|
|
1.1 ! root 1: #include <a.out.h> ! 2: int a_magic[] = {A_MAGIC1, A_MAGIC2, A_MAGIC3, A_MAGIC4, 0}; ! 3: #define SPACE 100 /* number of symbols read at a time */ ! 4: ! 5: nlist(name, list) ! 6: char *name; ! 7: struct nlist *list; ! 8: { ! 9: register struct nlist *p, *q; ! 10: register int f, n, m, i, nreq; ! 11: long sa; ! 12: struct exec buf; ! 13: struct nlist space[SPACE]; ! 14: ! 15: for(p = list, nreq = 0; p->n_name[0]; p++, nreq++) { ! 16: p->n_type = 0; ! 17: p->n_value = 0; ! 18: } ! 19: f = open(name, 0); ! 20: if(f < 0) ! 21: return(-1); ! 22: read(f, (char *)&buf, sizeof buf); ! 23: for(i=0; a_magic[i]; i++) ! 24: if(a_magic[i] == buf.a_magic) break; ! 25: if(a_magic[i] == 0){ ! 26: close(f); ! 27: return(-1); ! 28: } ! 29: sa = buf.a_text + (long)buf.a_data; ! 30: sa += buf.a_trsize + buf.a_drsize; ! 31: sa += sizeof buf; ! 32: lseek(f, sa, 0); ! 33: n = buf.a_syms; ! 34: ! 35: while(n){ ! 36: m = sizeof space; ! 37: if(n < sizeof space) ! 38: m = n; ! 39: read(f, (char *)space, m); ! 40: n -= m; ! 41: for(q = space; (m -= sizeof(struct nlist)) >= 0; q++) { ! 42: for(p = list; p->n_name[0]; p++) { ! 43: for(i=0;i<8;i++) ! 44: if(p->n_name[i] != q->n_name[i]) goto cont; ! 45: p->n_value = q->n_value; ! 46: p->n_type = q->n_type; ! 47: if(--nreq == 0) ! 48: goto alldone; ! 49: break; ! 50: cont: ; ! 51: } ! 52: } ! 53: } ! 54: alldone: ! 55: close(f); ! 56: return(0); ! 57: } ! 58: ! 59:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.