Skip to content

Commit

Permalink
feat(harness): use cmake and rpath
Browse files Browse the repository at this point in the history
  • Loading branch information
saruman9 committed May 24, 2023
1 parent d5d2eaa commit 646d2c1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ libafl_frida
harness
*.o
*.so
build

# External crates
frida-rust
Expand Down
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.8)
project(harness)

option(TRIAGE "Triaging" OFF)

link_directories(${CMAKE_SOURCE_DIR}/lib)

if(TRIAGE)
add_definitions(-DTRIAGE)
add_executable(harness "harness.c")
else(TRIAGE)
add_library(harness SHARED "harness.c")
endif(TRIAGE)

set_property(TARGET harness APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-rpath=$ORIGIN")
target_link_libraries(harness icuBinder linkparser c++_shared)
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,28 @@ Here you can find an example of a fuzzer implementation for the library `liblink
2. Make sure that the paths to cross-compiler are listed in the `PATH` environment variable.
3. `rustup target add x86_64-linux-android`
4. `cargo build --release --target=x86_64-linux-android`
5. Build the harness:
- `x86_64-linux-android-clang -O3 harness.c -shared -o harness.so` (for fuzzing)
- `x86_64-linux-android-clang -DTRIAGE -O0 harness.c -o harness` (for triaging and debugging)
6. Libraries: `adb push libc++_shared.so libicuBinder.so liblinkparser.so /data/local/tmp`
7. The fuzzer: `adb push ./target/x86_64-linux-android/release/frida_fuzzer harness.so /data/local/tmp`
8. The corpus: `adb push ./corpus /data/local/tmp`
5. Copy the shared dependency libraries to the `lib` directory.
6. Build the harness:
- For fuzzing:
```console
cmake -B build -S . -DANDROID_PLATFORM=${YOUR_ANDROID_PLATFORM_NUMBER_HERE} \
-DCMAKE_TOOLCHAIN_FILE=${SPECIFIC_ANDROID_NDK_TOOLCHAIN_PATH_HERE}/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=x86_64
cmake --build build
```

- For triaging and debugging:
```console
cmake -B build -S . -DTRIAGE -DANDROID_PLATFORM=${YOUR_ANDROID_PLATFORM_NUMBER_HERE} \
-DCMAKE_TOOLCHAIN_FILE=${SPECIFIC_ANDROID_NDK_TOOLCHAIN_PATH_HERE}/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=x86_64
cmake --build build
```
7. Copy everything to the device or to the emulator:

```shell
adb push ./corpus ./lib/* ./build/*harness* ./target/x86_64-linux-android/release/frida_fuzzer /data/local/tmp
```

## Using

Expand Down
Empty file added lib/.keep
Empty file.

0 comments on commit 646d2c1

Please sign in to comment.