Skip to content
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

Merged
merged 3 commits into from May 7, 2018

Conversation

cyanpencil
Copy link
Contributor

Now agf supports the following outputs:

- non interactive ascii-> agf 
- interactive ascii    -> agfv     
- tiny ascii           -> agft
- graphviz dot         -> agfd  
- graphviz w/ metadata -> agfdm 
- json                 -> agfj 
- json w/ disassembly  -> agfJ  
- gml                  -> agfg  
- SDB key-value        -> agfk 
- r2 commands          -> agf*  
- web/png              -> agfw  

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.


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));
Copy link
Collaborator

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

Copy link
Collaborator

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

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);
Copy link
Collaborator

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

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);
Copy link
Collaborator

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

return false;
}

r_cons_printf ("graph\n[\n" "hierarchic\t1\n" "label\t\"\"\n" "directed\t1\n");
Copy link
Collaborator

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

if (input[2] == 'm') {
r_core_anal_graph (core, r_num_math (core->num, input + 2),
R_CORE_ANAL_GRAPHLINES);
}
Copy link
Collaborator

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 }

if (input[2] == 'f') {
//TODO
}
RAnalFunction *fcn = NULL;
Copy link
Collaborator

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

R_CORE_ANAL_JSON | R_CORE_ANAL_JSON_FORMAT_DISASM);
case 'g':// "agfg"
if (input[2] == 'f') {
//TODO
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uh

if (*(input + 2)) {
ut64 off_fcn = r_num_math (core->num, input + 2);
fcn = r_anal_get_fcn_in (core->anal, off_fcn, 0);
}
Copy link
Collaborator

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)

if (*(input + 2)) {
ut64 off_fcn = r_num_math (core->num, input + 2);
fcn = r_anal_get_fcn_in (core->anal, off_fcn, 0);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@cyanpencil
Copy link
Contributor Author

@radare Thank you for the reviews.
I tried to fix them all with the latest commit.
Let me know if now everything's ok!

@radare radare merged commit 94807b4 into radareorg:master May 7, 2018
@radare
Copy link
Collaborator

radare commented May 7, 2018

Thanks!

@cyanpencil cyanpencil deleted the agf-output-formats branch May 8, 2018 17:37
SakiiR pushed a commit to SakiiR/radare2 that referenced this pull request Jul 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants