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