Skip to content

Commit

Permalink
Fix #22894 - Add z, to print zignatures in table format ##zignatures
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed May 7, 2024
1 parent 34e2176 commit 0869b60
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
13 changes: 9 additions & 4 deletions libr/anal/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -1837,26 +1837,31 @@ static bool listCB(RSignItem *it, void *user) {
}

// Zignspace and name (except for radare format)
if (ctx->format == '*') {
switch (ctx->format) {
case '*':
if (it->space) {
a->cb_printf ("zs %s\n", it->space->name);
} else {
a->cb_printf ("zs *\n");
}
} else if (ctx->format == 'q') {
break;
case 'q':
a->cb_printf ("0x%08" PFMT64x " ", it->addr);
const char *pad = r_str_pad (' ', 30 - strlen (it->name));
a->cb_printf ("%s:%s", it->name, pad);
} else if (ctx->format == 'j') {
break;
case 'j':
if (it->space) {
pj_ks (ctx->pj, "zignspace", it->space->name);
}
pj_ks (ctx->pj, "name", it->name);
} else {
break;
default:
if (!r_spaces_current (&a->zign_spaces) && it->space) {
a->cb_printf ("(%s) ", it->space->name);
}
a->cb_printf ("%s:\n", it->name);
break;
}

// Bytes pattern
Expand Down
48 changes: 48 additions & 0 deletions libr/core/cmd_zign.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ static RCoreHelpMessage help_msg_z = {
"Usage:", "z[*j-aof/cs] [args] ", "# Manage zignatures",
"z", " ([addr])", "show/list zignatures", // TODO: rename to zl ?
"z.", "", "find matching zignatures in current offset", // rename to 'z' ?
"z,", "([:help])", "list zignatures loaded in table format (see z,:help)",
"zb", "[?][n=5]", "search for best match",
"zd", "zignature", "diff current function and signature",
"z*", " ([addr])", "show zignatures in radare format",
Expand Down Expand Up @@ -1267,6 +1268,51 @@ static int cmdInfo(void *data, const char *input) {
return true;
}

struct ctxListCB {
RAnal *anal;
RTable *t;
};


// R2_600 - move into anal/sign.c
static bool listCB(RSignItem *it, void *user) {
struct ctxListCB *ctx = (struct ctxListCB *)user;
#if 0
RAnal *a = ctx->anal;
if (!validate_item (it)) {
return true;
}
#endif
// End item
char *bytes = r_hex_bin2strdup (it->bytes->bytes, it->bytes->size);
char *masks = r_hex_bin2strdup (it->bytes->mask, it->bytes->size);
r_table_add_rowf (ctx->t, "dssss", it->addr, it->name, it->hash->bbhash, bytes, masks);
free (bytes);
free (masks);

return true;
}

static int csvZignatures(RCore *core, const char *arg) {
RTable *t = r_table_new ("pxr");
RTableColumnType *n = r_table_type ("number");
RTableColumnType *s = r_table_type ("string");
r_table_add_column (t, n, "addr", 0);
r_table_add_column (t, s, "name", 1);
r_table_add_column (t, s, "hash", 2);
r_table_add_column (t, s, "data", 3);
r_table_add_column (t, s, "mask", 4);
struct ctxListCB ctx = { core->anal, t };
r_sign_foreach (core->anal, listCB, &ctx);
if (r_table_query (t, arg)) {
char *ts = r_table_tostring (t);
r_cons_printf ("%s", ts); // \n?
free (ts);
}
r_table_free (t);
return 0;
}

static int cmd_zign(void *data, const char *input) {
RCore *core = (RCore *) data;
const char *arg = input + 1;
Expand All @@ -1291,6 +1337,8 @@ static int cmd_zign(void *data, const char *input) {
core->offset = oaddr;
}
break;
case ',':
return csvZignatures (core, arg);
case 'k': // "zk"
r_core_cmd0 (core, "k anal/zigns/*");
break;
Expand Down

0 comments on commit 0869b60

Please sign in to comment.