 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
MegaZero How do I cheat?
Reputation: 0
Joined: 08 May 2015 Posts: 6 Location: Tokyo
|
Posted: Mon May 11, 2015 2:01 pm Post subject: jmp in C++ ? |
|
|
i need to make this jmp in c++ dll
| Code: |
main.exe+1E4168:
db EB
|
i tried it:
| Code: |
#define HS_BYTE_JMP 0x1E4168
BYTE JMP[] = { 0xEB };
BYTE JE[] = { 0x84 };
BYTE JNZ[] = { 0x85 }
void WriteJMP()
{
BYTE old1 = 0x00;
*((BYTE*)(((DWORD)GetModuleHandle(NULL) + HS_BYTE_JMP ))) = JMP[0];
}
|
I do not know why it does not work
|
|
| Back to top |
|
 |
Gniarf Grandmaster Cheater Supreme
Reputation: 43
Joined: 12 Mar 2012 Posts: 1285
|
Posted: Mon May 11, 2015 2:22 pm Post subject: |
|
|
Your problem comes from memory access rights aka memory protection (which has nothing to do with DRM). Usually the memory regions that contain code are readable and executable, but not writable, yet you are trying to write on it, which triggers and access violation (error code 0xC0000005 ).
To fix your problem, try:
| Code: | void WriteJMP()
{
LPVOID PatchAddress=reinterpret_cast<LPVOID>( ((DWORD)GetModuleHandle(NULL) + HS_BYTE_JMP ) );
DWORD OriginalProtection;
DWORD DummyVariable;
VirtualProtect(PatchAddress,1,PAGE_EXECUTE_READWRITE,&OriginalProtection); //make the memory region at PatchAddress readable,writable and executable, and save the current protection.
*((BYTE*)(PatchAddress) = JMP[0];
VirtualProtect(PatchAddress,1,OriginalProtection,&DummyVariable); //restore protection
}; | Note: I didn't check this code, there might be some small mistakes.
_________________
DO NOT PM me if you want help on making/fixing/using a hack. |
|
| Back to top |
|
 |
MegaZero How do I cheat?
Reputation: 0
Joined: 08 May 2015 Posts: 6 Location: Tokyo
|
Posted: Mon May 11, 2015 2:41 pm Post subject: |
|
|
| Gniarf wrote: | Your problem comes from memory access rights aka memory protection (which has nothing to do with DRM). Usually the memory regions that contain code are readable and executable, but not writable, yet you are trying to write on it, which triggers and access violation (error code 0xC0000005 ).
To fix your problem, try:
| Code: | void WriteJMP()
{
LPVOID PatchAddress=reinterpret_cast<LPVOID>( ((DWORD)GetModuleHandle(NULL) + HS_BYTE_JMP ) );
DWORD OriginalProtection;
DWORD DummyVariable;
VirtualProtect(PatchAddress,1,PAGE_EXECUTE_READWRITE,&OriginalProtection); //make the memory region at PatchAddress readable,writable and executable, and save the current protection.
*((BYTE*)(PatchAddress) = JMP[0];
VirtualProtect(PatchAddress,1,OriginalProtection,&DummyVariable); //restore protection
}; | Note: I didn't check this code, there might be some small mistakes. |
It is not possible to convert reinterpret_cast <LPVOID>
any idea?
|
|
| Back to top |
|
 |
Gniarf Grandmaster Cheater Supreme
Reputation: 43
Joined: 12 Mar 2012 Posts: 1285
|
Posted: Mon May 11, 2015 2:58 pm Post subject: |
|
|
reinterpret_cast<AAA>(BBB) should be the same thing as (AAA)BBB (like (BYTE*)PatchAddress ) except that it doesn't throw a warning.
If your compiler doesn't like it I guess you'll have to experiment to find a way to typecast that it accepts.
_________________
DO NOT PM me if you want help on making/fixing/using a hack. |
|
| 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
|
|