shithub: scc

Download patch

ref: 0665b2980f119a119f4c158a7d82267c640f953f
parent: 6ae55e2a61f1de10f7d41e37ff5bf9fa532532be
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Nov 27 15:08:33 EST 2017

[objdump] Add printsections()

This function prints all the sections of the file.

--- a/objdump/main.c
+++ b/objdump/main.c
@@ -68,6 +68,33 @@
 	}
 }
 
+static int
+printsections(struct myrohdr *hdr, FILE *fp)
+{
+	size_t n, i;
+	struct myrosect sect;
+
+	puts("sections:");
+	n = hdr->secsize / MYROSECT_SIZ;
+	for (i = 0; i < n; ++i) {
+		if (rdmyrosec(fp, &sect) < 0)
+			return -1;
+		printf("\tname: %lu (\"%s\")\n"
+		       "\tflags: %x\n"
+		       "\tfill: %x\n"
+		       "\taligment: %u\n"
+		       "\toffset: %llu\n"
+		       "\tlength: %llu\n\n",
+		        sect.name, getstring(sect.name),
+		        sect.flags,
+		        sect.fill,
+		        sect.aligment,
+		        sect.offset,
+		        sect.len);
+	}
+	return 0;
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -84,8 +111,10 @@
 			goto wrong_file;
 		if (rdmyrohdr(fp, &hdr) < 0)
 			goto wrong_file;
-		if (hdr.strsize > SIZE_MAX)
+		if (hdr.strsize > SIZE_MAX ||
+		    hdr.secsize > SIZE_MAX / MYROSECT_SIZ) {
 			goto overflow;
+		}
 		strsiz = hdr.strsize;
 
 		if (strsiz > 0) {
@@ -97,6 +126,8 @@
 
 		printhdr(&hdr);
 		printstrings(&hdr);
+		if (printsections(&hdr, fp) < 0)
+			goto wrong_file;
 
 
 		goto close_file;