| View previous topic :: View next topic |
| Author |
Message |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Fri Jan 16, 2009 8:27 pm Post subject: Memory Viewer |
|
|
im trying to code a engine in C++.
I want my memory viewer to replicate CE's, but i have one problem. I'm able to read the bytes properly, but i want to know how to put the right bytes together. For example :
//supposed to be mov eax, 10
00400000 : mov eax
00400001 : 10
In cheatengine, it looks like:
00400000 : mov eax, 10
00400002 : new operations
I need help with splitting the bytes properly :[
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Fri Jan 16, 2009 8:29 pm Post subject: |
|
|
Start at an address, and try to convert the first byte to an Assembler instruction. If that fails, then try with the first two bytes; if that fails, first three...
etc.
_________________
|
|
| Back to top |
|
 |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Fri Jan 16, 2009 8:31 pm Post subject: |
|
|
| Is there like an open source file where i can convert Byte in String format to opcodes?
|
|
| Back to top |
|
 |
FerrisBuellerYourMyHero Master Cheater
Reputation: 0
Joined: 14 Feb 2007 Posts: 401 Location: Inside your <kernel>
|
Posted: Fri Jan 16, 2009 8:47 pm Post subject: |
|
|
The bytes that make up the code is called machine code. Obviously no matter how good with numbers you are it would be pretty hard to be able to interpret the machine code as assembly instructions.
What your asking is how to code a disassembler in C++. A disassembler takes those machine code bytes and converts them into human readable assembly instructions. An assembler is quite the opposite, it takes your asm instructions and converts them into machine code.
Anyway its a bit complicated. I've thought of the idea before but never actually tried doing it.
A good place to start is maybe with cheat engine's disassembler.pas!
http://ce.colddot.nl/browser/Cheat%20Engine/disassembler.pas?rev=62
So you see its not a matter of "splitting the bytes properly". You have to read the bytes and convert them into string assembly instructions.
For example for a jump or call instruction you'd have to interpret 0xE9/0xE8 as JMP/CALL
then add the jump offset (the next one/four bytes) to the address of where the E8/E9 is. Finally add the size of the instruction (a long jump is 5 bytes) that gives you the address it jumps to/calls
so long jump
Addr + jump offset + 5;
short jump
Addr + jump offset + 2;
and thats just one of the many opcodes there are! There's a lot which is what makes it tricky. Also E8/E9 isnt always a jump or call it could be part of another instruction.
If you've ever noticed if you make ce go to an address in the middle of an instruction it disassembles it even though its in the middle of an instruction... Thats the disassembler at work! Trying to interpret the bytes as assembly instructions...
_________________
You know, life moves pretty fast. If you don't stop and look around once in a while, You could miss it!
 |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Fri Jan 16, 2009 9:56 pm Post subject: |
|
|
It's actually not that difficult. Dark_Byte filters every single byte (Which i found kinda confusing... especially for SIB, which was so unnecessary... I made the same function in C++ in 52 lines...)
What I did was make a huge array of opcode commands and rules. (Using the operand and size rules in Intel's software manual). Each function would return a size to add on to the main size that is being used.
I have a function for
Interpreting the first byte for rules
ModRM (For byte commands which next byte is a ModRM byte)
SIB (For byte commands which next byte is SIB byte)
Overall it wasn't to difficult, you just need to know what your doing.
Here's a pic:
I haven't filtered all rules yet so some opcodes get skipped like in the picture u can see BOUND ESP, its one of the ones i haven't implimented yet. I also need to do Float pointer instructions. Other then that its done
_________________
|
|
| Back to top |
|
 |
sponge I'm a spammer
Reputation: 1
Joined: 07 Nov 2006 Posts: 6009
|
Posted: Fri Jan 16, 2009 10:51 pm Post subject: |
|
|
| lurc wrote: | It's actually not that difficult. Dark_Byte filters every single byte (Which i found kinda confusing... especially for SIB, which was so unnecessary... I made the same function in C++ in 52 lines...)
What I did was make a huge array of opcode commands and rules. (Using the operand and size rules in Intel's software manual). Each function would return a size to add on to the main size that is being used.
I have a function for
Interpreting the first byte for rules
ModRM (For byte commands which next byte is a ModRM byte)
SIB (For byte commands which next byte is SIB byte)
Overall it wasn't to difficult, you just need to know what your doing.
Here's a pic:
I haven't filtered all rules yet so some opcodes get skipped like in the picture u can see BOUND ESP, its one of the ones i haven't implimented yet. I also need to do Float pointer instructions. Other then that its done  | SSE instructions? MMX?
_________________
|
|
| Back to top |
|
 |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Fri Jan 16, 2009 11:08 pm Post subject: |
|
|
lurc you need to helpp mee
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sat Jan 17, 2009 11:50 am Post subject: |
|
|
| sponge wrote: | | SSE instructions? MMX? |
No SSE, working on MMX. I kinda put the project aside for now, but i'll get back to it soon.
_________________
|
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Sat Jan 17, 2009 1:37 pm Post subject: |
|
|
| I gave up on this while making my crap engine. So I just made it a hex editor instead. Before I started, I asked dark byte and he said look at the intel instruction manual. I did then I forgot about it cause there were hundreds of pages of instructions and their matching opcodes >.<
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sat Jan 17, 2009 2:15 pm Post subject: |
|
|
| dnsi0 wrote: | | I gave up on this while making my crap engine. So I just made it a hex editor instead. Before I started, I asked dark byte and he said look at the intel instruction manual. I did then I forgot about it cause there were hundreds of pages of instructions and their matching opcodes >.< |
The structure of it all actually isn't that difficult.
If you look at the chart that's in there for all the Opcodes from 00 to FF you can just build on that. You still have to know what your doing though.
Understanding which bit means what and such.
_________________
|
|
| Back to top |
|
 |
|