home *** CD-ROM | disk | FTP | other *** search
- /*
- * (C) Copyright 1991 Stephen A. Bleazard <Steve@RoboBar.Co.Uk>
- *
- * Permission is granted to redistribute this program and any derivatives
- * thereof in source or binary form, for any purpose, including commercial
- * use, provided that this copyright message is retained in the source code
- * and is reproduced in full in any documentation that accompanies such
- * redistribution. Source code redistribution is encouraged, but is not
- * mandatory. The rcsid string above must be retained unmodified in any
- * redistributed binary.
- *
- * NO WARRANTY: This software is licensed free of charge without any claim
- * regarding its fitness for any purpose. The Licensor cannot accept
- * responsibility for any damage arising from the use or inability to use
- * this software for any purpose.
- */
-
- char rcsid[] = "@(#) $Id: omfdump.c,v 1.1 1991/08/29 15:17:56 root Exp $";
-
- #ifdef __TSC__
- # include <io.h>
- # include <stdlib.h>
- # include <alloc.h>
- # include <stdarg.h>
- #else
- # include <varargs.h>
- extern char *sys_errlist[];
- extern int errno;
- #endif /* __TSC __ */
-
- #ifdef i386
- # undef i386
- #endif /* because I have variables called i386 */
-
- #include <ctype.h>
- #include <stdio.h>
- #include <string.h>
- #include <fcntl.h>
- #include <ar.h>
- #include "xenixomf.h"
-
- #define HDRSIZE 3
- #define TRUE 1
- #define FALSE 0
-
- #define NOERROR 0
- #define NODATA 1
- #define ILLSTRLEN 2
-
- #define EXT_EXTERN 0
- #define EXT_LOC_EXT 1
- #define EXT_FLOC_EXT 2
-
- #define PUB_16 0
- #define PUB_32 1
- #define PUB_LOC_32 2
- #define PUB_LOC_16 3
-
- typedef struct sName {
- char *name;
- struct sName *next;
- } Name;
-
- FILE *infile;
- FILE *outfile;
- int prevrdoff = 0, lastrdoff = 0;
- int lnamecnt = 1, extdefcnt = 1, segdefcnt = 1, grpdefcnt = 1;
- Name *lnamelst = NULL, *lastlname = NULL;
- int error = NOERROR;
- int rawdump = FALSE;
-
-
- void dump();
-
- main(argc, argv)
- char **argv;
- int argc;
- {
- int opt;
- extern optind;
-
- infile = stdin; outfile = stdout;
- #ifdef __TSC__
- setmode(fileno(infile), O_BINARY);
- #endif /* __TSC __ */
-
- while ((opt = getopt(argc, argv, "rv")) != EOF)
- {
- switch (opt)
- {
- case 'v':
- fprintf(stderr, "omfdump version %s\n", rcsid + 5);
- fprintf(stderr, "report bugs to steve@robobar.co.uk\n");
- break;
- case 'r':
- rawdump = TRUE;
- break;
- case '?':
- fprintf(stderr, "usage: omfdump [-r] file1...\n");
- exit(1);
- break;
- }
- }
-
- if (optind >= argc)
- dump();
- else
- {
- for ( ; optind < argc; optind++ )
- {
- if ((infile = fopen(argv[optind], "rb")) == NULL)
- {
- fprintf(stderr, "omfdump: cannot open %s (%s)\n",
- argv[optind], sys_errlist[errno]);
- }
- else
- dump();
- fclose(infile);
- }
- }
- }
-
- void abend(s)
- char *s;
- {
- fprintf(stderr, "Fatal Error: %s\n", s);
- exit(1);
- }
-
- #ifdef __TSC__
- void output(char *fmt, ...)
- {
- va_list args;
-
- va_start(args, fmt);
- if (error == NOERROR)
- vfprintf(outfile, fmt, args);
- va_end(args);
- }
- #else /* __TSC__ */
- void output(va_alist)
- va_dcl
- {
- char *fmt;
- va_list args;
-
- va_start(args);
- fmt = va_arg(args, char *);
- if (error == NOERROR)
- vfprintf(outfile, fmt, args);
- va_end(args);
- }
- #endif /* __TSC__ */
-
- void setinfilepos(pos)
- long pos;
- {
- fseek(infile, pos, 0);
- prevrdoff = lastrdoff = pos;
- }
-
- int rdbytes(buff, count)
- char *buff;
- int count;
- {
- prevrdoff = lastrdoff;
- lastrdoff += count;
- return (fread(buff, 1, count, infile) == count);
- }
-
- void skiprecord(reclen)
- int *reclen;
- {
- while (*reclen > 1)
- {
- unsigned char junk;
-
- if (!rdbytes(&junk, 1))
- *reclen = 0;
- (*reclen)--;
- }
- }
-
- int checkcnt(from, count)
- int *from, count;
- {
- if ((*from - 1) < count)
- {
- output("\nWarning: Not enough data in record\n");
- error = NODATA;
- skiprecord(from);
- return FALSE;
- }
- *from -= count;
- return TRUE;
- }
-
- void rddata(buff, count)
- char *buff;
- int count;
- {
- if (!rdbytes(buff, count))
- abend("unexpected end of file");
- }
-
- unsigned short rdmagic()
- {
- unsigned short magic;
-
- rddata(&magic, sizeof magic);
- return magic;
- }
-
- int rdarhdr(name, size)
- char *name;
- long *size;
- {
- char cjunk;
- short sjunk;
- long ljunk;
-
- if (!rdbytes(name, 14))
- return FALSE;
- rddata(&ljunk, sizeof(long));
- rddata(&cjunk, sizeof(char));
- rddata(&cjunk, sizeof(char));
- rddata(&sjunk, sizeof(short));
- rddata(size, sizeof(long));
- return TRUE;
- }
-
- long rdvint(count, reclen)
- int count;
- int *reclen;
- {
- long val = 0;
- unsigned char b;
- int i = 0;
-
- if (!checkcnt(reclen, count))
- return -1;
- while (i < count)
- {
- rddata(&b, 1);
- val = val | ((long)b << ( 8 * i));
- i++;
- }
- return val;
- }
-
- long rdoffset(i386, reclen)
- int i386;
- int *reclen;
- {
- return rdvint(i386 ? 4 : 2, reclen);
- }
-
- unsigned int rdword(reclen)
- int *reclen;
- {
- return (unsigned int)rdvint(2, reclen);
- }
-
- unsigned char rdbyte(reclen)
- int *reclen;
- {
- unsigned char b;
-
- if (!checkcnt(reclen, 1))
- return 0;
- rddata(&b, 1);
- return b;
- }
-
- unsigned int rdindex(reclen)
- int *reclen;
- {
- unsigned char b, b1;
-
- b = rdbyte(reclen);
- if (b < 128)
- return b;
- b1 = rdbyte(reclen);
- return (((unsigned int)b & 0x7f) << 8) + b1;
- }
-
- void rdomfstr(name, reclen)
- char *name;
- int *reclen;
- {
- unsigned char l;
-
- l = rdbyte(reclen);
- if (l > OMFNAMELENGTH)
- {
- output("\nWarning: illegal string length - skipping record\n");
- name[0] = '\0';
- error = ILLSTRLEN;
- skiprecord(reclen);
- return;
- }
- if (!checkcnt(reclen, l))
- {
- name[0] = '\0';
- return;
- }
- rddata(name, l); name[l] = '\0';
- }
-
- void addtolnamelst(s)
- char *s;
- {
- Name *node;
- int count;
-
- count = strlen(s);
- node = (Name *)malloc(sizeof(Name));
- node->next = NULL;
- if (lastlname == NULL)
- lnamelst = node;
- else
- lastlname->next = node;
- lastlname = node;
- node->name = (char *)malloc(count + 1);
- strncpy(node->name, s, count);
- node->name[count] = '\0';
- }
-
- displaylname(fp, index)
- FILE *fp;
- unsigned int index;
- {
- int i;
- Name *node = lnamelst;
-
-
- for (i = 1; i < index; i++)
- {
- if (node->next == NULL)
- break;
- else
- node = node->next;
- }
- output("\"%s\"", (node == NULL) ? "NoName" : node->name);
-
- }
-
- void dumpbytes(data, count)
- unsigned char *data;
- {
- int i;
-
- output("%6s", "");
- for (i = 0; i < count; i++)
- {
- output("%02x ", data[i]);
- if (i == 7) output(" ");
- }
- for (i = 16 - count; i > 0; i--)
- output(" ");
- output(" ");
-
- for (i = 0; i < count; i++)
- {
- char c = ((data[i] > 32) && (data[i] < 127)) ? data[i] : '.';
- output("%c", c);
- }
- output("\n");
- }
-
- void dumpdata(count)
- int count;
- {
- unsigned char buff[16];
-
- while (count != 0)
- {
- int size = count > 16 ? 16 : count;
-
- rddata(buff, size);
- dumpbytes(buff, size);
- count -= size;
- }
- }
-
- void outomfstr(p)
- unsigned char *p;
- {
- output("%c", '\"');
- while (*p != '\0')
- {
- unsigned char c = *p++;
-
- output((c > 31) && (c <= 128) ? "%c" : "\\%03o", c);
- }
- output("%c", '\"');
- }
-
- void skipchksum(reclen)
- int reclen;
- {
- unsigned char b;
-
- if (reclen > 1)
- {
- output("%d bytes of trailing garbage:\n", reclen - 1);
- dumpdata(reclen - 1);
- }
- else if (reclen < 1)
- output("No checksum");
- else
- rddata(&b, 1);
- }
-
- void theadr(reclen)
- int reclen;
- {
- unsigned char buff[OMFNAMELENGTH+2];
-
- output("THEADR ");
- rdomfstr(buff, &reclen);
- outomfstr(buff);
- output("\n");
- skipchksum(reclen);
- }
-
- void coment(reclen)
- int reclen;
- {
- unsigned char class, bits;
-
- output("COMENT ");
- bits = rdbyte(&reclen);
- class = rdbyte(&reclen);
- output("%s, ", (bits & CMT_PURGE) ? "NOPURGE" : "PURGE");
- output("%s, ", (bits & CMT_LIST) ? "NOLIST" : "LIST");
- output("CLASS = %d\n", class);
- dumpdata(reclen - 1);
- skipchksum(1);
- }
-
- void lnames(reclen)
- int reclen;
- {
- unsigned char buff[OMFNAMELENGTH+2]; /* include space for length byte */
- int i = 1;
-
- output("LNAMES ");
- while (reclen > 1)
- {
- rdomfstr(buff, &reclen);
- addtolnamelst(buff);
- output(i > 1 ? "%17d " : "%3d ", lnamecnt);
- outomfstr(buff);
- output("\n");
- i++; lnamecnt++;
- }
- skipchksum(1);
- }
-
- void segdef(reclen, i386)
- int reclen, i386;
- {
- unsigned int segname, classname, overlayname;
- long seglen;
- unsigned char attr;
- unsigned int frame, offset;
-
- attr = rdbyte(&reclen);
- if ((attr & SD_ALIGN) == 0)
- {
- frame = rdword(&reclen);
- offset = rdword(&reclen);
- }
- seglen = rdoffset(i386, &reclen);
- segname = rdindex(&reclen);
- classname = rdindex(&reclen);
- overlayname = rdindex(&reclen);
-
- if (i386)
- output("SEG386 %4d: ", segdefcnt++);
- else
- output("SEGDEF %4d: ", segdefcnt++);
-
- displaylname(outfile, segname);
- output(", Class = ");
- displaylname(outfile, classname);
- output(", ");
-
- switch (attr & SD_COMBO)
- {
- case SD_PRIV: output("NO COMBINE, "); break;
- case SD_HCOMM: output("HIGH_MEM COMM, "); break;
- case SD_PUBLIC: output("PUBLIC, "); break;
- case SD_BAD: output("UNDEFINED, "); break;
- case SD_C4: output("NOT-KNOWN, "); break;
- case SD_STACK: output("STACK, "); break;
- case SD_COMM: output("COMMON, "); break;
- case SD_RCOMM: output("REV-COMM, "); break;
- }
-
- switch (attr & SD_ALIGN)
- {
- case SD_ABS:output("ABSOLUTE (%d:%d),",frame,offset);break;
- case SD_BYTE: output("BYTE, "); break;
- case SD_WORD: output("WORD, "); break;
- case SD_PARA: output("PARA, "); break;
- case SD_PAGE: output("PAGE, "); break;
- case SD_DWORD: output("DWORD, "); break;
- case SD_LTL: output("LOAD-TIME, "); break;
- case 7: output("UKNOWN(7), "); break;
- }
-
- if (attr & SD_PGRES)
- output("PAGE-RES, ");
- if (i386)
- {
- if (attr & SD_64K)
- output("Len = %ld(B)", seglen);
- else
- output("Len = %ld", seglen);
- }
- else
- {
- if (attr & SD_64K)
- {
- output("Len = 65536");
- if (seglen != 0)
- output("(B, length != 0(%ld))",seglen);
- else
- output("(B)");
- }
- else
- output("Len = %ld", seglen);
- }
- output("\n");
- skipchksum(reclen);
- }
-
- void grpdef(reclen)
- int reclen;
- {
- unsigned int grpname;
-
- grpname = rdindex(&reclen);
- output("GRPDEF %4d: ", grpdefcnt++);
- displaylname(outfile, grpname);
- output("\n");
-
- while (reclen > 1)
- {
- unsigned char junk;
- int segindex;
-
- junk = rdbyte(&reclen);
- segindex = rdindex(&reclen);
- output("%6sSI = %d\n", "", segindex);
- }
- skipchksum(1);
- }
-
- void extdef(reclen, type)
- int reclen;
- int type;
- {
- int i = 1;
-
- switch (type)
- {
- case EXT_EXTERN: output("EXTDEF "); break;
- case EXT_LOC_EXT: output("LOCEXD "); break;
- case EXT_FLOC_EXT: output("FLCEXD "); break;
- }
- while (reclen > 1)
- {
- int type;
- unsigned char buff[OMFNAMELENGTH+2];
-
- rdomfstr(buff, &reclen);
- type = rdindex(&reclen);
- output(i > 1 ? "%17d " : "%3d ", extdefcnt);
- outomfstr(buff);
- output("\n");
- extdefcnt++; i++;
- }
- skipchksum(reclen);
-
- }
-
- void pubdef(reclen, rtype)
- int reclen;
- int rtype;
- {
- unsigned int grpindex, segindex, framenum;
-
- grpindex = rdindex(&reclen);
- segindex = rdindex(&reclen);
- if (grpindex == 0 && segindex == 0)
- framenum = rdword(&reclen);
-
- switch (rtype)
- {
- case PUB_32: output("PUB386 "); break;
- case PUB_16: output("PUBDEF "); break;
- case PUB_LOC_32: output("LPB386 "); break;
- case PUB_LOC_16: output("LOCPUB "); break;
- }
-
- output("GI = %d, SI = %d", grpindex, segindex);
- if (grpindex == 0 && segindex == 0)
- output(", Frame no. = 0x%x\n", framenum);
- else
- output("\n");
-
- while (reclen > 1)
- {
- unsigned char buff[OMFNAMELENGTH+2];
- unsigned long offset;
- int type;
- int i386 = (rtype == PUB_32) || (rtype == PUB_LOC_32);
-
- rdomfstr(buff, &reclen);
- offset = rdoffset(i386, &reclen);
- type = rdindex(&reclen);
-
- output("%18s", "");
- outomfstr(buff);
- output(" Offset = 0x%lx\n", offset);
- }
- skipchksum(reclen);
- }
-
- void frametype(method, index)
- unsigned int method;
- unsigned int index;
- {
- switch (method)
- {
- case FRM_SI: output("SI(%d)", index); break;
- case FRM_GI: output("GI(%d)", index); break;
- case FRM_EI: output("EI(%d)", index); break;
- case FRM_ABS: output("ABS(0x%x)", index); break;
- case FRM_LOC: output("LOCATION"); break;
- case FRM_TRGT: output("TARGET"); break;
- }
- }
-
- void targettype(method, index)
- unsigned int method;
- unsigned int index;
- {
- switch (method)
- {
- case TGT_SI: output("SI(%d)", index); break;
- case TGT_GI: output("GI(%d)", index); break;
- case TGT_EI: output("EI(%d)", index); break;
- case TGT_ABS: output("ABS(0x%x)", index); break;
- case TGT_SI_0: output("SI(%d)", index); break;
- case TGT_GI_0: output("GI(%d)", index); break;
- case TGT_EI_0: output("EI(%d)", index); break;
- case TGT_ABS_0: output("ABS(0x%x)", index); break;
- }
- }
-
- void threadfixup(i386, reclen, trd)
- int i386;
- int *reclen;
- unsigned char trd;
- {
- unsigned int index;
- int method;
-
- output("THREAD: ");
- method = (trd & TRD_MTHDMSK) >> TRD_MTHDSHFT;
- if (trd & TRD_FRAME)
- {
- if (method < 4)
- index = rdindex(reclen);
- output("FRAME=");
- frametype(method, index);
- }
- else
- {
- index = rdindex(reclen);
- output("TARGET=");
- targettype(method, index);
- }
- output(", THREAD=%d\n", trd & TRD_THRED);
- }
-
- void displayfixdat(i386, dat, reclen)
- int i386;
- int dat;
- int *reclen;
- {
- unsigned int frame, index, target;
-
- frame = (dat & FIXDAT_FRAME) >> FIXDAT_FRSHFT;
- if (dat & FIXDAT_FTHRD)
- output("Thread %d", frame);
- else
- {
- if (frame < 4)
- index = rdindex(reclen);
- frametype(frame, index);
- }
-
- output(" TARGET=");
- target = dat & FIXDAT_TRGT;
- if (dat & FIXDAT_TTHRD)
- output("Thread %d", target);
- else
- {
- index = rdindex(reclen);
- targettype(target, index);
- }
-
- if ((dat & FIXDAT_TSCND) == 0)
- output("+0x%lx", rdoffset(i386, reclen));
- }
-
- void fixupfixup(i386, reclen, locat)
- int i386;
- int *reclen;
- unsigned int locat;
- {
- unsigned int off, loc, fixdat;
-
- output("FIX @");
- off = locat & FIX_DATAOFF;
- loc = (locat & FIX_LOCMSK) >> FIX_LOCSHFT;
- output("0x%x Mode=%s", off, locat & FIX_SEG ? "Seg":"Self");
- output(", LOC=");
- switch (loc)
- {
- case LOC_LOBYTE: output("LoByte"); break;
- case LOC_OFFSET: output("Offset"); break;
- case LOC_BASE: output("Base"); break;
- case LOC_POINTER: output("Pointer"); break;
- case LOC_HIBTE: output("HiByte"); break;
- case LOC_OFFSETL: output("offset (link res)"); break;
- case LOC_OFFSET32: output("32 bit offset"); break;
- case LOC_POINTER48: output("48 bit pointer"); break;
- case LOC_OFFSETL32: output("32 bit offset (link res)"); break;
- default: output("Unknown"); break;
- }
-
- output(" => FRAME=");
- fixdat = rdbyte(reclen);
- displayfixdat(i386, fixdat, reclen);
- output("\n");
- }
-
- void fixup(i386, reclen)
- int i386;
- int reclen;
- {
- unsigned char b;
-
- if (i386)
- output("FIX386\n");
- else
- output("FIXUPP\n");
-
- while (reclen > 1)
- {
- output("%6s", "");
- b = rdbyte(&reclen);
- if (b & FIX_FIXUP)
- {
- unsigned int locat;
-
- locat = (b << 8) | rdbyte(&reclen);
- fixupfixup(i386, &reclen, locat);
- }
- else
- threadfixup(i386, &reclen, b);
- }
- skipchksum(1);
- }
-
- void comdef(reclen)
- int reclen;
- {
- int i = 1;
-
- output("COMDEF ");
-
- while (reclen > 1)
- {
- int type, flag;
- long size, width;
- unsigned char buff[OMFNAMELENGTH+2];
-
- output(i > 1 ? "%17d " : "%3d ", extdefcnt);
- rdomfstr(buff, &reclen);
- outomfstr(buff);
- output(", ");
- flag = rdbyte(&reclen);
- if (flag != 0)
- {
- output("Debug = 0x%02x", flag);
- flag = rdbyte(&reclen);
- output(" 0x%02x, ", flag);
- }
- type = rdbyte(&reclen);
- if (type == TD_CNEAR) output("NEAR, ");
- else if (type == TD_CFAR) output("FAR, ");
- else output("unknown, ");
-
- size = rdbyte(&reclen);
- if (size > 128)
- {
- switch (size)
- {
- case 129: size = rdvint(2, &reclen); break;
- case 132: size = rdvint(3, &reclen); break;
- case 136: size = rdvint(4, &reclen); break;
- }
- }
-
- if (type == 0x61)
- {
- width = rdbyte(&reclen);
- if (width > 128)
- {
- switch (width)
- {
- case 129: width = rdvint(2, &reclen); break;
- case 132: width = rdvint(3, &reclen); break;
- case 136: width = rdvint(4, &reclen); break;
- }
- }
-
- output("element width=%ld bytes, ", width);
- output("size=%ld elements\n", size);
- }
- else
- output("Size=%ld bytes\n", size);
- extdefcnt++; i++;
- }
- skipchksum(1);
- }
-
- void modend(i386, reclen)
- int i386;
- int reclen;
- {
- int type, saddr, enddat;
-
- if (i386)
- output("386END ");
- else
- output("MODEND ");
-
- type = rdbyte(&reclen);
-
- saddr = 0;
- switch ((type >> 6) & 3)
- {
- case 1:
- output("NON-MAIN Start address = ");
- saddr = 1;
- break;
- case 3:
- output("MAIN Start address = ");
- saddr = 1;
- break;
- }
- if (saddr)
- {
- enddat = rdbyte(&reclen);
- displayfixdat(i386, enddat, &reclen);
- }
- output("\n");
- skipchksum(reclen);
- }
-
- void ledata(i386, reclen)
- int i386;
- int reclen;
- {
- int segindex;
- long offset;
-
- if (i386)
- output("LED386 ");
- else
- output("LEDATA ");
-
- segindex = rdindex(&reclen);
- offset = rdoffset(i386, &reclen);
- output("SI = %d, Offset = 0x%lx\n", segindex, offset);
- dumpdata(reclen - 1);
- skipchksum(1);
- }
-
- void linnum(i386, reclen)
- int i386;
- int reclen;
- {
- int segindex, grpindex;
-
- if (i386)
- output("LIN386 ");
- else
- output("LINNUM ");
-
- grpindex = rdindex(&reclen);
- segindex = rdindex(&reclen);
- output("SI = %d\n", segindex);
- while (reclen > 1)
- {
- int line;
- long offset;
-
- line = rdword(&reclen);
- offset = rdoffset(i386, &reclen);
- output("%6sLine = %d, ", "", line);
- output("Offset = 0x%lx\n", offset);
- }
- skipchksum(1);
- }
-
- void dumprec(rectype, reclen)
- int rectype, reclen;
- {
- error = NOERROR;
- output("%5x ", prevrdoff);
-
- if (rawdump)
- {
- output("Record type = 0x%02x ", rectype);
- output("length = %d\n", reclen);
- dumpdata(reclen);
- }
- else
- {
- switch (rectype) {
- case MLNAMES:
- lnames(reclen);
- break;
- case MTHEADR:
- theadr(reclen);
- break;
- case MCOMENT:
- coment(reclen);
- break;
- case MSEGDEF:
- segdef(reclen, FALSE);
- break;
- case MSEG386:
- segdef(reclen, TRUE);
- break;
- case MGRPDEF:
- grpdef(reclen);
- break;
- case MPUBDEF:
- pubdef(reclen, PUB_16);
- break;
- case MPUB386:
- pubdef(reclen, PUB_32);
- break;
- case MLOCPUB:
- pubdef(reclen, PUB_LOC_16);
- break;
- case MLPB386:
- pubdef(reclen, PUB_LOC_32);
- break;
- case MEXTDEF:
- extdef(reclen, EXT_EXTERN);
- break;
- case MLOCEXD:
- extdef(reclen, EXT_LOC_EXT);
- break;
- case MFLCEXD:
- extdef(reclen, EXT_FLOC_EXT);
- break;
- case MFIXUPP:
- fixup(FALSE, reclen);
- break;
- case MFIX386:
- fixup(TRUE, reclen);
- break;
- case MCOMDEF:
- comdef(reclen);
- break;
- case M386END:
- modend(TRUE, reclen);
- break;
- case MLEDATA:
- ledata(FALSE, reclen);
- break;
- case MLED386:
- ledata(TRUE, reclen);
- break;
- case MMODEND:
- modend(FALSE, reclen);
- break;
- case MLINNUM:
- linnum(FALSE, reclen);
- break;
- case MLIN386:
- linnum(TRUE, reclen);
- break;
- default:
- output("Record type = 0x%02x ", rectype);
- output("length = %d\n", reclen);
- dumpdata(reclen);
- break;
- }
- }
- }
-
- void dumpobj()
- {
- unsigned char buff[HDRSIZE+2];
-
- while (rdbytes(buff, HDRSIZE))
- {
- int rectype, reclen;
-
- rectype = buff[0];
- reclen = buff[1] | ((int)buff[2] << 8);
- dumprec(rectype, reclen);
- }
- }
-
- void dumparsymdef(size)
- {
- char len;
- char name[256];
- long addr;
- unsigned short scount;
-
- for (rddata(&scount, sizeof(unsigned short)); scount > 0; scount--)
- {
- rddata(&len, 1);
- rddata(name, len);
- name[len] = 0;
- rddata(&addr, sizeof(long));
- size -= len + 1 + sizeof(long);
- output("0x%08x %s\n", addr, name);
- }
- }
-
- void dumparobj(size)
- long size;
- {
- long ftell();
- long startpos;
- unsigned char buff[HDRSIZE+2];
-
- startpos = ftell(infile);
- while (((ftell(infile) - startpos) < size) && rdbytes(buff, HDRSIZE))
- {
- int rectype, reclen;
-
- rectype = buff[0];
- reclen = buff[1] | ((int)buff[2] << 8);
- dumprec(rectype, reclen);
- }
- }
-
- void dumpar()
- {
- long ftell();
- char name[15];
- long size, memcount = 0, memoffset;
-
- rdmagic();
-
- name[14] = '\0'; memoffset = ftell(infile);
- while (rdarhdr(name, &size))
- {
- output("\n%s:\n", name);
- if (!memcount && (strcmp(name, "__.SYMDEF") == 0))
- dumparsymdef(size);
- else
- dumparobj(size);
- memcount++;
- memoffset += 26 + size;
- if (memoffset & 1) memoffset++;
- setinfilepos(memoffset);
- }
- }
-
- void dump()
- {
- unsigned short magic;
-
- prevrdoff = 0; lastrdoff = 0;
- lnamecnt = 1; extdefcnt = 1; segdefcnt = 1; grpdefcnt = 1;
- lnamelst = NULL; lastlname = NULL;
- error = NOERROR;
-
- magic = rdmagic();
- setinfilepos(0L);
- if (magic == XARMAG)
- dumpar();
- else
- dumpobj();
- }
-