|
|
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(head), 1, fp) || ! 40: head.f_magic != C_386_MAGIC) { ! 41: fclose (fp); ! 42: return (0); ! 43: } ! 44: ! 45: fseek(fp, head.f_symptr + (SYMESZ * head.f_nsyms), 0); ! 46: if (1 != fread(&str_length, sizeof(str_length), 1, fp)) ! 47: str_length = 0; ! 48: if (str_length) { ! 49: unsigned len; ! 50: ! 51: len = str_length -= 4; ! 52: if (len != str_length || NULL == (str_tab = malloc(len))) { ! 53: fclose (fp); ! 54: return (0); ! 55: } ! 56: ! 57: if (1 != fread(str_tab, len, 1, fp)) { ! 58: free(str_tab); ! 59: fclose (fp); ! 60: return (0); ! 61: } ! 62: } ! 63: ! 64: fseek(fp, head.f_symptr, 0); ! 65: for (i = aux = 0; i < head.f_nsyms; i++) { ! 66: SYMENT sym; /* symbol read in */ ! 67: int taux, j; ! 68: ! 69: if (1 != fread(&sym, SYMESZ, 1, fp)) { ! 70: free(str_tab); ! 71: fclose (fp); ! 72: return (0); ! 73: } ! 74: if (aux) { ! 75: aux--; ! 76: continue; ! 77: } ! 78: aux = sym.n_numaux; ! 79: for (j = taux = 0; j < count; j++) { ! 80: static char n1[SYMNMLEN + 1], n2[SYMNMLEN + 1]; ! 81: register SYMENT *np; ! 82: ! 83: if (taux) { ! 84: taux--; ! 85: continue; ! 86: } ! 87: np = nlp + j; ! 88: taux = np->n_numaux; ! 89: if (np->n_type != 0xFFFF || ! 90: strcmp(symName(np, names, n1), ! 91: symName(&sym, str_tab, n2))) ! 92: continue; ! 93: np->n_value = sym.n_value; ! 94: np->n_scnum = sym.n_scnum; ! 95: np->n_type = sym.n_type; ! 96: np->n_sclass = sym.n_sclass; ! 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.