Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Archiving apps with iOS 9 #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Switch to get for archiving
= committed Apr 11, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit baaf6f78bf2700add4e9d3e56a0d584da6f3164b
140 changes: 58 additions & 82 deletions SBServerTweak/SBServerTweak/SBSTHTTPServer.m
Original file line number Diff line number Diff line change
@@ -428,106 +428,82 @@ - (void)setupRoutes {
[response setStatusCode:[responseDict[RESPONSE_CODE] integerValue]];
}];

[self.http post:@"/archive" withBlock:^(RouteRequest *request, RouteResponse *response) {
[self.http get:@"/archive/:bundleId" withBlock:^(RouteRequest *request, RouteResponse *response) {
NSMutableDictionary *responseDict = [self _defaultResponseDict];

NSData *requestBody = request.body;
NSMutableDictionary *info = [NSMutableDictionary dictionaryWithCapacity:9];
if (requestBody==nil) {

NSString *bundleId = [request param:@"bundleId"];;
if ([bundleId length] == 0) {
responseDict[RESPONSE_CODE] = HTTP_CODE_BAD_REQUEST;
responseDict[RESPONSE_MESSAGE] = @"empty request";
} else {
NSError *error;
NSDictionary *requestDict = [NSJSONSerialization JSONObjectWithData:requestBody
options:0
error:&error];
DDLogVerbose(@"RequestDict: %@", requestDict);
DDLogVerbose(@"Error: %@", error);
responseDict[RESPONSE_MESSAGE] = @"bundleId missing";
[self sendResponse:response dict:responseDict];
return;
}

NSString *bundleId = requestDict[@"bundleId"];
if ([bundleId length] == 0) {
responseDict[RESPONSE_CODE] = HTTP_CODE_BAD_REQUEST;
responseDict[RESPONSE_MESSAGE] = @"bundleId missing";
[self sendResponse:response dict:responseDict];
return;
}
if ([self getApplicationInfo:info bundleId:bundleId] == NO) {
responseDict[RESPONSE_CODE] = HTTP_CODE_BAD_REQUEST;
responseDict[RESPONSE_MESSAGE] = @"Cannot get app info";
[self sendResponse:response dict:responseDict];
return;
}

if ([self getApplicationInfo:info bundleId:bundleId] == NO) {
responseDict[RESPONSE_CODE] = HTTP_CODE_BAD_REQUEST;
responseDict[RESPONSE_MESSAGE] = @"Cannot get app info";
[self sendResponse:response dict:responseDict];
return;
}
if (info[@"BUNDLE_PATH"]) {
NSString *cmd = [NSString stringWithFormat:@"%@; %@; %@; cp -r %@/*.app/ Payload/; cp %@/iTunes* .; %@; %@; %@%@.ipa",
@"mkdir /tmp/apparchive",
@"cd /tmp/apparchive",
@"mkdir Payload",
info[@"BUNDLE_PATH"],
info[@"BUNDLE_PATH"],
@"zip -r tmp Payload/ iTunes*",
@"rm -R Payload/ iTunes*",
@"mv tmp.zip /tmp/apparchive/",
info[@"APP_ID"]];
NSString *cmd2 = [NSString stringWithFormat:@"cd /var/root; DYLD_INSERT_LIBRARIES=dumpdecrypted.dylib '%@/%@'", info[@"APP_PATH"], info[@"EXECUTABLE"]];
[SBSTShellExecutor runCommand:cmd2];
DDLogVerbose(@"CMD: %@", cmd);
NSDictionary *result = [SBSTShellExecutor runCommand:cmd];
DDLogVerbose(@"Result: %@", result);
responseDict[@"file"] = [NSString stringWithFormat:@"/tmp/apparchive/%@.ipa", info[@"APP_ID"]];

if (info[@"BUNDLE_PATH"]) {
NSString *cmd = [NSString stringWithFormat:@"%@; %@; %@; cp -r %@/*.app/ Payload/; cp %@/iTunes* .; %@; %@; %@%@.ipa",
@"mkdir /tmp/apparchive",
@"cd /tmp/apparchive",
@"mkdir Payload",
info[@"BUNDLE_PATH"],
info[@"BUNDLE_PATH"],
@"zip -r tmp Payload/ iTunes*",
@"rm -R Payload/ iTunes*",
@"mv tmp.zip /tmp/apparchive/",
info[@"APP_ID"]];
NSString *cmd2 = [NSString stringWithFormat:@"cd /var/root; DYLD_INSERT_LIBRARIES=dumpdecrypted.dylib '%@/%@'", info[@"APP_PATH"], info[@"EXECUTABLE"]];
[SBSTShellExecutor runCommand:cmd2];
DDLogVerbose(@"CMD: %@", cmd);
NSDictionary *result = [SBSTShellExecutor runCommand:cmd];
DDLogVerbose(@"Result: %@", result);
responseDict[@"file"] = [NSString stringWithFormat:@"/tmp/apparchive/%@.ipa", info[@"APP_ID"]];

[response setHeader:@"Content-Type" value:@"application/json"];
} else {
responseDict[RESPONSE_CODE] = HTTP_CODE_BAD_REQUEST;
responseDict[RESPONSE_MESSAGE] = @"Bundle not found";
}
[self sendResponse:response dict:responseDict];
[response setHeader:@"Content-Type" value:@"application/json"];
} else {
responseDict[RESPONSE_CODE] = HTTP_CODE_BAD_REQUEST;
responseDict[RESPONSE_MESSAGE] = @"Bundle not found";
}
[self sendResponse:response dict:responseDict];
}];

[self.http post:@"/archive/decrypted" withBlock:^(RouteRequest* request, RouteResponse* response) {
[self.http get:@"/archive/decrypted/:bundleId" withBlock:^(RouteRequest* request, RouteResponse* response) {
NSMutableDictionary *responseDict = [self _defaultResponseDict];

NSData *requestBody = request.body;
NSMutableDictionary *info = [NSMutableDictionary dictionaryWithCapacity:9];
if (requestBody == nil) {
responseDict[RESPONSE_CODE] = HTTP_CODE_BAD_REQUEST;
responseDict[RESPONSE_MESSAGE] = @"empty request";
} else {
NSError *error;
NSDictionary *requestDict = [NSJSONSerialization JSONObjectWithData:requestBody
options:0
error:&error];
DDLogVerbose(@"RequestDict: %@", requestDict);
DDLogVerbose(@"Error: %@", error);

NSString *bundleId = requestDict[@"bundleId"];
if ([bundleId length] == 0) {
responseDict[RESPONSE_CODE] = HTTP_CODE_BAD_REQUEST;
responseDict[RESPONSE_MESSAGE] = @"bundleId missing";
[self sendResponse:response dict:responseDict];
return;
}
NSString *bundleId = [request param:@"bundleId"];
if ([bundleId length] == 0) {
responseDict[RESPONSE_CODE] = HTTP_CODE_BAD_REQUEST;
responseDict[RESPONSE_MESSAGE] = @"bundleId missing";
[self sendResponse:response dict:responseDict];
return;
}

if ([self getApplicationInfo:info bundleId:bundleId] == NO) {
responseDict[RESPONSE_CODE] = HTTP_CODE_BAD_REQUEST;
responseDict[RESPONSE_MESSAGE] = @"Cannot get app info";
[self sendResponse:response dict:responseDict];
return;
}
if ([self getApplicationInfo:info bundleId:bundleId] == NO) {
responseDict[RESPONSE_CODE] = HTTP_CODE_BAD_REQUEST;
responseDict[RESPONSE_MESSAGE] = @"Cannot get app info";
[self sendResponse:response dict:responseDict];
return;
}

NSString *cmd = [NSString stringWithFormat:@"%@; sudo Clutch2 -d %2$@; %@; mv /var/mobile/Documents/Dumped/%2$@* /tmp/apparchive/%[email protected]",
@"mkdir /tmp/apparchive",
bundleId,
@"sudo chown mobile -R /var/mobile/Documents/Dumped"];
DDLogVerbose(@"CMD: %@", cmd);
system([cmd UTF8String]);
NSString *cmd = [NSString stringWithFormat:@"%@; sudo Clutch2 -d %2$@; %@; mv /var/mobile/Documents/Dumped/%2$@* /tmp/apparchive/%[email protected]",
@"mkdir /tmp/apparchive",
bundleId,
@"sudo chown mobile -R /var/mobile/Documents/Dumped"];
DDLogVerbose(@"CMD: %@", cmd);
system([cmd UTF8String]);

responseDict[@"file"] = [NSString stringWithFormat:@"/tmp/apparchive/%@.ipa", info[@"APP_ID"]];
responseDict[@"file"] = [NSString stringWithFormat:@"/tmp/apparchive/%@.ipa", info[@"APP_ID"]];

[response setHeader:@"Content-Type" value:@"application/json"];
}
[response setHeader:@"Content-Type" value:@"application/json"];
[self sendResponse:response dict:responseDict];
}];