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/FIRCLSMachOSlice.h"
|
|
|
16 |
|
|
|
17 |
#include <mach-o/loader.h>
|
|
|
18 |
|
|
|
19 |
// this is defined only if __OPEN_SOURCE__ is *not* defined in the TVOS SDK's mach-o/loader.h
|
|
|
20 |
// also, it has not yet made it back to the OSX SDKs, for example
|
|
|
21 |
#ifndef LC_VERSION_MIN_TVOS
|
|
|
22 |
#define LC_VERSION_MIN_TVOS 0x2F
|
|
|
23 |
#endif
|
|
|
24 |
|
|
|
25 |
@implementation FIRCLSMachOSlice
|
|
|
26 |
|
|
|
27 |
+ (id)runningSlice {
|
|
|
28 |
struct FIRCLSMachOSlice slice;
|
|
|
29 |
|
|
|
30 |
slice = FIRCLSMachOSliceGetCurrent();
|
|
|
31 |
|
|
|
32 |
return [[self alloc] initWithSlice:&slice];
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
@synthesize minimumOSVersion = _minimumOSVersion;
|
|
|
36 |
@synthesize linkedSDKVersion = _linkedSDKVersion;
|
|
|
37 |
|
|
|
38 |
- (id)initWithSlice:(FIRCLSMachOSliceRef)sliceRef {
|
|
|
39 |
self = [super init];
|
|
|
40 |
if (self) {
|
|
|
41 |
NSMutableArray* dylibs;
|
|
|
42 |
|
|
|
43 |
_slice = *sliceRef;
|
|
|
44 |
|
|
|
45 |
_minimumOSVersion.major = 0;
|
|
|
46 |
_minimumOSVersion.minor = 0;
|
|
|
47 |
_minimumOSVersion.bugfix = 0;
|
|
|
48 |
|
|
|
49 |
_linkedSDKVersion.major = 0;
|
|
|
50 |
_linkedSDKVersion.minor = 0;
|
|
|
51 |
_linkedSDKVersion.bugfix = 0;
|
|
|
52 |
|
|
|
53 |
dylibs = [NSMutableArray array];
|
|
|
54 |
|
|
|
55 |
FIRCLSMachOSliceEnumerateLoadCommands(
|
|
|
56 |
&_slice, ^(uint32_t type, uint32_t size, const struct load_command* cmd) {
|
|
|
57 |
switch (type) {
|
|
|
58 |
case LC_UUID:
|
|
|
59 |
self->_uuidString =
|
|
|
60 |
[FIRCLSMachONormalizeUUID((CFUUIDBytes*)FIRCLSMachOGetUUID(cmd)) copy];
|
|
|
61 |
break;
|
|
|
62 |
case LC_LOAD_DYLIB:
|
|
|
63 |
[dylibs addObject:[NSString stringWithUTF8String:FIRCLSMachOGetDylibPath(cmd)]];
|
|
|
64 |
break;
|
|
|
65 |
case LC_VERSION_MIN_IPHONEOS:
|
|
|
66 |
case LC_VERSION_MIN_MACOSX:
|
|
|
67 |
case LC_VERSION_MIN_WATCHOS:
|
|
|
68 |
case LC_VERSION_MIN_TVOS:
|
|
|
69 |
self->_minimumOSVersion = FIRCLSMachOGetMinimumOSVersion(cmd);
|
|
|
70 |
self->_linkedSDKVersion = FIRCLSMachOGetLinkedSDKVersion(cmd);
|
|
|
71 |
break;
|
|
|
72 |
}
|
|
|
73 |
});
|
|
|
74 |
|
|
|
75 |
_linkedDylibs = [dylibs copy];
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
return self;
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
- (NSString*)architectureName {
|
|
|
82 |
return [NSString stringWithUTF8String:FIRCLSMachOSliceGetArchitectureName(&_slice)];
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
- (NSString*)uuid {
|
|
|
86 |
return _uuidString;
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
- (NSArray*)linkedDylibs {
|
|
|
90 |
return _linkedDylibs;
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
@end
|