From 7867e610b5cffd2c0749703eca1333bdd7840824 Mon Sep 17 00:00:00 2001 From: van Hauser Date: Thu, 1 Mar 2018 13:20:26 +0100 Subject: added -S switch, make install, updated README --- CHANGES | 5 ++++- Makefile | 9 +++++++++ README.txt | 25 ++++++++++++++++++++----- afl-dyninst.cpp | 14 ++++++++++++-- libAflDyninst.cpp | 2 +- 5 files changed, 46 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index 550a845..8bba0a3 100644 --- a/CHANGES +++ b/CHANGES @@ -1,7 +1,10 @@ Changelog ========= -vh@thc.org / https://github.com/vanhauser-thc/afl-dyninst: +https://github.com/vanhauser-thc/afl-dyninst + - added -S switch to skip instrumenting a specific function + - added make install target + - updated README - Fix for programs that were unable to print to stdout after instrumentation - added -f switch to fix a bug in dyninst where sometimes the edi/rdi register is not saved which is used in the instrumentation function diff --git a/Makefile b/Makefile index 9685c96..25ef545 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,9 @@ AFL_ROOT = ./afl # path to libelf and libdwarf DEPS_ROOT = /usr/local +# where to install +INSTALL_ROOT = /usr/local + CXX = g++ CXXFLAGS = -g -Wall -O3 -std=c++11 LIBFLAGS = -fpic -shared @@ -33,3 +36,9 @@ afl-dyninst.o: afl-dyninst.cpp clean: rm -f afl-dyninst *.so *.o + +install: all + install -d $(INSTALL_ROOT)/bin + install -d $(INSTALL_ROOT)/lib + install afl-dyninst $(INSTALL_ROOT)/bin + install libAflDyninst.so $(INSTALL_ROOT)/lib diff --git a/README.txt b/README.txt index adecc8b..b8a4b07 100644 --- a/README.txt +++ b/README.txt @@ -8,6 +8,10 @@ Instrumentation tool (afl-dyninst) instruments the supplied binary by inserting callbacks for each basic block and an initialization callback either at _init or at specified entry point. + +Commandline options +------------------- + Usage: ./afl-dyninst -i -o -l -e
-s -i: Input binary -o: Output binary @@ -17,6 +21,7 @@ Usage: ./afl-dyninst -i -o -l -e
-s runtimeLibraries; int bbSkip = 0, dynfix = 0; unsigned int bbMinSize = 1; bool skipMainModule = false; +char *skipFunc = NULL; BPatch_function *save_rdi; BPatch_function *restore_rdi; const char *instLibrary = "libAflDyninst.so"; -static const char *OPT_STR = "fi:o:l:e:vs:dr:m:"; +static const char *OPT_STR = "fi:o:l:e:vs:dr:m:S:"; static const char *USAGE = " -i -o -l -e
-s -m \n \ -i: Input binary \n \ -o: Output binary\n \ @@ -47,6 +48,7 @@ static const char *USAGE = " -i -o -l -e
- -s: Number of basic blocks to skip\n \ -m: minimum size of a basic bock to instrument (default: 1)\n \ -f: try to fix crashes\n \ + -S: do not instrument this function (can be specified only once)\n \ -v: Verbose output\n"; bool parseOptions(int argc, char **argv) { @@ -54,6 +56,9 @@ bool parseOptions(int argc, char **argv) { while ((c = getopt(argc, argv, OPT_STR)) != -1) { switch ((char) c) { + case 'S': + skipFunc = optarg; + break; case 'e': entryPoint = strtoul(optarg, NULL, 16);; break; @@ -181,7 +186,7 @@ bool insertBBCallback(BPatch_binaryEdit *appBin, BPatch_function *curFunc, char randID = rand() % USHRT_MAX; if (verbose) { - cout << "Instrumenting Basic Block 0x" << hex << address << " of " << funcName << " of size " << dec << (*iter)->size() << " with random id " << randID << endl; + cout << "Instrumenting Basic Block 0x" << hex << address << " of " << funcName << " with size " << dec << (*iter)->size() << " with random id " << randID << "/0x" << hex << randID << endl; } BPatch_Vector < BPatch_snippet * >instArgs1; @@ -322,6 +327,11 @@ int main(int argc, char **argv) { curFunc->getName(funcName, 1024); if (string(funcName) == string("_start")) continue; // here's a bug on hlt // XXX: check what happens if removed + if (skipFunc != NULL && strcmp(skipFunc, funcName) == 0) { + if (verbose) + cout << "Skipping instrumenting function " << funcName << endl; + continue; + } insertBBCallback(appBin, curFunc, funcName, bbCallback, &bbIndex); } } diff --git a/libAflDyninst.cpp b/libAflDyninst.cpp index 3374010..51fa41d 100644 --- a/libAflDyninst.cpp +++ b/libAflDyninst.cpp @@ -20,7 +20,7 @@ static int __afl_temp_data; static pid_t __afl_fork_pid; static unsigned short prev_id; static long saved_di; -register long rdi asm("di"); // the warning is fine - we need the warning because of a bug in dyninst +register long rdi asm("di"); // the warning is fine - we need the warning because of a bug in dyninst #define PRINT_ERROR(string) write(2, string, strlen(string)) -- cgit 1.4.1