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 


Where in hex is the next instruction starting??

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
qrfl
Advanced Cheater
Reputation: 0

Joined: 06 Apr 2006
Posts: 51

PostPosted: Sun Feb 28, 2016 11:49 am    Post subject: Where in hex is the next instruction starting?? Reply with quote

In cheat engine, when you create a codecave it overwrites memory with a jump, then it asks if we want the rest of the memory filled with nops.

How is this calculated?

I mean for example 0xE9 is JMP , however it doesnt necessarily mean is the beggining of an instruction, you could have.

E8 0066E912 where E8 is MOV and there is an E9 in the value that is not a JMP


thank you in advanced.
Back to top
View user's profile Send private message
hhhuut
Grandmaster Cheater
Reputation: 6

Joined: 08 Feb 2015
Posts: 607

PostPosted: Sun Feb 28, 2016 2:46 pm    Post subject: Reply with quote

CE always replaces the first byte of the selected instruction with the "E9" jump byte, followed by four bytes which specify the address to jump to.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Feb 28, 2016 2:48 pm    Post subject: Reply with quote

Assembly has specific bytes that represent specific instructions.
There are a limited number of possibilities and each instruction has a set length.
If the first byte is one thing, the processor knows what to expect in the next byte, and so on.
It then interprets those bytes into their corresponding instruction.
After executing the instruction, the processor moves on to the next byte.
It's as simple as that.

CE is disassembling the bytes to identify the instruction length.
It then knows that a JMP instruction takes up 5 bytes.
So it overwrites entire instructions until it covers those 5 bytes.
Any bytes beyond those 5 that are overwritten are converted into NOPs.
Back to top
View user's profile Send private message
qrfl
Advanced Cheater
Reputation: 0

Joined: 06 Apr 2006
Posts: 51

PostPosted: Sun Feb 28, 2016 3:00 pm    Post subject: Reply with quote

Zanzer wrote:

CE is disassembling the bytes to identify the instruction length.


This is exactly what I nead to learn to do

I was reading about the topic in another website and it seems that the first byte when you read it in binary it holds some of this info, i could be wrong, or the answer may be too extensive.


For example

8B442404 Mov Eax, [esp+4] is only 3 bytes
36A100054000 Mov Eax,[400500] is actually 6 bytes

so for me to create a mid-function detour that automatically calculates the lenght of the opcode like cheat engine does is necessary so i can replace the noped opcodes and know exactly where to return.

How to calculate the lenght? if it varies
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Feb 28, 2016 3:30 pm    Post subject: Reply with quote

http://forum.cheatengine.org/viewtopic.php?t=587413
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