-
Notifications
You must be signed in to change notification settings - Fork 698
/
Document.mm
853 lines (725 loc) · 25.5 KB
/
Document.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
/*
* MVDocument.mm
* MachOView
*
* Created by psaghelyi on 15/06/2010.
*
*/
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cxxabi.h>
#import "Common.h"
#import "Document.h"
#import "DataController.h"
#import "Layout.h"
#include <unistd.h>
//============================================================================
@implementation MVOutlineView
/*
//----------------------------------------------------------------------------
- (void)mouseDown:(NSEvent *)theEvent
{
// Control+Click invokes that the selected node will not be swapped out
if ([theEvent modifierFlags] & NSControlKeyMask)
{
NSPoint event_location = [theEvent locationInWindow];
NSPoint local_point = [self convertPoint:event_location fromView:nil];
MVNode * node = [self itemAtRow:[self rowAtPoint:local_point]];
// note: offset should not be zero for explicit change of dirty indicator
if (node.details != nil)
{
node.dirty = !node.dirty;
[self reloadItem:node];
NSLog(@"%@: node: %@ becomes %@", self, node, node.dirty ? @"dirty" : @"clean");
}
}
[super mouseDown:theEvent];
}
*/
@end
//============================================================================
@implementation MVTableView
//----------------------------------------------------------------------------
- (void)drawGridInClipRect:(NSRect)clipRect
{
MVDocument * document = [[[self window] windowController] document];
NSRange rowRange = [self rowsInRect:clipRect];
// Adjust column range, always go from zero, so we can gather columns even to
// the left of what we are supposed to draw.
[[NSColor grayColor] set];
for (NSUInteger rowIndex = rowRange.location ;
rowIndex < NSMaxRange(rowRange) ;
rowIndex++ )
{
MVRow * row = [document.dataController.selectedNode.details getRowToDisplay:rowIndex];
if (row == nil)
{
continue;
}
if ([[row.attributes objectForKey:MVUnderlineAttributeName] isEqualToString:@"YES"])
{
NSRect rowRect = [self rectOfRow:rowIndex];
[NSBezierPath strokeLineFromPoint:NSMakePoint(rowRect.origin.x,
-0.5+rowRect.origin.y+rowRect.size.height)
toPoint:NSMakePoint(rowRect.origin.x + rowRect.size.width,
-0.5+rowRect.origin.y+rowRect.size.height)];
}
}
//[super drawGridInClipRect:clipRect];
}
//----------------------------------------------------------------------------
- (void)highlightSelectionInClipRect:(NSRect)clipRect
{
MVDocument * document = [[[self window] windowController] document];
NSRange rowRange = [self rowsInRect:clipRect];
for (NSUInteger rowIndex = rowRange.location ;
rowIndex < NSMaxRange(rowRange) ;
rowIndex++ )
{
MVRow * row = [document.dataController.selectedNode.details getRowToDisplay:rowIndex];
if (row == nil)
{
continue;
}
NSColor * color = [row.attributes objectForKey:MVCellColorAttributeName];
if (color != nil)
{
NSColor * bgcolor = [[NSColor controlAlternatingRowBackgroundColors] objectAtIndex:rowIndex % 2];
[[color blendedColorWithFraction:0.85f ofColor:bgcolor] setFill];
NSRect rowRect = [self rectOfRow:rowIndex];
NSRectFill (rowRect);
}
}
[super highlightSelectionInClipRect: clipRect];
}
//----------------------------------------------------------------------------
- (void)cancelOperation:(id)sender
{
// I have no idea why NSTableView (or one of its parents) does not implement
// 'cancel editing' functionality by default....
// so, let's do it for ourselves
if ([self currentEditor] != nil)
{
[self abortEditing];
// We lose focus so re-establish
[[self window] makeFirstResponder:self];
}
}
@end
//============================================================================
@implementation MVRightFormatter
//----------------------------------------------------------------------------
- (instancetype)init
{
NSAssert(NO, @"plain init is not allowed");
return nil;
}
//-----------------------------------------------------------------------------
- (instancetype)initPlainWithLength:(NSUInteger)len
{
if (self = [super init])
{
compound = NO;
length = len;
alignLeft = NO;
}
return self;
}
//----------------------------------------------------------------------------
- (instancetype)initLeftAlignedWithLength:(NSUInteger)len
{
if (self = [super init])
{
compound = NO;
length = len;
alignLeft = YES;
}
return self;
}
//----------------------------------------------------------------------------
- (instancetype)initCompoundWithLength:(NSUInteger)len
{
if (self = [super init])
{
compound = YES;
length = len;
alignLeft = NO;
}
return self;
}
//----------------------------------------------------------------------------
+ (MVRightFormatter *)plainFormatterWithLength:(NSUInteger)len
{
return [[MVRightFormatter alloc] initPlainWithLength:len];
}
//----------------------------------------------------------------------------
+ (MVRightFormatter *)leftAlignedFormatterWithLength:(NSUInteger)len
{
return [[MVRightFormatter alloc] initLeftAlignedWithLength:len];
}
//----------------------------------------------------------------------------
+ (MVRightFormatter *)compoundFormatterWithLength:(NSUInteger)len
{
return [[MVRightFormatter alloc] initCompoundWithLength:len];
}
//----------------------------------------------------------------------------
- (NSString *)stringForObjectValue:(id)anObject
{
if ([anObject isKindOfClass:[NSAttributedString class]])
{
return [anObject string];
}
return anObject;
}
//----------------------------------------------------------------------------
- (BOOL)getObjectValue:(id *)anObject
forString:(NSString *)string
errorDescription:(NSString **)error
{
if (compound)
{
(*anObject) = string;
}
else
{
// put leading zeroes in order to preserve the original length
NSUInteger numZeroes = length - [string length];
NSMutableString * zeroes = [[NSMutableString alloc] initWithCapacity:numZeroes];
while (numZeroes-- > 0)
{
[zeroes appendString:@"0"];
}
(*anObject) = [NSString stringWithFormat:@"%@%@",
alignLeft ? string : zeroes,
alignLeft ? zeroes : string];
}
return YES;
}
//----------------------------------------------------------------------------
- (NSAttributedString *)attributedStringForObjectValue:(id)anObject
withDefaultAttributes:(NSDictionary *)attributes
{
if ([anObject isKindOfClass:[NSAttributedString class]])
{
return anObject;
}
return nil;
}
//----------------------------------------------------------------------------
- (BOOL)isPartialStringValid:(NSString **)partialStringPtr
proposedSelectedRange:(NSRangePointer)proposedSelRangePtr
originalString:(NSString *)origString
originalSelectedRange:(NSRange)origSelRange
errorDescription:(NSString **)error
{
NSScanner * scanner = [NSScanner scannerWithString:*partialStringPtr];
if (compound)
// option 1: formatted hex value (11 22 33 44 55 66 77 88 )
{
[scanner setCharactersToBeSkipped:[NSCharacterSet whitespaceCharacterSet]];
NSUInteger numBytes = length;
while ([scanner isAtEnd] == NO)
{
unsigned value;
// value needs to be hex and number of bytes is determined
if ([scanner scanHexInt:&value] == NO || value > 0xff || numBytes == 0)
{
return NO;
}
--numBytes;
}
}
else
// option 2: plain hex value
{
[scanner setCharactersToBeSkipped:nil];
NSCharacterSet * characterSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789ABCDEFabcdef"];
while ([scanner isAtEnd] == NO)
{
// must be a valid hex value
if ([scanner scanCharactersFromSet:characterSet intoString:NULL] == NO)
{
return NO;
}
// apply upper limit on length
if ([*partialStringPtr length] > length)
{
return NO;
}
}
}
return YES;
}
@end
//============================================================================
@implementation MVDocument
@synthesize dataController;
enum ViewType
{
e_details,
e_details64,
e_hex,
e_hex64,
};
//----------------------------------------------------------------------------
+ (NSString *)temporaryDirectory
{
NSProcessInfo * procInfo = [NSProcessInfo processInfo];
NSBundle * mainBundle = [NSBundle mainBundle];
NSString * swapDir = [NSString stringWithFormat:@"%@%@_%@.XXXXXXXXXXX",
NSTemporaryDirectory(),
[procInfo processName],
[mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
return swapDir;
}
//-----------------------------------------------------------------------------
- (instancetype)init
{
self = [super init];
if (self)
{
dataController = [[MVDataController alloc] init];
threadCount = 0;
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
typeof(self) __weak weakSelf = self;
/*
[nc addObserver:weakSelf
selector:@selector(handleDataTreeWillChange:)
name:MVDataTreeWillChangeNotification
object:nil];
[nc addObserver:weakSelf
selector:@selector(handleDataTreeDidChange:)
name:MVDataTreeDidChangeNotification
object:nil];
*/
[nc addObserver:weakSelf
selector:@selector(handleDataTreeChanged:)
name:MVDataTreeChangedNotification
object:nil];
[nc addObserver:weakSelf
selector:@selector(handleDataTableChanged:)
name:MVDataTableChangedNotification
object:nil];
[nc addObserver:weakSelf
selector:@selector(handleThreadStateChanged:)
name:MVThreadStateChangedNotification
object:nil];
}
return self;
}
//----------------------------------------------------------------------------
- (NSString *)windowNibName
{
// Implement this to return a nib to load OR implement -makeWindowControllers to manually create your controllers.
return @"Layout";
}
//----------------------------------------------------------------------------
- (BOOL)isRVA
{
return ([offsetModeSwitch selectedSegment] == 1 ? YES : NO);
}
//----------------------------------------------------------------------------
- (void)handleDataTreeWillChange:(NSNotification *)notification
{
if ([notification object] == dataController)
{
// lock treeView
}
}
//----------------------------------------------------------------------------
- (void)handleDataTreeDidChange:(NSNotification *)notification
{
if ([notification object] == dataController)
{
// unlock treeView
}
}
//----------------------------------------------------------------------------
- (void)handleDataTreeChanged:(NSNotification *)notification
{
if ([notification object] == dataController) {
dispatch_async(dispatch_get_main_queue(), ^
{
// Update UI here, on the main queue
NSDictionary * userInfo = [notification userInfo];
if (userInfo) {
//refresh the modified node only
MVNode * node = [userInfo objectForKey:MVNodeUserInfoKey];
// check if the window still exists which contains the leftView to update
if ([[self windowControllers] count] == 0) {
return;
}
[self->leftView reloadItem:node.parent];
if ([self->leftView isItemExpanded:node.parent]) {
[self->leftView reloadItem:node];
}
} else {
[self->leftView reloadItem:self->dataController.rootNode reloadChildren:YES];
}
});
}
}
//----------------------------------------------------------------------------
- (void)handleDataTableChanged:(NSNotification *)notification
{
if ([notification object] == dataController)
{
[rightView noteNumberOfRowsChanged];
[rightView reloadData];
}
}
//----------------------------------------------------------------------------
- (void)handleThreadStateChanged:(NSNotification *)notification
{
if ([notification object] == dataController) {
NSString * threadState = [[notification userInfo] objectForKey:MVStatusUserInfoKey];
if ([threadState isEqualToString:MVStatusTaskStarted] == YES) {
if (++threadCount == 1) {
dispatch_async(dispatch_get_main_queue(), ^{
[self->progressIndicator setUsesThreadedAnimation:YES];
[self->progressIndicator startAnimation:nil];
[self->stopButton setHidden:NO];
});
}
}
else if ([threadState isEqualToString:MVStatusTaskTerminated] == YES) {
if (--threadCount == 0) {
dispatch_async(dispatch_get_main_queue(), ^{
[self->progressIndicator stopAnimation:nil];
[self->statusText setStringValue:@""];
[self->stopButton setHidden:YES];
});
}
}
}
}
//----------------------------------------------------------------------------
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];
// fill in initial data sources
[statusText setStringValue:@"Loading..."];
for (MVLayout * layout in dataController.layouts)
{
[layout doMainTasks];
}
// refresh initial view
[leftView reloadData];
[leftView expandItem:dataController.rootNode];
// finish processing in background
[statusText setStringValue:@"Processing in background..."];
for (MVLayout * layout in dataController.layouts)
{
#ifdef MV_NO_MULTITHREAD
[layout doBackgroundTasks];
#else
[layout.backgroundThread start];
#endif
}
}
//----------------------------------------------------------------------------
- (void)awakeFromNib
{
[rightView setDoubleAction:@selector(rightViewDoubleAction:)];
[rightView setTarget:self];
}
//----------------------------------------------------------------------------
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
return dataController.fileData;
}
//----------------------------------------------------------------------------
- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
{
// create a temporary copy for patching
const char *tmp = [[MVDocument temporaryDirectory] UTF8String];
char *tmpFilePath = strdup(tmp);
int fd = mkstemp(tmpFilePath);
if (fd < 0) {
NSLog(@"mktemp failed!");
free(tmpFilePath);
return NO;
}
NSURL * tmpURL = [NSURL fileURLWithPath:[NSString stringWithUTF8String:tmpFilePath]];
free(tmpFilePath);
// open the original binary for viewing/editing
dataController.fileName = [absoluteURL path];
dataController.fileData = [NSMutableData dataWithContentsOfURL:absoluteURL
options:NSDataReadingMappedIfSafe
error:outError];
if (*outError) return NO;
// copy the file - the original code used NSFileManager but that doesn't work with mkstemp()
// [NSFileHandle writeData] is 10.15+ only
// https://developer.apple.com/library/archive/documentation/Security/Conceptual/SecureCodingGuide/Articles/RaceConditions.html
if (write(fd, [dataController.fileData bytes], [dataController.fileData length]) != (ssize_t)[dataController.fileData length]) {
NSLog(@"Write failed: %s", strerror(errno));
return NO;
}
close(fd);
// open the copied binary for patching
dataController.realData = [NSMutableData dataWithContentsOfURL:tmpURL
options:NSDataReadingMappedAlways
error:outError];
if (*outError) return NO;
@try
{
[dataController createLayouts:dataController.rootNode location:0 length:[dataController.fileData length]];
}
@catch (NSException * exception)
{
*outError = [NSError errorWithDomain:NSCocoaErrorDomain
code:NSFileReadUnknownError
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
[[self fileURL] path], NSFilePathErrorKey,
[exception reason], NSLocalizedDescriptionKey,
nil]];
return NO;
}
return YES;
}
//----------------------------------------------------------------------------
- (void)saveDocumentWithDelegate:(id)delegate didSaveSelector:(SEL)didSaveSelector contextInfo:(void *)contextInfo
{
if (delegate != nil)
{
[self runModalSavePanelForSaveOperation:NSSaveAsOperation
delegate:delegate
didSaveSelector:didSaveSelector
contextInfo:contextInfo];
}
else
{
[super saveDocumentWithDelegate:delegate
didSaveSelector:didSaveSelector
contextInfo:contextInfo];
}
}
//----------------------------------------------------------------------------
- (IBAction)updateSearchFilter:(id)sender
{
NSString * filter = [searchField stringValue];
if (dataController.selectedNode.details != nil)
{
[dataController.selectedNode filterDetails:filter];
[rightView reloadData];
}
}
//----------------------------------------------------------------------------
- (IBAction)updateAddressingMode:(id)sender
{
// send notification as if the tree has changed
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:NSOutlineViewSelectionDidChangeNotification
object:leftView];
}
//----------------------------------------------------------------------------
- (IBAction)stopProcessing:(id)sender
{
// stopping threads takes time so disable the stop button to give a feedback
// and preserve from further clicks
[stopButton setEnabled:NO];
// stop every background task
for (MVLayout * layout in dataController.layouts)
{
[layout.backgroundThread cancel];
}
}
//----------------------------------------------------------------------------
- (IBAction)rightViewDoubleAction:(id)sender
{
NSParameterAssert(sender == rightView);
NSInteger colIndex = [sender clickedColumn];
NSInteger rowIndex = [sender clickedRow];
if ([[[rightView tableColumns] objectAtIndex:colIndex] isEditable])
{
if (dataController.selectedNode.details != nil)
{
MVRow * row = [dataController.selectedNode.details getRowToDisplay:rowIndex];
if (row == nil)
{
return;
}
NSString * cellContent = [row columnAtIndex:colIndex];
if ([cellContent length] == 0)
{
return;
}
}
[rightView editColumn:colIndex row:rowIndex withEvent:nil select:YES];
return;
}
// jump to symbol definition
if (colIndex == VALUE_COLUMN)
{
// determine symbol type (local, public, external)
//NSIndexSet * indexes;
//[leftView selectRowIndexes:indexes byExtendingSelection:NO];
}
}
//----------------------------------------------------------------------------
- (void)changeView:(ViewType)viewType
{
//get current values
NSTableColumn * column0 = [[rightView tableColumns] objectAtIndex:0];
NSTableColumn * column1 = [[rightView tableColumns] objectAtIndex:1];
NSTableColumn * column2 = [[rightView tableColumns] objectAtIndex:2];
NSTableColumn * column3 = [[rightView tableColumns] objectAtIndex:3];
switch (viewType)
{
case e_details:
case e_details64:
[[column0 headerCell] setStringValue:[self isRVA] == NO ? @"Offset" : @"Address"];
[[column1 headerCell] setStringValue:@"Data"];
[[column2 headerCell] setStringValue:@"Description"];
[[column3 headerCell] setStringValue:@"Value"];
[column0 setEditable:NO];
[column1 setEditable:YES];
[column2 setEditable:NO];
[column3 setEditable:NO];
break;
case e_hex:
case e_hex64:
[[column0 headerCell] setStringValue:[self isRVA] == NO ? @"pFile" : @"Address"];
[[column1 headerCell] setStringValue:@"Data LO"];
[[column2 headerCell] setStringValue:@"Data HI"];
[[column3 headerCell] setStringValue:@"Value"];
[column0 setEditable:NO];
[column1 setEditable:YES];
[column2 setEditable:YES];
[column3 setEditable:NO];
break;
default:; // do not change current view
}
}
//----------------------------------------------------------------------------
- (void)canCloseDocumentWithDelegate:(id)delegate shouldCloseSelector:(SEL)shouldCloseSelector contextInfo:(void *)contextInfo
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
for (MVLayout * layout in dataController.layouts)
{
[layout.backgroundThread cancel];
}
[super canCloseDocumentWithDelegate:delegate shouldCloseSelector:shouldCloseSelector contextInfo:contextInfo];
}
#pragma mark responders for UI events
//----------------------------------------------------------------------------
- (void)outlineViewSelectionDidChange:(NSNotification *)notification
{
if ([notification object] == leftView)
{
NSInteger rowIndex = [leftView selectedRow];
MVNode * nodeToSelect = [leftView itemAtRow:rowIndex];
if (dataController.selectedNode != nodeToSelect)
{
// close old details
if (dataController.selectedNode.detailsOffset != 0)
{
// release swap file
[dataController.selectedNode closeDetails];
// kick out from memory
dataController.selectedNode.details = nil;
}
// open new details
[nodeToSelect openDetails];
// reset filter on node change
[nodeToSelect filterDetails:nil];
// swap nodes
dataController.selectedNode = nodeToSelect;
}
MVLayout * layout = [nodeToSelect.userInfo objectForKey:MVLayoutUserInfoKey];
BOOL is64bit = [layout is64bit];
if (nodeToSelect.details != nil)
{
[self changeView:is64bit == NO ? e_details : e_details64];
}
else
{
[self changeView:is64bit == NO ? e_hex : e_hex64];
}
[rightView reloadData];
}
}
//----------------------------------------------------------------------------
// set up the formatter for editable cells
//----------------------------------------------------------------------------
- (void)tableView:(NSTableView *)aTableView
willDisplayCell:(id)aCell
forTableColumn:(NSTableColumn *)aTableColumn
row:(NSInteger)rowIndex
{
if (aTableView == rightView)
{
if (dataController.selectedNode.details != nil)
{
MVRow * row = [dataController.selectedNode.details getRowToDisplay:rowIndex];
if (row == nil)
{
return;
}
NSUInteger len = [row.columns.dataStr length];
[aCell setFormatter:len > 16
? [MVRightFormatter leftAlignedFormatterWithLength:len]
: [MVRightFormatter plainFormatterWithLength:len]];
}
else
{
NSUInteger colIndex = [[aTableView tableColumns] indexOfObject:aTableColumn];
NSUInteger len = MIN(dataController.selectedNode.dataRange.length - rowIndex * 16, (NSUInteger)16);
if (colIndex == DATA_LO_COLUMN)
{
[aCell setFormatter:[MVRightFormatter compoundFormatterWithLength:len > 8 ? 8 : len]];
}
else if (colIndex == DATA_HI_COLUMN)
{
[aCell setFormatter:[MVRightFormatter compoundFormatterWithLength:len > 8 ? len - 8 : 0]];
}
}
}
}
//----------------------------------------------------------------------------
// TODO: show different tooltips for each if the cell contains more then one symbol
//----------------------------------------------------------------------------
- (NSString *)tableView:(NSTableView *)aTableView
toolTipForCell:(NSCell *)aCell
rect:(NSRectPointer)rect
tableColumn:(NSTableColumn *)aTableColumn
row:(NSInteger)rowIndex
mouseLocation:(NSPoint)mouseLocation
{
if (aTableView == rightView)
{
MVRow * row = [dataController.selectedNode.details getRowToDisplay:rowIndex];
if (row == nil)
{
return nil;
}
NSUInteger colIndex = [[aTableView tableColumns] indexOfObject:aTableColumn];
NSString * cellContent = [row columnAtIndex:colIndex];
// try to find C,C++ symbol prologue
NSUInteger start = [cellContent rangeOfString:@"_Z"].location;
if (start == NSNotFound)
{
return nil;
}
NSUInteger stop = [cellContent rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@")]"]
options:NSLiteralSearch
range:NSMakeRange(start, [cellContent length] - start)].location;
if (stop == NSNotFound)
{
stop = [cellContent length];
}
char const * cell_str = CSTRING([cellContent substringWithRange:NSMakeRange(start, stop - start)]);
int status;
char * sym_str = abi::__cxa_demangle (cell_str, NULL, NULL, &status);
if (status == 0)
{
NSString * toolTip= NSSTRING(sym_str);
free(sym_str);
return toolTip;
}
}
return nil;
}
@end