From ac169c30874251e3dcd74f9ce4b43a7d26435cdd Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Sat, 22 Jan 2022 17:22:00 +0100 Subject: fix makefiles for uc2 c examples --- unicorn_mode/samples/c/Makefile | 39 ++++++++++++++++++++++----------------- unicorn_mode/samples/c/harness.c | 5 +++-- 2 files changed, 25 insertions(+), 19 deletions(-) (limited to 'unicorn_mode/samples/c') diff --git a/unicorn_mode/samples/c/Makefile b/unicorn_mode/samples/c/Makefile index cb491e10..fd6dbe77 100644 --- a/unicorn_mode/samples/c/Makefile +++ b/unicorn_mode/samples/c/Makefile @@ -4,29 +4,28 @@ .POSIX: UNAME_S =$(shell uname -s)# GNU make UNAME_S:sh=uname -s # BSD make -_UNIQ=_QINU_ -LIBDIR = ../../unicornafl +UNICORNAFL_LIB = ../../unicornafl/build +UNICORN_LIB = ../../unicornafl/unicorn/build BIN_EXT = AR_EXT = a # Verbose output? V ?= 0 -CFLAGS += -Wall -Werror -I../../unicornafl/include +CFLAGS += -Wall -Werror -I../../unicornafl/unicorn/include -I../../unicornafl/include -LDFLAGS += -L$(LIBDIR) -lpthread -lm +LDFLAGS += -L$(UNICORNAFL_LIB) -L$(UNICORN_LIB) -lpthread -lm -lunicornafl -lunicorn -lc++ -_LRT = $(_UNIQ)$(UNAME_S:Linux=) -__LRT = $(_LRT:$(_UNIQ)=-lrt) -LRT = $(__LRT:$(_UNIQ)=) +ifeq ($(UNAME), Linux) +# do something Linux-y +LRT = -lrt +else +LRT = +endif LDFLAGS += $(LRT) -_CC = $(_UNIQ)$(CROSS) -__CC = $(_CC:$(_UNIQ)=$(CC)) -MYCC = $(__CC:$(_UNIQ)$(CROSS)=$(CROSS)gcc) - .PHONY: all clean all: harness @@ -34,14 +33,20 @@ all: harness clean: rm -rf *.o harness harness-debug -harness.o: harness.c ../../unicornafl/include/unicorn/*.h - ${MYCC} ${CFLAGS} -O3 -c harness.c +harness.o: harness.c ../../unicornafl/unicorn/include/unicorn/*.h + ${CC} ${CFLAGS} -O3 -c harness.c + +harness-debug.o: harness.c ../../unicornafl/unicorn/include/unicorn/*.h + ${CC} ${CFLAGS} -g -c harness.c -o $@ -harness-debug.o: harness.c ../../unicornafl/include/unicorn/*.h - ${MYCC} ${CFLAGS} -g -c harness.c -o $@ +../../unicornafl/build/libunicornafl.a: + cd ../.. && ./build_unicorn_support.sh harness: harness.o - ${MYCC} -L${LIBDIR} harness.o ../../unicornafl/libunicornafl.a $(LDFLAGS) -o $@ + ${CC} harness.o ../../unicornafl/build/libunicornafl.a $(LDFLAGS) -o $@ debug: harness-debug.o - ${MYCC} -L${LIBDIR} harness.o ../../unicornafl/libunicornafl.a $(LDFLAGS) -o harness-debug + ${CC} harness.o ../../unicornafl/build/libunicornafl.a $(LDFLAGS) -o harness-debug + +fuzz: harness + DYLD_FALLBACK_LIBRARY_PATH="../../unicornafl/unicorn/build" LD_LIBRARY_PATH="../../unicornafl/unicorn/build" ../../../afl-fuzz -m none -i sample_inputs -o out -- ./harness @@ diff --git a/unicorn_mode/samples/c/harness.c b/unicorn_mode/samples/c/harness.c index 4bda6e2d..3a93aeaa 100644 --- a/unicorn_mode/samples/c/harness.c +++ b/unicorn_mode/samples/c/harness.c @@ -26,6 +26,7 @@ #include #include +#include // Path to the file containing the binary to emulate #define BINARY_FILE ("persistent_target_x86_64") @@ -141,7 +142,7 @@ static void mem_map_checked(uc_engine *uc, uint64_t addr, size_t size, uint32_t //printf("SIZE %llx, align: %llx\n", size, ALIGNMENT); uc_err err = uc_mem_map(uc, addr, size, mode); if (err != UC_ERR_OK) { - printf("Error mapping %ld bytes at 0x%lx: %s (mode: %d)\n", size, addr, uc_strerror(err), mode); + printf("Error mapping %ld bytes at 0x%llx: %s (mode: %d)\n", size, (unsigned long long) addr, uc_strerror(err), (int) mode); exit(1); } } @@ -184,7 +185,7 @@ int main(int argc, char **argv, char **envp) { // Map memory. mem_map_checked(uc, BASE_ADDRESS, len, UC_PROT_ALL); - printf("Len: %lx\n", len); + printf("Len: %lx\n", (unsigned long) len); fflush(stdout); // write machine code to be emulated to memory -- cgit 1.4.1 From 87f2789e98b2194dc3049a048d50e9c7cac6d82c Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Tue, 25 Jan 2022 18:05:35 +0100 Subject: fix unicorn python test path --- unicorn_mode/build_unicorn_support.sh | 2 +- unicorn_mode/samples/c/harness.c | 2 +- unicorn_mode/samples/compcov_x64/compcov_test_harness.py | 2 +- unicorn_mode/samples/python_simple/simple_test_harness.py | 2 +- unicorn_mode/samples/python_simple/simple_test_harness_alt.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'unicorn_mode/samples/c') diff --git a/unicorn_mode/build_unicorn_support.sh b/unicorn_mode/build_unicorn_support.sh index 842ad020..74f9e174 100755 --- a/unicorn_mode/build_unicorn_support.sh +++ b/unicorn_mode/build_unicorn_support.sh @@ -212,7 +212,7 @@ echo "[*] Unicornafl bindings installed successfully." # Compile the sample, run it, verify that it works! echo "[*] Testing unicornafl python functionality by running a sample test harness" -cd ../samples/simple || echo "Cannot cd" +cd ../samples/python_simple || echo "Cannot cd" # Run afl-showmap on the sample application. If anything comes out then it must have worked! unset AFL_INST_RATIO diff --git a/unicorn_mode/samples/c/harness.c b/unicorn_mode/samples/c/harness.c index 3a93aeaa..30972ce7 100644 --- a/unicorn_mode/samples/c/harness.c +++ b/unicorn_mode/samples/c/harness.c @@ -8,7 +8,7 @@ Run under AFL as follows: - $ cd /unicorn_mode/samples/simple/ + $ cd /unicorn_mode/samples/c $ make $ ../../../afl-fuzz -m none -i sample_inputs -o out -- ./harness @@ */ diff --git a/unicorn_mode/samples/compcov_x64/compcov_test_harness.py b/unicorn_mode/samples/compcov_x64/compcov_test_harness.py index f0749d1b..52f0a286 100644 --- a/unicorn_mode/samples/compcov_x64/compcov_test_harness.py +++ b/unicorn_mode/samples/compcov_x64/compcov_test_harness.py @@ -10,7 +10,7 @@ Run under AFL as follows: - $ cd /unicorn_mode/samples/simple/ + $ cd /unicorn_mode/samples/python_simple $ AFL_COMPCOV_LEVEL=2 ../../../afl-fuzz -U -m none -i ./sample_inputs -o ./output -- python compcov_test_harness.py @@ """ diff --git a/unicorn_mode/samples/python_simple/simple_test_harness.py b/unicorn_mode/samples/python_simple/simple_test_harness.py index cd04ad3a..8c5239b6 100644 --- a/unicorn_mode/samples/python_simple/simple_test_harness.py +++ b/unicorn_mode/samples/python_simple/simple_test_harness.py @@ -10,7 +10,7 @@ Run under AFL as follows: - $ cd /unicorn_mode/samples/simple/ + $ cd /unicorn_mode/samples/python_simple $ ../../../afl-fuzz -U -m none -i ./sample_inputs -o ./output -- python simple_test_harness.py @@ """ diff --git a/unicorn_mode/samples/python_simple/simple_test_harness_alt.py b/unicorn_mode/samples/python_simple/simple_test_harness_alt.py index 3249b13d..5fb3f82f 100644 --- a/unicorn_mode/samples/python_simple/simple_test_harness_alt.py +++ b/unicorn_mode/samples/python_simple/simple_test_harness_alt.py @@ -13,7 +13,7 @@ Run under AFL as follows: - $ cd /unicorn_mode/samples/simple/ + $ cd /unicorn_mode/samples/python_simple $ ../../../afl-fuzz -U -m none -i ./sample_inputs -o ./output -- python simple_test_harness_alt.py @@ """ -- cgit 1.4.1