mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-22 23:31:26 +00:00
* Do not pass CFLAGS when linking asm/t/fastcall
* Populate r_io_lseek -> r_io_seek refactoring * R_APIfy a bit the r_hash * Also build hash/t/hello program * Fix some warnings and build blockers * Make rahash2 read from files (using slurp) * Added r_buf API in r_util (interacts with r_io) * Add initial template for r_io_bind - Needs some more work
This commit is contained in:
parent
16cf12c8d6
commit
e5c83d6d26
@ -6,7 +6,7 @@ LIBS+=-ldl
|
|||||||
all: ${BIN} fastcall
|
all: ${BIN} fastcall
|
||||||
|
|
||||||
fastcall: fastcall.o
|
fastcall: fastcall.o
|
||||||
${CC} -I../../include fastcall.o -Wl,-R.. -L.. -lr_asm -o fastcall
|
${CC} fastcall.o -Wl,-R.. -L.. -lr_asm -o fastcall
|
||||||
|
|
||||||
myclean:
|
myclean:
|
||||||
rm -f fastcall fastcall.o
|
rm -f fastcall fastcall.o
|
||||||
|
@ -776,7 +776,7 @@ static int cmd_write(void *data, const char *input)
|
|||||||
{
|
{
|
||||||
ut64 off = r_num_math(&core->num, input+1);
|
ut64 off = r_num_math(&core->num, input+1);
|
||||||
r_io_set_fd(&core->io, core->file->fd);
|
r_io_set_fd(&core->io, core->file->fd);
|
||||||
r_io_lseek(&core->io, core->seek, R_IO_SEEK_SET);
|
r_io_seek(&core->io, core->seek, R_IO_SEEK_SET);
|
||||||
if (off&UT64_32U) {
|
if (off&UT64_32U) {
|
||||||
/* 8 byte addr */
|
/* 8 byte addr */
|
||||||
ut64 addr8;
|
ut64 addr8;
|
||||||
|
@ -71,7 +71,7 @@ R_API int r_core_seek(struct r_core_t *core, ut64 addr, int rb)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
r_io_set_fd(&core->io, core->file->fd);
|
r_io_set_fd(&core->io, core->file->fd);
|
||||||
ret = r_io_lseek(&core->io, addr, R_IO_SEEK_SET);
|
ret = r_io_seek(&core->io, addr, R_IO_SEEK_SET);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
core->seek = addr;
|
core->seek = addr;
|
||||||
if (rb) return r_core_block_read (core, 0);
|
if (rb) return r_core_block_read (core, 0);
|
||||||
@ -96,7 +96,7 @@ R_API int r_core_block_read(struct r_core_t *core, int next)
|
|||||||
if (core->file == NULL)
|
if (core->file == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
r_io_set_fd (&core->io, core->file->fd);
|
r_io_set_fd (&core->io, core->file->fd);
|
||||||
r_io_lseek(&core->io, core->seek+((next)?core->blocksize:0), R_IO_SEEK_SET);
|
r_io_seek(&core->io, core->seek+((next)?core->blocksize:0), R_IO_SEEK_SET);
|
||||||
return r_io_read(&core->io, core->block, core->blocksize);
|
return r_io_read(&core->io, core->block, core->blocksize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "r_db.h"
|
#include "r_db.h"
|
||||||
|
#include "r_util.h"
|
||||||
/*
|
/*
|
||||||
struct r_db_table_t *table = \
|
struct r_db_table_t *table = \
|
||||||
r_db_table_new("cities", "ziu", "name people postal");
|
r_db_table_new("cities", "ziu", "name people postal");
|
||||||
@ -13,7 +14,6 @@ sizes['i'] = 4;
|
|||||||
struct r_db_table_t *r_db_table_new(const char *name, const char *fmt, const char *fields)
|
struct r_db_table_t *r_db_table_new(const char *name, const char *fmt, const char *fields)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *ptr;
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
struct r_db_table_t *table = MALLOC_STRUCT(struct r_db_table_t);
|
struct r_db_table_t *table = MALLOC_STRUCT(struct r_db_table_t);
|
||||||
table->args = strdup(fields);
|
table->args = strdup(fields);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include "r_hash.h"
|
#include "r_hash.h"
|
||||||
|
|
||||||
/* returns 0-100 */
|
/* returns 0-100 */
|
||||||
int r_hash_pcprint(ut8 *buffer, ut64 len)
|
R_API int r_hash_pcprint(ut8 *buffer, ut64 len)
|
||||||
{
|
{
|
||||||
ut8 *end = buffer + len;
|
ut8 *end = buffer + len;
|
||||||
int n;
|
int n;
|
||||||
@ -15,7 +15,7 @@ int r_hash_pcprint(ut8 *buffer, ut64 len)
|
|||||||
return ((100*n)/len);
|
return ((100*n)/len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int r_hash_par(ut8 *buf, ut64 len)
|
R_API int r_hash_par(ut8 *buf, ut64 len)
|
||||||
{
|
{
|
||||||
ut8 *end = buf+len;
|
ut8 *end = buf+len;
|
||||||
ut32 ones = 0;
|
ut32 ones = 0;
|
||||||
@ -29,7 +29,7 @@ int r_hash_par(ut8 *buf, ut64 len)
|
|||||||
|
|
||||||
/* These functions comes from 0xFFFF */
|
/* These functions comes from 0xFFFF */
|
||||||
/* fmi: nopcode.org/0xFFFF */
|
/* fmi: nopcode.org/0xFFFF */
|
||||||
ut16 r_hash_xorpair(const ut8 *a, ut64 len)
|
R_API ut16 r_hash_xorpair(const ut8 *a, ut64 len)
|
||||||
{
|
{
|
||||||
ut16 *b = (ut16 *)a;
|
ut16 *b = (ut16 *)a;
|
||||||
ut16 result = 0;
|
ut16 result = 0;
|
||||||
@ -38,7 +38,7 @@ ut16 r_hash_xorpair(const ut8 *a, ut64 len)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ut8 r_hash_xor(const ut8 *b, ut64 len)
|
R_API ut8 r_hash_xor(const ut8 *b, ut64 len)
|
||||||
{
|
{
|
||||||
ut8 res = 0;
|
ut8 res = 0;
|
||||||
for(;len--;b=b+1)
|
for(;len--;b=b+1)
|
||||||
@ -46,7 +46,7 @@ ut8 r_hash_xor(const ut8 *b, ut64 len)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
ut8 r_hash_mod255(const ut8 *b, ut64 len)
|
R_API ut8 r_hash_mod255(const ut8 *b, ut64 len)
|
||||||
{
|
{
|
||||||
int i, c = 0;
|
int i, c = 0;
|
||||||
/* from gdb */
|
/* from gdb */
|
||||||
@ -56,7 +56,7 @@ ut8 r_hash_mod255(const ut8 *b, ut64 len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: ignore case.. we have to use strcasestr */
|
/* TODO: ignore case.. we have to use strcasestr */
|
||||||
ut64 r_hash_name_to_bits(const char *name)
|
R_API ut64 r_hash_name_to_bits(const char *name)
|
||||||
{
|
{
|
||||||
ut64 bits = R_HASH_NONE;
|
ut64 bits = R_HASH_NONE;
|
||||||
if (strstr(name, "md4"))
|
if (strstr(name, "md4"))
|
||||||
|
@ -3,4 +3,12 @@ BIN=rahash2
|
|||||||
BINDEPS=r_io r_hash r_util
|
BINDEPS=r_io r_hash r_util
|
||||||
LIBS=-lm
|
LIBS=-lm
|
||||||
|
|
||||||
|
all: ${BIN} hello
|
||||||
|
|
||||||
|
hello: hello.o
|
||||||
|
${CC} -I../../include hello.o -Wl,-R.. -L.. -lr_hash -lr_io -o hello
|
||||||
|
|
||||||
|
myclean:
|
||||||
|
rm -f hello hello.o
|
||||||
|
|
||||||
include ../../rules.mk
|
include ../../rules.mk
|
||||||
|
@ -24,9 +24,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* get file size */
|
/* get file size */
|
||||||
r_io_lseek(&io, fd, 0, R_IO_SEEK_END);
|
size = r_io_size(&io, fd);
|
||||||
size = r_io_lseek(&io, fd, 0, R_IO_SEEK_END);
|
|
||||||
r_io_lseek(&io, fd, 0, R_IO_SEEK_SET);
|
|
||||||
|
|
||||||
/* read bytes */
|
/* read bytes */
|
||||||
buf = (ut8*) malloc(size);
|
buf = (ut8*) malloc(size);
|
||||||
@ -36,7 +34,8 @@ int main(int argc, char **argv)
|
|||||||
r_io_close(&io, fd);
|
r_io_close(&io, fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
r_io_read(&io, fd, buf, size);
|
memset(buf, 0, size);
|
||||||
|
r_io_read(&io, buf, size);
|
||||||
printf("----\n%s\n----\n", buf);
|
printf("----\n%s\n----\n", buf);
|
||||||
|
|
||||||
printf("file size = %lld\n", size);
|
printf("file size = %lld\n", size);
|
||||||
|
@ -18,6 +18,7 @@ static int do_hash(const char *algo, const ut8 *buf, int len, int bsize)
|
|||||||
bsize = len;
|
bsize = len;
|
||||||
|
|
||||||
r_hash_state_init(&ctx, R_HASH_ALL);
|
r_hash_state_init(&ctx, R_HASH_ALL);
|
||||||
|
//r_hash_state_init(&ctx, algobit);
|
||||||
/* TODO: Loop here for blocks */
|
/* TODO: Loop here for blocks */
|
||||||
if (algobit & R_HASH_MD4) {
|
if (algobit & R_HASH_MD4) {
|
||||||
c = r_hash_state_md4(&ctx, buf, len);
|
c = r_hash_state_md4(&ctx, buf, len);
|
||||||
@ -48,7 +49,7 @@ static int do_help(int line)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *algo = "md5"; /* default hashing algorithm */
|
char *algo = "md5"; /* default hashing algorithm */
|
||||||
ut8 *buf = NULL;
|
const ut8 *buf = NULL;
|
||||||
int c, buf_len = 0;
|
int c, buf_len = 0;
|
||||||
int bsize = 0;
|
int bsize = 0;
|
||||||
|
|
||||||
@ -62,13 +63,15 @@ int main(int argc, char **argv)
|
|||||||
bsize = (int)r_num_math(NULL, optarg);
|
bsize = (int)r_num_math(NULL, optarg);
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
buf = optarg;
|
buf = (ut8*) optarg;
|
||||||
buf_len = strlen(optarg);
|
buf_len = strlen(optarg);
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
return do_help(1);
|
return do_help(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (optind<argc)
|
||||||
|
buf = r_file_slurp(argv[optind], &buf_len);
|
||||||
|
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
do_help(0);
|
do_help(0);
|
||||||
|
@ -5,30 +5,30 @@
|
|||||||
|
|
||||||
/* checksums */
|
/* checksums */
|
||||||
/* XXX : crc16 should use 0 as arg0 by default */
|
/* XXX : crc16 should use 0 as arg0 by default */
|
||||||
ut16 r_hash_crc16(ut16 crc, const ut8 *buffer, ut64 len);
|
R_API ut16 r_hash_crc16(ut16 crc, const ut8 *buffer, ut64 len);
|
||||||
ut32 r_hash_crc32(const ut8 *buf, ut64 len);
|
R_API ut32 r_hash_crc32(const ut8 *buf, ut64 len);
|
||||||
ut8 r_hash_xor(const ut8 *b, ut64 len);
|
R_API ut8 r_hash_xor(const ut8 *b, ut64 len);
|
||||||
ut16 r_hash_xorpair(const ut8 *a, ut64 len);
|
R_API ut16 r_hash_xorpair(const ut8 *a, ut64 len);
|
||||||
ut8 r_hash_parity(ut8 *buf, ut64 len);
|
R_API ut8 r_hash_parity(ut8 *buf, ut64 len);
|
||||||
ut8 r_hash_mod255(const ut8 *b, ut64 len);
|
R_API ut8 r_hash_mod255(const ut8 *b, ut64 len);
|
||||||
|
|
||||||
/* analysis */
|
/* analysis */
|
||||||
ut8 r_hash_hamdist(const ut8 *buf, ut64 len);
|
R_API ut8 r_hash_hamdist(const ut8 *buf, ut64 len);
|
||||||
double r_hash_entropy(const ut8 *data, ut64 len);
|
R_API double r_hash_entropy(const ut8 *data, ut64 len);
|
||||||
int r_hash_pcprint(ut8 *buffer, ut64 len);
|
R_API int r_hash_pcprint(ut8 *buffer, ut64 len);
|
||||||
|
|
||||||
/* hashing */
|
/* hashing */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ut32 state[4];
|
ut32 state[4];
|
||||||
ut32 count[2];
|
ut32 count[2];
|
||||||
ut8 buffer[64];
|
ut8 buffer[64];
|
||||||
} MD5_CTX;
|
} MD5_CTX;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned int H[5];
|
unsigned int H[5];
|
||||||
unsigned int W[80];
|
unsigned int W[80];
|
||||||
int lenW;
|
int lenW;
|
||||||
unsigned int sizeHi, sizeLo;
|
unsigned int sizeHi, sizeLo;
|
||||||
} SHA_CTX;
|
} SHA_CTX;
|
||||||
|
|
||||||
#define SHA256_BLOCK_LENGTH 64
|
#define SHA256_BLOCK_LENGTH 64
|
||||||
@ -82,17 +82,20 @@ struct r_hash_t {
|
|||||||
#define R_HASH_MOD255 16384
|
#define R_HASH_MOD255 16384
|
||||||
#define R_HASH_ALL 0xFFFF
|
#define R_HASH_ALL 0xFFFF
|
||||||
|
|
||||||
const ut8 *r_hash_state_md4(struct r_hash_t *ctx, const ut8 *input, ut32 len);
|
R_API const ut8 *r_hash_state_md4(struct r_hash_t *ctx, const ut8 *input, ut32 len);
|
||||||
const ut8 *r_hash_state_md5(struct r_hash_t *ctx, const ut8 *input, ut32 len);
|
R_API const ut8 *r_hash_state_md5(struct r_hash_t *ctx, const ut8 *input, ut32 len);
|
||||||
const ut8 *r_hash_state_sha1(struct r_hash_t *ctx, const ut8 *input, ut32 len);
|
R_API const ut8 *r_hash_state_sha1(struct r_hash_t *ctx, const ut8 *input, ut32 len);
|
||||||
const ut8 *r_hash_state_sha256(struct r_hash_t *ctx, const ut8 *input, ut32 len);
|
R_API const ut8 *r_hash_state_sha256(struct r_hash_t *ctx, const ut8 *input, ut32 len);
|
||||||
const ut8 *r_hash_state_sha384(struct r_hash_t *ctx, const ut8 *input, ut32 len);
|
R_API const ut8 *r_hash_state_sha384(struct r_hash_t *ctx, const ut8 *input, ut32 len);
|
||||||
const ut8 *r_hash_state_sha512(struct r_hash_t *ctx, const ut8 *input, ut32 len);
|
R_API const ut8 *r_hash_state_sha512(struct r_hash_t *ctx, const ut8 *input, ut32 len);
|
||||||
|
|
||||||
/* OO */
|
/* OO */
|
||||||
struct r_hash_t *r_hash_state_new(int init);
|
R_API struct r_hash_t *r_hash_state_new(int init);
|
||||||
void r_hash_init(struct r_hash_t *ptr, int flags);
|
R_API void r_hash_init(struct r_hash_t *ptr, int flags);
|
||||||
void r_hash_state_init(struct r_hash_t *ctx, int flags);
|
R_API void r_hash_state_init(struct r_hash_t *ctx, int flags);
|
||||||
void r_hash_state_free(struct r_hash_t *ctx);
|
R_API void r_hash_state_free(struct r_hash_t *ctx);
|
||||||
|
|
||||||
|
|
||||||
|
R_API ut64 r_hash_name_to_bits(const char *name);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -54,6 +54,12 @@ struct r_io_t {
|
|||||||
struct list_head desc;
|
struct list_head desc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct r_io_bind_t {
|
||||||
|
//int (*read_at)(void *user, );
|
||||||
|
int (*write_at)();
|
||||||
|
void *user;
|
||||||
|
};
|
||||||
|
|
||||||
//struct r_io_handle_fd_t {
|
//struct r_io_handle_fd_t {
|
||||||
// ... store io changes here
|
// ... store io changes here
|
||||||
//};
|
//};
|
||||||
@ -102,6 +108,7 @@ R_API int r_io_open(struct r_io_t *io, const char *file, int flags, int mode);
|
|||||||
R_API int r_io_open_as(struct r_io_t *io, const char *urihandler, const char *file, int flags, int mode);
|
R_API int r_io_open_as(struct r_io_t *io, const char *urihandler, const char *file, int flags, int mode);
|
||||||
R_API int r_io_redirect(struct r_io_t *io, const char *file);
|
R_API int r_io_redirect(struct r_io_t *io, const char *file);
|
||||||
R_API int r_io_set_fd(struct r_io_t *io, int fd);
|
R_API int r_io_set_fd(struct r_io_t *io, int fd);
|
||||||
|
R_API struct r_buf_t *r_io_read_buf(struct r_io_t *io, ut64 addr, int len);
|
||||||
R_API int r_io_read(struct r_io_t *io, ut8 *buf, int len);
|
R_API int r_io_read(struct r_io_t *io, ut8 *buf, int len);
|
||||||
R_API int r_io_read_at(struct r_io_t *io, ut64 addr, ut8 *buf, int len);
|
R_API int r_io_read_at(struct r_io_t *io, ut64 addr, ut8 *buf, int len);
|
||||||
R_API ut64 r_io_read_i(struct r_io_t *io, ut64 addr, int sz, int endian);
|
R_API ut64 r_io_read_i(struct r_io_t *io, ut64 addr, int sz, int endian);
|
||||||
@ -112,6 +119,9 @@ R_API int r_io_system(struct r_io_t *io, const char *cmd);
|
|||||||
R_API int r_io_close(struct r_io_t *io, int fd);
|
R_API int r_io_close(struct r_io_t *io, int fd);
|
||||||
R_API ut64 r_io_size(struct r_io_t *io, int fd);
|
R_API ut64 r_io_size(struct r_io_t *io, int fd);
|
||||||
|
|
||||||
|
/* io/bind.c */
|
||||||
|
R_API int r_io_bind(struct r_io_t *io, struct r_io_bind_t *bnd);
|
||||||
|
|
||||||
/* io/map.c */
|
/* io/map.c */
|
||||||
R_API void r_io_map_init(struct r_io_t *io);
|
R_API void r_io_map_init(struct r_io_t *io);
|
||||||
R_API int r_io_map_add(struct r_io_t *io, int fd, int flags, ut64 delta, ut64 offset, ut64 size);
|
R_API int r_io_map_add(struct r_io_t *io, int fd, int flags, ut64 delta, ut64 offset, ut64 size);
|
||||||
|
@ -6,6 +6,12 @@
|
|||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "iter.h"
|
#include "iter.h"
|
||||||
|
|
||||||
|
struct r_buf_t {
|
||||||
|
ut8 *buf;
|
||||||
|
int length;
|
||||||
|
ut64 base;
|
||||||
|
};
|
||||||
|
|
||||||
/* r_cache */
|
/* r_cache */
|
||||||
// TOTHINK: move into a separated library?
|
// TOTHINK: move into a separated library?
|
||||||
struct r_cache_item_t {
|
struct r_cache_item_t {
|
||||||
|
@ -9,7 +9,7 @@ STATIC_OBJS=
|
|||||||
include ../config.mk
|
include ../config.mk
|
||||||
include ${STATIC_IO_PLUGINS}
|
include ${STATIC_IO_PLUGINS}
|
||||||
STATIC_OBJS=$(subst ..,p/..,$(subst io_,p/io_,$(STATIC_OBJ)))
|
STATIC_OBJS=$(subst ..,p/..,$(subst io_,p/io_,$(STATIC_OBJ)))
|
||||||
OBJ=${STATIC_OBJS} io.o handle.o map.o section.o desc.o
|
OBJ=${STATIC_OBJS} io.o handle.o map.o section.o desc.o bind.o
|
||||||
|
|
||||||
pre:
|
pre:
|
||||||
@echo STATICOBJS: ${STATIC_OBJS}
|
@echo STATICOBJS: ${STATIC_OBJS}
|
||||||
|
9
libr/io/bind.c
Normal file
9
libr/io/bind.c
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/* radare - LGPL - Copyright 2008-2009 pancake<nopcode.org> */
|
||||||
|
|
||||||
|
#include <r_io.h>
|
||||||
|
|
||||||
|
R_API int r_io_bind(struct r_io_t *io, struct r_io_bind_t *bnd)
|
||||||
|
{
|
||||||
|
|
||||||
|
return R_TRUE;
|
||||||
|
}
|
16
libr/io/io.c
16
libr/io/io.c
@ -23,6 +23,22 @@ R_API struct r_io_t *r_io_new()
|
|||||||
return r_io_init(io);
|
return r_io_init(io);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
R_API struct r_buf_t *r_io_read_buf(struct r_io_t *io, ut64 addr, int len)
|
||||||
|
{
|
||||||
|
struct r_buf_t *b;
|
||||||
|
b = MALLOC_STRUCT(struct r_buf_t);
|
||||||
|
b->buf = malloc(len);
|
||||||
|
len = r_io_read_at(io, addr, b->buf, len);
|
||||||
|
if (len<0) len = 0;
|
||||||
|
b->length = len;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
R_API int r_io_write_buf(struct r_io_t *io, struct r_buf_t *b)
|
||||||
|
{
|
||||||
|
return r_io_write_at(io, b->base, b->buf, b->length);
|
||||||
|
}
|
||||||
|
|
||||||
R_API struct r_io_t *r_io_free(struct r_io_t *io)
|
R_API struct r_io_t *r_io_free(struct r_io_t *io)
|
||||||
{
|
{
|
||||||
/* TODO: properly free inner nfo */
|
/* TODO: properly free inner nfo */
|
||||||
|
@ -186,13 +186,15 @@ int r_macro_cmd_args(struct r_macro_t *mac, const char *ptr, const char *args, i
|
|||||||
{
|
{
|
||||||
int i,j;
|
int i,j;
|
||||||
char *cmd = alloca(strlen(ptr)+1024);
|
char *cmd = alloca(strlen(ptr)+1024);
|
||||||
|
char *arg = strdup(args);
|
||||||
cmd[0]='\0';
|
cmd[0]='\0';
|
||||||
|
|
||||||
// eprintf("call(%s)\n", ptr);
|
// eprintf("call(%s)\n", ptr);
|
||||||
for(i=j=0;ptr[j];i++,j++) {
|
for(i=j=0;ptr[j];i++,j++) {
|
||||||
if (ptr[j]=='$') {
|
if (ptr[j]=='$') {
|
||||||
if (ptr[j+1]>='0' && ptr[j+1]<='9') {
|
if (ptr[j+1]>='0' && ptr[j+1]<='9') {
|
||||||
const char *word = r_str_word_get0(args, ptr[j+1]-'0');
|
char *word = r_str_word_get0(arg, ptr[j+1]-'0');
|
||||||
|
// TODO: use r_str_concat ??
|
||||||
strcat(cmd, word);
|
strcat(cmd, word);
|
||||||
j++;
|
j++;
|
||||||
i = strlen(cmd)-1;
|
i = strlen(cmd)-1;
|
||||||
@ -214,9 +216,8 @@ int r_macro_cmd_args(struct r_macro_t *mac, const char *ptr, const char *args, i
|
|||||||
}
|
}
|
||||||
while(*cmd==' '||*cmd=='\t')
|
while(*cmd==' '||*cmd=='\t')
|
||||||
cmd = cmd + 1;
|
cmd = cmd + 1;
|
||||||
if (*cmd==')')
|
free(arg);
|
||||||
return 0;
|
return (*cmd==')')?0:mac->cmd(mac->user, cmd);
|
||||||
return mac->cmd(mac->user, cmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *r_macro_label_process(struct r_macro_t *mac, struct r_macro_label_t *labels, int *labels_n, char *ptr)
|
char *r_macro_label_process(struct r_macro_t *mac, struct r_macro_label_t *labels, int *labels_n, char *ptr)
|
||||||
|
@ -4,8 +4,8 @@ include ../../rules.mk
|
|||||||
|
|
||||||
all: test test-str test-regexp rafind2
|
all: test test-str test-regexp rafind2
|
||||||
|
|
||||||
rafind2:
|
rafind2: rafind2.o
|
||||||
${CC} -g -I ../../include rafind2.c ${LDFLAGS} -o rafind2
|
${CC} -g -I ../../include rafind2.o ${LDFLAGS} -o rafind2
|
||||||
|
|
||||||
test:
|
test:
|
||||||
${CC} -g -I ../../include test.c ${LDFLAGS} -o test
|
${CC} -g -I ../../include test.c ${LDFLAGS} -o test
|
||||||
|
@ -11,13 +11,14 @@ TODO:
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
#include <r_types.h>
|
#include <r_types.h>
|
||||||
|
#include <r_print.h>
|
||||||
#include <r_search.h>
|
#include <r_search.h>
|
||||||
#include <r_util.h>
|
#include <r_util.h>
|
||||||
|
#include <r_cons.h>
|
||||||
#include <r_lib.h>
|
#include <r_lib.h>
|
||||||
#include <r_io.h>
|
#include <r_io.h>
|
||||||
|
|
||||||
static struct r_io_t io;
|
static struct r_io_t io;
|
||||||
static int hexdump = 0;
|
|
||||||
static int fd = -1;
|
static int fd = -1;
|
||||||
static int rad = 0;
|
static int rad = 0;
|
||||||
struct r_search_t *rs;
|
struct r_search_t *rs;
|
||||||
@ -27,21 +28,22 @@ static char *mask = "";
|
|||||||
static int nonstop = 0;
|
static int nonstop = 0;
|
||||||
static int mode = R_SEARCH_KEYWORD;
|
static int mode = R_SEARCH_KEYWORD;
|
||||||
static ut64 cur = 0;
|
static ut64 cur = 0;
|
||||||
static char *buffer = NULL;
|
static ut8 *buffer = NULL;
|
||||||
static char *curfile = NULL;
|
static char *curfile = NULL;
|
||||||
static ut64 bsize = 4096;
|
static ut64 bsize = 4096;
|
||||||
static int hexstr = 0;
|
static int hexstr = 0;
|
||||||
|
static struct r_print_t *pr = NULL;
|
||||||
|
|
||||||
static int hit(struct r_search_kw_t *kw, void *user, ut64 addr)
|
static int hit(struct r_search_kw_t *kw, void *user, ut64 addr)
|
||||||
{
|
{
|
||||||
const ut8 *buf = (ut8*)user;
|
//const ut8 *buf = (ut8*)user;
|
||||||
int delta = addr-cur;
|
int delta = addr-cur;
|
||||||
if (rad) {
|
if (rad) {
|
||||||
printf("f hit%d_%d 0x%08llx ; %s\n", 0, kw->count, addr, curfile);
|
printf("f hit%d_%d 0x%08llx ; %s\n", 0, kw->count, addr, curfile);
|
||||||
} else {
|
} else {
|
||||||
printf("==> HIT %d AT 0x%llx ; %s\n", kw->count, addr, curfile);
|
printf("%s: %03d @ 0x%llx\n", curfile, kw->count, addr);
|
||||||
if (hexdump) {
|
if (pr) {
|
||||||
r_print_hexdump(addr, buffer+delta, 16, 78, R_TRUE);
|
r_print_hexdump(pr, addr, (ut8*)buffer+delta, 78, 16, R_TRUE);
|
||||||
r_cons_flush();
|
r_cons_flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,7 +69,8 @@ static int show_help(char *argv0, int line)
|
|||||||
|
|
||||||
int radiff_open(char *file)
|
int radiff_open(char *file)
|
||||||
{
|
{
|
||||||
int last = 0;
|
int ret, last = 0;
|
||||||
|
|
||||||
r_io_init(&io);
|
r_io_init(&io);
|
||||||
// TODO: add support for multiple files
|
// TODO: add support for multiple files
|
||||||
fd = r_io_open(&io, file, R_IO_READ, 0);
|
fd = r_io_open(&io, file, R_IO_READ, 0);
|
||||||
@ -90,14 +93,14 @@ int radiff_open(char *file)
|
|||||||
}
|
}
|
||||||
curfile = file;
|
curfile = file;
|
||||||
r_search_begin(rs);
|
r_search_begin(rs);
|
||||||
r_io_lseek(&io, fd, from, R_IO_SEEK_SET);
|
r_io_seek(&io, 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) {
|
for(cur=from; !last && cur<to;cur+=bsize) {
|
||||||
if ((cur+bsize)>to) {
|
if ((cur+bsize)>to) {
|
||||||
bsize = to-cur;
|
bsize = to-cur;
|
||||||
last=1;
|
last=1;
|
||||||
}
|
}
|
||||||
int ret = r_io_read(&io, fd, buffer, bsize);
|
ret = r_io_read(&io, buffer, bsize);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
if (nonstop) continue;
|
if (nonstop) continue;
|
||||||
// fprintf(stderr, "Error reading at 0x%08llx\n", cur);
|
// fprintf(stderr, "Error reading at 0x%08llx\n", cur);
|
||||||
@ -108,6 +111,7 @@ int radiff_open(char *file)
|
|||||||
r_search_update_i(rs, cur, buffer, bsize);
|
r_search_update_i(rs, cur, buffer, bsize);
|
||||||
}
|
}
|
||||||
rs = r_search_free(rs);
|
rs = r_search_free(rs);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
@ -149,7 +153,7 @@ int main(int argc, char **argv)
|
|||||||
to = r_num_math(NULL, optarg);
|
to = r_num_math(NULL, optarg);
|
||||||
break;
|
break;
|
||||||
case 'X':
|
case 'X':
|
||||||
hexdump = 1;
|
pr = r_print_new();
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
return show_help(argv[0], 0);
|
return show_help(argv[0], 0);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
NAME=r_util
|
NAME=r_util
|
||||||
OBJ=mem.o num.o str.o re.o hex.o file.o alloca.o float.o prof.o cache.o sys.o btree.o iter.o
|
OBJ=mem.o num.o str.o re.o hex.o file.o alloca.o float.o prof.o cache.o sys.o btree.o iter.o buf.o
|
||||||
|
|
||||||
#CFLAGS+=-O2
|
#CFLAGS+=-O2
|
||||||
#CC=gcc-4.1.1
|
#CC=gcc-4.1.1
|
||||||
|
55
libr/util/buf.c
Normal file
55
libr/util/buf.c
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
|
||||||
|
|
||||||
|
#include "r_types.h"
|
||||||
|
#include "r_util.h"
|
||||||
|
|
||||||
|
R_API struct r_buf_t *r_buf_init(struct r_buf_t *b)
|
||||||
|
{
|
||||||
|
b->length = 0;
|
||||||
|
b->base = 0LL;
|
||||||
|
b->buf = NULL;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
R_API struct r_buf_t *r_buf_new()
|
||||||
|
{
|
||||||
|
struct r_buf_t *b = MALLOC_STRUCT(struct r_buf_t);
|
||||||
|
return r_buf_init(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
R_API void r_buf_set_bytes(struct r_buf_t *b, ut8 *buf, int length)
|
||||||
|
{
|
||||||
|
free(b->buf);
|
||||||
|
b->buf = malloc(length);
|
||||||
|
memcpy(b->buf, buf, length);
|
||||||
|
b->length = length;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int r_buf_memcpy(struct r_buf_t *b, ut64 addr, ut8 *dst, ut8 *src, int len)
|
||||||
|
{
|
||||||
|
int end;
|
||||||
|
addr -= b->base;
|
||||||
|
if (addr > b->length)
|
||||||
|
return -1;
|
||||||
|
end = (int)(addr+len);
|
||||||
|
if (end > b->length)
|
||||||
|
len -= end-b->length;
|
||||||
|
memcpy(dst, src, len);
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
R_API int r_buf_read_at(struct r_buf_t *b, ut64 addr, ut8 *buf, int len)
|
||||||
|
{
|
||||||
|
return r_buf_memcpy(b, addr, buf, b->buf, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
R_API int r_buf_write_at(struct r_buf_t *b, ut64 addr, ut8 *buf, int len)
|
||||||
|
{
|
||||||
|
return r_buf_memcpy(b, addr, b->buf, buf, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
R_API void r_buf_free(struct r_buf_t *b)
|
||||||
|
{
|
||||||
|
free(b->buf);
|
||||||
|
free(b);
|
||||||
|
}
|
@ -154,6 +154,11 @@ R_API const char *r_str_chop_ro(const char *str)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
R_API char *r_str_new(char *str)
|
||||||
|
{
|
||||||
|
return strdup(str);
|
||||||
|
}
|
||||||
|
|
||||||
R_API char *r_str_chop(char *str)
|
R_API char *r_str_chop(char *str)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user