scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit ab1aa62f96d477d4ba584eef7bfd436d63767be6
parent d90e6fd689d42cd8b519650687db9cea5c0c3d0c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 27 Nov 2017 20:08:33 +0100

[objdump] Add printsections()

This function prints all the sections of the file.

Diffstat:
Mobjdump/main.c | 33++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/objdump/main.c b/objdump/main.c @@ -68,6 +68,33 @@ printstrings(struct myrohdr *hdr) } } +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 @@ main(int argc, char *argv[]) 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 @@ main(int argc, char *argv[]) printhdr(&hdr); printstrings(&hdr); + if (printsections(&hdr, fp) < 0) + goto wrong_file; goto close_file;