- Added .gitignore to exclude build directory - Added utils submodule for shared utilities - Configured CMake build system with dependencies - Added main executable and DLL injection logic - Included necessary headers and manifest files - Added README with build and usage instructions
81 lines
3.7 KiB
C++
81 lines
3.7 KiB
C++
#include <Windows.h>
|
|
#include "detours.h"
|
|
#include <stdio.h>
|
|
#include "wchar_util.h"
|
|
|
|
static HFONT(WINAPI *TrueCreateFontW)(int nHeight, int nWidth, int nEscapement, int nOrientation, int fnWeight, DWORD dwItalic, DWORD dwUnderline, DWORD dwStrikeOut, DWORD dwCharSet, DWORD dwOutPrecision, DWORD dwClipPrecision, DWORD dwQuality, DWORD dwPitchAndFamily, LPCWSTR lpFaceName) = CreateFontW;
|
|
static HFONT(WINAPI *TrueCreateFontA)(int nHeight, int nWidth, int nEscapement, int nOrientation, int fnWeight, DWORD dwItalic, DWORD dwUnderline, DWORD dwStrikeOut, DWORD dwCharSet, DWORD dwOutPrecision, DWORD dwClipPrecision, DWORD dwQuality, DWORD dwPitchAndFamily, LPCSTR lpFaceName) = CreateFontA;
|
|
|
|
typedef char*(*ConvertWideToMultibyte)(LPSTR result, LPCWSTR source, int cp);
|
|
|
|
ConvertWideToMultibyte GetHandle() {
|
|
HMODULE hModule = GetModuleHandleA(NULL);
|
|
return (ConvertWideToMultibyte)((char*)hModule + 0x9e9e0);
|
|
}
|
|
|
|
static ConvertWideToMultibyte h = nullptr;
|
|
|
|
char* convert(LPSTR result, LPCWSTR source, int cp) {
|
|
if (!h) return nullptr;
|
|
return h(result, source, 1);
|
|
}
|
|
|
|
HFONT WINAPI HookedCreateFontW(int nHeight, int nWidth, int nEscapement, int nOrientation, int fnWeight, DWORD dwItalic, DWORD dwUnderline, DWORD dwStrikeOut, DWORD dwCharSet, DWORD dwOutPrecision, DWORD dwClipPrecision, DWORD dwQuality, DWORD dwPitchAndFamily, LPCWSTR lpFaceName) {
|
|
std::wstring name(lpFaceName);
|
|
if (name == L"MS Gothic" || name == L"MS ゴシック") {
|
|
lpFaceName = L"微软雅黑";
|
|
nWidth = 0;
|
|
dwCharSet = 0;
|
|
}
|
|
return TrueCreateFontW(nHeight, nWidth, nEscapement, nOrientation, fnWeight, dwItalic, dwUnderline, dwStrikeOut, dwCharSet, dwOutPrecision, dwClipPrecision, dwQuality, dwPitchAndFamily, lpFaceName);
|
|
}
|
|
|
|
HFONT WINAPI HookedCreateFontA(int nHeight, int nWidth, int nEscapement, int nOrientation, int fnWeight, DWORD dwItalic, DWORD dwUnderline, DWORD dwStrikeOut, DWORD dwCharSet, DWORD dwOutPrecision, DWORD dwClipPrecision, DWORD dwQuality, DWORD dwPitchAndFamily, LPCSTR lpFaceName) {
|
|
UINT cp[] = { CP_UTF8, CP_OEMCP, CP_ACP, 932 };
|
|
std::wstring font;
|
|
for (int i = 0; i < 4; i++) {
|
|
if (wchar_util::str_to_wstr(font, lpFaceName, cp[i])) {
|
|
if (font == L"MS Gothic" || font == L"MS ゴシック") {
|
|
font = L"微软雅黑";
|
|
}
|
|
return TrueCreateFontW(nHeight, nWidth, nEscapement, nOrientation, fnWeight, dwItalic, dwUnderline, dwStrikeOut, dwCharSet, dwOutPrecision, dwClipPrecision, dwQuality, dwPitchAndFamily, font.c_str());
|
|
}
|
|
}
|
|
if (!strcmp(lpFaceName, "MS Gothic")) {
|
|
lpFaceName = "Microsoft YaHei";
|
|
}
|
|
return TrueCreateFontA(nHeight, nWidth, nEscapement, nOrientation, fnWeight, dwItalic, dwUnderline, dwStrikeOut, dwCharSet, dwOutPrecision, dwClipPrecision, dwQuality, dwPitchAndFamily, lpFaceName);
|
|
}
|
|
|
|
extern "C" __declspec(dllexport) void Attach() {
|
|
DetourTransactionBegin();
|
|
DetourUpdateThread(GetCurrentThread());
|
|
h = GetHandle();
|
|
DetourAttach(&h, convert);
|
|
DetourAttach(&TrueCreateFontW, HookedCreateFontW);
|
|
DetourAttach(&TrueCreateFontA, HookedCreateFontA);
|
|
DetourTransactionCommit();
|
|
}
|
|
|
|
extern "C" __declspec(dllexport) void Detach() {
|
|
if (!h) return;
|
|
DetourTransactionBegin();
|
|
DetourUpdateThread(GetCurrentThread());
|
|
DetourDetach(&h, convert);
|
|
DetourDetach(&TrueCreateFontW, HookedCreateFontW);
|
|
DetourDetach(&TrueCreateFontA, HookedCreateFontA);
|
|
DetourTransactionCommit();
|
|
}
|
|
|
|
BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID rev) {
|
|
switch (reason) {
|
|
case DLL_PROCESS_ATTACH:
|
|
Attach();
|
|
break;
|
|
case DLL_PROCESS_DETACH:
|
|
Detach();
|
|
break;
|
|
}
|
|
return TRUE;
|
|
}
|