コード例 #1
0
ファイル: elfdump.c プロジェクト: coyizumi/cs111
static void
elf_print_rel(Elf32_Ehdr *e, void *sh)
{
    u_int64_t offset;
    u_int64_t entsize;
    u_int64_t size;
    u_int64_t name;
    u_int64_t info;
    void *r;
    void *v;
    int i;

    offset = elf_get_off(e, sh, SH_OFFSET);
    entsize = elf_get_size(e, sh, SH_ENTSIZE);
    size = elf_get_size(e, sh, SH_SIZE);
    name = elf_get_word(e, sh, SH_NAME);
    v = (char *)e + offset;
    fprintf(out, "\nrelocation (%s):\n", shstrtab + name);
    for (i = 0; (u_int64_t)i < size / entsize; i++) {
        r = (char *)v + i * entsize;
        offset = elf_get_addr(e, r, R_OFFSET);
        info = elf_get_word(e, r, R_INFO);
        fprintf(out, "\n");
        fprintf(out, "entry: %d\n", i);
        fprintf(out, "\tr_offset: %#jx\n", offset);
        fprintf(out, "\tr_info: %jd\n", (intmax_t)info);
    }
}
コード例 #2
0
ファイル: elfdump.c プロジェクト: coyizumi/cs111
static void
elf_print_dynamic(Elf32_Ehdr *e, void *sh)
{
    u_int64_t offset;
    u_int64_t entsize;
    u_int64_t size;
    int64_t tag;
    u_int64_t ptr;
    u_int64_t val;
    void *d;
    int i;

    offset = elf_get_off(e, sh, SH_OFFSET);
    entsize = elf_get_size(e, sh, SH_ENTSIZE);
    size = elf_get_size(e, sh, SH_SIZE);
    fprintf(out, "\ndynamic:\n");
    for (i = 0; (u_int64_t)i < size / entsize; i++) {
        d = (char *)e + offset + i * entsize;
        tag = elf_get_size(e, d, D_TAG);
        ptr = elf_get_size(e, d, D_PTR);
        val = elf_get_addr(e, d, D_VAL);
        fprintf(out, "\n");
        fprintf(out, "entry: %d\n", i);
        fprintf(out, "\td_tag: %s\n", d_tags(tag));
        switch (tag) {
        case DT_NEEDED:
        case DT_SONAME:
        case DT_RPATH:
            fprintf(out, "\td_val: %s\n", dynstr + val);
            break;
        case DT_PLTRELSZ:
        case DT_RELA:
        case DT_RELASZ:
        case DT_RELAENT:
        case DT_STRSZ:
        case DT_SYMENT:
        case DT_RELSZ:
        case DT_RELENT:
        case DT_PLTREL:
            fprintf(out, "\td_val: %jd\n", (intmax_t)val);
            break;
        case DT_PLTGOT:
        case DT_HASH:
        case DT_STRTAB:
        case DT_SYMTAB:
        case DT_INIT:
        case DT_FINI:
        case DT_REL:
        case DT_JMPREL:
            fprintf(out, "\td_ptr: %#jx\n", ptr);
            break;
        case DT_NULL:
        case DT_SYMBOLIC:
        case DT_DEBUG:
        case DT_TEXTREL:
            break;
        }
    }
}
コード例 #3
0
ファイル: elfdump.c プロジェクト: coyizumi/cs111
static void
elf_print_ehdr(Elf32_Ehdr *e, void *sh)
{
    u_int64_t class;
    u_int64_t data;
    u_int64_t osabi;
    u_int64_t type;
    u_int64_t machine;
    u_int64_t version;
    u_int64_t entry;
    u_int64_t phoff;
    u_int64_t shoff;
    u_int64_t flags;
    u_int64_t ehsize;
    u_int64_t phentsize;
    u_int64_t phnum;
    u_int64_t shentsize;
    u_int64_t shnum;
    u_int64_t shstrndx;

    class = elf_get_byte(e, e, E_CLASS);
    data = elf_get_byte(e, e, E_DATA);
    osabi = elf_get_byte(e, e, E_OSABI);
    type = elf_get_quarter(e, e, E_TYPE);
    machine = elf_get_quarter(e, e, E_MACHINE);
    version = elf_get_word(e, e, E_VERSION);
    entry = elf_get_addr(e, e, E_ENTRY);
    phoff = elf_get_off(e, e, E_PHOFF);
    shoff = elf_get_off(e, e, E_SHOFF);
    flags = elf_get_word(e, e, E_FLAGS);
    ehsize = elf_get_quarter(e, e, E_EHSIZE);
    phentsize = elf_get_quarter(e, e, E_PHENTSIZE);
    phnum = elf_get_quarter(e, e, E_PHNUM);
    shentsize = elf_get_quarter(e, e, E_SHENTSIZE);
    fprintf(out, "\nelf header:\n");
    fprintf(out, "\n");
    fprintf(out, "\te_ident: %s %s %s\n", ei_classes[class], ei_data[data],
            ei_abis[osabi]);
    fprintf(out, "\te_type: %s\n", e_types[type]);
    fprintf(out, "\te_machine: %s\n", e_machines(machine));
    fprintf(out, "\te_version: %s\n", ei_versions[version]);
    fprintf(out, "\te_entry: %#jx\n", (intmax_t)entry);
    fprintf(out, "\te_phoff: %jd\n", (intmax_t)phoff);
    fprintf(out, "\te_shoff: %jd\n", (intmax_t)shoff);
    fprintf(out, "\te_flags: %jd\n", (intmax_t)flags);
    fprintf(out, "\te_ehsize: %jd\n", (intmax_t)ehsize);
    fprintf(out, "\te_phentsize: %jd\n", (intmax_t)phentsize);
    fprintf(out, "\te_phnum: %jd\n", (intmax_t)phnum);
    fprintf(out, "\te_shentsize: %jd\n", (intmax_t)shentsize);
    if (sh != NULL) {
        shnum = elf_get_shnum(e, sh);
        shstrndx = elf_get_shstrndx(e, sh);
        fprintf(out, "\te_shnum: %jd\n", (intmax_t)shnum);
        fprintf(out, "\te_shstrndx: %jd\n", (intmax_t)shstrndx);
    }
}
コード例 #4
0
ファイル: elfdump.c プロジェクト: coyizumi/cs111
static void
elf_print_shdr(Elf32_Ehdr *e, void *sh)
{
    u_int64_t shentsize;
    u_int64_t shnum;
    u_int64_t name;
    u_int64_t type;
    u_int64_t flags;
    u_int64_t addr;
    u_int64_t offset;
    u_int64_t size;
    u_int64_t shlink;
    u_int64_t info;
    u_int64_t addralign;
    u_int64_t entsize;
    u_int64_t machine;
    void *v;
    int i;

    if (sh == NULL) {
        fprintf(out, "\nNo section headers\n");
        return;
    }

    machine = elf_get_quarter(e, e, E_MACHINE);
    shentsize = elf_get_quarter(e, e, E_SHENTSIZE);
    shnum = elf_get_shnum(e, sh);
    fprintf(out, "\nsection header:\n");
    for (i = 0; (u_int64_t)i < shnum; i++) {
        v = (char *)sh + i * shentsize;
        name = elf_get_word(e, v, SH_NAME);
        type = elf_get_word(e, v, SH_TYPE);
        flags = elf_get_word(e, v, SH_FLAGS);
        addr = elf_get_addr(e, v, SH_ADDR);
        offset = elf_get_off(e, v, SH_OFFSET);
        size = elf_get_size(e, v, SH_SIZE);
        shlink = elf_get_word(e, v, SH_LINK);
        info = elf_get_word(e, v, SH_INFO);
        addralign = elf_get_size(e, v, SH_ADDRALIGN);
        entsize = elf_get_size(e, v, SH_ENTSIZE);
        fprintf(out, "\n");
        fprintf(out, "entry: %d\n", i);
        fprintf(out, "\tsh_name: %s\n", shstrtab + name);
        fprintf(out, "\tsh_type: %s\n", sh_types(machine, type));
        fprintf(out, "\tsh_flags: %s\n", sh_flags[flags & 0x7]);
        fprintf(out, "\tsh_addr: %#jx\n", addr);
        fprintf(out, "\tsh_offset: %jd\n", (intmax_t)offset);
        fprintf(out, "\tsh_size: %jd\n", (intmax_t)size);
        fprintf(out, "\tsh_link: %jd\n", (intmax_t)shlink);
        fprintf(out, "\tsh_info: %jd\n", (intmax_t)info);
        fprintf(out, "\tsh_addralign: %jd\n", (intmax_t)addralign);
        fprintf(out, "\tsh_entsize: %jd\n", (intmax_t)entsize);
    }
}
コード例 #5
0
ファイル: elfdump.c プロジェクト: coyizumi/cs111
static void
elf_print_phdr(Elf32_Ehdr *e, void *p)
{
    u_int64_t phentsize;
    u_int64_t phnum;
    u_int64_t type;
    u_int64_t offset;
    u_int64_t vaddr;
    u_int64_t paddr;
    u_int64_t filesz;
    u_int64_t memsz;
    u_int64_t flags;
    u_int64_t align;
    void *v;
    int i;

    phentsize = elf_get_quarter(e, e, E_PHENTSIZE);
    phnum = elf_get_quarter(e, e, E_PHNUM);
    fprintf(out, "\nprogram header:\n");
    for (i = 0; (u_int64_t)i < phnum; i++) {
        v = (char *)p + i * phentsize;
        type = elf_get_word(e, v, P_TYPE);
        offset = elf_get_off(e, v, P_OFFSET);
        vaddr = elf_get_addr(e, v, P_VADDR);
        paddr = elf_get_addr(e, v, P_PADDR);
        filesz = elf_get_size(e, v, P_FILESZ);
        memsz = elf_get_size(e, v, P_MEMSZ);
        flags = elf_get_word(e, v, P_FLAGS);
        align = elf_get_size(e, v, P_ALIGN);
        fprintf(out, "\n");
        fprintf(out, "entry: %d\n", i);
        fprintf(out, "\tp_type: %s\n", p_types[type & 0x7]);
        fprintf(out, "\tp_offset: %jd\n", (intmax_t)offset);
        fprintf(out, "\tp_vaddr: %#jx\n", (intmax_t)vaddr);
        fprintf(out, "\tp_paddr: %#jx\n", (intmax_t)paddr);
        fprintf(out, "\tp_filesz: %jd\n", (intmax_t)filesz);
        fprintf(out, "\tp_memsz: %jd\n", (intmax_t)memsz);
        fprintf(out, "\tp_flags: %s\n", p_flags[flags]);
        fprintf(out, "\tp_align: %jd\n", (intmax_t)align);
    }
}
コード例 #6
0
ファイル: elfdump.c プロジェクト: 2trill2spill/freebsd
static void
elf_print_symtab(Elf32_Ehdr *e, void *sh, char *str)
{
	u_int64_t machine;
	u_int64_t offset;
	u_int64_t entsize;
	u_int64_t size;
	u_int64_t name;
	u_int64_t value;
	u_int64_t info;
	u_int64_t shndx;
	void *st;
	int len;
	int i;

	machine = elf_get_quarter(e, e, E_MACHINE);
	offset = elf_get_off(e, sh, SH_OFFSET);
	entsize = elf_get_size(e, sh, SH_ENTSIZE);
	size = elf_get_size(e, sh, SH_SIZE);
	name = elf_get_word(e, sh, SH_NAME);
	len = size / entsize;
	fprintf(out, "\nsymbol table (%s):\n", shstrtab + name);
	for (i = 0; i < len; i++) {
		st = (char *)e + offset + i * entsize;
		name = elf_get_word(e, st, ST_NAME);
		value = elf_get_addr(e, st, ST_VALUE);
		size = elf_get_size(e, st, ST_SIZE);
		info = elf_get_byte(e, st, ST_INFO);
		shndx = elf_get_quarter(e, st, ST_SHNDX);
		fprintf(out, "\n");
		fprintf(out, "entry: %d\n", i);
		fprintf(out, "\tst_name: %s\n", str + name);
		fprintf(out, "\tst_value: %#jx\n", value);
		fprintf(out, "\tst_size: %jd\n", (intmax_t)size);
		fprintf(out, "\tst_info: %s %s\n",
		    st_type(machine, ELF32_ST_TYPE(info)),
		    st_bindings[ELF32_ST_BIND(info)]);
		fprintf(out, "\tst_shndx: %jd\n", (intmax_t)shndx);
	}
}
コード例 #7
0
ファイル: elfdump.c プロジェクト: coyizumi/cs111
static void
elf_print_got(Elf32_Ehdr *e, void *sh)
{
    u_int64_t offset;
    u_int64_t addralign;
    u_int64_t size;
    u_int64_t addr;
    void *v;
    int i;

    offset = elf_get_off(e, sh, SH_OFFSET);
    addralign = elf_get_size(e, sh, SH_ADDRALIGN);
    size = elf_get_size(e, sh, SH_SIZE);
    v = (char *)e + offset;
    fprintf(out, "\nglobal offset table:\n");
    for (i = 0; (u_int64_t)i < size / addralign; i++) {
        addr = elf_get_addr(e, (char *)v + i * addralign, 0);
        fprintf(out, "\n");
        fprintf(out, "entry: %d\n", i);
        fprintf(out, "\t%#jx\n", addr);
    }
}