Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Unified Diff: experimental/windows_debugger/debugger/base/debug_utils.cpp

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: experimental/windows_debugger/debugger/base/debug_utils.cpp
diff --git a/experimental/windows_debugger/debugger/base/debug_utils.cpp b/experimental/windows_debugger/debugger/base/debug_utils.cpp
deleted file mode 100644
index 775a5bda2be5960b69b790d666b0fb32cc84fcb7..0000000000000000000000000000000000000000
--- a/experimental/windows_debugger/debugger/base/debug_utils.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-#include "debugger/base/debug_utils.h"
-
-namespace {
-HMODULE sm_LoadNTDLLFunctions();
-typedef NTSTATUS (NTAPI *pfnNtQueryInformationProcess)(
- IN HANDLE ProcessHandle,
- IN PROCESSINFOCLASS ProcessInformationClass,
- OUT PVOID ProcessInformation,
- IN ULONG ProcessInformationLength,
- OUT PULONG ReturnLength OPTIONAL
- );
-pfnNtQueryInformationProcess gNtQueryInformationProcess = 0;
-}
-
-namespace debug {
-bool Utils::GetProcessCmdLine(HANDLE ProcessHandle, std::string* cmd_line) {
- if (!gNtQueryInformationProcess)
- sm_LoadNTDLLFunctions();
-
- if (gNtQueryInformationProcess) {
- PROCESS_BASIC_INFORMATION pbi;
- memset(&pbi, 0, sizeof(pbi));
- ULONG ReturnLength = 0;
- NTSTATUS st = (*gNtQueryInformationProcess)(ProcessHandle, ProcessBasicInformation, &pbi, sizeof(pbi), &ReturnLength);
-
- PEB* peb_addr = (PEB*)pbi.PebBaseAddress;
- PEB peb;
- memset(&peb, 0, sizeof(peb));
-
- SIZE_T sz = 0;
- if (!::ReadProcessMemory(ProcessHandle, peb_addr, &peb, sizeof(peb), &sz))
- return false;
-
-#ifdef _WIN64
- RTL_USER_PROCESS_PARAMETERS* proc_params_addr = peb.ProcessParameters;
- RTL_USER_PROCESS_PARAMETERS proc_params;
- memset(&proc_params, 0, sizeof(proc_params));
- if (!::ReadProcessMemory(ProcessHandle, proc_params_addr, &proc_params, sizeof(proc_params), &sz))
- return false;
-
- *cmd_line = ReadUNICODE_STRING(ProcessHandle, proc_params.CommandLine);
- return true;
-#endif
- }
- return false;
-}
-
-std::string Utils::ReadUNICODE_STRING(HANDLE ProcessHandle, const UNICODE_STRING& str) {
- std::string result;
- if (str.Length > 0) {
- size_t len_in_bytes = 2 * (str.Length + 1);
- wchar_t* w_str = (wchar_t*)malloc(len_in_bytes);
- char* a_str = (char*)malloc(str.Length + 1);
- if ((NULL != w_str) && (NULL != a_str)) {
- SIZE_T sz = 0;
- if (::ReadProcessMemory(ProcessHandle, str.Buffer, w_str, len_in_bytes, &sz)) {
-
- ::WideCharToMultiByte(CP_ACP, 0, w_str, -1, a_str, str.Length, 0, 0);
- a_str[str.Length] = 0;
- result = a_str;
- }
- free(w_str);
- free(a_str);
- }
- }
- return result;
-}
-
-bool Utils::ReadUnucodeStr(HANDLE ProcessHandle, const void* addr_addr, std::string* str) {
- void* addr = 0;
- SIZE_T sz = 0;
- ::ReadProcessMemory(ProcessHandle, addr_addr, &addr, sizeof(addr), &sz);
- if (sz == 0)
- return false;
-
- char utmp[4096];
- ::ReadProcessMemory(ProcessHandle, addr, &utmp, sizeof(utmp), &sz);
- if (sz == 0)
- return false;
-
- char* a_str = (char*)malloc(sz + 1);
- a_str[0] = 0;
- ::WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)utmp, -1, a_str, sz/2, 0, 0);
-
- *str = a_str;
- delete a_str;
- return true;
-}
-
-int Utils::GetProcessorWordSizeInBits(HANDLE h) {
- BOOL is_wow = FALSE;
- if (!::IsWow64Process(h, &is_wow))
- return 0;
- if (is_wow)
- return 32;
-#ifdef _WIN64
- return 64;
-#else
- return 32;
-#endif
- return 0;
-}
-
-bool Utils::GetProcessName(int pid, std::string* name) {
- HANDLE h_snapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- if (INVALID_HANDLE_VALUE == h_snapshot)
- return false;
-
- PROCESSENTRY32 pe = { 0 };
- pe.dwSize = sizeof(PROCESSENTRY32);
-
- bool found = false;
- if (::Process32First(h_snapshot, &pe)) {
- do {
- if (pe.th32ProcessID == pid) {
- *name = pe.szExeFile;
- found = true;
- }
- } while (::Process32Next(h_snapshot, &pe));
- }
- ::CloseHandle(h_snapshot);
- return found;
-}
-} // namespace debug
-
-namespace {
-HMODULE sm_LoadNTDLLFunctions() {
- HMODULE hNtDll = LoadLibrary("ntdll.dll");
- if(hNtDll == NULL) return NULL;
-
- gNtQueryInformationProcess = (pfnNtQueryInformationProcess)GetProcAddress(hNtDll,
- "NtQueryInformationProcess");
- if(gNtQueryInformationProcess == NULL) {
- FreeLibrary(hNtDll);
- return NULL;
- }
- return hNtDll;
-}
-} // namespace
« no previous file with comments | « experimental/windows_debugger/debugger/base/debug_utils.h ('k') | experimental/windows_debugger/debugger/core/debug_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698