| 14 | } |
| 15 | |
| 16 | int EmmyTool::Launch() { |
| 17 | std::string dllDirectory = _cmd.Get<std::string>("dir"); |
| 18 | std::string dllName = _cmd.Get<std::string>("dll"); |
| 19 | std::string workDirectory = _cmd.Get<std::string>("work"); |
| 20 | std::string exeFileName = _cmd.Get<std::string>("exe"); |
| 21 | std::string command = "\"" + exeFileName + "\"" + " " + _cmd.Get<std::string>("args"); |
| 22 | bool createNewWindow = _cmd.Get<bool>("create-new-window"); |
| 23 | |
| 24 | PROCESS_INFORMATION pi; |
| 25 | STARTUPINFO si; |
| 26 | |
| 27 | ZeroMemory(&pi, sizeof(pi)); |
| 28 | ZeroMemory(&si, sizeof(si)); |
| 29 | |
| 30 | si.cb = sizeof(si); |
| 31 | |
| 32 | ExeInfo info{}; |
| 33 | if (!GetExeInfo(exeFileName.c_str(), info) || info.entryPoint == 0) { |
| 34 | //MessageEvent("Error: The entry point for the application could not be located", MessageType_Error); |
| 35 | return -1; |
| 36 | } |
| 37 | |
| 38 | DWORD flags = DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS; |
| 39 | if (createNewWindow) { |
| 40 | flags |= CREATE_NEW_CONSOLE; |
| 41 | } |
| 42 | |
| 43 | if (!CreateProcess(nullptr, |
| 44 | (LPSTR) command.c_str(), |
| 45 | nullptr, |
| 46 | nullptr, |
| 47 | TRUE, |
| 48 | flags, |
| 49 | nullptr, |
| 50 | workDirectory.c_str(), |
| 51 | &si, |
| 52 | &pi)) { |
| 53 | //OutputError(GetLastError()); |
| 54 | return -1; |
| 55 | } |
| 56 | |
| 57 | if (!info.managed) { |
| 58 | size_t entryPoint = info.entryPoint; |
| 59 | |
| 60 | BYTE breakPointData; |
| 61 | bool done = false; |
| 62 | bool hasInject = false; |
| 63 | bool firstBreakPoint = true; |
| 64 | bool backToEntry = false; |
| 65 | while (!done) { |
| 66 | DEBUG_EVENT debugEvent; |
| 67 | WaitForDebugEvent(&debugEvent, INFINITE); |
| 68 | |
| 69 | DWORD continueStatus = DBG_EXCEPTION_NOT_HANDLED; |
| 70 | |
| 71 | if (debugEvent.dwDebugEventCode == EXCEPTION_DEBUG_EVENT) { |
| 72 | if (debugEvent.u.Exception.ExceptionRecord.ExceptionCode == EXCEPTION_SINGLE_STEP || |
| 73 | debugEvent.u.Exception.ExceptionRecord.ExceptionCode == EXCEPTION_BREAKPOINT) { |
no test coverage detected