Process 32bit lấy thông tin peb của process 64bit trên windows x64

,

Chào các ace!
Em cần lấy command line của một windows process đang chạy bằng cách:

BOOL GetCommandLineFromPid(DWORD dwProcessId, LPTSTR szCommandLine, DWORD dwSizeofCmdLine, LPTSTR szCurrentDirectory)
{	
	//
	// khai báo biến và check đầu hàm
	//
	...


	//
	// lấy hàm NtQueryInformationProcess từ thư viện ntdll
	//
	if (g_pfnQueryInformationProcess == NULL)
	{
		g_pfnQueryInformationProcess = (MyNtQueryInformationProcess)GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "NtQueryInformationProcess");
		if (g_pfnQueryInformationProcess == NULL)
		{
			return FALSE;
		}
	}

	hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);
	if (hProcess)
	{
		//
		// lấy địa chỉ peb từ handle process
		//
		status = g_pfnQueryInformationProcess(hProcess, ProcessBasicInformation, &pbi, sizeof(PROCESS_BASIC_INFORMATION), &ulRet);
		if (NT_SUCCESS(status))
		{

			if (pbi.PebBaseAddress)
			{
				pPEB = (PMYPEB)malloc(sizeof(MYPEB) + 10);
				if (pPEB && ReadProcessMemory(hProcess, pbi.PebBaseAddress, pPEB, sizeof(MYPEB), &dwByteRead))
				{
					//
					// doan lay comand line trong nay
					//
					...
			}
		}
		CloseHandle(hProcess);
	}

	return bRet;
}

Vấn đề của em là:

  • Em cần gọi hàm GetCommandLineFromPid từ tiến trình 32bit trên win64bit để lấy commend line của các tiến trình đang chạy khác.
  • Khi gọi hàm GetCommandLineFromPid để lấy command line của tiến trình 32bit thì ok. Nhưng lấy command line của tiến trình 64bit thì lỗi ngay ở chỗ lấy peb. tức là ở đoạn code trên khi QueryInformationProcess thì trả về pbi.PebBaseAddress = NULL.
  • Em tìm kiếm trên mạng thì chưa có cách nào khắc phục được lỗi này.

Ở đây ae có ai làm về lập trình hệ thống windows thì giúp em với ạ? hay có cách nào khác lấy command line khác hơn cách trên không ạ?