Skip to content

Commit

Permalink
YOPA patching
Browse files Browse the repository at this point in the history
  • Loading branch information
ttwj committed Jan 23, 2014
1 parent 07b5cda commit a57ae72
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 11 deletions.
1 change: 1 addition & 0 deletions Classes/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
- (NSString *)minimumOSVersion;
- (UIImage *)applicationIcon;
- (NSData *)applicationSINF;
- (NSInteger)appVersion;

- (NSDictionary *)dictionaryRepresentation;

Expand Down
4 changes: 4 additions & 0 deletions Classes/Application.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,8 @@ - (NSString *)description {
return [NSString stringWithFormat:@"<%@: %p, appName: %@, bundleID: %@>",NSStringFromClass([self class]),self,self.applicationName,self.applicationBundleID];
}

-(NSInteger)appVersion {
return [[applicationVersion stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue];
}

@end
4 changes: 4 additions & 0 deletions Classes/Cracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
NSString *_ipapath;
NSString *_yopaPath;
BOOL* _yopaEnabled;

NSMutableArray* _yopaAddFiles;
NSMutableArray* _yopaRemFiles;
NSMutableArray* _yopaVersions;
}

-(id)init;
Expand Down
94 changes: 83 additions & 11 deletions Classes/Cracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ -(void)compressIPAto7z:(NSString*)packagePath {
}


void yopainstaller_peer_event_handler(xpc_connection_t peer, xpc_object_t reply)
void yopainstalld_peer_event_handler(Cracker* cracker, xpc_connection_t peer, xpc_object_t reply)
{

xpc_type_t type = xpc_get_type(reply);
Expand All @@ -366,17 +366,41 @@ void yopainstaller_peer_event_handler(xpc_connection_t peer, xpc_object_t reply)

NSString *status = [NSString stringWithUTF8String:xpc_dictionary_get_string(reply, "Status")];


if ([status isEqualToString:@"Complete"]) {
xpc_object_t addFiles = xpc_dictionary_get_value(reply, "AddFiles");
xpc_object_t remFiles = xpc_dictionary_get_value(reply, "RemoveFiles");
NSLog(@"Complete! YAY");
xpc_array_apply(addFiles, ^_Bool(size_t index, xpc_object_t value) {
NSLog(@"Array value %s", (const char*)value);
return true;
});
NSString* command = [NSString stringWithUTF8String:xpc_dictionary_get_string(reply, "Command")];
if ([command isEqualToString:@"SaveVersion"]) {
NSLog(@"save version ok");
}
else if ([command isEqualToString:@"GetVersions"]) {
xpc_object_t versions = xpc_dictionary_get_value(reply, "Versions");
cracker->_yopaVersions = [[NSMutableArray alloc] init];
xpc_array_apply(versions, ^_Bool(size_t index, xpc_object_t value) {
[cracker->_yopaVersions addObject:[NSNumber numberWithInt:(int)value]];
return true;
});
}
else if ([command isEqualToString:@"GetPatchFiles"]) {
xpc_object_t diff = xpc_dictionary_get_value(reply, "Diff");
xpc_object_t addFiles = xpc_dictionary_get_value(diff, "AddFiles");
xpc_object_t remFiles = xpc_dictionary_get_value(diff, "RemoveFiles");
NSLog(@"Complete! YAY");
cracker->_yopaAddFiles = [[NSMutableArray alloc] init];
cracker->_yopaRemFiles = [[NSMutableArray alloc] init];
xpc_array_apply(addFiles, ^_Bool(size_t index, xpc_object_t value) {
NSLog(@"Add Array value %s", (const char*)value);
[cracker->_yopaAddFiles addObject:[NSString stringWithUTF8String:(const char*)value]];
return true;
});

xpc_array_apply(remFiles, ^_Bool(size_t index, xpc_object_t value) {
NSLog(@"Remove Array value %s", (const char*)value);
[cracker->_yopaRemFiles addObject:[NSString stringWithUTF8String:(const char*)value]];
return true;
});

}
xpc_connection_cancel(peer);
exit(0);

}
else if ([status isEqualToString:@"Error"])
{
Expand Down Expand Up @@ -410,7 +434,7 @@ -(void)packageYOPA
xpc_connection_t c = xpc_connection_create_mach_service("zorro.yopainstalld", NULL, 0);

xpc_connection_set_event_handler(c, ^(xpc_object_t object) {
yopainstaller_peer_event_handler(c, object);
yopainstalld_peer_event_handler(self, c, object);
});

xpc_connection_resume(c);
Expand All @@ -426,6 +450,54 @@ -(void)packageYOPA
xpc_release(message);

dispatch_main();


// Messages are always dictionaries.
message = xpc_dictionary_create(NULL, NULL, 0);
xpc_dictionary_set_string(message, "Command", "GetVersions");
xpc_dictionary_set_string(message, "AppBundle", _app.applicationBundleID.UTF8String);

xpc_connection_send_message(c, message);

xpc_release(message);

dispatch_main();

for (NSNumber* version in _yopaVersions) {
if ([version isEqualToNumber:_app.appVersion]) {
NSLog(@"same version! %@", version);
continue;

// Messages are always dictionaries.
message = xpc_dictionary_create(NULL, NULL, 0);
xpc_dictionary_set_string(message, "Command", "GetPatchFiles");
xpc_dictionary_set_string(message, "AppBundle", _app.applicationBundleID.UTF8String);
xpc_dictionary_set_int64(message, "Version", [version intValue]);

xpc_connection_send_message(c, message);

xpc_release(message);

dispatch_main();

ZipArchive* archive = [[ZipArchive alloc] init];
NSString* archivePath = [_tempPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip", version]];
[archive CreateZipFile2:archivePath];
for (NSString* file in _yopaAddFiles) {
NSLog(@"yopa add file patch %@", file);
NSString* longPath = [_workingDir stringByAppendingPathComponent:file];
[archive addFileToZip:longPath newname:file compressionLevel:0];
}
[archive CloseZipFile2];

YOPASegment* segment = [[YOPASegment alloc] initWithPatchPackage:archivePath withCompressionType:ZIP_COMPRESSION withBundleName:_app.applicationBundleID withVersion:version];

[package addSegment:segment];

}

}



//default zip segment
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions Libraries/yopa-package/YOPASegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@

- (struct yopa_segment)getSegmentHeader;
- (id)initWithNormalPackage:(NSString*)packagePath withCompressionType:(int)compressionType withBundleName:(NSString*)bundle;
- (id)initWithPatchPackage:(NSString*)packagePath withCompressionType:(int)compressionType withBundleName:(NSString*)bundle withVersion:(NSInteger)version;

@end
14 changes: 14 additions & 0 deletions Libraries/yopa-package/YOPASegment.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ - (id)initWithNormalPackage:(NSString*)packagePath withCompressionType:(int)comp
return self;
}

- (id)initWithPatchPackage:(NSString*)packagePath withCompressionType:(int)compressionType withBundleName:(NSString*)bundle withVersion:(NSInteger)version {
if (self = [super init]) {
_file = fopen(packagePath.UTF8String, "r");
fseek(_file, 0, SEEK_END);
_size = (uint32_t) ftell(_file);
_packagePath = packagePath;
_compression_type = compressionType;
_app_bundle = bundle;
_required_version = version;
}
return self;
}


- (struct yopa_segment)getSegmentHeader {
struct yopa_segment header;
header.compression_type = _compression_type;
Expand Down

0 comments on commit a57ae72

Please sign in to comment.