Skip to content

Commit

Permalink
feat: replace hook library to support arm64
Browse files Browse the repository at this point in the history
Related issues: #37 #52 #88.

Co-authored-by: Ritchie1108 <Ritchie1108@gmail.com>
Co-authored-by: YorkWaugh <67750590+YorkWaugh@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 4, 2024
1 parent 5e524a9 commit fd0f7b2
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 258 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
include: [
{ name: Chrome++_x86, arch: x86 },
{ name: Chrome++_x64, arch: x64 },
{ name: Chrome++_arm64, arch: arm64 }
]

name: ${{ matrix.name }}
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "minhook"]
path = minhook
url = https://github.com/TsudaKageyu/minhook
[submodule "mini_gzip"]
path = mini_gzip
url = https://github.com/Bush2021/mini_gzip
[submodule "detours"]
path = detours
url = https://github.com/microsoft/Detours
4 changes: 3 additions & 1 deletion VC-LTL5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ target("VC-LTL-5")
archpath = "Win32"
elseif arch=="x64" then
archpath = "x64"
elseif arch=="arm64" then
archpath = "arm64"
end
cprint("${color.warning}Platform : %s", archpath)
local libpath = VC_LTL_Root .. [[TargetPlatform\]] .. WindowsTargetPlatformMinVersion..[[\lib\]] .. archpath .. ";"
Expand All @@ -41,4 +43,4 @@ target("VC-LTL-5")

-- print(runenvs.INCLUDE)
-- print(runenvs.LIB)
end)
end)
1 change: 1 addition & 0 deletions detours
Submodule detours added at 4b8c65
1 change: 0 additions & 1 deletion minhook
Submodule minhook deleted from 91cc94
22 changes: 7 additions & 15 deletions src/appid.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
#include <propvarutil.h>
#include <shobjidl.h>

typedef HRESULT(WINAPI* pPSStringFromPropertyKey)(REFPROPERTYKEY pkey,
LPWSTR psz,
UINT cch);
pPSStringFromPropertyKey RawPSStringFromPropertyKey = nullptr;
auto RawPSStringFromPropertyKey = PSStringFromPropertyKey;

HRESULT WINAPI MyPSStringFromPropertyKey(REFPROPERTYKEY pkey,
LPWSTR psz,
Expand All @@ -24,17 +21,12 @@ HRESULT WINAPI MyPSStringFromPropertyKey(REFPROPERTYKEY pkey,
}

void SetAppId() {
HMODULE Propsys = LoadLibrary(L"Propsys.dll");

PBYTE PSStringFromPropertyKey =
(PBYTE)GetProcAddress(Propsys, "PSStringFromPropertyKey");
MH_STATUS status =
MH_CreateHook(PSStringFromPropertyKey, MyPSStringFromPropertyKey,
(LPVOID*)&RawPSStringFromPropertyKey);
if (status == MH_OK) {
MH_EnableHook(PSStringFromPropertyKey);
} else {
DebugLog(L"MH_CreateHook PSStringFromPropertyKey failed:%d", status);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((LPVOID*)&RawPSStringFromPropertyKey, MyPSStringFromPropertyKey);
auto status = DetourTransactionCommit();
if (status != NO_ERROR) {
DebugLog(L"SetAppId failed %d", status);
}
}

Expand Down
32 changes: 12 additions & 20 deletions src/chrome++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ HMODULE hInstance;

#define MAGIC_CODE 0x1603ABD9

#include "MinHook.h"
#include "detours.h"
#include "version.h"

#include "hijack.h"
Expand Down Expand Up @@ -68,36 +68,28 @@ void InstallLoader() {
MODULEINFO mi;
GetModuleInformation(GetCurrentProcess(), GetModuleHandle(nullptr), &mi,
sizeof(MODULEINFO));
PBYTE entry = (PBYTE)mi.EntryPoint;

// Jump from the original entry to the loader.
MH_STATUS status = MH_CreateHook(entry, Loader, (LPVOID*)&ExeMain);
if (status == MH_OK) {
MH_EnableHook(entry);
} else {
DebugLog(L"MH_CreateHook InstallLoader failed:%d", status);
ExeMain = (Startup)mi.EntryPoint;

DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((LPVOID*)&ExeMain, Loader);
auto status = DetourTransactionCommit();
if (status != NO_ERROR) {
DebugLog(L"InstallLoader failed: %d", status);
}
}
#define EXTERNC extern "C"

//
EXTERNC __declspec(dllexport) void portable() {}
__declspec(dllexport) void portable() {}

EXTERNC BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID pv) {
BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID pv) {
if (dwReason == DLL_PROCESS_ATTACH) {
DisableThreadLibraryCalls(hModule);
hInstance = hModule;

// Maintain the original function of system DLLs.
LoadSysDll(hModule);

// Install the loader after successfully initializing MinHook.
MH_STATUS status = MH_Initialize();
if (status == MH_OK) {
InstallLoader();
} else {
DebugLog(L"MH_Initialize failed:%d", status);
}
InstallLoader();
}
return TRUE;
}
Loading

0 comments on commit fd0f7b2

Please sign in to comment.