This commit is contained in:
Nibble 2009-05-02 01:08:57 +02:00
commit f76f81b917
6 changed files with 143 additions and 19 deletions

View File

@ -96,6 +96,10 @@ int r_anal_aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
return R_FALSE;
}
struct r_anal_fcn_t *r_anal_funcions_get(struct r_anal_t *anal, u8 *buf, u64 len)
{
}
struct r_anal_refline_t *r_anal_reflines_get(struct r_anal_t *anal, u8 *buf, u64 len, int nlines, int linesout)
{
struct r_anal_refline_t *list = MALLOC_STRUCT(struct r_anal_refline_t);

101
libr/cons/README Normal file
View File

@ -0,0 +1,101 @@
+--------+
| r_cons |
+--------+
r_cons_fb
r_cons_frame
r_cons_frame_add
r_cons_frame_del
struct r_cons_frame_t {
int w, h; // should be the same as text|draw->w and text|draw->h
int rw, rh;
struct r_cons_buffer_t *text;
struct r_cons_buffer_t *draw;
struct
};
struct r_cons_buffer_t {
int alpha; /* ' ' chars in buffers are not written */
int w, h;
u8 *buf;
};
struct r_cons_t {
struct r_cons_buffer_t *b;
int w, h;
struct list_head frames;
};
struct r_cons_frame_t *r_cons_frame_new(int x, int y, int w, int h)
{
struct r_cons_frame_t *f = MALLOC_STRUCT(struct r_cons_frame_t);
f->text = r_cons_buffer_new(w, h);
f->draw = r_cons_buffer_new(w, h);
f->w = w;
f->h = h;
return f;
}
void r_cons_frame_add(struct r_cons_t *cons, struct r_cons_frame_t *f, int head)
{
if (head) list_add(&(f->list), &cons->frames);
else list_add_tail(&(f->list), &cons->frames);
}
int r_cons_frame_render(struct r_cons_frame_t *frame, struct r_cons_buffer_t *buf)
{
/* foreach pixel resolve matching frame (Z-ordered) and draw */
}
/* <{:api-prefix r_cons_}> */
/* <{:doc Draws a line between two points in a buffer}> */
/* <{:api int,buffer_line,int,int,int,int}> */
void r_cons_buffer_line(struct r_cons_buffer_t *buf, int x0, int y0, int x1, int y1)
{
/* XXX PURE SHIT */
char onechars[9] = {
'.', '_',',',
'\\', '|','/',
'\'', '^','\'',
};
double x = x0;
double y = y0;
double xi = x1-x0;
double yi = y1-y0;
for(;x<x1;x++) {
r_cons_buffer_putch(buf, x, y, '.');
x+=xi;
}
}
/* buffers */
struct r_cons_buffer *r_cons_buffer_new(int w, int h)
{
struct r_cons_buffer_t *buf = MALLOC_STRUCT(struct r_cons_buffer_t);
if (w<1) w=1;
if (h<1) h=1;
buf->rw = buf->w = w;
buf->rh = buf->h = h;
buf->buf = (u8*)malloc(w*h);
return buf;
}
int r_cons_buffer_set_size(struct r_cons_buffer *buf, int w, int h)
{
struct r_cons_buffer_t *buf = MALLOC_STRUCT(struct r_cons_buffer_t);
if (w<1) w=1;
if (h<1) h=1;
if (w>buf->rw) {
/* must resize internal buffer */
buf->rw = w;
buf->buf = (u8*) realloc(buf->buf, w*h);
}
buf->rw = buf->w = w;
buf->rh = buf->h = h;
buf->buf = (u8*)malloc(w*h);
return buf;
}

View File

@ -8,6 +8,8 @@
#include "r_types.h"
#include "list.h"
#define R_ANAL_MAXREG 16
enum {
R_ANAL_AOP_FAMILY_UNKNOWN = 0,
R_ANAL_AOP_FAMILY_CPU, /* normal cpu insturction */
@ -92,19 +94,24 @@ struct r_anal_refline_t {
};
struct r_anal_aop_t {
int type; /* type of opcode */
int stackop; /* operation on stack? */
int length; /* length in bytes of opcode */
int family; /* family of opcode */
int eob; /* end of block (boolean) */
u64 jump; /* true jmp */
u64 fail; /* false jmp */
u64 ref; /* reference to memory */
u64 value; /* reference to value */
int r_dst,r_src1,r_src2; /* register arguments */
u64 i_dst,i_src1,i_src2; /* inmediate arguments */
int type; /* type of opcode */
int stackop; /* operation on stack? */
int length; /* length in bytes of opcode */
int family; /* family of opcode */
int eob; /* end of block (boolean) */
u64 jump; /* true jmp */
u64 fail; /* false jmp */
u64 ref; /* reference to memory */
u64 value; /* reference to value */
int r_dst[R_ANAL_MAXREG]; /* register arguments */
u64 i_dst[R_ANAL_MAXREG]; /* inmediate arguments */
};
struct r_anal_fcn_t {
u64 from;
u64 to;
}
struct r_anal_ctx_t {
/* TODO: add more info here */
/* per opcode deep level */

View File

@ -1,4 +1,4 @@
CFLAGS=-I../../include -Wall
CFLAGS=-I../../include -Wall -DWORDSIZE=64
BINDEPS=
all: io_ptrace.so io_dbg.so io_malloc.so io_shm.so

View File

@ -28,16 +28,18 @@ static int nonstop = 0;
static int mode = R_SEARCH_KEYWORD;
static u64 cur = 0;
static char *buffer = NULL;
static char *curfile = NULL;
static u64 bsize = 4096;
static int hexstr = 0;
static int hit(struct r_search_kw_t *kw, void *user, u64 addr)
{
const u8 *buf = (u8*)user;
int delta = addr-cur;
if (rad) {
printf("f hit%d_%d 0x%08llx\n", 0, kw->count, addr);
printf("f hit%d_%d 0x%08llx ; %s\n", 0, kw->count, addr, curfile);
} else {
printf("==> HIT %d AT %lld\n", kw->count, addr);
printf("==> HIT %d AT 0x%llx ; %s\n", kw->count, addr, curfile);
if (hexdump) {
r_print_hexdump(addr, buffer+delta, 16, 78, R_TRUE);
r_cons_flush();
@ -82,11 +84,14 @@ int radiff_open(char *file)
to = r_io_size(&io, fd);
}
if (mode == R_SEARCH_KEYWORD) {
r_search_kw_add(rs, str, mask);
if (hexstr)
r_search_kw_add_hex(rs, str, mask);
else r_search_kw_add(rs, str, mask);
}
curfile = file;
r_search_begin(rs);
r_io_lseek(&io, fd, from, R_IO_SEEK_SET);
printf("; %s 0x%08llx-0x%08llx\n", file, from, to);
//printf("; %s 0x%08llx-0x%08llx\n", file, from, to);
for(cur=from; !last && cur<to;cur+=bsize) {
if ((cur+bsize)>to) {
bsize = to-cur;
@ -95,7 +100,7 @@ int radiff_open(char *file)
int ret = r_io_read(&io, fd, buffer, bsize);
if (ret == 0) {
if (nonstop) continue;
fprintf(stderr, "Error reading at 0x%08llx\n", cur);
// fprintf(stderr, "Error reading at 0x%08llx\n", cur);
return 1;
}
if (ret != bsize)
@ -120,6 +125,7 @@ int main(int argc, char **argv)
case 's':
mode = R_SEARCH_KEYWORD;
str = optarg;
hexstr = 0;
break;
case 'b':
bsize = r_num_math(NULL, optarg);
@ -129,6 +135,7 @@ int main(int argc, char **argv)
break;
case 'x':
mode = R_SEARCH_KEYWORD;
hexstr = 1;
str = optarg;
break;
case 'm':

View File

@ -251,6 +251,12 @@ int r_socket_accept(int fd)
return accept(fd, NULL, NULL);
}
int r_socket_flush(int fd)
{
/* TODO */
}
int r_socket_fgets(int fd, char *buf, int size)
{
int i = 0;
@ -261,9 +267,8 @@ int r_socket_fgets(int fd, char *buf, int size)
while(i<size-1) {
ret = r_socket_read(fd, (u8 *)buf+i, 1);
if (ret==0) {
if (ret==0)
return -1;
}
if (ret<0) {
r_socket_close(fd);
return -1;