Skip to main content
gamedev.net
🔒 Locked

Memhacking Problem

Started by TonyB 4 replies 1.1k views
Original Post
TonyB
TonyB
here is the code i use to read the memory, when i try it on some things, it says access violation very often, and is quite unreliable, i was wondering if anyone can refine it, or tell me what im doing wrong.. float CMemHax::ReadFloat( DWORD address ) { if(!readytouse) { return 0.0f; } float retvalx; ReadProcessMemory( game, (LPCVOID) address, &retvalx, sizeof(float), NULL ); return retvalx; } playptr = memory.ReadLong(0xB6F5F0); pointer = memory.ReadLong(playptr + 0x14); x = memory.ReadFloat(pointer + 0x30); y = memory.ReadFloat(pointer + 0x34); z = memory.ReadFloat(pointer + 56);
moeron
moeron
Are you sure your sending valid memory addresses to it? I'd imagine if you sent stack addresses that could cause an exception of some sort...What exactly are you doing this for anyway?

[EDIT]
Here is something I found on MSDN about the function
Quote:

BOOL ReadProcessMemory(
HANDLE hProcess,
LPCVOID lpBaseAddress,
LPVOID lpBuffer,
SIZE_T nSize,
SIZE_T* lpNumberOfBytesRead
);

hProcess
[in] A handle to the process with memory that is being read. The handle must have PROCESS_VM_READ access to the process.


Are you sure the handle fits these criteria?
moe.ron
Lord Hen
Lord Hen
Well, lets see.
Lets take a look at this line:
playptr = memory.ReadLong(0xB6F5F0);

lets say the memory at that location gave you the value 8. That value is now stored in playptr.

in the next line, you have:
pointer = memory.ReadLong(playptr + 0x14);

This would try to get the value of the memory at 8 +0x14, which is not the desired thing to do. What you want to do is have playptr set to the address, not the value at the address.

Later.
moeron
moeron
Quote:
Original post by Lord Hen
Well, lets see.
Lets take a look at this line:
playptr = memory.ReadLong(0xB6F5F0);

lets say the memory at that location gave you the value 8. That value is now stored in playptr.

in the next line, you have:
pointer = memory.ReadLong(playptr + 0x14);

This would try to get the value of the memory at 8 +0x14, which is not the desired thing to do. What you want to do is have playptr set to the address, not the value at the address.

Later.


If the memory at 0xB6F5F0 is a pointer then it will have an address in it. I think you are confused. That code isn't dereferencing the pointer, it is finding what address the pointer is pointing to.




moe.ron
fongerJr
fongerJr
Unless the value at 0xB6F5F0 was in fact a pointer to a memory address, which seems to be a valid assumption.

Edit: Beaten.
TonyB
TonyB
i should have been more specific, it reads the coordanites X and Y fine, but around the 5th time around i usually get some kind of error when it trys to read Z (which is also read fine untill the 5th time or so)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.