From a2924f4a2cc56a075fe33aa95f08b5fa60ecf2d4 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sat, 21 Jul 2018 11:09:07 -0700 Subject: [PATCH] continue implementing interop --- GUI.sln | 3 +++ GUI/GUI.csproj | 10 ++++------ HostInterop/AssemblyInfo.cpp | Bin 1522 -> 1476 bytes HostInterop/HostInterop.cpp | Bin 104 -> 4858 bytes HostInterop/HostInterop.h | Bin 394 -> 1718 bytes HostInterop/HostInterop.vcxproj | 15 ++++----------- HostInterop/HostInterop.vcxproj.filters | 18 ++++++------------ HostInterop/stdafx.cpp | Bin 44 -> 0 bytes HostInterop/stdafx.h | Bin 30 -> 0 bytes oldgui/ProcessWindow.cpp | 4 ++-- oldgui/command.cpp | 4 ++-- oldgui/main.cpp | 2 +- oldgui/window.cpp | 2 +- texthook/hookman.cc | 3 +-- texthook/hookman.h | 2 +- texthook/host.cc | 12 ++++++------ texthook/host.h | 8 ++++---- 17 files changed, 35 insertions(+), 48 deletions(-) delete mode 100644 HostInterop/stdafx.cpp delete mode 100644 HostInterop/stdafx.h diff --git a/GUI.sln b/GUI.sln index 1a657a6..22cde48 100644 --- a/GUI.sln +++ b/GUI.sln @@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 VisualStudioVersion = 15.0.27703.2042 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GUI", "GUI\GUI.csproj", "{D847D0DC-78F5-4722-8E06-1A124B957353}" + ProjectSection(ProjectDependencies) = postProject + {0DF42D0B-0F87-475E-9E2C-9E32776B2AD5} = {0DF42D0B-0F87-475E-9E2C-9E32776B2AD5} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HostInterop", "HostInterop\HostInterop.vcxproj", "{0DF42D0B-0F87-475E-9E2C-9E32776B2AD5}" EndProject diff --git a/GUI/GUI.csproj b/GUI/GUI.csproj index 3a00a0d..16eeb66 100644 --- a/GUI/GUI.csproj +++ b/GUI/GUI.csproj @@ -52,6 +52,10 @@ true + + False + ..\Builds\Debug\Debug\HostInterop.dll + @@ -95,11 +99,5 @@ - - - {0df42d0b-0f87-475e-9e2c-9e32776b2ad5} - HostInterop - - \ No newline at end of file diff --git a/HostInterop/AssemblyInfo.cpp b/HostInterop/AssemblyInfo.cpp index c11d2a380dab0f8e6378793ffd7c02d711668133..58c692ea021eb3efc86bd57283c4df1d12172ace 100644 GIT binary patch delta 11 ScmeyweT19o|G$j}hgbn2_62kR delta 55 zcmX@Y{fS%q|377hOolv$WQH7uQic?UR0ahGC5B>#5+FN~A&sGeL60E=D8kFYHSwY0 IM!jjQ0HSmav;Y7A diff --git a/HostInterop/HostInterop.cpp b/HostInterop/HostInterop.cpp index bef4b4090aba63c40346f1a8bc7eae63d4081c00..5667ebec5bbf01deff6c09cf4398b403c55d3e1c 100644 GIT binary patch literal 4858 zcmb_g+fExX5S`al>OZVNm6l%MovM{k=uK(?kw|@Ol_s#HXeoxnl|RyWf`G*jTKKmB=s-scLq$Rg%=?pt>)nlHb?Vjx8??%5*N*!(3IKt@}R<5BdhlUv}8yi0~ z1AHoEN44GQXQM_VBQ?Xhclh@eQQunNXu!%GJ7cVOU}3V58LPEI-pG3)nkJ&n{R5Th zz@HqpjV}#3hXhYD8(m1|p4L9riQDSm!8eQMmE!4_dd&J9`;<3N#>RaaHRglWbfS0| z>r4@b@k(cnv5wEbfClSt7|#&To!l>wIy9+lr)@LiHc!{E*GKL%MZ-EEvSU=t89ZlX zGstG;iq&Xho&g87HRPAZVo=e;T4Anco~F4smGF@C}#=Zd+ z<5l4NL|Dc41ik-+)mfRHP}W5x^rJwvjd1Q}p)0nMdwLn?G#2V-HLr>+Ip8fyI>rAP^2qGk2!)vGYn>i@b~TzqjhN}U$DpaxlR~oxCQnx${bF^n z_H3k6k$LUq%kSe0M2>sRlwn4Gv%KfHwLY>j0^jr(4=; zXvtQE@r+f@{%2*@d*nEcb$kN9$nc?0w!;kLhg{)%<6DirSZ2v;4?PIkJ)I5mI_LQW zv!4^0$mqA@V!t{V$+{D+S{vvZfBL1Zw_uI-$+T7baYfi#s3NMke2#7c3eQe8xb_p8IP<*M$AQPuTW6-kPpL$6ziuAO7+_W3$Eii-wN~v`H(E`Plu**3@6SRdcK3Y9f0e3zqy2NU-E-a zUb0bDE`#)WS;t*Zqj~q?uHR1&N9RxGs@2WVkx}g};wjMa-V;Y;b8JT6Cdk6u=mAji zjf8K8apXeThh~;lVs$FPSKkIeJLkdGGg93vRLoq`Mke$eo#!$ha$B+RO;bq{O7%MsP Gp9%njpA8HE diff --git a/HostInterop/HostInterop.h b/HostInterop/HostInterop.h index 1f9aad4747c734005c2e880694027412bacb9d83..e6daf99662990b5a134f5fb967925539a1ea48c2 100644 GIT binary patch literal 1718 zcma)6O>Y`85Iuv$f3Vccrb@+qqgINbZE|QqY^2_h%z6TDjJ>jFQKN|e-m$$Orm!@( z_002|@tb-3p|X6t=gjC5CgaJtc2aMd=6i4zFM$=W4q<=iQ+@EkIDFIy)>M=6+hjbl z@XSiZonsHiy!_yrZ^6=~B=H1)@M&j(i_^Hju;iBe8Yw(L+XSVmdZT2?(n<~)-#E0q zMCO1i5QOvXL~Kr9BZnO6+QCS{78U61#@A`X8)FnJkXt;B2lz}G2dDAmb!+w=Fgc$B z1M#E&4J9tEDZ#mH{%f(Cvr3Bd4(5Qo+zkMy)8-8grvn@6_Jp@V^`I5oRkzHc$aB)A zo#c7J73|FceD^6!?2rp#!;K>;)rol`d^ciBd%dOK1-7fcG@7ibl(+|m_Y7@m>KPif<=v0jad;!ux3cBA8}rdFsE*N!s*HoMlDIRZ9mDG z!*G&sG@XWqSFn|2T^l_&BjX{=xKbNlzGN}@^*}PTF;+g`us2o)Ap1KFHYdmz1-cVh8P4v=xc|iW3Fr!LCpEo929@`gTS41pT6`lBJ2-wG(!gM7nEwB`LoYvdEOuXb?14;n{%jS bx7e2|c1bGOeWyQzA=bF2!6K2j>EQSmQQIf~ literal 394 zcmZvXOAdlS5JYQ>iFY8d(GBk90=o7DfcT00GC-m+UR`}N0&zhm)6-quRn_x(hiYV$ z=&X|Ht5&5*DB-oZ zCeFv#K@Z2u>BJLjZgMy1@6oaDhPpx3?)r4mqwbZez%ip^m^$%hAPFul`KV%9-YjoB vXnAh01h1c3ieHVA-MK^05La4LKe^Vc!`-mm|HSBLCu2IVLH#xS_E&!a=>9(2 diff --git a/HostInterop/HostInterop.vcxproj b/HostInterop/HostInterop.vcxproj index 6ccee25..9bf83ac 100644 --- a/HostInterop/HostInterop.vcxproj +++ b/HostInterop/HostInterop.vcxproj @@ -92,7 +92,7 @@ Level3 Disabled WIN32;_DEBUG;%(PreprocessorDefinitions) - Use + NotUsing ..\Builds\Debug\texthook\vnrhost.lib;%(AdditionalDependencies) @@ -134,19 +134,12 @@ - - - - - - Create - Create - Create - Create - + + + diff --git a/HostInterop/HostInterop.vcxproj.filters b/HostInterop/HostInterop.vcxproj.filters index a76d3b0..68e44a6 100644 --- a/HostInterop/HostInterop.vcxproj.filters +++ b/HostInterop/HostInterop.vcxproj.filters @@ -6,18 +6,10 @@ cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - {93995380-89BD-4b04-88EB-625FBE52EBFB} + {344ee2d7-eda2-4003-8c18-092ff651deb3} h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - - - Header Files - - - Header Files - - Source Files @@ -25,8 +17,10 @@ Source Files - - Source Files - + + + + Header Files + \ No newline at end of file diff --git a/HostInterop/stdafx.cpp b/HostInterop/stdafx.cpp deleted file mode 100644 index 08343afdf790eaa4524432ba7b0c3ddc395ee814..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 44 xcmezWPnjW;A&()MA%~%qA%!88L4iSup_rir$WCNPW2j)zW5@uC@G@{Q008!y2%rD} diff --git a/HostInterop/stdafx.h b/HostInterop/stdafx.h deleted file mode 100644 index 866b7f5b647af399e28ddfc986dce977754dd671..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 30 kcmezWPnn^Bp@<=oA)O%?NGdSoGvqNOGo&)`GH@{f0E5H^bpQYW diff --git a/oldgui/ProcessWindow.cpp b/oldgui/ProcessWindow.cpp index 91eccee..06e62f9 100644 --- a/oldgui/ProcessWindow.cpp +++ b/oldgui/ProcessWindow.cpp @@ -75,7 +75,7 @@ void ProcessWindow::RefreshProcess() void ProcessWindow::AttachProcess() { DWORD pid = GetSelectedPID(); - if (InjectProcessById(pid)) + if (InjectProcess(pid)) RefreshThreadWithPID(pid, true); else ConsoleOutput(L"NextHooker: could not inject"); @@ -84,7 +84,7 @@ void ProcessWindow::AttachProcess() void ProcessWindow::DetachProcess() { DWORD pid = GetSelectedPID(); - DetachProcessById(pid); + ::DetachProcess(pid); RefreshThreadWithPID(pid, false); } diff --git a/oldgui/command.cpp b/oldgui/command.cpp index 3b791f8..02197d4 100644 --- a/oldgui/command.cpp +++ b/oldgui/command.cpp @@ -35,13 +35,13 @@ DWORD ProcessCommand(const std::wstring& cmd, DWORD pid) if (regex_match(cmd, m, wregex(L"/p(\\d+)", wregex::icase))) { pid = std::stoul(m[1].str()); - InjectProcessById(pid); + InjectProcess(pid); } else if (regex_match(cmd, m, wregex(L"/h(.+)", wregex::icase))) { HookParam hp = {}; if (Parse(m[1].str(), hp)) - InsertHook(pid, &hp); + InsertHook(pid, hp); } else if (regex_match(cmd, m, wregex(L":(?:h|help)", wregex::icase))) { diff --git a/oldgui/main.cpp b/oldgui/main.cpp index a884736..bc72605 100644 --- a/oldgui/main.cpp +++ b/oldgui/main.cpp @@ -149,7 +149,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine if (StartHost()) { SetUnhandledExceptionFilter(UnhandledExcept); - GetHostHookManager(&man); + man = GetHostHookManager(); pfman = new ProfileManager(); DefaultSettings(); LoadSettings(); diff --git a/oldgui/window.cpp b/oldgui/window.cpp index 81d9a5e..ba0abc1 100644 --- a/oldgui/window.cpp +++ b/oldgui/window.cpp @@ -488,7 +488,7 @@ void RegisterProcess(DWORD pid) { for (auto i = pf->Hooks().begin(); i != pf->Hooks().end(); ++i) { - InsertHook(pid, &i->get()->HP(), toMultiByteString(i->get()->Name())); + InsertHook(pid, i->get()->HP(), toMultiByteString(i->get()->Name())); } } } diff --git a/texthook/hookman.cc b/texthook/hookman.cc index 9d723ca..ea0ec1b 100644 --- a/texthook/hookman.cc +++ b/texthook/hookman.cc @@ -141,10 +141,9 @@ void HookManager::DispatchText(DWORD pid, DWORD hook, DWORD retn, DWORD spl, con it->AddText(text, len); } -void HookManager::AddConsoleOutput(LPCWSTR text) +void HookManager::AddConsoleOutput(std::wstring text) { HM_LOCK; - int len = wcslen(text) * 2; TextThread *console = textThreadsByParams[{ 0, -1UL, -1UL, -1UL }]; console->AddSentence(std::wstring(text)); } diff --git a/texthook/hookman.h b/texthook/hookman.h index fb5328a..f2b1241 100644 --- a/texthook/hookman.h +++ b/texthook/hookman.h @@ -42,7 +42,7 @@ public: void ClearCurrent(); void SelectCurrent(DWORD num); void SetCurrent(TextThread *it); - void AddConsoleOutput(LPCWSTR text); + void AddConsoleOutput(std::wstring text); void DispatchText(DWORD pid, DWORD hook, DWORD retn, DWORD split, const BYTE *text, int len); void RemoveProcessContext(DWORD pid); // private void RemoveSingleHook(DWORD pid, DWORD addr); diff --git a/texthook/host.cc b/texthook/host.cc index 5e5393b..8a691e0 100644 --- a/texthook/host.cc +++ b/texthook/host.cc @@ -78,7 +78,7 @@ DLLEXPORT void CloseHost() } } -DLLEXPORT bool InjectProcessById(DWORD processId, DWORD timeout) +DLLEXPORT bool InjectProcess(DWORD processId, DWORD timeout) { if (processId == GetCurrentProcessId()) return false; @@ -110,26 +110,26 @@ DLLEXPORT bool InjectProcessById(DWORD processId, DWORD timeout) return false; } -DLLEXPORT bool DetachProcessById(DWORD processId) +DLLEXPORT bool DetachProcess(DWORD processId) { DWORD command = HOST_COMMAND_DETACH; DWORD unused; return WriteFile(man->GetHostPipe(processId), &command, sizeof(command), &unused, nullptr); } -DLLEXPORT void GetHostHookManager(HookManager** hookman) +DLLEXPORT HookManager* GetHostHookManager() { - *hookman = man; + return man; } -DLLEXPORT bool InsertHook(DWORD pid, const HookParam *hp, std::string name) +DLLEXPORT bool InsertHook(DWORD pid, HookParam hp, std::string name) { HANDLE commandPipe = man->GetHostPipe(pid); if (commandPipe == nullptr) return false; BYTE buffer[PIPE_BUFFER_SIZE] = {}; *(DWORD*)buffer = HOST_COMMAND_NEW_HOOK; - *(HookParam*)(buffer + sizeof(DWORD)) = *hp; + *(HookParam*)(buffer + sizeof(DWORD)) = hp; if (name.size()) strcpy((char*)buffer + sizeof(DWORD) + sizeof(HookParam), name.c_str()); DWORD unused; return WriteFile(commandPipe, buffer, sizeof(DWORD) + sizeof(HookParam) + name.size(), &unused, nullptr); diff --git a/texthook/host.h b/texthook/host.h index 3919943..1166693 100644 --- a/texthook/host.h +++ b/texthook/host.h @@ -12,10 +12,10 @@ DLLEXPORT void OpenHost(); DLLEXPORT bool StartHost(); DLLEXPORT void CloseHost(); -DLLEXPORT void GetHostHookManager(HookManager **hookman); -DLLEXPORT bool InjectProcessById(DWORD pid, DWORD timeout = 5000); -DLLEXPORT bool DetachProcessById(DWORD pid); -DLLEXPORT bool InsertHook(DWORD pid, const HookParam *hp, std::string name = ""); +DLLEXPORT HookManager* GetHostHookManager(); +DLLEXPORT bool InjectProcess(DWORD pid, DWORD timeout = 5000); +DLLEXPORT bool DetachProcess(DWORD pid); +DLLEXPORT bool InsertHook(DWORD pid, HookParam hp, std::string name = ""); DLLEXPORT bool RemoveHook(DWORD pid, DWORD addr); // EOF