dynamic x64

This commit is contained in:
恍兮惚兮 2024-05-13 18:28:08 +08:00
parent 69de553d13
commit fe499a63a2
9 changed files with 15 additions and 25 deletions

View File

@ -1,12 +1,12 @@
#include"IronGameSystem.h" #include"IronGameSystem.h"
bool InsertIGSDynamicHook(LPVOID addr, hook_stack* ,uintptr_t frame, uintptr_t stack) bool InsertIGSDynamicHook(LPVOID addr, hook_stack* stack)
{ {
if (addr != GetGlyphOutlineW) if (addr != GetGlyphOutlineW)
return false; return false;
DWORD i; DWORD i;
i = *(DWORD *)frame; i = *(DWORD *)stack->ebp;
i = *(DWORD *)(i+4); i = *(DWORD *)(i+4);
//if (SafeFillRange(L"mscorlib.ni.dll", &j, &k)) { // Artikash 6/30/2018: Dunno why addresses are needed //if (SafeFillRange(L"mscorlib.ni.dll", &j, &k)) { // Artikash 6/30/2018: Dunno why addresses are needed
while (*(BYTE *)i != 0xe8) while (*(BYTE *)i != 0xe8)

View File

@ -57,12 +57,12 @@ Reallive hook:
* 012da884 83c4 08 add esp,0x8 * 012da884 83c4 08 add esp,0x8
* 012da887 85f6 test esi,esi * 012da887 85f6 test esi,esi
*/ */
static bool InsertRealliveDynamicHook(LPVOID addr, hook_stack*, uintptr_t frame, uintptr_t stack) static bool InsertRealliveDynamicHook(LPVOID addr, hook_stack* stack)
{ {
if (addr != ::GetGlyphOutlineA) if (addr != ::GetGlyphOutlineA)
return false; return false;
// jichi 5/13/2015: Find the enclosing caller of GetGlyphOutlineA // jichi 5/13/2015: Find the enclosing caller of GetGlyphOutlineA
if (DWORD i = frame) { if (DWORD i = stack->ebp) {
i = *(DWORD *)(i + 4); i = *(DWORD *)(i + 4);
for (DWORD j = i; j > i - 0x100; j--) for (DWORD j = i; j > i - 0x100; j--)
if (*(WORD *)j == 0xec83) { // jichi 7/26/2014: function starts if (*(WORD *)j == 0xec83) { // jichi 7/26/2014: function starts

View File

@ -14,7 +14,7 @@ static void SpecialHookRyokucha(hook_stack* stack, HookParam *hp, uintptr_t *da
} }
*len = 0; *len = 0;
} }
bool InsertRyokuchaDynamicHook(LPVOID addr, hook_stack*, uintptr_t frame, uintptr_t stack) bool InsertRyokuchaDynamicHook(LPVOID addr, hook_stack*)
{ {
if (addr != ::GetGlyphOutlineA) if (addr != ::GetGlyphOutlineA)
return false; return false;

View File

@ -155,14 +155,14 @@ bool InsertShinaHook(int ver )
if (ver >= 50) { if (ver >= 50) {
//trigger_fun = StackSearchingTrigger<GetGlyphOutlineA, NULL>; //trigger_fun = StackSearchingTrigger<GetGlyphOutlineA, NULL>;
trigger_fun = [](LPVOID funcAddr, hook_stack*, auto, uintptr_t stack) trigger_fun = [](LPVOID funcAddr, hook_stack* stack)
{ {
bool ret = false; bool ret = false;
if (funcAddr != GetGlyphOutlineA && funcAddr != GetTextExtentPoint32A) return false; if (funcAddr != GetGlyphOutlineA && funcAddr != GetTextExtentPoint32A) return false;
for (int i = 0; i < 100; ++i) for (int i = 0; i < 100; ++i)
{ {
// Address of text is somewhere on stack in call to func. Search for it. // Address of text is somewhere on stack in call to func. Search for it.
DWORD addr = *((DWORD*)stack + i); DWORD addr = *((DWORD*)stack->esp + i);
//ConsoleOutput(std::to_string((DWORD)*addr).c_str()); //ConsoleOutput(std::to_string((DWORD)*addr).c_str());
if (IthGetMemoryRange((void*)addr, nullptr, nullptr) && strlen((char*)addr) > 9) if (IthGetMemoryRange((void*)addr, nullptr, nullptr) && strlen((char*)addr) > 9)
{ {

View File

@ -128,7 +128,7 @@ int GetSystemAoiVersion() // return result is cached
return ret; return ret;
} }
bool InsertSystemAoiDynamicHook(LPVOID addr, hook_stack*,uintptr_t frame, uintptr_t stack) bool InsertSystemAoiDynamicHook(LPVOID addr, hook_stack* stack)
{ {
int version = GetSystemAoiVersion(); int version = GetSystemAoiVersion();
bool utf16 = true; bool utf16 = true;
@ -145,8 +145,8 @@ bool InsertSystemAoiDynamicHook(LPVOID addr, hook_stack*,uintptr_t frame, uintpt
Util::GetCodeRange(processStartAddress, &low, &high); Util::GetCodeRange(processStartAddress, &low, &high);
// jichi 2/15/2015: Traverse the stack to dynamically find the ancestor call from the main module // jichi 2/15/2015: Traverse the stack to dynamically find the ancestor call from the main module
const DWORD stop = (stack & 0xffff0000) + 0x10000; // range to traverse the stack const DWORD stop = (stack->esp & 0xffff0000) + 0x10000; // range to traverse the stack
for (DWORD i = stack; i < stop; i += 4) { for (DWORD i = stack->esp; i < stop; i += 4) {
DWORD k = *(DWORD *)i; DWORD k = *(DWORD *)i;
if (k > low && k < high && // jichi: if the stack address falls into the code region of the main exe module if (k > low && k < high && // jichi: if the stack address falls into the code region of the main exe module
((*(WORD *)(k - 6) == 0x15ff) || *(BYTE *)(k - 5) == 0xe8)) { // jichi 10/20/2014: call dword ptr ds ((*(WORD *)(k - 6) == 0x15ff) || *(BYTE *)(k - 5) == 0xe8)) { // jichi 10/20/2014: call dword ptr ds

View File

@ -34,7 +34,7 @@ bool InsertTriangleHook()
bool Triangle::attach_function() { bool Triangle::attach_function() {
trigger_fun=[](LPVOID addr, hook_stack* stack,auto,auto){ trigger_fun=[](LPVOID addr, hook_stack* stack){
//Triangle やっぱり妹がすきっ! //Triangle やっぱり妹がすきっ!
if((DWORD)addr!=(DWORD)TextOutA)return false; if((DWORD)addr!=(DWORD)TextOutA)return false;
if(auto addr=MemDbg::findEnclosingAlignedFunction(stack->retaddr)) if(auto addr=MemDbg::findEnclosingAlignedFunction(stack->retaddr))

View File

@ -1,6 +1,6 @@
#include"Waffle.h" #include"Waffle.h"
bool InsertWaffleDynamicHook(LPVOID addr, hook_stack*, uintptr_t frame, uintptr_t stack) bool InsertWaffleDynamicHook(LPVOID addr, hook_stack* stack)
{ {
ConsoleOutput("WaffleDynamic:triggered"); ConsoleOutput("WaffleDynamic:triggered");
if (addr != ::GetTextExtentPoint32A) if (addr != ::GetTextExtentPoint32A)

View File

@ -195,10 +195,9 @@ void TextHook::Send(uintptr_t lpDataBase)
{ {
auto stack=get_hook_stack(lpDataBase); auto stack=get_hook_stack(lpDataBase);
#ifndef _WIN64
if (auto current_trigger_fun = trigger_fun.exchange(nullptr)) if (auto current_trigger_fun = trigger_fun.exchange(nullptr))
if (!current_trigger_fun(location, stack, stack->ebp, stack->esp)) trigger_fun = current_trigger_fun; if (!current_trigger_fun(location, stack)) trigger_fun = current_trigger_fun;
#endif
if(hp.type&HOOK_RETURN){ if(hp.type&HOOK_RETURN){
hp.type&=~HOOK_RETURN; hp.type&=~HOOK_RETURN;
hp.address=stack->retaddr; hp.address=stack->retaddr;

View File

@ -8,17 +8,8 @@
// - Clean up this file // - Clean up this file
// - Reduce global variables. Use namespaces or singleton classes instead. // - Reduce global variables. Use namespaces or singleton classes instead.
inline std::atomic<bool (*)(LPVOID addr, hook_stack* stack)> trigger_fun = nullptr;
// Artikash 6/17/2019 TODO: These have the wrong values on x64
/** jichi 12/24/2014
* @param addr function address
* @param frame real address of the function, supposed to be the same as addr
* @param stack address of current stack - 4
* @return If success, which is reverted
*/
#ifndef _WIN64
inline std::atomic<bool (*)(LPVOID addr, hook_stack* stack, uintptr_t ebp, uintptr_t esp)> trigger_fun = nullptr;
#endif
// jichi 9/25/2013: This class will be used by NtMapViewOfSectionfor // jichi 9/25/2013: This class will be used by NtMapViewOfSectionfor
// interprocedure communication, where constructor/destructor will NOT work. // interprocedure communication, where constructor/destructor will NOT work.
struct EmbedSharedMem{ struct EmbedSharedMem{