|
|
1.1 ! root 1: #include "strip.h" ! 2: ! 3: Adotout * ! 4: rdout(name, sflag) ! 5: register char *name; ! 6: { ! 7: register Adotout *a; Adotout *rderr(); ! 8: if ((a = Calloc(Adotout, 1)) == 0) ! 9: return rderr(a, name); ! 10: a->name = name; ! 11: if ((a->fd = open(a->name, 0)) < 0) ! 12: return rderr(a, "cannot open file"); ! 13: fstat(a->fd, &a->filstat); ! 14: if (Read(a->fd, (char *)&a->hd, sizeof(struct exec))) ! 15: return rderr(a, "cannot read header"); ! 16: if (N_BADMAG(a->hd)) ! 17: return rderr(a, "bad magic number"); ! 18: ! 19: if (a->nsymbols = a->hd.a_syms/sizeof(struct nlist)) { ! 20: lseek(a->fd, N_STROFF(a->hd), 0); ! 21: if (Read(a->fd, (char *)&a->strsize, sizeof(long)) || ! 22: a->strsize < 4) ! 23: return rderr(a, "read failed on string table size"); ! 24: } ! 25: ! 26: if (sflag && a->nsymbols) { ! 27: if ((a->symtab = Malloc(struct nlist, a->nsymbols+1)) == 0) ! 28: return rderr(a, "cannot malloc symbol table"); ! 29: lseek(a->fd, N_SYMOFF(a->hd), 0); ! 30: if (Read(a->fd, (char *)a->symtab, a->hd.a_syms)) ! 31: return rderr(a, "read failed on symbol table"); ! 32: a->symend = (struct nlist *)((char *)a->symtab + a->hd.a_syms); ! 33: a->symend->n_un.n_name = 0; ! 34: a->symend->n_type = 0; ! 35: a->symend->n_other = 0; ! 36: a->symend->n_desc = 0; ! 37: a->symend->n_value = 0; ! 38: ! 39: if ((a->strtab = Malloc(char, a->strsize)) == 0) ! 40: return rderr(a, "cannot malloc string table"); ! 41: lseek(a->fd, N_STROFF(a->hd), 0); ! 42: if (Read(a->fd, (char *)a->strtab, a->strsize)) ! 43: return rderr(a, "read failed on string table"); ! 44: } ! 45: return a; ! 46: } ! 47: ! 48: freeout(a) ! 49: register Adotout *a; ! 50: { ! 51: if (a) { ! 52: if (a->fd) ! 53: close(a->fd); ! 54: Free(a->symtab); ! 55: Free(a->strtab); ! 56: free(a); ! 57: } ! 58: } ! 59: ! 60: Adotout * ! 61: rderr(a, s) ! 62: register Adotout *a; register char *s; ! 63: { ! 64: if (a) { ! 65: fprintf(stderr, "%s: file %s\n", s, a->name); ! 66: freeout(a); ! 67: } else { ! 68: fprintf(stderr, "cannot allocate struct Adotout: file %s\n", s); ! 69: } ! 70: return 0; ! 71: } ! 72: ! 73: prtout(a) ! 74: register Adotout *a; ! 75: { ! 76: printf("magic number = 0%o\n", a->hd.a_magic); ! 77: printf("text size = %d = 0x%x\n", a->hd.a_text, a->hd.a_text); ! 78: printf("data size = %d = 0x%x\n", a->hd.a_data, a->hd.a_data); ! 79: printf("bss size = %d = 0x%x\n", a->hd.a_bss, a->hd.a_bss); ! 80: printf("sym tab size = %d (%d)\n", a->hd.a_syms, a->nsymbols); ! 81: printf("entry point = 0x%x\n", a->hd.a_entry); ! 82: printf("text rel size = %d\n", a->hd.a_trsize); ! 83: printf("data rel size = %d\n", a->hd.a_drsize); ! 84: printf("str tab size = %d\n", a->strsize); ! 85: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.