Minor integration tweaks
MODIFY
frida_mode/GNUmakefile
frida_mode/GNUmakefile
@@ -25,6 +25,7 @@ LDFLAGS+=-shared \
-lpthread \
-lresolv \
-ldl \
+ -z noexecstack \
ifdef DEBUG
CFLAGS+=-Werror \

MODIFY
frida_mode/src/main.c
frida_mode/src/main.c
@@ -75,16 +75,22 @@ static void on_main_os(int argc, char **argv, char **envp) {
#endif
-static int *on_main(int argc, char **argv, char **envp) {
+static void embedded_init() {
- void *fork_addr;
+ static gboolean initialized = false;
+ if (!initialized) {
- on_main_os(argc, argv, envp);
+ gum_init_embedded();
+ initialized = true;
- unintercept_self();
+ }
- stalker_init();
+}
+
+void afl_frida_start() {
+ embedded_init();
+ stalker_init();
lib_init();
entry_init();
instrument_init();
@@ -92,12 +98,23 @@ static int *on_main(int argc, char **argv, char **envp) {
prefetch_init();
ranges_init();
- fork_addr = GSIZE_TO_POINTER(gum_module_find_export_by_name(NULL, "fork"));
+ void *fork_addr =
+ GSIZE_TO_POINTER(gum_module_find_export_by_name(NULL, "fork"));
intercept(fork_addr, on_fork, NULL);
stalker_start();
entry_run();
+}
+
+static int *on_main(int argc, char **argv, char **envp) {
+
+ on_main_os(argc, argv, envp);
+
+ unintercept_self();
+
+ afl_frida_start();
+
return main_fn(argc, argv, envp);
}
@@ -149,13 +166,7 @@ static void intercept_main(void) {
__attribute__((constructor)) static void init(void) {
- gum_init_embedded();
- if (!gum_stalker_is_supported()) {
-
- gum_deinit_embedded();
- FATAL("Failed to initialize embedded");
-
- }
+ embedded_init();
intercept_main();

MODIFY
frida_mode/src/stalker.c
frida_mode/src/stalker.c
@@ -7,6 +7,8 @@ static GumStalker *stalker = NULL;
void stalker_init(void) {
+ if (!gum_stalker_is_supported()) { FATAL("Failed to initialize embedded"); }
+
stalker = gum_stalker_new();
if (stalker == NULL) { FATAL("Failed to initialize stalker"); }

Minor integration tweaks (#926)

Co-authored-by: Your Name <you@example.com>