fixing indentation

This commit is contained in:
oddcoder 2016-03-18 13:58:49 +02:00 committed by pancake
parent 6b256183c2
commit 9a7ea1b3f1

View File

@ -4,65 +4,63 @@
#define TEMP_MAX 127
#endif
static void show_help(RCore *core) {
const char * help_message[] = {
"Usage: t", "", "# cparse types commands",
"t", "", "List all loaded types",
"t", " <type>", "Show type in 'pf' syntax",
"t*", "", "List types info in r2 commands",
"t-", " <name>", "Delete types by its name",
"t-*", "", "Remove all types",
const char *help_message[] = {
"Usage: t", "", "# cparse types commands",
"t", "", "List all loaded types",
"t", " <type>", "Show type in 'pf' syntax",
"t*", "", "List types info in r2 commands",
"t-", " <name>", "Delete types by its name",
"t-*", "", "Remove all types",
//"t-!", "", "Use to open $EDITOR",
"tb", " <enum> <value>","Show matching enum bitfield for given number",
"te", " <enum> <value>","Show name for given enum number",
"td", " <string>","Load types from string",
"td-", "<name>", "Undefine type by name",
"tf", " <addr>", "View linked type at given address",
"tl", "[?]", "Show/Link type to an address",
"tb", " <enum> <value>", "Show matching enum bitfield for given number",
"te", " <enum> <value>", "Show name for given enum number",
"td", " <string>", "Load types from string",
"td-", "<name>", "Undefine type by name",
"tf", " <addr>", "View linked type at given address",
"tl", "[?]", "Show/Link type to an address",
//"to", "", "List opened files",
"to", " -", "Open cfg.editor to load types",
"to", " <path>", "Load types from C header file",
"tk", " <sdb-query>", "Perform sdb query",
"ts", " <k>=<v>", "Set fields at curseek linked type",
"to", " -", "Open cfg.editor to load types",
"to", " <path>", "Load types from C header file",
"tk", " <sdb-query>", "Perform sdb query",
"ts", " <k>=<v>", "Set fields at curseek linked type",
//"| ts k=v k=v @ link.addr set fields at given linked type\n"
NULL
};
NULL };
r_core_cmd_help (core, help_message);
}
static int sdbforcb (void *p, const char *k, const char *v) {
static int sdbforcb(void *p, const char *k, const char *v) {
r_cons_printf ("%s=%s\n", k, v);
return 1;
}
static int sdbdelete(void *p, const char *k, const char *v){
RCore *core= (RCore*)p;
r_anal_type_del (core->anal,k);
static int sdbdelete(void *p, const char *k, const char *v) {
RCore *core = (RCore *)p;
r_anal_type_del (core->anal, k);
return 1;
}
static int typelist (void *p, const char *k, const char *v) {
static int typelist(void *p, const char *k, const char *v) {
#define DB core->anal->sdb_types
RCore *core = (RCore*)p;
RCore *core = (RCore *)p;
int i;
if (!strcmp (v, "func")) {
const char *rv = sdb_const_get (DB,
sdb_fmt (0, "func.%s.ret", k), 0);
sdb_fmt (0, "func.%s.ret", k), 0);
r_cons_printf ("# %s %s(", rv, k);
for (i=0; i<16; i++) {
for (i = 0; i < 16; i++) {
char *av = sdb_get (DB,
sdb_fmt (0, "func.%s.arg.%d", k, i), 0);
sdb_fmt (0, "func.%s.arg.%d", k, i), 0);
if (!av) break;
r_str_replace_char (av, ',', ' ');
r_cons_printf ("%s%s", i?", ":"", av);
r_cons_printf ("%s%s", i? ", ": "", av);
free (av);
}
r_cons_printf (");\n");
// signature in pf for asf
r_cons_printf ("asf %s=", k);
// formats
for (i=0; i<16; i++) {
for (i = 0; i < 16; i++) {
const char *fmt;
char *comma, *av = sdb_get (DB,
sdb_fmt (0, "func.%s.arg.%d", k, i), 0);
sdb_fmt (0, "func.%s.arg.%d", k, i), 0);
if (!av) break;
comma = strchr (av, ',');
if (comma) *comma = 0;
@ -72,36 +70,35 @@ static int typelist (void *p, const char *k, const char *v) {
free (av);
}
// names
for (i=0; i<16; i++) {
for (i = 0; i < 16; i++) {
char *comma, *av = sdb_get (DB,
sdb_fmt (0, "func.%s.arg.%d", k, i), 0);
sdb_fmt (0, "func.%s.arg.%d", k, i), 0);
if (!av) break;
comma = strchr (av, ',');
if (comma) *comma++ = 0;
r_cons_printf (" %s", comma);
free (av);
}
r_cons_newline();
r_cons_newline ();
}
return 1;
}
static int cmd_type(void *data, const char *input) {
RCore *core = (RCore*)data;
RCore *core = (RCore *)data;
switch (input[0]) {
// t [typename] - show given type in C syntax
case 'k':
if (input[1]==' ') {
sdb_query (core->anal->sdb_types, input+2);
if (input[1] == ' ') {
sdb_query (core->anal->sdb_types, input + 2);
} else sdb_query (core->anal->sdb_types, "*");
break;
case 's':
{
case 's': {
char *q, *p, *o, *e;
p = o = strdup (input+1);
p = o = strdup (input + 1);
for (;;) {
if (*p == '\0'){
if (*p == '\0') {
eprintf ("Usage: ts <k>=<v> Set fields at curseek linked type\n");
break;
}
@ -115,29 +112,27 @@ static int cmd_type(void *data, const char *input) {
if (e) {
*e = 0;
r_anal_type_set (core->anal, core->offset,
p, r_num_math (core->num, e+1));
p, r_num_math (core->num, e + 1));
} else eprintf ("TODO: implement get\n");
if (!q) break;
p = q+1;
p = q + 1;
}
free (o);
}
break;
case 'b':
{
char *p, *s = (strlen (input) > 1) ? strdup (input+2): NULL;
} break;
case 'b': {
char *p, *s = (strlen (input) > 1)? strdup (input + 2): NULL;
const char *isenum;
p = s ? strchr (s, ' ') : NULL;
p = s? strchr (s, ' '): NULL;
if (p) {
*p++ = 0;
// dupp in core.c (see getbitfield())
// dupp in core.c (see getbitfield())
isenum = sdb_const_get (core->anal->sdb_types, s, 0);
if (isenum && !strcmp (isenum, "enum")) {
*--p='.';
*--p = '.';
const char *res = sdb_const_get (core->anal->sdb_types, s, 0);
if (res)
r_cons_printf ("%s\n", res);
else eprintf("Invalid enum member\n");
else eprintf ("Invalid enum member\n");
} else {
eprintf ("This is not an enum\n");
}
@ -145,15 +140,13 @@ static int cmd_type(void *data, const char *input) {
eprintf ("Missing value\n");
}
free (s);
}
break;
case 'e':
{
} break;
case 'e': {
if (!input[1]) {
char *name = NULL;
SdbKv *kv;
SdbListIter *iter;
SdbList *l = sdb_foreach_list (core->anal->sdb_types);
SdbList *l = sdb_foreach_list (core->anal->sdb_types);
ls_foreach (l, iter, kv) {
if (!strcmp (kv->value, "enum")) {
if (!name || strcmp (kv->value, name)) {
@ -167,7 +160,7 @@ static int cmd_type(void *data, const char *input) {
ls_free (l);
break;
}
char *p, *s = strdup (input+2);
char *p, *s = strdup (input + 2);
const char *isenum;
p = strchr (s, ' ');
if (p) {
@ -186,22 +179,19 @@ static int cmd_type(void *data, const char *input) {
r_core_cmdf (core, "t~&%s,=0x", s);
}
free (s);
}
break;
case ' ':
{
const char *isenum = sdb_const_get (core->anal->sdb_types, input+1, 0);
} break;
case ' ': {
const char *isenum = sdb_const_get (core->anal->sdb_types, input + 1, 0);
if (isenum && !strcmp (isenum, "enum")) {
eprintf ("IS ENUM! \n");
} else {
char *fmt = r_anal_type_format (core->anal, input +1);
char *fmt = r_anal_type_format (core->anal, input + 1);
if (fmt) {
r_cons_printf ("pf %s\n", fmt);
free (fmt);
} else eprintf ("Cannot find '%s' type\n", input+1);
} else eprintf ("Cannot find '%s' type\n", input + 1);
}
}
break;
} break;
// t* - list all types in 'pf' syntax
case '*':
sdb_foreach (core->anal->sdb_types, typelist, core);
@ -250,21 +240,20 @@ static int cmd_type(void *data, const char *input) {
// td - parse string with cparse engine and load types from it
case 'd':
if (input[1] == '?') {
const char * help_message[] = {
const char *help_message[] = {
"Usage:", "td[...]", "",
"td", "[string]", "Load types from string",
NULL
};
r_core_cmd_help(core, help_message);
} else
if (input[1] == '-') {
const char *arg = strchr (input+1, ' ');
if (arg) arg++; else arg = input+2;
NULL };
r_core_cmd_help (core, help_message);
} else if (input[1] == '-') {
const char *arg = strchr (input + 1, ' ');
if (arg)
arg++;
else arg = input + 2;
r_anal_type_del (core->anal, arg);
} else
if (input[1] == ' ') {
} else if (input[1] == ' ') {
char tmp[8192];
snprintf (tmp, sizeof (tmp)-1, "%s;", input+2);
snprintf (tmp, sizeof (tmp) - 1, "%s;", input + 2);
//const char *string = input + 2;
//r_anal_str_to_type (core->anal, string);
char *out = r_parse_c_string (tmp);
@ -279,77 +268,72 @@ static int cmd_type(void *data, const char *input) {
break;
// tl - link a type to an address
case 'l':
if (input[1]=='?') {
const char * help_message[] = {
if (input[1] == '?') {
const char *help_message[] = {
"Usage: tl", " [typename|addr] ([addr])@[addr|function]", "",
NULL
};
NULL };
r_core_cmd_help(core, help_message);
r_core_cmd_help (core, help_message);
} else if (input[1]) {
ut64 addr = r_num_math (core->num, input+2);
ut64 addr = r_num_math (core->num, input + 2);
char *ptr = strchr (input + 2, ' ');
if (ptr) {
addr = r_num_math (core->num, ptr + 1);
*ptr = '\0';
} else addr = core->offset;
r_anal_type_link (core->anal, input+2, addr);
r_anal_type_link (core->anal, input + 2, addr);
} else {
r_core_cmd0 (core, "t~^link");
}
break;
case '-':
if (input[1] == '?') {
const char * help_message[] = {
const char *help_message[] = {
"Usage: t-", " <type>", "Delete type by its name",
NULL
};
NULL };
r_core_cmd_help(core, help_message);
} else
if (input[1]=='*') {
sdb_foreach (core->anal->sdb_types,sdbdelete, core);
r_core_cmd_help (core, help_message);
} else if (input[1] == '*') {
sdb_foreach (core->anal->sdb_types, sdbdelete, core);
} else {
const char *name = input + 1;
if (*name==' ') name++;
if (*name == ' ') name++;
if (*name) {
//TODO delete all types that is name or starts with name.
r_anal_type_del (core->anal, name);
char tmp[TEMP_MAX+1];
snprintf(tmp,TEMP_MAX,"%s.",name);
char tmp[TEMP_MAX + 1];
snprintf (tmp, TEMP_MAX, "%s.", name);
SdbKv *kv;
SdbListIter *iter;
SdbList *l = sdb_foreach_list (core->anal->sdb_types);
SdbList *l = sdb_foreach_list (core->anal->sdb_types);
ls_foreach (l, iter, kv) {
if (!strncmp (kv->key,tmp,strlen(tmp)))
r_anal_type_del(core->anal,kv->key);
if (!strncmp (kv->key, tmp, strlen (tmp)))
r_anal_type_del (core->anal, kv->key);
}
} else eprintf ("Invalid use of t- . See t-? for help.\n");
}
break;
// tv - get/set type value linked to a given address
case 'f':
{
ut64 addr;
char *fmt, key[128];
const char *type;
if (input[1]) {
addr = r_num_math (core->num, input+1);
} else addr = core->offset;
snprintf (key, sizeof (key), "link.%08"PFMT64x, addr);
type = sdb_const_get (core->anal->sdb_types, key, 0);
if (type) {
fmt = r_anal_type_format (core->anal, type);
r_cons_printf ("struct %s {\n", type);
if (fmt) {
r_core_cmdf (core, "pf %s @ 0x%08"PFMT64x"\n", fmt, addr);
free (fmt);
}// else eprintf ("Cannot find '%s' type\n", input+1);
r_cons_printf ("}\n");
} //else eprintf ("Cannot find type at 0x%llx\n", addr);
}
break;
case 'f': {
ut64 addr;
char *fmt, key[128];
const char *type;
if (input[1]) {
addr = r_num_math (core->num, input + 1);
} else addr = core->offset;
snprintf (key, sizeof (key), "link.%08" PFMT64x, addr);
type = sdb_const_get (core->anal->sdb_types, key, 0);
if (type) {
fmt = r_anal_type_format (core->anal, type);
r_cons_printf ("struct %s {\n", type);
if (fmt) {
r_core_cmdf (core, "pf %s @ 0x%08" PFMT64x "\n", fmt, addr);
free (fmt);
} // else eprintf ("Cannot find '%s' type\n", input+1);
r_cons_printf ("}\n");
} //else eprintf ("Cannot find type at 0x%llx\n", addr);
} break;
case '?':
show_help (core);
break;