Testare Testare - 1 year ago 112
Linux Question

How to turn hex code into x86 instructions

I'm trying to make a script or program that will take given bytes (given in hexadecimal), and convert them into a x86 instructions (For example c3 -> retq)

I've tried doing it by calling

gcc -c
on an assembly file just containing


and then using a script to insert bytes where it says "c3 c3", then using
objdump -d
to see what it says now. But it seems that it messes up the format of the file unless I only pass an instruction of the same size as the original instruction bytes.

I'm running it on a Raspbian Pi (A linux based operating system) using SSH, BASH terminal. I'm using BASH shell scripts and python, as well as the tools listed here, and gdb.

Answer Source

Disassemble flat binary file: objdump -D -b binary -m i386 foo.bin. Or create an object file using .byte directives from assembly source, e.g. put .byte 0xc3 into foo.s then gcc -c foo.s then objdump -d foo.o

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download