-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathips2crash.m
More file actions
79 lines (70 loc) · 2.46 KB
/
ips2crash.m
File metadata and controls
79 lines (70 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#import <Foundation/Foundation.h>
#import <libgen.h>
// TODO: looks like OSATransformOptionTracerURL can be used for
// symbolication, somehow.
extern NSString * const OSATransformOptionFullReport;
extern NSString * const OSATransformResultError;
extern NSString * const OSATransformResultReport;
// Private API from OSAnalytics.framework
@interface OSALegacyXform : NSObject
+ (NSDictionary *)transformURL:(NSURL *)url options:(NSDictionary *)options;
@end
int main(int argc, char *argv[])
{
NSString *ipsPath = nil;
NSString *outputPath = nil;
if (argc == 2) {
ipsPath = @(argv[1]);
} else if (argc == 3) {
ipsPath = @(argv[1]);
outputPath = @(argv[2]);
if ([@"-" isEqualToString:outputPath]) {
outputPath = nil;
}
} else {
fprintf(stderr, "usage: %s <ips-path> [<output-path>]\n", basename(argv[0]));
exit(1);
}
NSURL* ipsUrl = [NSURL fileURLWithPath:ipsPath];
// use OSALegacyXform to transform the IPS file
NSDictionary *options = @{OSATransformOptionFullReport: @YES};
NSDictionary *transformed = [OSALegacyXform transformURL:ipsUrl options:options];
if (![transformed isKindOfClass:[NSDictionary class]]) {
fprintf(stderr, "error: unknown transformation failure\n");
exit(1);
}
// handle errors
NSError *error = transformed[OSATransformResultError];
if (error) {
if ([error isKindOfClass:[NSError class]]) {
fprintf(stderr, "error: %s\n", error.localizedDescription.UTF8String);
} else {
fprintf(stderr, "error: unknown transformation failure\n");
}
exit(1);
}
// get transformed result
NSString *result = transformed[OSATransformResultReport];
if (![result isKindOfClass:[NSString class]]) {
fprintf(stderr, "error: result missing\n");
exit(1);
}
if (outputPath == nil) {
printf("%s", result.UTF8String);
} else {
NSError *writeError = nil;
BOOL didWrite = [result writeToFile:outputPath
atomically:YES
encoding:NSUTF8StringEncoding
error:&writeError];
if (!didWrite) {
fprintf(
stderr,
"error: could not write to %s: %s\n",
outputPath.UTF8String,
writeError.localizedDescription.UTF8String
);
exit(1);
}
}
}