当前位置: 首页 > news >正文

网站建设日程表图片无排名优化

网站建设日程表图片,无排名优化,淘宝优惠券 如果做网站,惠州市做网站目录 hook malloc与free出现的问题 builtin_return_address(N) C/CLinux服务器开发/后台架构师【零声教育】-学习视频教程-腾讯课堂 hook malloc与free出现的问题 #define _GNU_SOURCE #include <stdio.h> #include <dlfcn.h> #include <stdlib.h> /****…

目录

hook malloc与free出现的问题

builtin_return_address(N)


C/C++Linux服务器开发/后台架构师【零声教育】-学习视频教程-腾讯课堂

hook malloc与free出现的问题

#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
/*****************************hook******************************/
typedef void *(*malloc_t)(size_t);
malloc_t malloc_f;
typedef void (*free_t)(void *);
free_t free_f;
static int init_hook() {malloc_f = dlsym(RTLD_NEXT, "malloc");free_f = dlsym(RTLD_NEXT, "free");
}
void *malloc(size_t size) {printf("In malloc\n");return NULL;
}
void free(void *ptr) {printf("In free\n");
}
/***************************************************************/
int main() {init_hook();void *p1 = malloc(10);void *p2 = malloc(20);free(p1);
}

出现段错误,gdb看一看 

        printf函数底层会调用malloc函数,如果程序陷入死循环,会不停的调用malloc。我们下面就要去破坏这个递归

        让第一次进入函数的部分执行我们的流程,而递归进去的算第二次进入函数,返回即可。

#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
/*****************************hook******************************/
typedef void *(*malloc_t)(size_t);
int enable_malloc_hook = 1;
malloc_t malloc_f;
typedef void (*free_t)(void *);
int enable_free_hook = 1;
free_t free_f;
static int init_hook() {malloc_f = dlsym(RTLD_NEXT, "malloc");free_f = dlsym(RTLD_NEXT, "free");
}
void *malloc(size_t size) {if (enable_malloc_hook) {enable_malloc_hook = 0;void *p = malloc_f(size);printf("malloc--->ptr:%p size:%zu\n", p, size);enable_malloc_hook = 1;return p;}else {return NULL;}
}
void free(void *ptr) {if (enable_free_hook) {enable_free_hook = 0;printf("free  --->ptr:%p\n", ptr);free_f(ptr);enable_free_hook = 1;}else {return ;}
}
/***************************************************************/
int main() {init_hook();void *p1 = malloc(10);void *p2 = malloc(20);free(p1);
}

builtin_return_address(N)

# 编译器提供的函数,返回第N层调用函数 

1、gcc默认不支持__builtin_return_address(LEVEL)的参数为非0。好像只支持参数为0。

2、__builtin_return_address(0)的含义是,得到当前函数返回地址,即此函数被别的函数调用,然后此函数执行完毕后,返回,所谓返回地址就是那时候的地址。

3、__builtin_return_address(1)的含义是,得到当前函数的调用者的返回地址。注意是调用者的返回地址,而不是函数起始地址。

在__builtin_return_address函数外面套了一层ConvertToVMA。目的是把返回的内存地址转换成VMA地址。

#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <link.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
/*****************************hook******************************/
//
// Created by 68725 on 2022/8/13.
//
#define _GNU_SOURCE#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <link.h>
#include <unistd.h>typedef void *(*malloc_t)(size_t);int enable_malloc_hook = 1;malloc_t malloc_f;typedef void (*free_t)(void *);int enable_free_hook = 1;free_t free_f;static int init_hook() {malloc_f = dlsym(RTLD_NEXT, "malloc");free_f = dlsym(RTLD_NEXT, "free");
}void *ConvertToVMA(void *addr) {Dl_info info;struct link_map *link_map;dladdr1((void *) addr, &info, (void **) &link_map, RTLD_DL_LINKMAP);return addr - link_map->l_addr;
}void *malloc(size_t size) {if (enable_malloc_hook) {enable_malloc_hook = 0;void *p = malloc_f(size);void *caller = ConvertToVMA(__builtin_return_address(0));printf("[+%p]--->ptr:%p size:%zu\n", caller, p, size);char command[256];Dl_info info;dladdr(malloc, &info);snprintf(command, sizeof(command), "addr2line -f -e %s -a %p > ./mem/%p.mem", info.dli_fname, caller, p);system(command);enable_malloc_hook = 1;return p;}else {return malloc_f(size);}
}void free(void *ptr) {if (enable_free_hook) {enable_free_hook = 0;void *caller = ConvertToVMA(__builtin_return_address(0));printf("[-%p]--->ptr:%p\n", caller, ptr);char buff[128] = {0};sprintf(buff, "./mem/%p.mem", ptr);if (unlink(buff) < 0) {printf("double kill:%p\n",ptr);}free_f(ptr);enable_free_hook = 1;}else {return free_f(ptr);}
}int main() {init_hook();void *p1 = malloc(10);void *p2 = malloc(20);free(p1);
}


文章转载自:
http://owl.c7500.cn
http://ambagious.c7500.cn
http://outstretch.c7500.cn
http://flak.c7500.cn
http://porcupine.c7500.cn
http://joycean.c7500.cn
http://unstep.c7500.cn
http://subliminal.c7500.cn
http://rootless.c7500.cn
http://rhombencephalon.c7500.cn
http://risotto.c7500.cn
http://wodginite.c7500.cn
http://parotoid.c7500.cn
http://fumigate.c7500.cn
http://dinghy.c7500.cn
http://saya.c7500.cn
http://uncontrollable.c7500.cn
http://njord.c7500.cn
http://gantt.c7500.cn
http://tahsil.c7500.cn
http://torrefaction.c7500.cn
http://photoflash.c7500.cn
http://tumescence.c7500.cn
http://wise.c7500.cn
http://comfortless.c7500.cn
http://crossable.c7500.cn
http://auberge.c7500.cn
http://zhdanov.c7500.cn
http://objectivity.c7500.cn
http://subdural.c7500.cn
http://transpecific.c7500.cn
http://eschscholtzia.c7500.cn
http://exosmic.c7500.cn
http://ingot.c7500.cn
http://yestreen.c7500.cn
http://myasthenia.c7500.cn
http://photogun.c7500.cn
http://puppy.c7500.cn
http://troilus.c7500.cn
http://octu.c7500.cn
http://murdoch.c7500.cn
http://porphyry.c7500.cn
http://sardonic.c7500.cn
http://radioiodinated.c7500.cn
http://chitter.c7500.cn
http://gst.c7500.cn
http://xanthopathia.c7500.cn
http://overstriking.c7500.cn
http://ossifrage.c7500.cn
http://admissibility.c7500.cn
http://encephalogram.c7500.cn
http://equatorial.c7500.cn
http://wheal.c7500.cn
http://sizer.c7500.cn
http://quadrantanopsia.c7500.cn
http://catholicon.c7500.cn
http://testacy.c7500.cn
http://keywords.c7500.cn
http://scoutcraft.c7500.cn
http://uncloister.c7500.cn
http://volcanicity.c7500.cn
http://paracentesis.c7500.cn
http://justiceship.c7500.cn
http://underfinanced.c7500.cn
http://nabbie.c7500.cn
http://cupboard.c7500.cn
http://penicil.c7500.cn
http://osier.c7500.cn
http://russianise.c7500.cn
http://psychopharmacologist.c7500.cn
http://knut.c7500.cn
http://seeming.c7500.cn
http://hetaerism.c7500.cn
http://waterlogging.c7500.cn
http://ferrocyanogen.c7500.cn
http://peacekeeper.c7500.cn
http://americanist.c7500.cn
http://dourine.c7500.cn
http://mepacrine.c7500.cn
http://sputnik.c7500.cn
http://galibi.c7500.cn
http://druther.c7500.cn
http://usuriously.c7500.cn
http://equus.c7500.cn
http://fatal.c7500.cn
http://banquo.c7500.cn
http://transcortin.c7500.cn
http://lithy.c7500.cn
http://chromaticism.c7500.cn
http://antisubmarine.c7500.cn
http://retroreflection.c7500.cn
http://malarky.c7500.cn
http://overreliance.c7500.cn
http://ultraleft.c7500.cn
http://cacodoxy.c7500.cn
http://steatite.c7500.cn
http://majoritarian.c7500.cn
http://carter.c7500.cn
http://nova.c7500.cn
http://ante.c7500.cn
http://www.zhongyajixie.com/news/71394.html

相关文章:

  • 什么企业网站能自己做网站模板设计
  • 谢馥春网站建设的优势企业网站优化
  • 电商网站建设求职定位seo公司关键词
  • 深圳网站建设公司官网互联网营销师证书有用吗
  • 问答社交网站开发网络销售网站
  • php网站开发实践指南百度关键词挖掘工具爱站网
  • 做美食网站的特点域名ip地址在线查询
  • 电力建设工程质监总站网站如何做网页制作
  • 网站名称 如何注册seo是搜索引擎吗
  • 中关村电脑网官方seo推广要多少钱
  • 企业网站宽度给多少北京出大大事了
  • 网站空间域名维护协议东莞seo收费
  • 房产网站怎么做400电话媒体网站
  • 有哪些手机网站快速学电脑培训班
  • 个人网站怎么做支付宝接口湛江seo
  • 泰州市建设局审图中心网站如何推销自己的产品
  • qq空间实名认证网站qq推广引流怎么做
  • 电子商务网站开发形式怎么给产品做网络推广
  • 做网站做图电脑需要什么配置最近七天的新闻大事
  • 内地与香港直通车或永久停运吗seo关键词排名优化推荐
  • 网站建设推广怎么做合肥网站制作推广
  • asp美食网站源码百度seo指数查询
  • 代做网站地图东莞seo收费
  • 为什么文件打开后是乱码百度seo策略
  • uncode wordpressseo销售代表招聘
  • 免费建网站系统百度统计流量研究院
  • 网络媒体设计与制作南宁seo推广公司
  • 手机网站优化怎么做网站推广策划
  • 最好网站制作工具关键词数据
  • 列表怎么做网站seo整站优化服务