diff 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
line wrap: on
line diff
--- a/objgrep/dumpmatch.c	Fri Jul 04 03:07:09 2014 +0000
+++ b/objgrep/dumpmatch.c	Fri Jul 04 03:22:41 2014 +0000
@@ -38,3 +38,70 @@
 		}
 	}
 }
+
+static unsigned
+arm_branch_reloc(location)
+	unsigned location;
+{
+	unsigned word, dest;
+
+	word = get_u32(binfilemap + location);
+	dest = (word & 0x00FFFFFF) << 2;
+	if (dest & 0x02000000)
+		dest |= 0xFC000000;
+	dest += location + 8;
+	return(dest);
+}
+
+static unsigned
+thumb_bl_reloc(location)
+	unsigned location;
+{
+	unsigned ins1, ins2;
+	unsigned dest;
+
+	ins1 = get_u16(binfilemap + location);
+	ins2 = get_u16(binfilemap + location + 2);
+	dest = ((ins1 & 0x7FF) << 12) | ((ins2 & 0x7FF) << 1);
+	if (dest & 0x00400000)
+		dest |= 0xFF800000;
+	dest += location + 4;
+	return(dest);
+}
+
+dump_relocs_on_match()
+{
+	unsigned n, value;
+	struct internal_reloc *rel;
+
+	printf("\nDeduced from relocs:\n\n");
+	for (n = 0, rel = relocs; n < grep_section->nreloc; n++, rel++) {
+		switch (rel->type) {
+		case RTYPE_LONG:
+			value = get_u32(binfilemap + match_offset +
+					rel->location);
+			break;
+		case RTYPE_ARM_B:
+			value = arm_branch_reloc(match_offset + rel->location);
+			break;
+		case RTYPE_THUMB_BL:
+			value = thumb_bl_reloc(match_offset + rel->location);
+			break;
+		default:
+			fprintf(stderr,
+			"BUG in dump_relocs_on_match(): bad reloc type\n");
+			abort();
+		}
+		value -= rel->addend;
+		if (rel->secbase)
+			printf("%s:%s = %08X\n", objfilename,
+				rel->secbase->name, value);
+		else if (rel->extsym)
+			printf("%s = %08X\n", rel->extsym->name, value);
+		else {
+			fprintf(stderr,
+			"BUG in dump_relocs_on_match(): no base for reloc\n");
+			abort();
+		}
+	}
+}