我需要找到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);
答案 0 :(得分:0)
为什么需要使用PEB?您是否查看了argv
的内容?
在你的代码中,(对我而言)可怕的commandLine.Length / 2
是什么......?
答案 1 :(得分:0)
使用VC2010在Windows 7上运行正常。 printf
可能被定义为wprintf
,它将%S视为ANSI字符串。这是一个很长的镜头,因为这也会导致它抱怨格式字符串是非Unicode。尝试使用MessageBoxW输出字符串,以确保您将所有内容都视为Unicode。
顺便说一句,当你从自己的过程中读取时,你不需要使用ReadProcessMemory。