在汇编中注册ClassEx

发布于 2024-09-29 11:28:20 字数 133 浏览 0 评论 0原文

我正在尝试手动调用 RegisterClassEx Windows API,而不在 .data 部分使用 WNDCLASS 结构,我需要仅使用 push 指令创建此结构。

有人可以帮我吗?

多谢

I'm trying to manually call RegisterClassEx Windows API without using a WNDCLASS structure on .data section, I need to create this structure only using push instruction.

Could someone help me on that please?

Thanks a lot

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

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

发布评论

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

评论(3

烟─花易冷 2024-10-06 11:28:20

事实上,您可以轻松地做您想做的事。您只需要小心地正确计算结构中每个元素的地址即可。但这也是一个简单的任务...;)

请查看我所做的代码:

WinMain:
    push ebp
    mov ebp, esp
    add esp, -50h

    push 7F00h
    push 0h
    call LoadIconA

    mov ebx, eax

    push 7F00h
    push 0h
    call LoadCursorA
    ;eax = return of LoadCursorA
    ;ebx = return of LoadIconA

    mov dword ptr ss:[ebp-30h], 30h                 ;WNDCLASSEX.cbSize,           dd    WNDCLASSEX_size
    mov dword ptr ss:[ebp-2Ch], 3h                  ;WNDCLASSEX.style,            dd    CS_VREDRAW + CS_HREDRAW
    mov dword ptr ss:[ebp-28h], WndProc             ;WNDCLASSEX.lpfnWndProc,      dd    WndProc
    mov dword ptr ss:[ebp-24h], 0h                  ;WNDCLASSEX.cbClsExtra,       dd    NULL
    mov dword ptr ss:[ebp-20h], 0h                  ;WNDCLASSEX.cbWndExtra,       dd    NULL
    mov dword ptr ss:[ebp-1Ch], 0h                  ;WNDCLASSEX.hInstance,        dd    NULL
    mov dword ptr ss:[ebp-18h], ebx                 ;WNDCLASSEX.hIcon,            dd    return of LoadIconA
    mov dword ptr ss:[ebp-14h], eax                 ;WNDCLASSEX.hIconSm,          dd    return of LoadCursorA
    mov dword ptr ss:[ebp-10h], 06h                 ;WNDCLASSEX.hbrBackground,    dd    COLOR_BTNFACE + 1
    mov dword ptr ss:[ebp-0Ch], 0h                  ;WNDCLASSEX.lpszMenuName,     dd    NULL
    mov dword ptr ss:[ebp-08h], offset WndProc      ;WNDCLASSEX.lpszClassName,    dd    offset of ClassName
    mov dword ptr ss:[ebp-04h], ebx                 ;WNDCLASSEX.hCursor,          dd    return of LoadIconA

    lea eax,[ebp-30h]
    push eax
    call RegisterClassEx

您只需要把它放在调用 CreateWindow 之前。

有任何疑问就喊吧。

PS.:记住 WndProc 是汇编程序的循环过程

In fact you can easily do what you want. You just need to be careful to correctly calculate the addresses of each element of the structure. But this is also an easy task... ;)

Please check out the code I did:

WinMain:
    push ebp
    mov ebp, esp
    add esp, -50h

    push 7F00h
    push 0h
    call LoadIconA

    mov ebx, eax

    push 7F00h
    push 0h
    call LoadCursorA
    ;eax = return of LoadCursorA
    ;ebx = return of LoadIconA

    mov dword ptr ss:[ebp-30h], 30h                 ;WNDCLASSEX.cbSize,           dd    WNDCLASSEX_size
    mov dword ptr ss:[ebp-2Ch], 3h                  ;WNDCLASSEX.style,            dd    CS_VREDRAW + CS_HREDRAW
    mov dword ptr ss:[ebp-28h], WndProc             ;WNDCLASSEX.lpfnWndProc,      dd    WndProc
    mov dword ptr ss:[ebp-24h], 0h                  ;WNDCLASSEX.cbClsExtra,       dd    NULL
    mov dword ptr ss:[ebp-20h], 0h                  ;WNDCLASSEX.cbWndExtra,       dd    NULL
    mov dword ptr ss:[ebp-1Ch], 0h                  ;WNDCLASSEX.hInstance,        dd    NULL
    mov dword ptr ss:[ebp-18h], ebx                 ;WNDCLASSEX.hIcon,            dd    return of LoadIconA
    mov dword ptr ss:[ebp-14h], eax                 ;WNDCLASSEX.hIconSm,          dd    return of LoadCursorA
    mov dword ptr ss:[ebp-10h], 06h                 ;WNDCLASSEX.hbrBackground,    dd    COLOR_BTNFACE + 1
    mov dword ptr ss:[ebp-0Ch], 0h                  ;WNDCLASSEX.lpszMenuName,     dd    NULL
    mov dword ptr ss:[ebp-08h], offset WndProc      ;WNDCLASSEX.lpszClassName,    dd    offset of ClassName
    mov dword ptr ss:[ebp-04h], ebx                 ;WNDCLASSEX.hCursor,          dd    return of LoadIconA

    lea eax,[ebp-30h]
    push eax
    call RegisterClassEx

You just need to put this before the call to CreateWindow.

Any doubt just shout.

PS.: Remember that WndProc is the loop procedure of your Assembly program

写给空气的情书 2024-10-06 11:28:20
.data 
    wndclass WNDCLASS
.code
    push offset wndclass
    call RegisterClassEx 

您应该推送其偏移量,而不是结构本身

对于局部变量,推送其地址

 LOCAL wndclass:WNDCLASS
 lea edx, wndclass
 push edx
 call RegisterClassEx 
.data 
    wndclass WNDCLASS
.code
    push offset wndclass
    call RegisterClassEx 

You should push its offset, not structure itself

For local variable, push its address

 LOCAL wndclass:WNDCLASS
 lea edx, wndclass
 push edx
 call RegisterClassEx 
自我难过 2024-10-06 11:28:20

反转push结构体入栈,push有效地址到第一项,调用RegisterClassEx,pop堆栈外的结构。

Reverse push the structure to the stack, push the effective address to the first item, call RegisterClassEx, pop the structure off the stack.

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