C++ reading string from memory -
i wrote dll application hooked process. works shows first letter.
wanted whole string. string vary 2 letters 32 letters.
//reading memory handle exebaseaddress = getmodulehandlea(0); char unameaddr = *(char*)((char*)exebaseaddress + 0x34f01c); printf("%c \n", unameaddr);
i wanted understand parts:
*(char*)((char*) //<-- for.
and if possible use if using multilevel pointers:
char multipoint = *(char*)((char*)exebaseaddress + 0x34f01c + 0x123 + 0x321 + 0x20);
update
i guess wrong here:
if(unameaddr == "omnicient") cout << "you omni" << endl;
i used username name omnicient
did not cout you omni
. guess compare wrong?
%c
displays char
s (single characters), %s
displays null-terminated char*
s (strings):
handle exebaseaddress = getmodulehandlea(0); char *unameaddr = (char*) exebaseaddress + 0x34f01c; printf("%s \n", unameaddr);
notice tidied pointer casting, important thing got rid of final dereference (*
@ front) , assigned char*
(pointer) instead of char
.
if string isn't null-terminated (unlikely), need use %.*s
, pass length of string too.
as second part of question:
*(char*)((char*) exebaseaddress + 0x34f01c)
let's break down. inside brackets (therefore first thing evaluated) this:
(char *) exebaseaddress + 0x34f01c
well that's c cast (casting handle
char*
) followed addition. in other words, says "treat thing if pointer memory, ahead 0x34f01c bytes of memory" (char
1 byte). pointer new position in memory.
then out of brackets , cast char*
again... needlessly. have been:
*((char*) exebaseaddress + 0x34f01c)
and dereference (the *
@ front), says "now tell me bit of memory you're pointing is". in case don't want that, because want whole string, not first letter (inside printf
, loops along memory send printing each character until finds 0
, aka \0
aka null
).
Comments
Post a Comment