forked from roothide/XcodeAnyDebug
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.x
More file actions
84 lines (63 loc) · 2.21 KB
/
main.x
File metadata and controls
84 lines (63 loc) · 2.21 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
80
81
82
83
84
#import <Foundation/Foundation.h>
#import <dlfcn.h>
#import <roothide.h>
#define TAG "[XcodeAnyDebug] "
@interface DTDSLaunchTargetID : NSObject
- (instancetype)initWithUser:(uid_t)user group:(gid_t)group;
@end
@interface DTDSSpawnOptions : NSObject
@property (nonatomic, strong) DTDSLaunchTargetID *targetUserAndGroup;
@end
%group SMJob
static void* _SMJobSubmit;
%hookf(Boolean, _SMJobSubmit, CFStringRef domain, CFDictionaryRef job, CFTypeID auth, CFErrorRef *outError)
{
NSMutableDictionary* mjob = [(__bridge NSDictionary*)job mutableCopy];
if (job != nil && mjob[@"ProgramArguments"] != nil)
{
NSArray* argv = mjob[@"ProgramArguments"];
NSLog(@TAG "_SMJobSubmit argv=%@", argv);
if ([argv[0] hasSuffix:@"/debugserver"])
{
NSMutableArray* new_argv = [argv mutableCopy];
new_argv[0] = jbroot(@"/usr/bin/xcodeanydebug/debugserver");
mjob[@"UserName"] = @"root";
mjob[@"ProgramArguments"] = new_argv;
}
job = (__bridge_retained CFDictionaryRef)mjob;
}
return %orig;
}
%end
%group Dtds
static void* _dtdsSpawnExecutableWithOptions;
%hookf(Boolean, _dtdsSpawnExecutableWithOptions, const char *path, DTDSSpawnOptions *options, pid_t *pid, NSError **error)
{
NSLog(@TAG "_dtdsSpawnExecutableWithOptions path=%s", path);
if ([[NSString stringWithUTF8String:path] hasSuffix:@"/debugserver"])
{
DTDSLaunchTargetID *target = [[%c(DTDSLaunchTargetID) alloc] initWithUser:0 group:0];
[options setTargetUserAndGroup:target];
NSString *newPath = jbroot(@"/usr/bin/xcodeanydebug/debugserver");
return %orig([newPath UTF8String], options, pid, error);
}
return %orig;
}
%end
%ctor {
BOOL isDtds = NO;
for (NSString* arg in [[NSProcessInfo processInfo] arguments]) {
if ([arg hasSuffix:@"dtdebugproxyd"]) {
isDtds = YES;
break;
}
}
NSLog(@TAG "isDtds=%@", isDtds ? @"YES" : @"NO");
if (isDtds) {
_dtdsSpawnExecutableWithOptions = dlsym(RTLD_DEFAULT, "dtdsSpawnExecutableWithOptions");
%init(Dtds);
} else {
_SMJobSubmit = dlsym(RTLD_DEFAULT, "SMJobSubmit");
%init(SMJob);
}
}