我正在尝试使用以下代码获取 Windows 中正在运行的进程的命令行:但我只得到这样的命令行IDman.exe
:
C:\Program Files (x86)\Internet Download Manager\IDMan.exe" /onboot
但我知道还有许多其他带有命令行的进程。
告诉我我的代码有什么问题。
PVOID GetPebAddress(HANDLE ProcessHandle )
{
_NtQueryInformationProcess NtQueryInformationProcess =
(_NtQueryInformationProcess)GetProcAddress(
GetModuleHandleA("ntdll.dll"), "NtQueryInformationProcess");
PROCESS_BASIC_INFORMATION pbi;
NtQueryInformationProcess(ProcessHandle, 0, &pbi, sizeof(pbi), NULL);
return pbi.PebBaseAddress;
}
void get_process_cmd_line(DWORD pID)
{
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ |
PROCESS_TERMINATE,
FALSE, pID);
PPEB ppeb = (PPEB) GetPebAddress(hProcess);
PPEB ppebCopy = (PPEB)malloc(sizeof(PEB));
BOOL result = ReadProcessMemory(hProcess,
ppeb,
ppebCopy,
sizeof(PEB),
NULL);
if(!result){std::cout<<"Er. adress";return;}
PRTL_USER_PROCESS_PARAMETERS pRtlProcParam = ppebCopy->ProcessParameters;
PRTL_USER_PROCESS_PARAMETERS pRtlProcParamCopy =
(PRTL_USER_PROCESS_PARAMETERS)malloc(sizeof(RTL_USER_PROCESS_PARAMETERS));
result = ReadProcessMemory(hProcess,
pRtlProcParam,
pRtlProcParamCopy,
sizeof(RTL_USER_PROCESS_PARAMETERS),
NULL);
if(!result){std::cout<<"Er. ";return;}
PWSTR wBuffer = pRtlProcParamCopy->CommandLine.Buffer;
USHORT len = pRtlProcParamCopy->CommandLine.Length;
PWSTR wBufferCopy = (PWSTR)malloc(len);
result = ReadProcessMemory(hProcess,
wBuffer,
wBufferCopy,
len,NULL);
if(!result){std::cout<<"Er. cmdLine";return;}
std::wcout<<wBufferCopy;
return;
}