簡體   English   中英

NASM x86程序集中的GetModuleFileName

[英]GetModuleFileName in NASM x86 assembly

這是代碼...

extern GetStdHandle
extern GetModuleFileNameW
extern WriteFile
extern ExitProcess

import GetStdHandle kernel32.dll
import GetModuleFileNameW kernel32.dll
import WriteFile kernel32.dll
import ExitProcess kernel32.dll

global ..start

segment .code USE32

..start:

push dword -11
call [GetStdHandle]
mov dword [hStdOut], eax

;Getting the filepath of exe on disk...
push dword 256 ;MAX_PATH
push dword [filepath] ;Pointer to the buffer
push dword 0 ;NULL
call [GetModuleFileNameW]

;Trying to output the filepath...
push dword 0
push dword nBytes
push dword 256 ;MAX_PATH
push dword filepath
push dword [hStdOut]
call [WriteFile]

xor eax, eax
push eax
call [ExitProcess]

segment .data

segment .bss
hStdOut resd 1
nBytes resd 1
filepath resd 32

我玩了一點,得到的只是空白輸出。 當我玩弄它時,我也變得一團糟。 仍然沒有文件路徑,也沒有喜悅。 我有一種直覺,就是我使用GetModuleFileNameW做錯了什么,但是我不確定。 我按照Microsoft網站上的文檔進行操作,並按照相反的順序將參數放在了匯編語言中,就像您應該使用的那樣。 我究竟做錯了什么?

;Getting the filepath of exe on disk...
push dword 256 ;MAX_PATH
push dword [filepath] ;Pointer to the buffer
push dword 0 ;NULL
call [GetModuleFileNameW]

...必須更改為...

;Getting the filepath of exe on disk...
push dword 256 ;MAX_PATH
push dword filepath ;Pointer to the buffer
push dword 0 ;NULL
call [GetModuleFileNameW]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM