如何使用 WinApi 的 WriteConsole 打印 LOCAL 字节

问题描述

我很难澄清我的问题,但我会努力。我正在尝试学习 MASM32,我的任务是在控制台中打印一些文本而不使用 .data 或 .const。问题是 LOCAL 将变量放在堆栈上,而不是放在静态内存中。所以我无法获得它们的地址(偏移量),并且 WriteConsole 使用指向内存中文本地址的指针。关于如何处理这个问题的任何想法?谢谢! 我有这个:

.data
string db 10 'somestring'

.code
WritetoConsole PROC 
    LOCAL handle :DWORD
    invoke GetStdHandle,-11
    mov handle,eax
    mov edx,offset string
    invoke WriteConsoleA,handle,edx,10,0
    xor eax,eax
    ret
WritetoConsole ENDP

我想要这样的东西:

.code
WritetoConsole PROC 
    LOCAL string[10] :SBYTE
    LOCAL handle :DWORD
    invoke GetStdHandle,offset string ;impossible because of stack
    invoke WriteConsoleA,0 ;can't call without a pointer
    xor eax,eax
    ret
WritetoConsole ENDP```

解决方法

好吧,我找到了答案:

 LOCAL string[10] :DWORD
 lea edx,string
 invoke WriteConsoleA,handle,edx,stringlength,0

加载有效地址而不是偏移量有帮助!