- Add r_anal_strmask
  - Add nopcode (opcode count) to RAnalAop
* r_util
  - Fix constant types in r_types_base
* Add r_anal stuff to TODO
This commit is contained in:
Nibble 2010-05-16 14:04:08 +02:00
parent 6759768392
commit 8ff37cd30b
10 changed files with 59 additions and 13 deletions

1
TODO
View File

@ -59,6 +59,7 @@
BUGS
====
* anal fastargs
* anal_x86_x86im vars 0xff...
* console grep
* x@esp&&x@eip # BUG

View File

@ -106,3 +106,36 @@ R_API int r_anal_set_big_endian(RAnal *anal, int bigend) {
anal->big_endian = bigend;
return R_TRUE;
}
R_API char *r_anal_strmask (RAnal *anal, const char *data) {
RAnalAop *aop;
ut8 *buf;
char *ret = NULL;
int oplen, len, idx = 0;
ret = strdup (data);
buf = malloc (strlen (data));
aop = r_anal_aop_new ();
if (aop == NULL || ret == NULL || buf == NULL) {
free (aop);
free (buf);
free (ret);
return NULL;
}
len = r_hex_str2bin (data, buf);
while (idx < len) {
if ((oplen = r_anal_aop (anal, aop, 0, buf+idx, len-idx)) == 0)
break;
switch (aop->type) {
case R_ANAL_OP_TYPE_CALL:
case R_ANAL_OP_TYPE_CJMP:
case R_ANAL_OP_TYPE_JMP:
if (aop->nopcode != 0)
memset (ret+(idx+aop->nopcode)*2, '.', (oplen-aop->nopcode)*2);
}
idx += oplen;
}
free (aop);
free (buf);
return ret;
}

View File

@ -157,6 +157,7 @@ static int aop(RAnal *anal, RAnalAop *aop, ut64 addr, const ut8 *data, int len)
aop->value = imm;
}
aop->length = io.len;
aop->nopcode = io.opcode_count;
}
return aop->length;

View File

@ -253,7 +253,7 @@ static int cmd_zign(void *data, const char *input) {
ptr = strchr (input+3, ' ');
if (ptr) {
*ptr = 0;
r_sign_add (&core->sign, *input, input+2, ptr+1);
r_sign_add (&core->sign, &core->anal, (int)*input, input+2, ptr+1);
} else eprintf ("Usage: z%c [name] [bytes]\n", *input);
break;
case 'c':

View File

@ -129,6 +129,7 @@ typedef struct r_anal_aop_t {
int stackop; /* operation on stack? */
int cond; /* condition type */
int length; /* length in bytes of opcode */
int nopcode; /* number of opcodes */
int family; /* family of opcode */
int eob; /* end of block (boolean) */
ut64 jump; /* true jmp */
@ -207,6 +208,7 @@ R_API int r_anal_list(RAnal *anal);
R_API int r_anal_use(RAnal *anal, const char *name);
R_API int r_anal_set_bits(RAnal *anal, int bits);
R_API int r_anal_set_big_endian(RAnal *anal, int boolean);
R_API char *r_anal_strmask (RAnal *anal, const char *data);
/* bb.c */
R_API RAnalBB *r_anal_bb_new();

View File

@ -2,6 +2,7 @@
#define _INCLUDE_R_SIGN_H_
#include <r_types.h>
#include <r_anal.h>
#include <r_util.h>
#include "list.h"
@ -33,7 +34,8 @@ typedef int (*RSignCallback)(RSignItem *si, void *user);
#ifdef R_API
R_API RSign *r_sign_init(RSign *sig);
R_API int r_sign_add(RSign *sig, int type, const char *name, const char *arg);
R_API int r_sign_add(RSign *sig, RAnal *anal, int type,
const char *name, const char *arg);
R_API RSign *r_sign_free(RSign *sig);
R_API void r_sign_prefix(RSign *sig, const char *str);
R_API void r_sign_list(RSign *sig, int rad);

View File

@ -22,11 +22,11 @@
#define UT64_32U 0xFFFFFFFF00000000LL
#define UT64_16U 0xFFFFFFFFFFFF0000LL
#define UT64_8U 0xFFFFFFFFFFFFFF00LL
#define UT32_MIN 0L
#define UT32_GT0 0x80000000L
#define UT32_LT0 0x7FFFFFFFL
#define ST32_MAX 0x7FFFFFFFL
#define UT32_MAX 0xFFFFFFFFL
#define UT32_MIN 0
#define UT32_GT0 0x80000000
#define UT32_LT0 0x7FFFFFFF
#define ST32_MAX 0x7FFFFFFF
#define UT32_MAX 0xFFFFFFFF
#define UT16_GT0 0x8000
#define UT16_MAX 0xFFFF
#define UT8_GT0 0x80

View File

@ -1,5 +1,5 @@
NAME=r_sign
DEPS=r_util
DEPS=r_util r_anal
OBJ=sign.o
include ../rules.mk

View File

@ -1,6 +1,7 @@
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
#include <r_sign.h>
#include <r_anal.h>
R_API RSign *r_sign_new() {
return r_sign_init (R_NEW (RSign));
@ -21,11 +22,13 @@ R_API void r_sign_prefix(RSign *sig, const char *str) {
sig->prefix[sizeof (sig->prefix)] = '\0';
}
R_API int r_sign_add(RSign *sig, int type, const char *name, const char *arg) {
R_API int r_sign_add(RSign *sig, RAnal *anal, int type, const char *name, const char *arg) {
int len, ret = R_FALSE;
char *data;
RSignItem *si; // TODO: like in r_search.. we need r_sign_item_new ()
// TODO: but..we need to use a pool here..
if (!name || !arg)
if (!name || !arg || !anal)
return R_FALSE;
switch (type) {
@ -37,7 +40,10 @@ R_API int r_sign_add(RSign *sig, int type, const char *name, const char *arg) {
si->type = type;
snprintf (si->name, sizeof (si->name), "%s.%s",
*sig->prefix?sig->prefix:"sign", name);
len = strlen (arg);
data = r_anal_strmask (anal, arg);
if (data == NULL)
break;
len = strlen (data);
si->bytes = (ut8 *)malloc (len);
si->mask = (ut8 *)malloc (len);
if (si->bytes == NULL || si->mask == NULL) {
@ -47,12 +53,13 @@ R_API int r_sign_add(RSign *sig, int type, const char *name, const char *arg) {
free (si);
break;
}
si->size = r_hex_str2binmask (arg, si->bytes, si->mask);
si->size = r_hex_str2binmask (data, si->bytes, si->mask);
if (si->size<1) {
free (si->bytes);
free (si);
} else list_add_tail (&(si->list), &(sig->items));
sig->s_byte++;
free (data);
break;
default:
case R_SIGN_ANAL:

View File

@ -1,5 +1,5 @@
OBJ=rasign2.o
BIN=rasign2
BINDEPS=r_io r_sign r_util r_lib
BINDEPS=r_io r_sign r_util r_lib r_anal
include ../../rules.mk