【发布时间】:2017-05-31 04:11:19
【问题描述】:
我一直在尝试读取写入 .txt 文件中的字符串并在控制台上打印出来。但似乎我做得不对。有人可以查看我的代码并告诉我出了什么问题吗?谢谢!
include \masm32\include\masm32rt.inc
.data
txtFilter db "*.txt",0
txtFD WIN32_FIND_DATA <>
txtHandle HANDLE ?
fHandle HANDLE ?
bufferLength db ?
buffer db 5000 dup(?)
lnt db "1024",0
okay db "Okay!",0
dokay db "Dokay!",0
.code
start:
push offset txtFD
push offset txtFilter
call FindFirstFile
mov txtHandle, eax
push offset txtFD.cFileName
call StdOut
push 0
push FILE_ATTRIBUTE_NORMAL
push OPEN_EXISTING
push 0
push 0
push FILE_APPEND_DATA
push offset txtFD.cFileName
call CreateFile
.if eax == INVALID_HANDLE_VALUE
jmp _error
.else
mov fHandle, eax
.endif
push 0
push offset bufferLength
push offset lnt
push offset buffer
push fHandle
call ReadFile
jmp _next
_error:
push offset dokay
call StdOut
jmp _next
_okay:
push offset okay
call StdOut
_next:
push offset buffer
call StdOut
push fHandle
call CloseHandle
push txtHandle
call FindClose
push 0
call ExitProcess
end start
代码似乎无法读取我的 txt 文件中的内容。但是我可以成功搜索我的 txt 文件并执行函数 CreateFile
【问题讨论】:
-
当您调用 ReadFile 时,您推送的是
offset lnt而不仅仅是lnt。nNumberOfBytesToRead参数按值传递,而不是按地址传递。 -
我也怀疑你必须提供长度
lnt作为 ascii 字符串。我会尝试'lnt dd 1024'
标签: windows assembly command-line x86 masm32