New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support every output format for the bb graph (agf) #10030
Conversation
libr/core/canal.c
Outdated
|
||
char *title = get_title (bb->addr); | ||
char *body = r_core_cmd_strf (core, "pdb @ 0x%08"PFMT64x, bb->addr); | ||
char *body_b64= r_base64_encode_dyn (body, strlen(body)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space before = and before (. if you use -1 in the length argument, the bsae64 api will do the strlen for you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if any of those variables are null, following lines will make it crash
libr/core/canal.c
Outdated
char *body_b64= r_base64_encode_dyn (body, strlen(body)); | ||
body_b64 = r_str_prefix (body_b64, "base64:"); | ||
|
||
r_cons_printf ("agn \"%s\" \"%s\"\n", title, body_b64); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quotes dont work like this in r2land
libr/core/canal.c
Outdated
char *u = get_title (bb->addr), *v = NULL; | ||
if (bb->jump != UT64_MAX) { | ||
v = get_title (bb->jump); | ||
r_cons_printf ("age \"%s\" \"%s\"\n", u, v); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quotes dont work like this in r2land, remove them
libr/core/canal.c
Outdated
return false; | ||
} | ||
|
||
r_cons_printf ("graph\n[\n" "hierarchic\t1\n" "label\t\"\"\n" "directed\t1\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use spaces intead of tabs here? or graphviz will not work? it is better to not print tabs to stdout in r2 commands to avoid problems in visual and such, even if its not suposed to be printed
libr/core/cmd_anal.c
Outdated
if (input[2] == 'm') { | ||
r_core_anal_graph (core, r_num_math (core->num, input + 2), | ||
R_CORE_ANAL_GRAPHLINES); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else goes here , in the same line of the }
libr/core/cmd_anal.c
Outdated
if (input[2] == 'f') { | ||
//TODO | ||
} | ||
RAnalFunction *fcn = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use ternary operator instead of assigning to null and such. also the only thing that changes is the off_fcn, so you dont need to copy the r_anal-get_fcn_in call twice
libr/core/cmd_anal.c
Outdated
R_CORE_ANAL_JSON | R_CORE_ANAL_JSON_FORMAT_DISASM); | ||
case 'g':// "agfg" | ||
if (input[2] == 'f') { | ||
//TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uh
libr/core/cmd_anal.c
Outdated
if (*(input + 2)) { | ||
ut64 off_fcn = r_num_math (core->num, input + 2); | ||
fcn = r_anal_get_fcn_in (core->anal, off_fcn, 0); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as before (else in this line, use ternary operator and avoid dupped call when only 1 arg changes)
libr/core/cmd_anal.c
Outdated
if (*(input + 2)) { | ||
ut64 off_fcn = r_num_math (core->num, input + 2); | ||
fcn = r_anal_get_fcn_in (core->anal, off_fcn, 0); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
@radare Thank you for the reviews. |
Thanks! |
Now agf supports the following outputs:
Note: this pr doesn't break any existing commands. It only adds new ones.
Also, I know nested switches are ugly, but I prefer to do code polishing when I'm done with the other types of graphs (agg, agc...) so that I can see better which parts of the code can be generalized.
But please if you have an idea on how this could be improved / written more elegantly don't hesistate to tell me.