mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-27 15:44:12 +08:00
.
This commit is contained in:
parent
c3f232dcfc
commit
0872e76fee
@ -243,9 +243,8 @@ bool SendJitVeh(PCONTEXT context, uintptr_t address, uint64_t em_addr, JITTYPE j
|
|||||||
if (tm - addresscalledtime[address] < 100)
|
if (tm - addresscalledtime[address] < 100)
|
||||||
return false;
|
return false;
|
||||||
addresscalledtime[address] = tm;
|
addresscalledtime[address] = tm;
|
||||||
auto stack = std::make_unique<hook_stack>();
|
hook_stack stack = hook_stack::fromContext(context);
|
||||||
context_get(stack.get(), context);
|
SafeSendJitVeh(&stack, address, em_addr, jittype, padding);
|
||||||
SafeSendJitVeh(stack.get(), address, em_addr, jittype, padding);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::vector<uintptr_t> GetFunctions(uintptr_t module)
|
std::vector<uintptr_t> GetFunctions(uintptr_t module)
|
||||||
|
@ -333,71 +333,4 @@ std::string LoadResData(LPCWSTR pszResID, LPCWSTR _type)
|
|||||||
GlobalFree(m_hMem);
|
GlobalFree(m_hMem);
|
||||||
FreeResource(lpRsrc);
|
FreeResource(lpRsrc);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void context_get(hook_stack *stack, PCONTEXT context)
|
|
||||||
{
|
|
||||||
#ifndef _WIN64
|
|
||||||
stack->eax = context->Eax;
|
|
||||||
stack->ecx = context->Ecx;
|
|
||||||
stack->edx = context->Edx;
|
|
||||||
stack->ebx = context->Ebx;
|
|
||||||
stack->esp = context->Esp;
|
|
||||||
stack->ebp = context->Ebp;
|
|
||||||
stack->esi = context->Esi;
|
|
||||||
stack->edi = context->Edi;
|
|
||||||
stack->eflags = context->EFlags;
|
|
||||||
stack->retaddr = *(DWORD *)context->Esp;
|
|
||||||
#else
|
|
||||||
stack->rax = context->Rax;
|
|
||||||
stack->rbx = context->Rbx;
|
|
||||||
stack->rcx = context->Rcx;
|
|
||||||
stack->rdx = context->Rdx;
|
|
||||||
stack->rsp = context->Rsp;
|
|
||||||
stack->rbp = context->Rbp;
|
|
||||||
stack->rsi = context->Rsi;
|
|
||||||
stack->rdi = context->Rdi;
|
|
||||||
stack->r8 = context->R8;
|
|
||||||
stack->r9 = context->R9;
|
|
||||||
stack->r10 = context->R10;
|
|
||||||
stack->r11 = context->R11;
|
|
||||||
stack->r12 = context->R12;
|
|
||||||
stack->r13 = context->R13;
|
|
||||||
stack->r14 = context->R14;
|
|
||||||
stack->r15 = context->R15;
|
|
||||||
stack->eflags = context->EFlags;
|
|
||||||
stack->retaddr = *(DWORD64 *)context->Rsp;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
void context_set(hook_stack *stack, PCONTEXT context)
|
|
||||||
{
|
|
||||||
#ifndef _WIN64
|
|
||||||
context->Eax = stack->eax;
|
|
||||||
context->Ecx = stack->ecx;
|
|
||||||
context->Edx = stack->edx;
|
|
||||||
context->Ebx = stack->ebx;
|
|
||||||
context->Esp = stack->esp;
|
|
||||||
context->Ebp = stack->ebp;
|
|
||||||
context->Esi = stack->esi;
|
|
||||||
context->Edi = stack->edi;
|
|
||||||
context->EFlags = stack->eflags;
|
|
||||||
#else
|
|
||||||
context->Rax = stack->rax;
|
|
||||||
context->Rbx = stack->rbx;
|
|
||||||
context->Rcx = stack->rcx;
|
|
||||||
context->Rdx = stack->rdx;
|
|
||||||
context->Rsp = stack->rsp;
|
|
||||||
context->Rbp = stack->rbp;
|
|
||||||
context->Rsi = stack->rsi;
|
|
||||||
context->Rdi = stack->rdi;
|
|
||||||
context->R8 = stack->r8;
|
|
||||||
context->R9 = stack->r9;
|
|
||||||
context->R10 = stack->r10;
|
|
||||||
context->R11 = stack->r11;
|
|
||||||
context->R12 = stack->r12;
|
|
||||||
context->R13 = stack->r13;
|
|
||||||
context->R14 = stack->r14;
|
|
||||||
context->R15 = stack->r15;
|
|
||||||
context->EFlags = stack->eflags;
|
|
||||||
#endif
|
|
||||||
}
|
|
@ -24,9 +24,6 @@ extern std::unordered_map<uintptr_t, std::pair<JITTYPE, uint64_t>> jitaddr2emuad
|
|||||||
void jitaddraddr(uint64_t em_addr, uintptr_t jitaddr, JITTYPE);
|
void jitaddraddr(uint64_t em_addr, uintptr_t jitaddr, JITTYPE);
|
||||||
void jitaddrclear();
|
void jitaddrclear();
|
||||||
|
|
||||||
void context_get(hook_stack *, PCONTEXT);
|
|
||||||
void context_set(hook_stack *, PCONTEXT);
|
|
||||||
|
|
||||||
void delayinsertadd(HookParam, std::string);
|
void delayinsertadd(HookParam, std::string);
|
||||||
void delayinsertNewHook(uint64_t);
|
void delayinsertNewHook(uint64_t);
|
||||||
inline bool safeautoleaveveh = false;
|
inline bool safeautoleaveveh = false;
|
||||||
|
@ -159,8 +159,8 @@ inline uintptr_t *argidx(hook_stack *stack, int idx)
|
|||||||
default:
|
default:
|
||||||
offset = get_stack(idx);
|
offset = get_stack(idx);
|
||||||
}
|
}
|
||||||
return (uintptr_t *)(stack->get_base() + offset);
|
return (uintptr_t *)(stack->base + offset);
|
||||||
#else
|
#else
|
||||||
return (uintptr_t *)(stack->get_base() + get_stack(idx));
|
return (uintptr_t *)(stack->base + get_stack(idx));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
@ -245,13 +245,16 @@ void commonfilter(TextBuffer *buffer, HookParam *hp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void TextHook::Send(uintptr_t lpDataBase)
|
void TextHook::Send(uintptr_t lpDataBase)
|
||||||
|
{
|
||||||
|
Send(hook_stack::fromBase(lpDataBase));
|
||||||
|
}
|
||||||
|
void TextHook::Send(hook_stack *stack)
|
||||||
{
|
{
|
||||||
auto buffer = (TextOutput_T *)local_buffer;
|
auto buffer = (TextOutput_T *)local_buffer;
|
||||||
TextBuffer buff{buffer->data, 0};
|
TextBuffer buff{buffer->data, 0};
|
||||||
_InterlockedIncrement((long *)&useCount);
|
_InterlockedIncrement((long *)&useCount);
|
||||||
__try
|
__try
|
||||||
{
|
{
|
||||||
auto stack = get_hook_stack(lpDataBase);
|
|
||||||
|
|
||||||
if (auto current_trigger_fun = trigger_fun.exchange(nullptr))
|
if (auto current_trigger_fun = trigger_fun.exchange(nullptr))
|
||||||
if (!current_trigger_fun(location, stack))
|
if (!current_trigger_fun(location, stack))
|
||||||
@ -280,7 +283,7 @@ void TextHook::Send(uintptr_t lpDataBase)
|
|||||||
|
|
||||||
uintptr_t lpSplit = 0,
|
uintptr_t lpSplit = 0,
|
||||||
lpRetn = stack->retaddr,
|
lpRetn = stack->retaddr,
|
||||||
plpdatain = (lpDataBase + hp.offset),
|
plpdatain = (uintptr_t)(stack->base + hp.offset),
|
||||||
lpDataIn = *(uintptr_t *)plpdatain;
|
lpDataIn = *(uintptr_t *)plpdatain;
|
||||||
|
|
||||||
if (hp.jittype != JITTYPE::PC && hp.jittype != JITTYPE::UNITY)
|
if (hp.jittype != JITTYPE::PC && hp.jittype != JITTYPE::UNITY)
|
||||||
@ -312,7 +315,7 @@ void TextHook::Send(uintptr_t lpDataBase)
|
|||||||
if (hp.jittype != JITTYPE::PC && hp.jittype != JITTYPE::UNITY)
|
if (hp.jittype != JITTYPE::PC && hp.jittype != JITTYPE::UNITY)
|
||||||
lpSplit = jitgetaddr(stack, &hp, false);
|
lpSplit = jitgetaddr(stack, &hp, false);
|
||||||
else
|
else
|
||||||
lpSplit = *(uintptr_t *)(lpDataBase + hp.split);
|
lpSplit = *(uintptr_t *)(stack->base + hp.split);
|
||||||
if (hp.type & SPLIT_INDIRECT)
|
if (hp.type & SPLIT_INDIRECT)
|
||||||
lpSplit = *(uintptr_t *)(lpSplit + hp.split_index);
|
lpSplit = *(uintptr_t *)(lpSplit + hp.split_index);
|
||||||
}
|
}
|
||||||
@ -444,11 +447,9 @@ void TextHook::Send(uintptr_t lpDataBase)
|
|||||||
}
|
}
|
||||||
bool TextHook::breakpointcontext(PCONTEXT context)
|
bool TextHook::breakpointcontext(PCONTEXT context)
|
||||||
{
|
{
|
||||||
auto stack = std::make_unique<hook_stack>();
|
hook_stack stack = hook_stack::fromContext(context);
|
||||||
context_get(stack.get(), context);
|
Send(&stack);
|
||||||
auto lpDataBase = stack->get_base();
|
stack.toContext(context);
|
||||||
Send(lpDataBase);
|
|
||||||
context_set(stack.get(), context);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool TextHook::InsertBreakPoint()
|
bool TextHook::InsertBreakPoint()
|
||||||
|
@ -18,7 +18,8 @@ private:
|
|||||||
bool InsertBreakPoint();
|
bool InsertBreakPoint();
|
||||||
bool RemoveBreakPoint();
|
bool RemoveBreakPoint();
|
||||||
bool breakpointcontext(PCONTEXT);
|
bool breakpointcontext(PCONTEXT);
|
||||||
void Send(uintptr_t dwDatabase);
|
void Send(uintptr_t);
|
||||||
|
void Send(hook_stack*);
|
||||||
int GetLength(hook_stack *stack, uintptr_t in); // jichi 12/25/2013: Return 0 if failed
|
int GetLength(hook_stack *stack, uintptr_t in); // jichi 12/25/2013: Return 0 if failed
|
||||||
int HookStrlen(BYTE *data);
|
int HookStrlen(BYTE *data);
|
||||||
void RemoveHookCode();
|
void RemoveHookCode();
|
||||||
|
@ -65,16 +65,79 @@ struct hook_stack
|
|||||||
uintptr_t retaddr;
|
uintptr_t retaddr;
|
||||||
BYTE base[1];
|
BYTE base[1];
|
||||||
};
|
};
|
||||||
uintptr_t get_base()
|
void toContext(PCONTEXT context)
|
||||||
{
|
{
|
||||||
return (uintptr_t)this + sizeof(hook_stack) - sizeof(uintptr_t);
|
#ifndef _WIN64
|
||||||
|
context->Eax = eax;
|
||||||
|
context->Ecx = ecx;
|
||||||
|
context->Edx = edx;
|
||||||
|
context->Ebx = ebx;
|
||||||
|
context->Esp = esp;
|
||||||
|
context->Ebp = ebp;
|
||||||
|
context->Esi = esi;
|
||||||
|
context->Edi = edi;
|
||||||
|
context->EFlags = eflags;
|
||||||
|
#else
|
||||||
|
context->Rax = rax;
|
||||||
|
context->Rbx = rbx;
|
||||||
|
context->Rcx = rcx;
|
||||||
|
context->Rdx = rdx;
|
||||||
|
context->Rsp = rsp;
|
||||||
|
context->Rbp = rbp;
|
||||||
|
context->Rsi = rsi;
|
||||||
|
context->Rdi = rdi;
|
||||||
|
context->R8 = r8;
|
||||||
|
context->R9 = r9;
|
||||||
|
context->R10 = r10;
|
||||||
|
context->R11 = r11;
|
||||||
|
context->R12 = r12;
|
||||||
|
context->R13 = r13;
|
||||||
|
context->R14 = r14;
|
||||||
|
context->R15 = r15;
|
||||||
|
context->EFlags = eflags;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
static hook_stack fromContext(PCONTEXT context)
|
||||||
|
{
|
||||||
|
hook_stack stack;
|
||||||
|
#ifndef _WIN64
|
||||||
|
stack.eax = context->Eax;
|
||||||
|
stack.ecx = context->Ecx;
|
||||||
|
stack.edx = context->Edx;
|
||||||
|
stack.ebx = context->Ebx;
|
||||||
|
stack.esp = context->Esp;
|
||||||
|
stack.ebp = context->Ebp;
|
||||||
|
stack.esi = context->Esi;
|
||||||
|
stack.edi = context->Edi;
|
||||||
|
stack.eflags = context->EFlags;
|
||||||
|
stack.retaddr = *(DWORD *)context->Esp;
|
||||||
|
#else
|
||||||
|
stack.rax = context->Rax;
|
||||||
|
stack.rbx = context->Rbx;
|
||||||
|
stack.rcx = context->Rcx;
|
||||||
|
stack.rdx = context->Rdx;
|
||||||
|
stack.rsp = context->Rsp;
|
||||||
|
stack.rbp = context->Rbp;
|
||||||
|
stack.rsi = context->Rsi;
|
||||||
|
stack.rdi = context->Rdi;
|
||||||
|
stack.r8 = context->R8;
|
||||||
|
stack.r9 = context->R9;
|
||||||
|
stack.r10 = context->R10;
|
||||||
|
stack.r11 = context->R11;
|
||||||
|
stack.r12 = context->R12;
|
||||||
|
stack.r13 = context->R13;
|
||||||
|
stack.r14 = context->R14;
|
||||||
|
stack.r15 = context->R15;
|
||||||
|
stack.eflags = context->EFlags;
|
||||||
|
stack.retaddr = *(DWORD64 *)context->Rsp;
|
||||||
|
#endif
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
static hook_stack *fromBase(uintptr_t lpDataBase)
|
||||||
|
{
|
||||||
|
return (hook_stack *)(lpDataBase - (uintptr_t)((hook_stack *)0)->base);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline hook_stack *get_hook_stack(uintptr_t lpDataBase)
|
|
||||||
{
|
|
||||||
return (hook_stack *)(lpDataBase - sizeof(hook_stack) + sizeof(uintptr_t));
|
|
||||||
}
|
|
||||||
// jichi 3/7/2014: Add guessed comment
|
// jichi 3/7/2014: Add guessed comment
|
||||||
|
|
||||||
#define ALIGNPTR(Y, X) \
|
#define ALIGNPTR(Y, X) \
|
||||||
@ -236,14 +299,14 @@ struct TextBuffer
|
|||||||
if (!c)
|
if (!c)
|
||||||
return;
|
return;
|
||||||
size = strlenEx(c) * sizeof(CharT);
|
size = strlenEx(c) * sizeof(CharT);
|
||||||
if(size)
|
if (size)
|
||||||
strncpyEx((CharT *)buff, c, TEXT_BUFFER_SIZE);
|
strncpyEx((CharT *)buff, c, TEXT_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
template <typename StringT, typename = std::enable_if_t<!std::is_pointer_v<StringT>>>
|
template <typename StringT, typename = std::enable_if_t<!std::is_pointer_v<StringT>>>
|
||||||
void from(const StringT &c)
|
void from(const StringT &c)
|
||||||
{
|
{
|
||||||
size = min(TEXT_BUFFER_SIZE, strSize(c));
|
size = min(TEXT_BUFFER_SIZE, strSize(c));
|
||||||
if(size)
|
if (size)
|
||||||
memcpy(buff, c.data(), size);
|
memcpy(buff, c.data(), size);
|
||||||
}
|
}
|
||||||
template <typename AddrT>
|
template <typename AddrT>
|
||||||
@ -252,7 +315,7 @@ struct TextBuffer
|
|||||||
if (!ptr || !t)
|
if (!ptr || !t)
|
||||||
return;
|
return;
|
||||||
size = min(TEXT_BUFFER_SIZE, t);
|
size = min(TEXT_BUFFER_SIZE, t);
|
||||||
if(size)
|
if (size)
|
||||||
memcpy(buff, (void *)ptr, size);
|
memcpy(buff, (void *)ptr, size);
|
||||||
}
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
set(VERSION_MAJOR 6)
|
set(VERSION_MAJOR 6)
|
||||||
set(VERSION_MINOR 10)
|
set(VERSION_MINOR 10)
|
||||||
set(VERSION_PATCH 3)
|
set(VERSION_PATCH 4)
|
||||||
set(VERSION_REVISION 0)
|
set(VERSION_REVISION 0)
|
||||||
set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}")
|
set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}")
|
||||||
add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp)
|
add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user