RQAppEventAnnotation.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // RQAppEventAnnotation.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2020/4/8.
  6. // Copyright © 2020 JCZ. All rights reserved.
  7. //
  8. #import "RQAppEventAnnotation.h"
  9. #include <mach-o/getsect.h>
  10. #include <mach-o/loader.h>
  11. #include <mach-o/dyld.h>
  12. #include <dlfcn.h>
  13. static NSArray<NSString *>* FFReadConfiguration(char *section)
  14. {
  15. NSMutableArray *configs = [NSMutableArray array];
  16. Dl_info info;
  17. dladdr(FFReadConfiguration, &info);
  18. #ifndef __LP64__
  19. // const struct mach_header *mhp = _dyld_get_image_header(0); // both works as below line
  20. const struct mach_header *mhp = (struct mach_header*)info.dli_fbase;
  21. unsigned long size = 0;
  22. uint32_t *memory = (uint32_t*)getsectiondata(mhp, "__DATA", section, & size);
  23. #else /* defined(__LP64__) */
  24. const struct mach_header_64 *mhp = (struct mach_header_64*)info.dli_fbase;
  25. unsigned long size = 0;
  26. uint64_t *memory = (uint64_t*)getsectiondata(mhp, "__DATA", section, & size);
  27. #endif /* defined(__LP64__) */
  28. for(int idx = 0; idx < size/sizeof(void*); ++idx){
  29. char *string = (char*)memory[idx];
  30. NSString *str = [NSString stringWithUTF8String:string];
  31. if(!str)continue;
  32. if(str) [configs addObject:str];
  33. }
  34. return configs;
  35. }
  36. @implementation RQAppEventAnnotation
  37. + (NSArray<NSString *> *)AnnotationModules
  38. {
  39. static NSArray<NSString *> *mods = nil;
  40. static dispatch_once_t onceToken;
  41. dispatch_once(&onceToken, ^{
  42. mods = FFReadConfiguration(RQAppEventModSectName);
  43. });
  44. return mods;
  45. }
  46. @end