C++ ASM Inline如何使用布尔值?

发布于 2024-12-28 18:32:07 字数 842 浏览 0 评论 0原文

假设我得到了这样的东西..

bool isPatched;

我还有一些其他的 GUI,我在其中设置了 isPatched= true;isPatched= false;, isPatched = !isPatched;< /code>

void __declspec( naked ) test(void) { //
    __asm {
        PUSHAD
        PUSHFD

        MOV EAX, isPatched
        CMP EAX, 0
        je noPatched
            MOV EAX, DWORD PTR DS:[ESI+0x77C]
            MOV John.oldA, EAX
            MOV EAX, John.A
            MOV DWORD PTR DS:[ESI+0x77C], EAX
            JMP finish
noPatched:
            PUSH EDX
            MOV DWORD PTR DS:[ESI+0x77C], EDX
        finish:
        POPFD
        POPAD

        JMP gotoAddressBack

    }
}

是否可以在内联汇编中使用 bool 运算符?

我认为它认为 isPatched 是一个标签..来自这个错误消息。 错误 C2094:标签“isPatched”未定义

Say I got something like this..

bool isPatched;

I have a few other GUI's where I set isPatched= true; and isPatched= false;, isPatched = !isPatched;

void __declspec( naked ) test(void) { //
    __asm {
        PUSHAD
        PUSHFD

        MOV EAX, isPatched
        CMP EAX, 0
        je noPatched
            MOV EAX, DWORD PTR DS:[ESI+0x77C]
            MOV John.oldA, EAX
            MOV EAX, John.A
            MOV DWORD PTR DS:[ESI+0x77C], EAX
            JMP finish
noPatched:
            PUSH EDX
            MOV DWORD PTR DS:[ESI+0x77C], EDX
        finish:
        POPFD
        POPAD

        JMP gotoAddressBack

    }
}

Is it possible to use bool operator in inline assembly?

I think it thinks isPatched is a label.. from this error message.
error C2094: label 'isPatched' was undefined

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与之呼应 2025-01-04 18:32:07

您想要TESTCMP。在这种情况下,TEST 是最简单的:

XOR EAX,EAX
MOV AL,isPatched //isPatched would be a byte, hence we need correct operand sizes
TEST EAX,EAX
JE NotSet
Set:
//handle true case
JMP End
NotSet:
//handle false case
End:
//continue

根据其他情况,您还可以使用 SUBSETccMOVcc


问题是作用域之一,isPatched 在 ASM 使用时不在作用域内,因此它假定它是一个 DWORD,然后无法找到内存标签(符号名称)在生成地址时为其指定。您还需要为 bool 使用正确的操作数大小。

MSVC 的肮脏小测试,

bool b = true;
int __declspec( naked ) test(void) {
    __asm {
        xor eax,eax
        MOV al, b
        TEST eax,eax
        JE NotSet
        mov eax,1
NotSet:
        RETN

    }
}

int _tmain(int argc, _TCHAR* argv[])
{
    printf("%d\n", test());
    system("pause");
    return 0;
}

btrue 时输出 1,当 bfalse 时输出 0。

You want to TEST or CMP. TEST is the easiest in this case:

XOR EAX,EAX
MOV AL,isPatched //isPatched would be a byte, hence we need correct operand sizes
TEST EAX,EAX
JE NotSet
Set:
//handle true case
JMP End
NotSet:
//handle false case
End:
//continue

Depending on other cases you can also use SUB, SETcc or MOVcc


Your issue is one of scoping, isPatched is not in scope when used by the ASM, so it assumes it to be a DWORD, and then fails to find a memory label (the symbol name) for it when generating the addresses. You also need to use the correct operand size for bool as well.

A dirty litte test for MSVC

bool b = true;
int __declspec( naked ) test(void) {
    __asm {
        xor eax,eax
        MOV al, b
        TEST eax,eax
        JE NotSet
        mov eax,1
NotSet:
        RETN

    }
}

int _tmain(int argc, _TCHAR* argv[])
{
    printf("%d\n", test());
    system("pause");
    return 0;
}

this outputs 1 when b is true, or 0 when b is false.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文