diff --git a/Windows/debugger.cpp b/Windows/debugger.cpp index 1c72773..cfc83f3 100644 --- a/Windows/debugger.cpp +++ b/Windows/debugger.cpp @@ -1742,8 +1742,6 @@ DebuggerStatus Debugger::Attach(unsigned int pid, uint32_t timeout) { if (!DebugActiveProcess(pid)) { DWORD error_code = GetLastError(); - - if(error_code == 5) { HANDLE hToken = NULL; LUID luid; @@ -1822,7 +1820,7 @@ DebuggerStatus Debugger::Continue(uint32_t timeout) { return dbg_last_status; } - + // initializes options from command line void Debugger::Init(int argc, char **argv) { have_thread_context = false; diff --git a/Windows/debugger.h b/Windows/debugger.h index c0cc4c2..6604b8e 100644 --- a/Windows/debugger.h +++ b/Windows/debugger.h @@ -76,7 +76,7 @@ class Debugger { Exception GetLastException() { return last_exception; } - + protected: enum MemoryProtection { diff --git a/common.cpp b/common.cpp index 02a3131..6cf08fe 100755 --- a/common.cpp +++ b/common.cpp @@ -20,6 +20,13 @@ limitations under the License. #include #include "common.h" +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) + #include +#endif +#include +#include +#include +#include uint64_t GetCurTime(void) { auto duration = std::chrono::system_clock::now().time_since_epoch(); @@ -96,6 +103,27 @@ int GetIntOption(const char *name, int argc, char** argv, int default_value) { return (int)strtol(option, NULL, 0); } +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) + DWORD FindProcessId(char * process_name) + { + PROCESSENTRY32 entry; + entry.dwSize = sizeof(PROCESSENTRY32); + + HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); + + if (Process32First(snapshot, &entry) == TRUE) + { + while (Process32Next(snapshot, &entry) == TRUE) + { + if (stricmp(entry.szExeFile, process_name) == 0) + { + CloseHandle(snapshot); + return entry.th32ProcessID; + } + } + } + } +#endif //quoting on Windows is weird size_t ArgvEscapeWindows(char *in, char *out) { diff --git a/common.h b/common.h index 03ef16e..847e866 100755 --- a/common.h +++ b/common.h @@ -75,6 +75,9 @@ uint64_t GetCurTime(void); char *GetOption(const char *name, int argc, char** argv); void GetOptionAll(const char *name, int argc, char** argv, std::list *results); bool GetBinaryOption(const char *name, int argc, char** argv, bool default_value); +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) + DWORD FindProcessId(char * process_name); +#endif int GetIntOption(const char *name, int argc, char** argv, int default_value); char *ArgvToCmd(int argc, char** argv);