Need help coding Delphi ISO parser

Discussion in 'Wii - Hacking' started by Hendi48, Apr 11, 2009.

Apr 11, 2009
  1. Hendi48
    OP

    Newcomer Hendi48 Newbie

    Joined:
    Apr 11, 2009
    Messages:
    7
    Country:
    Germany
    Hello,

    sorry if this is the wrong section for this topic; I didn't know in which section I should put it.
    I've already done quite a bit and my problem is reading the file contents.
    Most of it is a translation of "disc_usage_table.c" from wbfs.exe, but I didn't want to use Pointers, so I decided to use streams for reading.

    Code:
    function TWiiISO.PartitionRead(Offset: Int64; Len: Integer): TMemoryStream;
    var
    ÂÂblock: array[0..$7FFF] of Byte;ÂÂÂÂÂÂ // Length = $8000
    ÂÂoffset_in_block, len_in_block: Integer;
    begin
    ÂÂResult := TMemoryStream.Create;
    
    ÂÂwhile Len > 0 do
    ÂÂbegin
    ÂÂÂÂoffset_in_block := offset mod $7c00;
    ÂÂÂÂlen_in_block := $7c00 - offset_in_block;
    ÂÂÂÂif (len_in_block > Len) then
    ÂÂÂÂÂÂlen_in_block := Len;
    ÂÂÂÂPartitionReadBlock(offset div $7c00, block);
    
    ÂÂÂÂResult.Write(block, $8000);
    ÂÂÂÂoffset := offset + len_in_block;
    ÂÂÂÂLen := Len - len_in_block;
    ÂÂend;
    end;
    
    procedure TWiiISO.PartitionReadBlock(BlockNo: Int64; var Block);
    var
    ÂÂRaw: array[0..$7FFF] of Byte;ÂÂÂÂÂÂ // Length = $8000
    ÂÂIV: array[0..15] of Byte;ÂÂÂÂÂÂ // Length = 16
    ÂÂOffset: Int64;
    begin
    ÂÂOffset := ActivePart.DataOffset + $8000 * BlockNo;ÂÂÂÂ// ActivePart is the partition which is currently parsed
    
    ÂÂISO.Seek(ActivePart.Offset + Offset + $3d0, soBeginning);
    ÂÂISO.ReadBuffer(IV, 16);
    ÂÂISO.Seek(ActivePart.Offset + Offset + $400, soBeginning);
    ÂÂISO.ReadBuffer(Raw, $7c00);
    
    ÂÂwith TCipher_Rijndael.Create do
    ÂÂbegin
    ÂÂÂÂInit(FDiscKey, 16, IV, 16);ÂÂÂÂ // the decrypted title key is stored in FDiscKey
    ÂÂÂÂMode := cmCBCx;
    ÂÂÂÂDecode(Raw, Block, $7c00);
    ÂÂÂÂFree;
    ÂÂend;
    end;
    
    procedure TWiiISO.DecryptTitleKey(const IV; const Source; var Dest);
    var
    ÂÂAES: TCipher_Rijndael;ÂÂÂÂ // DECCipher
    begin
    ÂÂAES := TCipher_Rijndael.Create;
    ÂÂtry
    ÂÂÂÂAES.Init(CommonKey, 16, IV, 8);ÂÂÂÂ// on WiiBrew it says title_id/IV has a size of 0x08, is that correct?
    ÂÂÂÂAES.Mode := cmCBCx;
    ÂÂÂÂAES.Decode(Source, Dest, 16);
    ÂÂfinally
    ÂÂÂÂAES.Free;
    ÂÂend;
    end;
    
    procedure TWiiISO.DoFiles;
    var
    ÂÂMS: TMemoryStream;
    begin
    ÂÂMS := PartitionRead(0, $480);
    ÂÂShowmessage(IntToStr(be34($0428, MS)));ÂÂ // FST-size
    ÂÂMS.SaveToFile('E:\lol.txt');
    ÂÂMS.Free;
    end;
    
    function TWiiISO.ReadInt(Off: Int64; S: TStream = nil): Integer;
    var
    ÂÂByte1, Byte2, Byte3, Byte4: Byte;
    begin
    ÂÂif S = nil then
    ÂÂÂÂS := ISO;
    
    ÂÂS.Seek(Off, soBeginning);
    
    ÂÂS.Read(Byte1, 1);
    ÂÂS.Read(Byte2, 1);
    ÂÂS.Read(Byte3, 1);
    ÂÂS.Read(Byte4, 1);
    
    ÂÂResult := (byte1 shl 24) or (byte2 shl 16) or (byte3 shl 8) or byte4;
    end;
    
    function TWiiISO.be34(Off: Int64; S: TStream = nil): Int64;
    begin
    ÂÂif S = nil then
    ÂÂÂÂS := ISO;
    
    ÂÂS.Seek(Off, soBeginning);
    
    ÂÂResult := 4 * ReadInt(Off, S);
    end;
    The shown message has a negative value, so something went wrong, but I don't know what. Maybe the DiskKey is decrypted wrong.

    I hope somebody here has good knowledge of Wii Discs and can tell me what's wrong. If you need the whole unit to test sth. etc. just tell me.
     
  2. Hendi48
    OP

    Newcomer Hendi48 Newbie

    Joined:
    Apr 11, 2009
    Messages:
    7
    Country:
    Germany
    No idea?

    Does anyone know a person who could help me with this or a better forum to post this question in?
     

Share This Page