Skip to content

Commit ad6d718

Browse files
committed
Added trampoline property to Function.
Removed call_trampoline. Removed trampoline_address.
1 parent 3cb810d commit ad6d718

File tree

3 files changed

+23
-41
lines changed

3 files changed

+23
-41
lines changed

src/core/modules/memory/memory_function.cpp

100644100755
Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ CFunction::CFunction(unsigned long ulAddr, object oCallingConvention, object oAr
170170
}
171171

172172
CFunction::CFunction(unsigned long ulAddr, Convention_t eCallingConvention,
173-
int iCallingConvention, ICallingConvention* pCallingConvention, tuple tArgs,
174-
DataType_t eReturnType, object oConverter)
173+
int iCallingConvention, tuple tArgs, DataType_t eReturnType, object oConverter)
175174
:CPointer(ulAddr)
176175
{
177176
m_eCallingConvention = eCallingConvention;
178177
m_iCallingConvention = iCallingConvention;
179-
m_pCallingConvention = pCallingConvention;
178+
m_pCallingConvention = NULL;
179+
m_oCallingConvention = object();
180180

181181
// We didn't allocate the calling convention, someone else is responsible for it.
182182
m_bAllocatedCallingConvention = false;
@@ -218,6 +218,16 @@ bool CFunction::IsHooked()
218218
return GetHookManager()->FindHook((void *) m_ulAddr) != NULL;
219219
}
220220

221+
CFunction* CFunction::GetTrampoline()
222+
{
223+
CHook* pHook = GetHookManager()->FindHook((void *) m_ulAddr);
224+
if (!pHook)
225+
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Function was not hooked.")
226+
227+
return new CFunction((unsigned long) pHook->m_pTrampoline, m_eCallingConvention,
228+
m_iCallingConvention, m_tArgs, m_eReturnType, m_oConverter);
229+
}
230+
221231
template<class ReturnType, class Function>
222232
ReturnType CallHelper(Function func, DCCallVM* vm, unsigned long addr)
223233
{
@@ -312,35 +322,14 @@ object CFunction::Call(tuple args, dict kw)
312322
return object();
313323
}
314324

315-
object CFunction::CallTrampoline(tuple args, dict kw)
316-
{
317-
if (!IsCallable())
318-
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Function is not callable.")
319-
320-
Validate();
321-
CHook* pHook = GetHookManager()->FindHook((void *) m_ulAddr);
322-
if (!pHook)
323-
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Function was not hooked.")
324-
325-
return CFunction((unsigned long) pHook->m_pTrampoline, m_eCallingConvention,
326-
m_iCallingConvention, m_pCallingConvention, m_tArgs, m_eReturnType, m_oConverter).Call(args, kw);
327-
}
328-
329325
object CFunction::SkipHooks(tuple args, dict kw)
330-
{
331-
if (IsHooked())
332-
return CallTrampoline(args, kw);
333-
334-
return Call(args, kw);
335-
}
336-
337-
unsigned long CFunction::GetTrampolineAddress()
338326
{
339327
CHook* pHook = GetHookManager()->FindHook((void *) m_ulAddr);
340-
if (!pHook)
341-
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Function was not hooked.")
328+
if (pHook)
329+
return CFunction((unsigned long) pHook->m_pTrampoline, m_eCallingConvention,
330+
m_iCallingConvention, m_tArgs, m_eReturnType, m_oConverter).Call(args, kw);
342331

343-
return (unsigned long) pHook->m_pTrampoline;
332+
return Call(args, kw);
344333
}
345334

346335
CHook* HookFunctionHelper(void* addr, ICallingConvention* pConv)

src/core/modules/memory/memory_function.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ class CFunction: public CPointer, private boost::noncopyable
5757
public:
5858
CFunction(unsigned long ulAddr, object oCallingConvention, object oArgs, object oReturnType);
5959
CFunction(unsigned long ulAddr, Convention_t eCallingConvention, int iCallingConvention,
60-
ICallingConvention* pCallingConvention, boost::python::tuple tArgs,
61-
DataType_t eReturnType, object oConverter);
60+
boost::python::tuple tArgs, DataType_t eReturnType, object oConverter);
6261

6362
~CFunction();
6463

@@ -67,12 +66,11 @@ class CFunction: public CPointer, private boost::noncopyable
6766

6867
bool IsHooked();
6968

69+
CFunction* GetTrampoline();
70+
7071
object Call(boost::python::tuple args, dict kw);
71-
object CallTrampoline(boost::python::tuple args, dict kw);
7272
object SkipHooks(boost::python::tuple args, dict kw);
7373

74-
unsigned long GetTrampolineAddress();
75-
7674
void AddHook(HookType_t eType, PyObject* pCallable);
7775
void RemoveHook(HookType_t eType, PyObject* pCallable);
7876

src/core/modules/memory/memory_wrap.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,6 @@ void export_function(scope _memory)
476476
"Return True if the function is hooked."
477477
)
478478

479-
.def("call_trampoline",
480-
raw_method(&CFunction::CallTrampoline),
481-
"Calls the trampoline function dynamically."
482-
)
483-
484479
.def("skip_hooks",
485480
raw_method(&CFunction::SkipHooks),
486481
"Call the function, but skip hooks if there are any."
@@ -541,9 +536,9 @@ void export_function(scope _memory)
541536
)
542537

543538
// Properties
544-
.add_property("trampoline_address",
545-
&CFunction::GetTrampolineAddress,
546-
"Return the trampoline address if the function is hooked, otherwise return the function address."
539+
.add_property("trampoline",
540+
make_function(&CFunction::GetTrampoline, manage_new_object_policy()),
541+
"Return the trampoline function if the function is hooked."
547542
)
548543
;
549544
}

0 commit comments

Comments
 (0)