FIRCLSMachOSlice.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright 2019 Google
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "Crashlytics/Shared/FIRCLSMachO/FIRCLSMachOSlice.h"
  15. #include <mach-o/loader.h>
  16. // this is defined only if __OPEN_SOURCE__ is *not* defined in the TVOS SDK's mach-o/loader.h
  17. // also, it has not yet made it back to the OSX SDKs, for example
  18. #ifndef LC_VERSION_MIN_TVOS
  19. #define LC_VERSION_MIN_TVOS 0x2F
  20. #endif
  21. @implementation FIRCLSMachOSlice
  22. + (id)runningSlice {
  23. struct FIRCLSMachOSlice slice;
  24. slice = FIRCLSMachOSliceGetCurrent();
  25. return [[self alloc] initWithSlice:&slice];
  26. }
  27. @synthesize minimumOSVersion = _minimumOSVersion;
  28. @synthesize linkedSDKVersion = _linkedSDKVersion;
  29. - (id)initWithSlice:(FIRCLSMachOSliceRef)sliceRef {
  30. self = [super init];
  31. if (self) {
  32. NSMutableArray* dylibs;
  33. _slice = *sliceRef;
  34. _minimumOSVersion.major = 0;
  35. _minimumOSVersion.minor = 0;
  36. _minimumOSVersion.bugfix = 0;
  37. _linkedSDKVersion.major = 0;
  38. _linkedSDKVersion.minor = 0;
  39. _linkedSDKVersion.bugfix = 0;
  40. dylibs = [NSMutableArray array];
  41. FIRCLSMachOSliceEnumerateLoadCommands(
  42. &_slice, ^(uint32_t type, uint32_t size, const struct load_command* cmd) {
  43. switch (type) {
  44. case LC_UUID:
  45. self->_uuidString =
  46. [FIRCLSMachONormalizeUUID((CFUUIDBytes*)FIRCLSMachOGetUUID(cmd)) copy];
  47. break;
  48. case LC_LOAD_DYLIB:
  49. [dylibs addObject:[NSString stringWithUTF8String:FIRCLSMachOGetDylibPath(cmd)]];
  50. break;
  51. case LC_VERSION_MIN_IPHONEOS:
  52. case LC_VERSION_MIN_MACOSX:
  53. case LC_VERSION_MIN_WATCHOS:
  54. case LC_VERSION_MIN_TVOS:
  55. self->_minimumOSVersion = FIRCLSMachOGetMinimumOSVersion(cmd);
  56. self->_linkedSDKVersion = FIRCLSMachOGetLinkedSDKVersion(cmd);
  57. break;
  58. }
  59. });
  60. _linkedDylibs = [dylibs copy];
  61. }
  62. return self;
  63. }
  64. - (NSString*)architectureName {
  65. return [NSString stringWithUTF8String:FIRCLSMachOSliceGetArchitectureName(&_slice)];
  66. }
  67. - (NSString*)uuid {
  68. return _uuidString;
  69. }
  70. - (NSArray*)linkedDylibs {
  71. return _linkedDylibs;
  72. }
  73. @end