-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Unicorn engine (#1054)
* feat: unicorn support * feat: update * fix: remove unused files * fix: clean * fix: remove undeeded parameters * fix: typo * moved to justfile * use log::debug! * fix cargo and created justfile * feat: add CI * add runs on * fix: CI * fix: CI * fix: don't use fork executor * not needed anymore * fix: CI * fix: CI * remove extra space
- Loading branch information
Showing
13 changed files
with
700 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "unicorn" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[features] | ||
# Enable a code hook which log the program counter at each executed instruction | ||
default = [] | ||
code_hook = [] | ||
mem_hook = [] | ||
|
||
[dependencies] | ||
libafl = { path = "../../../libafl/" } | ||
libafl_bolts = { path = "../../../libafl_bolts/" } | ||
libafl_targets = { path = "../../../libafl_targets" } | ||
libafl_unicorn = { path = "../../../libafl_unicorn/" } | ||
|
||
unicorn-engine = "2.1.2" | ||
log = "0.4.25" | ||
env_logger = "0.11.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
FUZZER_NAME := 'unicorn' | ||
PROJECT_DIR := absolute_path(".") | ||
PROFILE := 'release' | ||
PROFILE_DIR := 'release' | ||
CARGO_TARGET_DIR := env("CARGO_TARGET_DIR", "target") | ||
FUZZER := CARGO_TARGET_DIR / PROFILE_DIR / FUZZER_NAME | ||
|
||
|
||
alias build := fuzzer | ||
|
||
fuzzer: | ||
cargo build --profile={{PROFILE}} | ||
|
||
run: fuzzer | ||
RUST_LOG="debug" {{FUZZER}} arm | ||
|
||
build_bin: | ||
cd bin && just all | ||
|
||
|
||
[linux] | ||
[macos] | ||
test: fuzzer build_bin (test_single "arm") (test_single "arm64") (test_single "x86") | ||
echo "Done" | ||
|
||
test_single arch="arm": | ||
#!/bin/bash | ||
echo "Testing {{arch}}" | ||
|
||
RUST_LOG="debug" timeout 10s {{FUZZER}} {{arch}} 2>&1 | tee fuzz_stdout.log || true | ||
if grep -qa "objectives: 1" fuzz_stdout.log; then | ||
echo "Fuzzer is working" | ||
else | ||
echo "Fuzzer does not generate any testcases or any crashes" | ||
exit 1 | ||
fi | ||
|
||
[windows] | ||
test: fuzzer | ||
echo "Unsupported on this platform" | ||
|
||
clean: | ||
cargo clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
arm64 := "aarch64-linux-gnu" | ||
arm := "arm-linux-gnueabihf" | ||
x64 := "x86_64-linux-gnu" | ||
|
||
assembly_arm64: | ||
{{arm64}}-gcc -O2 -S -c foo.c -o foo_arm64.s | ||
|
||
binary_arm64: | ||
{{arm64}}-as foo_arm64.s -o foo_arm64.elf | ||
{{arm64}}-objcopy -O binary -j .text.startup foo_arm64.elf foo_arm64.bin | ||
|
||
assembly_arm: | ||
{{arm}}-gcc -O2 -S -c foo.c -o foo_arm.s | ||
|
||
binary_arm: | ||
{{arm}}-as foo_arm.s -o foo_arm.elf | ||
{{arm}}-objcopy -O binary foo_arm.elf foo_arm.bin | ||
|
||
assembly_x86: | ||
{{x64}}-gcc -O2 -S -c foo.c -o foo_x86.s | ||
|
||
binary_x86: | ||
{{x64}}-as foo_x86.s -o foo_x86.elf | ||
# Extract the .text.startup section | ||
{{x64}}-objcopy -O binary -j .text.startup foo_x86.elf foo_x86.bin | ||
|
||
build_arm: assembly_arm binary_arm | ||
build_arm64: assembly_arm64 binary_arm64 | ||
build_x86: assembly_x86 binary_x86 | ||
|
||
clean: | ||
rm foo_* | ||
|
||
|
||
all: build_arm build_arm64 build_x86 | ||
# sudo apt install gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
int main() { | ||
char *data = (char *)0x8000; | ||
// Extract the input from the memory at 0x8000 | ||
unsigned char a = data[0]; | ||
unsigned char b = data[1]; | ||
|
||
if (a > b) { | ||
if (a < 0x30) return 0x2; | ||
if (a > 0x80) return 0x3; | ||
if (a > 0x60) return 0x4; | ||
if (a != 0x50) return 0x5; | ||
|
||
if (b < 0x20) return 0x7; | ||
if (b > 0x60) return 0x8; | ||
if (b > 0x30) return 0x9; | ||
if (b == 0x24) return 0x6; // Success | ||
|
||
return 0x5; | ||
} | ||
|
||
return 0x1; | ||
} |
Oops, something went wrong.