From 6ae86a5988d9facfafa95950a8d9bb12a5efcafd Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Mon, 17 Sep 2018 19:44:29 -0400 Subject: [PATCH] refactor misc pchooks --- vnrhook/engine/match.cc | 46 +++++++++++++++++----------------- vnrhook/engine/pchooks.cc | 52 ++++++--------------------------------- vnrhook/engine/pchooks.h | 4 +-- 3 files changed, 30 insertions(+), 72 deletions(-) diff --git a/vnrhook/engine/match.cc b/vnrhook/engine/match.cc index 43e028d..87bfc60 100644 --- a/vnrhook/engine/match.cc +++ b/vnrhook/engine/match.cc @@ -373,7 +373,7 @@ bool DetermineEngineByFile4() if (Util::CheckFile(L"bmp.pak") && Util::CheckFile(L"dsetup.dll")) { // 1/1/2016 jich: skip izumo4 from studio ego that is not supported by debonosu if (Util::CheckFile(L"*izumo4*.exe")) { - PcHooks::hookLstrFunctions(); + PcHooks::hookOtherPcFunctions(); return true; } InsertDebonosuHook(); @@ -662,26 +662,26 @@ bool DetermineEngineAtLast() // jichi 6/1/2014 // Artikash 9/3/2018 Hook wchar by default -bool DetermineEngineGeneric() -{ - bool ret = false; - - //if (Util::CheckFile(L"AlterEgo.exe")) { - // ConsoleOutput("vnreng: AlterEgo, INSERT WideChar hooks"); - // ret = true; - //} else if (Util::CheckFile(L"data\\Sky\\*")) { - // ConsoleOutput("vnreng: TEATIME, INSERT WideChar hooks"); - // ret = true; - //} - ////} else if (Util::CheckFile(L"image\\*.po2") || Util::CheckFile(L"image\\*.jo2")) { - //// ConsoleOutput("vnreng: HarukaKanata, INSERT WideChar hooks"); // はるかかなた - //// ret = true; - ////} - //if (ret) - // PcHooks::hookWcharFunctions(); - PcHooks::hookWcharFunctions(); - return ret; -} +//bool DetermineEngineGeneric() +//{ +// bool ret = false; +// +// //if (Util::CheckFile(L"AlterEgo.exe")) { +// // ConsoleOutput("vnreng: AlterEgo, INSERT WideChar hooks"); +// // ret = true; +// //} else if (Util::CheckFile(L"data\\Sky\\*")) { +// // ConsoleOutput("vnreng: TEATIME, INSERT WideChar hooks"); +// // ret = true; +// //} +// ////} else if (Util::CheckFile(L"image\\*.po2") || Util::CheckFile(L"image\\*.jo2")) { +// //// ConsoleOutput("vnreng: HarukaKanata, INSERT WideChar hooks"); // はるかかなた +// //// ret = true; +// ////} +// //if (ret) +// // PcHooks::hookWcharFunctions(); +// PcHooks::hookWcharFunctions(); +// return ret; +//} bool DetermineNoEngine() { @@ -842,7 +842,6 @@ bool UnsafeDetermineEngineType() || DetermineEngineByProcessName() || DetermineEngineOther() || DetermineEngineAtLast() - || DetermineEngineGeneric() || DetermineNoEngine() ; } @@ -857,8 +856,7 @@ bool DetermineEngineType() __except(ExceptHandler((GetExceptionInformation())->ExceptionRecord, 0, 0, 0)) {} #endif // ITH_DISABLE_ENGINE if (!found) { // jichi 10/2/2013: Only enable it if no game engine is detected - PcHooks::hookLstrFunctions(); - PcHooks::hookCharNextFunctions(); + PcHooks::hookOtherPcFunctions(); } //else // ConsoleOutput("vnreng: found game engine, IGNORE non gui hooks"); return found; diff --git a/vnrhook/engine/pchooks.cc b/vnrhook/engine/pchooks.cc index 395e56d..b5f5a00 100644 --- a/vnrhook/engine/pchooks.cc +++ b/vnrhook/engine/pchooks.cc @@ -5,7 +5,6 @@ #include "main.h" //#include -#define DEBUG "vnrcli" // 8/1/2014 jichi: Split is not used. // Although split is specified, USING_SPLIT is not assigned. @@ -40,7 +39,6 @@ // jichi 7/17/2014: Renamed from InitDefaultHook void PcHooks::hookGDIFunctions() { - ConsoleOutput("enter"); // int TextHook::InitHook(LPVOID addr, DWORD data, DWORD data_ind, DWORD split_off, DWORD split_ind, WORD type, DWORD len_off) // // jichi 9/8/2013: Guessed meaning @@ -114,8 +112,6 @@ void PcHooks::hookGDIFunctions() NEW_HOOK(DrawTextExA, s_arg2, 0,s_arg1,0, USING_STRING, 3) // int DrawTextEx(HDC hdc, LPTSTR lpchText,int cchText, LPRECT lprc, UINT dwDTFormat, LPDRAWTEXTPARAMS lpDTParams); NEW_HOOK(DrawTextW, s_arg2, 0,s_arg1,0, USING_UNICODE|USING_STRING, 3) NEW_HOOK(DrawTextExW, s_arg2, 0,s_arg1,0, USING_UNICODE|USING_STRING, 3) - - ConsoleOutput("leave"); } // jichi 6/18/2015: GDI+ functions @@ -127,7 +123,7 @@ void PcHooks::hookGDIPlusFunctions() return; } - ConsoleOutput("enter"); + ConsoleOutput("gdi+: loaded"); enum stack { s_retaddr = 0 , s_arg1 = 4 * 1 // 0x4 @@ -150,25 +146,22 @@ void PcHooks::hookGDIPlusFunctions() //NEW_MODULE_HOOK(hModule, GdipMeasureCharacterRanges, s_arg2, 0,s_arg1,0, USING_UNICODE|USING_STRING, 3) // GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics *graphics, GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font, GDIPCONST RectF &layoutRect, GDIPCONST GpStringFormat *stringFormat, INT regionCount, GpRegion **regions) NEW_MODULE_HOOK(hModule, GdipDrawString, s_arg2, 0,s_arg1,0, USING_UNICODE|USING_STRING, 3) // GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font, GDIPCONST RectF *layoutRect, GDIPCONST GpStringFormat *stringFormat, GDIPCONST GpBrush *brush); NEW_MODULE_HOOK(hModule, GdipMeasureString, s_arg2, 0,s_arg1,0, USING_UNICODE|USING_STRING, 3) // GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics, GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font, GDIPCONST RectF *layoutRect, GDIPCONST GpStringFormat *stringFormat, RectF *boundingBox, INT *codepointsFitted, INT *linesFilled ) - - ConsoleOutput("leave"); } // jichi 10/2/2013 // Note: All functions does not have NO_CONTEXT attribute and will be filtered. -void PcHooks::hookLstrFunctions() +void PcHooks::hookOtherPcFunctions() { - ConsoleOutput("enter"); // int TextHook::InitHook(LPVOID addr, DWORD data, DWORD data_ind, DWORD split_off, DWORD split_ind, WORD type, DWORD len_off) enum stack { s_retaddr = 0 , s_arg1 = 4 * 1 // 0x4 - //, s_arg2 = 4 * 2 // 0x8 - //, s_arg3 = 4 * 3 // 0xc - //, s_arg4 = 4 * 4 // 0x10 - //, s_arg5 = 4 * 5 // 0x14 - //, s_arg6 = 4 * 6 // 0x18 + , s_arg2 = 4 * 2 // 0x8 + , s_arg3 = 4 * 3 // 0xc + , s_arg4 = 4 * 4 // 0x10 + , s_arg5 = 4 * 5 // 0x14 + , s_arg6 = 4 * 6 // 0x18 }; // http://msdn.microsoft.com/en-us/library/78zh94ax.aspx @@ -199,12 +192,7 @@ void PcHooks::hookLstrFunctions() // unsigned char *_mbsinc_l(const unsigned char *current, _locale_t locale); //_(L"_strinc", _strinc, 4, 0,4,0, USING_STRING, 0) // 12/13/2013 jichi //_(L"_wcsinc", _wcsinc, 4, 0,4,0, USING_UNICODE|USING_STRING, 0) - ConsoleOutput("leave"); -} -void PcHooks::hookWcharFunctions() -{ - ConsoleOutput("enter"); // 12/1/2013 jichi: // AlterEgo // http://tieba.baidu.com/p/2736475133 @@ -235,43 +223,17 @@ void PcHooks::hookWcharFunctions() // _Out_opt_ LPBOOL lpUsedDefaultChar // ); - enum stack { - s_retaddr = 0 - , s_arg1 = 4 * 1 // 0x4 - //, s_arg2 = 4 * 2 // 0x8 - , s_arg3 = 4 * 3 // 0xc - //, s_arg4 = 4 * 4 // 0x10 - //, s_arg5 = 4 * 5 // 0x14 - //, s_arg6 = 4 * 6 // 0x18 - }; - // 3/17/2014 jichi: Temporarily disabled // http://sakuradite.com/topic/159 NEW_HOOK(MultiByteToWideChar, s_arg3, 0,4,0, USING_STRING, 4) NEW_HOOK(WideCharToMultiByte, s_arg3, 0,4,0, USING_UNICODE|USING_STRING, 4) - ConsoleOutput("leave"); -} -void PcHooks::hookCharNextFunctions() -{ - enum stack { - s_retaddr = 0 - , s_arg1 = 4 * 1 // 0x4 - , s_arg2 = 4 * 2 // 0x8 - //, s_arg3 = 4 * 3 // 0xc - //, s_arg4 = 4 * 4 // 0x10 - //, s_arg5 = 4 * 5 // 0x14 - //, s_arg6 = 4 * 6 // 0x18 - }; - - ConsoleOutput("enter"); NEW_HOOK(CharNextA, s_arg1, 0,0,0, USING_STRING|DATA_INDIRECT, 1) // LPTSTR WINAPI CharNext(_In_ LPCTSTR lpsz); NEW_HOOK(CharNextW, s_arg1, 0,0,0, USING_UNICODE|DATA_INDIRECT, 1) NEW_HOOK(CharPrevA, s_arg1, 0,0,0, USING_STRING|DATA_INDIRECT, 1) // LPTSTR WINAPI CharPrev(_In_ LPCTSTR lpszStart, _In_ LPCTSTR lpszCurrent); NEW_HOOK(CharPrevW, s_arg1, 0,0,0, USING_UNICODE|DATA_INDIRECT, 1) //NEW_HOOK(CharNextExA, s_arg2, 0,0,0, USING_STRING|DATA_INDIRECT, 1) // LPSTR WINAPI CharNextExA(_In_ WORD CodePage, _In_ LPCSTR lpCurrentChar, _In_ DWORD dwFlags); //NEW_HOOK(CharNextExW, s_arg2, 0,0,0, USING_UNICODE|DATA_INDIRECT, 1) - ConsoleOutput("leave"); } // EOF diff --git a/vnrhook/engine/pchooks.h b/vnrhook/engine/pchooks.h index 7ce99b5..60eac25 100644 --- a/vnrhook/engine/pchooks.h +++ b/vnrhook/engine/pchooks.h @@ -7,9 +7,7 @@ namespace PcHooks { void hookGDIFunctions(); void hookGDIPlusFunctions(); -void hookLstrFunctions(); -void hookWcharFunctions(); -void hookCharNextFunctions(); +void hookOtherPcFunctions(); } // namespace PcHooks