-
Notifications
You must be signed in to change notification settings - Fork 708
/
Layout.mm
123 lines (105 loc) · 3.55 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
/*
* 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);
}
*/
//-----------------------------------------------------------------------------
- (instancetype)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 (mkstemp(swapFilePath) == -1) {
NSLog(@"mkstemp failed!");
free(swapFilePath);
return nil;
}
NSString *swapPath = [NSString stringWithFormat:@"%s.%@", swapFilePath, [[dataController fileName] lastPathComponent]];
free(swapFilePath);
archiver = [MVArchiver archiverWithPath:swapPath];
}
return self;
}
//-----------------------------------------------------------------------------
- (void const *)imageAt:(uint64_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:(uint64_t)location
length:(uint64_t)length
{
MVNode * node = [parent insertChild:caption location:location length:length];
return node;
}
@end