assembly - Binary Patching - modifing existing instructions and keeping machine code alignment -
i'd edit first instruction , change jmp 100h
(give or take few bytes) mov edi,edi
takes 2 bytes , jmp 100h
takes 5 bytes (correct me if im wrong)
i edit machine code jmp 100h
, add nop
round 6 bytes.
.text:08048dd5 mov edi, edi .text:08048dd7 mov edi, edi .text:08048dd9 mov edi, edi .text:08048ddb mov edi, edi .text:08048ddd mov edi, edi .text:08048ddf mov edi, edi .text:08048de1 mov edi, edi .text:08048de3 mov edi, edi .text:08048de5 add [ebp+var_c], 1 ; add .text:08048de9 mov eax, offset format ; "message %d: %s" .text:08048dee lea edx, [ebp+s] ; load effective address .text:08048df4 mov [esp+8], edx
the result looks like:
.text:08048dd5 jmp loc_8048d41 .text:08048dd5 ; --------------------------------------------------------------------------- .text:08048dda db 90h .text:08048ddb db 89h, 0ffh .text:08048ddd db 89h, 0ffh .text:08048ddf db 89h, 0ffh .text:08048de1 db 89h, 0ffh .text:08048de3 db 89h, 0ffh .text:08048de5 ; --------------------------------------------------------------------------- .text:08048de5 add [ebp+var_c], 1 .text:08048de9 mov eax, offset amessageds ; "message %d: %s" .text:08048dee lea edx, [ebp+s] .text:08048df4 mov [esp+8], edx .text:08048df8 mov edx, [ebp+var_c]
what goes wrong here? how keep rest of code intact?
looks works, disassembler isn't interpreting data instructions. because of preceding jmp
instruction - disassembler sees code right after never reached, assumes it's not code (and interprets straight data).
Comments
Post a Comment