Qhimm.com Forums

Miscellaneous Forums => Scripting and Reverse Engineering => Topic started by: Alhexx on 2002-03-02 12:16:00

Title: To Fice & SaiNt
Post by: Alhexx on 2002-03-02 12:16:00
Okay, I need a Source Code translation for Melissa, my Parasite Eve ripper. Could you please do me a favor and translate those two types into C++ and Pascal?

Code: [Select]

'Melissa Index File Header
Public Type MelHeader   'Offset Len     Description
  ID As String * 8      ' 0      8      = "MELISSA1"
  FLen As Long          ' 8     12      Length of File
  NumEntries As Long    '12     16      Count of Entries
End Type

'Melissa Index File Entry
Public Type MelEntry
  ID As String * 4      ' 0      4      Type / Extension (e.g. "TIM ")
  Offset As Long        ' 4      8      Offset of File in IMG
  Length As Long        ' 8     12      Length of File
  Dummy As String * 4   '12     16      = "MLSA"
End Type


 - Alhexx
Title: To Fice & SaiNt
Post by: The SaiNt on 2002-03-02 12:43:00
Code: [Select]

// Melissa Index File Header
typedef struct {
// Offset Len Description
char ID[8]; // 0 8 = "MELISSA1"
long FLen; // 8 12      Length of File
long NumEntries; // 12 16      Count of Entries
} MelHeader;

// Melissa Index File Entry
typedef struct {
char ID[4]; // 0      4      Type / Extension (e.g. "TIM ")
long offset; // 4      8      Offset of File in IMG
long Length; // 8     12      Length of File
char Dummy[4]; // 12     16      = "MLSA"
} MelEntry;
[edited] 1 2002-03-02 13:46
Title: To Fice & SaiNt
Post by: Darkness on 2002-03-02 15:14:00
if youre planning on using strings in c++, i would use string classes rather than standard character arrays. They are SO MUCH easier to handle. It adds more memory if the string goes beyond

saint-> theres ways to do that without typedef :)
Title: To Fice & SaiNt
Post by: ficedula on 2002-03-02 15:25:00
Darkness: String classes also don't necessarily read into/out of files as well, certainly not in this situation where the strings ARE fixed length.

Alhexx:

Type
  MelHeader = packed record
    ID:     Array[0..7] of Char;
    FLen: Integer;
    NumEntries: Integer;
  end;

  MelEntry = packed record
    ID:    Array[0..3] of Char;
    Offset, Length: Integer;
    Dummy: Array[0..3] of Char;
  end;
Title: To Fice & SaiNt
Post by: The SaiNt on 2002-03-02 16:25:00
Darkness :

Are you refering to CString?
Have you ever made a memory dump of a program that uses CString?
You'll notice that there will be extra space allocated before the string.
If you use char Apple[] = "This here's a string";
and the string was stored at offset 0xABCDEF00, your memory dump would probably look like this.
Code: [Select]

ABCDEF00  54 68 69 73 20 68 65 72 65 27 This here'
ABCDEF0F  73 20 61 20 73 74 72 69 6E 67 s a string

If you were to use CString Apple = "This here's a string";
you would probably get something like this.
Code: [Select]

ABCDEEF6  01 00 00 00 10 00 00 00 00 00 ..........
ABCDEF00  54 68 69 73 20 68 65 72 65 27 This here'
ABCDEF0F  73 20 61 20 73 74 72 69 6E 67 s a string

See the extra memory used? This is the place where the class instance is setting aside for all the housekeeping chores ;)
So like fice said, for fixed length strings, char arrays work better :)
I agree with you though that CString makes it easier to manipulate strings.
About typedef, Alhexx's was defining a type so I did the same ;)
Title: To Fice & SaiNt
Post by: Alhexx on 2002-03-03 13:06:00
Fice & SaiNt:

(http://www.8ung.at/alhexx/tankyou.jpg)

 - Alhexx