Skip to content

Commit

Permalink
better result
Browse files Browse the repository at this point in the history
  • Loading branch information
duytai committed Aug 9, 2019
1 parent 7a7b1e7 commit 97270d2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 24 deletions.
4 changes: 2 additions & 2 deletions libfuzzer/Fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ContractInfo Fuzzer::mainContract() {
return *it;
}

void Fuzzer::showStats(Mutation mutation, vector<bool> vulnerabilities) {
void Fuzzer::showStats(const Mutation &mutation, vector<bool> vulnerabilities) {
int numLines = 26, i = 0, expCout = 0;;
if (!fuzzStat.clearScreen) {
for (i = 0; i < numLines; i++) cout << endl;
Expand Down Expand Up @@ -146,7 +146,7 @@ void Fuzzer::showStats(Mutation mutation, vector<bool> vulnerabilities) {
printf(bBL bV20 bV2 bV10 bV5 bV2 bV bBTR bV10 bV5 bV20 bV2 bV2 bBR "\n");
}

void Fuzzer::writeStats(Mutation mutation, vector<bool> vulnerabilities) {
void Fuzzer::writeStats(const Mutation &mutation, vector<bool> vulnerabilities) {
auto contract = mainContract();
ofstream stats(contract.contractName + "/stats.csv", ofstream::app);
if (timer.elapsed() < fuzzParam.csvInterval) {
Expand Down
4 changes: 2 additions & 2 deletions libfuzzer/Fuzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ namespace fuzzer {
Timer timer;
FuzzParam fuzzParam;
FuzzStat fuzzStat;
void writeStats(Mutation mutation, vector<bool> vulnerabilities);
void writeStats(const Mutation &mutation, vector<bool> vulnerabilities);
ContractInfo mainContract();
public:
Fuzzer(FuzzParam fuzzParam);
bool hasNewExceptions(unordered_map<string, unordered_set<u64>> uniqExceptions);
FuzzItem saveIfInterest(TargetExecutive& te, bytes data, uint64_t depth);
void writeTestcase(bytes data, string prefix);
void writeException(bytes data, string prefix);
void showStats(Mutation mutation, vector<bool> vulerabilities);
void showStats(const Mutation &mutation, vector<bool> vulerabilities);
void updateTracebits(unordered_set<uint64_t> tracebits);
void updatePredicates(unordered_map<uint64_t, u256> predicates);
void start();
Expand Down
2 changes: 1 addition & 1 deletion libfuzzer/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace fuzzer {

void Logger::info(string str) {
if (enabled) {
infoFile << "INFO: " << str << endl;
infoFile << str << endl;
}
}

Expand Down
21 changes: 3 additions & 18 deletions libfuzzer/Mutation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ Mutation::Mutation(FuzzItem item, Dicts dicts): curFuzzItem(item), dicts(dicts),
eff[effAPos(dataSize - 1)] = 1;
effCount ++;
}
stageName = stageShort = "init";
stageName = "init";
logger.setEnabled(true);
}

void Mutation::flipbit(int pos) {
curFuzzItem.data[pos >> 3] ^= (128 >> (pos & 7));
}

void Mutation::singleWalkingBit(OnMutateFunc cb) {
stageShort = "flip1";
stageName = "bitflip 1/1";
stageMax = dataSize << 3;
/* Start fuzzing */
Expand All @@ -38,7 +38,6 @@ void Mutation::singleWalkingBit(OnMutateFunc cb) {
}

void Mutation::twoWalkingBit(OnMutateFunc cb) {
stageShort = "flip2";
stageName = "bitflip 2/1";
stageMax = (dataSize << 3) - 1;
/* Start fuzzing */
Expand All @@ -53,7 +52,6 @@ void Mutation::twoWalkingBit(OnMutateFunc cb) {
}

void Mutation::fourWalkingBit(OnMutateFunc cb) {
stageShort = "flip4";
stageName = "bitflip 4/1";
stageMax = (dataSize << 3) - 3;
/* Start fuzzing */
Expand All @@ -72,7 +70,6 @@ void Mutation::fourWalkingBit(OnMutateFunc cb) {
}

void Mutation::singleWalkingByte(OnMutateFunc cb) {
stageShort = "flip8";
stageName = "bitflip 8/8";
stageMax = dataSize;
/* Start fuzzing */
Expand Down Expand Up @@ -101,7 +98,6 @@ void Mutation::singleWalkingByte(OnMutateFunc cb) {
}

void Mutation::twoWalkingByte(OnMutateFunc cb) {
stageShort = "flip16";
stageName = "bitflip 16/8";
stageMax = dataSize - 1;
stageCur = 0;
Expand All @@ -122,7 +118,6 @@ void Mutation::twoWalkingByte(OnMutateFunc cb) {
}

void Mutation::fourWalkingByte(OnMutateFunc cb) {
stageShort = "flip32";
stageName = "bitflip 32/8";
stageMax = dataSize - 3;
stageCur = 0;
Expand All @@ -144,7 +139,6 @@ void Mutation::fourWalkingByte(OnMutateFunc cb) {
}

void Mutation::singleArith(OnMutateFunc cb) {
stageShort = "arith8";
stageName = "arith 8/8";
stageMax = 2 * dataSize * ARITH_MAX;
stageCur = 0;
Expand Down Expand Up @@ -176,7 +170,6 @@ void Mutation::singleArith(OnMutateFunc cb) {
}

void Mutation::twoArith(OnMutateFunc cb) {
stageShort = "arith16";
stageName = "arith 16/8";
stageMax = 4 * (dataSize - 1) * ARITH_MAX;
stageCur = 0;
Expand Down Expand Up @@ -220,7 +213,6 @@ void Mutation::twoArith(OnMutateFunc cb) {
}

void Mutation::fourArith(OnMutateFunc cb) {
stageShort = "arith32";
stageName = "arith 32/8";
stageMax = 4 * (dataSize - 3) * ARITH_MAX;
stageCur = 0;
Expand Down Expand Up @@ -265,7 +257,6 @@ void Mutation::fourArith(OnMutateFunc cb) {
}

void Mutation::singleInterest(OnMutateFunc cb) {
stageShort = "int8";
stageName = "interest 8/8";
stageMax = dataSize * sizeof(INTERESTING_8);
stageCur = 0;
Expand All @@ -292,7 +283,6 @@ void Mutation::singleInterest(OnMutateFunc cb) {
}

void Mutation::twoInterest(OnMutateFunc cb) {
stageShort = "int16";
stageName = "interest 16/8";
stageMax = 2 * (dataSize - 1) * (sizeof(INTERESTING_16) >> 1);
stageCur = 0;
Expand Down Expand Up @@ -328,7 +318,6 @@ void Mutation::twoInterest(OnMutateFunc cb) {
}

void Mutation::fourInterest(OnMutateFunc cb) {
stageShort = "int32";
stageName = "interest 32/8";
stageMax = 2 * (dataSize - 3) * (sizeof(INTERESTING_32) >> 2);
stageCur = 0;
Expand Down Expand Up @@ -367,7 +356,6 @@ void Mutation::fourInterest(OnMutateFunc cb) {
}

void Mutation::overwriteWithDictionary(OnMutateFunc cb) {
stageShort = "ext_UO";
stageName = "dict (over)";
auto dict = get<0>(dicts);
stageMax = dataSize * dict.extras.size();
Expand Down Expand Up @@ -412,7 +400,6 @@ void Mutation::overwriteWithDictionary(OnMutateFunc cb) {
}

void Mutation::overwriteWithAddressDictionary(OnMutateFunc cb) {
stageShort = "ext_AO";
stageName = "address (over)";
auto dict = get<1>(dicts);

Expand Down Expand Up @@ -445,7 +432,6 @@ void Mutation::overwriteWithAddressDictionary(OnMutateFunc cb) {
* TODO: If found more, do more havoc
*/
void Mutation::havoc(OnMutateFunc cb) {
stageShort = "havoc";
stageName = "havoc";
stageMax = HAVOC_MIN;
stageCur = 0;
Expand Down Expand Up @@ -589,7 +575,7 @@ void Mutation::havoc(OnMutateFunc cb) {
}
}
}
cb(curFuzzItem.data);
cb(data);
stageCur ++;
/* Restore to original state */
data = origin;
Expand Down Expand Up @@ -628,7 +614,6 @@ bool Mutation::splice(vector<FuzzItem> queues) {
}

void Mutation::random(OnMutateFunc cb) {
stageShort = "random";
stageName = "random 8/8";
stageMax = 1;
for (int i = 0; i < dataSize; i ++) {
Expand Down
3 changes: 2 additions & 1 deletion libfuzzer/Mutation.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <vector>
#include "Common.h"
#include "Logger.h"
#include "TargetContainer.h"
#include "Dictionary.h"
#include "FuzzItem.h"
Expand All @@ -12,6 +13,7 @@ using namespace std;
namespace fuzzer {
using Dicts = tuple<Dictionary/* code */, Dictionary/* address */>;
class Mutation {
Logger logger;
FuzzItem curFuzzItem;
Dicts dicts;
int effCount;
Expand All @@ -22,7 +24,6 @@ namespace fuzzer {
int stageMax;
int stageCur;
string stageName;
string stageShort;
static int stageCycles[32];
Mutation(FuzzItem item, Dicts dicts);
void singleWalkingBit(OnMutateFunc cb);
Expand Down

0 comments on commit 97270d2

Please sign in to comment.