-
Notifications
You must be signed in to change notification settings - Fork 1
/
AppController.m
103 lines (85 loc) · 3.69 KB
/
AppController.m
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#import "AppController.h"
#include <stdlib.h>
#import <IOKit/IOReturn.h>
#import <Kernel/libkern/OSReturn.h>
#import <DiskArbitration/DADissenter.h>
#import <IOBluetooth/IOBluetoothTypes.h>
#if 1
#define sub_iokit_hidsystem err_sub(14)
#else
#import <IOKit/hidsystem/IOHIDSystem.h>
#endif
#if 1
#define sub_iokit_pccard err_sub(21)
#else
#import <IOKit/pccard/IOPCCardBridge.h>
#endif
#define MAKE_OBJECT_AND_SYSTEM_KEY(VALUE) @#VALUE, [NSNumber numberWithInt:err_get_system(VALUE)]
#define MAKE_OBJECT_AND_SUBSYSTEM_KEY(VALUE) @#VALUE, [NSNumber numberWithInt:err_get_sub(VALUE)]
#define sub_unix_err err_sub(3) // Derived from unix_err().
@implementation AppController
- (id)init {
self = [super init];
if (self) {
mach_errorString = [[NSString alloc] init];
system = [[NSString alloc] init];
subsystem = [[NSString alloc] init];
code = [[NSString alloc] init];
systemLookup = [[NSDictionary alloc] initWithObjectsAndKeys:
MAKE_OBJECT_AND_SYSTEM_KEY(err_kern), // 0 0x0
MAKE_OBJECT_AND_SYSTEM_KEY(err_us), // 1 0x1
MAKE_OBJECT_AND_SYSTEM_KEY(err_server), // 2 0x2
MAKE_OBJECT_AND_SYSTEM_KEY(err_ipc), // 3 0x3
MAKE_OBJECT_AND_SYSTEM_KEY(err_mach_ipc), // 4 0x4
MAKE_OBJECT_AND_SYSTEM_KEY(err_dipc), // 7 0x7
MAKE_OBJECT_AND_SYSTEM_KEY(sys_libkern), // 55 0x37
MAKE_OBJECT_AND_SYSTEM_KEY(sys_iokit), // 56 0x38
MAKE_OBJECT_AND_SYSTEM_KEY(err_local), // 62 0x3e
MAKE_OBJECT_AND_SYSTEM_KEY(err_ipc_compat), // 63 0x3f
nil];
subsystemLookup = [[NSDictionary alloc] initWithObjectsAndKeys:
MAKE_OBJECT_AND_SUBSYSTEM_KEY(sub_iokit_common), // 0
MAKE_OBJECT_AND_SUBSYSTEM_KEY(sub_iokit_usb), // 1
MAKE_OBJECT_AND_SUBSYSTEM_KEY(sub_iokit_firewire), // 2
MAKE_OBJECT_AND_SUBSYSTEM_KEY(sub_unix_err), // 3
MAKE_OBJECT_AND_SUBSYSTEM_KEY(sub_iokit_block_storage), // 4
MAKE_OBJECT_AND_SUBSYSTEM_KEY(sub_iokit_graphics), // 5
MAKE_OBJECT_AND_SUBSYSTEM_KEY(sub_iokit_networking), // 6
MAKE_OBJECT_AND_SUBSYSTEM_KEY(sub_iokit_bluetooth), // 8
MAKE_OBJECT_AND_SUBSYSTEM_KEY(sub_iokit_pmu), // 9
MAKE_OBJECT_AND_SUBSYSTEM_KEY(sub_iokit_acpi), // 10
MAKE_OBJECT_AND_SUBSYSTEM_KEY(sub_iokit_smbus), // 11
MAKE_OBJECT_AND_SUBSYSTEM_KEY(sub_iokit_ahci), // 12
MAKE_OBJECT_AND_SUBSYSTEM_KEY(sub_iokit_hidsystem), // 14
MAKE_OBJECT_AND_SUBSYSTEM_KEY(sub_iokit_pccard), // 21
MAKE_OBJECT_AND_SUBSYSTEM_KEY(sub_iokit_vendor_specific), // -2
MAKE_OBJECT_AND_SUBSYSTEM_KEY(sub_iokit_reserved), // -1
nil];
}
return self;
}
- (void)setMach_errorString:(NSString*)mach_errorString_ {
if (mach_errorString != mach_errorString_) {
[mach_errorString release];
mach_errorString = [mach_errorString_ retain];
//--
if (mach_errorString) {
mach_error_t err = strtol([mach_errorString UTF8String], NULL, 0);
int systemCode = err_get_system(err);
NSString *systemName = [systemLookup objectForKey:[NSNumber numberWithInt:systemCode]];
[self setValue:[NSString stringWithFormat:@"%03d 0x%02x %@", systemCode, systemCode, systemName ? systemName : @"unknown system"]
forKey:@"system"];
int subsystemCode = err_get_sub(err);
NSString *subsystemName = [subsystemLookup objectForKey:[NSNumber numberWithInt:subsystemCode]];
[self setValue:[NSString stringWithFormat:@"%03d 0x%02x %@", subsystemCode, subsystemCode, subsystemName ? subsystemName : @"unknown subsystem"]
forKey:@"subsystem"];
int codeCode = err_get_code(err);
[self setValue:[NSString stringWithFormat:@"%03d 0x%02x", codeCode, codeCode]
forKey:@"code"];
}
}
}
- (void)applicationDidFinishLaunching:(NSNotification*)notification_ {
// Do me.
}
@end