我一直在尋找一種實用的工具,可以在Linux中打印任何英特爾64位或32位指令的操作碼,例如。像DOS中的Hiew's
彙編程序。基於網絡的服務也是一種選擇。在Linux中輕鬆檢查英特爾彙編操作碼
因爲我找不到任何東西,我製作了自己的bash
腳本,它通過命令行參數(指令[s]和< 32/64>)創建彙編源文件,編譯,鏈接和反彙編並顯示正確的反彙編行。但是,是否已經有一些程序會顯示全部任何給定指令的可能編碼,例如。爲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
爲什麼你需要所有可能的操作碼? [x86asm.net](http://ref.x86asm.net/)提供了所有操作碼的XML描述,也許這會有所幫助? – DCoder
用於開發我自己的非源代碼調試器。我有x86asm.net的XML描述和英特爾的文檔,但我正在尋找一個實用的工具,可用於生成所有不同的操作碼,最好在Linux控制檯中。 – nrz
爲什麼你需要生成所有不同的?測試你自己的反彙編代碼?如果是這樣,那麼如何生成隨機序列(或不是如此隨機,順序),並將反彙編器的輸出與ndisasm的輸出進行比較?顯然,不需要爲disp和imm生成所有可能的值,但所有前綴,所有操作碼(1字節,2字節等),ModR/M和SIB值都是可行的。注意:AFAIR,有AMD 3d!現在的指令,其功能在'imm'操作數編碼,令人驚訝。 –