forked from gdbinit/MachOView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Layout.mm
132 lines (113 loc) · 3.63 KB
/
Layout.mm
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* Layout.mm
* MachOView
*
* Created by psaghelyi on 18/03/2011.
*
*/
#import "Common.h"
#import "Document.h"
#import "DataController.h"
#import "Layout.h"
//============================================================================
@implementation MVLayout
@synthesize dataController, backgroundThread, archiver;
/*
- (void)dealloc
{
NSLog(@"********MVLayout deallocated: %@", self);
}
*/
//-----------------------------------------------------------------------------
- (id)init
{
NSAssert(NO, @"plain init is not allowed");
return nil;
}
//-----------------------------------------------------------------------------
- (id)initWithDataController:(MVDataController *)dc rootNode:(MVNode *)node
{
if (self = [super init])
{
dataController = dc;
rootNode = node;
imageOffset = node.dataRange.location;
imageSize = node.dataRange.length;
backgroundThread = [[NSThread alloc] initWithTarget:self selector:@selector(doBackgroundTasks) object:nil];
const char *tmp = [[MVDocument temporaryDirectory] UTF8String];
char *swapFilePath = strdup(tmp);
if (mktemp(swapFilePath) == NULL)
{
NSLog(@"mktemp failed!");
free(swapFilePath);
return NO;
}
NSString *swapPath = [NSString stringWithFormat:@"%s.%@", swapFilePath, [[dataController fileName] lastPathComponent]];
free(swapFilePath);
archiver = [MVArchiver archiverWithPath:swapPath];
}
return self;
}
//-----------------------------------------------------------------------------
- (void const *)imageAt:(uint32_t)location
{
auto p = (uint8_t const *)[dataController.realData bytes];
return p ? p + location : NULL;
}
//-----------------------------------------------------------------------------
- (NSString *)description
{
return [[super description] stringByAppendingFormat:@" [%@]",rootNode.caption];
}
//-----------------------------------------------------------------------------
-(void)printException:(NSException *)exception caption:(NSString *)caption
{
@synchronized([NSApp class])
{
NSLog(@"%@: Exception (%@): %@", self, caption, [exception name]);
NSLog(@" Reason: %@", [exception reason]);
NSLog(@" User Info: %@", [exception userInfo]);
NSLog(@" Backtrace:\n%@", [exception callStackSymbols]);
}
}
//-----------------------------------------------------------------------------
- (BOOL)is64bit
{
return NO;
}
//-----------------------------------------------------------------------------
- (void)doMainTasks
{
}
//-----------------------------------------------------------------------------
- (void)doBackgroundTasks
{
[archiver halt];
}
//-----------------------------------------------------------------------------
- (NSString *)convertToRVA: (NSString *)offsetStr
{
return @"";
}
//-----------------------------------------------------------------------------
// Depth-first Traversal of nodes
//-----------------------------------------------------------------------------
- (MVNode *)findNodeByUserInfo:(NSDictionary *)userInfo
{
[dataController.treeLock lock];
MVNode * node = [rootNode findNodeByUserInfo:userInfo];
[dataController.treeLock unlock];
return node;
}
//-----------------------------------------------------------------------------
// Create data node without details table (only hex content)
//-----------------------------------------------------------------------------
- (MVNode *)createDataNode:(MVNode *)parent
caption:(NSString *)caption
location:(uint32_t)location
length:(uint32_t)length
{
MVNode * node = [parent insertChild:caption location:location length:length];
return node;
}
@end