我试图得到一个进程环境字符串,下面的代码是我已经写好的。
#include <windows.h>
#include <tchar.h>
#define ProcessBasicInformation 0
typedef struct _PROCESS_BASIC_INFORMATION {
NTSTATUS ExitStatus;
PVOID PebBaseAddress;
ULONG_PTR AffinityMask;
LONG BasePriority;
HANDLE UniqueProcessId;
HANDLE InheritedFromUniqueProcessId;
} PROCESS_BASIC_INFORMATION, *PPROCESS_BASIC_INFORMATION;
int _tmain(int argc, TCHAR* argv[]) {
TCHAR *app;
DWORD pid;
HANDLE proc;
NTSTATUS nts;
PVOID rupp; // RTL_USER_PROCESS_PARAMETERS, offset 0x10
PVOID env; // Environment, offset 0x48
TCHAR *buf;
PROCESS_BASIC_INFORMATION pbi;
MEMORY_BASIC_INFORMATION mbi;
if (argc != 2) {
app = _tcsrchr(argv[0], '\\');
_tprintf(TEXT("Usage: %s [PID]\n"), app ? ++app : argv[0]);
return -1;
}
_stscanf_s(argv[1], TEXT("%lu"), &pid);
if (!(proc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid))) {
return -1;
}
if (!(nts = NtQueryInformationProcess(
proc, ProcessBasicInformation, &pbi, sizeof(pbi), NULL
))) {
if (ReadProcessMemory(
proc, (PCHAR)pbi.PebBaseAddress + 0x10, &rupp, sizeof(rupp), NULL
)) {
if (ReadProcessMemory(proc, (PCHAR)rupp + 0x48, &env, sizeof(env), NULL)) {
//what I need to do to get enironment strings?
}
}
}
CloseHandle(proc);
return 0;
}
有人能解释一下我需要做些什么来获取进程的环境字符串吗?
1条答案
按热度按时间t9aqgxwy1#
首先,您代码只用于x86,但是x64系统如何?在x64上,您必须从x64代码运行以访问x64进程的环境。但是Wow 64进程如何?它们有2个环境!1个naive和1个Wow,这不是相等的字符串。因此,任务可能足够复杂。但是,当然存在解决方案。