|
|
1.1 ! root 1: #include <stdio.h> ! 2: #include <sys/types.h> ! 3: #include <pagsiz.h> ! 4: #include <a.out.h> ! 5: ! 6: FILE *map; ! 7: int aout; ! 8: #define NEWSIZ 50000 ! 9: char newstrb[NEWSIZ]; ! 10: ! 11: main(argc, argv) ! 12: int argc; ! 13: char *argv[]; ! 14: { ! 15: char sym[50], svalue[50]; ! 16: char *strb,*newstr,*malloc(); ! 17: char *curstr; ! 18: int value; ! 19: int cnt; ! 20: int strsiz; ! 21: int strcnt; ! 22: int size; ! 23: struct nlist a; ! 24: struct exec e; ! 25: ! 26: argc--, argv++; ! 27: if (argc == 0 || argc > 2) { ! 28: usage: ! 29: fprintf(stderr, "usage: tackon map [ a.out ]\n"); ! 30: exit(1); ! 31: } ! 32: map = fopen(argv[0], "r"); ! 33: if (map == NULL) { ! 34: perror(argv[0]); ! 35: exit(1); ! 36: } ! 37: aout = open(argc == 2 ? argv[1] : "a.out", 2); ! 38: if (aout < 0) { ! 39: printf(" No object file to tackon or text busy\n"); ! 40: exit(1); ! 41: } ! 42: read(aout,&e, sizeof(e)); ! 43: /* read current string table into buffer */ ! 44: lseek(aout, N_STROFF(e), 0); /* seek to string table beginning */ ! 45: read(aout,&strsiz,4); /* read in string table size */ ! 46: strb = malloc(strsiz); ! 47: read(aout,strb,strsiz); /* read in string table */ ! 48: lseek(aout, N_STROFF(e), 0); /* now write at end of symbols */ ! 49: cnt = 0; ! 50: strcnt = 4 + strsiz; ! 51: curstr = newstrb; /* point to new string buffer */ ! 52: for (;;) { ! 53: if (fgets(sym, 50, map) == NULL) ! 54: break; ! 55: sym[size=strlen(sym)-1] = 0; ! 56: if (fgets(svalue, 50, map) == NULL) { ! 57: fprintf(stderr, "missing value\n"); ! 58: break; ! 59: } ! 60: strcpy(curstr,sym); ! 61: sscanf(svalue, "%x", &a.n_value); ! 62: a.n_un.n_strx = strcnt; ! 63: a.n_type = N_EXT|N_TEXT; ! 64: write(aout, &a, sizeof (a)); ! 65: curstr += size+1; ! 66: strcnt += size+1; ! 67: cnt++; ! 68: if( curstr >= &newstrb[NEWSIZ]) ! 69: { ! 70: printf(" Tackon; string buffer overflow \n"); ! 71: exit(1); ! 72: } ! 73: } ! 74: write(aout, &strcnt, 4); /* new character count */ ! 75: write(aout, strb, strsiz); /* write out old string table */ ! 76: write(aout, newstrb, strcnt - ( 4 + strsiz)); ! 77: lseek(aout, 0, 0); ! 78: e.a_syms += cnt*sizeof(struct nlist); ! 79: lseek(aout, 0, 0); ! 80: write(aout, &e, sizeof (e)); ! 81: exit(0); ! 82: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.