frida mode android build fix proposal.
also protecting seccomp the other way around in case it is ported
in another platform supported by frida.
MODIFY
frida_mode/GNUmakefile
frida_mode/GNUmakefile
@@ -80,6 +80,22 @@ ifeq "$(shell uname)" "Linux"
OS:=linux
endif
+ifneq "$(findstring android, $(shell $(CC) --version 2>/dev/null))" ""
+ OS:=android
+ ifneq "$(findstring aarch64, $(shell $(CC) --version 2>/dev/null))" ""
+ ARCH:=arm64
+ endif
+ ifneq "$(findstring arm, $(shell $(CC) --version 2>/dev/null))" ""
+ ARCH:=arm
+ endif
+ ifneq "$(findstring x86_64, $(shell $(CC) --version 2>/dev/null))" ""
+ ARCH:=x86_64
+ endif
+ ifneq "$(findstring i686, $(shell $(CC) --version 2>/dev/null))" ""
+ ARCH:=x86
+ endif
+endif
+
ifndef OS
$(error "Operating system unsupported")
endif

MODIFY
frida_mode/README.md
frida_mode/README.md
@@ -55,6 +55,20 @@ tests in 32-bit mode, run `make ARCH=x86 frida`. When switching between
architectures it may be necessary to run `make clean` first for a given build
target to remove previously generated binaries for a different architecture.
+### Android
+
+In order to build, you need to download the Android SDK.
+
+```
+https://developer.android.com/ndk/downloads
+```
+
+Then creating locally a standalone chain as follow.
+
+```
+https://developer.android.com/ndk/guides/standalone_toolchain
+```
+
## Usage
FRIDA mode added some small modifications to `afl-fuzz` and similar tools

MODIFY
frida_mode/src/instrument/instrument_x64.c
frida_mode/src/instrument/instrument_x64.c
#include <sys/shm.h>
#if defined(__linux__)
+#if !defined(__ANDROID__)
#include <asm/prctl.h>
#include <sys/syscall.h>
+#else
+#include <linux/ashmem.h>
+#endif
#endif
#include "frida-gumjs.h"
@@ -156,8 +160,16 @@ static void instrument_coverage_optimize_map_mmap(char * shm_file_path,
__afl_area_ptr = NULL;
+#if !defined(__ANDROID__)
shm_fd = shm_open(shm_file_path, O_RDWR, DEFAULT_PERMISSION);
if (shm_fd == -1) { FATAL("shm_open() failed\n"); }
+#else
+ shm_fd = open("/dev/ashmem", O_RDWR);
+ if (shm_fd == -1) { FATAL("open() failed\n"); }
+ if (ioctl(shm_fd, ASHMEM_SET_NAME, shm_file_path) == -1) { FATAL("ioctl(ASHMEM_SET_NAME) failed"); }
+ if (ioctl(shm_fd, ASHMEM_SET_SIZE, __afl_map_size) == -1) { FATAL("ioctl(ASHMEM_SET_SIZE) failed"); }
+
+#endif
__afl_area_ptr = mmap(address, __afl_map_size, PROT_READ | PROT_WRITE,
MAP_FIXED_NOREPLACE | MAP_SHARED, shm_fd, 0);

MODIFY
frida_mode/src/seccomp/seccomp_atomic.c
frida_mode/src/seccomp/seccomp_atomic.c
-#ifndef __APPLE__
+#if defined(__linux__) && !defined(__ANDROID__)
#include <stdbool.h>
#include <stdio.h>

MODIFY
frida_mode/src/seccomp/seccomp_callback.c
frida_mode/src/seccomp/seccomp_callback.c
-#ifndef __APPLE__
+#if defined(__linux__) && !defined(__ANDROID__)
#include <execinfo.h>
#include <fcntl.h>

MODIFY
frida_mode/src/seccomp/seccomp_child.c
frida_mode/src/seccomp/seccomp_child.c
-#ifndef __APPLE__
+#if defined(__linux__) && !defined(__ANDROID__)
#include <fcntl.h>
#include <sched.h>

MODIFY
frida_mode/src/seccomp/seccomp_event.c
frida_mode/src/seccomp/seccomp_event.c
-#ifndef __APPLE__
+#if defined(__linux__) && !defined(__ANDROID__)
#include <stdint.h>
#include <stdio.h>

MODIFY
frida_mode/src/seccomp/seccomp_filter.c
frida_mode/src/seccomp/seccomp_filter.c
-#ifndef __APPLE__
+#if defined(__linux__) && !defined(__ANDROID__)
#include <alloca.h>
#include <errno.h>

MODIFY
frida_mode/src/seccomp/seccomp_print.c
frida_mode/src/seccomp/seccomp_print.c
-#ifndef __APPLE__
+#if defined(__linux__) && !defined(__ANDROID__)
#include <stdarg.h>

MODIFY
frida_mode/src/seccomp/seccomp_socket.c
frida_mode/src/seccomp/seccomp_socket.c
-#ifndef __APPLE__
+#if defined(__linux__) && !defined(__ANDROID__)
#include <stdio.h>
#include <string.h>

MODIFY
frida_mode/src/seccomp/seccomp_syscall.c
frida_mode/src/seccomp/seccomp_syscall.c
-#ifndef __APPLE__
+#if defined(__linux__) && !defined(__ANDROID__)
#include <limits.h>
#include <stdio.h>

frida mode android build fix proposal.

also protecting seccomp the other way around in case it is ported
 in another platform supported by frida.