2010-11-15 95 views
1

我需要用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);

回答

0

爲什麼你需要使用PEB?你有沒有看過argv的內容?

什麼是(對我)可怕的看你commandLine.Length/2 ...?

0

適用於Windows 7的VC2010。 printf可能被定義爲wprintf,它將%S視爲ANSI字符串。這是一個長鏡頭,因爲這也會導致它抱怨格式字符串是非Unicode的。嘗試使用MessageBoxW輸出字符串以確保您將所有內容都視爲Unicode。

順便說一句,當你從自己的過程中讀取時,不需要使用ReadProcessMemory。 「

+0

」「順便說一句,當你從自己的過程中讀取時,不需要使用ReadProcessMemory。」「怎麼樣? – maysam 2010-11-15 09:32:09

+0

您從__readfsdword獲得的地址位於您自己的過程中。只要把它當作一個指針和取消引用/ memcpy。 PUNICODE_STRING cl =(PUNICODE_STRING)((*(LPBYTE *)((LPBYTE)__ readfsdword(0x30)+ 0x10))+ 0x40);' – kichik 2010-11-15 09:42:34