mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-23 13:19:54 +00:00
* Major refactoring patch
- Remove plugin prefixes - It was unnecessary complicated - Remove unused code - Some RAPIfication - Rename _set( methods into _use( - Simplify some string processing - r_parse is working again - Sync all those api changes in r_core - External static plugin lists moved to .c - Fix some cast-related segfaults in core * Review the r_search API - RAPIfication - Allow to pass NULL as binmask - Added TODO with some more ideas
This commit is contained in:
parent
dd2501b188
commit
9442317413
3
TODO
3
TODO
@ -6,6 +6,9 @@
|
||||
|
||||
----------------------------------------[ todo
|
||||
|
||||
* public delegate void RangeEachFunc(int i);
|
||||
* public void each(RangeEachFunc each_func) { ... }
|
||||
|
||||
** Add R_ASM_PLUGIN_PREFIX... in short
|
||||
** in a vapi file you can define a different constructor class Foo { bar Bar(); }..
|
||||
definition of Bar will override the previous Bar() class definition
|
||||
|
131
libr/asm/asm.c
131
libr/asm/asm.c
@ -13,69 +13,55 @@ static struct r_asm_handle_t *asm_static_plugins[] =
|
||||
|
||||
static int r_asm_pseudo_string(struct r_asm_aop_t *aop, char *input)
|
||||
{
|
||||
int len = 0;
|
||||
char *arg = strchr(input, ' ');
|
||||
if (arg && (len = strlen(arg+1))) {
|
||||
arg += 1; len += 1;
|
||||
r_hex_bin2str((ut8*)arg, len, aop->buf_hex);
|
||||
strncpy((char*)aop->buf, arg, R_ASM_BUFSIZE);
|
||||
}
|
||||
int len = strlen(input)+1;
|
||||
r_hex_bin2str((ut8*)input, len, aop->buf_hex);
|
||||
strncpy((char*)aop->buf, input, R_ASM_BUFSIZE);
|
||||
return len;
|
||||
}
|
||||
|
||||
static int r_asm_pseudo_arch(struct r_asm_t *a, char *input)
|
||||
// XXX WTF? THIS MUST BE INLINED
|
||||
// TODO: use R_TRUE/R_FALSE HERE!!1
|
||||
static inline int r_asm_pseudo_arch(struct r_asm_t *a, char *input)
|
||||
{
|
||||
char *arg = strchr(input, ' '), str[R_ASM_BUFSIZE];
|
||||
if (arg) {
|
||||
sprintf(str, "asm_%s", arg+1);
|
||||
if (!r_asm_set(a, str)) {
|
||||
fprintf(stderr, "Error: Unknown plugin\n");
|
||||
return -1;
|
||||
}
|
||||
// KINDA INNECESSARY ???
|
||||
if (!r_asm_use(a, input)) {
|
||||
fprintf(stderr, "Error: Unknown plugin\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int r_asm_pseudo_bits(struct r_asm_t *a, char *input)
|
||||
static inline int r_asm_pseudo_bits(struct r_asm_t *a, char *input)
|
||||
{
|
||||
char *arg = strchr(input, ' ');
|
||||
if (arg)
|
||||
if (!(r_asm_set_bits(a, r_num_math(NULL, arg+1)))) {
|
||||
fprintf(stderr, "Error: Unsupported bits value\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int r_asm_pseudo_org(struct r_asm_t *a, char *input)
|
||||
{
|
||||
char *arg = strchr(input, ' ');
|
||||
if (arg)
|
||||
r_asm_set_pc(a, r_num_math(NULL, arg+1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int r_asm_pseudo_byte(struct r_asm_aop_t *aop, char *input)
|
||||
{
|
||||
int len = 0;
|
||||
char *arg = strchr(input, ' ');
|
||||
if (arg) {
|
||||
arg += 1;
|
||||
len = r_hex_str2bin(arg, aop->buf);
|
||||
strncpy(aop->buf_hex, r_str_trim(arg), R_ASM_BUFSIZE);
|
||||
if (!(r_asm_set_bits(a, r_num_math(NULL, input)))) {
|
||||
fprintf(stderr, "Error: Unsupported bits value\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int r_asm_pseudo_org(struct r_asm_t *a, char *input)
|
||||
{
|
||||
r_asm_set_pc(a, r_num_math(NULL, input));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int r_asm_pseudo_byte(struct r_asm_aop_t *aop, char *input)
|
||||
{
|
||||
int len = r_hex_str2bin(input, aop->buf);
|
||||
strncpy(aop->buf_hex, r_str_trim(input), R_ASM_BUFSIZE);
|
||||
return len;
|
||||
}
|
||||
|
||||
R_API struct r_asm_t *r_asm_new()
|
||||
{
|
||||
struct r_asm_t *a = MALLOC_STRUCT(struct r_asm_t);
|
||||
r_asm_init(a);
|
||||
return a;
|
||||
return r_asm_init(a);
|
||||
}
|
||||
|
||||
R_API void r_asm_free(struct r_asm_t *a)
|
||||
{
|
||||
// TOOD: free plugins and so on
|
||||
free(a);
|
||||
}
|
||||
|
||||
@ -97,19 +83,21 @@ R_API const char *r_asm_fastcall(struct r_asm_t *a, int idx, int num)
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API int r_asm_init(struct r_asm_t *a)
|
||||
R_API struct r_asm_t *r_asm_init(struct r_asm_t *a)
|
||||
{
|
||||
int i;
|
||||
a->user = NULL;
|
||||
a->cur = NULL;
|
||||
a->bits = 32;
|
||||
a->big_endian = 0;
|
||||
a->syntax = R_ASM_SYN_INTEL;
|
||||
a->pc = 0;
|
||||
INIT_LIST_HEAD(&a->asms);
|
||||
for(i=0;asm_static_plugins[i];i++)
|
||||
r_asm_add(a, asm_static_plugins[i]);
|
||||
return R_TRUE;
|
||||
if (a) {
|
||||
a->user = NULL;
|
||||
a->cur = NULL;
|
||||
a->bits = 32;
|
||||
a->big_endian = 0;
|
||||
a->syntax = R_ASM_SYN_INTEL;
|
||||
a->pc = 0;
|
||||
INIT_LIST_HEAD(&a->asms);
|
||||
for(i=0;asm_static_plugins[i];i++)
|
||||
r_asm_add(a, asm_static_plugins[i]);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
R_API void r_asm_set_user_ptr(struct r_asm_t *a, void *user)
|
||||
@ -120,6 +108,7 @@ R_API void r_asm_set_user_ptr(struct r_asm_t *a, void *user)
|
||||
R_API int r_asm_add(struct r_asm_t *a, struct r_asm_handle_t *foo)
|
||||
{
|
||||
struct list_head *pos;
|
||||
// TODO: cache foo->name length and use memcmp instead of strcmp
|
||||
if (foo->init)
|
||||
foo->init(a->user);
|
||||
/* avoid dupped plugins */
|
||||
@ -144,12 +133,13 @@ R_API int r_asm_list(struct r_asm_t *a)
|
||||
struct list_head *pos;
|
||||
list_for_each_prev(pos, &a->asms) {
|
||||
struct r_asm_handle_t *h = list_entry(pos, struct r_asm_handle_t, list);
|
||||
printf(" %s: %s\n", h->name, h->desc);
|
||||
printf("asm %s\t %s\n", h->name, h->desc);
|
||||
}
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
R_API int r_asm_set(struct r_asm_t *a, const char *name)
|
||||
// TODO: this can be optimized using r_str_hash()
|
||||
R_API int r_asm_use(struct r_asm_t *a, const char *name)
|
||||
{
|
||||
struct list_head *pos;
|
||||
list_for_each_prev(pos, &a->asms) {
|
||||
@ -182,7 +172,6 @@ static int has_bits(struct r_asm_handle_t *h, int bits)
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
|
||||
R_API int r_asm_set_bits(struct r_asm_t *a, int bits)
|
||||
{
|
||||
if (has_bits(a->cur, bits)) {
|
||||
@ -328,7 +317,7 @@ R_API int r_asm_massemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf)
|
||||
return 0;
|
||||
}
|
||||
snprintf(buf_token2, R_ASM_BUFSIZE, "%s0x%llx%s",
|
||||
ptr_start, label_offset, ptr+strlen(label_name));
|
||||
ptr_start, label_offset, ptr+strlen(label_name));
|
||||
strncpy(buf_token, buf_token2, R_ASM_BUFSIZE);
|
||||
ptr_start = buf_token;
|
||||
}
|
||||
@ -337,21 +326,19 @@ R_API int r_asm_massemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf)
|
||||
}
|
||||
}
|
||||
if ((ptr = strchr(ptr_start, '.'))) { /* Pseudo */
|
||||
if (!memcmp(ptr, ".string", 7))
|
||||
ret = r_asm_pseudo_string(aop, ptr);
|
||||
else if (!memcmp(ptr, ".arch", 5))
|
||||
ret = r_asm_pseudo_arch(a, ptr);
|
||||
else if (!memcmp(ptr, ".bits", 5))
|
||||
ret = r_asm_pseudo_bits(a, ptr);
|
||||
else if (!memcmp(ptr, ".byte", 5))
|
||||
ret = r_asm_pseudo_byte(aop, ptr);
|
||||
else if (!memcmp(ptr, ".org", 4))
|
||||
ret = r_asm_pseudo_org(a, ptr);
|
||||
if (!memcmp(ptr, ".string ", 8))
|
||||
ret = r_asm_pseudo_string(aop, ptr+8);
|
||||
else if (!memcmp(ptr, ".arch ", 6))
|
||||
ret = r_asm_pseudo_arch(a, ptr+6);
|
||||
else if (!memcmp(ptr, ".bits ", 6))
|
||||
ret = r_asm_pseudo_bits(a, ptr+6);
|
||||
else if (!memcmp(ptr, ".byte ", 6))
|
||||
ret = r_asm_pseudo_byte(aop, ptr+6);
|
||||
else if (!memcmp(ptr, ".org ", 5))
|
||||
ret = r_asm_pseudo_org(a, ptr+5);
|
||||
else return 0;
|
||||
if (!ret)
|
||||
continue;
|
||||
else if (ret < 0)
|
||||
return 0;
|
||||
if (!ret) continue;
|
||||
else if (ret < 0) return 0;
|
||||
} else { /* Instruction */
|
||||
ret = r_asm_assemble(a, aop, ptr_start);
|
||||
if (!ret)
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
#include "dis-asm.h"
|
||||
|
||||
|
||||
static int arm_mode = 0;
|
||||
static unsigned long Offset = 0;
|
||||
static char *buf_global = NULL;
|
||||
@ -88,7 +87,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut6
|
||||
}
|
||||
|
||||
struct r_asm_handle_t r_asm_plugin_arm = {
|
||||
.name = "asm_arm",
|
||||
.name = "arm",
|
||||
.arch = "arm",
|
||||
.bits = (int[]){ 16, 32, 0 },
|
||||
.desc = "ARM disassembly plugin",
|
||||
|
@ -65,7 +65,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut6
|
||||
}
|
||||
|
||||
struct r_asm_handle_t r_asm_plugin_bf = {
|
||||
.name = "asm_bf",
|
||||
.name = "bf",
|
||||
.arch = "brainfuck",
|
||||
.bits = (int[]){ 8, 0 },
|
||||
.desc = "BF disassembly plugin",
|
||||
|
@ -13,14 +13,12 @@
|
||||
static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut64 len)
|
||||
{
|
||||
arch_csr_disasm(aop->buf_asm, buf, a->pc);
|
||||
aop->inst_len = 2;
|
||||
aop->disasm_obj = NULL;
|
||||
|
||||
return aop->inst_len;
|
||||
return (aop->inst_len=2);
|
||||
}
|
||||
|
||||
struct r_asm_handle_t r_asm_plugin_csr = {
|
||||
.name = "asm_csr",
|
||||
.name = "csr",
|
||||
.arch = "csr",
|
||||
.bits = (int[]){ 16, 0 },
|
||||
.desc = "CSR disassembly plugin",
|
||||
|
@ -13,7 +13,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut6
|
||||
}
|
||||
|
||||
struct r_asm_handle_t r_asm_plugin_dummy = {
|
||||
.name = "asm_dummy",
|
||||
.name = "dummy",
|
||||
.arch = "none",
|
||||
.bits = (int[]){ 0 },
|
||||
.desc = "dummy disassembly plugin",
|
||||
|
@ -25,8 +25,8 @@ static int assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf)
|
||||
}
|
||||
|
||||
struct r_asm_handle_t r_asm_plugin_java = {
|
||||
.name = "asm_java",
|
||||
.desc = "java disassembly plugin",
|
||||
.name = "java",
|
||||
.desc = "Java CLASS assembler/disassembler",
|
||||
.arch = "java",
|
||||
.bits = (int[]){ 8, 0 },
|
||||
.init = NULL,
|
||||
|
@ -34,7 +34,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut6
|
||||
}
|
||||
|
||||
struct r_asm_handle_t r_asm_plugin_m68k = {
|
||||
.name = "asm_m68k",
|
||||
.name = "m68k",
|
||||
.arch = "m68k",
|
||||
.bits = (int[]){ 32, 0 },
|
||||
.desc = "M68K disassembly plugin",
|
||||
|
@ -93,7 +93,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut6
|
||||
}
|
||||
|
||||
struct r_asm_handle_t r_asm_plugin_mips = {
|
||||
.name = "asm_mips",
|
||||
.name = "mips",
|
||||
.arch = "mips",
|
||||
.bits = (int[]){ 32, 0 },
|
||||
.desc = "MIPS disassembly plugin",
|
||||
|
@ -34,7 +34,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut6
|
||||
}
|
||||
|
||||
struct r_asm_handle_t r_asm_plugin_ppc = {
|
||||
.name = "asm_ppc",
|
||||
.name = "ppc",
|
||||
.arch = "powepc",
|
||||
.bits = (int[]){ 32, 0 },
|
||||
.desc = "PPC disassembly plugin",
|
||||
|
@ -4,10 +4,8 @@
|
||||
#include <r_util.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_asm.h>
|
||||
|
||||
#include <psosvm/vmas/vmas.h>
|
||||
|
||||
|
||||
static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut64 len)
|
||||
{
|
||||
psosvmasm_init();
|
||||
@ -25,7 +23,7 @@ static int assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf)
|
||||
}
|
||||
|
||||
struct r_asm_handle_t r_asm_plugin_psosvm = {
|
||||
.name = "asm_psosvm",
|
||||
.name = "psosvm",
|
||||
.desc = "PSOS-VM disassembly plugin",
|
||||
.arch = "psosvm",
|
||||
.bits = (int[]){ 8, 16, 0 },
|
||||
|
@ -87,7 +87,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut6
|
||||
}
|
||||
|
||||
struct r_asm_handle_t r_asm_plugin_sparc = {
|
||||
.name = "asm_sparc",
|
||||
.name = "sparc",
|
||||
.arch = "sparc",
|
||||
.bits = (int[]){ 32, 0 },
|
||||
.desc = "SPARC disassembly plugin",
|
||||
|
@ -34,7 +34,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut6
|
||||
}
|
||||
|
||||
struct r_asm_handle_t r_asm_plugin_x86 = {
|
||||
.name = "asm_x86",
|
||||
.name = "x86",
|
||||
.desc = "X86 disassembly plugin",
|
||||
.arch = "x86",
|
||||
.bits = (int[]){ 16, 32, 64, 0 },
|
||||
|
@ -9,10 +9,8 @@
|
||||
#include <r_asm.h>
|
||||
|
||||
#include "x86/bea/BeaEngine.h"
|
||||
|
||||
#include "fastcall_x86.h"
|
||||
|
||||
|
||||
static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut64 len)
|
||||
{
|
||||
static DISASM disasm_obj;
|
||||
@ -35,7 +33,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut6
|
||||
}
|
||||
|
||||
struct r_asm_handle_t r_asm_plugin_x86_bea = {
|
||||
.name = "asm_x86_bea",
|
||||
.name = "x86.bea",
|
||||
.desc = "X86 disassembly plugin (bea engine)",
|
||||
.arch = "x86",
|
||||
.bits = (int[]){ 32, 64, 0 }, /* also 16 ? */
|
||||
|
@ -30,7 +30,7 @@ static int assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf)
|
||||
}
|
||||
|
||||
struct r_asm_handle_t r_asm_plugin_x86_nasm = {
|
||||
.name = "asm_x86_nasm",
|
||||
.name = "x86.nasm",
|
||||
.desc = "X86 nasm assembler plugin",
|
||||
.arch = "x86",
|
||||
.bits = (int[]){ 16, 32, 64, 0 },
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <r_asm.h>
|
||||
|
||||
#include "fastcall_x86.h"
|
||||
|
||||
#include "x86/ollyasm/disasm.h"
|
||||
|
||||
|
||||
@ -54,7 +53,7 @@ static int assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf)
|
||||
|
||||
|
||||
struct r_asm_handle_t r_asm_plugin_x86_olly = {
|
||||
.name = "asm_x86_olly",
|
||||
.name = "x86.olly",
|
||||
.desc = "X86 disassembly plugin (olly engine)",
|
||||
.arch = "x86",
|
||||
.bits = (int[]){ 32, 0 },
|
||||
|
@ -14,15 +14,14 @@ int main(int argc, char **argv)
|
||||
|
||||
printf("Supported plugins:\n");
|
||||
r_asm_list(a);
|
||||
r_asm_set(a, "asm_x86_nasm");
|
||||
r_asm_use(a, "x86.nasm");
|
||||
|
||||
printf("Fastcall args for %d\n", atoi(argv[1]));
|
||||
|
||||
printf("Using plugin: %s\n", a->cur->name);
|
||||
do {
|
||||
arg = r_asm_fastcall(a, i++, num);
|
||||
if (arg)
|
||||
printf("%s\n", arg);
|
||||
if (arg) printf("%s\n", arg);
|
||||
} while(arg);
|
||||
return 0;
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ static int rasm_asm(char *buf, ut64 offset, ut64 len, int bin)
|
||||
|
||||
#if 0
|
||||
/* TODO: Arch, syntax... */
|
||||
if (!r_asm_set(&a, "asm_x86_olly")) {
|
||||
if (!r_asm_use(&a, "x86.olly")) {
|
||||
fprintf(stderr, "Error: Cannot find asm_x86 plugin\n");
|
||||
return 1;
|
||||
}
|
||||
@ -123,7 +123,7 @@ int main(int argc, char *argv[])
|
||||
if (argc<2)
|
||||
return rasm_show_help();
|
||||
|
||||
r_asm_set(&a, "asm_x86");
|
||||
r_asm_use(&a, "x86");
|
||||
while ((c = getopt(argc, argv, "a:b:s:do:Bl:hL")) != -1)
|
||||
{
|
||||
switch( c ) {
|
||||
@ -162,18 +162,14 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (arch) {
|
||||
char *str = malloc(strlen(arch)+10);
|
||||
sprintf(str, "asm_%s", arch);
|
||||
if (!r_asm_set(&a, str)) {
|
||||
if (!r_asm_use(&a, arch)) {
|
||||
fprintf(stderr, "Error: Unknown plugin\n");
|
||||
free (str);
|
||||
return 0;
|
||||
}
|
||||
free (str);
|
||||
if (!strcmp(arch, "bf"))
|
||||
ascii = 1;
|
||||
} else if (!r_asm_set(&a, "asm_x86")) {
|
||||
fprintf(stderr, "Error: Cannot find asm_x86 plugin\n");
|
||||
ascii = 1; // uh?
|
||||
} else if (!r_asm_use(&a, "x86")) {
|
||||
fprintf(stderr, "Error: Cannot find asm.x86 plugin\n");
|
||||
return 0;
|
||||
}
|
||||
if (!r_asm_set_bits(&a, bits))
|
||||
|
@ -16,6 +16,14 @@
|
||||
#include <r_bin.h>
|
||||
#include "../config.h"
|
||||
|
||||
/* plugin pointers */
|
||||
extern struct r_bin_handle_t r_bin_plugin_elf;
|
||||
extern struct r_bin_handle_t r_bin_plugin_elf64;
|
||||
extern struct r_bin_handle_t r_bin_plugin_pe;
|
||||
extern struct r_bin_handle_t r_bin_plugin_pe64;
|
||||
extern struct r_bin_handle_t r_bin_plugin_java;
|
||||
extern struct r_bin_handle_t r_bin_plugin_dummy;
|
||||
|
||||
static struct r_bin_handle_t *bin_static_plugins[] =
|
||||
{ R_BIN_STATIC_PLUGINS };
|
||||
|
||||
@ -137,25 +145,24 @@ R_API int r_bin_add(struct r_bin_t *bin, struct r_bin_handle_t *foo)
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
int r_bin_list(struct r_bin_t *bin)
|
||||
R_API int r_bin_list(struct r_bin_t *bin)
|
||||
{
|
||||
struct list_head *pos;
|
||||
list_for_each_prev(pos, &bin->bins) {
|
||||
struct r_bin_handle_t *h = list_entry(pos, struct r_bin_handle_t, list);
|
||||
printf(" %s: %s\n", h->name, h->desc);
|
||||
printf("bin %s\t%s\n", h->name, h->desc);
|
||||
}
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
int r_bin_open(struct r_bin_t *bin, const char *file, int rw, char *plugin_name)
|
||||
R_API int r_bin_open(struct r_bin_t *bin, const char *file, int rw, char *plugin_name)
|
||||
{
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
struct list_head *pos;
|
||||
|
||||
if (bin == NULL || file == NULL)
|
||||
return -1;
|
||||
bin->file = file;
|
||||
bin->rw = rw;
|
||||
|
||||
struct list_head *pos;
|
||||
list_for_each_prev(pos, &bin->bins) {
|
||||
struct r_bin_handle_t *h = list_entry(pos, struct r_bin_handle_t, list);
|
||||
if ((plugin_name && !strcmp(h->name, plugin_name)) ||
|
||||
@ -164,12 +171,12 @@ int r_bin_open(struct r_bin_t *bin, const char *file, int rw, char *plugin_name)
|
||||
}
|
||||
if (bin->cur && bin->cur->open)
|
||||
return bin->cur->open(bin);
|
||||
if (plugin_name && !strcmp(plugin_name, "bin_dummy"))
|
||||
if (plugin_name && !strcmp(plugin_name, "dummy"))
|
||||
return -1;
|
||||
return r_bin_open(bin, file, rw, "bin_dummy");
|
||||
return r_bin_open(bin, file, rw, "dummy");
|
||||
}
|
||||
|
||||
int r_bin_close(struct r_bin_t *bin)
|
||||
R_API int r_bin_close(struct r_bin_t *bin)
|
||||
{
|
||||
if (bin->cur && bin->cur->close)
|
||||
return bin->cur->close(bin);
|
||||
@ -232,7 +239,8 @@ R_API struct r_bin_field_t* r_bin_get_fields(struct r_bin_t *bin)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API ut64 r_bin_get_section_offset(struct r_bin_t *bin, char *name)
|
||||
// why not just return a single instance of the Section struct?
|
||||
R_API ut64 r_bin_get_section_offset(struct r_bin_t *bin, const char *name)
|
||||
{
|
||||
struct r_bin_section_t *sections;
|
||||
ut64 ret = UT64_MAX;
|
||||
@ -250,7 +258,7 @@ R_API ut64 r_bin_get_section_offset(struct r_bin_t *bin, char *name)
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API ut64 r_bin_get_section_rva(struct r_bin_t *bin, char *name)
|
||||
R_API ut64 r_bin_get_section_rva(struct r_bin_t *bin, const char *name)
|
||||
{
|
||||
struct r_bin_section_t *sections;
|
||||
ut64 ret = UT64_MAX;
|
||||
@ -269,7 +277,7 @@ R_API ut64 r_bin_get_section_rva(struct r_bin_t *bin, char *name)
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API ut64 r_bin_get_section_size(struct r_bin_t *bin, char *name)
|
||||
R_API ut64 r_bin_get_section_size(struct r_bin_t *bin, const char *name)
|
||||
{
|
||||
struct r_bin_section_t *sections;
|
||||
ut64 ret = UT64_MAX;
|
||||
|
@ -19,7 +19,7 @@ static int bclose(struct r_bin_t *bin)
|
||||
}
|
||||
|
||||
struct r_bin_handle_t r_bin_plugin_dummy = {
|
||||
.name = "bin_dummy",
|
||||
.name = "dummy",
|
||||
.desc = "dummy bin plugin",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
|
@ -14,7 +14,6 @@ static int bopen(struct r_bin_t *bin)
|
||||
free(bin->bin_obj);
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
return bin->fd;
|
||||
}
|
||||
|
||||
@ -30,13 +29,12 @@ static ut64 baddr(struct r_bin_t *bin)
|
||||
|
||||
static struct r_bin_entry_t* entry(struct r_bin_t *bin)
|
||||
{
|
||||
struct r_bin_entry_t *ret = NULL;
|
||||
|
||||
if((ret = MALLOC_STRUCT(struct r_bin_entry_t)) == NULL)
|
||||
return NULL;
|
||||
memset(ret, '\0', sizeof(struct r_bin_entry_t));
|
||||
|
||||
ret->offset = ret->rva = Elf_(r_bin_elf_get_entry_offset)(bin->bin_obj);
|
||||
struct r_bin_entry_t *ret = MALLOC_STRUCT(struct r_bin_entry_t);
|
||||
if (ret) {
|
||||
memset(ret, '\0', sizeof(struct r_bin_entry_t));
|
||||
ret->offset = ret->rva = \
|
||||
Elf_(r_bin_elf_get_entry_offset)(bin->bin_obj);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -44,14 +42,14 @@ static struct r_bin_section_t* sections(struct r_bin_t *bin)
|
||||
{
|
||||
struct r_bin_section_t *ret = NULL;
|
||||
struct r_bin_elf_section_t *section = NULL;
|
||||
int i, sections_count;
|
||||
int i, count;
|
||||
|
||||
section = Elf_(r_bin_elf_get_sections)(bin->bin_obj);
|
||||
for (sections_count = 0; section && !section[sections_count].last; sections_count++);
|
||||
if ((ret = malloc((sections_count + 1) * sizeof(struct r_bin_section_t))) == NULL)
|
||||
for (count = 0; section && !section[count].last; count++);
|
||||
if ((ret = MALLOC_STRUCTS(struct r_bin_section_t, count+1))==NULL)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < sections_count; i++) {
|
||||
for (i = 0; i < count; i++) {
|
||||
strncpy(ret[i].name, (char*)section[i].name, R_BIN_SIZEOF_STRINGS);
|
||||
ret[i].size = section[i].size;
|
||||
ret[i].vsize = section[i].size;
|
||||
@ -67,9 +65,7 @@ static struct r_bin_section_t* sections(struct r_bin_t *bin)
|
||||
ret[i].last = 0;
|
||||
}
|
||||
ret[i].last = 1;
|
||||
|
||||
free(section);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -133,53 +129,50 @@ static struct r_bin_import_t* imports(struct r_bin_t *bin)
|
||||
static struct r_bin_info_t* info(struct r_bin_t *bin)
|
||||
{
|
||||
struct r_bin_info_t *ret = NULL;
|
||||
char *string;
|
||||
char *str;
|
||||
|
||||
if((ret = malloc(sizeof(struct r_bin_info_t))) == NULL)
|
||||
return NULL;
|
||||
memset(ret, '\0', sizeof(struct r_bin_info_t));
|
||||
|
||||
|
||||
if ((string = Elf_(r_bin_elf_get_file_type)(bin->bin_obj)) == NULL)
|
||||
if ((str = Elf_(r_bin_elf_get_file_type)(bin->bin_obj)) == NULL)
|
||||
return NULL;
|
||||
strncpy(ret->type, string, R_BIN_SIZEOF_STRINGS);
|
||||
free(string);
|
||||
strncpy(ret->type, str, R_BIN_SIZEOF_STRINGS);
|
||||
free(str);
|
||||
|
||||
if ((string = Elf_(r_bin_elf_get_elf_class)(bin->bin_obj)) == NULL)
|
||||
if ((str = Elf_(r_bin_elf_get_elf_class)(bin->bin_obj)) == NULL)
|
||||
return NULL;
|
||||
strncpy(ret->class, string, R_BIN_SIZEOF_STRINGS);
|
||||
free(string);
|
||||
strncpy(ret->class, str, R_BIN_SIZEOF_STRINGS);
|
||||
free(str);
|
||||
|
||||
if ((string = Elf_(r_bin_elf_get_osabi_name)(bin->bin_obj)) == NULL)
|
||||
if ((str = Elf_(r_bin_elf_get_osabi_name)(bin->bin_obj)) == NULL)
|
||||
return NULL;
|
||||
strncpy(ret->os, string, R_BIN_SIZEOF_STRINGS);
|
||||
free(string);
|
||||
strncpy(ret->os, str, R_BIN_SIZEOF_STRINGS);
|
||||
free(str);
|
||||
|
||||
if ((string = Elf_(r_bin_elf_get_osabi_name)(bin->bin_obj)) == NULL)
|
||||
if ((str = Elf_(r_bin_elf_get_osabi_name)(bin->bin_obj)) == NULL)
|
||||
return NULL;
|
||||
strncpy(ret->subsystem, string, R_BIN_SIZEOF_STRINGS);
|
||||
free(string);
|
||||
strncpy(ret->subsystem, str, R_BIN_SIZEOF_STRINGS);
|
||||
free(str);
|
||||
|
||||
if ((string = Elf_(r_bin_elf_get_machine_name)(bin->bin_obj)) == NULL)
|
||||
if ((str = Elf_(r_bin_elf_get_machine_name)(bin->bin_obj)) == NULL)
|
||||
return NULL;
|
||||
strncpy(ret->machine, string, R_BIN_SIZEOF_STRINGS);
|
||||
free(string);
|
||||
strncpy(ret->machine, str, R_BIN_SIZEOF_STRINGS);
|
||||
free(str);
|
||||
|
||||
if ((string = Elf_(r_bin_elf_get_arch)(bin->bin_obj)) == NULL)
|
||||
if ((str = Elf_(r_bin_elf_get_arch)(bin->bin_obj)) == NULL)
|
||||
return NULL;
|
||||
strncpy(ret->arch, string, R_BIN_SIZEOF_STRINGS);
|
||||
free(string);
|
||||
strncpy(ret->arch, str, R_BIN_SIZEOF_STRINGS);
|
||||
free(str);
|
||||
|
||||
strncpy(ret->rclass, "elf", R_BIN_SIZEOF_STRINGS);
|
||||
ret->big_endian=Elf_(r_bin_elf_is_big_endian)(bin->bin_obj);
|
||||
ret->dbg_info = 0;
|
||||
if (Elf_(r_bin_elf_get_stripped)(bin->bin_obj)) {
|
||||
ret->dbg_info |= 0x01;
|
||||
} else {
|
||||
if (!Elf_(r_bin_elf_get_stripped)(bin->bin_obj)) {
|
||||
ret->dbg_info |= 0x04;
|
||||
ret->dbg_info |= 0x08;
|
||||
ret->dbg_info |= 0x10;
|
||||
}
|
||||
} else ret->dbg_info |= 0x01;
|
||||
if (Elf_(r_bin_elf_get_static)(bin->bin_obj))
|
||||
ret->dbg_info |= 0x02;
|
||||
return ret;
|
||||
@ -189,22 +182,20 @@ static struct r_bin_field_t* fields(struct r_bin_t *bin)
|
||||
{
|
||||
struct r_bin_field_t *ret = NULL;
|
||||
struct r_bin_elf_field_t *field = NULL;
|
||||
int i, fields_count;
|
||||
int i, count;
|
||||
|
||||
field = Elf_(r_bin_elf_get_fields)(bin->bin_obj);
|
||||
for (fields_count = 0; field && !field[fields_count].last; fields_count++);
|
||||
if ((ret = malloc((fields_count + 1) * sizeof(struct r_bin_field_t))) == NULL)
|
||||
for (count = 0; field && !field[count].last; count++);
|
||||
if ((ret = malloc((count + 1) * sizeof(struct r_bin_field_t))) == NULL)
|
||||
return NULL;
|
||||
for (i = 0; i < fields_count; i++) {
|
||||
for (i = 0; i < count; i++) {
|
||||
strncpy(ret[i].name, field[i].name, R_BIN_SIZEOF_STRINGS);
|
||||
ret[i].rva = field[i].offset;
|
||||
ret[i].offset = field[i].offset;
|
||||
ret[i].last = 0;
|
||||
}
|
||||
ret[i].last = 1;
|
||||
|
||||
free(field);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -226,8 +217,8 @@ static int check(struct r_bin_t *bin)
|
||||
}
|
||||
|
||||
struct r_bin_handle_t r_bin_plugin_elf = {
|
||||
.name = "bin_elf",
|
||||
.desc = "elf bin plugin",
|
||||
.name = "elf",
|
||||
.desc = "ELF format r_bin plugin",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.open = &bopen,
|
||||
|
@ -21,7 +21,7 @@ static int check(struct r_bin_t *bin)
|
||||
}
|
||||
|
||||
struct r_bin_handle_t r_bin_plugin_elf64 = {
|
||||
.name = "bin_elf64",
|
||||
.name = "elf64",
|
||||
.desc = "elf64 bin plugin",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
|
@ -145,7 +145,7 @@ static int check(struct r_bin_t *bin)
|
||||
}
|
||||
|
||||
struct r_bin_handle_t r_bin_plugin_java = {
|
||||
.name = "bin_java",
|
||||
.name = "java",
|
||||
.desc = "java bin plugin",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
|
@ -1,3 +1,9 @@
|
||||
/* radare - GPL3 - Copyright 2009 pancake<@nopcode.org> */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_bin.h>
|
||||
|
||||
static int bopen(struct r_bin_t *bin)
|
||||
{
|
||||
}
|
||||
@ -28,7 +34,7 @@ static int check(struct r_bin_t *bin)
|
||||
}
|
||||
|
||||
struct r_bin_handle_t r_bin_plugin_mach0 = {
|
||||
.name = "bin_mach0",
|
||||
.name = "mach0",
|
||||
.desc = "mach0 bin plugin",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
|
@ -209,8 +209,8 @@ static int check(struct r_bin_t *bin)
|
||||
}
|
||||
|
||||
struct r_bin_handle_t r_bin_plugin_pe = {
|
||||
.name = "bin_pe",
|
||||
.desc = "pe bin plugin",
|
||||
.name = "pe",
|
||||
.desc = "PE bin plugin",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.open = &bopen,
|
||||
|
@ -22,8 +22,8 @@ static int check(struct r_bin_t *bin)
|
||||
}
|
||||
|
||||
struct r_bin_handle_t r_bin_plugin_pe64 = {
|
||||
.name = "bin_pe64",
|
||||
.desc = "pe64 (pe32+) bin plugin",
|
||||
.name = "pe64",
|
||||
.desc = "PE64 (PE32+) bin plugin",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.open = &bopen,
|
||||
|
@ -29,7 +29,9 @@
|
||||
|
||||
static struct r_lib_t l;
|
||||
static struct r_bin_t bin;
|
||||
static int verbose = 0, rad = 0, rw = 0;
|
||||
static int verbose = 0;
|
||||
static int rad = R_FALSE;
|
||||
static int rw = R_FALSE;
|
||||
static char* file;
|
||||
|
||||
static int rabin_show_help()
|
||||
@ -48,7 +50,6 @@ static int rabin_show_help()
|
||||
" -w Open file in rw mode\n"
|
||||
" -L List supported bin plugins\n"
|
||||
" -h This help\n");
|
||||
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
@ -110,7 +111,6 @@ static int rabin_show_imports()
|
||||
if (!rad) printf("\n%i imports\n", i);
|
||||
|
||||
free(imports);
|
||||
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
@ -170,8 +170,7 @@ static int rabin_show_strings()
|
||||
if ((strings = r_bin_get_strings(&bin)) == NULL)
|
||||
return R_FALSE;
|
||||
|
||||
if (rad)
|
||||
printf("fs strings\n");
|
||||
if (rad) printf("fs strings\n");
|
||||
else printf("[strings]\n");
|
||||
|
||||
for (i = 0; !strings[i].last; i++) {
|
||||
@ -188,7 +187,6 @@ static int rabin_show_strings()
|
||||
}
|
||||
|
||||
if (!rad) printf("\n%i strings\n", i);
|
||||
|
||||
free(strings);
|
||||
|
||||
return R_TRUE;
|
||||
@ -234,11 +232,8 @@ static int rabin_show_sections()
|
||||
}
|
||||
|
||||
if (!rad) printf("\n%i sections\n", i);
|
||||
|
||||
free(sections);
|
||||
|
||||
return R_TRUE;
|
||||
|
||||
}
|
||||
|
||||
static int rabin_show_info()
|
||||
@ -276,9 +271,7 @@ static int rabin_show_info()
|
||||
R_BIN_DBG_LINENUMS(info->dbg_info)?"True":"False",
|
||||
R_BIN_DBG_SYMS(info->dbg_info)?"True":"False",
|
||||
R_BIN_DBG_RELOCS(info->dbg_info)?"True":"False");
|
||||
|
||||
free(info);
|
||||
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
@ -308,11 +301,8 @@ static int rabin_show_fields()
|
||||
}
|
||||
|
||||
if (!rad) printf("\n%i fields\n", i);
|
||||
|
||||
free(fields);
|
||||
|
||||
return R_TRUE;
|
||||
|
||||
}
|
||||
|
||||
static int rabin_dump_symbols(int len)
|
||||
@ -344,7 +334,6 @@ static int rabin_dump_symbols(int len)
|
||||
}
|
||||
|
||||
free(symbols);
|
||||
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
@ -373,7 +362,6 @@ static int rabin_dump_sections(char *name)
|
||||
}
|
||||
|
||||
free(sections);
|
||||
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
@ -383,8 +371,8 @@ static int rabin_do_operation(const char *op)
|
||||
|
||||
if (!strcmp(op, "help")) {
|
||||
printf( "Operation string:\n"
|
||||
" Dump symbols: d/s/1024\n"
|
||||
" Dump section: d/S/.text\n");
|
||||
" Dump symbols: d/s/1024\n"
|
||||
" Dump section: d/S/.text\n");
|
||||
return R_FALSE;
|
||||
}
|
||||
arg = alloca(strlen(op)+1);
|
||||
@ -480,7 +468,7 @@ int main(int argc, char **argv)
|
||||
action |= ACTION_ENTRY;
|
||||
break;
|
||||
case 'w':
|
||||
rw = 1;
|
||||
rw = R_TRUE;
|
||||
break;
|
||||
case 'o':
|
||||
op = optarg;
|
||||
@ -490,7 +478,7 @@ int main(int argc, char **argv)
|
||||
format = optarg;
|
||||
break;
|
||||
case 'r':
|
||||
rad = 1;
|
||||
rad = R_TRUE;
|
||||
break;
|
||||
case 'v':
|
||||
verbose++;
|
||||
@ -510,16 +498,14 @@ int main(int argc, char **argv)
|
||||
|
||||
if (format) {
|
||||
plugin_name = malloc(strlen(format)+10);
|
||||
sprintf(plugin_name, "bin_%s", format);
|
||||
}
|
||||
|
||||
if (plugin_name)
|
||||
sprintf(plugin_name, R_BIN_PFX"%s", format);
|
||||
}
|
||||
if (r_bin_open(&bin, file, rw, plugin_name) == -1) {
|
||||
ERR("r_bin: Cannot open '%s'\n", file);
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
if (plugin_name != NULL)
|
||||
free (plugin_name);
|
||||
free (plugin_name);
|
||||
|
||||
if (action&ACTION_ENTRY)
|
||||
rabin_show_entrypoint();
|
||||
@ -539,6 +525,5 @@ int main(int argc, char **argv)
|
||||
rabin_do_operation(op);
|
||||
|
||||
r_bin_close(&bin);
|
||||
|
||||
return R_FALSE;
|
||||
}
|
||||
|
@ -1,2 +1,4 @@
|
||||
LIBDWARF:
|
||||
http://reality.sgiweb.org/davea/dwarf.html
|
||||
|
||||
* use r_db to cache line info
|
||||
|
@ -46,9 +46,8 @@ R_API void r_bp_handle_list(struct r_bp_t *bp)
|
||||
struct list_head *pos;
|
||||
list_for_each(pos, &bp->plugins) {
|
||||
b = list_entry(pos, struct r_bp_handle_t, list);
|
||||
printf(" %c %s\n",
|
||||
printf("bp %c %s\n",
|
||||
(bp->cur && !strcmp(bp->cur->name, b->name))?'*':'-',
|
||||
b->name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ static struct r_bp_arch_t r_bp_plugin_arm_bps[] = {
|
||||
};
|
||||
|
||||
struct r_bp_handle_t r_bp_plugin_arm = {
|
||||
.name = "bp_arm",
|
||||
.name = "arm",
|
||||
.arch = "arm",
|
||||
.nbps = 2,
|
||||
.bps = r_bp_plugin_arm_bps,
|
||||
|
@ -10,7 +10,7 @@ static struct r_bp_arch_t r_bp_plugin_x86_bps[] = {
|
||||
};
|
||||
|
||||
struct r_bp_handle_t r_bp_plugin_x86 = {
|
||||
.name = "bp_x86",
|
||||
.name = "x86",
|
||||
.arch = "x86",
|
||||
.nbps = 2,
|
||||
.bps = r_bp_plugin_x86_bps,
|
||||
|
@ -332,7 +332,7 @@ static int cmd_help(void *data, const char *input)
|
||||
" (macro arg0 arg1) ; define scripting macros\n"
|
||||
" q [ret] ; quit program with a return value\n"
|
||||
"Use '?$' to get help for the variables\n"
|
||||
"Use '?""??' for extra help about '?' subcommands.\n"
|
||||
"Use '?""?""?' for extra help about '?' subcommands.\n"
|
||||
"Append '?' to any char command to get detailed help\n");
|
||||
break;
|
||||
}
|
||||
@ -568,7 +568,7 @@ static int cmd_flag(void *data, const char *input)
|
||||
{
|
||||
char *file = PREFIX"/share/doc/radare2/fortunes";
|
||||
char *line = r_file_slurp_random_line (file);
|
||||
r_cons_printf("%s\n", line);
|
||||
r_cons_printf(" -- %s\n", line);
|
||||
free(line);
|
||||
}
|
||||
break;
|
||||
@ -654,8 +654,8 @@ static int cmd_write(void *data, const char *input)
|
||||
{
|
||||
/* TODO: Support user defined size? */
|
||||
int len = core->blocksize;
|
||||
char *arg = input+(input[1]==' ')?2:1;
|
||||
char *buf = core->block;
|
||||
const char *arg = input+(input[1]==' ')?2:1;
|
||||
const ut8 *buf = core->block;
|
||||
r_file_dump(arg, buf, len);
|
||||
}
|
||||
break;
|
||||
@ -720,16 +720,15 @@ static int cmd_write(void *data, const char *input)
|
||||
{
|
||||
int ret = 0;
|
||||
struct r_asm_aop_t aop;
|
||||
char buf[128];
|
||||
/* XXX ULTRAUGLY , needs fallback support in rasm */
|
||||
r_asm_set(&core->assembler, "asm_x86_olly");
|
||||
r_asm_use(&core->assembler, "x86.olly");
|
||||
r_asm_set_pc(&core->assembler, core->seek);
|
||||
if (input[1]==' ')input=input+1;
|
||||
ret = r_asm_massemble(&core->assembler, &aop, input+1);
|
||||
eprintf("Written %d bytes (%s)=wx %s\n", ret, input+1, aop.buf_hex);
|
||||
r_core_write_at(core, core->seek, aop.buf, ret);
|
||||
r_core_block_read(core, 0);
|
||||
r_asm_set(&core->assembler, "asm_x86"); /* XXX */
|
||||
r_asm_use(&core->assembler, "x86"); /* XXX */
|
||||
}
|
||||
break;
|
||||
case 'b':
|
||||
@ -896,7 +895,7 @@ static int cmd_search(void *data, const char *input)
|
||||
r_search_free(core->search);
|
||||
core->search = r_search_new(R_SEARCH_KEYWORD);
|
||||
n32 = r_num_math(&core->num, input+1);
|
||||
r_search_kw_add_bin(core->search, &n32, 4, "",0);
|
||||
r_search_kw_add_bin(core->search, (const ut8*)&n32, 4, NULL, 0);
|
||||
r_search_begin(core->search);
|
||||
dosearch = 1;
|
||||
break;
|
||||
@ -1236,7 +1235,7 @@ static int r_core_cmd_subst(struct r_core_t *core, char *cmd, int *rs, int *rfd,
|
||||
ptr[0] = '\0';
|
||||
if (ptr[1]=='<') {
|
||||
/* this is a bit mess */
|
||||
char *oprompt = r_line_prompt;
|
||||
const char *oprompt = r_line_prompt;
|
||||
oprompt = ">";
|
||||
for(str=ptr+2;str[0]== ' ';str=str+1);
|
||||
eprintf("==> Reading from stdin until '%s'\n", str);
|
||||
@ -1337,12 +1336,12 @@ R_API int r_core_cmd_foreach(struct r_core_t *core, const char *cmd, char *each)
|
||||
|
||||
switch(each[0]) {
|
||||
case '?':
|
||||
eprintf("Foreach '@@' iterator command:\n");
|
||||
eprintf(" This command is used to repeat a command over a list of offsets.\n");
|
||||
eprintf(" x @@ sym. ; run 'x' over all flags matching 'sym.'\n");
|
||||
eprintf(" x @@.file ; \"\" over the offsets specified in the file (one offset per line)\n");
|
||||
eprintf(" x @@=off1 off2 .. ; manual list of offsets\n");
|
||||
eprintf(" x @@=`pdf~call[0]` ; run 'x' at every call offset of the current function\n");
|
||||
eprintf("Foreach '@@' iterator command:\n"
|
||||
" This command is used to repeat a command over a list of offsets.\n"
|
||||
" x @@ sym. ; run 'x' over all flags matching 'sym.'\n"
|
||||
" x @@.file ; \"\" over the offsets specified in the file (one offset per line)\n"
|
||||
" x @@=off1 off2 .. ; manual list of offsets\n"
|
||||
" x @@=`pdf~call[0]` ; run 'x' at every call offset of the current function\n");
|
||||
break;
|
||||
case '=':
|
||||
/* foreach list of items */
|
||||
@ -1369,10 +1368,8 @@ R_API int r_core_cmd_foreach(struct r_core_t *core, const char *cmd, char *each)
|
||||
// TODO: use controlc() here
|
||||
for(core->macro.counter=0;i<999;core->macro.counter++) {
|
||||
r_macro_call(&core->macro, each+2);
|
||||
if (core->macro.brk_value == NULL) {
|
||||
//eprintf("==>breaks(%s)\n", each);
|
||||
if (core->macro.brk_value == NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
addr = core->macro._brk_value;
|
||||
sprintf(cmd2, "%s @ 0x%08llx", cmd, addr);
|
||||
@ -1385,9 +1382,7 @@ R_API int r_core_cmd_foreach(struct r_core_t *core, const char *cmd, char *each)
|
||||
char buf[1024];
|
||||
char cmd2[1024];
|
||||
FILE *fd = fopen(each+1, "r");
|
||||
if (fd == NULL) {
|
||||
eprintf("Cannot open file '%s' for reading one offset per line.\n", each+1);
|
||||
} else {
|
||||
if (fd) {
|
||||
core->macro.counter=0;
|
||||
while(!feof(fd)) {
|
||||
buf[0]='\0';
|
||||
@ -1395,12 +1390,12 @@ R_API int r_core_cmd_foreach(struct r_core_t *core, const char *cmd, char *each)
|
||||
addr = r_num_math(&core->num, buf);
|
||||
eprintf("0x%08llx: %s\n", addr, cmd);
|
||||
sprintf(cmd2, "%s @ 0x%08llx", cmd, addr);
|
||||
r_core_seek(core, buf, 1);
|
||||
r_core_seek(core, addr, 1); // XXX
|
||||
r_core_cmd(core, cmd2, 0);
|
||||
core->macro.counter++;
|
||||
}
|
||||
fclose(fd);
|
||||
}
|
||||
} else eprintf("Cannot open file '%s' to read offsets\n", each+1);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -1561,7 +1556,7 @@ int r_core_cmd(struct r_core_t *core, const char *command, int log)
|
||||
core->oobi = NULL;
|
||||
core->oobi_len = 0;
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int r_core_cmd_file(struct r_core_t *core, const char *file)
|
||||
@ -1624,9 +1619,9 @@ static int cmd_debug(void *data, const char *input)
|
||||
break;
|
||||
case 'h':
|
||||
if (input[2]==' ') {
|
||||
if (!r_bp_use(&core->dbg.bp, input+3))
|
||||
if (!r_bp_use(core->dbg.bp, input+3))
|
||||
eprintf("Invalid name: '%s'.\n", input+3);
|
||||
} else r_bp_handle_list(&core->dbg.bp);
|
||||
} else r_bp_handle_list(core->dbg.bp);
|
||||
break;
|
||||
case '?':
|
||||
r_cons_printf(
|
||||
@ -1675,11 +1670,9 @@ static int cmd_debug(void *data, const char *input)
|
||||
else fprintf(stderr, "TODO: List processes..\n");
|
||||
break;
|
||||
case 'h':
|
||||
if (input[1]==' ') {
|
||||
char buf[1024];
|
||||
snprintf(buf, "dbg_%s", input+2);
|
||||
r_debug_use(&core->dbg, buf);
|
||||
} else r_debug_handle_list(&core->dbg);
|
||||
if (input[1]==' ')
|
||||
r_debug_use(&core->dbg, input+2);
|
||||
else r_debug_handle_list(&core->dbg);
|
||||
break;
|
||||
default:
|
||||
r_cons_printf("Usage: d[sbhcrbo] [arg]\n"
|
||||
|
@ -6,9 +6,7 @@ static int config_asm_arch_callback(void *user, void *data)
|
||||
{
|
||||
struct r_core_t *core = (struct r_core_t *) user;
|
||||
struct r_config_node_t *node = (struct r_config_node_t *) data;
|
||||
char buf[128];
|
||||
snprintf(buf, 127, "asm_%s", node->value),
|
||||
r_asm_set(&core->assembler, buf);
|
||||
r_asm_use(&core->assembler, node->value);
|
||||
// TODO: control error and restore old value (return false?) show errormsg?
|
||||
return R_TRUE;
|
||||
}
|
||||
@ -17,9 +15,8 @@ static int config_asm_parser_callback(void *user, void *data)
|
||||
{
|
||||
struct r_core_t *core = (struct r_core_t *) user;
|
||||
struct r_config_node_t *node = (struct r_config_node_t *) data;
|
||||
char buf[128];
|
||||
snprintf(buf, 127, "parse_%s", node->value),
|
||||
r_asm_set(&core->assembler, buf);
|
||||
// XXX this is wrong? snprintf(buf, 127, "parse_%s", node->value),
|
||||
r_parse_use(&core->parser, node->value);
|
||||
// TODO: control error and restore old value (return false?) show errormsg?
|
||||
return R_TRUE;
|
||||
}
|
||||
@ -32,7 +29,7 @@ static int config_asm_bits_callback(void *user, void *data)
|
||||
if (ret == R_FALSE) {
|
||||
struct r_asm_handle_t *h = core->assembler.cur;
|
||||
if (h) {
|
||||
eprintf("Cannot set bits %d to '%s'\n",
|
||||
eprintf("Cannot set bits %lld to '%s'\n",
|
||||
node->i_value, h->name);
|
||||
} else {
|
||||
IFDBG eprintf("e asm.bits: Cannot set value, no plugins defined yet\n");
|
||||
@ -66,8 +63,8 @@ R_API int r_core_config_init(struct r_core_t *core)
|
||||
|
||||
r_config_set_cb(cfg, "asm.arch", "x86",
|
||||
&config_asm_arch_callback);
|
||||
r_parse_set(&core->parser, "parse_x86_pseudo");
|
||||
r_config_set_cb(cfg, "asm.parser", "x86_pseudo",
|
||||
r_parse_use(&core->parser, "x86.pseudo");
|
||||
r_config_set_cb(cfg, "asm.parser", "x86.pseudo",
|
||||
&config_asm_parser_callback);
|
||||
r_config_set(cfg, "dir.plugins", LIBDIR"/radare2/");
|
||||
r_config_set(cfg, "asm.syntax", "intel");
|
||||
|
@ -121,7 +121,7 @@ R_API int r_core_init(struct r_core_t *core)
|
||||
|
||||
/* initialize libraries */
|
||||
r_print_init(&core->print);
|
||||
core->print.printf = r_cons_printf;
|
||||
core->print.printf = (void *)r_cons_printf;
|
||||
r_lang_init(&core->lang);
|
||||
r_lang_set_user_ptr(&core->lang, core);
|
||||
r_anal_init(&core->anal);
|
||||
@ -136,7 +136,7 @@ R_API int r_core_init(struct r_core_t *core)
|
||||
r_meta_init(&core->meta);
|
||||
r_line_init();
|
||||
r_cons_init();
|
||||
r_cons_user_fgets = myfgets;
|
||||
r_cons_user_fgets = (void *)myfgets;
|
||||
r_line_hist_load(".radare2_history");
|
||||
|
||||
core->search = r_search_new(R_SEARCH_KEYWORD);
|
||||
@ -163,9 +163,9 @@ R_API int r_core_init(struct r_core_t *core)
|
||||
/* load plugins */
|
||||
r_core_loadlibs(core);
|
||||
/* UH? */
|
||||
r_asm_set(&core->assembler, "asm_"DEFAULT_ARCH);
|
||||
r_anal_set(&core->anal, "anal_"DEFAULT_ARCH);
|
||||
r_bp_use(core->dbg.bp, "bp_"DEFAULT_ARCH);
|
||||
r_asm_use(&core->assembler, DEFAULT_ARCH);
|
||||
r_anal_set(&core->anal, DEFAULT_ARCH);
|
||||
r_bp_use(core->dbg.bp, DEFAULT_ARCH);
|
||||
r_config_set(&core->config, "asm.arch", "x86");
|
||||
r_config_set_i(&core->config, "asm.bits", 32);
|
||||
|
||||
|
@ -80,7 +80,7 @@ R_API int r_core_seek(struct r_core_t *core, ut64 addr, int rb)
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
int r_core_write_at(struct r_core_t *core, ut64 addr, const ut8 *buf, int size)
|
||||
R_API int r_core_write_at(struct r_core_t *core, ut64 addr, const ut8 *buf, int size)
|
||||
{
|
||||
int ret = r_io_set_fd(&core->io, core->file->fd);
|
||||
if (ret != -1) {
|
||||
@ -100,7 +100,7 @@ R_API int r_core_block_read(struct r_core_t *core, int next)
|
||||
return r_io_read(&core->io, core->block, core->blocksize);
|
||||
}
|
||||
|
||||
int r_core_read_at(struct r_core_t *core, ut64 addr, ut8 *buf, int size)
|
||||
R_API int r_core_read_at(struct r_core_t *core, ut64 addr, ut8 *buf, int size)
|
||||
{
|
||||
int ret = r_io_set_fd (&core->io, core->file->fd);
|
||||
ret = r_io_read_at(&core->io, addr, buf, size);
|
||||
|
@ -73,11 +73,11 @@ R_API struct r_asm_t *r_asm_new();
|
||||
R_API const char *r_asm_fastcall(struct r_asm_t *a, int idx, int num);
|
||||
|
||||
R_API void r_asm_free(struct r_asm_t *a);
|
||||
R_API int r_asm_init(struct r_asm_t *a);
|
||||
R_API struct r_asm_t *r_asm_init(struct r_asm_t *a);
|
||||
R_API void r_asm_set_user_ptr(struct r_asm_t *a, void *user);
|
||||
R_API int r_asm_add(struct r_asm_t *a, struct r_asm_handle_t *foo);
|
||||
R_API int r_asm_list(struct r_asm_t *a);
|
||||
R_API int r_asm_set(struct r_asm_t *a, const char *name);
|
||||
R_API int r_asm_use(struct r_asm_t *a, const char *name);
|
||||
R_API int r_asm_set_bits(struct r_asm_t *a, int bits);
|
||||
R_API int r_asm_set_big_endian(struct r_asm_t *a, int boolean);
|
||||
R_API int r_asm_set_syntax(struct r_asm_t *a, int syntax);
|
||||
|
@ -136,16 +136,8 @@ R_API struct r_bin_import_t* r_bin_get_imports(struct r_bin_t *bin);
|
||||
R_API struct r_bin_string_t* r_bin_get_strings(struct r_bin_t *bin);
|
||||
R_API struct r_bin_info_t* r_bin_get_info(struct r_bin_t *bin);
|
||||
R_API struct r_bin_field_t* r_bin_get_fields(struct r_bin_t *bin);
|
||||
R_API ut64 r_bin_get_section_offset(struct r_bin_t *bin, char *name);
|
||||
R_API ut64 r_bin_get_section_rva(struct r_bin_t *bin, char *name);
|
||||
R_API ut64 r_bin_get_section_size(struct r_bin_t *bin, char *name);
|
||||
|
||||
/* plugin pointers */
|
||||
extern struct r_bin_handle_t r_bin_plugin_elf;
|
||||
extern struct r_bin_handle_t r_bin_plugin_elf64;
|
||||
extern struct r_bin_handle_t r_bin_plugin_pe;
|
||||
extern struct r_bin_handle_t r_bin_plugin_pe64;
|
||||
extern struct r_bin_handle_t r_bin_plugin_java;
|
||||
extern struct r_bin_handle_t r_bin_plugin_dummy;
|
||||
R_API ut64 r_bin_get_section_offset(struct r_bin_t *bin, const char *name);
|
||||
R_API ut64 r_bin_get_section_rva(struct r_bin_t *bin, const char *name);
|
||||
R_API ut64 r_bin_get_section_size(struct r_bin_t *bin, const char *name);
|
||||
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <r_types.h>
|
||||
#include <list.h>
|
||||
|
||||
|
||||
// XXX : remove this define???
|
||||
#define R_PARSE_STRLEN 256
|
||||
|
||||
struct r_parse_t {
|
||||
@ -26,19 +26,14 @@ struct r_parse_handle_t {
|
||||
};
|
||||
|
||||
/* parse.c */
|
||||
struct r_parse_t *r_parse_new();
|
||||
void r_parse_free(struct r_parse_t *p);
|
||||
int r_parse_init(struct r_parse_t *p);
|
||||
void r_parse_set_user_ptr(struct r_parse_t *p, void *user);
|
||||
int r_parse_add(struct r_parse_t *p, struct r_parse_handle_t *foo);
|
||||
int r_parse_list(struct r_parse_t *p);
|
||||
int r_parse_set(struct r_parse_t *p, const char *name);
|
||||
int r_parse_parse(struct r_parse_t *p, void *data, char *str);
|
||||
int r_parse_assemble(struct r_parse_t *p, char *data, char *str);
|
||||
|
||||
/* plugin pointers */
|
||||
extern struct r_parse_handle_t r_parse_plugin_dummy;
|
||||
extern struct r_parse_handle_t r_parse_plugin_x86_pseudo;
|
||||
extern struct r_parse_handle_t r_parse_plugin_mreplace;
|
||||
R_API struct r_parse_t *r_parse_new();
|
||||
R_API void r_parse_free(struct r_parse_t *p);
|
||||
R_API struct r_parse_t *r_parse_init(struct r_parse_t *p);
|
||||
R_API void r_parse_set_user_ptr(struct r_parse_t *p, void *user);
|
||||
R_API int r_parse_add(struct r_parse_t *p, struct r_parse_handle_t *foo);
|
||||
R_API int r_parse_list(struct r_parse_t *p);
|
||||
R_API int r_parse_use(struct r_parse_t *p, const char *name);
|
||||
R_API int r_parse_parse(struct r_parse_t *p, void *data, char *str);
|
||||
R_API int r_parse_assemble(struct r_parse_t *p, char *data, char *str);
|
||||
|
||||
#endif
|
||||
|
@ -51,72 +51,38 @@ struct r_search_t {
|
||||
struct list_head hits; //r_search_hit_t hits;
|
||||
};
|
||||
|
||||
struct r_search_t *r_search_new(int mode);
|
||||
int r_search_set_mode(struct r_search_t *s, int mode);
|
||||
int r_search_init(struct r_search_t *s, int mode);
|
||||
struct r_search_t *r_search_free(struct r_search_t *s);
|
||||
R_API struct r_search_t *r_search_new(int mode);
|
||||
R_API int r_search_set_mode(struct r_search_t *s, int mode);
|
||||
R_API int r_search_init(struct r_search_t *s, int mode);
|
||||
R_API struct r_search_t *r_search_free(struct r_search_t *s);
|
||||
|
||||
/* keyword management */
|
||||
int r_search_start(struct r_search_t *s);
|
||||
int r_search_update(struct r_search_t *s, ut64 *from, const ut8 *buf, ut32 len);
|
||||
int r_search_update_i(struct r_search_t *s, ut64 from, const ut8 *buf, ut32 len);
|
||||
R_API int r_search_start(struct r_search_t *s);
|
||||
R_API int r_search_update(struct r_search_t *s, ut64 *from, const ut8 *buf, long len);
|
||||
R_API int r_search_update_i(struct r_search_t *s, ut64 from, const ut8 *buf, long len);
|
||||
|
||||
/* */
|
||||
int r_search_kw_add(struct r_search_t *s, const char *kw, const char *bm);
|
||||
int r_search_kw_add_hex(struct r_search_t *s, const char *kw, const char *bm);
|
||||
int r_search_kw_add_bin(struct r_search_t *s, const ut8 *kw, int kw_len, const ut8 *bm, int bm_len);
|
||||
struct r_search_kw_t *r_search_kw_list(struct r_search_t *s);
|
||||
int r_search_reset(struct r_search_t *s);
|
||||
R_API int r_search_kw_add(struct r_search_t *s, const char *kw, const char *bm);
|
||||
R_API int r_search_kw_add_hex(struct r_search_t *s, const char *kw, const char *bm);
|
||||
R_API int r_search_kw_add_bin(struct r_search_t *s, const ut8 *kw, int kw_len, const ut8 *bm, int bm_len);
|
||||
R_API struct r_search_kw_t *r_search_kw_list(struct r_search_t *s);
|
||||
R_API int r_search_reset(struct r_search_t *s);
|
||||
|
||||
int r_search_range_add(struct r_search_t *s, ut64 from, ut64 to);
|
||||
int r_search_range_set(struct r_search_t *s, ut64 from, ut64 to);
|
||||
int r_search_range_reset(struct r_search_t *s);
|
||||
int r_search_set_blocksize(struct r_search_t *s, ut32 bsize);
|
||||
R_API int r_search_range_add(struct r_search_t *s, ut64 from, ut64 to);
|
||||
R_API int r_search_range_set(struct r_search_t *s, ut64 from, ut64 to);
|
||||
R_API int r_search_range_reset(struct r_search_t *s);
|
||||
R_API int r_search_set_blocksize(struct r_search_t *s, ut32 bsize);
|
||||
|
||||
int r_search_mybinparse_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len);
|
||||
int r_search_aes_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len);
|
||||
int r_search_strings_update_char(const unsigned char *buf, int min, int max, int enc, ut64 offset, const char *match);
|
||||
int r_search_regexp_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len);
|
||||
int r_search_xrefs_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len);
|
||||
R_API int r_search_mybinparse_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len);
|
||||
R_API int r_search_aes_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len);
|
||||
R_API int r_search_strings_update_char(const unsigned char *buf, int min, int max, int enc, ut64 offset, const char *match);
|
||||
R_API int r_search_regexp_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len);
|
||||
R_API int r_search_xrefs_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len);
|
||||
|
||||
/* pattern search */
|
||||
int r_search_pattern(struct r_search_t *s, ut32 size);
|
||||
int r_search_strings(struct r_search_t *s, ut32 min, ut32 max);
|
||||
int r_search_set_callback(struct r_search_t *s, int (*callback)(struct r_search_kw_t *, void *, ut64), void *user);
|
||||
int r_search_begin(struct r_search_t *s);
|
||||
R_API int r_search_pattern(struct r_search_t *s, ut32 size);
|
||||
R_API int r_search_strings(struct r_search_t *s, ut32 min, ut32 max);
|
||||
R_API int r_search_set_callback(struct r_search_t *s, int (*callback)(struct r_search_kw_t *, void *, ut64), void *user);
|
||||
R_API int r_search_begin(struct r_search_t *s);
|
||||
|
||||
#endif
|
||||
|
||||
/* -- deprecated -- */
|
||||
#if 0
|
||||
/* binparse api */
|
||||
// TODO: Remove typedef!!
|
||||
typedef struct r_search_binparse_token {
|
||||
ut8 mintok; // token
|
||||
ut8 range; // 0 only mintok, ( maxtoken - mintoken )
|
||||
ut8 mask; // binmask
|
||||
} token;
|
||||
|
||||
typedef struct r_search_binparse_tokenlist_t {
|
||||
token* tl;
|
||||
int numtok;
|
||||
char name [300];
|
||||
char actp[300]; //aux pel parseig actual
|
||||
int stat;
|
||||
/* int lastpos; XXX unused */
|
||||
} tokenlist;
|
||||
|
||||
struct r_search_binparse_t {
|
||||
//tokenlist** tls;
|
||||
struct r_search_binparse_tokenlist_t **tls;
|
||||
int nlists;
|
||||
int interrupted;
|
||||
int (*callback)(struct r_search_binparse_tokenlist_t *t, int i, ut64 where);
|
||||
};
|
||||
|
||||
struct r_search_binparse_t *binparse_new(int kws);
|
||||
int r_search_binparse_free(struct r_search_binparse_t *ptokenizer);
|
||||
int r_search_binparse_add(struct r_search_binparse_t *t, const char *string, const char *mask);
|
||||
int r_search_binparse_add_named(struct r_search_binparse_t *t, const char *name, const char *string, const char *mask);
|
||||
int r_search_binparse_update(struct r_search_binparse_t *t, ut8 inchar, ut64 where);
|
||||
#endif
|
||||
|
@ -146,10 +146,20 @@ static inline int ERR(char *str, ...)
|
||||
#define ralist_next(x) (x=x->next, (x != head))
|
||||
#define ralist_free(x) (x)
|
||||
|
||||
#if 1
|
||||
#define rarray_get(x,y) x; x=((y)x)+1;
|
||||
#define rarray_next(x,y) !((y)x)->last
|
||||
#define rarray_next(x,y) (( ((y)x)->last ) ?free(x),x=0,0:1)
|
||||
#define rarray_iterator(x) x
|
||||
#define rarray_free(x) x
|
||||
//free(x)
|
||||
#else
|
||||
typedef struct { void* head; void *cur; } rarray_t;
|
||||
#define rarray_get(x,y) (x)->cur; (x)->cur=((y)(x)->cur)+1
|
||||
#define rarray_next(x,y) !((y)(x)->cur)->last
|
||||
#define rarray_iterator(x,y) (y)->cur=(x),(y)->head=(y)->cur,*(y)
|
||||
//{.cur=(void*)x,.head=(void*)x}
|
||||
#define rarray_free(x) (free((x)->head))
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -13,7 +13,7 @@ static int parse(struct r_parse_t *p, void *data, char *str)
|
||||
}
|
||||
|
||||
struct r_parse_handle_t r_parse_plugin_dummy = {
|
||||
.name = "parse_dummy",
|
||||
.name = "dummy",
|
||||
.desc = "dummy parsing plugin",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
|
@ -23,12 +23,11 @@ static int parse(struct r_parse_t *p, void *data, char *str)
|
||||
memcpy(str, buf, R_PARSE_STRLEN);
|
||||
if (buf != NULL)
|
||||
free(buf);
|
||||
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
struct r_parse_handle_t r_parse_plugin_mreplace = {
|
||||
.name = "parse_mreplace",
|
||||
.name = "mreplace",
|
||||
.desc = "mreplace parsing plugin",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
|
@ -136,7 +136,7 @@ static int assemble(struct r_parse_t *p, void *data, char *str)
|
||||
}
|
||||
|
||||
struct r_parse_handle_t r_parse_plugin_x86_pseudo = {
|
||||
.name = "parse_x86_pseudo",
|
||||
.name = "x86.pseudo",
|
||||
.desc = "X86 pseudo syntax",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
|
@ -7,37 +7,43 @@
|
||||
#include <list.h>
|
||||
#include "../config.h"
|
||||
|
||||
/* plugin pointers */
|
||||
extern struct r_parse_handle_t r_parse_plugin_dummy;
|
||||
extern struct r_parse_handle_t r_parse_plugin_x86_pseudo;
|
||||
extern struct r_parse_handle_t r_parse_plugin_mreplace;
|
||||
|
||||
static struct r_parse_handle_t *parse_static_plugins[] =
|
||||
{ R_PARSE_STATIC_PLUGINS };
|
||||
|
||||
struct r_parse_t *r_parse_new()
|
||||
R_API struct r_parse_t *r_parse_new()
|
||||
{
|
||||
struct r_parse_t *p = MALLOC_STRUCT(struct r_parse_t);
|
||||
r_parse_init(p);
|
||||
return p;
|
||||
return r_parse_init(p);
|
||||
}
|
||||
|
||||
void r_parse_free(struct r_parse_t *p)
|
||||
R_API void r_parse_free(struct r_parse_t *p)
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
|
||||
int r_parse_init(struct r_parse_t *p)
|
||||
R_API struct r_parse_t *r_parse_init(struct r_parse_t *p)
|
||||
{
|
||||
int i;
|
||||
p->user = NULL;
|
||||
INIT_LIST_HEAD(&p->parsers);
|
||||
for(i=0;parse_static_plugins[i];i++)
|
||||
r_parse_add(p, parse_static_plugins[i]);
|
||||
return R_TRUE;
|
||||
if (p) {
|
||||
int i;
|
||||
p->user = NULL;
|
||||
INIT_LIST_HEAD(&p->parsers);
|
||||
for(i=0;parse_static_plugins[i];i++)
|
||||
r_parse_add(p, parse_static_plugins[i]);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
void r_parse_set_user_ptr(struct r_parse_t *p, void *user)
|
||||
R_API void r_parse_set_user_ptr(struct r_parse_t *p, void *user)
|
||||
{
|
||||
p->user = user;
|
||||
}
|
||||
|
||||
int r_parse_add(struct r_parse_t *p, struct r_parse_handle_t *foo)
|
||||
R_API int r_parse_add(struct r_parse_t *p, struct r_parse_handle_t *foo)
|
||||
{
|
||||
if (foo->init)
|
||||
foo->init(p->user);
|
||||
@ -45,17 +51,17 @@ int r_parse_add(struct r_parse_t *p, struct r_parse_handle_t *foo)
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
int r_parse_list(struct r_parse_t *p)
|
||||
R_API int r_parse_list(struct r_parse_t *p)
|
||||
{
|
||||
struct list_head *pos;
|
||||
list_for_each_prev(pos, &p->parsers) {
|
||||
struct r_parse_handle_t *h = list_entry(pos, struct r_parse_handle_t, list);
|
||||
printf(" %s: %s\n", h->name, h->desc);
|
||||
printf("parse %10s %s\n", h->name, h->desc);
|
||||
}
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
int r_parse_set(struct r_parse_t *p, const char *name)
|
||||
R_API int r_parse_use(struct r_parse_t *p, const char *name)
|
||||
{
|
||||
struct list_head *pos;
|
||||
list_for_each_prev(pos, &p->parsers) {
|
||||
@ -68,20 +74,18 @@ int r_parse_set(struct r_parse_t *p, const char *name)
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
int r_parse_assemble(struct r_parse_t *p, char *data, char *str)
|
||||
R_API int r_parse_assemble(struct r_parse_t *p, char *data, char *str)
|
||||
{
|
||||
int ret = R_FALSE;
|
||||
char *in = strdup(str);
|
||||
char *s, *o, *t = in;
|
||||
char *s, *o;
|
||||
|
||||
data[0]='\0';
|
||||
if (p->cur && p->cur->assemble) {
|
||||
o = data+strlen(data);
|
||||
do {
|
||||
s = strchr(str, ';');
|
||||
if (s) {
|
||||
*s='\0';
|
||||
}
|
||||
if (s) *s='\0';
|
||||
ret = p->cur->assemble(p, o, str);
|
||||
if (!ret) break;
|
||||
if (s) {
|
||||
@ -97,10 +101,10 @@ int r_parse_assemble(struct r_parse_t *p, char *data, char *str)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int r_parse_parse(struct r_parse_t *p, void *data, char *str)
|
||||
R_API int r_parse_parse(struct r_parse_t *p, void *data, char *str)
|
||||
{
|
||||
register int ret = R_FALSE;
|
||||
if (p->cur && p->cur->parse)
|
||||
return p->cur->parse(p, data, str);
|
||||
|
||||
return R_FALSE;
|
||||
ret = p->cur->parse(p, data, str);
|
||||
return ret;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ int main()
|
||||
printf("List: \n");
|
||||
r_parse_list(p);
|
||||
printf("Using plugin: \n");
|
||||
r_parse_set(p, "parse_x86_pseudo");
|
||||
r_parse_use(p, "x86.pseudo");
|
||||
str[0]='\0';
|
||||
r_parse_assemble(p, str, strdup("eax=1;int 0x80"));
|
||||
printf("--output--\n");
|
||||
|
@ -87,6 +87,9 @@ static int r_reg_set_word(struct r_reg_item_t *item, int idx, char *word)
|
||||
else
|
||||
if (!strcmp(word, "seg"))
|
||||
item->type = R_REG_TYPE_SEG;
|
||||
else
|
||||
if (!strcmp(word, "flg"))
|
||||
item->type = R_REG_TYPE_FLG;
|
||||
else printf("Unknown register type: '%s'\n", word);
|
||||
break;
|
||||
case 1:
|
||||
|
6
libr/search/TODO
Normal file
6
libr/search/TODO
Normal file
@ -0,0 +1,6 @@
|
||||
* Implement xrefs algorithm
|
||||
- We must think on a way to do it more algoritmically
|
||||
* Add support for stepped searchs (skip N bytes after every read)
|
||||
* Allow to enable/disable nested hits
|
||||
* Added support for negated searchs (find until no keyword matches)
|
||||
- useful to find the end of a \xff block
|
@ -30,17 +30,14 @@ unsigned char table_sbox[256] = {
|
||||
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
|
||||
};
|
||||
|
||||
int aes_key_test(const unsigned char *buf) {
|
||||
|
||||
if (buf[28]==table_sbox[buf[15]] \
|
||||
&& buf[29]==table_sbox[buf[12]] \
|
||||
&& buf[30]==table_sbox[buf[13]] \
|
||||
&& buf[31]==(table_sbox[buf[14]]^1))
|
||||
return 1;
|
||||
return 0;
|
||||
static int aes_key_test(const unsigned char *buf) {
|
||||
return (buf[28]==table_sbox[buf[15]] \
|
||||
&& buf[29]==table_sbox[buf[12]] \
|
||||
&& buf[30]==table_sbox[buf[13]] \
|
||||
&& buf[31]==(table_sbox[buf[14]]^1))?1:0;
|
||||
}
|
||||
|
||||
int r_search_aes_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len)
|
||||
R_API int r_search_aes_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len)
|
||||
{
|
||||
int i, last = len-31;
|
||||
if (last < 0)
|
||||
|
@ -26,7 +26,7 @@ token: Fruit for the loom
|
||||
------------------------------
|
||||
#endif
|
||||
|
||||
void r_search_binparse_apply_mask (char * maskout, int masklen , token* tlist , int ntok)
|
||||
R_API void r_search_binparse_apply_mask (char * maskout, int masklen , token* tlist , int ntok)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i < ntok ; i ++ )
|
||||
@ -69,14 +69,10 @@ static int get_range(char *str, int len, unsigned char *cbase)
|
||||
{
|
||||
int g;
|
||||
ut8 min, max;
|
||||
|
||||
// busca guio
|
||||
for ( g= 0; (g < len ) && ( str[g] != '-' ) ; g++ );
|
||||
min = get_byte ( str, g );
|
||||
max = get_byte ( str+g+1, len-g-1 );
|
||||
|
||||
*cbase = min;
|
||||
|
||||
return (max-min);
|
||||
}
|
||||
|
||||
@ -271,7 +267,7 @@ static const char *str_get_arg(const char *buf)
|
||||
/* public api */
|
||||
|
||||
//tokenizer* binparse_new(int kws)
|
||||
struct r_search_binparse_t *binparse_new(int kws)
|
||||
R_API struct r_search_binparse_t *binparse_new(int kws)
|
||||
{
|
||||
struct r_search_binparse_t *tll = MALLOC_STRUCT(struct r_search_binparse_t);
|
||||
if (tll == NULL)
|
||||
@ -287,7 +283,7 @@ struct r_search_binparse_t *binparse_new(int kws)
|
||||
}
|
||||
|
||||
//int binparser_free(tokenizer* ptokenizer)
|
||||
int r_search_binparse_free(struct r_search_binparse_t *ptokenizer)
|
||||
R_API int r_search_binparse_free(struct r_search_binparse_t *ptokenizer)
|
||||
{
|
||||
int i;
|
||||
if (ptokenizer == NULL)
|
||||
@ -303,7 +299,7 @@ int r_search_binparse_free(struct r_search_binparse_t *ptokenizer)
|
||||
}
|
||||
|
||||
//int binparse_add(tokenizer *t, char *string, char *mask)
|
||||
int r_search_binparse_add(struct r_search_binparse_t *t, const char *string, const char *mask)
|
||||
R_API int r_search_binparse_add(struct r_search_binparse_t *t, const char *string, const char *mask)
|
||||
{
|
||||
int n = t->nlists;
|
||||
char name[32];
|
||||
@ -320,7 +316,7 @@ int r_search_binparse_add(struct r_search_binparse_t *t, const char *string, con
|
||||
}
|
||||
|
||||
// XXX name needs to be changed in runtime?
|
||||
int r_search_binparse_add_named(struct r_search_binparse_t *t, const char *name, const char *string, const char *mask)
|
||||
R_API int r_search_binparse_add_named(struct r_search_binparse_t *t, const char *name, const char *string, const char *mask)
|
||||
{
|
||||
int ret = r_search_binparse_add(t, string, mask);
|
||||
if (ret != -1)
|
||||
@ -329,7 +325,7 @@ int r_search_binparse_add_named(struct r_search_binparse_t *t, const char *name,
|
||||
}
|
||||
|
||||
/* -1 = error, 0 = skip, 1 = hit found */
|
||||
int r_search_binparse_update(struct r_search_binparse_t *t, ut8 inchar, ut64 where)
|
||||
R_API int r_search_binparse_update(struct r_search_binparse_t *t, ut8 inchar, ut64 where)
|
||||
//int update_tlist(tokenizer* t, ut8 inchar, ut64 where )
|
||||
{
|
||||
ut8 cmin, cmax, cmask;
|
||||
@ -369,152 +365,5 @@ int r_search_binparse_update(struct r_search_binparse_t *t, ut8 inchar, ut64 whe
|
||||
t->tls[i]->stat = 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* unused .. deprecate ? */
|
||||
|
||||
#if 0
|
||||
void tokenize(int fd, tokenizer* t)
|
||||
{
|
||||
char ch;
|
||||
int ret;
|
||||
int where = lseek(fd, (off_t)0, SEEK_CUR);
|
||||
|
||||
while(1) {
|
||||
if ( read(fd, &ch, 1) <= 0 ) break;
|
||||
ret = update_tlist(t, ch, where);
|
||||
if (ret == -1) break;
|
||||
where++;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
tokenizer* binparse_new_from_file(char *file)
|
||||
{
|
||||
char buf[2049];
|
||||
FILE *fd;
|
||||
tokenizer *tok;
|
||||
char *str = NULL;
|
||||
char *mask = NULL;
|
||||
char *name = NULL;
|
||||
|
||||
tok = binparse_new(0);
|
||||
fd = fopen(file, "r");
|
||||
if (fd == NULL) {
|
||||
eprintf("Cannot open file '%s'\n", file);
|
||||
return NULL;
|
||||
}
|
||||
while(!feof(fd)) {
|
||||
/* read line */
|
||||
buf[0]='\0';
|
||||
fgets(buf, 2048, fd);
|
||||
if (buf[0]=='\0') continue;
|
||||
buf[strlen(buf)-1]='\0';
|
||||
|
||||
/* find token: */
|
||||
if (!memcmp(buf, "token:",6)) {
|
||||
if (str != NULL) {
|
||||
eprintf("new keyword(%s,%s,%s)\n", name, str, mask);
|
||||
binparse_add_name(tok, name, str, mask);
|
||||
free(name); name = NULL;
|
||||
free(str); str = NULL;
|
||||
free(mask); mask = NULL;
|
||||
}
|
||||
free(name);
|
||||
name = (const char *)str_get_arg(buf);
|
||||
} else
|
||||
if (!memcmp(buf, "\tstring:", 8)) {
|
||||
str = str_get_arg(buf);
|
||||
} else
|
||||
if (!memcmp(buf, "\tmask:", 6)) {
|
||||
mask = str_get_arg(buf);
|
||||
}
|
||||
}
|
||||
|
||||
if (str != NULL) {
|
||||
eprintf("new keyword(%s,%s,%s)\n", name, str, mask);
|
||||
binparse_add_name(tok, name, str, mask);
|
||||
}
|
||||
|
||||
free(name);
|
||||
free(str);
|
||||
free(mask);
|
||||
printf("TOKEN ELEMENTS: %d\n", tok->nlists);
|
||||
|
||||
return tok;
|
||||
}
|
||||
#if 0
|
||||
/* not necessary */
|
||||
static void print_tok_list(tokenlist* toklist)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf ("TOKLIST %s:\n",toklist->name);
|
||||
for (i=0; i<toklist->numtok; i++)
|
||||
printf ("TOK : %c , range : %d mask : %x\n",
|
||||
toklist->tl[i].mintok,
|
||||
toklist->tl[i].range,
|
||||
toklist->tl[i].mask);
|
||||
NEWLINE;
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
static void print_tokenizer ( tokenizer* ptokenizer )
|
||||
{
|
||||
int i;
|
||||
for (i=0 ; i < ptokenizer->nlists; i++ )
|
||||
print_tok_list(ptokenizer->tls[i]);
|
||||
}
|
||||
|
||||
static char* fd_readline ( int fd, char* line, int maxsize )
|
||||
{
|
||||
int i,ret ;
|
||||
memset(line, 0x00, maxsize);
|
||||
for (i=0; i<maxsize; i++) {
|
||||
ret = read (fd, line + i, 1);
|
||||
if (ret <1) return NULL;
|
||||
if (line[i] =='\n') break;
|
||||
}
|
||||
line[i+1]=0;
|
||||
return line;
|
||||
}
|
||||
|
||||
static int indent_count( int fd )
|
||||
{
|
||||
int ret=0;
|
||||
char t;
|
||||
read ( fd, &t, 1 );
|
||||
while ( t=='\t') {
|
||||
read ( fd, &t, 1 );
|
||||
ret++;
|
||||
}
|
||||
|
||||
// Posiciono a la primera diferent.
|
||||
lseek ( fd, (off_t)-1, SEEK_CUR );
|
||||
|
||||
return ret;
|
||||
}
|
||||
#if 0
|
||||
// XXX should be deprecated ?
|
||||
int binparse_add_search(struct r_search_binparse_t *t, int id)
|
||||
{
|
||||
char *token;
|
||||
char *mask;
|
||||
char tmp[128];
|
||||
|
||||
snprintf(tmp, 127, "SEARCH[%d]", id);
|
||||
token = getenv(tmp);
|
||||
snprintf(tmp, 127, "MASK[%d]", id);
|
||||
mask = getenv(tmp);
|
||||
|
||||
return binparse_add(t, token, mask);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -117,6 +117,7 @@ int do_byte_pat(int patlen)
|
||||
//rb = read ( fd, block, nr );
|
||||
//rb = radare_read_at(bproc, block, nr);
|
||||
//XXX
|
||||
rb = nr;
|
||||
moar = 0;
|
||||
for(i=0; i<nr; i++){
|
||||
if (!memcmp(&block[i], sblk, patlen) && !is_fi_present(root, sblk, patlen)){
|
||||
@ -153,7 +154,7 @@ int do_byte_pat(int patlen)
|
||||
|
||||
/* -- */
|
||||
|
||||
int r_search_pattern_update(int patlen)
|
||||
R_API int r_search_pattern_update(int patlen)
|
||||
{
|
||||
unsigned char block[BSIZE+MAX_PATLEN];
|
||||
unsigned char sblk[MAX_PATLEN+1];
|
||||
@ -213,6 +214,9 @@ int r_search_pattern_update(int patlen)
|
||||
//radare_controlc();
|
||||
nr = ((bytes-bproc) < BSIZE)?(bytes-bproc):BSIZE;
|
||||
nr = nr + ( patlen - (nr % patlen) ); // tamany de bloc llegit multiple superior de tamany busqueda
|
||||
|
||||
/* XXX: we need to read here!! */
|
||||
rb = nr;
|
||||
//rb = read ( fd, block, nr );
|
||||
//rb = radare_read_at(bproc, block, nr);
|
||||
//XXX
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "r_search.h"
|
||||
#include <regex.h>
|
||||
|
||||
int r_search_regexp_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len)
|
||||
R_API int r_search_regexp_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len)
|
||||
{
|
||||
struct list_head *pos;
|
||||
char *buffer = malloc(len+1);
|
||||
|
@ -2,9 +2,7 @@
|
||||
|
||||
#include "r_search.h"
|
||||
|
||||
/* object life cycle */
|
||||
|
||||
int r_search_init(struct r_search_t *s, int mode)
|
||||
R_API int r_search_init(struct r_search_t *s, int mode)
|
||||
{
|
||||
memset(s,'\0', sizeof(struct r_search_t));
|
||||
if (!r_search_set_mode(s, mode))
|
||||
@ -21,7 +19,7 @@ int r_search_init(struct r_search_t *s, int mode)
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
int r_search_set_string_limits(struct r_search_t *s, ut32 min, ut32 max)
|
||||
R_API int r_search_set_string_limits(struct r_search_t *s, ut32 min, ut32 max)
|
||||
{
|
||||
if (max < min)
|
||||
return R_FALSE;
|
||||
@ -30,7 +28,7 @@ int r_search_set_string_limits(struct r_search_t *s, ut32 min, ut32 max)
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
int r_search_set_mode(struct r_search_t *s, int mode)
|
||||
R_API int r_search_set_mode(struct r_search_t *s, int mode)
|
||||
{
|
||||
int ret = R_FALSE;
|
||||
switch(mode) {
|
||||
@ -46,7 +44,7 @@ int r_search_set_mode(struct r_search_t *s, int mode)
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct r_search_t *r_search_new(int mode)
|
||||
R_API struct r_search_t *r_search_new(int mode)
|
||||
{
|
||||
struct r_search_t *s = MALLOC_STRUCT(struct r_search_t);
|
||||
if (r_search_init(s, mode) == -1) {
|
||||
@ -56,14 +54,20 @@ struct r_search_t *r_search_new(int mode)
|
||||
return s;
|
||||
}
|
||||
|
||||
struct r_search_t *r_search_free(struct r_search_t *s)
|
||||
R_API void r_search_deinit(struct r_search_t *s)
|
||||
{
|
||||
// TODO: free linked lists and so on
|
||||
}
|
||||
|
||||
R_API struct r_search_t *r_search_free(struct r_search_t *s)
|
||||
{
|
||||
r_search_deinit(s);
|
||||
free(s);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* control */
|
||||
int r_search_begin(struct r_search_t *s)
|
||||
R_API int r_search_begin(struct r_search_t *s)
|
||||
{
|
||||
struct list_head *pos;
|
||||
|
||||
@ -85,7 +89,7 @@ int r_search_begin(struct r_search_t *s)
|
||||
}
|
||||
|
||||
// TODO: move into a plugin */
|
||||
int r_search_mybinparse_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len)
|
||||
R_API int r_search_mybinparse_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len)
|
||||
{
|
||||
struct list_head *pos;
|
||||
int i, count = 0;
|
||||
@ -117,13 +121,13 @@ int r_search_mybinparse_update(struct r_search_t *s, ut64 from, const ut8 *buf,
|
||||
return count;
|
||||
}
|
||||
|
||||
int r_search_set_pattern_size(struct r_search_t *s, int size)
|
||||
R_API int r_search_set_pattern_size(struct r_search_t *s, int size)
|
||||
{
|
||||
s->pattern_size = size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int r_search_set_callback(struct r_search_t *s, int (*callback)(struct r_search_kw_t *, void *, ut64), void *user)
|
||||
R_API int r_search_set_callback(struct r_search_t *s, int (*callback)(struct r_search_kw_t *, void *, ut64), void *user)
|
||||
{
|
||||
s->callback = callback;
|
||||
s->user = user;
|
||||
@ -131,7 +135,7 @@ int r_search_set_callback(struct r_search_t *s, int (*callback)(struct r_search_
|
||||
}
|
||||
|
||||
/* TODO: initialize update callback in _init */
|
||||
int r_search_update(struct r_search_t *s, ut64 *from, const ut8 *buf, ut32 len)
|
||||
R_API int r_search_update(struct r_search_t *s, ut64 *from, const ut8 *buf, long len)
|
||||
{
|
||||
int i, ret = 0;
|
||||
switch(s->mode) {
|
||||
@ -159,7 +163,7 @@ int r_search_update(struct r_search_t *s, ut64 *from, const ut8 *buf, ut32 len)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int r_search_update_i(struct r_search_t *s, ut64 from, const ut8 *buf, ut32 len)
|
||||
R_API int r_search_update_i(struct r_search_t *s, ut64 from, const ut8 *buf, long len)
|
||||
{
|
||||
return r_search_update(s, &from, buf, len);
|
||||
}
|
||||
@ -167,7 +171,7 @@ int r_search_update_i(struct r_search_t *s, ut64 from, const ut8 *buf, ut32 len)
|
||||
/* --- keywords --- */
|
||||
|
||||
/* string */
|
||||
int r_search_kw_add(struct r_search_t *s, const char *kw, const char *bm)
|
||||
R_API int r_search_kw_add(struct r_search_t *s, const char *kw, const char *bm)
|
||||
{
|
||||
struct r_search_kw_t *k = MALLOC_STRUCT(struct r_search_kw_t);
|
||||
int kwlen = strlen(kw)+1;
|
||||
@ -187,22 +191,24 @@ int r_search_kw_add(struct r_search_t *s, const char *kw, const char *bm)
|
||||
}
|
||||
|
||||
/* hexpair string */
|
||||
int r_search_kw_add_hex(struct r_search_t *s, const char *kw, const char *bm)
|
||||
R_API int r_search_kw_add_hex(struct r_search_t *s, const char *kw, const char *bm)
|
||||
{
|
||||
struct r_search_kw_t *k = MALLOC_STRUCT(struct r_search_kw_t);
|
||||
if (k == NULL)
|
||||
if (k == NULL) // is necessary to assert everywhere??
|
||||
return R_FALSE;
|
||||
strncpy(k->keyword, kw, sizeof(k->keyword));
|
||||
k->keyword_length = r_hex_str2bin(kw, k->bin_keyword);
|
||||
strncpy(k->binmask, bm, sizeof(k->binmask));
|
||||
k->binmask_length = r_hex_str2bin(bm, k->bin_binmask);
|
||||
if (bm) {
|
||||
strncpy(k->binmask, bm, sizeof(k->binmask));
|
||||
k->binmask_length = r_hex_str2bin(bm, k->bin_binmask);
|
||||
} else k->binmask[0] = k->binmask_length = 0;
|
||||
list_add(&(k->list), &(s->kws));
|
||||
k->kwidx = s->n_kws++;
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
/* raw bin */
|
||||
int r_search_kw_add_bin(struct r_search_t *s, const ut8 *kw, int kw_len, const ut8 *bm, int bm_len)
|
||||
R_API int r_search_kw_add_bin(struct r_search_t *s, const ut8 *kw, int kw_len, const ut8 *bm, int bm_len)
|
||||
{
|
||||
struct r_search_kw_t *k = MALLOC_STRUCT(struct r_search_kw_t);
|
||||
if (kw == NULL)
|
||||
@ -219,7 +225,7 @@ int r_search_kw_add_bin(struct r_search_t *s, const ut8 *kw, int kw_len, const u
|
||||
}
|
||||
|
||||
/* show keywords */
|
||||
struct r_search_kw_t *r_search_kw_list(struct r_search_t *s)
|
||||
R_API struct r_search_kw_t *r_search_kw_list(struct r_search_t *s)
|
||||
{
|
||||
struct list_head *pos;
|
||||
list_for_each_prev(pos, &s->kws) {
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "r_search.h"
|
||||
|
||||
// TODO: this file needs some love
|
||||
enum {
|
||||
ENCODING_ASCII = 0,
|
||||
ENCODING_CP850 = 1
|
||||
@ -11,15 +12,13 @@ static char *encodings[3] = { "ascii", "cp850", NULL };
|
||||
//static int encoding = ENCODING_ASCII; // default
|
||||
//encoding = resolve_encoding(config_get("cfg.encoding"));
|
||||
|
||||
int r_search_get_encoding(const char *name)
|
||||
R_API int r_search_get_encoding(const char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (name != NULL)
|
||||
for(i=0;encodings[i];i++)
|
||||
if (!strcasecmp(name, encodings[i]))
|
||||
return i;
|
||||
|
||||
return ENCODING_ASCII;
|
||||
}
|
||||
|
||||
@ -56,7 +55,7 @@ static int is_encoded(int encoding, unsigned char c)
|
||||
}
|
||||
|
||||
// XXX last char is lost :(
|
||||
int r_search_strings_update_char(const ut8 *buf, int min, int max, int enc, ut64 offset, const char *match)
|
||||
R_API int r_search_strings_update_char(const ut8 *buf, int min, int max, int enc, ut64 offset, const char *match)
|
||||
{
|
||||
int i = 0;
|
||||
static int widechar = 0;
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "r_search.h"
|
||||
#include <regex.h>
|
||||
|
||||
int r_search_xrefs_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len)
|
||||
R_API int r_search_xrefs_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len)
|
||||
{
|
||||
// ut8 code[1024];
|
||||
// ut8 mask[1024];
|
||||
|
@ -1,4 +1,4 @@
|
||||
* Pluggify!
|
||||
* Add w32 0x2e syscall support
|
||||
* include syscalls from file
|
||||
* import syscalls from file (ala r_reg)
|
||||
* Added documentation string per-syscall in r_syscall_list_t
|
||||
|
@ -63,7 +63,7 @@ namespace Radare {
|
||||
|
||||
public int init();
|
||||
public int list();
|
||||
public bool set(string name);
|
||||
public bool use(string name);
|
||||
// public bool set_arch(Asm.Arch arch);
|
||||
public bool set_bits(int bits);
|
||||
public bool set_syntax(Asm.Syntax syntax);
|
||||
|
@ -35,10 +35,10 @@ namespace Radare.Search {
|
||||
public unowned string binmask;
|
||||
public uint8 *bin_keyword;
|
||||
public uint8 *bin_binmask;
|
||||
public uint32 keyword_length;
|
||||
public uint32 binmask_length;
|
||||
public uint32 idx;
|
||||
public uint32 count;
|
||||
public int keyword_length;
|
||||
public int binmask_length;
|
||||
public int idx;
|
||||
public int count;
|
||||
}
|
||||
|
||||
public static delegate int Callback(Radare.Search.Keyword s, void *user, uint64 addr);
|
||||
|
@ -62,6 +62,21 @@ namespace Radare {
|
||||
public List<unowned G> iterator();
|
||||
}
|
||||
|
||||
/*
|
||||
[Compact]
|
||||
[CCode (cprefix="rarray_", cheader_filename="r_types.h", cname="rarray_t")]
|
||||
public static struct RarrayFoo<G> {
|
||||
[CCode (cname="rarray_next", generic_type_pos=2)]
|
||||
public bool next();
|
||||
[CCode (cname="")]
|
||||
public G @free(G arg);
|
||||
[CCode (cname="rarray_get", generic_type_pos=2)]
|
||||
public unowned G get();
|
||||
[CCode (cname="rarray_iterator")] //, generic_type_pos=2)]
|
||||
public RarrayFoo<G> iterator();
|
||||
}
|
||||
*/
|
||||
|
||||
[Compact]
|
||||
[CCode (cprefix="rarray_", cheader_filename="r_types.h", cname="void")]
|
||||
public static class Rarray<G> {
|
||||
@ -71,7 +86,7 @@ namespace Radare {
|
||||
public G @free(G arg);
|
||||
[CCode (cname="rarray_get", generic_type_pos=2)]
|
||||
public unowned G get();
|
||||
[CCode (cname="rarray_iterator")]
|
||||
public Rarray<unowned G> iterator();
|
||||
[CCode (cname="rarray_iterator")] //, generic_type_pos=2)]
|
||||
public Rarray<G> iterator();
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ public class AsmExample
|
||||
public static void main(string[] args)
|
||||
{
|
||||
Asm st = new Asm();
|
||||
st.set("asm_x86_olly");
|
||||
st.use("x86.olly");
|
||||
st.set_syntax(Asm.Syntax.INTEL);
|
||||
st.set_bits(32);
|
||||
st.set_big_endian(false);
|
||||
|
@ -18,8 +18,8 @@ public class SearchExample
|
||||
|
||||
stdout.printf("string: \"%s\"\n", buf);
|
||||
stdout.printf("search: \"%s\"\n", "lib");
|
||||
stdout.printf("length: %d\n", (int)buf.len());
|
||||
s.update_i(0LL, (uint8*)buf, (uint32)buf.len());
|
||||
stdout.printf("length: %ld\n", buf.len());
|
||||
s.update_i(0LL, (uint8*)buf, buf.len());
|
||||
s = null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user