gpt4 book ai didi

c - 将十六进制操作码解码为 asm 或在 __asm 中运行十六进制?

转载 作者:太空宇宙 更新时间:2023-11-04 00:31:27 27 4
gpt4 key购买 nike

Visual Studio 2010(或 Windows 上的其他工具)是否有任何方法可以采用十六进制操作码指令,例如

EB D2

并“解码”或以其他方式将它们翻译成人类可读的 asm?

或者,有没有办法直接在 __asm block 中运行十六进制指令?

最佳答案

因为您提到了 Visual Studio,我假设您正在寻找内部工具,或者您可能正在使用 MASM。 NASM 有自己的反汇编器,但它的语法与 MASM 的不同。

有一个我知道的老把戏,至少在几年前用过。您可以像这样将字符串转换为 C 中的函数:

/*
* Illustration of executing machine code as a C string. Works on an
* IA-32 processor.
*/

#include <stdio.h>

int (*f)() = "\xb0\x64\x0f\xb6\xc0\xc3";

int main() {
printf("%d\n", f());
return 0;
}

这里函数 f 将值 100 移入 eax 寄存器并返回它(C3 是返回的操作码)。不确定这是否适用于 Visual Studio 的 C 方言,如果您使用的是 64 位处理器,则可能必须更新它。它确实为 __asm block 提供了一个有趣的替代方案。

附录

该程序在运行 Mountain Lion 的 MacBook Pro 上仍然可以正常运行:

$ cat hundred.c 
#include <stdio.h>

int (*f)() = "\xb0\x64\x0f\xb6\xc0\xc3";

int main() {
printf("%d\n", f());
return 0;
}

$ gcc hundred.c && ./a.out
hundred.c:3: warning: initialization from incompatible pointer type
100

正如在下面的评论中所指出的,如果字符串位于 O.S. 的段中,则这种解决方案将不起作用。将不允许执行。

关于c - 将十六进制操作码解码为 asm 或在 __asm 中运行十六进制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14074040/

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