refactor misc pchooks

This commit is contained in:
Akash Mozumdar 2018-09-17 19:44:29 -04:00
parent 50c488f109
commit 6ae86a5988
3 changed files with 30 additions and 72 deletions

View File

@ -373,7 +373,7 @@ bool DetermineEngineByFile4()
if (Util::CheckFile(L"bmp.pak") && Util::CheckFile(L"dsetup.dll")) { 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 // 1/1/2016 jich: skip izumo4 from studio ego that is not supported by debonosu
if (Util::CheckFile(L"*izumo4*.exe")) { if (Util::CheckFile(L"*izumo4*.exe")) {
PcHooks::hookLstrFunctions(); PcHooks::hookOtherPcFunctions();
return true; return true;
} }
InsertDebonosuHook(); InsertDebonosuHook();
@ -662,26 +662,26 @@ bool DetermineEngineAtLast()
// jichi 6/1/2014 // jichi 6/1/2014
// Artikash 9/3/2018 Hook wchar by default // Artikash 9/3/2018 Hook wchar by default
bool DetermineEngineGeneric() //bool DetermineEngineGeneric()
{ //{
bool ret = false; // bool ret = false;
//
//if (Util::CheckFile(L"AlterEgo.exe")) { // //if (Util::CheckFile(L"AlterEgo.exe")) {
// ConsoleOutput("vnreng: AlterEgo, INSERT WideChar hooks"); // // ConsoleOutput("vnreng: AlterEgo, INSERT WideChar hooks");
// ret = true; // // ret = true;
//} else if (Util::CheckFile(L"data\\Sky\\*")) { // //} else if (Util::CheckFile(L"data\\Sky\\*")) {
// ConsoleOutput("vnreng: TEATIME, INSERT WideChar hooks"); // // ConsoleOutput("vnreng: TEATIME, INSERT WideChar hooks");
// ret = true; // // ret = true;
//} // //}
////} else if (Util::CheckFile(L"image\\*.po2") || Util::CheckFile(L"image\\*.jo2")) { // ////} else if (Util::CheckFile(L"image\\*.po2") || Util::CheckFile(L"image\\*.jo2")) {
//// ConsoleOutput("vnreng: HarukaKanata, INSERT WideChar hooks"); // はるかかなた // //// ConsoleOutput("vnreng: HarukaKanata, INSERT WideChar hooks"); // はるかかなた
//// ret = true; // //// ret = true;
////} // ////}
//if (ret) // //if (ret)
// PcHooks::hookWcharFunctions(); // // PcHooks::hookWcharFunctions();
PcHooks::hookWcharFunctions(); // PcHooks::hookWcharFunctions();
return ret; // return ret;
} //}
bool DetermineNoEngine() bool DetermineNoEngine()
{ {
@ -842,7 +842,6 @@ bool UnsafeDetermineEngineType()
|| DetermineEngineByProcessName() || DetermineEngineByProcessName()
|| DetermineEngineOther() || DetermineEngineOther()
|| DetermineEngineAtLast() || DetermineEngineAtLast()
|| DetermineEngineGeneric()
|| DetermineNoEngine() || DetermineNoEngine()
; ;
} }
@ -857,8 +856,7 @@ bool DetermineEngineType()
__except(ExceptHandler((GetExceptionInformation())->ExceptionRecord, 0, 0, 0)) {} __except(ExceptHandler((GetExceptionInformation())->ExceptionRecord, 0, 0, 0)) {}
#endif // ITH_DISABLE_ENGINE #endif // ITH_DISABLE_ENGINE
if (!found) { // jichi 10/2/2013: Only enable it if no game engine is detected if (!found) { // jichi 10/2/2013: Only enable it if no game engine is detected
PcHooks::hookLstrFunctions(); PcHooks::hookOtherPcFunctions();
PcHooks::hookCharNextFunctions();
} //else } //else
// ConsoleOutput("vnreng: found game engine, IGNORE non gui hooks"); // ConsoleOutput("vnreng: found game engine, IGNORE non gui hooks");
return found; return found;

View File

@ -5,7 +5,6 @@
#include "main.h" #include "main.h"
//#include <gdiplus.h> //#include <gdiplus.h>
#define DEBUG "vnrcli"
// 8/1/2014 jichi: Split is not used. // 8/1/2014 jichi: Split is not used.
// Although split is specified, USING_SPLIT is not assigned. // Although split is specified, USING_SPLIT is not assigned.
@ -40,7 +39,6 @@
// jichi 7/17/2014: Renamed from InitDefaultHook // jichi 7/17/2014: Renamed from InitDefaultHook
void PcHooks::hookGDIFunctions() 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) // 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 // 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(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(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) NEW_HOOK(DrawTextExW, s_arg2, 0,s_arg1,0, USING_UNICODE|USING_STRING, 3)
ConsoleOutput("leave");
} }
// jichi 6/18/2015: GDI+ functions // jichi 6/18/2015: GDI+ functions
@ -127,7 +123,7 @@ void PcHooks::hookGDIPlusFunctions()
return; return;
} }
ConsoleOutput("enter"); ConsoleOutput("gdi+: loaded");
enum stack { enum stack {
s_retaddr = 0 s_retaddr = 0
, s_arg1 = 4 * 1 // 0x4 , 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, 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, 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 ) 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 // jichi 10/2/2013
// Note: All functions does not have NO_CONTEXT attribute and will be filtered. // 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) // int TextHook::InitHook(LPVOID addr, DWORD data, DWORD data_ind, DWORD split_off, DWORD split_ind, WORD type, DWORD len_off)
enum stack { enum stack {
s_retaddr = 0 s_retaddr = 0
, s_arg1 = 4 * 1 // 0x4 , s_arg1 = 4 * 1 // 0x4
//, s_arg2 = 4 * 2 // 0x8 , s_arg2 = 4 * 2 // 0x8
//, s_arg3 = 4 * 3 // 0xc , s_arg3 = 4 * 3 // 0xc
//, s_arg4 = 4 * 4 // 0x10 , s_arg4 = 4 * 4 // 0x10
//, s_arg5 = 4 * 5 // 0x14 , s_arg5 = 4 * 5 // 0x14
//, s_arg6 = 4 * 6 // 0x18 , s_arg6 = 4 * 6 // 0x18
}; };
// http://msdn.microsoft.com/en-us/library/78zh94ax.aspx // 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); // 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"_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) //_(L"_wcsinc", _wcsinc, 4, 0,4,0, USING_UNICODE|USING_STRING, 0)
ConsoleOutput("leave");
}
void PcHooks::hookWcharFunctions()
{
ConsoleOutput("enter");
// 12/1/2013 jichi: // 12/1/2013 jichi:
// AlterEgo // AlterEgo
// http://tieba.baidu.com/p/2736475133 // http://tieba.baidu.com/p/2736475133
@ -235,43 +223,17 @@ void PcHooks::hookWcharFunctions()
// _Out_opt_ LPBOOL lpUsedDefaultChar // _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 // 3/17/2014 jichi: Temporarily disabled
// http://sakuradite.com/topic/159 // http://sakuradite.com/topic/159
NEW_HOOK(MultiByteToWideChar, s_arg3, 0,4,0, USING_STRING, 4) NEW_HOOK(MultiByteToWideChar, s_arg3, 0,4,0, USING_STRING, 4)
NEW_HOOK(WideCharToMultiByte, s_arg3, 0,4,0, USING_UNICODE|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(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(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(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(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(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) //NEW_HOOK(CharNextExW, s_arg2, 0,0,0, USING_UNICODE|DATA_INDIRECT, 1)
ConsoleOutput("leave");
} }
// EOF // EOF

View File

@ -7,9 +7,7 @@ namespace PcHooks {
void hookGDIFunctions(); void hookGDIFunctions();
void hookGDIPlusFunctions(); void hookGDIPlusFunctions();
void hookLstrFunctions(); void hookOtherPcFunctions();
void hookWcharFunctions();
void hookCharNextFunctions();
} // namespace PcHooks } // namespace PcHooks