【发布时间】:2019-01-26 17:37:28
【问题描述】:
我正在尝试将用 AT&T 语法编写的程序集从 DevC++ 项目转换为 Visual Studio 中的内联程序集。
这是我要转换的 AT&T:
void Painter::drawRectangle(int surface, int x, int y, int width, int height, int red, int green, int blue) {
asm("mov %0, %%eax":: "r" (0x004EAA90));
asm("call *%eax");
asm("mov %eax, %ecx");
asm("mov (%ecx), %eax");
asm("push %0":: "m" (blue));
asm("push %0":: "m" (green));
asm("push %0":: "m" (red));
asm("push %0":: "m" (height));
asm("push %0":: "m" (width));
asm("push %0":: "m" (y));
asm("push %0":: "m" (x));
asm("push %0":: "m" (surface));
asm("call *0x14(%eax)");
}
到目前为止我做了什么:
void _drawrectangle(int surface, int x, int y, int width, int height, int red, int green, int blue)
{
__asm
{
mov eax, 0x004eaa90
call dword ptr [eax]
mov ecx, eax
mov eax, [ecx]
push blue
push green
push red
push height
push width
push y
push x
push surface
call dword ptr [eax + 0x14]
}
}
我在我的 DLL 中编写这个,我已经将它注入到游戏中。游戏一打开就崩溃。而且我已经在 C++ 中使用了另一个绘图函数,它起作用了。
希望你能帮助我/引导我朝着正确的方向前进。谢谢。
【问题讨论】:
-
mov eax, ecx应该是mov eax, [ecx]。为什么要颠倒参数推送的顺序? -
在任何情况下看起来只是两个函数调用,为什么你需要汇编呢?
-
你也不应该使用内联汇编。只需使用普通汇编,那么您不必担心第一个示例中的代码会因为您使用的内联汇编代码是错误的而损坏。或者就像 Jester 所说的,普通的 C++ 也可以。
-
@500-InternalServerError Ops,测试后忘记切换命令。
-
原始代码已经损坏,除非你很幸运并使用
-fno-omit-frame-pointer进行编译,因为你在不告诉编译器的情况下操纵了堆栈指针。
标签: visual-studio assembly inline-assembly att dll-injection