shithub: scc

Download patch

ref: b73d39323bf98cf2a69294815cc020d02555391c
parent: ddd03ea3045bd6d12db62662695479317a44cbe0
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Nov 27 15:47:05 EST 2017

[objdump] Add printdata()

This function prints a binary dump of the data.

--- a/objdump/main.c
+++ b/objdump/main.c
@@ -149,6 +149,31 @@
 	return 0;
 }
 
+static int
+printdata(struct myrohdr *hdr, FILE *fp)
+{
+	unsigned long off;
+	int c, i, j;
+
+	puts("data:");
+	for (off = 0; ; off += 32) {
+		printf("\t%08x:", off);
+		for (i = 0; i < 2; i++) {
+			for (j = 0; j < 16; j++) {
+				if ((c = getc(fp)) == EOF)
+					goto exit_loop;
+				printf(" %02X", c);
+			}
+			putchar('\t');
+		}
+		putchar('\n');
+	}
+
+exit_loop:
+	putchar('\n');
+	return (ferror(fp)) ? -1 : 0;
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -187,6 +212,8 @@
 		if (printsymbols(&hdr, fp) < 0)
 			goto wrong_file;
 		if (printrelocs(&hdr, fp) < 0)
+			goto wrong_file;
+		if (printdata(&hdr, fp) < 0)
 			goto wrong_file;
 
 		goto close_file;