问题描述
我需要介入一个C ++程序中的方法调用(该类驻留在一个单独的共享库中)。我想我可以使用LD_PRELOAD,但我不知道这将如何工作(我只找到C函数的例子):是否有一种方法来设置插入一个单一的方法,而不复制任何代码从插入类实现? p>
I need to interpose on a method call in a C++ program (the class resides in a separate shared library). I thought I could use LD_PRELOAD, but i am not sure how this would work (i only found examples of C functions): is there a way to setup interposition for a single method without copying over any code from the interposed class implementation?
推荐答案
它不会很便携,但你可以在C中写入你的插入函数,并给它的C ++方法的名称。你必须明确地处理这个参数,当然,但我认为所有的ELF ABI只是把它看作是一个看不见的第一个参数。
It wouldn't be very portable, but you could write your interposing function in C and give it the mangled name of the C++ method. You would have to handle the this parameter explicitly, of course, but I think all ELF ABIs just treat it as an invisible first argument.
这篇关于LD_PRELOAD用于C ++类方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!