Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


jmp in C++ ?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
MegaZero
How do I cheat?
Reputation: 0

Joined: 08 May 2015
Posts: 6
Location: Tokyo

PostPosted: Mon May 11, 2015 2:01 pm    Post subject: jmp in C++ ? Reply with quote

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
View user's profile Send private message
Gniarf
Grandmaster Cheater Supreme
Reputation: 43

Joined: 12 Mar 2012
Posts: 1285

PostPosted: Mon May 11, 2015 2:22 pm    Post subject: This post has 1 review(s) Reply with quote

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
View user's profile Send private message
MegaZero
How do I cheat?
Reputation: 0

Joined: 08 May 2015
Posts: 6
Location: Tokyo

PostPosted: Mon May 11, 2015 2:41 pm    Post subject: Reply with quote

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
View user's profile Send private message
Gniarf
Grandmaster Cheater Supreme
Reputation: 43

Joined: 12 Mar 2012
Posts: 1285

PostPosted: Mon May 11, 2015 2:58 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites