Last active
December 16, 2015 14:49
-
-
Save 5kg/5451894 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: mutator mutatee | |
mutator: mutator.o | |
g++ mutator.o -L/usr/lib/dyninst -ldyninstAPI -o mutator | |
mutatee: mutatee.o | |
gcc mutatee.o -std=gnu99 -g -o mutatee -lrt | |
mutatee.o: mutatee.c | |
gcc mutatee.c -std=gnu99 -g -c -o mutatee.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <unistd.h> | |
#include <time.h> | |
#define tic() do { struct timespec ts_start, ts_end; clock_gettime(CLOCK_MONOTONIC, &ts_start) | |
#define toc() clock_gettime(CLOCK_MONOTONIC, &ts_end); \ | |
printf("%lfs\n", (ts_end.tv_sec - ts_start.tv_sec) + (double)(ts_end.tv_nsec - ts_start.tv_nsec)/1e9); } \ | |
while (0) | |
void foo() { | |
sleep(1); | |
printf("I am foo()\n"); | |
return; | |
} | |
void bar() { | |
printf("I am bar()\n"); | |
return; | |
} | |
int main() | |
{ | |
printf("Hello World!\n"); | |
tic(); | |
for (int i = 0; i < 10; ++i) | |
foo(); | |
toc(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <dyninst/BPatch.h> | |
#include <dyninst/BPatch_point.h> | |
#include <dyninst/BPatch_function.h> | |
#include <vector> | |
int main (int argc, const char* argv[]) { | |
BPatch bpatch; | |
BPatch_process *proc = bpatch.processCreate(argv[1], argv + 2); | |
//bpatch.setTrampRecursive(true); | |
//bpatch.setSaveFPR(false); | |
//bpatch.setInstrStackFrames(false); | |
//BPatch_process *proc = bpatch.processAttach(argv[1], atoi(argv[2])); | |
BPatch_image *image = proc->getImage(); | |
std::vector<BPatch_function *> foo_fns, bar_fns; | |
image->findFunction("foo", foo_fns); | |
image->findFunction("bar", bar_fns); | |
std::vector<BPatch_snippet*> args; | |
BPatch_funcCallExpr call_bar(*bar_fns[0], args); | |
proc->insertSnippet(call_bar, (foo_fns[0]->findPoint(BPatch_entry))[0]); | |
proc->continueExecution(); | |
//proc->detach(true); | |
while (!proc->isTerminated()) { | |
bpatch.waitForStatusChange(); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello World! | |
I am bar() | |
I am foo() | |
I am bar() | |
I am foo() | |
I am bar() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment