1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- //
- // RQAppEventAnnotation.m
- // jiaPei
- //
- // Created by 张嵘 on 2020/4/8.
- // Copyright © 2020 JCZ. All rights reserved.
- //
- #import "RQAppEventAnnotation.h"
- #include <mach-o/getsect.h>
- #include <mach-o/loader.h>
- #include <mach-o/dyld.h>
- #include <dlfcn.h>
- static NSArray<NSString *>* FFReadConfiguration(char *section)
- {
- NSMutableArray *configs = [NSMutableArray array];
-
- Dl_info info;
- dladdr(FFReadConfiguration, &info);
-
- #ifndef __LP64__
- // const struct mach_header *mhp = _dyld_get_image_header(0); // both works as below line
- const struct mach_header *mhp = (struct mach_header*)info.dli_fbase;
- unsigned long size = 0;
- uint32_t *memory = (uint32_t*)getsectiondata(mhp, "__DATA", section, & size);
- #else /* defined(__LP64__) */
- const struct mach_header_64 *mhp = (struct mach_header_64*)info.dli_fbase;
- unsigned long size = 0;
- uint64_t *memory = (uint64_t*)getsectiondata(mhp, "__DATA", section, & size);
- #endif /* defined(__LP64__) */
-
- for(int idx = 0; idx < size/sizeof(void*); ++idx){
- char *string = (char*)memory[idx];
-
- NSString *str = [NSString stringWithUTF8String:string];
- if(!str)continue;
-
- if(str) [configs addObject:str];
- }
-
- return configs;
-
- }
- @implementation RQAppEventAnnotation
- + (NSArray<NSString *> *)AnnotationModules
- {
- static NSArray<NSString *> *mods = nil;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- mods = FFReadConfiguration(RQAppEventModSectName);
- });
- return mods;
- }
- @end
|