Browse Source

rewriter demo initla

master
LER0ever 8 months ago
commit
3db222eed5
4 changed files with 68 additions and 0 deletions
  1. 2
    0
      .gitignore
  2. 1
    0
      compile.sh
  3. 22
    0
      mutatee.c
  4. 43
    0
      mutator.cpp

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
*.out
mutator

+ 1
- 0
compile.sh View File

@@ -0,0 +1 @@
g++ -g mutator.cpp -I/home/rong/Code/install/include -L/home/rong/Code/install/lib -ldyninstAPI -lboost_system -o mutator

+ 22
- 0
mutatee.c View File

@@ -0,0 +1,22 @@
#include "stdio.h"

int main()
{
printf("Dyninst mutator test demo\n");
return 0;
}

void fe()
{
printf(" == \n");
}

void fne()
{
printf(" != \n");
}

void fn(char* s)
{
printf("%s", s);
}

+ 43
- 0
mutator.cpp View File

@@ -0,0 +1,43 @@
#include <bits/stdc++.h>

#include "BPatch.h"
#include "BPatch_snippet.h"
#include "BPatch_point.h"
#include "BPatch_function.h"
#include "BPatch_binaryEdit.h"

using namespace std;
using namespace Dyninst;

int main()
{
BPatch bpatch;
BPatch_binaryEdit* handle = bpatch.openBinary("a.out", NULL);
if (!handle) {
printf("error opening\n");
exit(1);
}
BPatch_image* apimg = handle->getImage();
vector<BPatch_function*> functions;
apimg->findFunction("main", functions);
vector<BPatch_point*>* pt = functions[0]->findPoint(BPatch_entry);

functions.clear();
apimg->findFunction("fe", functions);
BPatch_function *f0 = functions[0];
vector<BPatch_snippet*> argss;
BPatch_funcCallExpr fnc(*f0, argss);

functions.clear();
apimg->findFunction("fne", functions);
BPatch_function *f1 = functions[0];
BPatch_funcCallExpr fnc1(*f1, argss);

cout << "Testing :: " << "0 | 1" << endl;
BPatch_ifExpr ifexp4(BPatch_boolExpr(BPatch_eq, BPatch_constExpr(0), BPatch_constExpr(1)), fnc, fnc1 );
handle->insertSnippet(ifexp4, *pt);

handle->writeFile("mutated.out");

return 0;
}

Loading…
Cancel
Save