mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-22 07:13:43 +00:00
Completely remove all references to list.h
This commit is contained in:
parent
f8df2d0655
commit
94d47c79bb
@ -4,7 +4,6 @@
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
#include <r_asm.h>
|
||||
#include <list.h>
|
||||
#include "../config.h"
|
||||
|
||||
R_LIB_VERSION (r_asm);
|
||||
|
@ -2,13 +2,11 @@
|
||||
|
||||
// TODO: dlopen library and show address
|
||||
|
||||
#include <r_bin.h>
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_list.h>
|
||||
#include <r_bin.h>
|
||||
#include <r_io.h>
|
||||
#include <list.h>
|
||||
#include "../config.h"
|
||||
|
||||
R_LIB_VERSION (r_bin);
|
||||
|
694
libr/bp/parser.c
694
libr/bp/parser.c
@ -1,694 +0,0 @@
|
||||
/* Copyright (C) 2007, 2008, 2009 - th0rpe <nopcode.org> */
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
#if 0
|
||||
extern struct regs_off roff[];
|
||||
extern unsigned long get_reg(char *reg);
|
||||
struct regs_off roff[] = {
|
||||
{"eax", R_EAX_OFF},
|
||||
{"ebx", R_EBX_OFF},
|
||||
{"ecx", R_ECX_OFF},
|
||||
{"edx", R_EDX_OFF},
|
||||
{"esi", R_ESI_OFF},
|
||||
{"edi", R_EDI_OFF},
|
||||
{"esp", R_ESP_OFF},
|
||||
{"ebp", R_EBP_OFF},
|
||||
{"eip", R_EIP_OFF},
|
||||
{"eflags", R_EFLAGS_OFF},
|
||||
|
||||
#if __WINDOWS__
|
||||
{"dr0", R_DR0_OFF},
|
||||
{"dr1", R_DR1_OFF},
|
||||
{"dr2", R_DR2_OFF},
|
||||
{"dr3", R_DR3_OFF},
|
||||
{"dr6", R_DR6_OFF},
|
||||
{"dr7", R_DR7_OFF},
|
||||
#endif
|
||||
{0, 0}
|
||||
};
|
||||
#endif
|
||||
|
||||
#define ishexa(c) ((c >='0' && c <= '9') || \
|
||||
(tolower(c) >='a' && tolower(c) <= 'f'))
|
||||
|
||||
/* skip \s\t and space characters */
|
||||
char skip_chars(const char **c)
|
||||
{
|
||||
for(;**c == ' ' || **c == '\t'; *c = *c + 1)
|
||||
;
|
||||
|
||||
return **c;
|
||||
}
|
||||
|
||||
int get_tok_op(const char **c, struct tok *t)
|
||||
{
|
||||
t->op = -1;
|
||||
|
||||
if(**c == '>') {
|
||||
if(*(*c + 1) != '=') {
|
||||
t->op = _OP_GT;
|
||||
*c = *c + 1;
|
||||
} else {
|
||||
t->op = _OP_GE;
|
||||
*c = *c + 2;
|
||||
}
|
||||
|
||||
} else if(**c == '=') {
|
||||
t->op = _OP_EQ;
|
||||
*c = *c + 1;
|
||||
|
||||
} else if(**c == '<') {
|
||||
if(*(*c + 1) == '=') {
|
||||
t->op = _OP_LE;
|
||||
*c = *c + 1;
|
||||
} else if(*(*c + 1) == '>'){
|
||||
t->op = _OP_NE;
|
||||
*c = *c + 2;
|
||||
} else {
|
||||
t->op = _OP_LT;
|
||||
*c = *c + 2;
|
||||
}
|
||||
}
|
||||
|
||||
if(t->type == MEM_TOK && t->op != _OP_EQ && t->op != _OP_NE)
|
||||
return -1;
|
||||
|
||||
return t->op;
|
||||
}
|
||||
|
||||
int get_tok_value(const char **c, struct tok *t)
|
||||
{
|
||||
char aux[512];
|
||||
char *val = *c;
|
||||
int len;
|
||||
|
||||
t->val = 0;
|
||||
|
||||
/* hexadecimal value */
|
||||
if(**c == '0' && *(*c + 1) == 'x') {
|
||||
for(*c = *c + 2; ishexa(**c); *c = *c + 1) ;
|
||||
|
||||
len = *c - val - 2;
|
||||
if( len <= 0 || (t->type == REG_TOK &&
|
||||
(len >> 1) > sizeof(unsigned long)) ||
|
||||
len + 2 >= sizeof(aux)) {
|
||||
|
||||
eprintf(":error token value too large,"
|
||||
" near %s\n", val);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* copy hexadecimal string */
|
||||
memcpy(aux, val, len + 2);
|
||||
aux[len + 2] = 0;
|
||||
|
||||
if(t->type == REG_TOK) {
|
||||
t->val = malloc(sizeof(unsigned long));
|
||||
if(!t->val) {
|
||||
perror(":error malloc tok value");
|
||||
return -1;
|
||||
}
|
||||
|
||||
*((unsigned long *)t->val) = get_math(aux);
|
||||
t->len = sizeof(unsigned long);
|
||||
} else {
|
||||
t-> val = malloc(len);
|
||||
if(!t->val) {
|
||||
perror(":error malloc tok value");
|
||||
return -1;
|
||||
}
|
||||
|
||||
t->len = hexstr2binstr((const char *)aux + 2,
|
||||
(unsigned char *)(aux + 2));
|
||||
memcpy(t->val, aux + 2, t->len);
|
||||
/*
|
||||
for(i = 0; i < t->len; i++) {
|
||||
printf("\\x%.2x\n", (unsigned char)t->val[i]);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/* decimal value */
|
||||
} else if(**c >= '0' && **c <= '9') {
|
||||
|
||||
for(*c = *c + 1; **c >= '0' && **c <= '9'; *c = *c + 1)
|
||||
;
|
||||
|
||||
len = *c - val;
|
||||
|
||||
/* copy decimal string */
|
||||
memcpy(aux, val, len);
|
||||
aux[len] = 0;
|
||||
|
||||
t->val = malloc(sizeof(unsigned long));
|
||||
if(!t->val) {
|
||||
eprintf(":error malloc tok value");
|
||||
return -1;
|
||||
}
|
||||
|
||||
*((unsigned long *)t->val) = get_math(aux);
|
||||
t->len = sizeof(unsigned long);
|
||||
|
||||
} else {
|
||||
/* TODO: get value from an external script */
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct tok* get_tok(const char **c)
|
||||
{
|
||||
struct tok *t = NULL;
|
||||
char aux[60];
|
||||
const char *val;
|
||||
int ret;
|
||||
|
||||
skip_chars((const char**)c);
|
||||
|
||||
/* register */
|
||||
if(**c == '%') {
|
||||
ret = get_reg(*c + 1);
|
||||
if(ret < 0) {
|
||||
eprintf(":error invalid register near ' %s '\n",
|
||||
*c);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*c = *c + strlen(roff[ret].reg) + 1;
|
||||
|
||||
t = (struct tok *)malloc(sizeof(*t));
|
||||
if(!t) {
|
||||
perror(":error malloc parse register");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
t->off = roff[ret].off;
|
||||
|
||||
skip_chars((const char**)c);
|
||||
|
||||
/* get operation */
|
||||
if(get_tok_op(c, t) == -1) {
|
||||
eprintf(":missing or invalid operation "
|
||||
"on register ' r%s '"
|
||||
"\n", roff[ret].reg);
|
||||
goto err_get_tok;
|
||||
}
|
||||
|
||||
skip_chars((const char**)c);
|
||||
|
||||
t->type = REG_TOK;
|
||||
|
||||
/* get value */
|
||||
if(get_tok_value(c, t) == -1) {
|
||||
eprintf(":missing or invalid value "
|
||||
"on register ' r%s '"
|
||||
"\n", roff[ret].reg);
|
||||
goto err_get_tok;
|
||||
}
|
||||
|
||||
/* memory */
|
||||
} if(**c == '[') {
|
||||
|
||||
*c = *c + 1;
|
||||
|
||||
skip_chars((const char **)c);
|
||||
|
||||
val = *c;
|
||||
|
||||
/* hexadecimal address */
|
||||
if(*val != '0' || *(val + 1) != 'x') {
|
||||
eprintf(":error invalid address near ' %s '\n",
|
||||
val);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*c = *c + 2;
|
||||
|
||||
for(; ishexa(**c) ; *c = *c + 1)
|
||||
;
|
||||
|
||||
ret = *c - val - 2;
|
||||
if((ret >> 1) > sizeof(unsigned long)) {
|
||||
eprintf(":error invalid address near ' %s '\n",
|
||||
val);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
skip_chars((const char **)c);
|
||||
|
||||
if(**c != ']') {
|
||||
eprintf(":error invalid sintax near ' %s '\n",
|
||||
*c);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(aux, val, ret + 2);
|
||||
aux[ret + 2] = 0;
|
||||
|
||||
t = (struct tok *)malloc(sizeof(*t));
|
||||
if(!t) {
|
||||
perror(":error malloc parse memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*c = *c + 1;
|
||||
|
||||
skip_chars((const char**)c);
|
||||
|
||||
/* get operation */
|
||||
if(get_tok_op(c, t) == -1) {
|
||||
eprintf(":missing or invalid operation "
|
||||
"near ' %s '\n"
|
||||
, *c);
|
||||
goto err_get_tok;
|
||||
}
|
||||
|
||||
skip_chars((const char**)c);
|
||||
|
||||
t->off = get_math(aux);
|
||||
t->type = MEM_TOK;
|
||||
|
||||
/* get value */
|
||||
if(get_tok_value(c, t) == -1) {
|
||||
fprintf(stderr, ":missing or invalid value "
|
||||
"near ' %s '\n"
|
||||
, *c);
|
||||
goto err_get_tok;
|
||||
}
|
||||
}
|
||||
|
||||
return t;
|
||||
|
||||
err_get_tok:
|
||||
if(t)
|
||||
free(t);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int get_log_op(const char **c, struct tok *t, int f)
|
||||
{
|
||||
if(strncmp(*c, "and", 3) == 0) {
|
||||
if(!f)
|
||||
return -1;
|
||||
|
||||
t->log_op = LOG_AND;
|
||||
|
||||
*c = *c + 3;
|
||||
} else if(strncmp(*c, "or", 2) == 0) {
|
||||
if(!f)
|
||||
return -1;
|
||||
|
||||
t->log_op = LOG_OR;
|
||||
|
||||
*c = *c + 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void free_cond(struct tok *group)
|
||||
{
|
||||
struct list_head *pos, *aux, *group_list;
|
||||
struct tok *t;
|
||||
|
||||
assert(group->type == GROUP_TOK);
|
||||
|
||||
group_list = &group->list;
|
||||
pos = group_list->next;
|
||||
|
||||
while(pos && pos != group_list)
|
||||
{
|
||||
t = (struct tok *)((char *)pos + \
|
||||
sizeof(struct list_head) - \
|
||||
sizeof(struct tok));
|
||||
|
||||
aux = pos->next;
|
||||
|
||||
if(t->type == GROUP_TOK)
|
||||
free_cond(t);
|
||||
|
||||
list_del(&(t->next));
|
||||
|
||||
if(t->val)
|
||||
free(t->val);
|
||||
|
||||
free(t);
|
||||
|
||||
pos = aux;
|
||||
}
|
||||
|
||||
free(group);
|
||||
}
|
||||
|
||||
/* TODO: free list when error */
|
||||
struct tok* process_cond(const char **c, int top)
|
||||
{
|
||||
struct tok *t = NULL;
|
||||
struct tok *group;
|
||||
char *val;
|
||||
int f = 0;
|
||||
|
||||
val = *c;
|
||||
|
||||
/*printf("enter condition: %s\n", val); */
|
||||
|
||||
|
||||
group = (struct tok *)malloc(sizeof(*group));
|
||||
if(!group) {
|
||||
perror(":error malloc group token");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* initialize list group */
|
||||
INIT_LIST_HEAD(&group->list);
|
||||
group->type = GROUP_TOK;
|
||||
group->log_op = 0;
|
||||
|
||||
for(;**c;) {
|
||||
|
||||
skip_chars((const char **)c);
|
||||
|
||||
if(get_log_op(c, t, f) < 0) {
|
||||
eprintf(":error missing token or "
|
||||
" operator not valid near ' %s '\n", val);
|
||||
goto err_cond;
|
||||
}
|
||||
|
||||
skip_chars((const char **)c);
|
||||
|
||||
/* enter condition */
|
||||
if(**c == '(') {
|
||||
*c = *c + 1;
|
||||
t = process_cond(c, 0);
|
||||
if(!t)
|
||||
goto err_cond;
|
||||
|
||||
list_add(&t->next, &group->list);
|
||||
|
||||
if(**c != ')') {
|
||||
fprintf(stderr, ":error not closed condition "
|
||||
" near ' %s '\n",
|
||||
val);
|
||||
goto err_cond;
|
||||
}
|
||||
|
||||
*c = *c + 1;
|
||||
f = 1;
|
||||
|
||||
/* exit condition */
|
||||
} else if(**c == ')') {
|
||||
if(top != 0) {
|
||||
fprintf(stderr, ":error not opened "
|
||||
"condition near ' %s '\n",
|
||||
val);
|
||||
goto err_cond;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
/* get token */
|
||||
} else {
|
||||
t = get_tok(c);
|
||||
if(!t)
|
||||
goto err_cond;
|
||||
|
||||
t->log_op = 0;
|
||||
|
||||
/* add token at group list */
|
||||
list_add(&t->next, &group->list);
|
||||
|
||||
f = 2;
|
||||
}
|
||||
}
|
||||
|
||||
/* printf("exit condition group\n"); */
|
||||
|
||||
return group;
|
||||
|
||||
err_cond:
|
||||
|
||||
free_cond(group);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int eval_token_reg(struct tok *t)
|
||||
{
|
||||
unsigned long reg_val;
|
||||
unsigned long val;
|
||||
int op, ret;
|
||||
|
||||
if (!config.debug)
|
||||
return 0;
|
||||
|
||||
op = t->op;
|
||||
reg_val = debug_get_regoff(&WS(regs), t->off);
|
||||
val = *(unsigned long *)(t->val);
|
||||
|
||||
switch(op) {
|
||||
case _OP_LE:
|
||||
ret = (reg_val <= val);
|
||||
break;
|
||||
|
||||
case _OP_LT:
|
||||
ret = (reg_val < val);
|
||||
break;
|
||||
|
||||
case _OP_EQ:
|
||||
ret = (reg_val == val);
|
||||
break;
|
||||
|
||||
case _OP_NE:
|
||||
ret = (reg_val != val);
|
||||
break;
|
||||
|
||||
case _OP_GE:
|
||||
ret = (reg_val >= val);
|
||||
break;
|
||||
|
||||
case _OP_GT:
|
||||
default:
|
||||
ret = (reg_val >= val);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int eval_token_mem(struct tok *t)
|
||||
{
|
||||
unsigned char rvalue[512];
|
||||
int op = t->op;
|
||||
int ret;
|
||||
|
||||
if (!config.debug)
|
||||
return 0;
|
||||
|
||||
/* printf("read_at: 0x%x %d\n", t->off, t->len); */
|
||||
if(debug_read_at(ps.tid, rvalue, t->len, t->off) <= 0)
|
||||
return 0;
|
||||
/*
|
||||
printf("val: %x %x %x %x %x %x\n", rvalue[0], rvalue[1], rvalue[2],
|
||||
t->val[0], t->val[1], t->val[2]);
|
||||
printf("memcmp: %x\n", memcmp(t->val, rvalue, t->len));
|
||||
*/
|
||||
|
||||
switch(op) {
|
||||
case _OP_EQ:
|
||||
ret = (memcmp(t->val, rvalue, t->len) == 0);
|
||||
break;
|
||||
case _OP_NE:
|
||||
default:
|
||||
ret = (memcmp(t->val, rvalue, t->len) != 0);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int eval_token(struct tok *t)
|
||||
{
|
||||
int type = t->type;
|
||||
int ret;
|
||||
|
||||
switch(type) {
|
||||
/* token register */
|
||||
case REG_TOK:
|
||||
ret = eval_token_reg(t);
|
||||
break;
|
||||
/* token memory */
|
||||
case MEM_TOK:
|
||||
default:
|
||||
ret = eval_token_mem(t);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int eval_cond(struct tok *group)
|
||||
{
|
||||
struct list_head *pos;
|
||||
int log_op = 0, val_cond = 1;
|
||||
|
||||
assert(group->type == GROUP_TOK);
|
||||
|
||||
/* printf("EVAL enter group\n"); */
|
||||
|
||||
list_for_each_prev(pos, &group->list) {
|
||||
|
||||
struct tok *t = (struct tok *)((char *)pos + \
|
||||
sizeof(struct list_head) - \
|
||||
sizeof(struct tok));
|
||||
|
||||
/* not evalue next 'or' conditions
|
||||
when the condition is true yet or
|
||||
the condition is false and exist next 'and'
|
||||
conditions
|
||||
*/
|
||||
|
||||
if( (val_cond && log_op == LOG_OR) ||
|
||||
(!val_cond && log_op == LOG_AND))
|
||||
continue;
|
||||
|
||||
if(t->log_op)
|
||||
log_op = t->log_op;
|
||||
|
||||
switch(t->type) {
|
||||
|
||||
case GROUP_TOK:
|
||||
val_cond = eval_cond(t);
|
||||
break;
|
||||
default:
|
||||
val_cond = eval_token(t);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* printf("EVAL exit group\n"); */
|
||||
|
||||
return val_cond;
|
||||
}
|
||||
|
||||
|
||||
void print_token(struct tok *t)
|
||||
{
|
||||
char *op;
|
||||
char *log_op;
|
||||
|
||||
switch(t->op) {
|
||||
case _OP_LE:
|
||||
op = "<=";
|
||||
break;
|
||||
|
||||
case _OP_LT:
|
||||
op = "<";
|
||||
break;
|
||||
|
||||
case _OP_EQ:
|
||||
op = "=";
|
||||
break;
|
||||
|
||||
case _OP_NE:
|
||||
op = "<>";
|
||||
break;
|
||||
|
||||
case _OP_GE:
|
||||
op = ">=";
|
||||
break;
|
||||
|
||||
case _OP_GT:
|
||||
op = ">";
|
||||
break;
|
||||
default:
|
||||
op = "none";
|
||||
}
|
||||
|
||||
if(t->log_op == LOG_OR)
|
||||
log_op = "or";
|
||||
else if(t->log_op == LOG_AND)
|
||||
log_op = "and";
|
||||
else
|
||||
log_op = "";
|
||||
|
||||
if(t->type == REG_TOK) {
|
||||
printf( "register off %i\n"
|
||||
"logical op %s\n"
|
||||
"operator %s\n"
|
||||
"value %x\n"
|
||||
,(unsigned int)t->off
|
||||
,log_op
|
||||
,op
|
||||
,(unsigned int)*((unsigned long *)t->val)
|
||||
);
|
||||
} else if(t->type == MEM_TOK) {
|
||||
printf( "memory %x\n"
|
||||
"logical op %s\n"
|
||||
"operator %s\n"
|
||||
"val %x\n"
|
||||
"len %d\n"
|
||||
,(unsigned int)t->off
|
||||
,log_op
|
||||
,op
|
||||
,(unsigned int)*((unsigned long *)t->val)
|
||||
,(unsigned int)t->len
|
||||
);
|
||||
} else {
|
||||
printf(" operator group %s\n", log_op);
|
||||
}
|
||||
}
|
||||
|
||||
void print_expr(struct tok *group)
|
||||
{
|
||||
struct list_head *pos;
|
||||
|
||||
assert(group->type == GROUP_TOK);
|
||||
|
||||
printf("enter group\n");
|
||||
|
||||
list_for_each_prev(pos, &group->list) {
|
||||
struct tok *t = (struct tok *)((char *)pos + \
|
||||
sizeof(struct list_head) - \
|
||||
sizeof(struct tok));
|
||||
|
||||
switch(t->type) {
|
||||
case GROUP_TOK:
|
||||
print_token(t);
|
||||
print_expr(t);
|
||||
break;
|
||||
|
||||
default:
|
||||
print_token(t);
|
||||
}
|
||||
}
|
||||
|
||||
printf("exit group\n");
|
||||
}
|
||||
|
||||
struct tok* parse_cond(const char *cond)
|
||||
{
|
||||
return process_cond(&cond, 1);
|
||||
}
|
||||
#if 0
|
||||
void test_parser()
|
||||
{
|
||||
struct tok *gr;
|
||||
char *v;
|
||||
char *p = "reip >= 0x01020304 and rebx = 15 "
|
||||
"and ([0x80456] = 10 or reip = 5) "
|
||||
"and ([0xff456] = 1 and reip = 2) or "
|
||||
"(reax <> 10 and recx = 4)"
|
||||
;
|
||||
v = p;
|
||||
gr = process_cond(&p, 1);
|
||||
if(gr) {
|
||||
print_expr(gr);
|
||||
printf("cond: %s\n", v);
|
||||
printf("eval cond: %d\n", eval_cond(gr));
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,50 +0,0 @@
|
||||
#ifndef PARSER_H
|
||||
#define PARSER_H
|
||||
#include "../list.h"
|
||||
|
||||
struct regs_off {
|
||||
char *reg;
|
||||
int off; // XXX 32 bit only !? wtf?
|
||||
};
|
||||
|
||||
/* token types */
|
||||
enum {
|
||||
GROUP_TOK = 0,
|
||||
REG_TOK,
|
||||
MEM_TOK
|
||||
};
|
||||
|
||||
/* token structure */
|
||||
struct tok {
|
||||
ut64 off;
|
||||
int type;
|
||||
int op, log_op;
|
||||
char *val;
|
||||
int len;
|
||||
|
||||
struct list_head list;
|
||||
struct list_head next;
|
||||
};
|
||||
|
||||
/* arithmetical operations */
|
||||
enum {
|
||||
_OP_LT = 1,
|
||||
_OP_LE,
|
||||
_OP_EQ,
|
||||
_OP_NE,
|
||||
_OP_GE,
|
||||
_OP_GT
|
||||
};
|
||||
|
||||
/* logical operations */
|
||||
enum {
|
||||
LOG_OR = 1,
|
||||
LOG_AND
|
||||
};
|
||||
|
||||
char skip_chars(const char **c);
|
||||
struct tok* parse_cond(const char *cond);
|
||||
int eval_cond(struct tok *group);
|
||||
void free_cond(struct tok *group);
|
||||
|
||||
#endif
|
@ -1,28 +1,27 @@
|
||||
/* radare - LGPL - Copyright 2009-2014 pancake */
|
||||
/* radare - LGPL - Copyright 2009-2016 pancake */
|
||||
|
||||
#include <r_debug.h>
|
||||
#include "../config.h"
|
||||
|
||||
static RDebugPlugin *debug_static_plugins[] =
|
||||
{ R_DEBUG_STATIC_PLUGINS };
|
||||
static RDebugPlugin *debug_static_plugins[] = {
|
||||
R_DEBUG_STATIC_PLUGINS
|
||||
};
|
||||
|
||||
R_API void r_debug_plugin_init(RDebug *dbg) {
|
||||
RDebugPlugin *static_plugin;
|
||||
int i;
|
||||
|
||||
INIT_LIST_HEAD (&dbg->plugins);
|
||||
for (i=0; debug_static_plugins[i]; i++) {
|
||||
static_plugin = R_NEW (RDebugPlugin);
|
||||
memcpy (static_plugin, debug_static_plugins[i], sizeof (RDebugPlugin));
|
||||
r_debug_plugin_add (dbg, static_plugin);
|
||||
dbg->plugins = r_list_new ();
|
||||
for (i = 0; debug_static_plugins[i]; i++) {
|
||||
RDebugPlugin *p = R_NEW (RDebugPlugin);
|
||||
memcpy (p, debug_static_plugins[i], sizeof (RDebugPlugin));
|
||||
r_debug_plugin_add (dbg, p);
|
||||
}
|
||||
}
|
||||
|
||||
R_API bool r_debug_use(RDebug *dbg, const char *str) {
|
||||
struct list_head *pos;
|
||||
if (str) {
|
||||
list_for_each_prev (pos, &dbg->plugins) {
|
||||
RDebugPlugin *h = list_entry (pos, RDebugPlugin, list);
|
||||
RDebugPlugin *h;
|
||||
RListIter *iter;
|
||||
r_list_foreach (dbg->plugins, iter, h) {
|
||||
if (h->name && !strcmp (str, h->name)) {
|
||||
dbg->h = h;
|
||||
if (dbg->anal && dbg->anal->cur)
|
||||
@ -54,11 +53,11 @@ R_API bool r_debug_use(RDebug *dbg, const char *str) {
|
||||
R_API int r_debug_plugin_list(RDebug *dbg, int mode) {
|
||||
char spaces[16];
|
||||
int count = 0;
|
||||
struct list_head *pos;
|
||||
memset (spaces, ' ', 15);
|
||||
spaces[15] = 0;
|
||||
list_for_each_prev (pos, &dbg->plugins) {
|
||||
RDebugPlugin *h = list_entry(pos, RDebugPlugin, list);
|
||||
RDebugPlugin *h;
|
||||
RListIter *iter;
|
||||
r_list_foreach (dbg->plugins, iter, h) {
|
||||
int sp = 8-strlen (h->name);
|
||||
spaces[sp] = 0;
|
||||
if (mode == 'q') {
|
||||
@ -75,7 +74,9 @@ R_API int r_debug_plugin_list(RDebug *dbg, int mode) {
|
||||
}
|
||||
|
||||
R_API bool r_debug_plugin_add(RDebug *dbg, RDebugPlugin *foo) {
|
||||
if (!dbg || !foo || !foo->name) return false;
|
||||
list_add_tail (&(foo->list), &(dbg->plugins));
|
||||
if (!dbg || !foo || !foo->name) {
|
||||
return false;
|
||||
}
|
||||
r_list_append (dbg->plugins, foo);
|
||||
return true;
|
||||
}
|
||||
|
@ -1,230 +0,0 @@
|
||||
#ifndef LIST_H
|
||||
#define LIST_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Simple doubly linked list implementation.
|
||||
*
|
||||
* Some of the internal functions ("__xxx") are useful when
|
||||
* manipulating whole lists rather than single entries, as
|
||||
* sometimes we already know the next/prev entries and we can
|
||||
* generate better code by using them directly rather than
|
||||
* using the generic single-entry routines.
|
||||
*/
|
||||
|
||||
struct list_head {
|
||||
struct list_head *next, *prev;
|
||||
};
|
||||
|
||||
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
||||
|
||||
#define LIST_HEAD(name) \
|
||||
struct list_head name = LIST_HEAD_INIT(name)
|
||||
|
||||
|
||||
#define INIT_LIST_HEAD(ptr) do { \
|
||||
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Insert a new entry between two known consecutive entries.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_add(struct list_head *entry,
|
||||
struct list_head *prev,
|
||||
struct list_head *next)
|
||||
{
|
||||
next->prev = entry;
|
||||
entry->next = next;
|
||||
entry->prev = prev;
|
||||
prev->next = entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add - add a new entry
|
||||
* @entry: new entry to be added
|
||||
* @head: list head to add it after
|
||||
*
|
||||
* Insert a new entry after the specified head.
|
||||
* This is good for implementing stacks.
|
||||
*/
|
||||
static inline void list_add(struct list_head *entry, struct list_head *head)
|
||||
{
|
||||
__list_add(entry, head, head->next);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add_tail - add a new entry
|
||||
* @entry: new entry to be added
|
||||
* @head: list head to add it before
|
||||
*
|
||||
* Insert a new entry before the specified head.
|
||||
* This is useful for implementing queues.
|
||||
*/
|
||||
static inline void list_add_tail(struct list_head *entry, struct list_head *head)
|
||||
{
|
||||
__list_add(entry, head->prev, head);
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete a list entry by making the prev/next entries
|
||||
* point to each other.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_del(struct list_head *prev, struct list_head *next)
|
||||
{
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del - deletes entry from list.
|
||||
* @entry: the element to delete from the list.
|
||||
* Note: list_empty on entry does not return true after this, the entry is in an undefined state.
|
||||
*/
|
||||
static inline void list_del(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
entry->next = (struct list_head*) 0;
|
||||
entry->prev = (struct list_head*) 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del_init - deletes entry from list and reinitialize it.
|
||||
* @entry: the element to delete from the list.
|
||||
*/
|
||||
static inline void list_del_init(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
INIT_LIST_HEAD(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_move - delete from one list and add as another's head
|
||||
* @list: the entry to move
|
||||
* @head: the head that will precede our entry
|
||||
*/
|
||||
static inline void list_move(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
__list_del(list->prev, list->next);
|
||||
list_add(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_move_tail - delete from one list and add as another's tail
|
||||
* @list: the entry to move
|
||||
* @head: the head that will follow our entry
|
||||
*/
|
||||
static inline void list_move_tail(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
__list_del(list->prev, list->next);
|
||||
list_add_tail(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_empty - tests whether a list is empty
|
||||
* @head: the list to test.
|
||||
*/
|
||||
static inline int list_empty(struct list_head *head)
|
||||
{
|
||||
return head->next == head;
|
||||
}
|
||||
|
||||
static inline void __list_splice(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
struct list_head *first = list->next;
|
||||
struct list_head *last = list->prev;
|
||||
struct list_head *at = head->next;
|
||||
|
||||
first->prev = head;
|
||||
head->next = first;
|
||||
|
||||
last->next = at;
|
||||
at->prev = last;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice - join two lists
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*/
|
||||
static inline void list_splice(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list))
|
||||
__list_splice(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice_init - join two lists and reinitialise the emptied list.
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*
|
||||
* The list at @list is reinitialised
|
||||
*/
|
||||
static inline void list_splice_init(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list)) {
|
||||
__list_splice(list, head);
|
||||
INIT_LIST_HEAD(list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* list_entry - get the struct for this entry
|
||||
* @ptr: the &struct list_head pointer.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_entry(ptr, type, member) \
|
||||
((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
|
||||
|
||||
/**
|
||||
* list_for_each - iterate over a list
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); pos = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_prev - iterate over a list backwards
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_prev(pos, head) \
|
||||
for (pos = (head)->prev; pos != (head); pos = pos->prev)
|
||||
|
||||
/**
|
||||
* list_for_each_safe - iterate over a list safe against removal of list entry
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @n: another &struct list_head to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_safe(pos, n, head) \
|
||||
for (pos = (head)->next, n = pos->next; pos != (head); \
|
||||
pos = n, n = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_entry - iterate over list of given type
|
||||
* @pos: the type * to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
|
||||
#define list_for_each_entry(pos, head, member) \
|
||||
for (pos = list_entry((head)->next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.next, typeof(*pos), member)) \
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -608,7 +608,6 @@ typedef struct r_anal_t {
|
||||
struct r_anal_esil_t *esil;
|
||||
struct r_anal_plugin_t *cur;
|
||||
RAnalRange *limit;
|
||||
//struct list_head anals; // TODO: Reimplement with RList
|
||||
RList *plugins;
|
||||
Sdb *sdb_xrefs;
|
||||
Sdb *sdb_types;
|
||||
@ -1100,7 +1099,6 @@ typedef struct r_anal_plugin_t {
|
||||
RAnalDiffBBCallback diff_bb;
|
||||
RAnalDiffFcnCallback diff_fcn;
|
||||
RAnalDiffEvalCallback diff_eval;
|
||||
struct list_head list;
|
||||
|
||||
RAnalIsValidOffsetCB is_valid_offset;
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_bin.h> // only for binding, no hard dep required
|
||||
#include <list.h>
|
||||
#include <r_util.h>
|
||||
#include <r_parse.h>
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
#include "list.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#include "r_types.h"
|
||||
#include "r_util.h"
|
||||
#include "list.h" // TODO: port to r_list
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include <r_db.h>
|
||||
#include <r_io.h>
|
||||
#include <r_syscall.h>
|
||||
#include "list.h"
|
||||
|
||||
#include <r_config.h>
|
||||
#include "r_bind.h"
|
||||
@ -230,7 +229,7 @@ typedef struct r_debug_t {
|
||||
RIOBind iob;
|
||||
|
||||
struct r_debug_plugin_t *h;
|
||||
struct list_head plugins;
|
||||
RList *plugins;
|
||||
|
||||
RAnal *anal;
|
||||
RList *maps; // <RDebugMap>
|
||||
@ -318,7 +317,6 @@ typedef struct r_debug_plugin_t {
|
||||
int (*drx)(RDebug *dbg, int n, ut64 addr, int size, int rwx, int g);
|
||||
RDebugDescPlugin desc;
|
||||
// TODO: use RList here
|
||||
struct list_head list;
|
||||
} RDebugPlugin;
|
||||
|
||||
// TODO: rename to r_debug_process_t ? maybe a thread too ?
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2015 - pancake, nibble */
|
||||
/* radare - LGPL - Copyright 2009-2016 - pancake, nibble */
|
||||
|
||||
#ifndef R2_PARSE_H
|
||||
#define R2_PARSE_H
|
||||
@ -6,7 +6,6 @@
|
||||
#include <r_types.h>
|
||||
#include <r_flag.h>
|
||||
#include <r_anal.h>
|
||||
#include <list.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -42,7 +41,6 @@ typedef struct r_parse_plugin_t {
|
||||
int (*filter)(RParse *p, RFlag *f, char *data, char *str, int len, bool big_endian);
|
||||
bool (*varsub)(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len);
|
||||
int (*replace)(int argc, const char *argv[], char *newstr);
|
||||
struct list_head list;
|
||||
} RParsePlugin;
|
||||
|
||||
#ifdef R_API
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
#include <list.h>
|
||||
|
||||
R_LIB_VERSION_HEADER (r_reg);
|
||||
|
||||
|
@ -9,7 +9,6 @@ extern "C" {
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_db.h>
|
||||
#include <list.h>
|
||||
|
||||
R_LIB_VERSION_HEADER (r_syscall);
|
||||
|
||||
@ -56,7 +55,6 @@ typedef struct r_syscall_plugin_t {
|
||||
int bits;
|
||||
int nargs;
|
||||
struct r_syscall_args_t *args;
|
||||
struct list_head list;
|
||||
} RSyscallPlugin;
|
||||
|
||||
typedef struct r_syscall_arch_plugin_t {
|
||||
@ -66,7 +64,6 @@ typedef struct r_syscall_arch_plugin_t {
|
||||
int *bits;
|
||||
int nargs;
|
||||
struct r_syscall_args_t **args;
|
||||
struct list_head list;
|
||||
} RSyscallArchPlugin;
|
||||
|
||||
#ifdef R_API
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include <r_regex.h>
|
||||
#include <r_list.h> // radare linked list
|
||||
#include <r_flist.h> // radare fixed pointer array iterators
|
||||
#include <list.h> // kernel linked list
|
||||
#include <r_th.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/time.h>
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
#include "r_io.h"
|
||||
#include "../config.h"
|
||||
#include "list.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static RIOPlugin *io_static_plugins[] = {
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_parse.h>
|
||||
#include <list.h>
|
||||
#include "../config.h"
|
||||
|
||||
R_LIB_VERSION (r_parse);
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include <r_reg.h>
|
||||
#include <r_util.h>
|
||||
#include <list.h>
|
||||
|
||||
R_LIB_VERSION (r_reg);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user