View previous topic :: View next topic |
Author |
Message |
qrfl Advanced Cheater
Reputation: 0
Joined: 06 Apr 2006 Posts: 51
|
Posted: Sun Feb 28, 2016 11:49 am Post subject: Where in hex is the next instruction starting?? |
|
|
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 |
|
 |
hhhuut Grandmaster Cheater
Reputation: 6
Joined: 08 Feb 2015 Posts: 607
|
Posted: Sun Feb 28, 2016 2:46 pm Post subject: |
|
|
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 |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Sun Feb 28, 2016 2:48 pm Post subject: |
|
|
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 |
|
 |
qrfl Advanced Cheater
Reputation: 0
Joined: 06 Apr 2006 Posts: 51
|
Posted: Sun Feb 28, 2016 3:00 pm Post subject: |
|
|
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 |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
|
Back to top |
|
 |
|