* Add an REgg instance into the RCore class

- Make r2 -P use the r_egg api instead of the oldie rarc2
This commit is contained in:
pancake 2011-10-04 10:10:00 +02:00
parent 2201ddd641
commit 23936cfbe5
8 changed files with 52 additions and 19 deletions

View File

@ -202,6 +202,7 @@ static int javasm_init(RBinJavaObj *bin) {
IFDBG printf ("ConstantPoolCount %d\n", bin->cf.cp_count);
bin->cp_items = malloc (sizeof (struct r_bin_java_cp_item_t)*(bin->cf.cp_count+1));
eprintf ("%d\n", bin->cf.cp_count);
for(i=0;i<bin->cf.cp_count;i++) {
struct constant_t *c;
@ -374,11 +375,14 @@ char* r_bin_java_get_version(RBinJavaObj* bin) {
ut64 r_bin_java_get_main(RBinJavaObj* bin) {
int i, j;
for (i=0; i < bin->methods_count; i++)
eprintf ("GO GET MAIN\n");
for (i=0; i < bin->methods_count; i++) {
if (!strcmp(bin->methods[i].name, "main([Ljava/lang/String;)V"))
for (j=0; j < bin->methods[i].attr_count; j++)
if (bin->methods[i].attributes[j].type == R_BIN_JAVA_TYPE_CODE)
return (ut64)bin->methods[i].attributes->info.code.code_offset;
eprintf ("METH : %s\n", bin->methods[i].name);
}
return 0;
}

View File

@ -1,7 +1,7 @@
NAME=r_core
DEPS=r_config r_cons r_line r_io r_cmd r_util r_print r_flags r_asm r_lib
DEPS+=r_debug r_hash r_bin r_lang r_io r_anal r_parse r_print r_bp
DEPS+=r_debug r_hash r_bin r_lang r_io r_anal r_parse r_print r_bp r_egg
DEPS+=r_reg r_search r_syscall r_sign r_diff r_socket r_fs r_magic
OBJ=core.o cmd.o file.o config.o visual.o io.o yank.o libs.o

View File

@ -315,6 +315,7 @@ static int config_asmarch_callback(void *user, void *data) {
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data;
// TODO: control error and restore old value (return false?) show errormsg?
r_egg_setup (core->egg, node->value, core->anal->bits, 0, R_SYS_OS);
if (!r_asm_use (core->assembler, node->value))
eprintf ("asm.arch: cannot find (%s)\n", node->value);
r_config_set (core->config, "anal.plugin", node->value);

View File

@ -308,6 +308,8 @@ R_API int r_core_init(RCore *core) {
//core->num->callback = &num_callback;
//core->num->userptr = core;
core->curasmstep = 0;
core->egg = r_egg_new ();
r_egg_setup (core->egg, R_SYS_ARCH, R_SYS_BITS, 0, R_SYS_OS);
/* initialize libraries */
if (singleton) {
@ -394,6 +396,7 @@ R_API int r_core_init(RCore *core) {
R_API RCore *r_core_free(RCore *c) {
/* TODO: it leaks as shit */
r_egg_free (c->egg);
free (c);
return NULL;
}

View File

@ -2,8 +2,22 @@
#include <r_core.h>
#if 0
Patch format
============
^# -> comments
. -> execute command
! -> execute command
OFFSET { code block }
OFFSET "string"
OFFSET 01020304
OFFSET : assembly
#endif
R_API int r_core_patch (RCore *core, const char *patch) {
char *p, *p2, *q, str[200];
char *p, *p2, *q, str[200], tmp[64];
ut64 noff;
FILE *fd = fopen (patch, "r");
if (fd==NULL) {
@ -25,11 +39,11 @@ R_API int r_core_patch (RCore *core, const char *patch) {
for (++p;*p==' ';p++);
switch (*p) {
case '{': {
FILE *fw = fopen ("out.rarc", "w");
char *off = strdup (str);
char *s, *off = strdup (str);
RBuffer *b = r_buf_new ();
while (!feof (fd)) {
fgets (str, sizeof (str), fd);
// TODO: replace ${..}
if (*str=='}')
break;
if ((q=strstr (str, "${"))) {
@ -37,22 +51,28 @@ R_API int r_core_patch (RCore *core, const char *patch) {
if (end) {
*q = *end = 0;
noff = r_num_math (core->num, q+2);
fwrite (str, strlen (str), 1, fw);
fprintf (fw, "0x%08llx", noff);
fwrite (end+1, strlen (end+1), 1, fw);
r_buf_append_bytes (b, (const ut8*)str, strlen (str));
snprintf (tmp, sizeof (tmp), "0x%08llx", noff);
r_buf_append_bytes (b, (const ut8*)tmp, strlen (tmp));
r_buf_append_bytes (b, (const ut8*)end+1, strlen (end+1));
}
} else fwrite (str, strlen (str), 1, fw);
} else r_buf_append_bytes (b, (const ut8*)str, strlen (str));
}
fclose (fw);
/* XXX: use API here */
r_sys_cmd ("rarc2 < out.rarc > out.rasm");
s = r_buf_to_string (b);
r_egg_load (core->egg, s, 0);
free (s);
r_egg_compile (core->egg);
r_egg_assemble (core->egg);
r_buf_free (b);
b = r_egg_get_bin (core->egg);
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");
r_core_write_at (core, noff, b->buf, b->length);
r_buf_free (b);
free (off);
}
break;

View File

@ -6,6 +6,7 @@
#include "r_io.h"
#include "r_fs.h"
#include "r_lib.h"
#include "r_egg.h"
#include "r_lang.h"
#include "r_asm.h"
#include "r_parse.h"
@ -104,6 +105,7 @@ typedef struct r_core_t {
RSearch *search;
RSign *sign;
RFS *fs;
REgg *egg;
char *cmdqueue;
char *lastcmd;
int cmdrepeat;

View File

@ -37,8 +37,10 @@ typedef struct r_oflist_t {
#define r_list_head(x) x->head
#define r_list_tail(x) x->tail
#define r_list_unref(x) x
#define r_list_iter_get(x) x->data; x=x->n
#define r_list_iter_next(x) (x?1:0)
#define r_list_iter_cur(x) x->p
#define r_list_iter_unref(x) x
#define r_list_iter_free(x) x

View File

@ -13,5 +13,6 @@ else
cd valabind
fi
make clean
make
sudo make install