aboutsummaryrefslogtreecommitdiff
path: root/frida_mode/addr
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-12-17 18:23:49 +0000
committerYour Name <you@example.com>2021-12-17 18:23:49 +0000
commita3421f80998ea7f78b5dc9a4047e6f2a5f79c4f4 (patch)
tree4cc0deb52997967880d368c7b466d3e603b7c1df /frida_mode/addr
parentfd1d1621497e252a7be7599371875d170034d71f (diff)
downloadafl++-a3421f80998ea7f78b5dc9a4047e6f2a5f79c4f4.tar.gz
Added addr for finding default base address
Diffstat (limited to 'frida_mode/addr')
-rw-r--r--frida_mode/addr/addr.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/frida_mode/addr/addr.c b/frida_mode/addr/addr.c
new file mode 100644
index 00000000..40ddc5ba
--- /dev/null
+++ b/frida_mode/addr/addr.c
@@ -0,0 +1,39 @@
+#include <errno.h>
+#include <link.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/personality.h>
+
+#define UNUSED_PARAMETER(x) (void)(x)
+
+int phdr_callback(struct dl_phdr_info *info, size_t size, void *data)
+{
+ UNUSED_PARAMETER (size);
+
+ ElfW(Addr) * base = data;
+
+ if (info->dlpi_name[0] == 0) { *base = info->dlpi_addr; }
+ return 0;
+}
+
+int main (int argc, char** argv, char** envp) {
+ UNUSED_PARAMETER (argc);
+
+ ElfW(Addr) base = 0;
+
+ int persona = personality(ADDR_NO_RANDOMIZE);
+ if (persona == -1) {
+
+ printf("Failed to set ADDR_NO_RANDOMIZE: %d", errno);
+ return 1;
+ }
+
+ if ((persona & ADDR_NO_RANDOMIZE) == 0) { execvpe(argv[0], argv, envp); }
+
+ dl_iterate_phdr(phdr_callback, &base);
+
+ printf("0x%016lx\n", base);
+ if (base == 0) { return 1; }
+
+ return 0;
+}