forked from nygard/class-dump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCDClassDumpVisitor.m
118 lines (93 loc) · 4.23 KB
/
CDClassDumpVisitor.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// -*- mode: ObjC -*-
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
// Copyright (C) 1997-1998, 2000-2001, 2004-2009 Steve Nygard.
#import "CDClassDumpVisitor.h"
#include <mach-o/arch.h>
#import "NSArray-Extensions.h"
#import "CDClassDump.h"
#import "CDObjectiveCProcessor.h"
#import "CDMachOFile.h"
#import "CDOCProtocol.h"
#import "CDLCDylib.h"
#import "CDLCEncryptionInfo.h"
#import "CDLCRunPath.h"
#import "CDLCSegment.h"
#import "CDOCClass.h"
#import "CDOCCategory.h"
#import "CDSymbolReferences.h"
#import "CDTypeController.h"
@implementation CDClassDumpVisitor
- (void)willBeginVisiting;
{
[super willBeginVisiting];
[classDump appendHeaderToString:resultString];
if ([classDump containsObjectiveCData] || [classDump hasEncryptedFiles]) {
[[classDump typeController] appendStructuresToString:resultString symbolReferences:nil];
//[resultString appendString:@"// [structures go here]\n"];
} else {
[resultString appendString:@"This file does not contain any Objective-C runtime information.\n"];
}
}
- (void)didEndVisiting;
{
[super didEndVisiting];
[self writeResultToStandardOutput];
}
- (void)visitObjectiveCProcessor:(CDObjectiveCProcessor *)aProcessor;
{
CDMachOFile *machOFile;
const NXArchInfo *archInfo;
machOFile = [aProcessor machOFile];
[resultString appendString:@"#pragma mark -\n\n"];
[resultString appendString:@"/*\n"];
[resultString appendFormat:@" * File: %@\n", [machOFile filename]];
archInfo = NXGetArchInfoFromCpuType([machOFile cputype], [machOFile cpusubtype]);
if (archInfo == NULL)
[resultString appendFormat:@" * Arch: cputype: 0x%x, cpusubtype: 0x%x\n", [machOFile cputype], [machOFile cpusubtype]];
else
[resultString appendFormat:@" * Arch: %s (%s)\n", archInfo->description, archInfo->name];
if ([machOFile filetype] == MH_DYLIB) {
CDLCDylib *identifier;
identifier = [machOFile dylibIdentifier];
if (identifier != nil)
[resultString appendFormat:@" * Current version: %@, Compatibility version: %@\n",
[identifier formattedCurrentVersion], [identifier formattedCompatibilityVersion]];
}
[resultString appendFormat:@" *\n"];
[resultString appendFormat:@" * Objective-C Garbage Collection: %@\n", [aProcessor garbageCollectionStatus]];
for (CDLoadCommand *loadCommand in [machOFile loadCommands]) {
if ([loadCommand isKindOfClass:[CDLCRunPath class]]) {
CDLCRunPath *runPath = (CDLCRunPath *)loadCommand;
[resultString appendFormat:@" * Run path: %@\n", [runPath path]];
}
}
if ([machOFile isEncrypted]) {
[resultString appendString:@" * This file is encrypted:\n"];
for (CDLoadCommand *loadCommand in [machOFile loadCommands]) {
if ([loadCommand isKindOfClass:[CDLCEncryptionInfo class]]) {
CDLCEncryptionInfo *encryptionInfo = (CDLCEncryptionInfo *)loadCommand;
[resultString appendFormat:@" * cryptid: 0x%08x, cryptoff: 0x%08x, cryptsize: 0x%08x\n",
[encryptionInfo cryptid], [encryptionInfo cryptoff], [encryptionInfo cryptsize]];
}
}
} else if ([machOFile hasProtectedSegments]) {
if ([machOFile canDecryptAllSegments]) {
[resultString appendString:@" * This file has protected segments, decrypting.\n"];
} else {
NSUInteger index = 0;
[resultString appendString:@" * This file has protected segments that can't be decrypted:\n"];
for (CDLoadCommand *loadCommand in [machOFile loadCommands]) {
if ([loadCommand isKindOfClass:[CDLCSegment class]]) {
CDLCSegment *segment = (CDLCSegment *)loadCommand;
if ([segment canDecrypt] == NO) {
[resultString appendFormat:@" * Load command %u, segment encryption: %@\n",
index, CDSegmentEncryptionTypeName([segment encryptionType])];
}
}
index++;
}
}
}
[resultString appendString:@" */\n\n"];
}
@end