FreeCalypso > hg > freecalypso-reveng
changeset 73:10f3fbff5e97
tiobjd: symbol table parsing implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Tue, 25 Mar 2014 18:34:03 +0000 |
parents | 2bec477178fc |
children | 2eef88395908 |
files | ticoff/basics.c ticoff/globals.c ticoff/globals.h ticoff/intstruct.h ticoff/tables.c |
diffstat | 5 files changed, 72 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ticoff/basics.c Tue Mar 25 08:51:32 2014 +0000 +++ b/ticoff/basics.c Tue Mar 25 18:34:03 2014 +0000 @@ -45,6 +45,17 @@ return ptr[0] | ptr[1] << 8; } +get_s16(ptr) + u_char *ptr; +{ + int i; + + i = ptr[0] | ptr[1] << 8; + if (i >= 32768) + i -= 65536; + return(i); +} + unsigned get_u32(ptr) u_char *ptr;
--- a/ticoff/globals.c Tue Mar 25 08:51:32 2014 +0000 +++ b/ticoff/globals.c Tue Mar 25 18:34:03 2014 +0000 @@ -16,3 +16,4 @@ unsigned strtab_offset; struct internal_scnhdr *sections; +struct internal_syment **symtab;
--- a/ticoff/globals.h Tue Mar 25 08:51:32 2014 +0000 +++ b/ticoff/globals.h Tue Mar 25 18:34:03 2014 +0000 @@ -14,3 +14,4 @@ extern unsigned strtab_offset; extern struct internal_scnhdr *sections; +extern struct internal_syment **symtab;
--- a/ticoff/intstruct.h Tue Mar 25 08:51:32 2014 +0000 +++ b/ticoff/intstruct.h Tue Mar 25 18:34:03 2014 +0000 @@ -13,3 +13,12 @@ unsigned nlineent; unsigned flags; }; + +struct internal_syment { + char *name; + unsigned value; + int scnum; + int type; + int class; + u_char *aux; +};
--- a/ticoff/tables.c Tue Mar 25 08:51:32 2014 +0000 +++ b/ticoff/tables.c Tue Mar 25 18:34:03 2014 +0000 @@ -93,3 +93,53 @@ } exit(0); } + +get_int_symbol_table() +{ + unsigned n; + struct internal_syment *in; + + symtab = malloc(sizeof(struct internal_syment *) * nsymtab); + if (!symtab) { + perror("malloc"); + exit(1); + } + for (n = 0; n < nsymtab; ) { + in = malloc(sizeof(struct internal_syment)); + if (!in) { + perror("malloc"); + exit(1); + } + symtab[n] = in; + in->name = get_secorsym_name(symtab_raw[n].e_name); + in->value = get_u32(symtab_raw[n].e_value); + in->scnum = get_s16(symtab_raw[n].e_scnum); + if (in->scnum < -2 || in->scnum > nsections) { + fprintf(stderr, + "symtab entry #%u: scnum out of range\n", n); + exit(1); + } + in->type = get_u16(symtab_raw[n].e_type); + in->class = symtab_raw[n].e_sclass; + switch (symtab_raw[n++].e_numaux) { + case 0: + in->aux = 0; + continue; + case 1: + if (n >= nsymtab) { + fprintf(stderr, + "error: last symbol's aux spills over\n"); + exit(1); + } + symtab[n] = 0; + in->aux = (u_char *)(symtab_raw + n); + n++; + continue; + default: + n--; + fprintf(stderr, "symtab entry #%u: invalid numaux\n", + n); + exit(1); + } + } +}