2014-03-05 24 views
1

對於實驗室,我需要知道我編寫的十六進制指令。例如我有bang.s將gcc裝配到十六進制

movl 0xaaaaaaaa 0xbbbbbbbb 
push 0xcccccccc 
ret 

現在我想要得到這些指令的十六進制代碼。我如何使用cc和/或objdump來完成此操作?

我已經試過:

objdump -S bang.s 

,但我得到 「文件格式無法識別」

+1

無論你使用什麼彙編程序,它肯定都會有一個列表選項? – TonyK

回答

5

這是我做的。

1. Compile the assembly file. 
2. Disassemble the object file (objdump -d objFile.o > objFile.asm) 

在上面的例子中,它不一定是一個目標文件。它可能是一個可執行文件。

有時候,我只需要知道字節序列或兩條指令。在這種情況下,我使用以下內容。

1. In my .bashrc file (Linux), add the lines ... 

opcode32() { 
    echo $* > tmp.S && gcc -c tmp.S -o tmp.o && objdump -d tmp.o 
    rm -f tmp.o tmp.S 
} 

2. From the command line, use opcode32 'instruction'. For example ... 
     opcode32 'pushl %ecx' 
    This yields the following output ... 

tmp.o:  file format elf32-i386 


Disassembly of section .text: 

00000000 <.text>: 
    0: 51      push %ecx 

希望這會有所幫助。

2

您需要首先編譯(彙編)您的.s文件,然後在生成的.o文件上運行objdump。

CC或GCC通常知道如何建立彙編文件,所以:

cc -c bang.s 
objdump -d bang.o 

(Ofcourse,你dump.s必須是有效的組件,所以你可以建造它,你張貼在這裏是不是)