用PEB找到程序的命令行?
问题描述:
我需要用PEB找到程序的命令行。用PEB找到程序的命令行?
我用FS:[的0x30]找到PEB
int wmain(int argc, WCHAR *argv[])
{
PVOID pebAddress =(void *) __readfsdword(0x30); /* get the PEB address */
PVOID rtlUserProcParamsAddress;
ReadProcessMemory(GetCurrentProcess(),(PCHAR)pebAddress+ 0x10,
&rtlUserProcParamsAddress, /* we'll just read directly into our variable */
sizeof(PVOID),
NULL
);
UNICODE_STRING commandLine;
ReadProcessMemory(GetCurrentProcess(), (PCHAR)rtlUserProcParamsAddress + 0x40,&commandLine, sizeof(commandLine), NULL);
WCHAR * commandLineContents;
commandLineContents = (WCHAR *)malloc(commandLine.Length);
ReadProcessMemory(GetCurrentProcess(), commandLine.Buffer,commandLineContents, commandLine.Length, NULL);
printf("%.*S\n", commandLine.Length/2, commandLineContents);
}
,但它不工作。我只需要使用PEB而不是GetCommandLine(void);
答
为什么你需要使用PEB?你有没有看过argv
的内容?
什么是(对我)可怕的看你commandLine.Length/2
...?
答
适用于Windows 7的VC2010。 printf
可能被定义为wprintf
,它将%S视为ANSI字符串。这是一个长镜头,因为这也会导致它抱怨格式字符串是非Unicode的。尝试使用MessageBoxW输出字符串以确保您将所有内容都视为Unicode。
顺便说一句,当你从自己的过程中读取时,不需要使用ReadProcessMemory。 “
”“顺便说一句,当你从自己的过程中读取时,不需要使用ReadProcessMemory。”“怎么样? – maysam 2010-11-15 09:32:09
您从__readfsdword获得的地址位于您自己的过程中。只要把它当作一个指针和取消引用/ memcpy。 PUNICODE_STRING cl =(PUNICODE_STRING)((*(LPBYTE *)((LPBYTE)__ readfsdword(0x30)+ 0x10))+ 0x40);' – kichik 2010-11-15 09:42:34