#include <cstdint>
#include <iostream>
#define ALIAS(fn) __attribute__ ((alias (#fn), used))
static char buf[256];
extern "C"
{
void* my_malloc(size_t size) {
std::cout << "custom mallocn";
return buf;
}
void my_free(void* p) {
std::cout << "custom freen";
}
void* malloc(size_t size) ALIAS(my_malloc);
void free(void* ptr) ALIAS(my_free);
}
struct S {
S() {}
uint32_t a;
}__attribute__((aligned(64)));
struct S1 {
uint32_t a;
};
int main() {
auto s = new S();
delete s;
}
[xxxxx@localhost test]$ g++ test.cc --std=c++17 -g3 -O0
[xxxxx@localhost test]$ ./a.out
custom free
[xxxxx@localhost test]$
最后
以上就是爱撒娇自行车最近收集整理的关于[开发杂项][编译][C/C++]function hook的全部内容,更多相关[开发杂项][编译][C/C++]function内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复