From a24dc2755639577d46866eceb13eff871d5192f8 Mon Sep 17 00:00:00 2001 From: alvarofe Date: Tue, 9 May 2017 22:41:06 +0200 Subject: [PATCH] Move jni init function into entrypoints --- libr/bin/format/elf/elf.c | 6 ------ libr/bin/p/bin_elf.c | 24 ++++++++++++++++++++++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/libr/bin/format/elf/elf.c b/libr/bin/format/elf/elf.c index 6f47e29599..711a193b8f 100644 --- a/libr/bin/format/elf/elf.c +++ b/libr/bin/format/elf/elf.c @@ -1537,12 +1537,6 @@ static ut64 getmainsymbol(ELFOBJ *bin) { return UT64_MAX; } for (i = 0; !symbol[i].last; i++) { - if (!strncmp (symbol[i].name, "Java", 4)) { - if (r_str_endswith (symbol[i].name, "_init")) { - ut64 paddr = symbol[i].offset; - return Elf_(r_bin_elf_p2v) (bin, paddr); - } - } if (!strcmp (symbol[i].name, "main")) { ut64 paddr = symbol[i].offset; return Elf_(r_bin_elf_p2v) (bin, paddr); diff --git a/libr/bin/p/bin_elf.c b/libr/bin/p/bin_elf.c index 8516710187..a2c4305657 100644 --- a/libr/bin/p/bin_elf.c +++ b/libr/bin/p/bin_elf.c @@ -145,16 +145,17 @@ static RBinAddr* binsym(RBinFile *arch, int sym) { static RList* entries(RBinFile *arch) { struct Elf_(r_bin_elf_obj_t)* obj; RBinAddr *ptr = NULL; + struct r_bin_elf_symbol_t *symbol; RList *ret; + int i; if (!arch || !arch->o || !arch->o->bin_obj) { return NULL; } obj = arch->o->bin_obj; - if (!(ret = r_list_new ())) { + if (!(ret = r_list_newf ((RListFree)free))) { return NULL; } - ret->free = free; if (!(ptr = R_NEW0 (RBinAddr))) { return ret; } @@ -177,6 +178,25 @@ static RList* entries(RBinFile *arch) { } } r_list_append (ret, ptr); + //add entrypoint for jni libraries + if (!(symbol = Elf_(r_bin_elf_get_symbols) (obj))) { + return ret; + } + for (i = 0; !symbol[i].last; i++) { + if (!strncmp (symbol[i].name, "Java", 4)) { + if (r_str_endswith (symbol[i].name, "_init")) { + if (!(ptr = R_NEW0 (RBinAddr))) { + return ret; + } + ptr->paddr = symbol[i].offset; + ptr->vaddr = Elf_(r_bin_elf_p2v) (obj, ptr->paddr); + ptr->haddr = UT64_MAX; + ptr->type = R_BIN_ENTRY_TYPE_INIT; + r_list_append (ret, ptr); + break; + } + } + } return ret; }