int lua_elf_t_class (lua_State * L)
{
    struct _elf * elf;
    
    elf = lua_check_elf(L, 1);
    lua_pop(L, 1);
    
    if (elf_class(elf) == ELFCLASS32)
        lua_pushinteger(L, 32);
    else if (elf_class(elf) == ELFCLASS64)
        lua_pushinteger(L, 64);
    return 1;
}
Exemple #2
0
static int
binary_sym_read(sym_binary_t *binary, sym_type_t sym_type)
{
	sym_class_t cls;
	int ret = -1;

	if ((binary->fp = fopen(binary->path, "r")) == NULL) {		
		return (-1);
	}
		
	if ((cls = elf_class(binary->fp)) == SYM_CLASS_INVALID) {
		goto L_EXIT;
	}

	if ((s_sym_ops[cls].pfn_binary_read)(binary, sym_type) != 0) {
		goto L_EXIT;
	}

	ret = 0;

L_EXIT:
	fclose(binary->fp);
	binary->fp = NULL;
	return (ret);	
}
Exemple #3
0
void *get_bytes(struct elf_handle *h, char *symbol, int *size)
{
    int count;
    void *ret;
    void *main_hdr = h->main_header;
    void *sym = elf_get_symbol_entry(h, symbol);
    void *sect = elf_get_section_entry(h, ".text");

    if (sym == NULL)
        return NULL;

    if (elf_class(main_hdr) == ELFCLASS32) {
        fseek(h->fp, E32_SHDR(sect)->sh_offset, SEEK_SET);
        if (E32_SYM(sym)->st_size != 0) {
            fseek(h->fp, E32_SYM(sym)->st_value -
                    E32_EHDR(h->main_header)->e_entry, SEEK_CUR);
            count = E32_SYM(sym)->st_size;
        } else {
            fprintf(stderr, "Apparently %s is 0 bytes. Using .text instead\n", symbol);
            count = E32_SHDR(sect)->sh_size;
        }
    } else {
        fseek(h->fp, E64_SHDR(sect)->sh_offset, SEEK_SET);
        if (E64_SYM(sym)->st_size != 0) {
            fseek(h->fp, E64_SYM(sym)->st_value -
                    E64_EHDR(h->main_header)->e_entry, SEEK_CUR);
            count = E64_SYM(sym)->st_size;
        } else {
            fprintf(stderr, "Apparently %s is 0 bytes. Using .text instead\n", symbol);
            count = E64_SHDR(sect)->sh_size;
        }
    }

    *size = count;
    ret = malloc(count);
    fread(ret, count, 1, h->fp);

    return ret;
}