comparison objgrep/dumpmatch.c @ 172:452baa748747

objgrep: -r implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 04 Jul 2014 03:22:41 +0000
parents ddbfc1a1a811
children 77cd647375e5
comparison
equal deleted inserted replaced
171:ddbfc1a1a811 172:452baa748747
36 sym->value + match_offset); 36 sym->value + match_offset);
37 continue; 37 continue;
38 } 38 }
39 } 39 }
40 } 40 }
41
42 static unsigned
43 arm_branch_reloc(location)
44 unsigned location;
45 {
46 unsigned word, dest;
47
48 word = get_u32(binfilemap + location);
49 dest = (word & 0x00FFFFFF) << 2;
50 if (dest & 0x02000000)
51 dest |= 0xFC000000;
52 dest += location + 8;
53 return(dest);
54 }
55
56 static unsigned
57 thumb_bl_reloc(location)
58 unsigned location;
59 {
60 unsigned ins1, ins2;
61 unsigned dest;
62
63 ins1 = get_u16(binfilemap + location);
64 ins2 = get_u16(binfilemap + location + 2);
65 dest = ((ins1 & 0x7FF) << 12) | ((ins2 & 0x7FF) << 1);
66 if (dest & 0x00400000)
67 dest |= 0xFF800000;
68 dest += location + 4;
69 return(dest);
70 }
71
72 dump_relocs_on_match()
73 {
74 unsigned n, value;
75 struct internal_reloc *rel;
76
77 printf("\nDeduced from relocs:\n\n");
78 for (n = 0, rel = relocs; n < grep_section->nreloc; n++, rel++) {
79 switch (rel->type) {
80 case RTYPE_LONG:
81 value = get_u32(binfilemap + match_offset +
82 rel->location);
83 break;
84 case RTYPE_ARM_B:
85 value = arm_branch_reloc(match_offset + rel->location);
86 break;
87 case RTYPE_THUMB_BL:
88 value = thumb_bl_reloc(match_offset + rel->location);
89 break;
90 default:
91 fprintf(stderr,
92 "BUG in dump_relocs_on_match(): bad reloc type\n");
93 abort();
94 }
95 value -= rel->addend;
96 if (rel->secbase)
97 printf("%s:%s = %08X\n", objfilename,
98 rel->secbase->name, value);
99 else if (rel->extsym)
100 printf("%s = %08X\n", rel->extsym->name, value);
101 else {
102 fprintf(stderr,
103 "BUG in dump_relocs_on_match(): no base for reloc\n");
104 abort();
105 }
106 }
107 }