* Fix build of rapatch

This commit is contained in:
pancake 2011-04-28 09:50:38 +02:00
parent 708e10e413
commit 28de8a232f
2 changed files with 43 additions and 34 deletions

View File

@ -1,7 +1,17 @@
all:
gcc rapatch.c `pkg-config --cflags --libs r_core`
OBJ=rapatch.o
BIN=rapatch2${EXT_EXE}
a: all
CFLAGS+=-I../../libr/include
LDFLAGS+=-L../../libr/core -lr_core
LDFLAGS+=-L../../libr/util -lr_util
LDFLAGS+=-L../../libr/cons -lr_cons
all: ${BIN}
${BIN}: ${OBJ}
${CC} -o ${BIN} ${OBJ} ${CFLAGS} ${LDFLAGS}
test: all
cp /bin/ls ls
./a.out ls patch.txt
./ls

View File

@ -1,4 +1,4 @@
/* radare - Copyright 2010 - pancake<nopcode.org> */
/* radare - Copyright 2010-2011 - pancake<nopcode.org> */
#include <stdio.h>
#include <r_core.h>
@ -13,45 +13,45 @@ int main(int argc, char **argv) {
eprintf ("Usage: rapatch [target] [patchfile ...]\n");
return 1;
}
fd = fopen(patch, "r");
fd = fopen (patch, "r");
if (fd==NULL) {
eprintf ("Cannot open patch file\n");
return 1;
}
core = r_core_new ();
r_core_file_open (core, file, 2);
r_core_file_open (core, file, 2, 0LL);
r_core_cmdf (core, ".!rabin2 -revSIsi %s", file);
r_cons_flush ();
while (!feof(fd)) {
fgets(str, sizeof(str), fd);
while (!feof (fd)) {
fgets (str, sizeof (str), fd);
if (*str=='#' || *str=='\n' || *str=='\r')
continue;
if (*str=='.' || *str=='!') {
r_core_cmd0(core, str);
r_core_cmd0 (core, str);
continue;
}
p = strchr (str+1, ' ');
if (p) {
*p=0;
for(++p;*p==' ';p++);
switch(*p) {
for (++p;*p==' ';p++);
switch (*p) {
case '{': {
FILE *fw = fopen("out.rarc", "w");
char *off = strdup(str);
while(!feof(fd)) {
fgets(str, sizeof(str), fd);
FILE *fw = fopen ("out.rarc", "w");
char *off = strdup (str);
while (!feof (fd)) {
fgets (str, sizeof (str), fd);
// TODO: replace ${..}
if (*str=='}')
break;
if ((q=strstr(str, "${"))) {
char *end = strchr(q+2,'}');
if ((q=strstr (str, "${"))) {
char *end = strchr (q+2,'}');
if (end) {
*q = *end = 0;
noff = r_num_math(core->num, q+2);
noff = r_num_math (core->num, q+2);
fwrite (str, strlen (str), 1, fw);
fprintf(fw, "0x%08llx", noff);
fprintf (fw, "0x%08llx", noff);
fwrite (end+1, strlen (end+1), 1, fw);
}
} else fwrite (str, strlen (str), 1, fw);
@ -59,32 +59,31 @@ int main(int argc, char **argv) {
fclose (fw);
r_sys_cmd ("rarc2 < out.rarc > out.rasm");
noff = r_num_math(core->num, off);
r_sys_cmdf( "rasm2 -o 0x%llx -a x86.olly "
noff = r_num_math (core->num, off);
r_sys_cmdf ( "rasm2 -o 0x%llx -a x86.olly "
"-f out.rasm | tee out.hex", noff);
r_core_cmdf(core, "s %s", off);
r_core_cmd0(core, "wF out.hex");
free(off);
r_core_cmdf (core, "s %s", off);
r_core_cmd0 (core, "wF out.hex");
free (off);
}
break;
case '"':
p2=strchr(p+1,'"');
if (p2)
*p2=0;
r_core_cmdf(core, "s %s", str);
r_core_cmdf(core, "\" %s\"", p+1);
p2 = strchr (p+1,'"');
if (p2) *p2=0;
r_core_cmdf (core, "s %s", str);
r_core_cmdf (core, "\" %s\"", p+1);
break;
case ':':
r_core_cmdf(core, "s %s", str);
r_core_cmdf(core, "wa %s", p);
r_core_cmdf (core, "s %s", str);
r_core_cmdf (core, "wa %s", p);
break;
default:
r_core_cmdf(core, "s %s", str);
r_core_cmdf(core, "wx %s", p);
r_core_cmdf (core, "s %s", str);
r_core_cmdf (core, "wx %s", p);
break;
}
}
}
fclose(fd);
fclose (fd);
return 0;
}