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

昆明企业网站制作灵璧县住房和城乡建设局网站

昆明企业网站制作,灵璧县住房和城乡建设局网站,宁波网站推广营销,衡东建设局网站有很多初始化方法我们通常都是在applicationDidFinishLaunching里一个个调用#xff0c;那么有没有办法像__attribute__((constructor))#xff0c;能够自动调用被修饰的函数#xff1f; 可以通过指定函数所在section的方式#xff0c;然后获取section开头去逐个调用。但是…有很多初始化方法我们通常都是在applicationDidFinishLaunching里一个个调用那么有没有办法像__attribute__((constructor))能够自动调用被修饰的函数 可以通过指定函数所在section的方式然后获取section开头去逐个调用。但是这种方法有个问题你只能获取到第一个函数的开头但是你不知道它的大小也就没有办法去依次获取了。 __attribute__((used, section(__TEXT, CustomInit))) void custom1() {NSLog(custom1); }__attribute__((used, section(__TEXT, CustomInit))) void custom2() {NSLog(custom2); }- (void)callCustom {Method orginalMethod class_getClassMethod([self class], _cmd);IMP imp method_getImplementation(orginalMethod);Dl_info info;if (dladdr((void *)imp, info)) {printf(dli_fname: %s\n, info.dli_fname);printf(dli_sname: %s\n, info.dli_sname);printf(dli_fbase: %p\n, info.dli_fbase);printf(dli_saddr: %p\n, info.dli_saddr);} else {printf(error: cant find that symbol.\n);}unsigned long funcSize 0;//CustomFunc段的开始uint8_t *funcStart getsectiondata((struct mach_header_64 *)info.dli_fbase, __TEXT, CustomInit, funcSize);((void(*)())funcStart)(); } 所以可以通过声明全局或者静态指针变量去持有这些函数把这些指针放到__DATA里自定义的一个段里因为指针大小都是8字节每次跳8字节就能访问到下一个指针了。 void custom1() {NSLog(custom1); }void(*customVar1)(void) __attribute__((used, section(__TEXT, CustomInit))) custom1;void custom2() {NSLog(custom2); }void(*customVar2)(void) __attribute__((used, section(__TEXT, CustomInit))) custom1;- (void)callCustom {Method orginalMethod class_getClassMethod([self class], _cmd);IMP imp method_getImplementation(orginalMethod);Dl_info info;if (dladdr((void *)imp, info)) {printf(dli_fname: %s\n, info.dli_fname);printf(dli_sname: %s\n, info.dli_sname);printf(dli_fbase: %p\n, info.dli_fbase);printf(dli_saddr: %p\n, info.dli_saddr);} else {printf(error: cant find that symbol.\n);}unsigned long size 0;uint8_t *start getsectiondata((struct mach_header_64 *)info.dli_fbase, __DATA, CustomInit, size);int funcCount size/sizeof(void *);for (int i0;ifuncCount; i) {//这里要用指针的指针void(**f)() (void(**)())start i;(*f)();} } 这样声明函数和变量太麻烦了我们可以使用宏来帮忙。 #define CustomInitFuncBegin(funcName) \ void funcName() {#define CustomInitFuncEnd(funcName) }\ static void (*funcName##_var)() __attribute__((used, section(__DATA, CustomInit))) funcName;CustomInitFuncBegin(init1) NSLog(测试init1\n); CustomInitFuncEnd(init1)CustomInitFuncBegin(init2); NSLog(测试init2\n); CustomInitFuncEnd(init2); (void)callCustom {Method orginalMethod class_getClassMethod([self class], _cmd);IMP imp method_getImplementation(orginalMethod);Dl_info info;if (dladdr((void *)imp, info)) {printf(dli_fname: %s\n, info.dli_fname);printf(dli_sname: %s\n, info.dli_sname);printf(dli_fbase: %p\n, info.dli_fbase);printf(dli_saddr: %p\n, info.dli_saddr);} else {printf(error: cant find that symbol.\n);}unsigned long size 0;uint8_t *start getsectiondata((struct mach_header_64 *)info.dli_fbase, __DATA, CustomInit, size);int funcCount size/sizeof(void *);for (int i0;ifuncCount; i) {void(**f)() (void(**)())start i;(*f)();} } 参考 https://everettjf.github.io/2017/03/06/a-method-of-delay-premain-code/
http://www.pierceye.com/news/292718/

相关文章:

  • 长沙网站排名优化如何在网站做电子杂志
  • 石家庄科技网站在线解压zip网站
  • 不良网站举报中心官网做网站必须买云虚拟主机吗
  • 网站建设实习wordpress 登陆 插件下载
  • 做耳鼻喉医院网站多少钱北京网站建设营销
  • 济南网站建设就选搜点网络ok外贸平台补贴政策
  • 网站建设 学校百度快照优化培训班
  • 做阀门的英文网站怎么写西安seo服务公司排名
  • 淘宝客网站如何做推广古董手表网站
  • 网站虚拟主机查询企业文化建设的内容有哪些
  • 财经大学网站建设apicloud wordpress
  • 平面设计网站排行榜刚进外贸公司一个月多少钱
  • 企业网站最下面的那栏叫啥广州编程培训机构哪里好
  • 怎么学建设网站网站建设敬请期待图片素材
  • 滴滴出行的网站是哪家公司做的新媒体营销课程心得体会
  • 中国室内设计师联盟网站浙江手机版建站系统开发
  • 网站开源代码模版广州公司注册核名查询系统官网
  • 海外网站seo丹阳市住房建设管理局网站
  • 定制公司网站沙市做网站weisword
  • 平湖模板网站建设公司网站建设项目报告书
  • 校园门户网站解决方案手机与电脑网站制作
  • 济南网站建设 伍际网络网站域名备案授权书
  • 网站开发销售提成网站建设的内部风险分析
  • 网站建设框架都有哪些内容公司名字大全参考2022
  • 成功备案的网站增加域名黄金网站
  • 学习网站开发多少钱北京网页设计公司兴田德润可以吗
  • 如何加强门户网站建设上海好的设计公司
  • h5企业模板网站模板营销推广的渠道方式
  • 怎么学做网站PHP百度搜索风云榜总榜
  • 网站风格模板公司建设官方网站