Convert assembler instruction
Posted: Thu Mar 17, 2011 3:22 am
Is there a way to convert assembler code to byte?
push eax = $50
push eax = $50
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
If 0 ;do not execute asm code
Code_Start:
!push eax
Code_End:
EndIf
If ExamineAssembly(?Code_Start, ?Code_End)
If NextInstruction()
Debug Hex(PeekC(InstructionAddress()))
EndIf
EndIf
Code: Select all
If 0 ;do not execute asm code
Code_Start:
! mov eax,[edx]
! push eax
! push $004b9568
! jmp $0047e203
Code_End:
EndIf
;Original
;01240005 - 8b 02 - mov eax,[edx]
;01240007 - 50 - push eax
;01240008 - 68 68 95 4b 00 - push 004b9568 : [00640025]
;0124000D - e9 f1 e1 23 ff - jmp 0047e203
Global Dim aCounter(3)
aCounter(0) = 2
aCounter(1) = 1
aCounter(2) = 5
aCounter(3) = 5
If ExamineAssembly(?Code_Start, ?Code_End)
While NextInstruction()
s$ + InstructionString()+" - "
For j = 0 To aCounter(iNum) - 1
s$ + Hex(PeekC(InstructionAddress() + j)) + " "
Next
iNum + 1
Wend
EndIf
Debug s$
;Results
;mov eax, [edx] - 8B 2
;push eax - 50
;push dword 0x4b9568 - 68 68 95 4B 0
;jmp dword 0x87f203 - E9 88 E1 47 0
Code: Select all
If 0 ;do not execute asm code
Code_Start:
! mov eax,[edx]
! push eax
! push $004b9568
! jmp $0047e203
Code_End:
EndIf
Global Dim aCounter(3)
aCounter(0) = 2
aCounter(1) = 1
aCounter(2) = 5
aCounter(3) = 5
Macro reverse()
x$=LSet(Mid(a$,4),8,"0")
x$=Mid(x$,7,2)+Mid(x$,5,2)+Mid(x$,3,2)+Mid(x$,1,2)
EndMacro
If ExamineAssembly(?Code_Start, ?Code_End)
While NextInstruction()
s$ = InstructionString()
a$ = ""
For j = 0 To aCounter(iNum) - 1
a$ + Hex(PeekC(InstructionAddress() + j))
If j=0 : a$+" " : EndIf
Next
If FindString(s$,"push dword",1)
reverse()
a$=Mid(a$,1,2)+" "+x$
ElseIf FindString(s$,"jmp",1); Or FindString(s$,"call",1)
reverse()
x$=Hex(Val("$"+x$)+123) ;don't ask me where this 123 comes from
a$=Mid(a$,1,2)+" "+RSet(x$,8,"0")
EndIf
iNum + 1
Debug s$ + " - "+ a$
Wend
EndIf
Code: Select all
If 0 ;do not execute asm code
Code_Start:
! hCounter: ;$00457e61 in another process
! cmp dword [ecx + $0000009c], $01
! jne hCounter+$1c ; OK
! nop
! nop
! nop
! nop
! mov dword [hVar], ecx ; How to change hVar (hCounter+$18)?
! jmp hCounter+$1c ; OK
! nop
! nop
! nop
! hVar:
! add [eax], al
! add [eax], al
! mov [ecx + $000000a8], esi
Code_End:
EndIf
Dim aCounter(13)
aCounter(0) = 7
aCounter(1) = 2
aCounter(2) = 1
aCounter(3) = 1
aCounter(4) = 1
aCounter(5) = 1
aCounter(6) = 6
aCounter(7) = 2
aCounter(8) = 1
aCounter(9) = 1
aCounter(10) = 1
aCounter(11) = 2
aCounter(12) = 2
aCounter(13) = 6