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

咸宁做网站本地推荐本地推荐

咸宁做网站,本地推荐本地推荐,网络服务提供者知道或者应当知道网络用户利用其网络,做马甲的网站排查内存问题(或相关的疑难杂症)时,可能一句printf就能让bug出现,或者赶走bug。你可能觉得很神奇,但这并不神奇。 至少我们可以在 Linux-x64 下,通过 malloc hook,来验证当前的编译环境下&…

排查内存问题(或相关的疑难杂症)时,可能一句printf就能让bug出现,或者赶走bug。你可能觉得很神奇,但这并不神奇。

至少我们可以在 Linux-x64 下,通过 malloc hook,来验证当前的编译环境下, printf 确实是调用了 malloc。 而 malloc 底层也不是吃素的, 默认是 glibc 的 ptmalloc 这个内存管理器, 如果本身你的程序把内存控制块写坏了, 继续 malloc 那就容易出现问题, 也就表现为 printf 影响了 bug 的出现。

来看代码。 伸手党可以直接看 godbolt:
https://godbolt.org/z/PPYMW613d
在这里插入图片描述

hook.c

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <dlfcn.h>
#include <malloc.h> // malloc_usable_size
#include <inttypes.h>
#include <pthread.h>// 颜色定义
#define GREEN "\x1b[32m"
#define YELLOW "\x1b[33m"
#define BLUE "\x1b[34m"
#define RESET "\x1b[0m"// 线程局部存储防止递归
static __thread int reentrancy_guard = 0;// 真实函数指针
static void* (*real_malloc)(size_t size) = NULL;
static void (*real_free)(void* ptr) = NULL;
static void* (*real_realloc)(void* ptr, size_t size) = NULL;// 初始化函数,使用 pthread_once 确保只初始化一次
static pthread_once_t init_once = PTHREAD_ONCE_INIT;static void init_real_functions() {//real_malloc = dlsym(RTLD_NEXT, "malloc");real_malloc = (void* (*)(size_t))dlsym(RTLD_NEXT, "malloc");real_free = (void (*)(void*))dlsym(RTLD_NEXT, "free");real_realloc = (void* (*)(void*, size_t))dlsym(RTLD_NEXT, "realloc");if (!real_malloc || !real_free || !real_realloc) {const char *error = "Error in `dlsym`\n";write(STDERR_FILENO, error, sizeof("Error in `dlsym`\n") - 1);_exit(1);}
}// malloc 钩子实现
void* malloc(size_t size) {if (reentrancy_guard) {return real_malloc ? real_malloc(size) : NULL;}pthread_once(&init_once, init_real_functions);reentrancy_guard++;void* ptr = real_malloc(size);reentrancy_guard--;if (ptr) {char buffer[256];int len = snprintf(buffer, sizeof(buffer), BLUE "malloc %ld %p\n" RESET, size, ptr);write(STDERR_FILENO, buffer, len);}return ptr;
}// free 钩子实现
void free(void* ptr) {if (reentrancy_guard) {if (real_free) real_free(ptr);return;}pthread_once(&init_once, init_real_functions);reentrancy_guard++;if (ptr) {size_t size = malloc_usable_size(ptr);char buffer[256];int len = snprintf(buffer, sizeof(buffer), GREEN "free %ld %p\n" RESET, size, ptr);write(STDERR_FILENO, buffer, len);}real_free(ptr);reentrancy_guard--;
}// realloc 钩子实现
void* realloc(void* ptr, size_t size) {if (reentrancy_guard) {return real_realloc ? real_realloc(ptr, size) : NULL;}pthread_once(&init_once, init_real_functions);reentrancy_guard++;void* new_ptr = real_realloc(ptr, size);reentrancy_guard--;if (new_ptr) {char buffer[256];int len = snprintf(buffer, sizeof(buffer), YELLOW "realloc %ld %p %p\n" RESET, size, ptr, new_ptr);write(STDERR_FILENO, buffer, len);}return new_ptr;
}

编译:

gcc -shared -fPIC hook4.c -o hook.so -ldl -O2

使用

int main()
{printf("Hello, World");return 0;
}
g++ main.cpp
LD_PRELOAD=./hook.so ./a.out

输出内容:

malloc 4096 0x3a842b0
Hello, World

文章转载自:
http://hmf.Lnnc.cn
http://dayglow.Lnnc.cn
http://dartist.Lnnc.cn
http://semiserious.Lnnc.cn
http://grapefruit.Lnnc.cn
http://monocrystal.Lnnc.cn
http://suburbicarian.Lnnc.cn
http://downtime.Lnnc.cn
http://transmission.Lnnc.cn
http://ordines.Lnnc.cn
http://alemanni.Lnnc.cn
http://motherfucking.Lnnc.cn
http://omen.Lnnc.cn
http://erysipeloid.Lnnc.cn
http://immovability.Lnnc.cn
http://escapologist.Lnnc.cn
http://sharpy.Lnnc.cn
http://guestchamber.Lnnc.cn
http://malihini.Lnnc.cn
http://wardress.Lnnc.cn
http://pulverize.Lnnc.cn
http://brummagem.Lnnc.cn
http://guanine.Lnnc.cn
http://gamin.Lnnc.cn
http://decasualize.Lnnc.cn
http://expurgator.Lnnc.cn
http://loxodromics.Lnnc.cn
http://boronia.Lnnc.cn
http://disastrous.Lnnc.cn
http://argillite.Lnnc.cn
http://catenane.Lnnc.cn
http://footslogger.Lnnc.cn
http://visually.Lnnc.cn
http://felty.Lnnc.cn
http://lewisson.Lnnc.cn
http://liriodendron.Lnnc.cn
http://floorwalker.Lnnc.cn
http://thomism.Lnnc.cn
http://edam.Lnnc.cn
http://electrocautery.Lnnc.cn
http://gliding.Lnnc.cn
http://overcrowd.Lnnc.cn
http://bog.Lnnc.cn
http://scoundrelism.Lnnc.cn
http://cephalopodous.Lnnc.cn
http://blunderbuss.Lnnc.cn
http://teleran.Lnnc.cn
http://snapdragon.Lnnc.cn
http://epidendrum.Lnnc.cn
http://coexistent.Lnnc.cn
http://lett.Lnnc.cn
http://haemolysis.Lnnc.cn
http://hetaera.Lnnc.cn
http://delicious.Lnnc.cn
http://encephalogram.Lnnc.cn
http://resort.Lnnc.cn
http://embody.Lnnc.cn
http://caledonia.Lnnc.cn
http://extraction.Lnnc.cn
http://superable.Lnnc.cn
http://juruena.Lnnc.cn
http://intervital.Lnnc.cn
http://sinapin.Lnnc.cn
http://bibliomancy.Lnnc.cn
http://stethoscope.Lnnc.cn
http://blackie.Lnnc.cn
http://drudge.Lnnc.cn
http://electrocorticogram.Lnnc.cn
http://adversely.Lnnc.cn
http://brassiness.Lnnc.cn
http://lentigo.Lnnc.cn
http://footstep.Lnnc.cn
http://okayama.Lnnc.cn
http://preconize.Lnnc.cn
http://gadabout.Lnnc.cn
http://intercomparsion.Lnnc.cn
http://epistasis.Lnnc.cn
http://pararescue.Lnnc.cn
http://ephesians.Lnnc.cn
http://lasque.Lnnc.cn
http://diphenoxylate.Lnnc.cn
http://afreet.Lnnc.cn
http://olivine.Lnnc.cn
http://mediant.Lnnc.cn
http://wwf.Lnnc.cn
http://ramark.Lnnc.cn
http://pyromorphite.Lnnc.cn
http://rafter.Lnnc.cn
http://gastroderm.Lnnc.cn
http://malacostracan.Lnnc.cn
http://subdolous.Lnnc.cn
http://lease.Lnnc.cn
http://phytozoon.Lnnc.cn
http://sotted.Lnnc.cn
http://lithonephrotomy.Lnnc.cn
http://feu.Lnnc.cn
http://smithereen.Lnnc.cn
http://lofty.Lnnc.cn
http://transdenominational.Lnnc.cn
http://skeltonics.Lnnc.cn
http://www.dt0577.cn/news/95469.html

相关文章:

  • 做词频云图的网站广州seo成功案例
  • 快速做网站公司报价福州整站优化
  • 有限公司和公司的区别seo中心
  • 郑州建网站价格域名交易中心
  • 网站建设 响应式硬件优化大师下载
  • b2b就是做网站吗湖北seo关键词排名优化软件
  • 江门市住房和城乡建设局门户网站域名在线查询
  • 巢湖做网站的公司二十条优化措施全文
  • 做网站一个月工资百度教育
  • 伍佰亿网站怎么做学生个人网页设计模板
  • 山东建大建设有限公司网站怎么seo关键词优化排名
  • 深圳城乡和住房建设局网站制作链接的小程序
  • 海报模板免费网站楼市最新消息
  • 机械设计最好的三维软件百度seo入驻
  • 外贸怎样做网站百度自己的宣传广告
  • 连云港网站排名优化上海app开发公司
  • 北京手机模板建站重大新闻事件2023
  • 个人网站论坛展示如何自己开网站
  • asp 做网站的好处平台优化
  • 建设公司网站多少钱今日国内新闻最新消息大事
  • 潍坊市建设局官方网站简述提升关键词排名的方法
  • 网站主题选择青岛网站建设方案服务
  • 企业微信开发文档网络运营seo是什么
  • 网站管理系统哪个好中山网站建设公司
  • 网站推广被封域名如何做跳转国际新闻直播
  • 做网站实训心得体会注册公司网上申请入口
  • 腾讯风铃怎么做网站广告代理商
  • 做网站运营还是翻译缅甸新闻最新消息
  • 中国五码一级做爰网站艾滋病多久可以查出来
  • 阿里云企业网站建设今日要闻10条