summaryrefslogtreecommitdiff
path: root/src/elfucli.c
diff options
context:
space:
mode:
authornorly <ny-git@enpas.org>2013-06-18 08:47:33 +0100
committernorly <ny-git@enpas.org>2013-06-18 08:49:07 +0100
commitc98d704a812502c34d82e34949f37c8b87ae6018 (patch)
treeab0ea9890143ab40ead5e07bb9be29ac874e8ccd /src/elfucli.c
parentf88e1ad7d9db8a41abecc795200f21138af65c74 (diff)
Basic detour support
Diffstat (limited to 'src/elfucli.c')
-rw-r--r--src/elfucli.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/elfucli.c b/src/elfucli.c
index 0fd5a2d..cd8f0ba 100644
--- a/src/elfucli.c
+++ b/src/elfucli.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <getopt.h>
#include <libelfu/libelfu.h>
@@ -19,6 +20,7 @@ static void printUsage(char *progname)
" -c, --check Do a few sanity checks and print any errors\n"
" -d, --dump Dump current model state (debug only)\n"
" --reladd obj.o Insert object file contents\n"
+ " --detour from,to Write a jump to <to> at <from>\n"
" -o, --output outfile Where to write the modified ELF file to\n"
"\n");
}
@@ -42,6 +44,7 @@ int main(int argc, char **argv)
{"input", 1, 0, 'i'},
{"output", 1, 0, 'o'},
{"reladd", 1, 0, 10001},
+ {"detour", 1, 0, 10002},
{NULL, 0, NULL, 0}
};
@@ -148,6 +151,41 @@ int main(int argc, char **argv)
}
}
break;
+ case 10002:
+ if (!me) {
+ goto ERR_NO_INPUT;
+ } else {
+ GElf_Addr from;
+ GElf_Addr to;
+ char *second;
+
+ strtok_r(optarg, ",", &second);
+ printf("--detour: From '%s' to '%s'\n", optarg, second);
+
+
+ from = strtoul(optarg, NULL, 0);
+ if (from == 0) {
+ from = elfu_mSymtabLookupAddrByName(me, me->symtab, optarg);
+ }
+ if (from == 0) {
+ printf("--detour: Cannot parse argument 1, aborting.\n");
+ goto ERR;
+ }
+ printf("--detour: From %x\n", (unsigned)from);
+
+ to = strtoul(second, NULL, 0);
+ if (to == 0) {
+ to = elfu_mSymtabLookupAddrByName(me, me->symtab, second);
+ }
+ if (to == 0) {
+ printf("--detour: Cannot parse argument 2, aborting.\n");
+ goto ERR;
+ }
+ printf("--detour: To %x\n", (unsigned)to);
+
+ elfu_mDetour(me, from, to);
+ }
+ break;
case '?':
default:
printUsage(progname);