Skip to content

Commit

Permalink
A few minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
nygard committed Feb 25, 2012
1 parent 3a52c96 commit 8c8d341
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 38 deletions.
30 changes: 13 additions & 17 deletions deprotect.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void saveDeprotectedFileToPath(CDMachOFile *file, NSString *path)
if ([command isKindOfClass:[CDLCSegment class]]) {
CDLCSegment *segment = (CDLCSegment *)command;

if ([segment isProtected]) {
if (segment.isProtected) {
NSRange range;
NSUInteger flagOffset;

Expand Down Expand Up @@ -76,9 +76,6 @@ int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

int ch;
BOOL errorFlag = NO;

struct option longopts[] = {
{ NULL, 0, NULL, 0 },
};
Expand All @@ -87,13 +84,16 @@ int main(int argc, char *argv[])
print_usage();
exit(0);
}

BOOL errorFlag = NO;
int ch;

while ( (ch = getopt_long(argc, argv, "", longopts, NULL)) != -1) {
switch (ch) {
case '?':
default:
errorFlag = YES;
break;
case '?':
default:
errorFlag = YES;
break;
}
}

Expand All @@ -106,27 +106,23 @@ int main(int argc, char *argv[])
}

{
NSString *inputFile, *outputFile;
CDFile *file;
NSData *inputData;

inputFile = [NSString stringWithFileSystemRepresentation:argv[0]];
outputFile = [NSString stringWithFileSystemRepresentation:argv[1]];
NSString *inputFile = [NSString stringWithFileSystemRepresentation:argv[0]];
NSString *outputFile = [NSString stringWithFileSystemRepresentation:argv[1]];

NSLog(@"inputFile: %@", inputFile);
NSLog(@"outputFile: %@", outputFile);

inputData = [[NSData alloc] initWithContentsOfMappedFile:inputFile];
NSData *inputData = [[NSData alloc] initWithContentsOfMappedFile:inputFile];

file = [CDFile fileWithData:inputData filename:inputFile searchPathState:nil];
CDFile *file = [CDFile fileWithData:inputData filename:inputFile searchPathState:nil];
if (file == nil) {
fprintf(stderr, "deprotect: Input file (%s) is neither a Mach-O file nor a fat archive.\n", [inputFile UTF8String]);
exit(1);
}

if ([file isKindOfClass:[CDMachOFile class]]) {
NSLog(@"file: %@", file);
saveDeprotectedFileToPath((CDMachOFile*)file, outputFile);
saveDeprotectedFileToPath((CDMachOFile *)file, outputFile);
} else {
NSLog(@"Can only deprotect thin mach-o files at this point.");
}
Expand Down
40 changes: 19 additions & 21 deletions formatType.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,24 @@ void print_usage(void)
}

enum {
CDFormatIvar = 0,
CDFormatMethod = 1,
CDFormatBalance = 2,
CDFormat_Ivar = 0,
CDFormat_Method = 1,
CDFormat_Balance = 2,
};

int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

CDTypeFormatter *ivarTypeFormatter = [[CDTypeFormatter alloc] init];
[ivarTypeFormatter setShouldExpand:YES];
[ivarTypeFormatter setShouldAutoExpand:YES];
[ivarTypeFormatter setBaseLevel:0];
//[ivarTypeFormatter setDelegate:self];
ivarTypeFormatter.shouldExpand = YES;
ivarTypeFormatter.shouldAutoExpand = YES;
ivarTypeFormatter.baseLevel = 0;

CDTypeFormatter *methodTypeFormatter = [[CDTypeFormatter alloc] init];
[methodTypeFormatter setShouldExpand:NO];
[methodTypeFormatter setShouldAutoExpand:NO];
[methodTypeFormatter setBaseLevel:0];
//[methodTypeFormatter setDelegate:self];
methodTypeFormatter.shouldExpand = NO;
methodTypeFormatter.shouldAutoExpand = NO;
methodTypeFormatter.baseLevel = 0;

struct option longopts[] = {
{ "balance", no_argument, NULL, 'b' },
Expand All @@ -62,19 +60,19 @@ int main(int argc, char *argv[])
exit(0);
}

NSUInteger formatType = CDFormatIvar;
NSUInteger formatType = CDFormat_Ivar;

int ch;
BOOL errorFlag = NO;
int ch;

while ( (ch = getopt_long(argc, argv, "bm", longopts, NULL)) != -1) {
switch (ch) {
case 'b':
formatType = CDFormatBalance;
formatType = CDFormat_Balance;
break;

case 'm':
formatType = CDFormatMethod;
formatType = CDFormat_Method;
break;

case '?':
Expand All @@ -90,9 +88,9 @@ int main(int argc, char *argv[])
}

switch (formatType) {
case CDFormatIvar: printf("Format as ivars\n"); break;
case CDFormatMethod: printf("Format as methods\n"); break;
case CDFormatBalance: printf("Format as balance\n"); break;
case CDFormat_Ivar: printf("Format as ivars\n"); break;
case CDFormat_Method: printf("Format as methods\n"); break;
case CDFormat_Balance: printf("Format as balance\n"); break;
}

for (NSUInteger index = optind; index < argc; index++) {
Expand Down Expand Up @@ -126,15 +124,15 @@ int main(int argc, char *argv[])
type = line;

switch (formatType) {
case CDFormatIvar:
case CDFormat_Ivar:
str = [ivarTypeFormatter formatVariable:name type:type symbolReferences:nil];
break;

case CDFormatMethod:
case CDFormat_Method:
str = [methodTypeFormatter formatMethodName:name type:type symbolReferences:nil];
break;

case CDFormatBalance: {
case CDFormat_Balance: {
CDBalanceFormatter *balance = [[CDBalanceFormatter alloc] initWithString:type];
str = [balance format];
[balance release];
Expand Down

0 comments on commit 8c8d341

Please sign in to comment.