|
|
1.1 root 1: /*
2: * Get entries from coff nlist.
3: */
4: #include <stdio.h>
5: #include <coff.h>
6:
7: /*
8: * Symbol name.
9: */
10: static char *
11: symName(sym, str_tab, work)
12: SYMENT *sym;
13: char *str_tab, *work;
14: {
15: if (!sym->n_zeroes)
16: return (str_tab + sym->n_offset - 4);
17:
18: /* make sure it's zero terminated */
19: memcpy(work, sym->n_name, SYMNMLEN);
20: work[SYMNMLEN] = '\0';
21: return (work);
22: }
23:
24: coffnlist(fn, nlp, names, count)
25: char *fn; /* file name */
26: SYMENT *nlp; /* names to look up */
27: char *names; /* long names */
28: int count; /* size of passed table */
29: {
30: FILEHDR head;
31: FILE *fp;
32: char *str_tab;
33: long str_length;
34: int aux, i;
35:
36: if (NULL == (fp = fopen(fn, "rb")))
37: return(0);
38:
39: if (1 != fread(&head, sizeof(FILEHDR), 1, fp) || head.f_magic != C_386_MAGIC) {
40: fclose (fp);
41: return (0);
42: }
43:
44: fseek(fp, head.f_symptr + (SYMESZ * head.f_nsyms), 0);
45: if (1 != fread(&str_length, sizeof(str_length), 1, fp))
46: str_length = 0;
47: if (str_length) {
48: unsigned len;
49:
50: len = str_length -= 4;
51: if (len != str_length || NULL == (str_tab = malloc(len))) {
52: fclose (fp);
53: return (0);
54: }
55:
56: if (1 != fread(str_tab, len, 1, fp)) {
57: free(str_tab);
58: fclose (fp);
59: return (0);
60: }
61: }
62:
63: fseek(fp, head.f_symptr, 0);
64: for (i = aux = 0; i < head.f_nsyms; i++) {
65: SYMENT sym; /* symbol read in */
66: int taux, j;
67:
68: if (1 != fread(&sym, SYMESZ, 1, fp)) {
69: free(str_tab);
70: fclose (fp);
71: return (0);
72: }
73: if (aux) {
74: aux--;
75: continue;
76: }
77: aux = sym.n_numaux;
78: for (j = taux = 0; j < count; j++) {
79: static char n1[SYMNMLEN + 1], n2[SYMNMLEN + 1];
80: register SYMENT *np;
81:
82: if (taux) {
83: taux--;
84: continue;
85: }
86: np = nlp + j;
87: taux = np->n_numaux;
88: if (np->n_type != -1 ||
89: strcmp(symName(np, names, n1),
90: symName(&sym, str_tab, n2)))
91: continue;
92: np->n_value = sym.n_value;
93: np->n_scnum = sym.n_scnum;
94: np->n_type = sym.n_type;
95: np->n_sclass = sym.n_sclass;
96: break;
97: }
98: }
99: free(str_tab);
100: fclose (fp);
101: return (1);
102: }
103:
104: #ifdef TEST
105: main()
106: {
107: static SYMENT sym[3];
108: static char ptr[] = "a_very_long_name";
109:
110: strcpy(sym[0]._n._n_name, "x");
111: sym[0].n_type = -1;
112:
113: strcpy(sym[1]._n._n_name, "y");
114: sym[1].n_type = -1;
115:
116: sym[2]._n._n_n._n_zeroes = 0;
117: sym[2]._n._n_n._n_offset = sizeof(long);
118: sym[2].n_type = -1;
119:
120: coffnlist("tx.o", sym, ptr, 3);
121: }
122: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.