Declaring an Array from a variable?

Ask for Help on Using the Language With Memory Hacking Software

Moderators: g3nuin3, SpeedWing, WhiteHat, mezzo

Declaring an Array from a variable?

Postby CoMPMStR » Mon Apr 21, 2008 8:21 am

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
Image

______________________________________________________
My Utilities:
CT <-> LSSAVE Converter
LSS Visual Dialog Designer
.NET Trainer Helper Library

~Whether you think you can or you think you can't, you're right.

L. Spiro wrote:In my left hand is a red pill. If you take it I will show you the truth. I lost my right hand in the war, so I’m afraid you’re stuck with the red pill.
User avatar
CoMPMStR
(P)ot (I)n (M)y (P)ipe
 
Posts: 451
Joined: Thu Mar 06, 2008 7:50 am
Location: Best Place

Postby L. Spiro » Mon Apr 21, 2008 2:55 pm

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
Our songs remind you of songs you’ve never heard.
User avatar
L. Spiro
L. Spiro
 
Posts: 3129
Joined: Mon Jul 17, 2006 10:14 pm
Location: Tokyo, Japan


Return to Help

Who is online

Users browsing this forum: No registered users and 0 guests

cron