Skip to content

Commit

Permalink
Failed framework dumps are properly registered
Browse files Browse the repository at this point in the history
  • Loading branch information
ttwj committed Aug 8, 2016
1 parent 470663a commit 992103c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
Binary file modified Clutch/.DS_Store
Binary file not shown.
11 changes: 7 additions & 4 deletions Clutch/BundleDumpOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ + (NSArray *)availableDumpers;
@implementation BundleDumpOperation

-(void)failedOperation {
NSLog(@"failed operation :(");
NSLog(@"application %@", _application->_dumpQueue);
NSArray* wow = [_application->_dumpQueue operations];
for (NSOperation* operation in wow) {
[[ClutchPrint sharedInstance] printDeveloper:@"operation hash %lu", (unsigned long)operation.hash];
Expand Down Expand Up @@ -163,18 +165,19 @@ - (void)main {

BOOL result = [_dumper dumpBinary];

if (result) {
if (result == YES) {
dumpCount++;
//SUCCESS(@"Sucessfully dumped %@ segment of %@", [Dumper readableArchFromHeader:macho], originalBinary);
[[ClutchPrint sharedInstance] printDeveloper:@"Sucessfully dumped %@ segment of %@", [Dumper readableArchFromHeader:macho], originalBinary];
} else {
[[ClutchPrint sharedInstance] printError:@"Failed to dump binary %@ with arch %@",originalBinary,[Dumper readableArchFromHeader:macho]];
[[ClutchPrint sharedInstance] printError:@"Failed to dump %@ with arch %@",originalBinary,[Dumper readableArchFromHeader:macho]];
[self failedOperation];
}

[_handle closeFile];
}

if (!dumpCount) {
[[ClutchPrint sharedInstance] printError:@"Failed to dump binary %@", originalBinary];
[[ClutchPrint sharedInstance] printError:@"Failed to dump %@", originalBinary];
[self failedOperation];

return;
Expand Down
2 changes: 1 addition & 1 deletion Clutch/Clutch-Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int diff_ms(struct timeval t1, struct timeval t2);



#define CLUTCH_VERSION_ @"2.0.2"
#define CLUTCH_VERSION_ @"2.0.3"

#ifdef DEBUG
#define CLUTCH_VERSION [NSString stringWithFormat:@"%@ DEBUG",CLUTCH_VERSION_]
Expand Down
9 changes: 8 additions & 1 deletion Clutch/Framework64Dumper.m
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ - (BOOL)dumpBinary
exit_with_errno (posix_spawnattr_setflags (&attr, flags), "::posix_spawnattr_setflags (&attr, flags) error: ");

int dumpResult = posix_spawnp(&pid, argv[0], NULL, &attr, (char* const*)argv, environ);
__block int finalDumpResult = 9999;

if (dumpResult == 0) {
[[ClutchPrint sharedInstance] printDeveloper: @"Child pid: %i", pid];
Expand All @@ -216,6 +217,7 @@ - (BOOL)dumpBinary
kill(pid, SIGCONT);
if (waitpid(pid, &dumpResult, 0) != -1) {
[[ClutchPrint sharedInstance] printColor:ClutchPrinterColorPurple format:@"Child exited with status %u", dumpResult];
finalDumpResult = dumpResult;
} else {
perror("waitpid");
}
Expand All @@ -237,9 +239,14 @@ - (BOOL)dumpBinary

[[NSFileManager defaultManager] removeItemAtPath:workingPath error:nil];

if (dumpResult == 0)
[[ClutchPrint sharedInstance] printDeveloper: @"Final dump result %u", finalDumpResult];

if (finalDumpResult == 0)
return YES;




return NO;
}

Expand Down
4 changes: 3 additions & 1 deletion Clutch/FrameworkDumper.m
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ - (BOOL)dumpBinary
exit_with_errno (posix_spawnattr_setflags (&attr, flags), "::posix_spawnattr_setflags (&attr, flags) error: ");

int dumpResult = posix_spawnp(&pid, argv[0], NULL, &attr, (char* const*)argv, environ);
__block finalDumpResult = 9999; //it shouldn't be 9999

if (dumpResult == 0) {
[[ClutchPrint sharedInstance] printDeveloper: @"Child pid: %i", pid];
Expand All @@ -224,6 +225,7 @@ - (BOOL)dumpBinary
int dumpResult = 0;
if (waitpid(pid, &dumpResult, 0) != -1) {
[[ClutchPrint sharedInstance] printDeveloper: @"Child exited with status %u", dumpResult];
finalDumpResult = dumpResult;
} else {
perror("waitpid");
}
Expand All @@ -245,7 +247,7 @@ - (BOOL)dumpBinary



if (dumpResult == 0)
if (finalDumpResult == 0)
return YES;

return NO;
Expand Down
9 changes: 5 additions & 4 deletions Clutch/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,18 @@ int main (int argc, const char * argv[])

if (result)
{
[[ClutchPrint sharedInstance] printColor:ClutchPrinterColorPurple format:@"Successfully dumped framework!"];
[[ClutchPrint sharedInstance] printColor:ClutchPrinterColorPurple format:@"Successfully dumped framework %@!", fmwk.binPath.lastPathComponent];

exit(0);
}
else {
[[ClutchPrint sharedInstance] printColor:ClutchPrinterColorPurple format:@"Failed to dumped framework! :("];
exit(-2);
[[ClutchPrint sharedInstance] printColor:ClutchPrinterColorPurple format:@"Failed to dump framework %@ :(", fmwk.binPath.lastPathComponent];
exit(2);
}

}

exit(-1);
exit(1);
}

switch (flags)
Expand Down

0 comments on commit 992103c

Please sign in to comment.