我一直在寻找一种实用的工具,可以在Linux中打印任何英特尔64位或32位指令的操作码,例如。 像DOS中的Hiew's
汇编程序。 基于networking的服务也是一个select。
因为我找不到任何东西,所以我创build了自己的bash
脚本,它从命令行参数(指令[s]和<32/64>)创build汇编源文件,编译,链接和反汇编,并显示正确拆卸行。 但是,是否已经有一些程序能够显示任何给定指令的所有可能的编码,例如。 对于mov eax,ebx
? 我使用nasm
, ld
和ndisasm
显然只给每个指令一个可能的编码。
通过这个脚本,我可以得到nasm
用于64位和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
像libdisasm和udis86反汇编程序通常带有一个查找表的操作码。
udis86还附带了一个命令行工具(udcli),它提供十六进制字节,它给你的解码版本。