[Win32]一個偵錯程式的實現(二)除錯事件的處理
阿新 • • 發佈:2018-12-27
1 void OnOutputDebugString(const OUTPUT_DEBUG_STRING_INFO* pInfo) {
2 3 BYTE* pBuffer = (BYTE*)malloc(pInfo->nDebugStringLength);
4 5 SIZE_T bytesRead;
6 7 ReadProcessMemory(
8 g_hProcess,
9 pInfo->lpDebugStringData,
10 pBuffer,
11 pInfo->nDebugStringLength,
12 &bytesRead);
13 14 int requireLen = MultiByteToWideChar(
15 CP_ACP,
16 MB_PRECOMPOSED,
17 (LPCSTR)pBuffer,
18 pInfo->nDebugStringLength,
19 NULL,
20 0);
21 22 TCHAR* pWideStr = (TCHAR*)malloc(requireLen *sizeof(TCHAR));
23 24 MultiByteToWideChar(
25 CP_ACP,
26 MB_PRECOMPOSED,
27 (LPCSTR)pBuffer,
28 pInfo->nDebugStringLength,
29 pWideStr,
30 requireLen);
31 32 std::wcout << TEXT("Debuggee debug string: ") << pWideStr << std::endl;
33 34 free(pWideStr);
35 free(pBuffer);
36 }
2 3 BYTE* pBuffer = (BYTE*)malloc(pInfo->nDebugStringLength);
4 5 SIZE_T bytesRead;
6 7 ReadProcessMemory(
8 g_hProcess,
9 pInfo->lpDebugStringData,
10 pBuffer,
11 pInfo->nDebugStringLength,
13 14 int requireLen = MultiByteToWideChar(
15 CP_ACP,
16 MB_PRECOMPOSED,
17 (LPCSTR)pBuffer,
18 pInfo->nDebugStringLength,
19 NULL,
20 0);
21 22 TCHAR* pWideStr = (TCHAR*)malloc(requireLen *sizeof(TCHAR));
23 24 MultiByteToWideChar(
25 CP_ACP,
27 (LPCSTR)pBuffer,
28 pInfo->nDebugStringLength,
29 pWideStr,
30 requireLen);
31 32 std::wcout << TEXT("Debuggee debug string: ") << pWideStr << std::endl;
33 34 free(pWideStr);
35 free(pBuffer);
36 }