Skip to content

Commit 11cec94

Browse files
committed
Added trampoline_address property to CFunction.
1 parent dd10a11 commit 11cec94

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

src/core/modules/memory/memory_function.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,15 @@ object CFunction::SkipHooks(tuple args, dict kw)
334334
return Call(args, kw);
335335
}
336336

337+
unsigned long CFunction::GetTrampolineAddress()
338+
{
339+
CHook* pHook = GetHookManager()->FindHook((void *) m_ulAddr);
340+
if (pHook)
341+
return (unsigned long) pHook->m_pTrampoline;
342+
343+
return m_ulAddr;
344+
}
345+
337346
CHook* HookFunctionHelper(void* addr, ICallingConvention* pConv)
338347
{
339348
CHook* result;

src/core/modules/memory/memory_function.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,30 @@ class CFunction: public CPointer, private boost::noncopyable
6666
bool IsHookable();
6767

6868
bool IsHooked();
69-
69+
7070
object Call(boost::python::tuple args, dict kw);
7171
object CallTrampoline(boost::python::tuple args, dict kw);
7272
object SkipHooks(boost::python::tuple args, dict kw);
73-
73+
74+
unsigned long GetTrampolineAddress();
75+
7476
void AddHook(HookType_t eType, PyObject* pCallable);
7577
void RemoveHook(HookType_t eType, PyObject* pCallable);
76-
78+
7779
void AddPreHook(PyObject* pCallable)
7880
{ return AddHook(HOOKTYPE_PRE, pCallable); }
7981

8082
void AddPostHook(PyObject* pCallable)
8183
{ return AddHook(HOOKTYPE_POST, pCallable); }
82-
84+
8385
void RemovePreHook(PyObject* pCallable)
8486
{ RemoveHook(HOOKTYPE_PRE, pCallable); }
8587

8688
void RemovePostHook(PyObject* pCallable)
8789
{ RemoveHook(HOOKTYPE_POST, pCallable); }
8890

8991
void DeleteHook();
90-
92+
9193
public:
9294
boost::python::tuple m_tArgs;
9395
object m_oConverter;

src/core/modules/memory/memory_wrap.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,12 @@ void export_function(scope _memory)
539539
.def_readonly("convention",
540540
&CFunction::m_eCallingConvention
541541
)
542+
543+
// Properties
544+
.add_property("trampoline_address",
545+
&CFunction::GetTrampolineAddress,
546+
"Return the trampoline address if the function is hooked, otherwise return the function address."
547+
)
542548
;
543549
}
544550

0 commit comments

Comments
 (0)