在Linux中轻松地检查了英特尔组装运算codeS [英] Checking up Intel assembly opcodes easily in Linux

查看:164
本文介绍了在Linux中轻松地检查了英特尔组装运算codeS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个实用的工具,将打印在任何Linux的英特尔64位或32位的指令,例如的运算codeS。像 邱博士的 在DOS汇编。基于Web的服务将是一个选项了。

因为我无法找到任何,我做我自己的庆典脚本,创建从命令行参数汇编源文件(指令[S]和&lt ; 32/64>),编译,链接和拆卸,并表明拆卸的正确行。但有已经有一些计划,将显示的所有的任何给定的指令可能的编码,例如。为 MOV EAX,EBX ?使用 NASM LD ndisasm 明明只给我的方法一个可能的编码每条指令。

使用这个脚本,我可以得到64位和32位code,使用 NASM 的编码例如:

  /家庭/用户/ code / ASM $ showop'NOP;添加EAX,EBX; CPUID6400000000 90 NOP
00000001 01D8添加EAX,EBX
00000003 0FA2 CPUID

但我怎么能轻易获得所有可能的运算code编码?是否有已经有一些程序可用于?

这里的code:

 #!/斌/庆典#用法:showop说明位asminstr = $ 1
位= $ 16#asminstr =NOP; NOP; NOP; NOP;添加EAX,EBX; NOP; NOP; NOP
#位= 64numberofinstr =`回声$ asminstr | grep的-o; | WC -l`
((numberofinstr ++))如果[-f tempasmfile.asm]
    然后
    RM tempasmfile.asm
科幻
如果[-f tempobjfile.o]
    然后
    RM tempobjfile.o
科幻
如果[-f tempexefile]
    然后
    RM tempexefile
科幻printf的[比特位$] \\ nsection的.text \\ nglobal _start \\ n \\ n_start:\\ $ n`echo asminstr | SED的/; / \\\\ N / g'` \\ n> tempasmfile.asmNASM -f精灵$位tempasmfile.asm -o tempobjfile.o
LD tempobjfile.o -o tempexefile如果[$位-eq 32]
然后
    ndisasm -b $位-e 0x60的tempexefile |头-n $ numberofinstr
ELIF [$位-eq 64]
然后
    ndisasm -b $位-e 0x80的tempexefile |头-n $ numberofinstr
科幻
RM tempasmfile.asm
RM tempobjfile.o
RM tempexefile


解决方案

反汇编器,如 libdisasm udis86 通常会与运codeS的查找表。

udis86还附带了一个命令行工具(udcli),你喂十六进制字节,它给你去codeD版本。

I have been looking for an practical tool that would print the opcodes of any Intel 64-bit or 32-bit instruction in Linux, eg. something like Hiew's assembler in DOS. A web-based service would be one option too.

As I wasn't able to find any, I made my own bash script, that creates an assembly source file from command line parameters (instruction[s] and <32/64>), compiles, links and disassembles it and shows the correct rows of disassembly. But is there already some program that would show all the possible encodings for any given instruction, eg. for mov eax,ebx? My approach using nasm, ld and ndisasm obviously only gives one possible encoding for each instruction.

With this script I can get the encodings used by nasm for 64 and 32-bit code, eg:

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

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

But how could I get easily all the possible opcode encodings? Is there already some program available for that?

Here's the code:

#!/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

解决方案

Disassemblers, like libdisasm and udis86 usually come with a lookup table for opcodes.

udis86 also comes with a command line tool (udcli), which you feed hex bytes and it gives you the decoded version.

这篇关于在Linux中轻松地检查了英特尔组装运算codeS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆