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

@cyanpencil cyanpencil commented May 6, 2018

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));

This comment has been minimized.

@radare

radare May 7, 2018
Collaborator

space before = and before (. if you use -1 in the length argument, the bsae64 api will do the strlen for you

This comment has been minimized.

@radare

radare May 7, 2018
Collaborator

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);

This comment has been minimized.

@radare

radare May 7, 2018
Collaborator

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);

This comment has been minimized.

@radare

radare May 7, 2018
Collaborator

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");

This comment has been minimized.

@radare

radare May 7, 2018
Collaborator

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);
}

This comment has been minimized.

@radare

radare May 7, 2018
Collaborator

else goes here , in the same line of the }

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

This comment has been minimized.

@radare

radare May 7, 2018
Collaborator

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

This comment has been minimized.

@radare

radare May 7, 2018
Collaborator

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);
}

This comment has been minimized.

@radare

radare May 7, 2018
Collaborator

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);
}

This comment has been minimized.

@radare

radare May 7, 2018
Collaborator

same here

@cyanpencil
Copy link
Contributor Author

@cyanpencil cyanpencil commented May 7, 2018

@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
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@radare
Copy link
Collaborator

@radare radare commented May 7, 2018

Thanks!

@cyanpencil cyanpencil deleted the cyanpencil:agf-output-formats branch May 8, 2018
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
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants