4

我一直在寻找一种实用的工具,可以在 Linux 中打印任何英特尔 64 位或 32 位指令的操作码,例如。类似于Hiew'sDOS 中的汇编程序。基于网络的服务也是一种选择。

由于找不到任何内容,我制作了自己的bash脚本,从命令行参数(指令 [s] 和 <32/64>)创建汇编源文件,编译、链接和反汇编它并显示正确的行的拆卸。但是是否已经有一些程序可以显示任何给定指令的所有可能编码,例如。为mov eax,ebx?我使用nasm,ld的方法ndisasm显然只为每条指令提供了一种可能的编码。

使用此脚本,我可以获得nasm64 位和 32 位代码使用的编码,例如:

/home/user/code/asm$ showop 'nop;add eax,ebx;cpuid' 64

00000000  90                nop
00000001  01D8              add eax,ebx
00000003  0FA2              cpuid

但是我怎样才能轻松获得所有可能的操作码编码呢?是否已经有一些可用的程序?

这是代码:

#!/bin/bash

# usage: showop instructions bits

asminstr=$1
bits=$2

# asminstr="nop;nop;nop;nop;add eax,ebx;nop;nop;nop"
# bits=64

numberofinstr=`echo $asminstr | grep -o ";" | wc -l`
((numberofinstr++))

if [ -f tempasmfile.asm ]
    then
    rm tempasmfile.asm
fi
if [ -f tempobjfile.o ]
    then
    rm tempobjfile.o
fi
if [ -f tempexefile ]
    then
    rm tempexefile
fi

printf "[bits $bits]\nsection .text\nglobal _start\n\n_start:\n`echo $asminstr | sed 's/;/\\n/g'`\n" >tempasmfile.asm

nasm -f elf$bits tempasmfile.asm -o tempobjfile.o
ld tempobjfile.o -o tempexefile

if [ $bits -eq 32 ]
then
    ndisasm -b $bits -e 0x60 tempexefile | head -n $numberofinstr
elif [ $bits -eq 64 ]
then
    ndisasm -b $bits -e 0x80 tempexefile | head -n $numberofinstr
fi
rm tempasmfile.asm
rm tempobjfile.o
rm tempexefile
4

2 回答 2

3

libdisasmudis86这样的反汇编程序通常带有一个操作码查找表。

udis86 还带有一个命令行工具(udcli),您可以输入十六进制字节,它会为您提供解码版本。

于 2012-09-18T11:58:35.500 回答
0

radare2和它的 fork rizin提供了一些 cmdline 工具来实现这个目的:

    $ rasm2 -a x86 nop
    90
    $ rasm2 -d -a x86 90
    nop

如果使用 rizin,请替换rasm2rz-asm.

来源

另一种选择是cstool来自capstone-tool包装。

于 2021-05-03T18:37:11.930 回答