From fcbc501717910e6468f1e4a20703663f17d2c1c0 Mon Sep 17 00:00:00 2001 From: elfmaster Date: Mon, 14 Mar 2022 00:31:21 -0700 Subject: [PATCH] added elf_interpreteR_path --- build/libelfmaster.pc | 7 ++++--- examples/Makefile | 1 + include/libelfmaster.h | 1 + src/libelfmaster.c | 17 +++++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/build/libelfmaster.pc b/build/libelfmaster.pc index 53489e8..a996dce 100755 --- a/build/libelfmaster.pc +++ b/build/libelfmaster.pc @@ -2,9 +2,10 @@ prefix=/opt/elfmaster includedir=/opt/elfmaster/include libdir=/opt/elfmaster/lib -Name: Backtrace I/O pdb parsing library -Description: Library for the loading and parsing of pdb files -URL: http://backtrace.io/ +Name: Advanced ELF binary parsing API +Description: Library for the loading, parsing, modifying and +forensic reconstruction of ELF binaries. +URL: https://github.com/elfmaster/libelfmaster Version: 0.1.0 Cflags: -D__x86_64__ -I${includedir} -D_GNU_SOURCE diff --git a/examples/Makefile b/examples/Makefile index 875354b..8f412cd 100755 --- a/examples/Makefile +++ b/examples/Makefile @@ -33,6 +33,7 @@ all: $(CC) -Wl,-z,separate-code test.c -o test_scop_pie $(CC) -no-pie -Wl,-z,separate-code test.c -o test_scop_binary $(CC) -O2 -g pltgot.c -o pltgot ../src/libelfmaster.a + $(CC) phoff.c -o phoff ../src/libelfmaster.a ./stripx test_stripped ./stripx test32_stripped clean: diff --git a/include/libelfmaster.h b/include/libelfmaster.h index 3d38146..2da1dc0 100644 --- a/include/libelfmaster.h +++ b/include/libelfmaster.h @@ -990,4 +990,5 @@ bool elf_section_commit(elfobj_t *); bool elf_lxc_set_rootfs(elfobj_t *, const char *); bool elf_lxc_get_rootfs(elfobj_t *, char *, const size_t); +char * elf_interpreter_path(elfobj_t *); #endif diff --git a/src/libelfmaster.c b/src/libelfmaster.c index bf0cf91..7a75687 100644 --- a/src/libelfmaster.c +++ b/src/libelfmaster.c @@ -3235,6 +3235,23 @@ elf_open_object(const char *path, struct elfobj *obj, uint64_t load_flags, return false; } +char * +elf_interpreter_path(elfobj_t *obj) +{ + struct elf_segment segment; + elf_segment_iterator_t p_iter; + char *path; + + elf_segment_iterator_init(obj, &p_iter); + while (elf_segment_iterator_next(&p_iter, &segment) == ELF_ITER_OK) { + if (segment.type == PT_INTERP) { + path = elf_offset_pointer(obj, segment.offset); + return path; + } + } + return NULL; +} + void elf_close_object(elfobj_t *obj) {