FIRCLSdSYM.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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/FIRCLSdSYM.h"
  15. #import "Crashlytics/Shared/FIRCLSMachO/FIRCLSMachOBinary.h"
  16. #define CLS_XCODE_DSYM_PREFIX (@"com.apple.xcode.dsym.")
  17. @interface FIRCLSdSYM ()
  18. @property(nonatomic, readonly) NSBundle* bundle;
  19. @end
  20. @implementation FIRCLSdSYM
  21. + (id)dSYMWithURL:(NSURL*)url {
  22. return [[self alloc] initWithURL:url];
  23. }
  24. - (id)initWithURL:(NSURL*)url {
  25. self = [super init];
  26. if (self) {
  27. NSDirectoryEnumerator* enumerator;
  28. NSString* path;
  29. NSFileManager* fileManager;
  30. BOOL isDirectory;
  31. BOOL fileExistsAtPath;
  32. NSArray* itemsInDWARFDir;
  33. fileManager = [NSFileManager defaultManager];
  34. // Is there a file at this path?
  35. if (![fileManager fileExistsAtPath:[url path]]) {
  36. return nil;
  37. }
  38. _bundle = [NSBundle bundleWithURL:url];
  39. if (!_bundle) {
  40. return nil;
  41. }
  42. path = [[url path] stringByAppendingPathComponent:@"Contents/Resources/DWARF"];
  43. // Does this path exist and is it a directory?
  44. fileExistsAtPath = [fileManager fileExistsAtPath:path isDirectory:&isDirectory];
  45. if (!fileExistsAtPath || !isDirectory) {
  46. return nil;
  47. }
  48. enumerator = [fileManager enumeratorAtPath:path];
  49. itemsInDWARFDir = [enumerator allObjects];
  50. // Do we have a Contents/Resources/DWARF dir but no contents?
  51. if ([itemsInDWARFDir count] == 0) {
  52. return nil;
  53. }
  54. path = [path stringByAppendingPathComponent:[itemsInDWARFDir objectAtIndex:0]];
  55. _binary = [[FIRCLSMachOBinary alloc] initWithURL:[NSURL fileURLWithPath:path]];
  56. }
  57. return self;
  58. }
  59. - (NSString*)bundleIdentifier {
  60. NSString* identifier;
  61. identifier = [_bundle bundleIdentifier];
  62. if ([identifier hasPrefix:CLS_XCODE_DSYM_PREFIX]) {
  63. return [identifier substringFromIndex:[CLS_XCODE_DSYM_PREFIX length]];
  64. }
  65. return identifier;
  66. }
  67. - (NSURL*)executableURL {
  68. return [_binary URL];
  69. }
  70. - (NSString*)executablePath {
  71. return [_binary path];
  72. }
  73. - (NSString*)bundleVersion {
  74. return [[_bundle infoDictionary] objectForKey:@"CFBundleVersion"];
  75. }
  76. - (NSString*)shortBundleVersion {
  77. return [[_bundle infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  78. }
  79. - (void)enumerateUUIDs:(void (^)(NSString* uuid, NSString* architecture))block {
  80. [_binary enumerateUUIDs:block];
  81. }
  82. @end