I'm currently trying to write a program in Rust (Windows 32-bits) which will basically extract some specific part machine code from it's own .text section.
Basically, if I define and call a function test1
as:
unsafe fn test1(){
asm!("
pushad
.byte 0x90, 0x90, 0x09, 0xC0, 0x09, 0xDB, 0x09, 0xC9, 0x90
inc eax
mov eax, ebx
xor eax, eax
.byte 0x90, 0x09, 0xC0, 0x09, 0xDB, 0x09, 0xC9, 0x90, 0x90
popad
"
:
:
:
:"intel");
}
It will output:
inc eax
mov eax, ebx
xor eax, eax
The program uses .byte 0x90, 0x09, 0xC0, 0x09, 0xDB, 0x09, 0xC9, 0x90, 0x90
and .byte 0x90, 0x09, 0xC0, 0x09, 0xDB, 0x09, 0xC9, 0x90, 0x90
to recognize the code to retrieve (those opcode represent some nop
and or reg, reg
which basically does nothing).
Everything was working fine until I tried to do the following thing:
unsafe fn test2(){
asm!("
.byte 0x90, 0x90, 0x09, 0xC0, 0x09, 0xDB, 0x09, 0xC9, 0x90
"
:
:
:
:"intel");
while a < 10{
a += 1;
}
asm!("
inc eax
dec eax
.byte 0x90, 0x09, 0xC0, 0x09, 0xDB, 0x09, 0xC9, 0x90, 0x90
"
:
:
:
:"intel");
}
It only detects the inc/dec
instructions, which means that I can't see anything which could be the assembly equivalent of the Rust code between the two usage of inline assembly (while loop that increments a).
I don't really know how the Rust compiler process inline assembly, but I logically thought that it would respect the order in which the code has to be executed...
I hope my question was clear enough.