简体   繁体   中英

WriteProcessMemory won't work

I want to WriteProcessMemory with an int and do it again making the int a negative number. I know how to do this in VB.NET; I tried the same way, but in C++, it won't work.

 WriteProcessMemory(hProcess, (void*)(MYBASE + 0x6F4), &number, 4, NULL);
 WriteProcessMemory(hProcess, (void*)(MYBASE + 0xA54), "-" & &number, 4, NULL);

Your "-" & &number is not doing what you seem to think it is. In C, the & binary operator means bitwise AND, not string concatenation (C doesn't have a native string type). So your second line is taking the pointer value (address of number ) and doing a bitwise AND with the ASCII numeric value of a hyphen (ie, you're taking the address & 46 ), which will give you a nonsense address and not do what you want.

That third parameter to WriteProcessMemory is an address, so you need a variable to take the address of. Replace the second line with these two lines:

int negativeNumber = -number;
WriteProcessMemory(hProcess, (void*)(MYBASE + 0xA54), &negativeNumber, 4, NULL);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM