home *** CD-ROM | disk | FTP | other *** search
- From: news@and.cs.liv.ac.uk
- Newsgroups: alt.sources
- Subject: Undumper for HPUX 7.0
- Message-ID: <1991Jul16.101517.297@and.cs.liv.ac.uk>
- Date: 16 Jul 91 10:15:15 GMT
-
- The below 'undump' program is for HPUX 7.xx Series 300 machines.
-
- Undump enables you to create pre-loaded programs
- e.g. a fast starting version of 'TeX' with pre-loaded
- format file.
-
- #---------------------------------- cut here ----------------------------------
- # This is a shell archive. Remove anything before this line,
- # then unpack it by saving it in a file and typing "sh file".
- #
- # Wrapped by David Nixon <djn@di8> on Thu May 23 15:23:02 1991
- #
- # This archive contains:
- # undump.c
- #
- # Error checking via wc(1) will be performed.
-
- LANG=""; export LANG
- PATH=/bin:/usr/bin:$PATH; export PATH
-
- echo x - undump.c
- cat >undump.c <<'@EOF'
- /* undump * Ver. 1.2 : 1/11/90 * Author: D.J.Nixon
- *
- * (C.) 1990 University of Liverpool
- *
-
- or HPUX on series 300 machines.
- *
- */
-
- /*
- Compilation: cc -O -DWOPR -o undump undump.c
-
- Syntax: undump [b.out] [a.out] [core]
-
- Given an executable and its core image 'undump' will combine
- the executable's header and text with data from the core file
- to build an "un-dumped" executable.
-
- Use to create "pre-loaded" programs such as 'TeX'.
-
- N.B. this version works with HPUX 7.0 shared, demand paged and non-shared executables.
- */
-
- #ifndef WOPR
- #define WOPR
- #endif
- #include <stdio.h>
- #include <fcntl.h>
- #include <signal.h>
- #include <errno.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/param.h>
- #include <sys/user.h>
- #include <sys/sysmacros.h>
- #define USERPAGES (EXEC_PAGESIZE * UPAGES) /* size of u-area in core file */
-
-
- extern int errno;
- struct exec hdr;
- struct user usr;
- int ex,core,nex; /* file descriptors */
- char *undumped;
-
- long lseek(), copyf();
- void fatal_err();
- int handler();
-
- void main(argc, argv)
- _int argc;
- char *argv[4];
- {
- long offset,
- bytecount,
- orig_data_sz;
- /* Open files and set signals. */
- if (argc != 4) {
- fprintf(stderr,"Usage: undump [b.out] [a.out] [core]\n"); exit(0);
- }
- if ((ex=open(argv[2], O_RDONLY)) == -1) {
- fatal_err("Can't open a.out file");
- }
- if ((core=open(argv[3], O_RDONLY)) == -1) {
- fatal_err("Can't open core file");
- }
- if ((nex=open(argv[1], O_WRONLY | O_CREAT | O_EXCL, 0700)) == -1) {
- fatal_err("Can't create b.out file");
- }
- signal(SIGQUIT, SIG_IGN);
- signal(SIGINT, handler);
- undumped=argv[1];
- /* Read in a.out file header. */
- if ((read(ex, &hdr, sizeof(struct exec))) < sizeof(struct exec))
- fatal_err("Could not read a.out file header");
- /* Check a.out file is executable. */
- if (N_BADMAG(hdr)) fatal_err("Bad magic number");
- /* save this to get symtabs offset later */
- orig_data_sz=hdr.a_data;
- udata,hdr.a_bss);
- /* Read in user area to get size of b.out data segment */
- if ((read(core, &usr, sizeof(struct user))) < sizeof(struct user))
- fatal_err("Could not read user area from core");
- if (hdr.a_magic.file_type != EXEC_MAGIC)
- hdr.a_data=ctob(usr.u_dsize); /* exact */
- /* Get size of core */
- if ((offset=lseek(core, 0L, 2)) == -1)
- fatal_err("Error seeking to end of core file");
- printf("core : %u u_area : %u\n",offset,USERPAGES);
- if (hdr.a_magic.file_type == EXEC_MAGIC)
- hdr.a_data=(offset - (USERPAGES + hdr.a_text)); /* data plus shell env. */
- hdr.a_bss=(0L); /* zero length BSS segment */
- printf("b.out :- text %u data %u bss %u\n\n",hdr.a_text,hdr.a_data,hdr.a_bss);
- /* Copy a.out header and text segment to b.out file. */
- if ((write(nex, &hdr, sizeof(struct exec))) < sizeof(struct exec))
- t");
- lseek(ex, TEXT_OFFSET(hdr), 0);
- lseek(nex, TEXT_OFFSET(hdr), 0);
- printf("copying %u bytes of text\n",hdr.a_text);
- if ((bytecount=copyf(ex, nex, hdr.a_text)) < hdr.a_text ) {
- if (bytecount < 0L) {
- fatal_err("Error copying text segment to b.out");
- } else {
- fatal_err("At EOF in a.out text segment");
- }
- }
- /* Copy contiguous data/BSS segment from core file to b.out file data segment. */
- if (hdr.a_magic.file_type == EXEC_MAGIC) /* normal executable; text dumped */
- offset=(USERPAGES + hdr.a_text);
- else
- offset=(USERPAGES); /* no text dumped for shared or demand paged */
- lseek(core, offset, 0);
- lseek(nex, DATA_OFFSET(hdr), 0);
- printf("copying %u bytes of undumped data\n",hdr.a_data);
- if ((bytecount=copyf(core, nex, hdr.a_data)) < hdr.a_data) {
- if (bytecount < 0L) {
- fatal_err("Error copying data segment to b.out");
- } else {
- fatal_err("At EOF in core");
- }
- }
- /* Copy symbol table and debugging info. onto end of b.out file */
- {
- long symtabs_sz=(hdr.a_trsize + hdr.a_drsize + hdr.a_pasint + hdr.a_lesyms + hdr.a_dnttsize + hdr.a_sltsize + hdr.a_vtsize);
- hdr.a_data=orig_data_sz;
- lseek(ex, MODCAL_OFFSET(hdr), 0);
- printf("copying %u bytes of symbol data\n",symtabs_sz);
- if ((bytecount=copyf(ex, nex, symtabs_sz)) < symtabs_sz) {
- if (bytecount < 0L) {
- fatal_err("Error copying symbol tables to b.out");
- } else {
- fatal_err("At EOF in a.out");
- }
- }
- }
- puts("\nundump done\n");
- exit(0);
- } /* main */
-
- /*
- * copyf
- *
- * Copies specified number of bytes from file f1 to file f2.
- *
- */
- long copyf(f1,f2,bytes)
- int f1,f2;
- long bytes;
- {
- char buf[BUFSIZ];
- register long count=0L;
- register int n,diff;
- while((n=read(f1, buf, BUFSIZ)) > 0) {
- count+=n;
- if (count > bytes) {
- diff=(count - bytes);
- if (lseek(f1, -(diff), 1) == -1) {
- return(-3L);
- }
- n-=(diff);
- count-=(diff);
- }
- if (write(f2, buf, n) == -1) {
- return(-2L);
- }
- if (count >= bytes) {
- break;
- }
- }
- if (n == -1) {
- return(-1L);
- } else {
- return(count);
- }
- }
-
- /*
- * fatal_err
- *
- */
- void fatal_err(message)
- char *message;
- {
- if (errno) perror(message);
- else
- fprintf(stderr,"%s\n",message);
- close(nex);
- unlink(undumped);
- exit(1);
- }
-
- /*
- * handler
- *
- * Removes b.out file on interrupt.
- *
- */
- handler(sig)
- int sig;
- {
- puts("Interrupt");
- close(nex);
- unlink(undumped);
- exit(1);
- }
- @EOF
- set `wc -lwc <undump.c`
- if test $1$2$3 != 2037115689
- then
- echo ERROR: wc results of undump.c are $* should be 203 711 5689
- fi
-
- chmod 644 undump.c
-
- exit 0
-