Skip to content

Commit

Permalink
Vutils
Browse files Browse the repository at this point in the history
  • Loading branch information
vic4key committed Nov 6, 2023
1 parent cdf4507 commit 8b509d2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
7 changes: 5 additions & 2 deletions include/Vutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1445,8 +1445,8 @@ class AsyncSocket : public LastError
* @param[in] F The function name.
* @return true if the function succeeds. Otherwise false.
*/
#define VU_API_INL_OVERRIDE(O, M, F) O.install(_T( # M ), _T( # F ), (void*)&Hfn ## F, (void**)&pfn ## F)
#define VU_API_INL_RESTORE(O, M, F) O.uninstall(_T( # M ), _T( # F ), (void**)&pfn ## F)
#define VU_API_INL_OVERRIDE(O, M, F) O.install(ts( # M ), ts( # F ), (void*)&Hfn ## F, (void**)&pfn ## F)
#define VU_API_INL_RESTORE(O, M, F) O.uninstall(ts( # M ), ts( # F ), (void**)&pfn ## F)

enum class memory_address_type
{
Expand Down Expand Up @@ -1503,6 +1503,9 @@ class INLHookingX
INLHookingX() : m_hooked(false) {};
virtual ~INLHookingX() {};

INLHookingX(const INLHookingX& right);
const INLHookingX& operator=(const INLHookingX& right);

bool vuapi attach(void* ptr_function, void* ptr_hook_function, void** pptr_old_function);
bool vuapi detach(void* ptr_function, void** pptr_old_function);
};
Expand Down
22 changes: 16 additions & 6 deletions src/details/apihookinl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace vu
* @param[out] instructions List instructions.
* @return True if current instruction is a memory struction, False if it is not.
*/
bool vuapi GetAssembleInstruction(
bool vuapi get_assemble_instruction(
const HDE::tagHDE& hde,
const ulong offset,
std::vector<MemoryInstruction>& instructions
Expand Down Expand Up @@ -166,6 +166,18 @@ bool vuapi GetAssembleInstruction(
return result;
}

INLHookingX::INLHookingX(const INLHookingX& right)
{
*this = right;
}

const INLHookingX& INLHookingX::operator=(const INLHookingX& right)
{
m_hooked = right.m_hooked;
m_memory_instructions = right.m_memory_instructions;
return *this;
}

bool vuapi INLHookingX::attach(void* ptr_function, void* ptr_hook_function, void** pptr_old_function)
{
/*
Expand Down Expand Up @@ -194,7 +206,7 @@ bool vuapi INLHookingX::attach(void* ptr_function, void* ptr_hook_function, void
}
else
{
GetAssembleInstruction(hde, trampoline_size, m_memory_instructions);
get_assemble_instruction(hde, trampoline_size, m_memory_instructions);
}

trampoline_size += hde.len;
Expand Down Expand Up @@ -252,7 +264,7 @@ bool vuapi INLHookingX::attach(void* ptr_function, void* ptr_hook_function, void
// Write the jump code (original -> new) on the top of the target function
memcpy(ptr_function, (void*)&O2N, sizeof(O2N));

return true;
return m_hooked = true;
}

bool vuapi INLHookingX::detach(void* ptr_function, void** pptr_old_function)
Expand Down Expand Up @@ -295,9 +307,7 @@ bool vuapi INLHookingA::install(
return false;
}

m_hooked = this->attach(ptr_function, ptr_hook_function, pptr_old_function);

return m_hooked;
return this->attach(ptr_function, ptr_hook_function, pptr_old_function);
}

bool vuapi INLHookingA::uninstall(
Expand Down

0 comments on commit 8b509d2

Please sign in to comment.