commit 41cc59a29119aec3e1015fcbb86ab89f53fd5745 Author: Mr. eXoDia Date: Sun Mar 22 12:22:55 2015 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2c7a15b --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +Debug/ +Release/ +*.suo +*.sdf +*.opensdf diff --git a/JoyBug.sln b/JoyBug.sln new file mode 100644 index 0000000..177d675 --- /dev/null +++ b/JoyBug.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.30723.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "JoyBug", "JoyBug\JoyBug.vcxproj", "{B65A3680-9B6B-44E6-A046-649F94DF9F56}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B65A3680-9B6B-44E6-A046-649F94DF9F56}.Debug|Win32.ActiveCfg = Debug|Win32 + {B65A3680-9B6B-44E6-A046-649F94DF9F56}.Debug|Win32.Build.0 = Debug|Win32 + {B65A3680-9B6B-44E6-A046-649F94DF9F56}.Release|Win32.ActiveCfg = Release|Win32 + {B65A3680-9B6B-44E6-A046-649F94DF9F56}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/JoyBug/Debugger.Core.cpp b/JoyBug/Debugger.Core.cpp new file mode 100644 index 0000000..cd1ded8 --- /dev/null +++ b/JoyBug/Debugger.Core.cpp @@ -0,0 +1,63 @@ +#include "Debugger.Core.h" +#include + +namespace Debugger +{ + static DebugState state; + + bool Init(const wchar_t* szFilePath, + const wchar_t* szCommandLine, + const wchar_t* szCurrentDirectory, + ProcessInfo* process) + { + STARTUPINFOW si; + memset(&si, 0, sizeof(si)); + PROCESS_INFORMATION pi; + memset(&pi, 0, sizeof(pi)); + const wchar_t* szFileNameCreateProcess; + wchar_t* szCommandLineCreateProcess; + if (szCommandLine == NULL || !wcslen(szCommandLine)) + { + szCommandLineCreateProcess = 0; + szFileNameCreateProcess = szFilePath; + } + else + { + wchar_t szCreateWithCmdLine[1024]; + swprintf_s(szCreateWithCmdLine, L"\"%s\" %s", szFilePath, szCommandLine); + szCommandLineCreateProcess = szCreateWithCmdLine; + szFileNameCreateProcess = 0; + } + + if (!CreateProcessW(szFileNameCreateProcess, + szCommandLineCreateProcess, + NULL, + NULL, + FALSE, + DEBUG_PROCESS | CREATE_NEW_CONSOLE, + NULL, + szCurrentDirectory, + &si, + &pi)) + { + return false; + } + state.process.hProcess = pi.hProcess; + state.process.hThread = pi.hThread; + state.process.ProcessId = pi.dwProcessId; + state.process.MainThreadId = pi.dwThreadId; + if (process) + *process = state.process; + return true; + } + + bool Stop() + { + return !!TerminateProcess(state.process.hProcess, 0); + } + + bool Detach() + { + return !!DebugActiveProcessStop(state.process.ProcessId); + } +}; \ No newline at end of file diff --git a/JoyBug/Debugger.Core.h b/JoyBug/Debugger.Core.h new file mode 100644 index 0000000..e6ce903 --- /dev/null +++ b/JoyBug/Debugger.Core.h @@ -0,0 +1,17 @@ +#ifndef _DEBUGGER_CORE_H +#define _DEBUGGER_CORE_H + +#include "_global.h" +#include "Debugger.State.h" + +namespace Debugger +{ + bool Init(const wchar_t* szFilePath, + const wchar_t* szCommandLine, + const wchar_t* szCurrentDirectory, + ProcessInfo* process); + bool Stop(); + bool Detach(); +}; + +#endif //_DEBUGGER_CORE_H \ No newline at end of file diff --git a/JoyBug/Debugger.State.h b/JoyBug/Debugger.State.h new file mode 100644 index 0000000..abc991b --- /dev/null +++ b/JoyBug/Debugger.State.h @@ -0,0 +1,19 @@ +#ifndef _DEBUG_STATE_H +#define _DEBUG_STATE_H + +#include "_global.h" + +struct ProcessInfo +{ + HANDLE hProcess; + HANDLE hThread; + DWORD ProcessId; + DWORD MainThreadId; +}; + +struct DebugState +{ + ProcessInfo process; +}; + +#endif //_DEBUG_STATE_H \ No newline at end of file diff --git a/JoyBug/JoyBug.vcxproj b/JoyBug/JoyBug.vcxproj new file mode 100644 index 0000000..55bc210 --- /dev/null +++ b/JoyBug/JoyBug.vcxproj @@ -0,0 +1,79 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {B65A3680-9B6B-44E6-A046-649F94DF9F56} + JoyBug + + + + Application + true + v120 + MultiByte + + + Application + false + v120 + true + MultiByte + + + + + + + + + + + + + + + Level3 + Disabled + true + + + true + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + true + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/JoyBug/JoyBug.vcxproj.filters b/JoyBug/JoyBug.vcxproj.filters new file mode 100644 index 0000000..729d120 --- /dev/null +++ b/JoyBug/JoyBug.vcxproj.filters @@ -0,0 +1,39 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/JoyBug/_global.cpp b/JoyBug/_global.cpp new file mode 100644 index 0000000..fc065f4 --- /dev/null +++ b/JoyBug/_global.cpp @@ -0,0 +1 @@ +#include "_global.h" \ No newline at end of file diff --git a/JoyBug/_global.h b/JoyBug/_global.h new file mode 100644 index 0000000..2aa6ad9 --- /dev/null +++ b/JoyBug/_global.h @@ -0,0 +1,7 @@ +#ifndef _GLOBAL_H +#define _GLOBAL_H + +#include +#include + +#endif //_GLOBAL_H \ No newline at end of file diff --git a/JoyBug/main.cpp b/JoyBug/main.cpp new file mode 100644 index 0000000..1911c48 --- /dev/null +++ b/JoyBug/main.cpp @@ -0,0 +1,22 @@ +#include +#include "Debugger.Core.h" + +int main() +{ + wchar_t szFilePath[256] = L"c:\\CodeBlocks\\arma_cert_bin_info\\bin\\arma_cert_bin_info.exe"; + wchar_t szCommandLine[256] = L""; + wchar_t szCurrentDir[256] = L"c:\\CodeBlocks\\arma_cert_bin_info\\bin"; + ProcessInfo process; + if (Debugger::Init(szFilePath, NULL, szCurrentDir, &process)) + { + printf("Debugger::Init success! PID: %X\n", process.ProcessId); + bool bDetached = Debugger::Detach(); + printf("Debugger::Detach returned %s\n", bDetached ? "true" : "false"); + } + else + { + puts("Debugger::Init failed!"); + } + system("pause"); + return 0; +} \ No newline at end of file