Pointers

Ask for Help on Using the Language With Memory Hacking Software

Moderators: g3nuin3, SpeedWing, WhiteHat, mezzo

Pointers

Postby daenerys » Sat Jul 29, 2006 6:33 am

Hi,
if I am not mistaken, the pointers used in the script are not really pointing to the real memory. Is this true?
I have managed to make an real pointer only if I declare it like
extern int * memptr {"",address};

but if I do only
int * ptr;

and
ptr=memptr;

the *ptr is not equal to the *memptr. Or am I making here something wrong?
The problem tha tI have is that I have a game with a pointer to a player structure and I want to access the values in this structure. I have only managed to get the real pointer to the beginning of the structure, but nothing more....
daenerys
Hackleberry Fin
 
Posts: 25
Joined: Wed Jul 26, 2006 6:21 pm

Postby L. Spiro » Sat Jul 29, 2006 10:44 am

Pointers in the script are pointing to real memory.
Internally the script works exactly like C.
This is what makes it so compatible with real C/C++ functions and makes it exceptionally fast to call real C/C++ functions.

However what you are doing is taking an extern pointer and assigning it to a local pointer.
You can’t do this because they are using two completely different addressing methods.
extern pointers point to addresses in the target process while local pointers point to addresses in the script, or within Memory Hacking Software itself otherwise.


So if you did this:
Code: Select all
extern byte e_bHeader[32] = { "", 0x00400000 };
byte * l_pbHeader = (byte *)0x00400000;


e_bHeader[X] gives you the PE header (data from the loaded .EXE file at address 0x00400000) from the target process while l_pbHeader[X] gives you the PE header of Memory Hacking Software.




When you assign memptr to the local ptr, you are removing its extern properties, and the result is not necessarily what you desire.



If you want to map the player structure using extern, define a structure that matches that of your player structure and create an extern variable of a pointer of that type with the address being the address of the real pointer in the game.

So, for example, my player class looks like this:
Code: Select all
struct PLAYER {
    int iHealth;
    int iAmmo;
    float fPos[3]; // XYZ position.
    char szName[32]; // Player name.
};



And if we have a pointer to our player (which translates to a pointer to the PLAYER structure above) at address 0x0056F3EC, then we do this:
Code: Select all
extern PLAYER * e_pPlayer = { "", 0x0056F3EC };


And now to access anything in our player, use the normal -> operator.
Code: Select all
PrintF( "Health: %d, Ammo: %d, Pos: %f %f %f", e_pPlayer->iHealth, e_pPlayer->iAmmo, e_pPlayer->fPos[0], e_pPlayer->fPos[1], e_pPlayer->fPos[2] );




If you try to pass extern pointer types to functions you will be an error because they use different addressing modes, and the function does not know that the addressing mode for the parameter you supplied is supposed to be extern.
So if you want to print strings, you have to copy the string locally.
Code: Select all
char szLocal[32];
for ( INT I = 0; I < 32; I++ ) {
    szLocal[I] = e_pPlayer->szName[I];
}

Now to print your name you can use szLocal rather than e_pPlayer->szName.


Soon I will add a function that does this for you.
It will accept an extern pointer and return a local string that can be used to print text from your games.


L. Spiro
User avatar
L. Spiro
L. Spiro
 
Posts: 3129
Joined: Mon Jul 17, 2006 10:14 pm
Location: Tokyo, Japan

Postby daenerys » Sat Jul 29, 2006 3:00 pm

Thanks Spiro,
I kinda tought it would be something like this, but I wasnt sure.
This what you wrote here is a quality material that should find its place in the help files :)
danny
daenerys
Hackleberry Fin
 
Posts: 25
Joined: Wed Jul 26, 2006 6:21 pm

Postby gibxam » Thu Oct 09, 2008 7:21 am

I agree with daenrys, this post along with the help file on externs really cleared this issue up for me. One question I have is when you (L. Spiro) say that "the address of the real pointer in the game" this is a pointer that I would have to find using a method like the one shown in Josese's tutorial about pointers and complex addresses before I implement it into my script. Am I correct in this assumption?

-Max
User avatar
gibxam
Acker
 
Posts: 51
Joined: Mon Oct 06, 2008 3:19 am

Postby L. Spiro » Thu Oct 09, 2008 11:21 am

Yes.


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