OLD | NEW |
(Empty) | |
| 1 // -*- mode: ObjC -*- |
| 2 |
| 3 // This file is part of class-dump, a utility for examining the Objective-C seg
ment of Mach-O files. |
| 4 // Copyright (C) 1997-1998, 2000-2001, 2004-2010 Steve Nygard. |
| 5 |
| 6 #include <stdio.h> |
| 7 #include <libc.h> |
| 8 #include <unistd.h> |
| 9 #include <getopt.h> |
| 10 #include <stdlib.h> |
| 11 |
| 12 #import <Foundation/Foundation.h> |
| 13 #import "NSString-Extensions.h" |
| 14 |
| 15 #import "CDClassDump.h" |
| 16 #import "CDMachOFile.h" |
| 17 |
| 18 void print_usage(void) |
| 19 { |
| 20 fprintf(stderr, |
| 21 "deprotect %s\n" |
| 22 "Usage: deprotect [options] <input file> <output file>\n" |
| 23 "\n" |
| 24 " where options are:\n" |
| 25 " (none)\n" |
| 26 , |
| 27 CLASS_DUMP_VERSION |
| 28 ); |
| 29 } |
| 30 |
| 31 enum { |
| 32 CDFormatIvar = 0, |
| 33 CDFormatMethod = 1, |
| 34 CDFormatBalance = 2, |
| 35 }; |
| 36 |
| 37 int main(int argc, char *argv[]) |
| 38 { |
| 39 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
| 40 |
| 41 int ch; |
| 42 BOOL errorFlag = NO; |
| 43 |
| 44 struct option longopts[] = { |
| 45 { NULL, 0, NULL, 0 }, |
| 46 }; |
| 47 |
| 48 if (argc == 1) { |
| 49 print_usage(); |
| 50 exit(0); |
| 51 } |
| 52 |
| 53 while ( (ch = getopt_long(argc, argv, "", longopts, NULL)) != -1) { |
| 54 switch (ch) { |
| 55 case '?': |
| 56 default: |
| 57 errorFlag = YES; |
| 58 break; |
| 59 } |
| 60 } |
| 61 |
| 62 argc -= optind; |
| 63 argv += optind; |
| 64 |
| 65 if (errorFlag || argc < 2) { |
| 66 print_usage(); |
| 67 exit(2); |
| 68 } |
| 69 |
| 70 { |
| 71 NSString *inputFile, *outputFile; |
| 72 CDFile *file; |
| 73 NSData *inputData; |
| 74 |
| 75 inputFile = [NSString stringWithFileSystemRepresentation:argv[0]]; |
| 76 outputFile = [NSString stringWithFileSystemRepresentation:argv[1]]; |
| 77 |
| 78 NSLog(@"inputFile: %@", inputFile); |
| 79 NSLog(@"outputFile: %@", outputFile); |
| 80 |
| 81 inputData = [[NSData alloc] initWithContentsOfMappedFile:inputFile]; |
| 82 |
| 83 file = [CDFile fileWithData:inputData filename:inputFile searchPathState
:nil]; |
| 84 if (file == nil) { |
| 85 fprintf(stderr, "deprotect: Input file (%s) is neither a Mach-O file
nor a fat archive.\n", [inputFile UTF8String]); |
| 86 exit(1); |
| 87 } |
| 88 |
| 89 if ([file isKindOfClass:[CDMachOFile class]]) { |
| 90 NSLog(@"file: %@", file); |
| 91 [(CDMachOFile *)file saveDeprotectedFileToPath:outputFile]; |
| 92 } else { |
| 93 NSLog(@"Can only deprotect thin mach-o files at this point."); |
| 94 } |
| 95 |
| 96 [inputData release]; |
| 97 } |
| 98 |
| 99 [pool release]; |
| 100 |
| 101 return 0; |
| 102 } |
OLD | NEW |