More indent fixes

This commit is contained in:
pancake 2015-12-09 00:41:44 +01:00
parent cfb03d3772
commit 92c1631a06
10 changed files with 171 additions and 373 deletions

View File

@ -2,6 +2,7 @@ Language: Cpp
MaxEmptyLinesToKeep: 1
SpaceBeforeParens: Always
SpaceInEmptyParentheses: false
SpacesInContainerLiterals: true
BasedOnStyle: LLVM
ContinuationIndentWidth: 8
IndentCaseLabels: false

View File

@ -597,7 +597,7 @@ R_API int r_bin_reload(RBin *bin, RIODesc *desc, ut64 baseaddr) {
}
buf_bytes = iob->desc_read (io, tdesc, &len_bytes);
iob->desc_close (io, tdesc);
} else if (sz == UT64_MAX || sz > (64 * 1024 * 1024)) { // too big, probably wrong
} else if (sz == UT64_MAX || sz > (64 * 1024 * 1024)) { // too big, probably wrong
eprintf ("Too big\n");
return false;
} else {

View File

@ -3,7 +3,7 @@
#include "r_config.h"
#include "r_util.h" // r_str_hash, r_str_chop, ...
R_API RConfigNode* r_config_node_new(const char *name, const char *value) {
R_API RConfigNode *r_config_node_new(const char *name, const char *value) {
RConfigNode *node;
if (!name || !*name)
return NULL;
@ -13,11 +13,12 @@ R_API RConfigNode* r_config_node_new(const char *name, const char *value) {
node->hash = r_str_hash (name);
node->value = strdup (value? value: "");
node->flags = CN_RW | CN_STR;
node->i_value = r_num_get (NULL, value);;
node->i_value = r_num_get (NULL, value);
;
return node;
}
R_API RConfigNode *r_config_node_clone (RConfigNode *n) {
R_API RConfigNode *r_config_node_clone(RConfigNode *n) {
RConfigNode *cn = R_NEW0 (RConfigNode);
cn->name = strdup (n->name);
cn->desc = n->desc? strdup (n->desc): NULL;
@ -29,8 +30,8 @@ R_API RConfigNode *r_config_node_clone (RConfigNode *n) {
return cn;
}
R_API void r_config_node_free (void *n) {
RConfigNode *node = (RConfigNode*)n;
R_API void r_config_node_free(void *n) {
RConfigNode *node = (RConfigNode *)n;
if (!node) return;
free (node->name);
free (node->desc);
@ -57,7 +58,7 @@ R_API void r_config_list(RConfig *cfg, const char *str, int rad) {
r_list_foreach (cfg->nodes, iter, node) {
if (!str || (str && (!strncmp (str, node->name, len))))
cfg->cb_printf ("%s%s = %s%s\n", pfx,
node->name, node->value, sfx);
node->name, node->value, sfx);
}
break;
case 2:
@ -65,7 +66,7 @@ R_API void r_config_list(RConfig *cfg, const char *str, int rad) {
if (!str || (str && (!strncmp (str, node->name, len))))
if (!str || !strncmp (str, node->name, len))
cfg->cb_printf ("%20s: %s\n", node->name,
node->desc?node->desc:"");
node->desc? node->desc: "");
}
break;
case 'j':
@ -77,10 +78,9 @@ R_API void r_config_list(RConfig *cfg, const char *str, int rad) {
if (node->flags & CN_BOOL || node->flags & CN_INT || node->flags & CN_OFFT) {
if (!val) val = "0";
cfg->cb_printf ("\"%s\":%s",
node->name, val);
} else
cfg->cb_printf ("\"%s\":\"%s\"",
node->name, val);
node->name, val);
} else cfg->cb_printf ("\"%s\":\"%s\"",
node->name, val);
if (iter->n)
cfg->cb_printf (",");
}
@ -96,7 +96,7 @@ R_API RConfigNode *r_config_node_get(RConfig *cfg, const char *name) {
return r_hashtable_lookup (cfg->ht, r_str_hash (name));
}
R_API int r_config_set_getter (RConfig *cfg, const char *key, RConfigCallback cb) {
R_API int r_config_set_getter(RConfig *cfg, const char *key, RConfigCallback cb) {
RConfigNode *node = r_config_node_get (cfg, key);
if (node) {
node->getter = cb;
@ -105,7 +105,7 @@ R_API int r_config_set_getter (RConfig *cfg, const char *key, RConfigCallback cb
return 0;
}
R_API int r_config_set_setter (RConfig *cfg, const char *key, RConfigCallback cb) {
R_API int r_config_set_setter(RConfig *cfg, const char *key, RConfigCallback cb) {
RConfigNode *node = r_config_node_get (cfg, key);
if (node) {
node->setter = cb;
@ -120,9 +120,9 @@ R_API const char *r_config_get(RConfig *cfg, const char *name) {
if (node->getter) node->getter (cfg->user, node);
cfg->last_notfound = 0;
if (node->flags & CN_BOOL)
return (const char *) (((!strcmp ("true", node->value))
|| (!strcmp ("1", node->value)))?
(const char *)"true" : "false"); // XXX (char*)1 is ugly
return (const char *)(((!strcmp ("true", node->value)) || (!strcmp ("1", node->value))) ?
(const char *)"true" :
"false"); // XXX (char*)1 is ugly
return node->value;
} else {
eprintf ("r_config_get: variable '%s' not found\n", name);
@ -183,16 +183,15 @@ R_API RConfigNode *r_config_set(RConfig *cfg, const char *name, const char *valu
oi = node->i_value;
if (node->value) {
ov = strdup (node->value);
}
else {
} else {
free (node->value);
node->value = strdup ("");
}
if (node->flags & CN_BOOL) {
int b = (!strcmp (value,"true") || !strcmp (value,"1"));
node->i_value = (ut64)(b == 0) ? 0 : 1;
int b = (!strcmp (value, "true") || !strcmp (value, "1"));
node->i_value = (ut64) (b == 0)? 0: 1;
free (node->value);
node->value = strdup (b ? "true" : "false");
node->value = strdup (b? "true": "false");
} else {
if (value == NULL) {
free (node->value);
@ -204,8 +203,7 @@ R_API RConfigNode *r_config_set(RConfig *cfg, const char *name, const char *valu
if (*value >= '0' && *value <= '9') {
if (strchr (value, '/')) {
node->i_value = r_num_get (cfg->num, value);
}
else {
} else {
node->i_value = r_num_math (cfg->num, value);
}
} else {
@ -241,7 +239,7 @@ R_API RConfigNode *r_config_set(RConfig *cfg, const char *name, const char *valu
if (ret == false) {
if (oi != UT64_MAX) node->i_value = oi;
free (node->value);
node->value = strdup (ov ? ov : "");
node->value = strdup (ov? ov: "");
free (ov);
return NULL;
}
@ -295,17 +293,18 @@ R_API RConfigNode *r_config_set_i(RConfig *cfg, const char *name, const ut64 i)
free (node->value);
}
if (node->flags & CN_BOOL) {
node->value = strdup (r_str_bool(i));
node->value = strdup (r_str_bool (i));
} else {
snprintf (buf, sizeof (buf)-1, "%"PFMT64d, i);
snprintf (buf, sizeof (buf) - 1, "%" PFMT64d, i);
node->value = strdup (buf);
}
//node->flags = CN_RW | CN_INT;
node->i_value = i;
} else {
if (!cfg->lock) {
if (i<1024) snprintf (buf, sizeof (buf), "%"PFMT64d"", i);
else snprintf (buf, sizeof (buf), "0x%08"PFMT64x"", i);
if (i < 1024)
snprintf (buf, sizeof (buf), "%" PFMT64d "", i);
else snprintf (buf, sizeof (buf), "0x%08" PFMT64x "", i);
node = r_config_node_new (name, buf);
if (!node) return NULL;
node->flags = CN_RW | CN_OFFT;
@ -335,7 +334,7 @@ R_API int r_config_eval(RConfig *cfg, const char *str) {
char *ptr, *a, *b, name[1024];
unsigned int len;
if (!str || !cfg) return false;
len = strlen (str)+1;
len = strlen (str) + 1;
if (len >= sizeof (name)) return false;
memcpy (name, str, len);
str = r_str_chop (name);
@ -361,14 +360,14 @@ R_API int r_config_eval(RConfig *cfg, const char *str) {
r_config_set (cfg, a, b);
} else {
char *foo = r_str_chop (name);
if (foo[strlen (foo) - 1]=='.') {
if (foo[strlen (foo) - 1] == '.') {
r_config_list (cfg, name, 0);
return false;
} else {
/* get */
const char *str = r_config_get(cfg, foo);
const char *str = r_config_get (cfg, foo);
if (str) cfg->cb_printf ("%s\n",
(((int)(size_t)str) == 1) ? "true" : str);
(((int)(size_t)str) == 1)? "true": str);
}
}
return true;
@ -383,7 +382,7 @@ R_API void r_config_lock(RConfig *cfg, int l) {
cfg->lock = l;
}
R_API int r_config_readonly (RConfig *cfg, const char *key) {
R_API int r_config_readonly(RConfig *cfg, const char *key) {
RConfigNode *n = r_config_node_get (cfg, key);
if (!n) return false;
n->flags |= CN_RO;
@ -404,7 +403,7 @@ R_API RConfig *r_config_new(void *user) {
return cfg;
}
R_API RConfig *r_config_clone (RConfig *cfg) {
R_API RConfig *r_config_clone(RConfig *cfg) {
RListIter *iter;
RConfigNode *node;
RConfig *c = r_config_new (cfg->user);
@ -431,5 +430,5 @@ R_API int r_config_free(RConfig *cfg) {
R_API void r_config_visual_hit_i(RConfig *cfg, const char *name, int delta) {
RConfigNode *node = r_config_node_get (cfg, name);
if (node && (node->flags & CN_INT || node->flags & CN_OFFT))
r_config_set_i (cfg, name, r_config_get_i (cfg, name)+delta);
r_config_set_i (cfg, name, r_config_get_i (cfg, name) + delta);
}

View File

@ -1,202 +0,0 @@
/* Like emenu but for real */
void config_visual_menu()
{
char cmd[1024];
struct list_head *pos;
#define MAX_FORMAT 2
const char *ptr;
char *fs = NULL;
char *fs2 = NULL;
int option = 0;
int _option = 0;
int delta = 9;
int menu = 0;
int i,j, ch;
int hit;
int show;
char old[1024];
old[0]='\0';
while(1) {
cons_gotoxy(0,0);
cons_clear();
/* Execute visual prompt */
ptr = config_get("cmd.vprompt");
if (ptr&&ptr[0]) {
int tmp = last_print_format;
radare_cmd_raw(ptr, 0);
last_print_format = tmp;
}
if (fs&&!memcmp(fs, "asm.", 4))
radare_cmd_raw("pd 5", 0);
switch(menu) {
case 0: // flag space
cons_printf("\n Eval spaces:\n\n");
hit = 0;
j = i = 0;
list_for_each(pos, &(config_new.nodes)) {
struct config_node_t *bt = list_entry(pos, struct config_node_t, list);
if (option==i) {
fs = bt->name;
hit = 1;
}
show = 0;
if (old[0]=='\0') {
strccpy(old, bt->name, '.');
show = 1;
} else if (strccmp(old, bt->name, '.')) {
strccpy(old, bt->name, '.');
show = 1;
}
if (show) {
if( (i >=option-delta) && ((i<option+delta)||((option<delta)&&(i<(delta<<1))))) {
cons_printf(" %c %s\n", (option==i)?'>':' ', old);
j++;
}
i++;
}
}
if (!hit && j>0) {
option = j-1;
continue;
}
cons_printf("\n Sel:%s \n\n", fs);
break;
case 1: // flag selection
cons_printf("\n Eval variables: (%s)\n\n", fs);
hit = 0;
j = i = 0;
// TODO: cut -d '.' -f 1 | sort | uniq !!!
list_for_each(pos, &(config_new.nodes)) {
struct config_node_t *bt = list_entry(pos, struct config_node_t, list);
if (option==i) {
fs2 = bt->name;
hit = 1;
}
if (!strccmp(bt->name, fs, '.')) {
if( (i >=option-delta) && ((i<option+delta)||((option<delta)&&(i<(delta<<1))))) {
// TODO: Better align
cons_printf(" %c %s = %s\n", (option==i)?'>':' ', bt->name, bt->value);
j++;
}
i++;
}
}
if (!hit && j>0) {
option = i-1;
continue;
}
if (fs2 != NULL)
cons_printf("\n Selected: %s\n\n", fs2);
}
cons_flush();
ch = cons_readchar();
ch = cons_get_arrow(ch); // get ESC+char, return 'hjkl' char
switch(ch) {
case 'j':
option++;
break;
case 'k':
if (--option<0)
option = 0;
break;
case 'h':
case 'b': // back
menu = 0;
option = _option;
break;
case 'q':
if (menu<=0) return; menu--;
break;
case '*':
case '+':
if (fs2 != NULL)
config_visual_hit_i(fs2, +1);
continue;
case '/':
case '-':
if (fs2 != NULL)
config_visual_hit_i(fs2, -1);
continue;
case 'l':
case 'e': // edit value
case ' ':
case '\r':
case '\n': // never happens
if (menu == 1) {
if (fs2 != NULL)
config_visual_hit(fs2);
} else {
flag_space_set(fs);
menu = 1;
_option = option;
option = 0;
}
break;
case '?':
cons_clear00();
cons_printf("\nVe: Visual Eval help:\n\n");
cons_printf(" q - quit menu\n");
cons_printf(" j/k - down/up keys\n");
cons_printf(" h/b - go back\n");
cons_printf(" e/' ' - edit/toggle current variable\n");
cons_printf(" +/- - increase/decrease numeric value\n");
cons_printf(" : - enter command\n");
cons_flush();
cons_any_key();
break;
case ':':
cons_set_raw (0);
#if HAVE_LIB_READLINE
char *ptr = readline (VISUAL_PROMPT);
if (ptr) {
strncpy (cmd, ptr, sizeof (cmd)-1);
radare_cmd (cmd, 1);
free (ptr);
}
#else
cmd[0]='\0';
dl_prompt = ":> ";
if (cons_fgets(cmd, 1000, 0, NULL) <0)
cmd[0]='\0';
//line[strlen(line)-1]='\0';
radare_cmd(cmd, 1);
#endif
cons_set_raw(1);
if (cmd[0])
cons_any_key();
cons_gotoxy(0,0);
cons_clear();
continue;
}
}
}
/* Visually activate the config variable */
void config_visual_hit(const char *name)
{
char buf[1024];
struct config_node_t *node;
node = config_node_get(name);
if (node) {
if (node->flags & CN_BOOL) {
/* TOGGLE */
node->i_value = !node->i_value;
node->value = estrdup(node->value, node->i_value?"true":"false");
} else {
// FGETS AND SO
cons_printf("New value (old=%s): ", node->value);
cons_flush();
cons_set_raw(0);
cons_fgets(buf, 1023, 0, 0);
cons_set_raw(1);
node->value = estrdup(node->value, buf);
}
}
}

View File

@ -1,20 +1,19 @@
#include "r_config.h"
int main()
{
int main () {
struct r_config_t *cfg;
/* initialize config table */
cfg = r_config_new(NULL);
r_config_set(cfg, "foo", "bar");
r_config_set_i(cfg, "bar", 33);
r_config_lock(cfg, 1);
cfg = r_config_new (NULL);
r_config_set (cfg, "foo", "bar");
r_config_set_i (cfg, "bar", 33);
r_config_lock (cfg, 1);
/* usage */
printf("foo = %s\n", r_config_get(cfg, "foo"));
printf("bar = %d\n", (int)r_config_get_i(cfg, "bar"));
printf ("foo = %s\n", r_config_get (cfg, "foo"));
printf ("bar = %d\n", (int)r_config_get_i (cfg, "bar"));
r_config_free(cfg);
r_config_free (cfg);
return 0;
}

View File

@ -12,14 +12,14 @@
#endif
#endif
R_LIB_VERSION(r_fs);
R_LIB_VERSION (r_fs);
static RFSPlugin *fs_static_plugins[] = { R_FS_STATIC_PLUGINS };
R_API RFS *r_fs_new () {
R_API RFS *r_fs_new() {
int i;
RFSPlugin *static_plugin;
RFS *fs = R_NEW (RFS);
RFS *fs = R_NEW0 (RFS);
if (fs) {
fs->view = R_FS_VIEW_NORMAL;
fs->roots = r_list_new ();
@ -27,7 +27,7 @@ R_API RFS *r_fs_new () {
fs->plugins = r_list_new ();
fs->plugins->free = free;
// XXX fs->roots->free = r_fs_plugin_free;
for (i=0; fs_static_plugins[i]; i++) {
for (i = 0; fs_static_plugins[i]; i++) {
static_plugin = R_NEW (RFSPlugin);
memcpy (static_plugin, fs_static_plugins[i], sizeof (RFSPlugin));
r_fs_add (fs, static_plugin);
@ -36,7 +36,7 @@ R_API RFS *r_fs_new () {
return fs;
}
R_API RFSPlugin *r_fs_plugin_get (RFS *fs, const char *name) {
R_API RFSPlugin *r_fs_plugin_get(RFS *fs, const char *name) {
RListIter *iter;
RFSPlugin *p;
r_list_foreach (fs->plugins, iter, p) {
@ -46,7 +46,7 @@ R_API RFSPlugin *r_fs_plugin_get (RFS *fs, const char *name) {
return NULL;
}
R_API void r_fs_free (RFS* fs) {
R_API void r_fs_free(RFS *fs) {
if (!fs) return;
//r_io_free (fs->iob.io);
r_list_free (fs->plugins);
@ -55,19 +55,19 @@ R_API void r_fs_free (RFS* fs) {
}
/* plugins */
R_API void r_fs_add (RFS *fs, RFSPlugin *p) {
R_API void r_fs_add(RFS *fs, RFSPlugin *p) {
// TODO: find coliding plugin name
if (p && p->init)
p->init ();
r_list_append (fs->plugins, p);
}
R_API void r_fs_del (RFS *fs, RFSPlugin *p) {
R_API void r_fs_del(RFS *fs, RFSPlugin *p) {
// TODO: implement r_fs_del
}
/* mountpoint */
R_API RFSRoot *r_fs_mount (RFS* fs, const char *fstype, const char *path, ut64 delta) {
R_API RFSRoot *r_fs_mount(RFS *fs, const char *fstype, const char *path, ut64 delta) {
RFSPlugin *p;
RFSRoot *root;
RFSFile *file;
@ -126,16 +126,16 @@ R_API RFSRoot *r_fs_mount (RFS* fs, const char *fstype, const char *path, ut64 d
return NULL;
}
r_list_append (fs->roots, root);
eprintf ("Mounted %s on %s at 0x%"PFMT64x"\n", fstype, str, delta);
eprintf ("Mounted %s on %s at 0x%" PFMT64x "\n", fstype, str, delta);
free (str);
return root;
}
static inline int r_fs_match (const char *root, const char *path, int len) {
static inline int r_fs_match(const char *root, const char *path, int len) {
return (!strncmp (path, root, len));
}
R_API int r_fs_umount (RFS* fs, const char *path) {
R_API int r_fs_umount(RFS *fs, const char *path) {
int len;
RFSRoot *root;
RListIter *iter, *riter = NULL;
@ -154,7 +154,7 @@ R_API int r_fs_umount (RFS* fs, const char *path) {
return false;
}
R_API RList *r_fs_root (RFS *fs, const char *p) {
R_API RList *r_fs_root(RFS *fs, const char *p) {
RList *roots = r_list_new ();
RFSRoot *root;
RListIter *iter;
@ -167,7 +167,7 @@ R_API RList *r_fs_root (RFS *fs, const char *p) {
olen = strlen (path);
if (len == 1 || olen == len)
r_list_append (roots, root);
else if ( olen > len && path[len] == '/')
else if (olen > len && path[len] == '/')
r_list_append (roots, root);
}
}
@ -176,7 +176,7 @@ R_API RList *r_fs_root (RFS *fs, const char *p) {
}
/* filez */
R_API RFSFile *r_fs_open (RFS* fs, const char *p) {
R_API RFSFile *r_fs_open(RFS *fs, const char *p) {
RFSRoot *root;
RList *roots;
RListIter *iter;
@ -203,19 +203,19 @@ R_API RFSFile *r_fs_open (RFS* fs, const char *p) {
}
// TODO: close or free?
R_API void r_fs_close (RFS* fs, RFSFile *file) {
R_API void r_fs_close(RFS *fs, RFSFile *file) {
if (fs && file && file->p && file->p->close)
file->p->close (file);
}
R_API int r_fs_read (RFS* fs, RFSFile *file, ut64 addr, int len) {
if (len<1) {
R_API int r_fs_read(RFS *fs, RFSFile *file, ut64 addr, int len) {
if (len < 1) {
eprintf ("r_fs_read: too short read\n");
return false;
}
if (fs && file) {
free (file->data);
file->data = malloc (len+1);
file->data = malloc (len + 1);
if (file->p && file->p->read) {
file->p->read (file, addr, len);
return true;
@ -224,7 +224,7 @@ R_API int r_fs_read (RFS* fs, RFSFile *file, ut64 addr, int len) {
return false;
}
R_API RList *r_fs_dir(RFS* fs, const char *p) {
R_API RList *r_fs_dir(RFS *fs, const char *p) {
RList *roots, *ret = NULL;
RFSRoot *root;
RListIter *iter;
@ -236,8 +236,7 @@ R_API RList *r_fs_dir(RFS* fs, const char *p) {
if (root) {
if (strlen (root->path) == 1)
dir = path;
else
dir = path + strlen (root->path);
else dir = path + strlen (root->path);
if (!*dir) dir = "/";
ret = root->p->dir (root, dir, fs->view);
if (ret)
@ -249,7 +248,7 @@ R_API RList *r_fs_dir(RFS* fs, const char *p) {
return ret;
}
R_API int r_fs_dir_dump (RFS* fs, const char *path, const char *name) {
R_API int r_fs_dir_dump(RFS *fs, const char *path, const char *name) {
RList *list;
RListIter *iter;
RFSFile *file, *item;
@ -267,7 +266,7 @@ R_API int r_fs_dir_dump (RFS* fs, const char *path, const char *name) {
r_list_foreach (list, iter, file) {
if (!strcmp (file->name, ".") || !strcmp (file->name, ".."))
continue;
str = (char *) malloc (strlen (name) + strlen (file->name) + 2);
str = (char *)malloc (strlen (name) + strlen (file->name) + 2);
if (!str)
return false;
strcpy (str, name);
@ -298,7 +297,7 @@ R_API int r_fs_dir_dump (RFS* fs, const char *path, const char *name) {
return true;
}
static void r_fs_find_off_aux (RFS* fs, const char *name, ut64 offset, RList *list) {
static void r_fs_find_off_aux(RFS *fs, const char *name, ut64 offset, RList *list) {
RList *dirs;
RListIter *iter;
RFSFile *item, *file;
@ -309,7 +308,7 @@ static void r_fs_find_off_aux (RFS* fs, const char *name, ut64 offset, RList *li
if (!strcmp (item->name, ".") || !strcmp (item->name, ".."))
continue;
found = (char *) malloc (strlen (name) + strlen (item->name) + 2);
found = (char *)malloc (strlen (name) + strlen (item->name) + 2);
if (!found) break;
strcpy (found, name);
strcat (found, "/");
@ -331,14 +330,14 @@ static void r_fs_find_off_aux (RFS* fs, const char *name, ut64 offset, RList *li
}
}
R_API RList *r_fs_find_off (RFS* fs, const char *name, ut64 off) {
RList *list = r_list_new ();
R_API RList *r_fs_find_off(RFS *fs, const char *name, ut64 off) {
RList *list = r_list_new ();
list->free = free;
r_fs_find_off_aux (fs, name, off, list);
return list;
}
static void r_fs_find_name_aux (RFS* fs, const char *name, const char *glob, RList *list) {
static void r_fs_find_name_aux(RFS *fs, const char *name, const char *glob, RList *list) {
RList *dirs;
RListIter *iter;
RFSFile *item;
@ -347,7 +346,7 @@ static void r_fs_find_name_aux (RFS* fs, const char *name, const char *glob, RLi
dirs = r_fs_dir (fs, name);
r_list_foreach (dirs, iter, item) {
if (r_str_glob (item->name, glob)) {
found = (char *) malloc (strlen (name) + strlen (item->name) + 2);
found = (char *)malloc (strlen (name) + strlen (item->name) + 2);
if (!found)
break;
strcpy (found, name);
@ -358,7 +357,7 @@ static void r_fs_find_name_aux (RFS* fs, const char *name, const char *glob, RLi
if (!strcmp (item->name, ".") || !strcmp (item->name, ".."))
continue;
if (item->type == R_FS_FILE_TYPE_DIRECTORY) {
found = (char *) malloc (strlen (name) + strlen (item->name) + 2);
found = (char *)malloc (strlen (name) + strlen (item->name) + 2);
if (!found)
break;
strcpy (found, name);
@ -370,24 +369,25 @@ static void r_fs_find_name_aux (RFS* fs, const char *name, const char *glob, RLi
}
}
R_API RList *r_fs_find_name (RFS* fs, const char *name, const char *glob) {
R_API RList *r_fs_find_name(RFS *fs, const char *name, const char *glob) {
RList *list = r_list_new ();
list->free = free;
r_fs_find_name_aux (fs, name, glob, list);
return list;
}
R_API RFSFile *r_fs_slurp(RFS* fs, const char *path) {
R_API RFSFile *r_fs_slurp(RFS *fs, const char *path) {
RFSFile *file = NULL;
RFSRoot *root;
RList * roots = r_fs_root (fs, path);
RList *roots = r_fs_root (fs, path);
RListIter *iter;
r_list_foreach (roots, iter, root) {
if (!root || !root->p)
continue;
if (root->p->open && root->p->read && root->p->close) {
file = root->p->open (root, path);
if (file) root->p->read (file, 0, file->size); //file->data
if (file)
root->p->read (file, 0, file->size); //file->data
else eprintf ("r_fs_slurp: cannot open file\n");
} else {
if (root->p->slurp) {
@ -405,20 +405,20 @@ R_API RFSFile *r_fs_slurp(RFS* fs, const char *path) {
#include "../../shlr/grub/include/grubfs.h"
#if USE_GRUB
static int grub_parhook (void *disk, struct grub_partition *par, void *closure) {
RList *list = (RList*)closure;
static int grub_parhook(void *disk, struct grub_partition *par, void *closure) {
RList *list = (RList *)closure;
RFSPartition *p = r_fs_partition_new (
r_list_length (list),
par->start*512, 512*par->len);
par->start * 512, 512 * par->len);
p->type = par->msdostype;
r_list_append (list, p);
return 0;
}
#endif
static int fs_parhook (void *disk, void *ptr, void *closure) {
static int fs_parhook(void *disk, void *ptr, void *closure) {
RFSPartition *par = ptr;
RList *list = (RList*)closure;
RList *list = (RList *)closure;
r_list_append (list, par);
return 0;
}
@ -427,37 +427,36 @@ static int fs_parhook (void *disk, void *ptr, void *closure) {
static RFSPartitionType partitions[] = {
/* LGPL code */
{ "dos", &fs_part_dos, fs_parhook },
{"dos", &fs_part_dos, fs_parhook},
#if USE_GRUB
/* WARNING GPL code */
{ "msdos", (void*)&grub_msdos_partition_map, (void*)grub_parhook },
{ "apple", &grub_apple_partition_map },
{ "sun", &grub_sun_partition_map },
{ "sunpc", &grub_sun_pc_partition_map },
{ "amiga", &grub_amiga_partition_map },
{ "bsdlabel", &grub_bsdlabel_partition_map },
{ "gpt", &grub_gpt_partition_map },
{"msdos", (void *) & grub_msdos_partition_map, (void *)grub_parhook},
{"apple", &grub_apple_partition_map},
{"sun", &grub_sun_partition_map},
{"sunpc", &grub_sun_pc_partition_map},
{"amiga", &grub_amiga_partition_map},
{"bsdlabel", &grub_bsdlabel_partition_map},
{"gpt", &grub_gpt_partition_map},
#endif
// XXX: In BURG all bsd partition map are in bsdlabel
// XXX: In BURG all bsd partition map are in bsdlabel
//{ "openbsdlabel", &grub_openbsd_partition_map },
//{ "netbsdlabel", &grub_netbsd_partition_map },
//{ "acorn", &grub_acorn_partition_map },
{ NULL }
};
{ NULL }};
R_API const char *r_fs_partition_type_get (int n) {
if (n<0 || n>=R_FS_PARTITIONS_LENGTH)
R_API const char *r_fs_partition_type_get(int n) {
if (n < 0 || n >= R_FS_PARTITIONS_LENGTH)
return NULL;
return partitions[n].name;
}
R_API int r_fs_partition_get_size () {
R_API int r_fs_partition_get_size() {
return R_FS_PARTITIONS_LENGTH;
}
R_API RList *r_fs_partitions (RFS *fs, const char *ptype, ut64 delta) {
R_API RList *r_fs_partitions(RFS *fs, const char *ptype, ut64 delta) {
int i, cur = -1;
for (i=0; partitions[i].name; i++) {
for (i = 0; partitions[i].name; i++) {
if (!strcmp (ptype, partitions[i].name)) {
cur = i;
break;
@ -467,13 +466,13 @@ R_API RList *r_fs_partitions (RFS *fs, const char *ptype, ut64 delta) {
RList *list = r_list_newf ((RListFree)r_fs_partition_free);
#if USE_GRUB
void *disk = NULL;
if (partitions[i].iterate == (void*)&grub_parhook) {
if (partitions[i].iterate == (void *)&grub_parhook) {
struct grub_partition_map *gpt = partitions[i].ptr;
grubfs_bind_io (NULL, 0);
disk = (void*)grubfs_disk (&fs->iob);
disk = (void *)grubfs_disk (&fs->iob);
if (gpt) {
gpt->iterate (disk,
(void*)partitions[i].iterate, list);
(void *)partitions[i].iterate, list);
}
grubfs_free (disk);
} else {
@ -488,18 +487,18 @@ R_API RList *r_fs_partitions (RFS *fs, const char *ptype, ut64 delta) {
if (ptype && *ptype)
eprintf ("Unknown partition type '%s'.\n", ptype);
eprintf ("Supported types:\n");
for (i=0; partitions[i].name; i++)
for (i = 0; partitions[i].name; i++)
eprintf (" %s", partitions[i].name);
eprintf ("\n");
return NULL;
}
R_API int r_fs_partition_type_str (const char *type) {
R_API int r_fs_partition_type_str(const char *type) {
// TODO: implement
return 0;
}
R_API const char *r_fs_partition_type (const char *part, int type) {
R_API const char *r_fs_partition_type(const char *part, int type) {
// XXX: part is ignored O_o
switch (type) {
case GRUB_PC_PARTITION_TYPE_FAT12:
@ -526,7 +525,7 @@ R_API const char *r_fs_partition_type (const char *part, int type) {
case GRUB_PC_PARTITION_TYPE_VSTAFS:
case GRUB_PC_PARTITION_TYPE_FREEBSD: // ufs
case GRUB_PC_PARTITION_TYPE_OPENBSD: // ufs
case GRUB_PC_PARTITION_TYPE_NETBSD: // ufs
case GRUB_PC_PARTITION_TYPE_NETBSD: // ufs
case GRUB_PC_PARTITION_TYPE_GPT_DISK:
case GRUB_PC_PARTITION_TYPE_LINUX_RAID:
case GRUB_PC_PARTITION_TYPE_NONE:
@ -535,19 +534,19 @@ R_API const char *r_fs_partition_type (const char *part, int type) {
}
}
R_API char *r_fs_name (RFS *fs, ut64 offset) {
R_API char *r_fs_name(RFS *fs, ut64 offset) {
ut8 buf[1024];
int i, j, len, ret = false;
for (i=0; fstypes[i].name; i++) {
for (i = 0; fstypes[i].name; i++) {
RFSType *f = &fstypes[i];
len = R_MIN (f->buflen, sizeof (buf)-1);
len = R_MIN (f->buflen, sizeof (buf) - 1);
fs->iob.read_at (fs->iob.io, offset + f->bufoff, buf, len);
if (f->buflen>0 && !memcmp (buf, f->buf, f->buflen)) {
if (f->buflen > 0 && !memcmp (buf, f->buf, f->buflen)) {
ret = true;
len = R_MIN (f->bytelen, sizeof (buf));
fs->iob.read_at (fs->iob.io, offset + f->byteoff, buf, len);
for (j=0; j<f->bytelen; j++) {
for (j = 0; j < f->bytelen; j++) {
if (buf[j] != f->byte) {
ret = false;
break;
@ -561,7 +560,7 @@ R_API char *r_fs_name (RFS *fs, ut64 offset) {
#define PROMT_PATH_BUFSIZE 1024
R_API int r_fs_prompt (RFS *fs, const char *root) {
R_API int r_fs_prompt(RFS *fs, const char *root) {
char buf[PROMT_PATH_BUFSIZE];
char path[PROMT_PATH_BUFSIZE];
char str[2048];
@ -571,7 +570,7 @@ R_API int r_fs_prompt (RFS *fs, const char *root) {
RFSFile *file = NULL;
if (root && *root) {
strncpy (buf, root, sizeof (buf)-1);
strncpy (buf, root, sizeof (buf) - 1);
r_str_chop_path (buf);
list = r_fs_root (fs, buf);
if (r_list_empty (list)) {
@ -579,31 +578,29 @@ R_API int r_fs_prompt (RFS *fs, const char *root) {
r_list_free (list);
return false;
}
strncpy (path, buf, sizeof (path)-1);
strncpy (path, buf, sizeof (path) - 1);
} else strcpy (path, "/");
for (;;) {
printf ("[%s]> ", path);
fflush (stdout);
fgets (buf, sizeof (buf)-1, stdin);
fgets (buf, sizeof (buf) - 1, stdin);
if (feof (stdin)) break;
buf[strlen (buf)-1] = '\0';
buf[strlen (buf) - 1] = '\0';
if (!strcmp (buf, "q") || !strcmp (buf, "exit")) {
r_list_free (list);
return true;
}
if (buf[0]=='!') {
r_sandbox_system (buf+1, 1);
} else
if (!memcmp (buf, "ls", 2)) {
if (buf[2]==' ') {
if (buf[0] == '!') {
r_sandbox_system (buf + 1, 1);
} else if (!memcmp (buf, "ls", 2)) {
if (buf[2] == ' ') {
if (buf[3] != '/') {
strncpy (str, path, sizeof (str)-1);
strncpy (str, path, sizeof (str) - 1);
strcat (str, "/");
strncat (str, buf+3, sizeof (buf)-1);
strncat (str, buf + 3, sizeof (buf) - 1);
list = r_fs_dir (fs, str);
} else
list = r_fs_dir (fs, buf+3);
} else list = r_fs_dir (fs, buf + 3);
} else list = r_fs_dir (fs, path);
if (list) {
r_list_foreach (list, iter, file)
@ -613,26 +610,26 @@ R_API int r_fs_prompt (RFS *fs, const char *root) {
eprintf ("%s\n", path);
} else if (!memcmp (buf, "cd ", 3)) {
char opath[PROMT_PATH_BUFSIZE];
strncpy (opath, path, sizeof (opath)-1);
input = buf+3;
strncpy (opath, path, sizeof (opath) - 1);
input = buf + 3;
while (*input == ' ')
input++;
if (!strcmp (input, "..")) {
char *p = (char *)r_str_lchr (path, '/');
if (p) p[(p==path)?1:0]=0;
if (p) p[(p == path)? 1: 0] = 0;
} else {
strcat (path, "/");
if (*input=='/') {
strncpy (path, input, sizeof (opath)-1);
if (*input == '/') {
strncpy (path, input, sizeof (opath) - 1);
} else {
if ((strlen (path)+strlen (input))>=sizeof (path)) {
if ((strlen (path) + strlen (input)) >= sizeof (path)) {
// overflow
path[0] = 0;
} else {
strcat (path, input);
}
}
path[sizeof(path)-1] = 0;
path[sizeof (path) - 1] = 0;
}
r_str_chop_path (path);
list = r_fs_dir (fs, path);
@ -641,15 +638,16 @@ R_API int r_fs_prompt (RFS *fs, const char *root) {
eprintf ("cd: unknown path: %s\n", path);
}
} else if (!memcmp (buf, "cat ", 4)) {
input = buf+3;
input = buf + 3;
while (input[0] == ' ')
input++;
if (input[0] == '/') {
if (root) strncpy (str, root, sizeof (str)-1);
if (root)
strncpy (str, root, sizeof (str) - 1);
else str[0] = 0;
} else strncpy (str, path, sizeof (str)-1);
} else strncpy (str, path, sizeof (str) - 1);
strncat (str, "/", sizeof (str) - strlen (str) - 1);
strncat (str, input, sizeof (str) -strlen (str) - 1);
strncat (str, input, sizeof (str) - strlen (str) - 1);
file = r_fs_open (fs, str);
if (file) {
r_fs_read (fs, file, 0, file->size);
@ -664,7 +662,7 @@ R_API int r_fs_prompt (RFS *fs, const char *root) {
}
} else if (!memcmp (buf, "get ", 4)) {
char *s = 0;
input = buf+3;
input = buf + 3;
while (input[0] == ' ')
input++;
if (input[0] == '/') {
@ -679,7 +677,7 @@ R_API int r_fs_prompt (RFS *fs, const char *root) {
strcpy (s, path);
}
if (!s) {
s = malloc (strlen (input)+32);
s = malloc (strlen (input) + 32);
if (!s) goto beach;
}
strcat (s, "/");
@ -699,16 +697,15 @@ R_API int r_fs_prompt (RFS *fs, const char *root) {
free (s);
} else if (!memcmp (buf, "help", 4) || !strcmp (buf, "?")) {
eprintf (
"Commands:\n"
" !cmd ; escape to system\n"
" ls [path] ; list current directory\n"
" cd path ; change current directory\n"
" cat file ; print contents of file\n"
" get file ; dump file to disk\n"
" mount ; list mount points\n"
" q/exit ; leave prompt mode\n"
" ?/help ; show this help\n"
);
"Commands:\n"
" !cmd ; escape to system\n"
" ls [path] ; list current directory\n"
" cd path ; change current directory\n"
" cat file ; print contents of file\n"
" get file ; dump file to disk\n"
" mount ; list mount points\n"
" q/exit ; leave prompt mode\n"
" ?/help ; show this help\n");
} else eprintf ("Unknown command %s\n", buf);
}
beach:
@ -718,6 +715,6 @@ beach:
return true;
}
R_API void r_fs_view (RFS *fs, int view) {
R_API void r_fs_view(RFS *fs, int view) {
fs->view = view;
}

View File

@ -5,7 +5,7 @@
#include <r_util.h>
#include <list.h>
R_LIB_VERSION_HEADER(r_reg);
R_LIB_VERSION_HEADER (r_reg);
enum {
R_REG_TYPE_GPR,
@ -68,12 +68,11 @@ enum {
#define R_REG_COND_LE 12
#define R_REG_COND_LAST 13
typedef struct r_reg_item_t {
char *name;
int type;
int size; /* 8,16,32,64 ... 128/256 ??? */
int offset; // offset in data structure
int size; /* 8,16,32,64 ... 128/256 ??? */
int offset; // offset in data structure
int packed_size; /* 0 means no packed register, 1byte pack, 2b pack... */
bool is_float;
char *flags;
@ -128,8 +127,8 @@ R_API const char *r_reg_get_name(RReg *reg, int kind);
R_API const char *r_reg_get_role(int role);
R_API RRegItem *r_reg_get(RReg *reg, const char *name, int type);
R_API RList *r_reg_get_list(RReg *reg, int type);
R_API RRegItem *r_reg_get_at (RReg *reg, int type, int regsize, int delta);
R_API RRegItem *r_reg_next_diff(RReg *reg, int type, const ut8* buf, int buflen, RRegItem *prev_ri, int regsize);
R_API RRegItem *r_reg_get_at(RReg *reg, int type, int regsize, int delta);
R_API RRegItem *r_reg_next_diff(RReg *reg, int type, const ut8 *buf, int buflen, RRegItem *prev_ri, int regsize);
/* Item */
R_API void r_reg_item_free(RRegItem *item);
@ -138,11 +137,11 @@ R_API void r_reg_item_free(RRegItem *item);
R_API int r_reg_type_by_name(const char *str);
R_API int r_reg_get_name_idx(const char *type);
R_API RRegItem* r_reg_cond_get (RReg *reg, const char *name);
R_API int r_reg_cond_get_value (RReg *r, const char *name);
R_API int r_reg_cond_bits (RReg *r, int type, RRegFlags *f);
R_API RRegFlags *r_reg_cond_retrieve (RReg *r, RRegFlags *);
R_API int r_reg_cond (RReg *r, int type);
R_API RRegItem *r_reg_cond_get(RReg *reg, const char *name);
R_API int r_reg_cond_get_value(RReg *r, const char *name);
R_API int r_reg_cond_bits(RReg *r, int type, RRegFlags *f);
R_API RRegFlags *r_reg_cond_retrieve(RReg *r, RRegFlags *);
R_API int r_reg_cond(RReg *r, int type);
/* integer value 8-64 bits */
R_API ut64 r_reg_get_value(RReg *reg, RRegItem *item);
@ -169,10 +168,10 @@ R_API int r_reg_set_pack(RReg *reg, RRegItem *item, int packidx, int packbits, u
R_API ut64 r_reg_get_pack(RReg *reg, RRegItem *item, int packidx, int packbits);
/* byte arena */
R_API ut8* r_reg_get_bytes(RReg *reg, int type, int *size);
R_API bool r_reg_set_bytes(RReg *reg, int type, const ut8* buf, const int len);
R_API RRegArena *r_reg_arena_new (int size);
R_API void r_reg_arena_free(RRegArena* ra);
R_API ut8 *r_reg_get_bytes(RReg *reg, int type, int *size);
R_API bool r_reg_set_bytes(RReg *reg, int type, const ut8 *buf, const int len);
R_API RRegArena *r_reg_arena_new(int size);
R_API void r_reg_arena_free(RRegArena *ra);
R_API int r_reg_fit_arena(RReg *reg);
R_API int r_reg_arena_set(RReg *reg, int n, int copy);
R_API void r_reg_arena_swap(RReg *reg, int copy);
@ -183,7 +182,7 @@ R_API void r_reg_arena_zero(RReg *reg);
R_API ut8 *r_reg_arena_peek(RReg *reg);
R_API void r_reg_arena_poke(RReg *reg, const ut8 *buf);
R_API ut64 r_reg_cmp(RReg *reg, RRegItem *item);
R_API const char *r_reg_cond_to_string (int n);
R_API const char *r_reg_cond_to_string(int n);
R_API int r_reg_cond_from_string(const char *str);
#endif

View File

@ -757,7 +757,7 @@ R_API ut64 r_io_seek(RIO *io, ut64 offset, int whence) {
// XXX: list_empty trick must be done in r_io_set_va();
//eprintf ("-(seek)-> 0x%08llx\n", offset);
//if (!io->debug && io->va && !r_list_empty (io->sections)) {
if (!io->debug || !io->raw) { //
if (!io->debug || !io->raw) { //
if (io->va && !r_list_empty (io->sections)) {
ut64 o = r_io_section_vaddr_to_maddr_try (io, offset);
if (o != UT64_MAX)

View File

@ -1,6 +1,11 @@
#!/bin/sh
FILES="
libr/io/io.c
libr/include/r_list.h
libr/include/r_reg.h
libr/config/config.c
libr/config/callback.c
libr/config/t/test.c
libr/fs/fs.c
libr/reg/reg.c
libr/reg/arena.c
libr/reg/double.c

View File

@ -59,10 +59,10 @@ indentFile() {
# spaces in { brackets
mv .tmp-format .tmp-format2
#perl -ne 's/{\s/{ /g;print' < .tmp-format2 > .tmp-format
perl -ne 's/{([^\n])/{ \1/g if(!/"/);print' < .tmp-format2 > .tmp-format
perl -ne 's/{([^ \n])/{ \1/g if(!/"/);print' < .tmp-format2 > .tmp-format
# spaces in } brackets
mv .tmp-format .tmp-format2
perl -ne 's/([^\t])}/$1 }/g if(!/"/);print' < .tmp-format2 > .tmp-format
perl -ne 's/([^ \t])}/$1 }/g if(!/"/);print' < .tmp-format2 > .tmp-format
# _( macro
mv .tmp-format .tmp-format2
perl -ne 's/_\s\(/_(/g;print' < .tmp-format2 > .tmp-format