#include “Instrument.h”
using namespace llvm;
Copyright By PowCoder代写 加微信 powcoder
namespace instrument {
static const char *SanitizerFunctionName = “__dbz_sanitizer__”;
static const char *CoverageFunctionName = “__coverage__”;
* Implement divide-by-zero sanitizer.
void instrumentSanitizer(Module *M, Function &F, Instruction &I) {
/* Add your code here */
int divisor = 0;
int line = 0;
int column = 0;
LLVMContext &context = M->getContext();
Type* divisorType = Type::getInt32Ty(context);
* Implement code coverage instrumentation.
void instrumentCoverage(Module *M, Function &F, Instruction &I) {
/* Add your code here */
int line = 0;
int column = 0;
LLVMContext &context = M->getContext();
Type* funcType = Type::getVoidTy(context);
Type* lineType = Type::getInt32Ty(context);
Type* columnType = Type::getInt32Ty(context);
DebugLoc debug = I.getDebugLoc();
((debug) ? Twine(line = debug.getLine()) : Twine(““));
((debug) ? Twine(column = debug.getCol()) : Twine(““));
if (line > 0) {
errs() << "line: " << line << " column: " << column << '\n';
bool Instrument::runOnFunction(Function &F) {
/* Add your code here */
Module *M = F.getParent();
for (auto& B : F) {
for (auto& I : B) {
instrumentCoverage(M, F, I);
instrumentSanitizer(M, F, I);
return true;
char Instrument::ID = 1;
static RegisterPass
X(“Instrument”, “Instrumentations for Dynamic Analysis”, false, false);
} // namespace instrument
#include
#include
#include
#include
#include
#include “Mutate.h”
#include “Utils.h”
int Freq = 1000000;
int Count = 0;
bool test(std::string &Target, std::string &Input, std::string &CampaignStr, std::string &OutDir) {
int ReturnCode = runTarget(Target, Input);
switch (ReturnCode) {
if (Count % Freq == 0)
storePassingInput(Input, CampaignStr, OutDir);
return true;
fprintf(stderr, “%d crashes found\n”, failureCount);
storeCrashingInput(Input, CampaignStr, OutDir);
return false;
fprintf(stderr, “%s not found\n”, Target.c_str());
// ./fuzzer [exe file] [seed input dir] [output dir]
int main(int argc, char **argv) {
if (argc < 5) {
printf("usage %s [exe file] [seed input dir] [output dir] [campaign]\n", argv[0]);
struct stat Buffer;
if (stat(argv[1], &Buffer)) {
fprintf(stderr, "%s not found\n", argv[1]);
if (stat(argv[2], &Buffer)) {
fprintf(stderr, "%s not found\n", argv[2]);
if (stat(argv[3], &Buffer)) {
fprintf(stderr, "%s not found\n", argv[3]);
if (argc >= 6) {
Freq = strtol(argv[5],NULL,10);
std::string Target(argv[1]);
std::string SeedInputDir(argv[2]);
std::string OutDir(argv[3]);
std::string CampaignStr(argv[4]);
Campaign FuzzCampaign;
if (!toCampaign(CampaignStr, FuzzCampaign)) {
initialize(OutDir);
if (readSeedInputs(SeedInputDir)) {
fprintf(stderr, “Cannot read seed input directory\n”);
while (true) {
for (auto i = 0; i < SeedInputs.size(); i++) {
auto I = SeedInputs[i];
std::string Mutant = mutate(I, FuzzCampaign);
test(Target, Mutant, CampaignStr, OutDir);
SeedInputs.push_back(Mutant);
#include "Mutate.h"
#include
#include