diff --git a/src/core/modules/memory/memory_function.cpp b/src/core/modules/memory/memory_function.cpp old mode 100644 new mode 100755 index 897878ea3..3ee4144da --- a/src/core/modules/memory/memory_function.cpp +++ b/src/core/modules/memory/memory_function.cpp @@ -170,13 +170,12 @@ CFunction::CFunction(unsigned long ulAddr, object oCallingConvention, object oAr } CFunction::CFunction(unsigned long ulAddr, Convention_t eCallingConvention, - int iCallingConvention, ICallingConvention* pCallingConvention, tuple tArgs, - DataType_t eReturnType, object oConverter) + int iCallingConvention, tuple tArgs, DataType_t eReturnType, object oConverter) :CPointer(ulAddr) { m_eCallingConvention = eCallingConvention; m_iCallingConvention = iCallingConvention; - m_pCallingConvention = pCallingConvention; + m_pCallingConvention = NULL; // We didn't allocate the calling convention, someone else is responsible for it. m_bAllocatedCallingConvention = false; @@ -218,6 +217,16 @@ bool CFunction::IsHooked() return GetHookManager()->FindHook((void *) m_ulAddr) != NULL; } +CFunction* CFunction::GetTrampoline() +{ + CHook* pHook = GetHookManager()->FindHook((void *) m_ulAddr); + if (!pHook) + BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Function was not hooked.") + + return new CFunction((unsigned long) pHook->m_pTrampoline, m_eCallingConvention, + m_iCallingConvention, m_tArgs, m_eReturnType, m_oConverter); +} + template ReturnType CallHelper(Function func, DCCallVM* vm, unsigned long addr) { @@ -314,22 +323,20 @@ object CFunction::Call(tuple args, dict kw) object CFunction::CallTrampoline(tuple args, dict kw) { - if (!IsCallable()) - BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Function is not callable.") - - Validate(); 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_pCallingConvention, m_tArgs, m_eReturnType, m_oConverter).Call(args, kw); + m_iCallingConvention, m_tArgs, m_eReturnType, m_oConverter).Call(args, kw); } object CFunction::SkipHooks(tuple args, dict kw) { - if (IsHooked()) - return CallTrampoline(args, kw); + CHook* pHook = GetHookManager()->FindHook((void *) m_ulAddr); + if (pHook) + return CFunction((unsigned long) pHook->m_pTrampoline, m_eCallingConvention, + m_iCallingConvention, m_tArgs, m_eReturnType, m_oConverter).Call(args, kw); return Call(args, kw); } diff --git a/src/core/modules/memory/memory_function.h b/src/core/modules/memory/memory_function.h index 0d25b0e7e..548d9bbae 100644 --- a/src/core/modules/memory/memory_function.h +++ b/src/core/modules/memory/memory_function.h @@ -57,8 +57,7 @@ class CFunction: public CPointer, private boost::noncopyable public: CFunction(unsigned long ulAddr, object oCallingConvention, object oArgs, object oReturnType); CFunction(unsigned long ulAddr, Convention_t eCallingConvention, int iCallingConvention, - ICallingConvention* pCallingConvention, boost::python::tuple tArgs, - DataType_t eReturnType, object oConverter); + boost::python::tuple tArgs, DataType_t eReturnType, object oConverter); ~CFunction(); @@ -66,20 +65,22 @@ class CFunction: public CPointer, private boost::noncopyable bool IsHookable(); bool IsHooked(); - + + 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); void RemoveHook(HookType_t eType, PyObject* pCallable); - + void AddPreHook(PyObject* pCallable) { return AddHook(HOOKTYPE_PRE, pCallable); } void AddPostHook(PyObject* pCallable) { return AddHook(HOOKTYPE_POST, pCallable); } - + void RemovePreHook(PyObject* pCallable) { RemoveHook(HOOKTYPE_PRE, pCallable); } @@ -87,7 +88,7 @@ class CFunction: public CPointer, private boost::noncopyable { RemoveHook(HOOKTYPE_POST, pCallable); } void DeleteHook(); - + public: boost::python::tuple m_tArgs; object m_oConverter; diff --git a/src/core/modules/memory/memory_wrap.cpp b/src/core/modules/memory/memory_wrap.cpp index 2dad81f88..d8ef5190f 100644 --- a/src/core/modules/memory/memory_wrap.cpp +++ b/src/core/modules/memory/memory_wrap.cpp @@ -539,6 +539,12 @@ void export_function(scope _memory) .def_readonly("convention", &CFunction::m_eCallingConvention ) + + // Properties + .add_property("trampoline", + make_function(&CFunction::GetTrampoline, manage_new_object_policy()), + "Return the trampoline function if the function is hooked." + ) ; }