Hacking Need help coding Delphi ISO parser

Hendi48

Member
Newcomer
Joined
Apr 11, 2009
Messages
7
Trophies
0
XP
143
Country
Gambia, The
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.
 

Site & Scene News

General chit-chat
Help Users
  • Olmectron @ Olmectron:
    bread
  • boomy @ boomy:
    bread
  • Olmectron @ Olmectron:
    breadofthewild
    +1
  • RichardTheKing @ RichardTheKing:
    ^ That explains why that game feels so stale and old and gross; thanks!
  • Asia81 @ Asia81:
    pooping a bread in the wild
    +2
  • kenenthk @ kenenthk:
    Yo found my PS1 pizza hut demo disc
  • thehawksfuckingdead7 @ thehawksfuckingdead7:
    ps1 games are wild man
  • RichardTheKing @ RichardTheKing:
    Okay, how do I disable that "GBAtemp wants to enable push notifications" banner at the bottom of the screen? It keeps appearing whenever I visit the home page, and I can't enable them.
  • kenenthk @ kenenthk:
    You embrace it
  • Veho @ Veho:
    PS "Look ma I can do 3D" 1.
  • kenenthk @ kenenthk:
    Embrace the triangles 📐
  • Veho @ Veho:
    Embrace the 12 polygons and lack of anti-aliasing! Learn to love the sub-DS graphics because it's the gAMePlAY tHat CoUNts
  • kenenthk @ kenenthk:
    Triangle snake
  • Veho @ Veho:
    It looks like those cheap vacuum formed Halloween masks, paper thin, with printed graphics instead of shapes.
  • kenenthk @ kenenthk:
    So Joe Biden? :tpi:
  • Sicklyboy @ Sicklyboy:
    wew lad I sure love not sleeping before going in ass-early for work
  • Veho @ Veho:
    Sleeping is for wimps.
  • Veho @ Veho:
    Chew on some caffeine pills and raw-dog reality.
  • Sicklyboy @ Sicklyboy:
    I'm a wimp
  • kenenthk @ kenenthk:
    Drugs are good for sleep
  • kenenthk @ kenenthk:
    I've heard
  • kenenthk @ kenenthk:
    Meth is also a good coffee replacement
    kenenthk @ kenenthk: Meth is also a good coffee replacement