for 循环中的 Masm DLL 过程
Masm DLL procedure inside for loop
我编写了一个 MASM 程序并将其动态加载到我的 C++ 应用程序中。
我一直在 for 循环中调用它,但在某个时候它只是更改了循环的迭代器并且一切都崩溃了。
循环代码:
for (int i = 0; i < 64; i++){
if (useAsm){
if (0 <= i && i <= 15){//F
F = FFunc(res[1],res[2],res[3]);
g = i;
}
else if (16 <= i && i <= 31){//G
F = GFunc(res[1], res[2], res[3]);
g = ((5 * i + 1) & 0x0F);
}
else if (32 <= i & i <= 47){//H
F = HFunc(res[1], res[2], res[3]);
g = ((3 * i + 5) & 0x0F);
}
else if (48 <= i & i <= 63){//I
F = IFunc(res[1], res[2], res[3]);
g = ((7 * i) & 0x0F);
}
}
}
当我是 24
时,我在 F = GFunc(res[1], res[2], res[3]);
发生变化
这是MASM程序的代码
GFunc proc Bval: DWORD,
Cval: DWORD,
Dval: DWORD
mov eax, Cval
xor eax, Bval
and eax, Dval
xor eax, Cval
ret
FFunc 工作正常所以我真的不明白为什么会这样。
我检查了反汇编:
call dword ptr [GFunc]
add esp,0Ch
add esp,0Ch
似乎以某种方式覆盖了 i ,至少调试器是这么告诉我的。
看起来 C++ 编译器认为您的汇编函数遵循 cdecl calling convention,但您的汇编函数很可能遵循 stdcall 约定。
解决此问题的一种方法是将 GFunc
的声明更改为类似以下内容:
extern DWORD __stdcall GFunc(DWORD, DWORD, DWORD);
我编写了一个 MASM 程序并将其动态加载到我的 C++ 应用程序中。 我一直在 for 循环中调用它,但在某个时候它只是更改了循环的迭代器并且一切都崩溃了。
循环代码:
for (int i = 0; i < 64; i++){
if (useAsm){
if (0 <= i && i <= 15){//F
F = FFunc(res[1],res[2],res[3]);
g = i;
}
else if (16 <= i && i <= 31){//G
F = GFunc(res[1], res[2], res[3]);
g = ((5 * i + 1) & 0x0F);
}
else if (32 <= i & i <= 47){//H
F = HFunc(res[1], res[2], res[3]);
g = ((3 * i + 5) & 0x0F);
}
else if (48 <= i & i <= 63){//I
F = IFunc(res[1], res[2], res[3]);
g = ((7 * i) & 0x0F);
}
}
}
当我是 24
时,我在F = GFunc(res[1], res[2], res[3]);
发生变化
这是MASM程序的代码
GFunc proc Bval: DWORD,
Cval: DWORD,
Dval: DWORD
mov eax, Cval
xor eax, Bval
and eax, Dval
xor eax, Cval
ret
FFunc 工作正常所以我真的不明白为什么会这样。
我检查了反汇编:
call dword ptr [GFunc]
add esp,0Ch
add esp,0Ch
似乎以某种方式覆盖了 i ,至少调试器是这么告诉我的。
看起来 C++ 编译器认为您的汇编函数遵循 cdecl calling convention,但您的汇编函数很可能遵循 stdcall 约定。
解决此问题的一种方法是将 GFunc
的声明更改为类似以下内容:
extern DWORD __stdcall GFunc(DWORD, DWORD, DWORD);