Page 1 of 1

Declaring an Array from a variable?

PostPosted: Mon Apr 21, 2008 8:21 am
by CoMPMStR
I am trying to write a script to get a name from memory (attached process). The name isn't null terminating and it's a variable length so I can't seem to declare the CHAR array successfully. Since I'm using a pointer and not a static address, I have an extern structure already declared:

Code: Select all
extern struct playerName {
   BYTE bBuffer[0x894];
   struct {
      struct {
      BYTE bBuffer[0x15];
      BYTE pNameLen;
      //CHAR pName[pNameLen];
      } * poPObj;
   } * poPObj;
} * poPBase = {"", 0x3404F1A4};


When I call poPBase->poPObj->poPObj->pNameLen it has the correct value. The name follows directly after the length so I thought of doing it like this. I already know the commented CHAR variable (pName) doesn't work as is. My question is, how can I declare it successfully from a variable?

I need something that will get the same results as
Code: Select all
BYTE tLen;
tLen = poPBase->poPObj->poPObj->pNameLen;
CHAR pName[tLen]; // this doesn't work >.<
char * szName = pName;
PrintF("Name:%s", szName);


Please help. I'm too used to VB. :roll: Thanks in advance. :D

PostPosted: Mon Apr 21, 2008 2:55 pm
by L. Spiro
Code: Select all
extern struct playerName {
   BYTE bBuffer[0x894];
   struct {
      struct {
      BYTE bBuffer[0x15];
      BYTE pNameLen;
      CHAR pName[1]; // Dummy array of 1 character.
      } * poPObj;
   } * poPObj;
} * poPBase = {"", 0x3404F1A4};


INT iLen = poPBase->poPObj->poPObj->pNameLen;
CHAR * pcName = Malloc( iLen + 1 );
for ( INT I = 0; I < iLen; I++ ) {
    pcName[I] = poPBase->poPObj->poPObj->pName[I];
}
pcName[iLen] = '\0';

PrintF("Name:%s", pcName);
Free( pcName );



L. Spiro