Merge pull request #1118 from devnexen/frida_android_build_upd

frida mode android build fix proposal.
This commit is contained in:
van Hauser 2021-10-16 18:43:30 +02:00 committed by GitHub
commit 88bcc34802
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 50 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -4,8 +4,12 @@
#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);

View File

@ -1,4 +1,4 @@
#ifndef __APPLE__
#if defined(__linux__) && !defined(__ANDROID__)
#include <stdbool.h>
#include <stdio.h>

View File

@ -1,4 +1,4 @@
#ifndef __APPLE__
#if defined(__linux__) && !defined(__ANDROID__)
#include <execinfo.h>
#include <fcntl.h>

View File

@ -1,4 +1,4 @@
#ifndef __APPLE__
#if defined(__linux__) && !defined(__ANDROID__)
#include <fcntl.h>
#include <sched.h>

View File

@ -1,4 +1,4 @@
#ifndef __APPLE__
#if defined(__linux__) && !defined(__ANDROID__)
#include <stdint.h>
#include <stdio.h>

View File

@ -1,4 +1,4 @@
#ifndef __APPLE__
#if defined(__linux__) && !defined(__ANDROID__)
#include <alloca.h>
#include <errno.h>

View File

@ -1,4 +1,4 @@
#ifndef __APPLE__
#if defined(__linux__) && !defined(__ANDROID__)
#include <stdarg.h>

View File

@ -1,4 +1,4 @@
#ifndef __APPLE__
#if defined(__linux__) && !defined(__ANDROID__)
#include <stdio.h>
#include <string.h>

View File

@ -1,4 +1,4 @@
#ifndef __APPLE__
#if defined(__linux__) && !defined(__ANDROID__)
#include <limits.h>
#include <stdio.h>