Skip to content

Commit

Permalink
Upgrade to E9Patch-1.0.0-rc3 & other improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
GJDuck committed Aug 1, 2022
1 parent c64d91e commit b00feae
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 19 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ To build E9AFL, simply run the `build.sh` script:

$ ./build.sh

To build the Debian package, simply run the `install.sh` script:

$ ./install.sh

## Usage

First, install `afl-fuzz`:
Expand All @@ -31,7 +35,10 @@ To use E9AFL, simply run the command:

This will generate an AFL-instrumented `binary.afl` which can be
used with `afl-fuzz`.
See the example below.

For more information on tool usage, see the man page:

$ man -l doc/e9afl.l

## Example

Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.7.0
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fi

set -e

VERSION=c30c678632f4a60b2f77c8c3cc252c5d557a33e0
VERSION=c08b98f76191221da950a34d7a7216844cd43629

# STEP (1): install e9patch if necessary:
if [ ! -x e9patch-$VERSION/e9patch ]
Expand Down Expand Up @@ -70,7 +70,7 @@ e9patch-$VERSION/e9compile.sh afl-rt.c -I e9patch-$VERSION/examples/ \
chmod a-x afl-rt

# STEP (4): build the driver:
g++ -std=c++11 -fPIC -pie -O2 -o e9afl e9afl.cpp
g++ -std=c++11 -fPIC -pie -O2 -DVERSION=`cat VERSION` -o e9afl e9afl.cpp
strip e9afl

# STEP (5): build the installation package:
Expand Down
5 changes: 4 additions & 1 deletion doc/e9afl.1
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ Use \fBoutput\fR as the output binary name.
By default, \fBe9afl\fR uses the basename of the input binary appended with
the string \fB".afl"\fR.
.TP
\fB--help\fR
\fB-h\fR, \fB--help\fR
Display the help message and exit.
.TP
\fB-v\fR, \fB--version\fR
Print the version and exit.
.SH "SEE ALSO"
\fIafl-fuzz\fR(1)
.SH AUTHOR
Expand Down
12 changes: 6 additions & 6 deletions e9AFLPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* | __/\__, / ___ \| _| | |___
* \___| /_/_/ \_\_| |_____|
*
* Copyright (C) 2021 National University of Singapore
* Copyright (C) 2022 National University of Singapore
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -129,7 +129,7 @@ enum
/*
* Initialization.
*/
extern void *e9_plugin_init_v1(const Context *cxt)
extern void *e9_plugin_init(const Context *cxt)
{
static const struct option long_options[] =
{
Expand Down Expand Up @@ -658,7 +658,7 @@ static void calcInstrumentPoints(const ELF *elf, const Instr *Is, size_t size,
/*
* Events.
*/
extern void e9_plugin_event_v1(const Context *cxt, Event event)
extern void e9_plugin_event(const Context *cxt, Event event)
{
switch (event)
{
Expand All @@ -678,23 +678,23 @@ extern void e9_plugin_event_v1(const Context *cxt, Event event)
/*
* Matching. Return `true' iff we should instrument this instruction.
*/
extern intptr_t e9_plugin_match_v1(const Context *cxt)
extern intptr_t e9_plugin_match(const Context *cxt)
{
return (instrument.find(cxt->I->address) != instrument.end());
}

/*
* Patch template.
*/
extern void e9_plugin_code_v1(const Context *cxt)
extern void e9_plugin_code(const Context *cxt)
{
fputs("\"$afl\",", cxt->out);
}

/*
* Patching.
*/
extern void e9_plugin_patch_v1(const Context *cxt)
extern void e9_plugin_patch(const Context *cxt)
{
if (instrument.find(cxt->I->address) == instrument.end())
return;
Expand Down
26 changes: 18 additions & 8 deletions e9afl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* | __/\__, / ___ \| _| | |___
* \___| /_/_/ \_\_| |_____|
*
* Copyright (C) 2021 National University of Singapore
* Copyright (C) 2022 National University of Singapore
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -33,14 +33,18 @@

#include <string>

#define STRING(s) STRING_2(s)
#define STRING_2(s) #s

enum Option
{
OPTION_COUNTER,
OPTION_OBLOCK,
OPTION_OSELECT,
OPTION_DEBUG,
OPTION_OUTPUT,
OPTION_HELP
OPTION_HELP,
OPTION_VERSION,
};

enum Value
Expand Down Expand Up @@ -172,12 +176,13 @@ int main(int argc, char **argv)
{"Oselect", required_argument, nullptr, OPTION_OSELECT},
{"debug", no_argument, nullptr, OPTION_DEBUG},
{"help", no_argument, nullptr, OPTION_HELP},
{"version", no_argument, nullptr, OPTION_VERSION},
{nullptr, no_argument, nullptr, 0}
};
while (true)
{
int idx;
int opt = getopt_long_only(argc, argv, "do:", long_options, &idx);
int opt = getopt_long_only(argc, argv, "dho:v", long_options, &idx);
if (opt < 0)
break;
switch (opt)
Expand All @@ -198,10 +203,10 @@ int main(int argc, char **argv)
free(option_output);
option_output = strdup(optarg);
break;
case OPTION_HELP:
case 'h': case OPTION_HELP:
fprintf(stderr, "usage %s [OPTIONS] binary [e9tool-OPTIONS]\n",
argv[0]);
fprintf(stderr,
printf(
"\n"
"OPTIONS:\n"
"\t--counter=classic,neverzero,saturated\n"
Expand All @@ -214,9 +219,14 @@ int main(int argc, char **argv)
"\t\tEnable debugging output.\n"
"\t-o OUTPUT\n"
"\t\tSet OUTPUT to be the output binary filename.\n"
"\t-help\n"
"\t\tPrint this message\n\n");
exit(0);
"\t-h, --help\n"
"\t\tPrint this message.\n"
"\t-v, -version\n"
"\t\tPrint version information.\n\n");
exit(EXIT_SUCCESS);
case 'v': case OPTION_VERSION:
printf("E9AFL " STRING(VERSION) "\n");
exit(EXIT_SUCCESS);
default:
error("failed to parse command-line options; try `--help' "
"for more information");
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ else
fi

NAME=e9afl
VERSION=0.6.0
VERSION=`cat VERSION`

if [ ! -x install/e9afl ]
then
Expand Down

0 comments on commit b00feae

Please sign in to comment.