如何将十六进制代码转换为x86指令 [英] How to turn hex code into x86 instructions
问题描述
我正在尝试制作一个脚本或程序,该脚本或程序将使用给定的字节(以十六进制形式),并将其转换为x86指令(例如c3-> retq)
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)
我尝试通过在仅包含程序集的文件上调用gcc -c
来做到这一点
I've tried doing it by calling gcc -c
on an assembly file just containing
retq
retq
,然后使用脚本在"c3 c3"所在的位置插入字节,然后使用objdump -d
查看现在的内容.但是,除非我仅传递与原始指令字节相同大小的指令,否则它似乎会弄乱文件的格式.
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.
我正在使用SSH,BASH终端在Raspbian Pi(基于Linux的操作系统)上运行它.我正在使用BASH Shell脚本和python,以及此处列出的工具和gdb.
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.
推荐答案
反汇编平面二进制文件:objdump -D -b binary -m i386 foo.bin
.或者使用汇编源中的.byte
指令创建目标文件,例如将.byte 0xc3
放入foo.s
然后gcc -c foo.s
然后objdump -d foo.o
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
这篇关于如何将十六进制代码转换为x86指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!