【问题标题】:Listing all running applications MASM32 Assembly列出所有正在运行的应用程序 MASM32 程序集
【发布时间】:2017-06-01 09:48:22
【问题描述】:

美好的一天!我一直在尝试列出所有当前正在运行的应用程序并使用 masm 将其写入文本文件。我是组装新手,但使用 MSDN 作为我的参考。到目前为止,我知道如何使用 CreateFile、WriteFile、ReadFile 等,但我不明白 Process32First 的工作原理。

我正在尝试将此链接中的代码转换为 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 不是字符串。 (顺便说一句,你确定你想要Process32First 的unicode 版本吗?)
  • 嗨,迈克尔!谢谢你的意见。我刚刚意识到我不需要获取 th32ProcessID。我需要的只是 exe 文件名,它现在可以工作了。我所做的只是将 kernel32.inc 和 kernel32p.inc 中的 Process32FirstW 更改为 Process32First,将 Process32NextW 更改为 Process32Next。谢谢你的线索! :)

标签: c++ assembly masm msdn masm32


【解决方案1】:

我体验过使用该功能。我所要做的就是按照您的建议更新我的 kernel32.inc 和 kernel32p.inc。完成这些操作后,我在 masm32 文件夹中运行 makelibs.bat,它从那里开始工作。

【讨论】:

  • 是的!我也是这样做的。不管怎样,谢谢你。 :)
  • 别这样!如果您在处理一个拙劣的文件时遇到麻烦,没有人可以帮助您。我找不到 Process32First(ANSI 版本 - 没有 Process32FirstA)和 Process32Next 失败的 MASM32 版本。报告的错误适用于 Unicode。而是获取newest MASM32 SDK 并安装它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-04
  • 2015-10-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-27
  • 1970-01-01
相关资源
最近更新 更多