-
Notifications
You must be signed in to change notification settings - Fork 708
/
LinkEdit.mm
1864 lines (1553 loc) · 86.5 KB
/
LinkEdit.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
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* LinkEdit.mm
* MachOView
*
* Created by psaghelyi on 20/07/2010.
*
*/
#include <string>
#include <vector>
#include <set>
#include <map>
#import "Common.h"
#import "LinkEdit.h"
#import "ReadWrite.h"
#import "DataController.h"
#import <mach-o/loader.h>
#import <mach-o/reloc.h>
#import <mach-o/arm/reloc.h>
#import <mach-o/arm64/reloc.h>
#import <mach-o/x86_64/reloc.h>
#import <mach-o/nlist.h>
using namespace std;
//============================================================================
@implementation MachOLayout (LinkEdit)
//-----------------------------------------------------------------------------
- (MVNode *) createRelocNode:(MVNode *)parent
caption:(NSString *)caption
location:(uint64_t)location
length:(uint64_t)length
baseAddress:(uint32_t)baseAddress // start of the section containing the relocation (image: start of the first segment)
{
MVNodeSaver nodeSaver;
MVNode * node = [parent insertChildWithDetails:caption location:location length:length saver:nodeSaver];
NSRange range = NSMakeRange(location,0);
NSString * lastReadHex;
MATCH_STRUCT(mach_header,imageOffset);
struct scattered_relocation_info const * prev_scattered_relocation_info = NULL; // for sectdiff & pair
for (uint32_t nreloc = 0; nreloc < length / sizeof(struct relocation_info); ++nreloc)
{
if ([backgroundThread isCancelled]) break;
// normal: relocation_info != NULL, scattered_relocation_info == NULL
// scattered: relocation_info == NULL, scattered_relocation_info != NULL
MATCH_STRUCT(relocation_info,location + nreloc * sizeof(struct relocation_info))
struct scattered_relocation_info const * scattered_relocation_info = NULL;
if (relocation_info->r_address & R_SCATTERED)
{
scattered_relocation_info = (struct scattered_relocation_info const *)relocation_info;
relocation_info = NULL;
}
// accumulate search info
NSUInteger bookmark = node.details.rowCount;
NSString * symbolName = nil;
NSColor * color = nil;
// read the first half of the entry
[dataController read_uint32:range lastReadHex:&lastReadHex];
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Address"
:[NSString stringWithFormat:@"0x%X", relocation_info
? relocation_info->r_address + baseAddress
: scattered_relocation_info->r_address + baseAddress]];
[node.details appendRow:@"":@"":@"Scattered":scattered_relocation_info ? @"True" : @"False"];
// read the second half of the entry
[dataController read_uint32:range lastReadHex:&lastReadHex];
if (relocation_info)
{
uint64_t relocLocation = [self RVAToFileOffset:baseAddress + relocation_info->r_address];
NSRange rangeReloc = NSMakeRange(relocLocation,0);
uint32_t relocValue = [dataController read_uint32:rangeReloc];
uint32_t relocLength = (1 << relocation_info->r_length);
NSParameterAssert(relocLength == sizeof(uint32_t));
// adjust for PC relative relocs
if (relocation_info->r_pcrel)
{
relocValue += relocation_info->r_address + baseAddress + relocLength;
}
if (relocation_info->r_extern)
{
// target is a symbol
if (relocation_info->r_symbolnum >= symbols.size())
{
[NSException raise:@"Symbol"
format:@"index is out of range %u", relocation_info->r_symbolnum];
}
struct nlist const * nlist = [self getSymbolByIndex:relocation_info->r_symbolnum];
symbolName = NSSTRING(strtab + nlist->n_un.n_strx);
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Symbol"
:(nlist->n_type & N_TYPE) == N_SECT
? [NSString stringWithFormat:@"0x%X (%@)", nlist->n_value, symbolName]
: symbolName];
[symbolNames setObject:[NSString stringWithFormat:@"%@->%@",
[self findSymbolAtRVA:[self fileOffsetToRVA:relocLocation]],symbolName]
forKey:[NSNumber numberWithUnsignedLong:[self fileOffsetToRVA:relocLocation]]];
if ((nlist->n_type & N_TYPE) == N_SECT)
{
// reference to local symbol
relocValue += nlist->n_value;
}
else
{
// reference to undefined external symbol
uint32_t relocAddend = relocValue;
// use the negative index of the symbol (hope that will not overlap)
relocValue += *symbols.begin() - nlist - 1;
if (relocAddend != 0)
{
[node.details appendRow:@"":@"":@"Addend":(int32_t)relocAddend < 0
? [NSString stringWithFormat:@"-0x%X",-relocAddend]
: [NSString stringWithFormat:@"0x%X",relocAddend]];
}
}
}
else // r_symbolnum means section index
{
if (relocation_info->r_symbolnum == R_ABS)
{
// absolute address
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Section"
:@"R_ABS"];
}
else
{
// section relative (symbolNum means sectionNum)
if (relocation_info->r_symbolnum >= sections.size())
{
[NSException raise:@"Section"
format:@"index is out of range %u", relocation_info->r_symbolnum];
}
struct section const * section = [self getSectionByIndex:relocation_info->r_symbolnum];
NSString * sectionName = [NSString stringWithFormat:@"(%s,%s)",
string(section->segname,16).c_str(),
string(section->sectname,16).c_str()];
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Section"
:[NSString stringWithFormat:@"%u %@", relocation_info->r_symbolnum, sectionName]];
[node.details appendRow:@"":@"":@"Target":(symbolName = [self findSymbolAtRVA:relocValue])];
[symbolNames setObject:[NSString stringWithFormat:@"%@->%@",
[self findSymbolAtRVA:[self fileOffsetToRVA:relocLocation]],symbolName]
forKey:[NSNumber numberWithUnsignedLong:[self fileOffsetToRVA:relocLocation]]];
}
}
// update real data
[self addRelocAtFileOffset:relocLocation withLength:relocLength andValue:relocValue];
//NSLog(@"%@ %.8X --> %@",[self findSectionContainsRVA:[self fileOffsetToRVA:relocLocation]],[self fileOffsetToRVA:relocLocation],[self findSymbolAtRVA:relocValue]);
}
else
//=============================== scattered relocation ===============================
if (scattered_relocation_info)
{
NSParameterAssert(scattered_relocation_info->r_pcrel == false); // have not faced with this yet
uint32_t r_type = scattered_relocation_info->r_type;
if (
(mach_header->cputype == CPU_TYPE_I386 && (r_type == GENERIC_RELOC_SECTDIFF || r_type == GENERIC_RELOC_LOCAL_SECTDIFF))
||
(mach_header->cputype == CPU_TYPE_ARM && (r_type == ARM_RELOC_SECTDIFF || r_type == ARM_RELOC_LOCAL_SECTDIFF))
)
{
prev_scattered_relocation_info = scattered_relocation_info;
}
else if (
((mach_header->cputype == CPU_TYPE_I386 && r_type == GENERIC_RELOC_PAIR)
||
(mach_header->cputype == CPU_TYPE_ARM && r_type == ARM_RELOC_PAIR))
&& prev_scattered_relocation_info
)
{
//read original content at relocation
uint64_t relocLocation = [self RVAToFileOffset:baseAddress + prev_scattered_relocation_info->r_address];
uint32_t relocLength = (1 << prev_scattered_relocation_info->r_length);
NSAssert1(relocLength == sizeof(uint32_t), @"unsupported reloc length (%u)", relocLength);
NSRange rangeReloc = NSMakeRange(relocLocation,0);
uint32_t relocValue = [dataController read_uint32:rangeReloc];
uint32_t relocAddend = relocValue - (prev_scattered_relocation_info->r_value - scattered_relocation_info->r_value);
// the relocation value only differs if it has an addend
if (relocAddend != 0)
{
[node.details appendRow:@"":@"":@"Addend"
:(int32_t)relocAddend < 0
? [NSString stringWithFormat:@"-0x%X", -relocAddend]
: [NSString stringWithFormat:@"0x%X", relocAddend]];
// update real data
relocValue += relocAddend;
[self addRelocAtFileOffset:relocLocation withLength:relocLength andValue:relocValue];
//NSLog(@"%@ %.8X --> %@",[self findSectionContainsRVA:[self fileOffsetToRVA:relocLocation]],[self fileOffsetToRVA:relocLocation],[self findSymbolAtRVA:relocValue]);
}
prev_scattered_relocation_info = NULL; // reset
}
}
//=============================== normal relocations ===============================
if (mach_header->cputype == CPU_TYPE_I386)
{
uint32_t r_type = (relocation_info ? relocation_info->r_type : scattered_relocation_info->r_type);
[node.details appendRow:@"":@"":@"Type"
:r_type == GENERIC_RELOC_VANILLA ? @"GENERIC_RELOC_VANILLA" :
r_type == GENERIC_RELOC_PAIR ? @"GENERIC_RELOC_PAIR" :
r_type == GENERIC_RELOC_SECTDIFF ? @"GENERIC_RELOC_SECTDIFF" :
r_type == GENERIC_RELOC_PB_LA_PTR ? @"GENERIC_RELOC_PB_LA_PTR" :
r_type == GENERIC_RELOC_LOCAL_SECTDIFF ? @"GENERIC_RELOC_LOCAL_SECTDIFF" :
r_type == GENERIC_RELOC_TLV ? @"GENERIC_RELOC_TLV" : @"?????"];
}
else if (mach_header->cputype == CPU_TYPE_ARM)
{
uint32_t r_type = (relocation_info ? relocation_info->r_type : scattered_relocation_info->r_type);
[node.details appendRow:@"":@"":@"Type"
:r_type == ARM_RELOC_VANILLA ? @"ARM_RELOC_VANILLA" :
r_type == ARM_RELOC_PAIR ? @"ARM_RELOC_PAIR" :
r_type == ARM_RELOC_SECTDIFF ? @"ARM_RELOC_SECTDIFF" :
r_type == ARM_RELOC_LOCAL_SECTDIFF ? @"ARM_RELOC_LOCAL_SECTDIFF" :
r_type == ARM_RELOC_PB_LA_PTR ? @"ARM_RELOC_PB_LA_PTR" :
r_type == ARM_RELOC_BR24 ? @"ARM_RELOC_BR24" :
r_type == ARM_THUMB_RELOC_BR22 ? @"ARM_THUMB_RELOC_BR22" :
r_type == ARM_THUMB_32BIT_BRANCH ? @"ARM_THUMB_32BIT_BRANCH" :
r_type == ARM_RELOC_HALF ? @"ARM_RELOC_HALF" :
r_type == ARM_RELOC_HALF_SECTDIFF ? @"ARM_RELOC_HALF_SECTDIFF" : @"?????"];
}
if (relocation_info)
{
[node.details appendRow:@"":@"":@"External"
:relocation_info->r_extern ? @"True" : @"False"];
}
[node.details appendRow:@"":@"":@"PCRelative"
:(relocation_info && relocation_info->r_pcrel) || (scattered_relocation_info && scattered_relocation_info->r_pcrel)
? @"True" : @"False"];
[node.details appendRow:@"":@"":@"Length"
:[NSString stringWithFormat:@"%u",
relocation_info ? (1 << relocation_info->r_length) : (1 << scattered_relocation_info->r_length)]];
if (scattered_relocation_info)
{
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Value"
:(symbolName = [self findSymbolAtRVA:scattered_relocation_info->r_value])];
color = [NSColor magentaColor];
}
[node.details setAttributesFromRowIndex:bookmark:MVMetaDataAttributeName,symbolName,
MVCellColorAttributeName,color,nil];
[node.details setAttributes:MVUnderlineAttributeName,@"YES",nil];
} // loop
return node;
}
//-----------------------------------------------------------------------------
- (MVNode *) createReloc64Node:(MVNode *)parent
caption:(NSString *)caption
location:(uint64_t)location
length:(uint64_t)length
baseAddress:(uint64_t)baseAddress // start of the section containing the relocation (image: start of the first segment)
{
MVNodeSaver nodeSaver;
MVNode * node = [parent insertChildWithDetails:caption location:location length:length saver:nodeSaver];
NSRange range = NSMakeRange(location,0);
NSString * lastReadHex;
MATCH_STRUCT(mach_header_64,imageOffset);
struct relocation_info const * prev_relocation_info = NULL;
for (uint32_t nreloc = 0; nreloc < length / sizeof(struct relocation_info); ++nreloc)
{
if ([backgroundThread isCancelled]) break;
// In the Mac OS X x86-64 environment scattered relocations are not used. Compiler-generated code
// uses mostly external relocations, in which the r_extern bit is set to 1 and the r_symbolnum field contains
// the symbol-table index of the target label.
MATCH_STRUCT(relocation_info,location + nreloc * sizeof(struct relocation_info))
uint32_t relocLength = (1 << relocation_info->r_length);
NSAssert1(relocLength == sizeof(uint32_t) || relocLength == sizeof(uint64_t), @"unsupported reloc length (%u)", relocLength);
// accumulate search info
NSUInteger bookmark = node.details.rowCount;
NSString * symbolName = nil;
NSColor * color = nil;
// read the first half of the entry
[dataController read_uint32:range lastReadHex:&lastReadHex];
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Address"
:[NSString stringWithFormat:@"0x%qX", relocation_info->r_address + baseAddress]];
// read the second half of the entry
[dataController read_uint32:range lastReadHex:&lastReadHex];
//========================================================================
if (relocation_info->r_extern)
{
uint64_t relocLocation = [self RVAToFileOffset:baseAddress + relocation_info->r_address];
NSRange rangeReloc = NSMakeRange(relocLocation,0);
// target symbol
if (relocation_info->r_symbolnum >= symbols_64.size())
{
[NSException raise:@"Symbol"
format:@"symbol is out of range %u", relocation_info->r_symbolnum];
}
struct nlist_64 const * nlist_64 = [self getSymbol64ByIndex:relocation_info->r_symbolnum];
symbolName = NSSTRING(strtab + nlist_64->n_un.n_strx);
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Symbol"
:(nlist_64->n_type & N_TYPE) == N_SECT
? [NSString stringWithFormat:@"0x%qX (%@)", nlist_64->n_value, symbolName]
: symbolName];
[symbolNames setObject:[NSString stringWithFormat:@"%@->%@",
[self findSymbolAtRVA:[self fileOffsetToRVA:relocLocation]],symbolName]
forKey:[NSNumber numberWithUnsignedLongLong:[self fileOffsetToRVA:relocLocation]]];
// For the x86_64 architecure on Mac OS X it is possible to
// encode a signed 32-bit expression of the form:
// "add_symbol - subtract_symbol + number"
// using two relocation entries pointing at the same 32-bits.
// The first one has to be a X86_64_RELOC_SUBTRACTOR then must
// be followed by a X86_64_RELOC_UNSIGNED.
if ((mach_header_64->cputype == CPU_TYPE_X86_64 && relocation_info->r_type == X86_64_RELOC_SUBTRACTOR)
||
(mach_header_64->cputype == CPU_TYPE_ARM64 && relocation_info->r_type == ARM64_RELOC_SUBTRACTOR))
{
color = [NSColor magentaColor];
prev_relocation_info = relocation_info;
}
else if (prev_relocation_info)
{
// reference computed from difference of two symbols
//============================================
NSAssert(!(mach_header_64->cputype == CPU_TYPE_X86_64) || relocation_info->r_type == X86_64_RELOC_UNSIGNED, @"X86_64_RELOC_SUBTRACTOR must be followed by X86_64_RELOC_UNSIGNED");
NSAssert(!(mach_header_64->cputype == CPU_TYPE_ARM64) || relocation_info->r_type == ARM64_RELOC_UNSIGNED, @"ARM64_RELOC_SUBTRACTOR must be followed by ARM64_RELOC_UNSIGNED");
NSParameterAssert (relocation_info->r_address == prev_relocation_info->r_address);
color = [NSColor magentaColor];
if (relocation_info->r_symbolnum >= symbols_64.size())
{
[NSException raise:@"Symbol"
format:@"index is out of range %u", relocation_info->r_symbolnum];
}
struct nlist_64 const * prev_nlist_64 = [self getSymbol64ByIndex:prev_relocation_info->r_symbolnum];
if (relocLength == sizeof(uint32_t))
{
uint32_t relocAddend = [dataController read_uint32:rangeReloc];
if (relocAddend != 0)
{
[node.details appendRow:@"":@"":@"Addend"
:(int32_t)relocAddend < 0
? [NSString stringWithFormat:@"-0x%X",-relocAddend]
: [NSString stringWithFormat:@"0x%X",relocAddend]];
}
uint64_t relocValue = nlist_64->n_value - prev_nlist_64->n_value + relocAddend;
// update real data
[self addRelocAtFileOffset:relocLocation withLength:relocLength andValue:relocValue];
//NSLog(@"diff32: %@ %.16qX --> (%u) %@",[self findSectionContainsRVA64:[self fileOffsetToRVA64:relocLocation]],[self fileOffsetToRVA64:relocLocation],relocLength,[self findSymbolAtRVA64:relocValue]);
}
else if (relocLength == sizeof(uint64_t))
{
uint64_t relocAddend = [dataController read_uint64:rangeReloc];
if (relocAddend != 0)
{
[node.details appendRow:@"":@"":@"Addend"
:(int64_t)relocAddend < 0
? [NSString stringWithFormat:@"-0x%qX",-relocAddend]
: [NSString stringWithFormat:@"0x%qX",relocAddend]];
}
uint64_t relocValue = nlist_64->n_value - prev_nlist_64->n_value + relocAddend;
// update real data
[self addRelocAtFileOffset:relocLocation withLength:relocLength andValue:relocValue];
//NSLog(@"diff64: %@ %.16qX --> (%u) %@",[self findSectionContainsRVA64:[self fileOffsetToRVA64:relocLocation]],[self fileOffsetToRVA64:relocLocation],relocLength,[self findSymbolAtRVA64:relocValue]);
}
prev_relocation_info = NULL; // reset
}
else if ((nlist_64->n_type & N_TYPE) == N_SECT)
{
// reference to local symbol
//============================================
if (relocLength == sizeof(uint32_t))
{
// 32bit signed PC Rel
NSParameterAssert(relocation_info->r_pcrel == true);
// XXX: is this cast correct?
uint32_t relocValue = (uint32_t)(nlist_64->n_value - relocation_info->r_address - baseAddress - relocLength);
uint32_t relocAddend = [dataController read_uint32:rangeReloc];
if (mach_header_64->cputype == CPU_TYPE_X86_64)
{
relocAddend -= (relocation_info->r_type == X86_64_RELOC_SIGNED_1 ? 1 :
relocation_info->r_type == X86_64_RELOC_SIGNED_2 ? 2 :
relocation_info->r_type == X86_64_RELOC_SIGNED_4 ? 4 : 0);
}
if (relocAddend != 0)
{
[node.details appendRow:@"":@"":@"Addend"
:(int32_t)relocAddend < 0
? [NSString stringWithFormat:@"-0x%X",-relocAddend]
: [NSString stringWithFormat:@"0x%X",relocAddend]];
}
// update real data
relocValue += relocAddend;
[self addRelocAtFileOffset:relocLocation withLength:relocLength andValue:relocValue];
//NSLog(@"local32: %@ %.16qX --> (%u) %@",[self findSectionContainsRVA64:[self fileOffsetToRVA64:relocLocation]],[self fileOffsetToRVA64:relocLocation],relocLength,[self findSymbolAtRVA64:relocValue]);
}
else if (relocLength == sizeof(uint64_t))
{
// 64bit unsigned direct
NSParameterAssert(relocation_info->r_pcrel == false);
uint64_t relocValue = nlist_64->n_value;
uint64_t relocAddend = [dataController read_uint64:rangeReloc];
if (relocAddend != 0)
{
[node.details appendRow:@"":@"":@"Addend"
:(int64_t)relocAddend < 0
? [NSString stringWithFormat:@"-0x%qX",-relocAddend]
: [NSString stringWithFormat:@"0x%qX",relocAddend]];
}
// update real data
relocValue += relocAddend;
[self addRelocAtFileOffset:relocLocation withLength:relocLength andValue:relocValue];
//NSLog(@"local64: %@ %.16qX --> (%u) %@",[self findSectionContainsRVA64:[self fileOffsetToRVA64:relocLocation]],[self fileOffsetToRVA64:relocLocation],relocLength,[self findSymbolAtRVA64:relocValue]);
}
}
else
{
// reference to undefined external symbol
//============================================
NSParameterAssert((nlist_64->n_type & N_TYPE) == N_UNDF); // N_PBUD is only in image
if (relocLength == sizeof(uint32_t))
{
NSParameterAssert(relocation_info->r_pcrel == true);
NSRange rangeReloc = NSMakeRange(relocLocation,0);
uint32_t relocAddend = [dataController read_uint32:rangeReloc];
if (mach_header_64->cputype == CPU_TYPE_X86_64)
{
relocAddend -= (relocation_info->r_type == X86_64_RELOC_SIGNED_1 ? 1 :
relocation_info->r_type == X86_64_RELOC_SIGNED_2 ? 2 :
relocation_info->r_type == X86_64_RELOC_SIGNED_4 ? 4 : 0);
}
if (relocAddend != 0)
{
[node.details appendRow:@"":@"":@"Addend"
:(int32_t)relocAddend < 0
? [NSString stringWithFormat:@"-0x%X",-relocAddend]
: [NSString stringWithFormat:@"0x%X",relocAddend]];
}
// XXX: is this cast correct?
uint32_t relocValue = (uint32_t)(*symbols_64.begin() - nlist_64 - 1);
relocValue -= relocation_info->r_address + baseAddress + relocLength; // it is PC relative
// update real data
relocValue += relocAddend;
[self addRelocAtFileOffset:relocLocation withLength:relocLength andValue:relocValue];
//NSLog(@"undef32: %@ %.16qX --> (%u) %@",[self findSectionContainsRVA64:[self fileOffsetToRVA64:relocLocation]],[self fileOffsetToRVA64:relocLocation],relocLength,[self findSymbolAtRVA64:relocValue]);
}
else
{
NSParameterAssert(relocation_info->r_pcrel == false);
NSRange rangeReloc = NSMakeRange(relocLocation,0);
uint64_t relocAddend = [dataController read_uint64:rangeReloc];
if (relocAddend != 0)
{
[node.details appendRow:@"":@"":@"Addend"
:(int64_t)relocAddend < 0
? [NSString stringWithFormat:@"-0x%qX",-relocAddend]
: [NSString stringWithFormat:@"0x%qX",relocAddend]];
}
uint64_t relocValue = *symbols_64.begin() - nlist_64 - 1;
// update real data
relocValue += relocAddend;
[self addRelocAtFileOffset:relocLocation withLength:relocLength andValue:relocValue];
//NSLog(@"undef64: %@ %.16qX --> (%u) %@",[self findSectionContainsRVA64:[self fileOffsetToRVA64:relocLocation]],[self fileOffsetToRVA64:relocLocation],relocLength,[self findSymbolAtRVA64:relocValue]);
}
}
}
else // r_symbolnum means section index
{
// section relative (symbolNum means sectionNum)
if (relocation_info->r_symbolnum >= sections_64.size())
{
[NSException raise:@"Section"
format:@"index is out of range %u", relocation_info->r_symbolnum];
}
struct section_64 const * section_64 = [self getSection64ByIndex:relocation_info->r_symbolnum];
NSString * sectionName = [NSString stringWithFormat:@"(%s,%s)",
string(section_64->segname,16).c_str(),
string(section_64->sectname,16).c_str()];
if (relocation_info->r_symbolnum == R_ABS)
{
// absolute address
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Section"
:@"R_ABS"];
}
else
{
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Section"
:[NSString stringWithFormat:@"%u %@", relocation_info->r_symbolnum, sectionName]];
uint64_t relocLocation = [self RVAToFileOffset:baseAddress + relocation_info->r_address];
NSRange rangeReloc = NSMakeRange(relocLocation,0);
uint64_t relocValue = 0;
if ((mach_header_64->cputype == CPU_TYPE_X86_64 && relocation_info->r_type == X86_64_RELOC_SUBTRACTOR)
||
(mach_header_64->cputype == CPU_TYPE_ARM64 && relocation_info->r_type == ARM64_RELOC_SUBTRACTOR))
{
prev_relocation_info = relocation_info;
}
else if (prev_relocation_info)
{
// TODO: calculate if we will ever be interested of the target
// (usually used only in debug_line section)
prev_relocation_info = NULL;
}
else if (relocLength == sizeof(uint32_t))
{
relocValue = [dataController read_uint32:rangeReloc];
if ((mach_header_64->cputype == CPU_TYPE_X86_64 && relocation_info->r_type == X86_64_RELOC_UNSIGNED)
||
(mach_header_64->cputype == CPU_TYPE_ARM64 && relocation_info->r_type == ARM64_RELOC_UNSIGNED))
{
// 32bit direct relocation
NSParameterAssert (relocation_info->r_pcrel == false);
}
else
{
// 32bit PC relative signed relocation
NSParameterAssert (relocation_info->r_pcrel == true);
relocValue += relocation_info->r_address + baseAddress + relocLength;
if (mach_header_64->cputype == CPU_TYPE_X86_64)
{
relocValue -= (relocation_info->r_type == X86_64_RELOC_SIGNED_1 ? 1 :
relocation_info->r_type == X86_64_RELOC_SIGNED_2 ? 2 :
relocation_info->r_type == X86_64_RELOC_SIGNED_4 ? 4 : 0);
}
}
}
else if (relocLength == sizeof(uint64_t))
{
// 64bit direct relocation
NSParameterAssert (!(mach_header_64->cputype == CPU_TYPE_X86_64) || relocation_info->r_type == X86_64_RELOC_UNSIGNED);
NSParameterAssert (!(mach_header_64->cputype == CPU_TYPE_ARM64) || relocation_info->r_type == ARM64_RELOC_UNSIGNED);
NSParameterAssert (relocation_info->r_pcrel == false);
relocValue = [dataController read_uint64:rangeReloc];
}
else
{
NSAssert(NO, @"Unsupported 64bit reloc");
}
[node.details appendRow:@"":@"":@"Target":(symbolName = [self findSymbolAtRVA:relocValue])];
// update real data
[self addRelocAtFileOffset:relocLocation withLength:relocLength andValue:relocValue];
[symbolNames setObject:[NSString stringWithFormat:@"%@->%@",
[self findSymbolAtRVA:[self fileOffsetToRVA:relocLocation]],symbolName]
forKey:[NSNumber numberWithUnsignedLongLong:[self fileOffsetToRVA:relocLocation]]];
//NSLog(@"%@ %.16qX --> (%u) %@",[self findSectionContainsRVA64:[self fileOffsetToRVA64:relocLocation]],[self fileOffsetToRVA64:relocLocation],relocLength,[self findSymbolAtRVA64:relocValue]);
}
}
//========== end of differentation
if (mach_header_64->cputype == CPU_TYPE_X86_64)
{
[node.details appendRow:@"":@"":@"Type"
:relocation_info->r_type == X86_64_RELOC_UNSIGNED ? @"X86_64_RELOC_UNSIGNED" :
relocation_info->r_type == X86_64_RELOC_SIGNED ? @"X86_64_RELOC_SIGNED" :
relocation_info->r_type == X86_64_RELOC_BRANCH ? @"X86_64_RELOC_BRANCH" :
relocation_info->r_type == X86_64_RELOC_GOT_LOAD ? @"X86_64_RELOC_GOT_LOAD" :
relocation_info->r_type == X86_64_RELOC_GOT ? @"X86_64_RELOC_GOT" :
relocation_info->r_type == X86_64_RELOC_SUBTRACTOR ? @"X86_64_RELOC_SUBTRACTOR" :
relocation_info->r_type == X86_64_RELOC_SIGNED_1 ? @"X86_64_RELOC_SIGNED_1" :
relocation_info->r_type == X86_64_RELOC_SIGNED_2 ? @"X86_64_RELOC_SIGNED_2" :
relocation_info->r_type == X86_64_RELOC_SIGNED_4 ? @"X86_64_RELOC_SIGNED_4" : @"?????"];
}
else if (mach_header_64->cputype == CPU_TYPE_ARM64)
{
[node.details appendRow:@"":@"":@"Type"
:relocation_info->r_type == ARM64_RELOC_UNSIGNED ? @"ARM64_RELOC_UNSIGNED" :
relocation_info->r_type == ARM64_RELOC_SUBTRACTOR ? @"ARM64_RELOC_SUBTRACTOR" :
relocation_info->r_type == ARM64_RELOC_BRANCH26 ? @"ARM64_RELOC_BRANCH26" :
relocation_info->r_type == ARM64_RELOC_PAGE21 ? @"ARM64_RELOC_PAGE21" :
relocation_info->r_type == ARM64_RELOC_PAGEOFF12 ? @"ARM64_RELOC_PAGEOFF12" :
relocation_info->r_type == ARM64_RELOC_GOT_LOAD_PAGE21 ? @"ARM64_RELOC_GOT_LOAD_PAGE21" :
relocation_info->r_type == ARM64_RELOC_GOT_LOAD_PAGEOFF12 ? @"ARM64_RELOC_GOT_LOAD_PAGEOFF12" :
relocation_info->r_type == ARM64_RELOC_POINTER_TO_GOT ? @"ARM64_RELOC_POINTER_TO_GOT" :
relocation_info->r_type == ARM64_RELOC_TLVP_LOAD_PAGE21 ? @"ARM64_RELOC_TLVP_LOAD_PAGE21" :
relocation_info->r_type == ARM64_RELOC_TLVP_LOAD_PAGEOFF12 ? @"ARM64_RELOC_TLVP_LOAD_PAGEOFF12" :
relocation_info->r_type == ARM64_RELOC_ADDEND ? @"ARM64_RELOC_ADDEND" : @"?????"];
}
if (relocation_info)
{
[node.details appendRow:@"":@"":@"External"
:relocation_info->r_extern ? @"True" : @"False"];
}
[node.details appendRow:@"":@"":@"PCRelative"
:relocation_info->r_pcrel ? @"True" : @"False"];
[node.details appendRow:@"":@"":@"Length"
:[NSString stringWithFormat:@"%u", relocLength]];
[node.details setAttributesFromRowIndex:bookmark:MVMetaDataAttributeName,symbolName,
MVCellColorAttributeName,color,nil];
[node.details setAttributes:MVUnderlineAttributeName,@"YES",nil];
} // loop relocs
return node;
}
//-----------------------------------------------------------------------------
- (MVNode *) createSymbolsNode:parent
caption:(NSString *)caption
location:(uint64_t)location
length:(uint64_t)length
{
MVNodeSaver nodeSaver;
MVNode * node = [parent insertChildWithDetails:caption location:location length:length saver:nodeSaver];
NSRange range = NSMakeRange(location,0);
NSString * lastReadHex;
for (uint32_t nsym = 0; nsym < length / sizeof(struct nlist); ++nsym)
{
if ([backgroundThread isCancelled]) break;
MATCH_STRUCT(nlist, location + nsym * sizeof(struct nlist))
// accumulate search info
NSUInteger bookmark = node.details.rowCount;
NSString * symbolName = NSSTRING(strtab + nlist->n_un.n_strx);
NSColor * color = nil;
/* print the symbol nr */
[node.details appendRow:[NSString stringWithFormat:@"#%d", nsym]
:@""
:@""
:@""];
[dataController read_uint32:range lastReadHex:&lastReadHex];
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"String Table Index"
:symbolName];
[dataController read_uint8:range lastReadHex:&lastReadHex];
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Type"
:@""];
if (nlist->n_type & N_STAB)
{
[node.details appendRow:@"":@"":@"E0":@"N_STAB"];
color = [NSColor magentaColor];
}
else
{
switch (nlist->n_type & N_TYPE)
{
case N_UNDF: [node.details appendRow:@"":@"":@"00":@"N_UNDF"]; break;
case N_ABS: [node.details appendRow:@"":@"":@"02":@"N_ABS"]; break;
case N_SECT: [node.details appendRow:@"":@"":@"0E":@"N_SECT"]; break;
case N_PBUD: [node.details appendRow:@"":@"":@"0C":@"N_PBUD"]; break;
case N_INDR: [node.details appendRow:@"":@"":@"0A":@"N_INDR"]; break;
}
if (nlist->n_type & N_PEXT) [node.details appendRow:@"":@"":@"10":@"N_PEXT"];
if (nlist->n_type & N_EXT) [node.details appendRow:@"":@"":@"01":@"N_EXT"];
if (nlist->n_type & N_EXT) color = ((nlist->n_type & N_TYPE) == N_UNDF || (nlist->n_type & N_TYPE) == N_PBUD
? [NSColor greenColor] : [NSColor orangeColor]);
}
struct section const * section = [self getSectionByIndex:nlist->n_sect];
[dataController read_uint8:range lastReadHex:&lastReadHex];
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Section Index"
:nlist->n_sect == NO_SECT ? @"NO_SECT"
: [NSString stringWithFormat:@"%u (%s,%s)",
nlist->n_sect,
string(section->segname,16).c_str(),
string(section->sectname,16).c_str()]];
[dataController read_uint16:range lastReadHex:&lastReadHex];
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Description"
:@""];
if ((nlist->n_type & N_STAB) == 0 &&
((nlist->n_type & N_TYPE) == N_UNDF || (nlist->n_type & N_TYPE) == N_PBUD) &&
(nlist->n_type & N_EXT))
{
switch (nlist->n_desc & REFERENCE_TYPE)
{
case REFERENCE_FLAG_UNDEFINED_NON_LAZY: [node.details appendRow:@"":@"":@"0":@"REFERENCE_FLAG_UNDEFINED_NON_LAZY"]; break;
case REFERENCE_FLAG_UNDEFINED_LAZY: [node.details appendRow:@"":@"":@"1":@"REFERENCE_FLAG_UNDEFINED_LAZY"]; break;
case REFERENCE_FLAG_DEFINED: [node.details appendRow:@"":@"":@"2":@"REFERENCE_FLAG_DEFINED"]; break;
case REFERENCE_FLAG_PRIVATE_DEFINED: [node.details appendRow:@"":@"":@"3":@"REFERENCE_FLAG_PRIVATE_DEFINED"]; break;
case REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY: [node.details appendRow:@"":@"":@"4":@"REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY"]; break;
case REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY: [node.details appendRow:@"":@"":@"5":@"REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY"]; break;
default:
[node.details appendRow:@"":@"":[NSString stringWithFormat:@"%u",nlist->n_desc & REFERENCE_TYPE]:@"???"]; break;
}
uint32_t libOrdinal = GET_LIBRARY_ORDINAL(nlist->n_desc);
struct dylib const * dylib = [self getDylibByIndex:libOrdinal];
[node.details appendRow:@"":@"":@"Library Ordinal"
:[NSString stringWithFormat:@"%u (%@)",libOrdinal,
libOrdinal == SELF_LIBRARY_ORDINAL ? @"SELF_LIBRARY_ORDINAL" :
libOrdinal == DYNAMIC_LOOKUP_ORDINAL ? @"DYNAMIC_LOOKUP_ORDINAL" :
libOrdinal == EXECUTABLE_ORDINAL ? @"EXECUTABLE_ORDINAL" :
[NSSTRING((uint8_t *)dylib + dylib->name.offset - sizeof(struct load_command)) lastPathComponent]]];
}
if ((nlist->n_desc & N_ARM_THUMB_DEF) == N_ARM_THUMB_DEF) [node.details appendRow:@"":@"":@"0008":@"N_ARM_THUMB_DEF"];
if ((nlist->n_desc & REFERENCED_DYNAMICALLY) == REFERENCED_DYNAMICALLY) [node.details appendRow:@"":@"":@"0010":@"REFERENCED_DYNAMICALLY"];
if ((nlist->n_desc & N_NO_DEAD_STRIP) == N_NO_DEAD_STRIP) [node.details appendRow:@"":@"":@"0020":@"N_NO_DEAD_STRIP"];
if ((nlist->n_desc & N_WEAK_REF) == N_WEAK_REF) [node.details appendRow:@"":@"":@"0040":@"N_WEAK_REF"];
if ((nlist->n_type & N_TYPE) == N_UNDF)
{
if ((nlist->n_desc & N_REF_TO_WEAK) == N_REF_TO_WEAK) [node.details appendRow:@"":@"":@"0080":@"N_REF_TO_WEAK"];
}
else
{
if ((nlist->n_desc & N_WEAK_DEF) == N_WEAK_DEF) [node.details appendRow:@"":@"":@"0080":@"N_WEAK_DEF"];
if ((nlist->n_desc & N_SYMBOL_RESOLVER) == N_SYMBOL_RESOLVER) [node.details appendRow:@"":@"":@"0100":@"N_SYMBOL_RESOLVER"];
}
[dataController read_uint32:range lastReadHex:&lastReadHex];
if ((nlist->n_type & N_TYPE) == N_SECT)
{
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Value"
:(nlist->n_type & N_STAB) || section == NULL
? [NSString stringWithFormat:@"%u", nlist->n_value] : nlist->n_value == 0 ? @"0"
: [NSString stringWithFormat:@"%u ($+%u)", nlist->n_value, nlist->n_value - section->addr]];
// fill in lookup table with defined sybols
if ((nlist->n_type & N_STAB) == 0)
{
// it is possible to associate more than one symbol to the same address.
// every new symbol will be appended to the list
NSString * nameToStore = [symbolNames objectForKey:[NSNumber numberWithUnsignedLong:nlist->n_value]];
nameToStore = (nameToStore != nil
? [nameToStore stringByAppendingFormat:@"(%@)", symbolName]
: [NSString stringWithFormat:@"0x%X (%@)", nlist->n_value, symbolName]);
[symbolNames setObject:nameToStore
forKey:[NSNumber numberWithUnsignedLong:nlist->n_value]];
}
}
else
{
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Value"
:[NSString stringWithFormat:@"%u", nlist->n_value]];
// fill in lookup table with undefined sybols (key equals (-1) * index)
uint32_t key = (uint32_t)(*symbols.begin() - nlist - 1);
[symbolNames setObject:symbolName
forKey:[NSNumber numberWithUnsignedLong:key]];
}
[node.details setAttributesFromRowIndex:bookmark:MVMetaDataAttributeName,symbolName,
MVCellColorAttributeName,color,nil];
[node.details setAttributes:MVUnderlineAttributeName,@"YES",nil];
} // loop
return node;
}
//-----------------------------------------------------------------------------
- (MVNode *) createSymbols64Node:parent
caption:(NSString *)caption
location:(uint64_t)location
length:(uint64_t)length
{
MVNodeSaver nodeSaver;
MVNode * node = [parent insertChildWithDetails:caption location:location length:length saver:nodeSaver];
NSRange range = NSMakeRange(location,0);
NSString * lastReadHex;
for (uint32_t nsym = 0; nsym < length / sizeof(struct nlist_64); ++nsym)
{
if ([backgroundThread isCancelled]) break;
MATCH_STRUCT(nlist_64, location + nsym * sizeof(struct nlist_64))
// accumulate search info
NSUInteger bookmark = node.details.rowCount;
NSString * symbolName = NSSTRING(strtab + nlist_64->n_un.n_strx);
NSColor * color = nil;
/* print the symbol nr */
[node.details appendRow:[NSString stringWithFormat:@"#%d", nsym]
:@""
:@""
:@""];
[dataController read_uint32:range lastReadHex:&lastReadHex];
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"String Table Index"
:symbolName];
[dataController read_uint8:range lastReadHex:&lastReadHex];
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Type"
:@""];
if (nlist_64->n_type & N_STAB)
{
[node.details appendRow:@"":@"":@"E0":@"N_STAB"];
color = [NSColor magentaColor];
}
else
{
switch (nlist_64->n_type & N_TYPE)
{
case N_UNDF: [node.details appendRow:@"":@"":@"00":@"N_UNDF"]; break;
case N_ABS: [node.details appendRow:@"":@"":@"02":@"N_ABS"]; break;
case N_SECT: [node.details appendRow:@"":@"":@"0E":@"N_SECT"]; break;
case N_PBUD: [node.details appendRow:@"":@"":@"0C":@"N_PBUD"]; break;
case N_INDR: [node.details appendRow:@"":@"":@"0A":@"N_INDR"]; break;
}
if (nlist_64->n_type & N_PEXT) [node.details appendRow:@"":@"":@"10":@"N_PEXT"];
if (nlist_64->n_type & N_EXT) [node.details appendRow:@"":@"":@"01":@"N_EXT"];
if (nlist_64->n_type & N_EXT) color = ((nlist_64->n_type & N_TYPE) == N_UNDF || (nlist_64->n_type & N_TYPE) == N_PBUD
? [NSColor greenColor] : [NSColor orangeColor]);
}
struct section_64 const * section_64 = [self getSection64ByIndex:nlist_64->n_sect];
[dataController read_uint8:range lastReadHex:&lastReadHex];
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Section Index"
:nlist_64->n_sect == NO_SECT ? @"NO_SECT"
: [NSString stringWithFormat:@"%u (%s,%s)",
nlist_64->n_sect,
string(section_64->segname,16).c_str(),
string(section_64->sectname,16).c_str()]];
[dataController read_uint16:range lastReadHex:&lastReadHex];
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Description"
:@""];
if ((nlist_64->n_type & N_STAB) == 0 &&
((nlist_64->n_type & N_TYPE) == N_UNDF || (nlist_64->n_type & N_TYPE) == N_PBUD) &&
(nlist_64->n_type & N_EXT))
{
switch (nlist_64->n_desc & REFERENCE_TYPE)
{
case REFERENCE_FLAG_UNDEFINED_NON_LAZY: [node.details appendRow:@"":@"":@"0":@"REFERENCE_FLAG_UNDEFINED_NON_LAZY"]; break;
case REFERENCE_FLAG_UNDEFINED_LAZY: [node.details appendRow:@"":@"":@"1":@"REFERENCE_FLAG_UNDEFINED_LAZY"]; break;
case REFERENCE_FLAG_DEFINED: [node.details appendRow:@"":@"":@"2":@"REFERENCE_FLAG_DEFINED"]; break;
case REFERENCE_FLAG_PRIVATE_DEFINED: [node.details appendRow:@"":@"":@"3":@"REFERENCE_FLAG_PRIVATE_DEFINED"]; break;
case REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY: [node.details appendRow:@"":@"":@"4":@"REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY"]; break;
case REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY: [node.details appendRow:@"":@"":@"5":@"REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY"]; break;
default:
[node.details appendRow:@"":@"":[NSString stringWithFormat:@"%u",nlist_64->n_desc & REFERENCE_TYPE]:@"???"]; break;
}
uint32_t libOrdinal = GET_LIBRARY_ORDINAL(nlist_64->n_desc);
struct dylib const * dylib = [self getDylibByIndex:libOrdinal];
[node.details appendRow:@"":@"":@"Library Ordinal"
:[NSString stringWithFormat:@"%u (%@)",libOrdinal,
libOrdinal == SELF_LIBRARY_ORDINAL ? @"SELF_LIBRARY_ORDINAL" :
libOrdinal == DYNAMIC_LOOKUP_ORDINAL ? @"DYNAMIC_LOOKUP_ORDINAL" :
libOrdinal == EXECUTABLE_ORDINAL ? @"EXECUTABLE_ORDINAL" :
[NSSTRING((uint8_t *)dylib + dylib->name.offset - sizeof(struct load_command)) lastPathComponent]]];
}
if ((nlist_64->n_desc & REFERENCED_DYNAMICALLY) == REFERENCED_DYNAMICALLY) [node.details appendRow:@"":@"":@"0010":@"REFERENCED_DYNAMICALLY"];
if ((nlist_64->n_desc & N_NO_DEAD_STRIP) == N_NO_DEAD_STRIP) [node.details appendRow:@"":@"":@"0020":@"N_NO_DEAD_STRIP"];
if ((nlist_64->n_desc & N_WEAK_REF) == N_WEAK_REF) [node.details appendRow:@"":@"":@"0040":@"N_WEAK_REF"];
if ((nlist_64->n_desc & N_WEAK_DEF) == N_WEAK_DEF) [node.details appendRow:@"":@"":@"0080":
(nlist_64->n_type & N_TYPE) == N_UNDF || (nlist_64->n_type & N_TYPE) == N_PBUD
? @"N_REF_TO_WEAK"
: @"N_WEAK_DEF"];
if ((nlist_64->n_desc & N_SYMBOL_RESOLVER) == N_SYMBOL_RESOLVER) [node.details appendRow:@"":@"":@"0100":@"N_SYMBOL_RESOLVER"];
[dataController read_uint64:range lastReadHex:&lastReadHex];
if ((nlist_64->n_type & N_TYPE) == N_SECT)
{
[node.details appendRow:[NSString stringWithFormat:@"%.8lX", range.location]
:lastReadHex
:@"Value"
:(nlist_64->n_type & N_STAB) || section_64 == NULL
? [NSString stringWithFormat:@"%qu", nlist_64->n_value] : nlist_64->n_value == 0 ? @"0"
: [NSString stringWithFormat:@"%qu ($+%qu)", nlist_64->n_value, nlist_64->n_value - section_64->addr]];
// fill in lookup table with defined sybols
if ((nlist_64->n_type & N_STAB) == 0)
{
// it is possible to associate more than one symbol to the same address.
// every new symbol will be appended to the list
NSString * nameToStore = [symbolNames objectForKey:[NSNumber numberWithUnsignedLongLong:nlist_64->n_value]];
nameToStore = (nameToStore != nil
? [nameToStore stringByAppendingFormat:@"(%@)", symbolName]