Linux 如何反汇编原始 MIPS 代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9916130/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:28:10  来源:igfitidea点击:

How do I disassemble raw MIPS code?

linuxassemblymipsobjdump

提问by Lekensteyn

Similarly to How do I disassemble raw x86 code?, but then for the MIPS architecture: how do I disassemble raw MIPS code with objdump? I want to check the instructions in a vmlinux image, but to do so I now have to:

类似于如何反汇编原始 x86 代码?,但是对于 MIPS 体系结构:如何使用 反汇编原始 MIPS 代码objdump?我想检查 vmlinux 映像中的说明,但为此我现在必须:

: > x.c
mipsel-linux-gnu-gcc -c -o x.o x.c
mipsel-linux-gnu-objcopy --add-section raw=vmlinux x.o
mipsel-linux-gnu-objcopy --remove-section .comment x.o
mipsel-linux-gnu-objdump -D x.o | less

Is there an easier way to do it? I've tried the below to no avail:

有没有更简单的方法来做到这一点?我试过以下无济于事:

mipsel-linux-gnu-objdump -b elf32-tradlittlemips -mmips -Mgpr-names=O32,cp0-names=mips1,cp0-names=mips1,hwr-names=mips1,reg-names=mips1 -D vmlinux | less

It just spits out:

它只是吐出来:

mipsel-linux-gnu-objdump: vmlinux: File format not recognized

If it helps, here is the output of some commands:

如果有帮助,这里是一些命令的输出:

$ file x.o
x.o: ELF 32-bit LSB relocatable, MIPS, MIPS-I version 1 (SYSV), with unknown capability 0xf41 = 0x756e6700, with unknown capability 0x70100 = 0x1040000, not stripped
$ mipsel-linux-gnu-objdump -p x.o

x.o:     file format elf32-tradlittlemips
private flags = 1006: [abi=O32] [mips1] [not 32bitmode] [PIC] [CPIC]

The target is an AR7 CPU.

目标是 AR7 CPU。

采纳答案by Lekensteyn

Hmm, it seems easier than that. -b elf32-tradlittlemipsdoes not work because the file is not an ELF executable, but binary. So, the correct option to be used is -b binary. The other option, -mmipsmakes objdump recognize the file as binary for MIPS. Since the target machine is little endian, I also had to add -ELto make the output match the output for x.o.

嗯,似乎比这更容易。-b elf32-tradlittlemips不起作用,因为该文件不是 ELF 可执行文件,而是二进制文件。因此,要使用的正确选项是-b binary. 另一个选项是-mmips让 objdump 将文件识别为 MIPS 的二进制文件。由于目标机器是小端,我还必须添加-EL以使输出与x.o.

-mmipsonly includes the basic instruction set. The AR7 has a MIPS32 processor which has more instructionsthan just mips. To decode these newer MIPS32 instructions, use -mmips:isa32. A list of available ISAs can be listed with objdump -i -m.

-mmips只包括基本指令集。AR7 有一个 MIPS32 处理器,它有更多的指令,而不仅仅是 mips。要解码这些较新的 MIPS32 指令,请使用-mmips:isa32. 可用 ISA 的列表可以用 列出objdump -i -m

The final command becomes:

最后的命令变成:

mipsel-linux-gnu-objdump -b binary -mmips:isa32 -EL -D vmlinux

This would show registers like $3instead of their names. To adjust that, I used the next additional options which are mentioned in mipsel-linux-gnu-objdump --help:

这将显示寄存器 like$3而不是它们的名称。为了调整它,我使用了以下提到的附加选项mipsel-linux-gnu-objdump --help

-Mgpr-names=32,cp0-names=mips32,cp0-names=mips32,hwr-names=mips32,reg-names=mips32

I chose for mips32after reading:

mips32在阅读后选择了:

回答by Kaz

??? What's wrong with just:

???只是有什么问题:

mipsel-linux-gnu-gcc -c -o x.o x.c
mipsel-linux-gnu-objdump -D x.o

Is the problem that -Ddiassembles all the sections, code or not? Use -dthen. Or -Sto show assembly interleaved with source (implies -d).

是否-D反汇编所有部分、代码的问题?使用-d即可。或者-S显示与源交错的程序集(暗示-d)。

or how about getting the assembly code from gcc:

或者如何从 gcc 获取汇编代码:

mipsel-linux-gnu-gcc -S x.c

回答by Anthony DeRosa

Use ODA, the online disassembler:

使用在线反汇编程序 ODA:

http://www.onlinedisassembler.com

http://www.onlinedisassembler.com