cechew@bruce.OZ (Earl Chew) (11/20/89)
There is a minor problem with dos2out. Large .exe headers will confuse it. Earl ------------------------------------------------------------------------------- *** a:dos2out.c Mon May 08 23:23:42 1989 --- dos2out.c Sat Nov 18 22:56:54 1989 *************** *** 96,103 **** #define A_BLR(cputype) ((cputype&0x01)!=0) /* TRUE if bytes left-to-right */ #define A_WLR(cputype) ((cputype&0x02)!=0) /* TRUE if words left-to-right */ ! #include <stdio.h> #include <fcntl.h> #include <io.h> #include <sys/stat.h> --- 96,104 ---- #define A_BLR(cputype) ((cputype&0x01)!=0) /* TRUE if bytes left-to-right */ #define A_WLR(cputype) ((cputype&0x02)!=0) /* TRUE if words left-to-right */ ! #include <stdlib.h> #include <stdio.h> + #include <string.h> #include <fcntl.h> #include <io.h> #include <sys/stat.h> *************** *** 133,138 **** --- 134,140 ---- unsigned int sym, /* data-relocation symbol offset */ sym_blk, sym_off; /* load-module block & offset in blk */ + long exehdr; /* length of exe header */ long d_size, /* size of data-segment */ t_size, /* size of text-segment */ load_size; /* size of load-module in bytes */ *************** *** 221,226 **** --- 223,231 ---- /*========================= PROCESS FILE =============================*/ + /* remember the length of the header */ + exehdr = d_ptr->hdr_size * 16; + /* get reloc symbol's position in load-module */ sym = (unsigned int) inbuf[d_ptr->reloc_table+3] << 12; sym += (unsigned int) inbuf[d_ptr->reloc_table+2] << 4; *************** *** 238,252 **** /* get symbol and calculate sizes */ sepid = inbuf2[sym_off+1] | inbuf2[sym_off+0]; t_size = (sym+2 + 0xf) & ~0xf; ! load_size = (long) (d_ptr->nr_of_pages - 1 - (d_ptr->last_page_size!=0)) ! * PH_SECTSIZE + d_ptr->last_page_size; if ((d_size = load_size - t_size) < 0) d_size = 0; ! /* reposition file */ ! close (inf); ! inf=open(in_name,O_RDONLY); ! in_cnt=read(inf,inbuf2,PH_SECTSIZE); /* make a.out header */ a_ptr->a_magic[0] = MAGIC0; --- 243,258 ---- /* get symbol and calculate sizes */ sepid = inbuf2[sym_off+1] | inbuf2[sym_off+0]; t_size = (sym+2 + 0xf) & ~0xf; ! load_size = (long) (d_ptr->nr_of_pages - (d_ptr->last_page_size!=0)) ! * PH_SECTSIZE + d_ptr->last_page_size - exehdr; if ((d_size = load_size - t_size) < 0) d_size = 0; ! /* reposition file at start of code */ ! if (lseek(inf, exehdr, SEEK_SET) == -1) { ! fprintf(stderr, "Cannot seek to start of code\n"); ! exit(1); ! } /* make a.out header */ a_ptr->a_magic[0] = MAGIC0; ------------------------------------------------------------------------------- -- Earl Chew, Dept of Computer Science, Monash University, Australia 3168 ARPA: cechew%bruce.cs.monash.oz.au@uunet.uu.net ACS : cechew@bruce.oz ----------------------------------------------------------------------