aboutsummaryrefslogtreecommitdiff
path: root/frida_mode/src/lib/lib.c
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2021-12-09 11:55:36 +0100
committerGitHub <noreply@github.com>2021-12-09 11:55:36 +0100
commit08ca4d54a55fe73e64a994c41a12af61f52e497e (patch)
tree2d0f060cf98afbe80f5bf810fd6b167a5152be81 /frida_mode/src/lib/lib.c
parent773baf9391ff5f1793deb7968366819e7fa07adc (diff)
parent4c6d94ea5f854071277ed9729de2d4ef7d07cc84 (diff)
downloadafl++-08ca4d54a55fe73e64a994c41a12af61f52e497e.tar.gz
Merge pull request #1101 from AFLplusplus/dev
Dev
Diffstat (limited to 'frida_mode/src/lib/lib.c')
-rw-r--r--frida_mode/src/lib/lib.c55
1 files changed, 29 insertions, 26 deletions
diff --git a/frida_mode/src/lib/lib.c b/frida_mode/src/lib/lib.c
index 59a3fcf9..48d2ea2a 100644
--- a/frida_mode/src/lib/lib.c
+++ b/frida_mode/src/lib/lib.c
@@ -8,9 +8,8 @@
#include "frida-gumjs.h"
- #include "debug.h"
-
#include "lib.h"
+ #include "util.h"
#if defined(__arm__) || defined(__i386__)
#define ELFCLASS ELFCLASS32
@@ -55,11 +54,11 @@ static gboolean lib_find_exe(const GumModuleDetails *details,
static void lib_validate_hdr(Elf_Ehdr *hdr) {
- if (hdr->e_ident[0] != ELFMAG0) FATAL("Invalid e_ident[0]");
- if (hdr->e_ident[1] != ELFMAG1) FATAL("Invalid e_ident[1]");
- if (hdr->e_ident[2] != ELFMAG2) FATAL("Invalid e_ident[2]");
- if (hdr->e_ident[3] != ELFMAG3) FATAL("Invalid e_ident[3]");
- if (hdr->e_ident[4] != ELFCLASS) FATAL("Invalid class");
+ if (hdr->e_ident[0] != ELFMAG0) FFATAL("Invalid e_ident[0]");
+ if (hdr->e_ident[1] != ELFMAG1) FFATAL("Invalid e_ident[1]");
+ if (hdr->e_ident[2] != ELFMAG2) FFATAL("Invalid e_ident[2]");
+ if (hdr->e_ident[3] != ELFMAG3) FFATAL("Invalid e_ident[3]");
+ if (hdr->e_ident[4] != ELFCLASS) FFATAL("Invalid class");
}
@@ -88,18 +87,22 @@ static void lib_read_text_section(lib_details_t *lib_details, Elf_Ehdr *hdr) {
}
- if (!found_preferred_base) { FATAL("Failed to find preferred load address"); }
+ if (!found_preferred_base) {
+
+ FFATAL("Failed to find preferred load address");
+
+ }
- OKF("Image preferred load address 0x%016" G_GSIZE_MODIFIER "x",
- preferred_base);
+ FOKF("Image preferred load address 0x%016" G_GSIZE_MODIFIER "x",
+ preferred_base);
shdr = (Elf_Shdr *)((char *)hdr + hdr->e_shoff);
shstrtab = &shdr[hdr->e_shstrndx];
shstr = (char *)hdr + shstrtab->sh_offset;
- OKF("shdr: %p", shdr);
- OKF("shstrtab: %p", shstrtab);
- OKF("shstr: %p", shstr);
+ FOKF("shdr: %p", shdr);
+ FOKF("shstrtab: %p", shstrtab);
+ FOKF("shstr: %p", shstr);
for (size_t i = 0; i < hdr->e_shnum; i++) {
@@ -108,16 +111,16 @@ static void lib_read_text_section(lib_details_t *lib_details, Elf_Ehdr *hdr) {
if (curr->sh_name == 0) continue;
section_name = &shstr[curr->sh_name];
- OKF("Section: %2" G_GSIZE_MODIFIER "u - base: 0x%016" G_GSIZE_MODIFIER
- "X size: 0x%016" G_GSIZE_MODIFIER "X %s",
- i, curr->sh_addr, curr->sh_size, section_name);
+ FOKF("Section: %2" G_GSIZE_MODIFIER "u - base: 0x%016" G_GSIZE_MODIFIER
+ "X size: 0x%016" G_GSIZE_MODIFIER "X %s",
+ i, curr->sh_addr, curr->sh_size, section_name);
if (memcmp(section_name, text_name, sizeof(text_name)) == 0 &&
text_base == 0) {
text_base = lib_details->base_address + curr->sh_addr - preferred_base;
text_limit = text_base + curr->sh_size;
- OKF("> text_addr: 0x%016" G_GINT64_MODIFIER "X", text_base);
- OKF("> text_limit: 0x%016" G_GINT64_MODIFIER "X", text_limit);
+ FOKF("> text_addr: 0x%016" G_GINT64_MODIFIER "X", text_base);
+ FOKF("> text_limit: 0x%016" G_GINT64_MODIFIER "X", text_limit);
}
@@ -132,16 +135,16 @@ static void lib_get_text_section(lib_details_t *details) {
Elf_Ehdr *hdr;
fd = open(details->path, O_RDONLY);
- if (fd < 0) { FATAL("Failed to open %s", details->path); }
+ if (fd < 0) { FFATAL("Failed to open %s", details->path); }
len = lseek(fd, 0, SEEK_END);
- if (len == (off_t)-1) { FATAL("Failed to lseek %s", details->path); }
+ if (len == (off_t)-1) { FFATAL("Failed to lseek %s", details->path); }
- OKF("len: %ld", len);
+ FOKF("len: %ld", len);
hdr = (Elf_Ehdr *)mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
- if (hdr == MAP_FAILED) { FATAL("Failed to map %s", details->path); }
+ if (hdr == MAP_FAILED) { FFATAL("Failed to map %s", details->path); }
lib_validate_hdr(hdr);
lib_read_text_section(details, hdr);
@@ -159,22 +162,22 @@ void lib_init(void) {
lib_details_t lib_details;
gum_process_enumerate_modules(lib_find_exe, &lib_details);
- OKF("Executable: 0x%016" G_GINT64_MODIFIER "x - %s", lib_details.base_address,
- lib_details.path);
+ FOKF("Executable: 0x%016" G_GINT64_MODIFIER "x - %s",
+ lib_details.base_address, lib_details.path);
lib_get_text_section(&lib_details);
}
guint64 lib_get_text_base(void) {
- if (text_base == 0) FATAL("Lib not initialized");
+ if (text_base == 0) FFATAL("Lib not initialized");
return text_base;
}
guint64 lib_get_text_limit(void) {
- if (text_limit == 0) FATAL("Lib not initialized");
+ if (text_limit == 0) FFATAL("Lib not initialized");
return text_limit;
}