我如何反汇编原始MIPS代码

我如何反汇编原始MIPS代码

本文介绍了我如何反汇编原始MIPS代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似于如何反汇编原始x86代码?,但是对于MIPS架构:如何反汇编原始x86代码? objdump的MIPS代码?我想查看vmlinux映像中的说明,但是要做到这一点,我现在必须:

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:

: > 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

它吐出来了:

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]

目标是AR7 CPU.

The target is an AR7 CPU.

推荐答案

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

Hmm, it seems easier than that. -b elf32-tradlittlemips does 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, -mmips makes objdump recognize the file as binary for MIPS. Since the target machine is little endian, I also had to add -EL to make the output match the output for x.o.

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

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

最终命令变为:

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

这将显示诸如$3之类的寄存器,而不显示其名称.为了进行调整,我使用了mipsel-linux-gnu-objdump --help中提到的下一个附加选项:

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

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

我在阅读后选择了mips32:

  • http://www.linux-mips.org/wiki/AR7
  • http://www.linux-mips.org/wiki/Instruction_Set_Architecture

这篇关于我如何反汇编原始MIPS代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 05:11