Skip to content

Add trampoline property to CFunction. #349

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

Merged
merged 5 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Reverted the deletion of call_trampoline.
  • Loading branch information
CookStar committed Sep 25, 2020
commit 8c28170e8eade372a0bb6bef190bb4f0ee56926e
10 changes: 10 additions & 0 deletions src/core/modules/memory/memory_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,16 @@ object CFunction::Call(tuple args, dict kw)
return object();
}

object CFunction::CallTrampoline(tuple args, dict kw)
{
CHook* pHook = GetHookManager()->FindHook((void *) m_ulAddr);
if (!pHook)
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Function was not hooked.")

return CFunction((unsigned long) pHook->m_pTrampoline, m_eCallingConvention,
m_iCallingConvention, m_tArgs, m_eReturnType, m_oConverter).Call(args, kw);
}

object CFunction::SkipHooks(tuple args, dict kw)
{
CHook* pHook = GetHookManager()->FindHook((void *) m_ulAddr);
Expand Down
1 change: 1 addition & 0 deletions src/core/modules/memory/memory_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class CFunction: public CPointer, private boost::noncopyable
CFunction* GetTrampoline();

object Call(boost::python::tuple args, dict kw);
object CallTrampoline(boost::python::tuple args, dict kw);
object SkipHooks(boost::python::tuple args, dict kw);

void AddHook(HookType_t eType, PyObject* pCallable);
Expand Down
5 changes: 5 additions & 0 deletions src/core/modules/memory/memory_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ void export_function(scope _memory)
"Return True if the function is hooked."
)

.def("call_trampoline",
raw_method(&CFunction::CallTrampoline),
"Calls the trampoline function dynamically."
)

.def("skip_hooks",
raw_method(&CFunction::SkipHooks),
"Call the function, but skip hooks if there are any."
Expand Down