Beispiel #1
0
    /*
     * Read in symbol table
     */
static void
getsymtab(FILE *nfile, const char *filename)
{
    register long	i;
    int			askfor;
    struct nlist	nbuf;

    /* pass1 - count symbols */
    fseek(nfile, (long)N_SYMOFF(xbuf), 0);
    nname = 0;
    for (i = xbuf.a_syms; i > 0; i -= sizeof(struct nlist)) {
	fread(&nbuf, sizeof(nbuf), 1, nfile);
	if ( ! funcsymbol( &nbuf ) ) {
	    continue;
	}
	nname++;
    }
    if (nname == 0)
	errx( 1 , "%s: no symbols" , filename );
    askfor = nname + 1;
    nl = (nltype *) calloc( askfor , sizeof(nltype) );
    if (nl == 0)
	errx( 1 , "no room for %d bytes of symbol table" ,
		askfor * sizeof(nltype) );

    /* pass2 - read symbols */
    fseek(nfile, (long)N_SYMOFF(xbuf), 0);
    npe = nl;
    nname = 0;
    for (i = xbuf.a_syms; i > 0; i -= sizeof(struct nlist)) {
	fread(&nbuf, sizeof(nbuf), 1, nfile);
	if ( ! funcsymbol( &nbuf ) ) {
#	    ifdef DEBUG
		if ( debug & AOUTDEBUG ) {
		    printf( "[getsymtab] rejecting: 0x%x %s\n" ,
			    nbuf.n_type , strtab + nbuf.n_un.n_strx );
		}
#	    endif /* DEBUG */
	    continue;
	}
	npe->value = nbuf.n_value;
	npe->name = strtab+nbuf.n_un.n_strx;
#	ifdef DEBUG
	    if ( debug & AOUTDEBUG ) {
		printf( "[getsymtab] %d %s 0x%08lx\n" ,
			nname , npe -> name , npe -> value );
	    }
#	endif /* DEBUG */
	npe++;
	nname++;
    }
    npe->value = -1;
}
Beispiel #2
0
static
void
count_func_symbols(
struct nlist *symbols,
struct nlist_64 *symbols64,
unsigned long nsymbols,
char *strings,
unsigned long strsize)
{
    unsigned long i;
    uint32_t n_strx;
    uint8_t n_type;
    uint8_t n_sect;

	for(i = 0; i < nsymbols; i++){
	    if(symbols != NULL){
		n_strx = symbols[i].n_un.n_strx;
		n_type = symbols[i].n_type;
		n_sect = symbols[i].n_sect;
	    }
	    else{
		n_strx = symbols64[i].n_un.n_strx;
		n_type = symbols64[i].n_type;
		n_sect = symbols64[i].n_sect;
	    }
	    if(n_strx != 0 && n_strx < strsize){
		if(funcsymbol(n_type, n_sect, strings + n_strx))
		    nname++;
	    }
	}
}
Beispiel #3
0
static
void
load_func_symbols(
struct nlist *symbols,
struct nlist_64 *symbols64,
unsigned long nsymbols,
char *strings,
unsigned long strsize,
unsigned long vmaddr_slide)
{
    unsigned long i;
    uint32_t n_strx;
    uint8_t n_type;
    uint8_t n_sect;
    uint64_t n_value;

	for(i = 0; i < nsymbols; i++){
	    if(symbols != NULL){
		n_strx = symbols[i].n_un.n_strx;
		n_type = symbols[i].n_type;
		n_sect = symbols[i].n_sect;
		n_value = symbols[i].n_value;
	    }
	    else{
		n_strx = symbols64[i].n_un.n_strx;
		n_type = symbols64[i].n_type;
		n_sect = symbols64[i].n_sect;
		n_value = symbols64[i].n_value;
	    }
	    if(n_strx != 0 && n_strx < strsize){
		if(funcsymbol(n_type, n_sect, strings + n_strx)){
		    npe->value = n_value + vmaddr_slide;
		    npe->name = strings + n_strx;
		    npe++;
		}
	    }
	}
}