Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artemis x64 engine hook #1182

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions texthook/engine/match64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
#include "engine.h"
#include "util.h"

#define XX2 XX,XX // WORD
#define XX4 XX2,XX2 // DWORD
#define XX8 XX4,XX4 // QWORD

namespace Engine
{
enum : DWORD { X64_MAX_REL_ADDR = 0x00300000 };
/** Artikash 6/7/2019
* PPSSPP JIT code has pointers, but they are all added to an offset before being used.
Find that offset so that hook searching works properly.
Expand Down Expand Up @@ -214,6 +219,35 @@ namespace Engine
return false;
}

bool InsertArtemisHook() {
//by Blu3train
/*
* Sample games:
* https://vndb.org/v45247
*/
const BYTE bytes[] = {
0xCC, // int 3
0x40, 0x57, // push rdi <- hook here
0x48, 0x83, 0xEC, 0x40, // sub rsp,40
0x48, 0xC7, 0x44, 0x24, 0x30, XX4, // mov qword ptr [rsp+30],FFFFFFFFFFFFFFFE
0x48, 0x89, 0x5C, 0x24, 0x50 // mov [rsp+50],rbx
};

ULONG64 range = min(processStopAddress - processStartAddress, X64_MAX_REL_ADDR);
for (auto addr : Util::SearchMemory(bytes, sizeof(bytes), PAGE_EXECUTE, processStartAddress, processStartAddress + range)) {
HookParam hp = {};
hp.address = addr + 1;
hp.offset = -0x44 -4; //RDI
hp.type = USING_STRING | USING_UTF8 | NO_CONTEXT;
ConsoleOutput("vnreng: INSERT Artemis Hook ");
NewHook(hp, "Artemis");
return true;
}

ConsoleOutput("vnreng:Artemis: pattern not found");
return false;
}

bool UnsafeDetermineEngineType()
{
if (Util::CheckFile(L"PPSSPP*.exe") && FindPPSSPP()) return true;
Expand All @@ -228,6 +262,11 @@ namespace Engine
return true;
}

if (Util::CheckFile(L"*.pfs")) {
InsertArtemisHook();
return true;
}

if (Util::CheckFile(L"*.py") && InsertRenpyHook()) return true;

for (const wchar_t* monoName : { L"mono.dll", L"mono-2.0-bdwgc.dll" }) if (HMODULE module = GetModuleHandleW(monoName)) if (InsertMonoHooks(module)) return true;
Expand Down