おはよう!私はすべての現在実行中のアプリケーションをリストし、masmを使ってそれをテキストファイルに書き込もうとしています。私はアセンブリでは新しいですが、参照としてMSDNを使用しています。これまでは、CreateFile、WriteFile、ReadFileなどを使用する方法を知っていましたが、Process32Firstの仕組みはわかりません。実行中のアプリケーションの一覧表示MASM32アセンブリ
私はこのリンクのコードをMASM(https://msdn.microsoft.com/en-us/library/windows/desktop/ms686701(v=vs.85).aspx)に変換しようとしていますが、運がないため出力が得られません。
本当に助けてもらえますか?ありがとうございました!良い一日を。
include \masm32\include\masm32rt.inc
.data
pe32 PROCESSENTRY32 <>
errorCreateTool db "ERROR: CreateToolhelp32Snapshot", 0
errorPF db "ERROR: Process32First", 0
errorOP db "ERROR: OpenProcess", 0
yesMsg db "proceed", 0
.data?
dwPriorityClass dd ?
hProcessSnap HANDLE ?
hProcess HANDLE ?
.code
_start:
push 0
push TH32CS_SNAPPROCESS
call CreateToolhelp32Snapshot
mov hProcessSnap, eax
cmp hProcessSnap, INVALID_HANDLE_VALUE
je _errorCT
mov pe32.dwSize, sizeof PROCESSENTRY32
push offset pe32
push hProcessSnap
call Process32FirstW
cmp eax, ERROR_NO_MORE_FILES
je _errorPF
push offset pe32.szExeFile
call StdOut
mov dwPriorityClass, 0
push offset pe32.th32ProcessID
push FALSE
push PROCESS_ALL_ACCESS
call OpenProcess
cmp eax, 00H ;if I comment this out, the code will proceed
je _errorOpen
push offset pe32.th32ProcessID ;but this doesn't have any value and doesn't print out
call StdOut
push offset yesMsg ;while this prints out on the console
call StdOut
jmp _done
_errorOpen:
push offset errorOP
call StdOut
jmp _done
_errorPF:
push offset errorPF
call StdOut
jmp _done
_errorCT:
push offset errorCreateTool
call StdOut
_done:
push 0
call ExitProcess
end _start
'StdOut'はゼロ終端の_文字列を出力します。 'pe32.th32ProcessID'は文字列ではありません。 (btw、あなたは 'Process32First'のユニコード版がほしいですか?) – Michael
こんにちはマイケル!コメントありがとうございました。私はth32ProcessIDを取得する必要はないことに気付きました。私が必要とするのはexeファイル名だけです。私がやったのは、Process32FirstをProcess32Firstに変更し、Process32NextWをProcess32Nextに変更することでした(kernel32.incとkernel32p.inc)。手がかりをありがとう! :) – fortress