Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,27 @@ The source code is also available from my Github repository at:
Usage
-----

class-dump 3.5 (64 bit)
class-dump 3.5b1 (64 bit)
Usage: class-dump [options] <mach-o-file>

where options are:
-a show instance variable offsets
-A show implementation addresses
--arch <arch> choose a specific architecture from a universal binary (ppc, ppc64, i386, x86_64)
-C <regex> only display classes matching regular expression
-f <str> find string in method name
-H generate header files in current directory, or directory specified with -o
-I sort classes, categories, and protocols by inheritance (overrides -s)
-o <dir> output directory used for -H
-r recursively expand frameworks and fixed VM shared libraries
-s sort classes and categories by name
-S sort methods by name
-t suppress header in output, for testing
--list-arches list the arches in the file, then exit
--sdk-ios specify iOS SDK version (will look in /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS<version>.sdk
--sdk-mac specify Mac OS X version (will look in /Developer/SDKs/MacOSX<version>.sdk
--sdk-root specify the full SDK root path (or use --sdk-ios/--sdk-mac for a shortcut)
-a show instance variable offsets
-A show implementation addresses
--arch <arch> choose a specific architecture from a universal binary (ppc, ppc64, i386, x86_64)
-C <regex> only display classes matching regular expression
-f <str> find string in method name
-H generate header files in current directory, or directory specified with -o
-I sort classes, categories, and protocols by inheritance (overrides -s)
-o <dir> output directory used for -H
-r recursively expand frameworks and fixed VM shared libraries
-R <regex>/<str> replace matching regular expression by the str
-s sort classes and categories by name
-S sort methods by name
-t suppress header in output, for testing
--list-arches list the arches in the file, then exit
--sdk-ios specify iOS SDK version (will look in /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS<version>.sdk
--sdk-mac specify Mac OS X version (will look in /Developer/SDKs/MacOSX<version>.sdk
--sdk-root specify the full SDK root path (or use --sdk-ios/--sdk-mac for a shortcut)

- class-dump AppKit:

Expand Down
11 changes: 10 additions & 1 deletion Source/CDClassDump.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
// Copyright (C) 1997-2019 Steve Nygard.

// M_20191124 BlackDady Add Option Replace (regex format)

#import "CDFile.h" // For CDArch

#define CLASS_DUMP_BASE_VERSION "3.5 (64 bit)"
#define CLASS_DUMP_BASE_VERSION "3.5b1 (64 bit)"

#ifdef DEBUG
#define CLASS_DUMP_VERSION CLASS_DUMP_BASE_VERSION " (Debug version compiled " __DATE__ " " __TIME__ ")"
Expand All @@ -30,7 +32,11 @@
@property (assign) BOOL shouldShowMethodAddresses;
@property (assign) BOOL shouldShowHeader;


@property (strong) NSRegularExpression *regularExpression;

@property (strong) NSMutableDictionary<NSRegularExpression *, NSString *> *dictReplaceRegularExpressions; // M_20191124 END M_20191124

- (BOOL)shouldShowName:(NSString *)name;

@property (strong) NSString *sdkRoot;
Expand All @@ -53,6 +59,9 @@

- (void)appendHeaderToString:(NSMutableString *)resultString;

- (void)replacePartsToMutableString:(NSMutableString *)resultString; // M_20191124 END M_20191124
- (NSString *)replacePartsToString:(NSString *)txtInput; // M_20191124 END M_20191124

- (void)registerTypes;

- (void)showHeader;
Expand Down
34 changes: 34 additions & 0 deletions Source/CDClassDump.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
// Copyright (C) 1997-2019 Steve Nygard.

// M_20191124 BlackDady Add Option Replace (regex format)

#import "CDClassDump.h"

#import "CDFatArch.h"
Expand Down Expand Up @@ -40,13 +42,18 @@ @implementation CDClassDump
BOOL _shouldShowMethodAddresses;
BOOL _shouldShowHeader;


NSRegularExpression *_regularExpression;

NSMutableDictionary<NSRegularExpression *, NSString *> *_dictReplaceRegularExpressions; // M_20191124 END M_20191124

NSString *_sdkRoot;
NSMutableArray *_machOFiles;
NSMutableDictionary *_machOFilesByName;
NSMutableArray *_objcProcessors;



CDTypeController *_typeController;

CDArch _targetArch;
Expand All @@ -62,6 +69,8 @@ - (id)init;
_machOFilesByName = [[NSMutableDictionary alloc] init];
_objcProcessors = [[NSMutableArray alloc] init];

_dictReplaceRegularExpressions = [[NSMutableDictionary alloc] init]; // M_20191124 END M_20191124

_typeController = [[CDTypeController alloc] initWithClassDump:self];

// These can be ppc, ppc7400, ppc64, i386, x86_64
Expand All @@ -79,6 +88,7 @@ - (id)init;
- (BOOL)shouldShowName:(NSString *)name;
{
if (self.regularExpression != nil) {

NSTextCheckingResult *firstMatch = [self.regularExpression firstMatchInString:name options:(NSMatchingOptions)0 range:NSMakeRange(0, [name length])];
return firstMatch != nil;
}
Expand Down Expand Up @@ -265,6 +275,30 @@ - (void)appendHeaderToString:(NSMutableString *)resultString;
}
}

// M_20191124
- (void)replacePartsToMutableString:(NSMutableString *)resultString;
{
NSString *txtOutput = [self replacePartsToString: resultString];

[resultString setString:txtOutput];
}

- (NSString *)replacePartsToString:(NSString *)txtInput;
{
NSString __block *txtOutput = txtInput;

if( (_dictReplaceRegularExpressions != nil) && ([_dictReplaceRegularExpressions count] > 0) )
{
[_dictReplaceRegularExpressions enumerateKeysAndObjectsUsingBlock:^(NSRegularExpression * _Nonnull regexp, NSString * _Nonnull replaceTemplate, BOOL * _Nonnull stop) {

txtOutput = [regexp stringByReplacingMatchesInString:txtOutput options:0 range:NSMakeRange(0, [txtOutput length]) withTemplate:replaceTemplate];
}];
}

return txtOutput;
}
// END M_20191124

- (void)registerTypes;
{
for (CDObjectiveCProcessor *processor in self.objcProcessors) {
Expand Down
4 changes: 4 additions & 0 deletions Source/CDClassDumpVisitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
// Copyright (C) 1997-2019 Steve Nygard.

// M_20191124 BlackDady Add Option Replace (regex format)

#import "CDClassDumpVisitor.h"

#include <mach-o/arch.h>
Expand Down Expand Up @@ -37,6 +39,8 @@ - (void)willBeginVisiting;

- (void)didEndVisiting;
{
[self.classDump replacePartsToMutableString:self.resultString]; // M_20191124 END M_20191124

[super didEndVisiting];

[self writeResultToStandardOutput];
Expand Down
4 changes: 4 additions & 0 deletions Source/CDFindMethodVisitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
// Copyright (C) 1997-2019 Steve Nygard.

// M_20191124 BlackDady Add Option Replace (regex format)

#import "CDFindMethodVisitor.h"

#import "CDClassDump.h"
Expand Down Expand Up @@ -66,6 +68,8 @@ - (void)visitObjectiveCProcessor:(CDObjectiveCProcessor *)processor;

- (void)didEndVisiting;
{
[self.classDump replacePartsToMutableString:self.resultString]; // M_20191124 END M_20191124

[self writeResultToStandardOutput];
}

Expand Down
18 changes: 18 additions & 0 deletions Source/CDLCBuildVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,26 @@
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
// Copyright (C) 1997-2019 Steve Nygard.

// M_20191104 BlackDady support Framework Catalina 10.15.1 XCode 11.2b2

#import "CDLoadCommand.h"

// M_20191104
#if (!defined(PLATFORM_IOSMAC))
#define PLATFORM_IOSMAC 6
#endif

#if (!defined(PLATFORM_MACCATALYST))
#define PLATFORM_MACCATALYST 6
#endif

#if (!defined(PLATFORM_DRIVERKIT))
#define PLATFORM_DRIVERKIT 10
#endif
// END M_20191104



@interface CDLCBuildVersion : CDLoadCommand

@property (nonatomic, readonly) NSString *buildVersionString;
Expand Down
12 changes: 11 additions & 1 deletion Source/CDLCBuildVersion.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
// Copyright (C) 1997-2019 Steve Nygard.

// M_20191104 BlackDady support Framework Catalina 10.15.1 XCode 11.2b2

#import "CDLCBuildVersion.h"

#import "CDMachOFile.h"
Expand All @@ -15,10 +17,18 @@
case PLATFORM_TVOS: return @"tvOS";
case PLATFORM_WATCHOS: return @"watchOS";
case PLATFORM_BRIDGEOS: return @"bridgeOS";
case PLATFORM_IOSMAC: return @"iOS Mac";

// M_20191104
//case PLATFORM_IOSMAC: return @"iOS Mac";
case PLATFORM_MACCATALYST: return @"macCatalyst";
// END M_20191104

case PLATFORM_IOSSIMULATOR: return @"iOS Simulator";
case PLATFORM_TVOSSIMULATOR: return @"tvOS Simulator";
case PLATFORM_WATCHOSSIMULATOR: return @"watchOS Simulator";

case PLATFORM_DRIVERKIT: return @"driverKit"; // M_20191104 END M_20191104

default: return [NSString stringWithFormat:@"Unknown platform %x", platform];
}
}
Expand Down
10 changes: 10 additions & 0 deletions Source/CDMultiFileVisitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
// Copyright (C) 1997-2019 Steve Nygard.

// M_20191124 BlackDady Add Option Replace (regex format)

#import "CDMultiFileVisitor.h"

#import "CDClassDump.h"
Expand Down Expand Up @@ -115,6 +117,8 @@ - (void)didVisitClass:(CDOCClass *)aClass;
NSString *filename = [NSString stringWithFormat:@"%@.h", aClass.name];
if (self.outputPath != nil)
filename = [self.outputPath stringByAppendingPathComponent:filename];

[self.classDump replacePartsToMutableString:self.resultString]; // M_20191124 END M_20191124

[[self.resultString dataUsingEncoding:NSUTF8StringEncoding] writeToFile:filename atomically:YES];
}
Expand Down Expand Up @@ -154,6 +158,8 @@ - (void)didVisitCategory:(CDOCCategory *)category;
if (self.outputPath != nil)
filename = [self.outputPath stringByAppendingPathComponent:filename];

[self.classDump replacePartsToMutableString:self.resultString]; // M_20191124 END M_20191124

[[self.resultString dataUsingEncoding:NSUTF8StringEncoding] writeToFile:filename atomically:YES];
}

Expand Down Expand Up @@ -184,6 +190,8 @@ - (void)didVisitProtocol:(CDOCProtocol *)protocol;
NSString *filename = [NSString stringWithFormat:@"%@-Protocol.h", protocol.name];
if (self.outputPath != nil)
filename = [self.outputPath stringByAppendingPathComponent:filename];

[self.classDump replacePartsToMutableString:self.resultString]; // M_20191124 END M_20191124

[[self.resultString dataUsingEncoding:NSUTF8StringEncoding] writeToFile:filename atomically:YES];
}
Expand Down Expand Up @@ -383,6 +391,8 @@ - (void)generateStructureHeader;
if (self.outputPath != nil)
filename = [self.outputPath stringByAppendingPathComponent:filename];

[self.classDump replacePartsToMutableString:self.resultString]; // M_20191124 END M_20191124

[[self.resultString dataUsingEncoding:NSUTF8StringEncoding] writeToFile:filename atomically:YES];
}

Expand Down
Loading