列出所有运行的应用程序MASM32组件

Listing all running applications MASM32 Assembly

本文关键字:应用程序 MASM32 组件 运行      更新时间:2023-10-16

美好的一天!我一直在尝试列出当前运行的所有应用程序,并使用MASM将其写入文本文件。我是汇编的新手,但正在使用MSDN作为我的参考。到目前为止,我知道如何使用createfile,writefile,readfile等

我正在尝试将此链接中的代码转换为MASM,(https://msdn.microsoft.com/en-us/library/windows/desktop/mss686701(v=vs.85(没有运气,我无法获得任何输出。

我将非常感谢任何帮助!谢谢你!祝你有美好的一天。

include masm32includemasm32rt.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

我使用该功能经历了。我所要做的就是您所建议的是我的kernel32.inc和kernel32p.inc。完成这些操作后,我在MASM32文件夹中运行makelibs.bat,从那里起作用。