Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::lambda::bind temporary function objects.. and raw C
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-07-31 19:22:17


On Fri, Jul 31, 2009 at 9:20 AM, Steven Watanabe<watanabesj_at_[hidden]> wrote:
> AMDG
>
> Tomasz Mloduchowski wrote:
>>
>> Hello everyone!
>>
>> I have a rather challenging question, that perhaps can be resolved without
>> too much dark magic.
>>
>> A little background: I'm patching an executable (x86 platform, but could
>> be easily extended to other architectures).
>>
>> players:
>> void TargetFunc(some parameters);
>> void Hook(some parameters);
>>
>> method:
>> Grab first 5 bytes of TargetFunc. Back them up. Replace them with a jmp
>> Hook.
>>
>> Make Hook finish as follows:
>>    Restore the backup of 5 bytes.
>>    Call TargetFunc again, this time the real one, not the jmp.
>>    Replace the 5 bytes with jmp Hook, getting ready for the next
>> invocation.
>>
>> In a nutshell - typical trampoline.
>>
>> Now, I want to write a framework for this. I would prefer to be able to
>> have some code reuse. Can either mem_fn or bind be helpful here?
>
> No.
>
>> I'm trying to understand how they work. I feel like they are creating
>> extra 'functions' with some game about parameters. Ideas?

This of them more like structs that hold the data they need and call
it with operator (), not something you can pass. However, you can
build your own functions in memory, then cast a function pointer to
it. That is difficult to do correctly though, especially if you use
multiple platforms, however, if you do not mind the heavy weight of
it, you can use something like the rather awesome LLVM to build the
functions for you.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net