 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Guy Expert Cheater
Reputation: 0
Joined: 30 May 2009 Posts: 187
|
Posted: Sat Aug 29, 2009 1:23 am Post subject: Inline ASM x64 |
|
|
Since Microsoft has dropped inline ASM support for their x64 compilers, are there any other suggested workarounds for "re-adding" inline ASM support?
Intrinsics are lacking, externally linking against .ASM files doesn't work if you need something *inlined*. I could modify the program during runtime to hard-code in what I want, but I prefer a less dynamic solution, that wouldn't cost me every single runtime. |
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sat Aug 29, 2009 3:59 am Post subject: |
|
|
| afaik you're going to have to make do with intrinsics |
|
| Back to top |
|
 |
Guy Expert Cheater
Reputation: 0
Joined: 30 May 2009 Posts: 187
|
Posted: Sat Aug 29, 2009 10:43 am Post subject: |
|
|
| Slugsnack wrote: | | afaik you're going to have to make do with intrinsics |
I've come up with the idea of adding my own, pseudo-reassembler, which will replace specially-formatted instructions in your application after the linker pulls your app together.
e.g
| Code: |
*( ( ( unsigned char ** ) "\x92\x91" ) )[0] = 0;
|
Generates..
| Code: |
0040100A |. C600 00 MOV BYTE PTR DS:[EAX],0
|
The pseudo-reassembler would replace the above with:
| Code: |
0040100A 60 PUSHAD
0040100B 90 NOP
0040100C 90 NOP
|
EDIT:
I'm expanding on the idea of using a script to replace specially-marked places in memory to represent what should be turned into blocks of ASM.
e.g.:
| Code: |
#define __pushad( ) *( ( ( unsigned char ** ) "\x60\xFF\x00" ) )[0] = 0
#define __popad( ) *( ( ( unsigned char ** ) "\x61\xFF\x00" ) )[0] = 0
#ifdef _M_IX86
#define __popEAX( ) *( ( ( unsigned char ** ) "\x58\xFF\x00" ) )[0] = 0
#elif _M_X64
#define __popRAX( ) *( ( ( unsigned char ** ) "\x58\xFF\x00" ) )[0] = 0
#endif
|
The "reassembler" script, to be ran after the compiling and linking process:
| Code: |
#!/usr/bin/python
raw_size = 0x200
raw_offset = 0x400
f = open( "emit.exe", "rb" )
data = f.read( )
f.close( )
# Load anything before the code segment
new_data = data[:raw_offset]
cs = ""
cs += data[raw_offset:][:0x200]
### BEGIN CODE SEGMENT ###
#pushad
cs = cs.replace( "\xA2\x60\xFF\x00\x00", "\x60\x90\x90\x90\x90" )
#popad
cs = cs.replace( "\xA2\x61\xFF\x00\x00", "\x61\x90\x90\x90\x90" )
#pop EAX/pop RAX
cs = cs.replace( "\xA2\x58\xFF\x00\x00", "\x58\x90\x90\x90\x90" )
### END CODE SEGMENT ###
new_data += cs
# Load the data after the code segment
new_data += data[raw_offset+raw_size:]
f = open( "emit-new.exe", "wb" )
f.write( new_data )
f.close( )
|
Of course, this technique could easily be adapted to allow users to emit bytes into the CPU stream, accomplishing the same effect as inline ASM. |
|
| 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
|
|