Dyninst demo learn and test Dyninst :)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

while-mutator.cpp 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <bits/stdc++.h>
  2. #include "BPatch.h"
  3. #include "BPatch_snippet.h"
  4. #include "BPatch_point.h"
  5. #include "BPatch_function.h"
  6. using namespace std;
  7. using namespace Dyninst;
  8. BPatch bpatch;
  9. #define BC(a) BPatch_constExpr(a)
  10. #define BA(a, b, c) BPatch_arithExpr(a, b, c)
  11. int main()
  12. {
  13. BPatch_process* handle = bpatch.processCreate("a.out", NULL);
  14. if (!handle) {
  15. printf("error opening\n");
  16. exit(1);
  17. }
  18. BPatch_image* apimg = handle->getImage();
  19. vector<BPatch_function*> functions;
  20. apimg->findFunction("main", functions);
  21. vector<BPatch_point*>* pt = functions[0]->findPoint(BPatch_entry);
  22. functions.clear();
  23. apimg->findFunction("fe", functions);
  24. BPatch_function *f0 = functions[0];
  25. vector<BPatch_snippet*> argss;
  26. BPatch_funcCallExpr fnc(*f0, argss);
  27. //cout << "Testing :: " << "LLONG_MAX == LLONG_MAX" << endl;
  28. //BPatch_ifExpr ifexp4(BPatch_boolExpr(BPatch_eq, BC((long long) LLONG_MAX), BC((long long) LLONG_MAX)), fnc, fnc1 );
  29. //handle->insertSnippet(ifexp4, *pt);
  30. BPatch_variableExpr *i = apimg->findVariable("i");
  31. BPatch_variableExpr *j = apimg->findVariable("j");
  32. BPatch_whileExpr whilexp(BPatch_boolExpr(BPatch_gt, *i, BC(0)),
  33. BA(BPatch_assign, *i, *j));
  34. handle->insertSnippet(whilexp, *pt);
  35. handle->continueExecution();
  36. return 0;
  37. }