gpt4 book ai didi

assembly - gcc 汇编到十六进制

转载 作者:行者123 更新时间:2023-12-05 08:43:51 24 4
gpt4 key购买 nike

对于实验室,我需要知道我编写的十六进制汇编指令。例如我有 bang.s:

movl 0xaaaaaaaa 0xbbbbbbbb
push 0xcccccccc
ret

现在我想获取这些指令的十六进制代码。我如何使用 cc 和/或 objdump 来完成此操作?

我试过:

objdump -S bang.s

但我得到“文件格式无法识别”

最佳答案

这是我的做法。

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

希望这对您有所帮助。

关于assembly - gcc 汇编到十六进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22208473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com