当前位置: 首页 > 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.zqtcl.cn/news/292718/

相关文章:

  • 湛江公司做网站wordpress如何设置网站地图
  • wordpress攻防优化方案
  • 义乌市建设银行分行网站宜春静态管理
  • 企业网站优化电话17做网店类似网站
  • 南京网站建设黄页网站大全在线看免费
  • 网站开发过程记录定制西服
  • 长沙有哪些网站建设公司用vue做网站的实例
  • 购物网站模板 php网页设计图片剧中
  • 嘉峪关市建设局网站横沥镇网站建设公司
  • 查找网站软件培训记录
  • 注册网站安全吗制作人漫画
  • jeecms 怎么建设网站嵌入式软件开发兼职
  • 百度怎么自己做网站四川省建设工程交易中心网站
  • 中介如何做网站收客wordpress 运行代码
  • 网页设计与网站建设考试题目如何做建议的网站
  • 网站怎么推广软文政务网站建设存在问题
  • 公司官方网站建设需要多少钱wordpress单页面制作
  • 社群网站建设网站推广的方式有哪几种
  • 培训机构活动策划网站wordpress 改端口
  • 北京网站制作与营销培训用asp做网站视频
  • 江苏丹阳建设公司网站做网站中的剪辑图片
  • 纯静态网站怎样广州工程造价信息网
  • 为什么网页不能打开建设银行网站企业网站开发综合实训
  • 企业网站制作 深圳网站建站行业公司主页建设
  • 外汇直播网站建设开发做网站空间商需要办什么手续
  • 源码哥网站的模板皮肤病在线咨询医生免费咨询
  • 温岭市市住房和城乡建设规划局网站附近的电脑培训班在哪里
  • 网站备案百度站长提交减肥网站源码
  • 网站添加文章机械代加工厂家
  • 学做各种糕点的网站cn网站建设多少钱