Date: Thu, 13 Mar 2008 04:46:23 GMT From: Marcel Moolenaar <marcel@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 137578 for review Message-ID: <200803130446.m2D4kNLw082960@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=137578 Change 137578 by marcel@marcel_fbsdvm on 2008/03/13 04:45:21 Save... Affected files ... .. //depot/projects/bdb/usr.bin/bdb/Makefile#2 edit .. //depot/projects/bdb/usr.bin/bdb/bdb.c#2 edit .. //depot/projects/bdb/usr.bin/bdb/session.h#1 add Differences ... ==== //depot/projects/bdb/usr.bin/bdb/Makefile#2 (text+ko) ==== @@ -8,6 +8,6 @@ NO_MAN= -WARNS?= 6 +WARNS?= 3 .include <bsd.prog.mk> ==== //depot/projects/bdb/usr.bin/bdb/bdb.c#2 (text+ko) ==== @@ -4,8 +4,12 @@ #include <libelf.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <sysexits.h> +#include <unistd.h> +#include "session.h" + static void usage(void) { @@ -13,24 +17,51 @@ exit(EX_USAGE); } +static void +disasm(u_char *base, Elf64_Addr va, Elf64_Xword sz, Elf64_Addr ip) +{ +} + static int -workon(Elf *elf) +workon(struct session *sess) { GElf_Ehdr ehdr; + GElf_Phdr phdr; + char *data; + size_t datasz; + int c, ph; - if (gelf_getehdr(elf, &ehdr) == NULL) { - warnx(elf_errmsg(-1)); + if (gelf_getehdr(sess->elf, &ehdr) == NULL) { + warnx("%s: %s", sess->file, elf_errmsg(-1)); return (EX_NOINPUT); } + data = elf_rawfile(sess->elf, &datasz); + + for (ph = 0; ph < ehdr.e_phnum; ph++) { + if (gelf_getphdr(sess->elf, ph, &phdr) == NULL) { + warnx("%s: %s", sess->file, elf_errmsg(-1)); + continue; + } + if (phdr.p_type != PT_LOAD) + continue; + if (phdr.p_vaddr > ehdr.e_entry || + phdr.p_vaddr + phdr.p_filesz <= ehdr.e_entry) + continue; + + for (c = 0; c < 8; c++) + disasm(data + phdr.p_offset, phdr.p_vaddr, + phdr.p_filesz, ehdr.e_entry + (c << 4)); + } + return (EX_OK); } int main(int argc, char *argv[]) { - Elf *elf; - int errc, fd; + struct session sess; + int errcode; if (elf_version(EV_CURRENT) == EV_NONE) errx(EX_SOFTWARE, elf_errmsg(-1)); @@ -38,19 +69,21 @@ if (argc != 2) usage(); - fd = open(argv[1], O_RDONLY); - if (fd == -1) - err(EX_NOINPUT, "unable to open %s", argv[1]); + sess.file = strdup(argv[1]); + sess.fd = open(sess.file, O_RDONLY); + if (sess.fd == -1) + err(EX_NOINPUT, "%s: Unable to open", sess.file); - elf = elf_begin(fd, ELF_C_READ, NULL); - if (elf == NULL) { - close(fd); - errx(EX_NOINPUT, elf_errmsg(-1)); + sess.elf = elf_begin(sess.fd, ELF_C_READ, NULL); + if (sess.elf == NULL) { + close(sess.fd); + errx(EX_NOINPUT, "%s: %s", sess.file, elf_errmsg(-1)); } - errc = workon(elf); + errcode = workon(&sess); - elf_end(elf); - close(fd); - return (errc); + elf_end(sess.elf); + close(sess.fd); + free(sess.file); + return (errcode); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200803130446.m2D4kNLw082960>