x86 程序集 - GetStdHandle &写控制台 [英] x86 assembly - GetStdHandle & WriteConsole

查看:34
本文介绍了x86 程序集 - GetStdHandle &写控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在回答我关于 Windows API 的问题时,我已经成功地让它工作了.我的问题与此代码有关:

In response to my question about Windows API's, I have successfully gotten it to work. My question is in regards to this code:

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 的值.为什么需要这样做:

This code is supposed to print the value of msg. Why does one need to do:

a)

push STD_OUTPUT_HANDLE
    call GetStdHandle
    push NULL

还有:

b)

push offset other
    push mlen
    push offset msg
    push eax

我只是想知道获取 StdHandle 和推送偏移量需要什么.

I am just wondering what the need is for getting a StdHandle and pushing offsets.

提前致谢,

程序

推荐答案

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

Look at the definition of WriteConsole. The NULL is the last argument of the function, the lpReserved argument. Arguments are pushed in right-to-left order. The first function argument is the console handle, the one you got from GetStdHandle and you pass by pushing 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

这篇关于x86 程序集 - GetStdHandle &写控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆