繁体   English   中英

x86程序集 - GetStdHandle和WriteConsole

[英]x86 assembly - GetStdHandle & WriteConsole

在回答我关于Windows API的问题时,我已经成功地使用了它。 我的问题是关于这段代码:

push STD_OUTPUT_HANDLE
    call GetStdHandle
    push NULL
    push offset other
    push mlen
    push offset msg
    push eax
    call WriteConsole
push    0
call ExitProcess

此代码应该打印msg的值。 为什么需要做:

一种)

push STD_OUTPUT_HANDLE
    call GetStdHandle
    push NULL

和:

b)

push offset other
    push mlen
    push offset msg
    push eax

我只是想知道需要什么来获得StdHandle并推动抵消。

提前致谢,

Progrmr

看看WriteConsole定义 NULL是函数的最后一个参数,即lpReserved参数。 参数按从右到左的顺序推送。 第一个函数参数是控制台句柄,你从GetStdHandle得到的那个,你通过推送eax传递。

所以正确评论汇编代码:

push STD_OUTPUT_HANDLE          ; GetStdHandle nStdHandle argument
call GetStdHandle               ; eax = Console handle
push NULL                       ; lpReserved = null
push offset other               ; lpNumberOfCharsWritten = pointer to "other"
push mlen                       ; nNumberOfCharsToWrite = length of "msg"
push offset msg                 ; lpBuffer = pointer to "msg"
push eax                        ; hConsoleOutput = console handle from GetStdHandle
call WriteConsole               ; Write string
push    0                       ; exit code = 0
call ExitProcess                ; terminate program

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM