From e621155e25b454ffd872be41e5eac3c0dc993034 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Wed, 22 Aug 2018 18:05:45 -0400 Subject: [PATCH] refactors --- host/host.cc | 10 ++- vnrhook/include/const.h | 172 ---------------------------------------- vnrhook/include/types.h | 25 +----- 3 files changed, 8 insertions(+), 199 deletions(-) diff --git a/host/host.cc b/host/host.cc index c7a1c7f..1126f80 100644 --- a/host/host.cc +++ b/host/host.cc @@ -19,6 +19,8 @@ ProcessEventCallback OnAttach, OnDetach; DWORD DUMMY[100]; +ThreadParameter CONSOLE{ 0, -1UL, -1UL, -1UL }; + #define HOST_LOCK std::lock_guard hostLocker(hostMutex) // Synchronized scope for accessing private data namespace Host @@ -27,17 +29,19 @@ namespace Host DLLEXPORT void Start(ProcessEventCallback onAttach, ProcessEventCallback onDetach, ThreadEventCallback onCreate, ThreadEventCallback onRemove) { OnAttach = onAttach; OnDetach = onDetach; OnCreate = onCreate; OnRemove = onRemove; - OnCreate(textThreadsByParams[{ 0, -1UL, -1UL, -1UL }] = new TextThread({ 0, -1UL, -1UL, -1UL }, USING_UNICODE)); + OnCreate(textThreadsByParams[CONSOLE] = new TextThread(CONSOLE, USING_UNICODE)); CreateNewPipe(); } DLLEXPORT void Close() { // Artikash 7/25/2018: This is only called when NextHooker is closed, at which point Windows should free everything itself...right? +#ifdef _DEBUG HOST_LOCK; OnRemove = [](TextThread* textThread) { delete textThread; }; for (auto i : processRecordsByIds) UnregisterProcess(i.first); - delete textThreadsByParams[{ 0, -1UL, -1UL, -1UL }]; + delete textThreadsByParams[CONSOLE]; +#endif } DLLEXPORT bool InjectProcess(DWORD processId, DWORD timeout) @@ -155,7 +159,7 @@ namespace Host DLLEXPORT void AddConsoleOutput(std::wstring text) { HOST_LOCK; - textThreadsByParams[{ 0, -1UL, -1UL, -1UL }]->AddSentence(std::wstring(text)); + textThreadsByParams[CONSOLE]->AddSentence(std::wstring(text)); } } diff --git a/vnrhook/include/const.h b/vnrhook/include/const.h index 38d9270..6aeb203 100644 --- a/vnrhook/include/const.h +++ b/vnrhook/include/const.h @@ -5,46 +5,6 @@ // 8/23/2013 jichi // Branch: ITH/common.h, rev 128 -// jichi 9/9/2013: Another importnat function is lstrcatA, which is already handled by -// Debonosu hooks. Wait until it is really needed by certain games. -// The order of the functions is used in several place. -// I need to recompile all of the dlls to modify the order. - -// jichi 10/14/2014 -#define HOOK_GDI_FUNCTION_LIST \ - GetTextExtentPoint32A \ - , GetTextExtentExPointA \ - , GetTabbedTextExtentA \ - , GetCharacterPlacementA \ - , GetGlyphIndicesA \ - , GetGlyphOutlineA \ - , ExtTextOutA \ - , TextOutA \ - , TabbedTextOutA \ - , GetCharABCWidthsA \ - , GetCharABCWidthsFloatA \ - , GetCharWidth32A \ - , GetCharWidthFloatA \ - , GetTextExtentPoint32W \ - , GetTextExtentExPointW \ - , GetTabbedTextExtentW \ - , GetCharacterPlacementW \ - , GetGlyphIndicesW \ - , GetGlyphOutlineW \ - , ExtTextOutW \ - , TextOutW \ - , TabbedTextOutW \ - , GetCharABCWidthsW \ - , GetCharABCWidthsFloatW \ - , GetCharWidth32W \ - , GetCharWidthFloatW \ - , DrawTextA \ - , DrawTextExA \ - , DrawTextW \ - , DrawTextExW - //, CharNextA - //, CharPrevA -//enum { HOOK_FUN_COUNT = 30 }; // total number of GDI hooks // jichi 1/16/2015: Though called max hook, it means max number of text threads enum { MAX_HOOK = 64 }; // must be larger than HOOK_FUN_COUNT @@ -117,138 +77,6 @@ enum { FIXED_SPLIT_VALUE = 0x10001 }; enum { PIPE_BUFFER_SIZE = 0x1000}; -// jichi 12/18/2013: -// These dlls are used to guess the range for non-NO_CONTEXT hooks. -// -// Disabling uxtheme.dll would crash certain system: http://tieba.baidu.com/p/2764436254 -#define IHF_FILTER_DLL_LIST \ - /* ITH original filters */ \ - L"gdiplus.dll" /* Graphics functions like TextOutA */ \ - , L"lpk.dll" /* Language package scripts and fonts */ \ - , L"msctf.dll" /* Text service */ \ - , L"psapi.dll" /* Processes */ \ - , L"usp10.dll" /* UNICODE rendering */ \ - , L"user32.dll" /* Non-graphics functions like lstrlenA */ \ - , L"uxtheme.dll" /* Theme */ \ - \ - /* Windows DLLs */ \ - , L"advapi32.dll" /* Advanced services */ \ - , L"apphelp.dll" /* Appliation help */ \ - , L"audioses.dll" /* Audios */ \ - , L"avrt.dll" /* Audio video runtime */ \ - , L"cfgmgr32.dll" /* Configuration manager */ \ - , L"clbcatq.dll" /* COM query service */ \ - , L"comctl32.dll" /* Common control library */ \ - , L"comdlg32.dll" /* Common dialogs */ \ - , L"crypt32.dll" /* Security cryption */ \ - , L"cryptbase.dll"/* Security cryption */ \ - , L"cryptsp.dll" /* Security cryption */ \ - , L"d3d8thk.dll" /* Direct3D 8 */ \ - , L"d3d9.dll" /* Direct3D 9 */ \ - , L"dbghelp.dll" /* Debug help */ \ - , L"dciman32.dll" /* Display cotrol */ \ - , L"devobj.dll" /* Device object */ \ - , L"ddraw.dll" /* Direct draw */ \ - , L"dinput.dll" /* Diret input */ \ - , L"dsound.dll" /* Direct sound */ \ - , L"DShowRdpFilter.dll" /* Direct show */ \ - , L"dwmapi.dll" /* Windows manager */ \ - , L"gdi32.dll" /* GDI32 */ \ - , L"hid.dll" /* HID user library */ \ - , L"iertutil.dll" /* IE runtime */ \ - , L"imagehlp.dll" /* Image help */ \ - , L"imm32.dll" /* Input method */ \ - , L"ksuser.dll" /* Kernel service */ \ - , L"ole32.dll" /* COM OLE */ \ - , L"oleacc.dll" /* OLE access */ \ - , L"oleaut32.dll" /* COM OLE */ \ - , L"kernel.dll" /* Kernel functions */ \ - , L"kernelbase.dll" /* Kernel functions */ \ - , L"midimap.dll" /* MIDI */ \ - , L"mmdevapi.dll" /* Audio device */ \ - , L"mpr.dll" /* Winnet */ \ - , L"msacm32.dll" /* MS ACM */ \ - , L"msacm32.drv" /* MS ACM */ \ - , L"msasn1.dll" /* Encoding/decoding */ \ - , L"msimg32.dll" /* Image */ \ - , L"msvfw32.dll" /* Media play */ \ - , L"netapi32.dll" /* Network service */ \ - , L"normaliz.dll" /* Normalize */ \ - , L"nsi.dll" /* NSI */ \ - , L"ntdll.dll" /* NT functions */ \ - , L"ntmarta.dll" /* NT MARTA */ \ - , L"nvd3dum.dll" /* Direct 3D */ \ - , L"powerprof.dll"/* Power profile */ \ - , L"profapi.dll" /* Profile API */ \ - , L"propsys.dll" /* System properties */ \ - , L"quartz.dll" /* OpenGL */ \ - , L"rpcrt4.dll" /* RPC runtime */ \ - , L"rpcrtremote.dll" /* RPC runtime */ \ - , L"rsabase.dll" /* RSA cryption */ \ - , L"rsaenh.dll" /* RSA cryption */ \ - , L"schannel.dll" /* Security channel */ \ - , L"sechost.dll" /* Service host */ \ - , L"setupapi.dll" /* Setup service */ \ - , L"shell32.dll" /* Windows shell */ \ - , L"shlwapi.dll" /* Light-weighted shell */ \ - , L"slc.dll" /* SLC */ \ - , L"srvcli.dll" /* Service client */ \ - , L"version.dll" /* Windows version */ \ - , L"wdmaud.drv" /* Wave output */ \ - , L"wldap32.dll" /* Wireless */ \ - , L"wininet.dll" /* Internet access */ \ - , L"winmm.dll" /* Windows sound */ \ - , L"winsta.dll" /* Connection system */ \ - , L"wtsapi32.dll" /* Windows terminal server */ \ - , L"wintrust.dll" /* Windows trust */ \ - , L"wsock32.dll" /* Windows sock */ \ - , L"ws2_32.dll" /* Terminal server */ \ - , L"wkscli.dll" /* ACIS */ \ - \ - /* MSVCRT */ \ - , L"msvcrt.dll" /* VC rutime */ \ - , L"msvcr80.dll" /* VC rutime 8 */ \ - , L"msvcp80.dll" /* VC rutime 8 */ \ - , L"msvcr90.dll" /* VC rutime 9 */ \ - , L"msvcp90.dll" /* VC rutime 9 */ \ - , L"msvcr100.dll" /* VC rutime 10 */ \ - , L"msvcp100.dll" /* VC rutime 10 */ \ - , L"msvcr110.dll" /* VC rutime 11 */ \ - , L"msvcp110.dll" /* VC rutime 11 */ \ - \ - /* VNR */ \ - , L"vnrhook.dll" \ - , L"vnrhookxp.dll" \ - \ - /* Sogou IME */ \ - , L"sogoupy.ime" \ - , L"PicFace.dll" \ - , L"AddressSearch.dll" \ - \ - /* QQ IME */ \ - , L"QQPINYIN.IME" \ - \ - /* AlphaROM */ \ - , L"kDays.dll" \ - \ - /* 360Safe */ \ - , L"safemon.dll" \ - \ - /* Locale changers */ \ - , L"AlLayer.dll" /* AppLocale */ \ - , L"LocaleEmulator.dll" /* Locale Emulator */ \ - , L"LSH.dll" /* LocaleSwitch */ \ - , L"ntleah.dll" /* NTLEA */ - - // Google Japanese IME - //, L"GoogleIMEJaTIP32.dll" - -enum { - //IHF_FILTER_COUNT = 7 - IHF_FILTER_COUNT = 7 + 72 + 9 + 4 + 3 + 1 + 1 + 1 + 4 // count of total dlls to filter - , IHF_FILTER_CAPACITY = IHF_FILTER_COUNT + 1 // one more than the dll count -}; - // jichi 12/25/2013: Header in each message sent to vnrsrv // There are totally three elements // - 0x0 dwAddr hook address diff --git a/vnrhook/include/types.h b/vnrhook/include/types.h index e5acde0..a6a1304 100644 --- a/vnrhook/include/types.h +++ b/vnrhook/include/types.h @@ -21,7 +21,7 @@ struct HookParam { // jichi 8/24/2013: For special hooks. typedef void (*text_fun_t)(DWORD esp, HookParam *hp, BYTE index, DWORD *data, DWORD *split, DWORD *len); - // jichi 10/24/2014: Add filter function. Return the if skip the text + // jichi 10/24/2014: Add filter function. Return true if skip the text typedef bool (*filter_fun_t)(LPVOID str, DWORD *len, HookParam *hp, BYTE index); // jichi 10/24/2014: Add generic hook function, return false if stop execution. @@ -49,29 +49,6 @@ struct HookParam { HANDLE readerHandle; }; -// jichi 6/1/2014: Structure of the esp for extern functions -struct HookStack -{ - // pushad - DWORD edi, // -0x24 - esi, // -0x20 - ebp, // -0x1c - esp, // -0x18 - ebx, // -0x14 - edx, // -0x10 - ecx, // -0xc - eax; // -0x8 - // pushfd - DWORD eflags; // -0x4 - DWORD retaddr; // 0 - DWORD args[1]; // 0x4 -}; - -struct SendParam { - DWORD type; - HookParam hp; -}; - struct Hook { // size: 0x80 HookParam hp; LPSTR hook_name;