 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
NoIPDotCom How do I cheat?
Reputation: 0
Joined: 18 Mar 2013 Posts: 2
|
Posted: Mon Mar 18, 2013 2:52 pm Post subject: Reading same value via .dll soure code as in cheat engine |
|
|
Hi all,
maybe it is just a twister in my thinking, but currently I am not getting any further with my problem implementing a mem read into my source code. Lets assume the following:
This code will be used through a .dll loaded by the process at startup:
| Code: |
void GetThisProcessHandle(){
try{
DWORD CurrentProcessID; // -- this will store the process ID of the current process used to read from the memory
CurrentProcessID = GetCurrentProcessId();
globalProcessID = CurrentProcessID;
if( CurrentProcessID ){
globalProcHandle = OpenProcess(PROCESS_VM_READ, 0, CurrentProcessID); // -- get permission to read
globalBaseAddress = (DWORD)globalProcHandle;
}
}catch( ... ){
// -- just catch any errors
}
}
int GetState(){
try{
DWORD AddressState = 0x00A7BCAE; // -- this is the address that we want to read from
int ValueState = -1; // -- this will store the value of the state
if( globalProcHandle ){
ReadProcessMemory(globalProcHandle, (void*)AddressState, &ValueState, sizeof(ValueState), 0);
}
return ValueState;
}catch( ... ){
return -2;
}
}
|
Triggering the value change and reading it via cheat engine, the result is as expected (either true or false || 1 or 0), but when I use those two functions, I always get (in this case) -65335 as a return value. Does anyone might can give me a hint what I am doing wrong !?!?
Thank you very much in advance ...
Cheers
NoIP
| Description: |
|
| Filesize: |
23.97 KB |
| Viewed: |
3504 Time(s) |

|
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Mon Mar 18, 2013 4:02 pm Post subject: |
|
|
One thing to note:
| Code: | | globalBaseAddress = (DWORD)globalProcHandle; |
This is not valid, the handle you open is not the base address of the module / executable.
As for your reading problem, you are trying to read 4 bytes instead of 1:
| Code: | int ValueState = -1; // -- this will store the value of the state
if( globalProcHandle ){
ReadProcessMemory(globalProcHandle, (void*)AddressState, &ValueState, sizeof(ValueState), 0);
} |
Instead, change the sizeof to just be 1 for the size to read.
_________________
- Retired. |
|
| Back to top |
|
 |
SteveAndrew Master Cheater
Reputation: 30
Joined: 02 Sep 2012 Posts: 323
|
Posted: Mon Mar 18, 2013 4:46 pm Post subject: |
|
|
As Wiccaan said that isn't the base address... but your main problem is you you're reading 4 bytes (sizeof(int)) rather than 1, so actually only read 1 byte and change you're variable to be the same size as the data you're reading, or initialize your variable to zero rather than -1...
Plus if you're inside the process already, why even use ReadProcessMemory?
You can just do: (since you're value is only a byte you probably want to store in a byte sized value also... you're using an int which is 4 bytes)
| Code: |
BYTE ValueState = *(BYTE*)AddressState;
//Or if you really wanted it to be in a 4 byte value and use your int
int ValueState = 0;
BYTE TheValue = *(BYTE*)AddressState;
ValueState = TheValue;
|
If you wanted to use ReadProcessMemory though for some reason... Then (since you're inside the process) use this to get it's base address instead of what you have:
| Code: |
globalBaseAddress = (DWORD)GetModuleHandleW(0); // or GetModuleHandleA(0);
|
And also change:
| Code: |
//to either this:
BYTE ValueState = -1;
//char ValueState = -1; //same thing if you don't include <Windows.h>
ReadProcessMemory(globalProcHandle, (void*)AddressState, &ValueState, sizeof(ValueState), 0);
//or you could use an int, but don't set it to -1 (0xFFFFFFFF) as if you only read one byte into it, it will it's not going to equal 1 or 0 after reading that byte into it... it will be some negative value (more like -255 or -256) as you'll be only setting that one byte, and since you've initialized it to -1 instead of zero, it will look like: 0xFFFFFF01 or 0xFFFFFF00
int ValueState = 0;
ReadProcessMemory(globalProcHandle, (void*)AddressState, &ValueState, 1, 0);
|
_________________
|
|
| Back to top |
|
 |
NoIPDotCom How do I cheat?
Reputation: 0
Joined: 18 Mar 2013 Posts: 2
|
Posted: Tue Mar 19, 2013 7:40 am Post subject: |
|
|
@Wic: That really get me going thank u so much !!!
So far I am using this to do the job:
| Code: |
bool GetState( DWORD Address ){
try{
bool Value = 0;
if( globalProcHandle ){
ReadProcessMemory(globalProcHandle, (void*)Address, &Value, sizeof(Value), 0);
}
return Value;
}catch( ... ){
return 0;
}
}
|
@Steve: You've giving me a lot to think about. Really appreciate that !!!
So as far as I understand this ...
| Code: |
BYTE ValueState = *(BYTE*)AddressState;
|
... could replace my whole function to access the state as if it is true or false ...
In general I would like to have the least impact with most highest reliability possible ... I just started with C++ and each day I finally find out what I don't know ... so here too ... thank u so much Steve!
Cheers
NoIP
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|