0

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

retq
retq

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.

Testare
  • 338
  • 3
  • 12

1 Answers1

4

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

Jester
  • 56,577
  • 4
  • 81
  • 125
  • 1
    If you literally have a hexdump, not a binary, you could also hex-"undump" back to a binary you can disassemble. `xxd -r` does that, and it may be easier than massaging it into a comma-separated list of bytes as an operand to a `.byte` directive. – Peter Cordes Nov 15 '16 at 19:30
  • Thank you so much! Both of those worked extremely well =] – Testare Nov 15 '16 at 20:01