diff --git a/binr/radare2/radare2.c b/binr/radare2/radare2.c index 8182d71bec..a0729e98d7 100644 --- a/binr/radare2/radare2.c +++ b/binr/radare2/radare2.c @@ -521,11 +521,10 @@ int main(int argc, char **argv, char **envp) { break; case '0': zerosep = true; - //r_config_set (r.config, "scr.color", "false"); /* implicit -q */ r_config_set (r.config, "scr.interactive", "false"); r_config_set (r.config, "scr.prompt", "false"); - r_config_set (r.config, "scr.color", "false"); + r_config_set_i (r.config, "scr.color", COLORS_DISABLED); quiet = true; break; case 'u': @@ -1293,7 +1292,7 @@ int main(int argc, char **argv, char **envp) { #if UNCOLORIZE_NONTTY #if __UNIX__ if (!r_cons_isatty ()) { - r_config_set_i (r.config, "scr.color", 0); + r_config_set_i (r.config, "scr.color", COLORS_DISABLED); } #endif #endif diff --git a/binr/radiff2/radiff2.c b/binr/radiff2/radiff2.c index 3c43ba9917..c5d2e2e76e 100644 --- a/binr/radiff2/radiff2.c +++ b/binr/radiff2/radiff2.c @@ -816,8 +816,8 @@ int main(int argc, char **argv) { addr = "main"; } /* should be in mode not in bool pdc */ - r_config_set (c->config, "scr.color", "false"); - r_config_set (c2->config, "scr.color", "false"); + r_config_set (c->config, "scr.color", COLORS_DISABLED); + r_config_set (c2->config, "scr.color", COLORS_DISABLED); ut64 addra = r_num_math (c->num, addr); bufa = (ut8 *) r_core_cmd_strf (c, "af;pdc @ 0x%08"PFMT64x, addra); diff --git a/doc/all68k.r2 b/doc/all68k.r2 index 27c6122dce..529e6e9f09 100755 --- a/doc/all68k.r2 +++ b/doc/all68k.r2 @@ -3,7 +3,7 @@ # r2 -qi all68k - > all68k.txt # -e scr.color=false +e scr.color=0 e asm.arch=m68k e asm.nbytes=16 diff --git a/doc/fortunes.tips b/doc/fortunes.tips index 3e12f39100..47d4d54941 100644 --- a/doc/fortunes.tips +++ b/doc/fortunes.tips @@ -38,7 +38,7 @@ Step through your seek history with the commands 'u' (undo) and 'U' (redo) Use hasher to calculate hashes of portion blocks of a file Use zoom.byte=entropy and press 'z' in visual mode to zoom out to see the entropy of the whole file Use 'zoom.byte=printable' in zoom mode ('z' in Visual mode) to find strings -Set color to your screen with 'e scr.color=true' +Add colors to your screen with 'e scr.color=X' where 1 is 16 colors, 2 is 256 colors and 3 is 16M colors Trace register changes while debugging with 'e trace.cmtregs=true' Move the comments to the right changing their margin with asm.cmt.margin Execute a command on the visual prompt with cmd.vprompt diff --git a/doc/hud b/doc/hud index c52358f2e4..0ff42680c0 100644 --- a/doc/hud +++ b/doc/hud @@ -6,7 +6,9 @@ analyze function af analyze preludes ap continue process execution dc;?i disable colors e scr.color=0 -enable colors e scr.color=1 +enable colors (ANSI 16) e scr.color=1 +enable colors (256) e scr.color=2 +enable colors (16M) e scr.color=3 randomize colors ecr hide bytes in disassembly e asm.bytes=false show bytes in disassembly e asm.bytes=true diff --git a/doc/node.js/index.js b/doc/node.js/index.js index 7b82656d5c..c64710e9fc 100644 --- a/doc/node.js/index.js +++ b/doc/node.js/index.js @@ -24,7 +24,7 @@ function runWebServer(r) { wwwroot = wwwroot.trim (); r.cmd ("e http.port", function(port) { port = +port.trim (); - r.cmd ("e scr.color=false", function() {}); + r.cmd ("e scr.color=0", function() {}); r.cmd ("e scr.interactive=false", function() {}); r.cmd ("e scr.html=true", function(){}); var app = express(); diff --git a/libr/cons/cons.c b/libr/cons/cons.c index 383700f7c4..2472bbdcfb 100644 --- a/libr/cons/cons.c +++ b/libr/cons/cons.c @@ -73,7 +73,7 @@ static inline void r_cons_write(const char *buf, int len) { R_API RColor r_cons_color_random(ut8 alpha) { RColor rcolor; - if (I.truecolor > 0) { + if (I.color > COLORS_16) { rcolor.r = r_num_rand (0xff); rcolor.g = r_num_rand (0xff); rcolor.b = r_num_rand (0xff); @@ -277,7 +277,7 @@ R_API RCons *r_cons_new() { I.event_interrupt = NULL; I.is_wine = -1; I.fps = 0; - I.use_color = false; + I.color = COLORS_DISABLED; I.blankline = true; I.teefile = NULL; I.fix_columns = 0; @@ -325,7 +325,6 @@ R_API RCons *r_cons_new() { } #endif I.pager = NULL; /* no pager by default */ - I.truecolor = 0; I.mouse = 0; I.cons_stack = r_stack_newf (6, cons_stack_free); I.break_stack = r_stack_newf (6, break_stack_free); diff --git a/libr/cons/grep.c b/libr/cons/grep.c index 7135aaaf0c..18711ff80f 100644 --- a/libr/cons/grep.c +++ b/libr/cons/grep.c @@ -479,7 +479,7 @@ R_API int r_cons_grepbuf(char *buf, int len) { Color_RESET, NULL }; - char *out = r_print_json_indent (buf, I (use_color), " ", palette); + char *out = r_print_json_indent (buf, I (color), " ", palette); if (!out) { return 0; } diff --git a/libr/cons/hud.c b/libr/cons/hud.c index 7f58c3a682..4fa07e1942 100644 --- a/libr/cons/hud.c +++ b/libr/cons/hud.c @@ -149,7 +149,7 @@ R_API char *r_cons_hud(RList *list, const char *prompt) { r_cons_printf (" %c %s\n", first_line? '-': ' ', current_entry); } else { // otherwise we need to emphasize the matching part - if (I (use_color)) { + if (I (color)) { last_color_change = 0; last_mask = 0; r_cons_printf (" %c ", first_line? '-': ' '); diff --git a/libr/cons/pal.c b/libr/cons/pal.c index cc51fefe5e..015937bd34 100644 --- a/libr/cons/pal.c +++ b/libr/cons/pal.c @@ -371,12 +371,12 @@ R_API void r_cons_pal_show () { colors[i].bgcode, colors[i].name); } - switch (r_cons_singleton ()->truecolor) { - case 1: // 256 color palette + switch (r_cons_singleton ()->color) { + case COLORS_256: // 256 color palette r_cons_pal_show_gs (); r_cons_pal_show_256 (); break; - case 2: // 16M + case COLORS_16M: // 16M (truecolor) r_cons_pal_show_gs (); r_cons_pal_show_rgb (); break; diff --git a/libr/cons/rgb.c b/libr/cons/rgb.c index 6228e407c9..77c1a90031 100644 --- a/libr/cons/rgb.c +++ b/libr/cons/rgb.c @@ -103,9 +103,6 @@ static void unrgb (int color, int *r, int *g, int *b) { R_API void r_cons_rgb_init (void) { RCons *cons = r_cons_singleton (); - if (cons->truecolor < 2) { - return; - } if (color_table[255] == 0) { init_color_table (); } @@ -166,7 +163,7 @@ R_API char *r_cons_rgb_str_off(char *outstr, ut64 off) { return r_cons_rgb_str (outstr, r, g, b, false); } -/* Return color string depending on cons->truecolor */ +/* Return color string depending on cons->color */ R_API char *r_cons_rgb_str(char *outstr, ut8 r, ut8 g, ut8 b, ut8 a) { ut8 fgbg = (a == ALPHA_BG)? 48: 38; if (!outstr) { @@ -180,15 +177,15 @@ R_API char *r_cons_rgb_str(char *outstr, ut8 r, ut8 g, ut8 b, ut8 a) { sprintf (outstr, "%s", Color_RESET); return outstr; } - switch (r_cons_singleton ()->truecolor) { - case 1: // 256 color palette + switch (r_cons_singleton ()->color) { + case COLORS_256: // 256 color palette sprintf (outstr, "\x1b[%d;5;%dm", fgbg, rgb (r, g, b)); break; - case 2: // 16M - xterm only + case COLORS_16M: // 16M (truecolor) sprintf (outstr, "\x1b[%d;2;%d;%d;%dm", fgbg, r, g, b); break; - case 0: // ansi 16 colors - default: { + case COLORS_16: // ansi 16 colors + { const char *bold = (a == ALPHA_BOLD)? "1;": ""; int k = (r + g + b) / 3; r = (r >= k) ? 1 : 0; diff --git a/libr/core/canal.c b/libr/core/canal.c index bcf306258e..12e67d071f 100644 --- a/libr/core/canal.c +++ b/libr/core/canal.c @@ -958,7 +958,7 @@ static char *core_anal_graph_label(RCore *core, RAnalBlock *bb, int opts) { const bool scrColor = r_config_get (core->config, "scr.color"); const bool scrUtf8 = r_config_get (core->config, "scr.utf8"); const bool asmComments = r_config_get (core->config, "asm.comments"); - r_config_set (core->config, "scr.color", "false"); + r_config_set (core->config, "scr.color", COLORS_DISABLED); r_config_set (core->config, "scr.utf8", "false"); r_config_set (core->config, "asm.comments", "false"); snprintf (cmd, sizeof (cmd), diff --git a/libr/core/cconfig.c b/libr/core/cconfig.c index d58ba7eaf4..7eb91716a0 100644 --- a/libr/core/cconfig.c +++ b/libr/core/cconfig.c @@ -1010,10 +1010,10 @@ static int cb_color(void *user, void *data) { if (node->i_value) { core->print->flags |= R_PRINT_FLAGS_COLOR; } else { - //c:core->print->flags ^= R_PRINT_FLAGS_COLOR; core->print->flags &= (~R_PRINT_FLAGS_COLOR); } - r_cons_singleton ()->use_color = node->i_value? 1: 0; + r_cons_singleton ()->color = (node->i_value > COLORS_16M)? COLORS_16M: node->i_value; + r_cons_pal_update_event (); r_print_set_flags (core->print, core->print->flags); return true; } @@ -1796,14 +1796,6 @@ static int cb_tracetag(void *user, void *data) { return true; } -static int cb_truecolor(void *user, void *data) { - RConfigNode *node = (RConfigNode *) data; - ut64 val = node->i_value > 2 ? 2 : node->i_value; - r_cons_singleton ()->truecolor = val; - r_cons_pal_update_event (); - return true; -} - static int cb_utf8(void *user, void *data) { RCore *core = (RCore *) user; RConfigNode *node = (RConfigNode *) data; @@ -2788,8 +2780,7 @@ R_API int r_core_config_init(RCore *core) { SETCB ("scr.prompt", "true", &cb_scrprompt, "Show user prompt (used by r2 -q)"); SETCB ("scr.tee", "", &cb_teefile, "Pipe output to file of this name"); SETPREF ("scr.seek", "", "Seek to the specified address on startup"); - SETICB ("scr.truecolor", 0, &cb_truecolor, "Manage color palette (0: ansi 16, 1: 256, 2: 16M)"); - SETCB ("scr.color", (core->print->flags&R_PRINT_FLAGS_COLOR)?"true":"false", &cb_color, "Enable colors"); + SETICB ("scr.color", (core->print->flags&R_PRINT_FLAGS_COLOR)?COLORS_16:COLORS_DISABLED, &cb_color, "Enable colors (0: none, 1: ansi, 2: 256 colors, 3: truecolor)"); SETCB ("scr.null", "false", &cb_scrnull, "Show no output"); SETCB ("scr.utf8", r_cons_is_utf8()?"true":"false", &cb_utf8, "Show UTF-8 characters instead of ANSI"); diff --git a/libr/core/cmd.c b/libr/core/cmd.c index 11f6607484..0985f75ac3 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -1439,7 +1439,7 @@ R_API int r_core_cmd_pipe(RCore *core, char *radare_cmd, char *shell_cmd) { r_config_set_i (core->config, "scr.interactive", 0); if (!r_config_get_i (core->config, "scr.pipecolor")) { pipecolor = r_config_get_i (core->config, "scr.color"); - r_config_set_i (core->config, "scr.color", 0); + r_config_set_i (core->config, "scr.color", COLORS_DISABLED); } if (*shell_cmd=='!') { r_cons_grep_parsecmd (shell_cmd, "\""); @@ -1884,7 +1884,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon) { r_config_set_i (core->config, "scr.html", true); } else if (!strcmp (ptr + 1, "T")) { // "|T" scr_color = r_config_get_i (core->config, "scr.color"); - r_config_set_i (core->config, "scr.color", false); + r_config_set_i (core->config, "scr.color", COLORS_DISABLED); core->cons->use_tts = true; } else if (ptr[1]) { // "| grep .." int value = core->num->value; @@ -1904,7 +1904,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon) { scr_html = r_config_get_i (core->config, "scr.html"); r_config_set_i (core->config, "scr.html", 0); scr_color = r_config_get_i (core->config, "scr.color"); - r_config_set_i (core->config, "scr.color", false); + r_config_set_i (core->config, "scr.color", COLORS_DISABLED); } } } @@ -2063,7 +2063,7 @@ next: pipefd = r_cons_pipe_open (str, fdn, ptr[1] == '>'); if (pipefd != -1) { if (!pipecolor) { - r_config_set_i (core->config, "scr.color", 0); + r_config_set_i (core->config, "scr.color", COLORS_DISABLED); } ret = r_core_cmd_subst (core, cmd); r_cons_flush (); diff --git a/libr/core/cmd_eval.c b/libr/core/cmd_eval.c index 04ed466fa4..92be962512 100644 --- a/libr/core/cmd_eval.c +++ b/libr/core/cmd_eval.c @@ -45,7 +45,7 @@ static const char *help_msg_ec[] = { "ec", " prompt red blue", "change color and background of prompt", "", " ", "", "colors:", "", "rgb:000, red, green, blue, #ff0000, ...", - "e scr.truecolor", "=0", "use more colors (0: ansi 16, 1: 256, 2: 16M)", + "e scr.color", "=0", "use more colors (0: no color 1: ansi 16, 2: 256, 3: 16M)", "$DATADIR/radare2/cons", "", "~/.config/radare2/cons ./", NULL }; diff --git a/libr/core/cmd_print.c b/libr/core/cmd_print.c index ad1dcfb491..1a880b2ddd 100644 --- a/libr/core/cmd_print.c +++ b/libr/core/cmd_print.c @@ -1967,7 +1967,7 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) { RConsPrintablePalette *pal = &core->cons->pal; // force defaults r_config_set_i (core->config, "asm.offset", true); - r_config_set_i (core->config, "scr.color", 0); + r_config_set_i (core->config, "scr.color", COLORS_DISABLED); r_config_set_i (core->config, "asm.tabs", 0); r_config_set_i (core->config, "asm.cmt.right", true); r_cons_push(); diff --git a/libr/core/visual.c b/libr/core/visual.c index 9916e54d90..a6493a7748 100644 --- a/libr/core/visual.c +++ b/libr/core/visual.c @@ -203,7 +203,7 @@ R_API int r_core_visual_hud(RCore *core) { char *homehud = r_str_home (R2_HOMEDIR "/hud"); char *res = NULL; char *p = 0; - r_cons_singleton ()->use_color = use_color; + r_cons_singleton ()->color = use_color; showcursor (core, true); if (c && *c && r_file_exists (c)) { diff --git a/libr/core/vmenus.c b/libr/core/vmenus.c index 5a4ecaf3b1..8f3d81097e 100644 --- a/libr/core/vmenus.c +++ b/libr/core/vmenus.c @@ -3150,7 +3150,7 @@ R_API void r_core_visual_colors(RCore *core) { } r_cons_gotoxy (0, 0); r_cons_rgb_str (cstr, rcolor.r, rcolor.g, rcolor.b, ALPHA_NORMAL); - if (r_cons_singleton ()->truecolor < 2) { + if (r_cons_singleton ()->color < COLORS_16M) { rcolor.r &= 0xf; rcolor.g &= 0xf; rcolor.b &= 0xf; diff --git a/libr/include/r_cons.h b/libr/include/r_cons.h index 832d715cf3..411e338210 100644 --- a/libr/include/r_cons.h +++ b/libr/include/r_cons.h @@ -140,6 +140,8 @@ enum { }; #endif +enum { COLORS_DISABLED = 0, COLORS_16, COLORS_256, COLORS_16M }; + enum { ALPHA_RESET = 0x00, ALPHA_NORMAL = 0x01, ALPHA_BG = 0x02, ALPHA_BOLD = 0x03 }; typedef struct rcolor_t { @@ -404,7 +406,7 @@ typedef struct r_cons_t { * current window. If NULL or "" no pager is used. */ char *pager; int blankline; - int truecolor; // 0 = ansi, 1 = rgb (256), 2 = truecolor (16M) + int color; // 0 = none, 1 = ansi (16), 2 = palette (256), 3 = truecolor (16M) char *highlight; int null; // if set, does not show anything int mouse; @@ -427,7 +429,6 @@ typedef struct r_cons_t { char *break_word; int break_word_len; ut64 timeout; - bool use_color; bool grep_color; bool use_tts; bool filter; diff --git a/shlr/www/console.html b/shlr/www/console.html index 174ac72128..23edbbbf98 100644 --- a/shlr/www/console.html +++ b/shlr/www/console.html @@ -57,7 +57,7 @@ function submit(cmd) { }); } function ready() { - r2.cmd("e scr.color=true"); + r2.cmd("e scr.color=3"); var input = document.getElementById('input'); input.focus(); input.onkeypress = function(e){ diff --git a/shlr/www/enyo/r2core.js b/shlr/www/enyo/r2core.js index 48634cd108..6b8d98c165 100644 --- a/shlr/www/enyo/r2core.js +++ b/shlr/www/enyo/r2core.js @@ -1,3 +1,3 @@ -function toggle_minimap(){r2ui._dis.minimap?(r2ui._dis.minimap=!1,r2ui.seek(r2ui._dis.selected_offset,!1),$("#minimap").hide()):(r2ui._dis.minimap=!0,r2ui.seek(r2ui._dis.selected_offset,!1),$("#minimap").show())}function update_minimap(){if(r2ui._dis.minimap&&$("#canvas svg").length){var e=200,t=200,n=$("#canvas svg")[0].getBBox().width,i=$("#canvas svg")[0].getBBox().height,r=Math.ceil(n/e),a=Math.ceil(i/t),s=1/Math.max(r,a),o=0;a>r&&(o=e/2-n*s/2);var c=null;$("#radareApp_mp").length?c=$("#main_panel"):$("#main_panel").length&&(c=$("#center_panel")),c.scrollTop()0?(i.addEdge(s,a.fail,"red"),a.jump>0&&i.addEdge(s,a.jump,"green")):a.jump>0&&i.addEdge(s,a.jump,"blue")}}i.render();var u=$("#canvas svg g .element");return u.on("mousedown",function(){flag=0}),u.on("mousemove",function(){flag=1}),u.on("mouseup",function(e){if(0===flag){var t=e.target.parentNode.parentNode.parentNode.getAttribute("model-id");if("minimap_area"!==t){var n=r2ui.get_fcn_BB(r2ui.current_fcn_offset,t);void 0!==n&&null!==n?"red"===n.color?n.color=r2ui.colors[".ec_gui_alt_background"]:n.color="red":n={x:"null",y:"null",color:"red"},r2ui.update_fcn_BB(r2ui.current_fcn_offset,t,n),reposition_graph()}}}),$(".addr").css("-webkit-user-select","text"),!0}function render_instructions(e){var t=document.createElement("div");t.id="outergbox";var n=document.getElementById("canvas");n.innerHTML="";var i=document.createElement("div");i.id="gbox",i.className="ec_gui_background",t.appendChild(i),n.appendChild(t);var r=getOffsetRect(n),a=r2.settings["asm.lines"],s=r2.settings["asm.offset"],o=r.top,c=[],d={},l=e[0].offset,p=e[e.length-1].offset;for(var f in e){var u=e[f];if(("jmp"==u.type||"cjmp"==u.type)&&void 0!==u.jump&&null!==u.jump){var m={};m.from=u.offset,pu.jump?(m.to_end=!1,m.to=l):(m.to_end=!0,m.to=u.jump),"jmp"==u.type?(m.color=r2ui.colors[".ec_flow"],m.dashed=!1):"cjmp"==u.type&&(m.color=r2ui.colors[".ec_gui_cflow"],m.dashed=!0),m.to_start=!0,c[c.length]=m,void 0===d[m.to]&&(d[m.to]=0)}if(void 0===u.comment||null===u.comment)u.comment="";else try{u.comment=atob(u.comment)}catch(_){console.log(u.comment)}var g=document.createElement("div");a?g.className="instructionbox enyo-selectable lines":g.className="instructionbox",g.style.top=o+"px",g.innerHTML=html_for_instruction(u),i.appendChild(g);var h=getOffsetRect(g),v=h.bottom-h.top;o+=v}if(a){var b=document.createElement("canvas");b.width=500,b.height=o,b.id="linecanvas",b.setAttribute("tabindex","1"),b.setAttribute("style","outline: none;"),i.appendChild(b);var y=b.getContext("2d");y.setLineDash||(y.setLineDash=function(){});var x=countProperties(d),k=0,B=100;for(var j in c){var m=c[j],w="0x"+m.from.toString(16),T="0x"+m.to.toString(16);0===d[m.to]&&(d[m.to]=(x-k-1)*(90/(x+1)),k+=1);var M=get_element_by_address(w),E=get_element_by_address(T);if(null!==M&&void 0!==M&&void 0!==E&&null!==E){var S=d[m.to],R=getOffsetRect(M),C=(R.top+R.bottom)/2,L=getOffsetRect(E),z=(L.top+L.bottom)/2;m.to==e[0].offset&&(z=0),y.beginPath(),y.moveTo(S,C),y.lineTo(S,z),y.strokeStyle=m.color,m.dashed&&y.setLineDash([2,3]),y.stroke(),m.to_start&&(y.beginPath(),y.moveTo(S,C),y.lineTo(B-5,C),y.strokeStyle=m.color,m.dashed&&y.setLineDash([2,3]),y.stroke(),y.beginPath(),y.arc(B-5-2,C,2,0,2*Math.PI,!1),y.fillStyle=m.color,y.fill()),m.to_end&&(y.beginPath(),y.moveTo(S,z),y.lineTo(B-5,z),y.strokeStyle=m.color,m.dashed&&y.setLineDash([2,3]),y.stroke(),y.beginPath(),y.moveTo(B-5,z),y.lineTo(B-10,z-5),y.lineTo(B-10,z+5),y.lineWidth=1,y.fillStyle=m.color,y.fill())}}}if(!s){var P=document.getElementsByClassName("insaddr");for(var O in P)P[O].style&&(P[O].style.display="none")}$(".addr").css("-moz-user-select","text"),$(".addr").css("-webkit-user-select","text")}function getOffsetRect(e){var t=e.getBoundingClientRect(),n=$("#gbox").offset().top,i=t.top-n,r=t.bottom-n;return{top:Math.round(i),bottom:Math.round(r)}}function countProperties(e){var t=0;for(var n in e)e.hasOwnProperty(n)&&++t;return t}function toBoolean(e){return"true"===e?!0:"false"===e?!1:void 0}function html_for_instruction(e){var t='
',n="0x"+e.offset.toString(16),i=n,r=r2.settings["asm.flags"],a=r2.settings["asm.bytes"],s=r2.settings["asm.xrefs"],o=r2.settings["asm.cmt.right"];if(e.fcn_addr>0&&n==="0x"+e.fcn_addr.toString(16)){"flat"==r2ui._dis.display&&(t+='
; -----------------------------------------------------------
');var c,d="afij "+n+";afvj "+n+";afaj "+n;r2.cmd(d,function(e){c=e.split("\n")});var l=JSON.parse(c[0]);null!==l&&void 0!==l&&l.length>0&&(t+='
(fcn) '+l[0].name+"
");var p=JSON.parse(c[1]),f=[];for(var u in p)t+='
; '+p[u].kind+" "+p[u].type+" "+escapeHTML(p[u].name)+" @ "+p[u].ref+"
",f[f.length]={name:p[u].name,id:address_canonicalize(n)+"_"+p[u].ref};r2.varMap[e.fcn_addr]=f;var m=JSON.parse(c[2]),_=[];for(var u in m)t+='
; '+m[u].kind+" "+m[u].type+" "+escapeHTML(m[u].name)+" @ "+m[u].ref+"
",_[_.length]={name:m[u].name,id:address_canonicalize(n)+"_"+m[u].ref};r2.argMap[e.fcn_addr]=_}if(r){var g;g=void 0!==e.flags&&null!==e.flags?e.flags.join(";"):r2.get_flag_names(address_canonicalize(n)).join(";"),""!==g&&void 0!==g&&null!==g&&(t+='
;-- '+escapeHTML(g)+":
")}if(e.comment&&!o&&(t+='
; '+escapeHTML(e.comment)+"
"),s&&void 0!==e.xrefs&&null!==e.xrefs&&e.xrefs.length>0){for(var u in e.xrefs){var h=e.xrefs[u],v="",b="0x"+h.addr.toString(16);r2.get_flag_names(address_canonicalize(b)).length>0&&(v=" ("+r2.get_flag_names(address_canonicalize(b)).join(";")+")"),t+='
; '+h.type.toUpperCase()+' XREF from '+b+" "+v+"
"}}if(t+=''+i+" ",a&&void 0!==e.bytes&&null!==e.bytes&&""!==e.bytes){var y=function(e){return"00"==e?'00':"ff"==e?'ff':"7f"==e?'7f':void 0},x=e.bytes.replace(new RegExp("(00)|(ff)|(7f)","g"),y);t+=''+x+" "}var $=highlight_instruction(e.opcode,!0);if(null!==r2.varMap[e.fcn_addr]&&void 0!==r2.varMap[e.fcn_addr]&&r2.varMap[e.fcn_addr].length>0||null!==r2.argMap[e.fcn_addr]&&void 0!==r2.argMap[e.fcn_addr]&&r2.argMap[e.fcn_addr].length>0){for(var u in r2.varMap[e.fcn_addr]){var k=r2.varMap[e.fcn_addr][u].name,B=r2.varMap[e.fcn_addr][u].id;$=$.replace(" "+k+" "," "+escapeHTML(k)+" ")}for(var u in r2.argMap[e.fcn_addr]){var j=r2.argMap[e.fcn_addr][u];r2.argMap[e.fcn_addr][u].id;$=$.replace(" "+j+" "," "+escapeHTML(k)+" ")}}return void 0!==e.type&&null!==e.type?(contains(math,e.type)&&(e.type="math"),contains(bin,e.type)&&(e.type="bin"),"ill"==e.type&&(e.type="invalid"),"null"==e.type&&(e.type="invalid"),"undefined"==e.type&&(e.type="invalid"),"ujmp"==e.type&&(e.type="jmp"),"upush"==e.type&&(e.type="push"),"upop"==e.type&&(e.type="pop"),"ucall"==e.type&&(e.type="call"),"lea"==e.type&&(e.type="mov"),contains(known_types,e.type)||(e.type="other"),t+='
'+$+"
"):t+='
'+$+"
",e.ptr_info&&(t+=''+escapeHTML(e.ptr_info)+""),e.comment&&o&&(t+=' ; '+escapeHTML(e.comment)+""),"ret"==e.type&&(t+="
 
"),t+="
"}function highlight_instruction(e,t){function n(e){if("0x"!=e.substr(0,2))return a[e];var t=r2.get_flag_names(address_canonicalize(e));for(var n in t){if(t[n].indexOf("sym.imp."))return""+t[n]+"";if(t[n].indexOf("fcn."))return""+t[n]+""}var i=get_data_type(e);return""===i?""+e+"":"datainstruction"===i?""+e+"":"datamemory"===i?""+e+"":void 0}if(void 0===e)return"undefined";void 0===t&&(t=!0);var i=escapeHTML(e),r="(0x[0123456789abcdef]+)",a={};if(t){for(var s in regs){var o=''+regs[s]+"";a[regs[s]]=o,o=''+regs[s].toLowerCase()+"",a[regs[s].toLowerCase()]=o}for(s in a)r+="|("+s+")"}return i.replace(new RegExp(r,"g"),n)}function hex2(e){if(void 0===e)return"__";var t=e.toString(16);return 1==t.length?"0"+t:t}function hex(e){return void 0===e?"":(0>e&&(e+=4294967296),"0x"+e.toString(16))}function get_data_type(e,t){var n=r2.get_address_type(e);return""===n?"":void 0!==t?"data"+n+" addr addr_"+e:"data"+n}function fnum(e){return parseInt(e,10)}function get_address_from_class(e,t){void 0===t&&(t="addr");var n=t+"_";if(e){var i=e.className.split(" ").filter(function(e){return e.substr(0,n.length)==t+"_"});if(1==i.length)return i[0].split("_")[1].split(" ")[0]}}function rehighlight_iaddress(e,t){void 0===t&&(t="addr"),$(".autohighlighti").removeClass("autohighlighti"),$("."+t+"_"+e).addClass("autohighlighti"),"addr"===t&&r2.cmd("s "+e,function(){})}function rehighlight_id(e){$(".autohighlighti").removeClass("autohighlighti"),$("#"+e).addClass("autohighlighti")}function get_element_by_address(e){var t=$(".insaddr.addr_"+e);return 1===t.length?t[0]:null}function scroll_to_address(e){var t=$(".insaddr.addr_"+e),n=t[0].documentOffsetTop()-window.innerHeight/2;n=Math.max(0,n),$("#main_panel").scrollTo({top:n,left:0})}function has_scrollbar(e){return e.scrollHeight>e.clientHeight}function on_scroll(e){if(!r2ui._dis.scrolling){var t=!!$("#radareApp").length,n=!1;if(t||(n=0===$("#main_panel").tabs("option","active")),r2ui._dis.scrolling=!0,"flat"==r2ui._dis.display&&(t||n)){var i=null,r=null,a=null;t?(i=$("#main_panel").scrollTop(),r=$("#gbox").height()-$("#main_panel").height()-10,container_element=$("#center_panel")):(i=$("#center_panel").scrollTop(),r=$("#gbox").height()-$("#center_panel").height()-10,container_element=$("#disasm_tab")),has_scrollbar($("#center_panel")[0])&&(0===i?(a="0x"+r2ui._dis.instructions[0].offset.toString(16),r2.get_disasm_before(a,50,function(e){r2ui._dis.instructions=e.concat(r2ui._dis.instructions)}),container_element.html("
"),render_instructions(r2ui._dis.instructions),scroll_to_address(a),rehighlight_iaddress(r2ui._dis.selected_offset)):i>r&&(a="0x"+r2ui._dis.instructions[r2ui._dis.instructions.length-1].offset.toString(16),r2.get_disasm_after(a,100,function(e){r2ui._dis.instructions=r2ui._dis.instructions.slice(0,-1).concat(e)}),container_element.html("
"),render_instructions(r2ui._dis.instructions),scroll_to_address(a),rehighlight_iaddress(r2ui._dis.selected_offset)))}r2ui._dis.scrolling=!1,e.preventDefault()}}function scroll_to_element(e){var t=e.documentOffsetTop()-window.innerHeight/2;t=Math.max(0,t),$("#main_panel").scrollTo({top:t,left:0})}function rename(e,t,n,i){if(void 0===i&&(i="functions"),"functions"==i&&r2.cmdj("pdfj @ "+e,function(t){null!==t&&void 0!==t&&"0x"+t.addr.toString(16)===e&&r2.cmd("afn "+n+" "+e,function(){r2.update_flags()})}),""!==n&&""!==t){var r="fs "+i+";fr "+t+" "+n;r2.cmd(r,function(){})}else if(""===n&&""!==t){var r="fs "+i+";f-@"+e;r2.cmd(r,function(){})}else if(""!==n&&""===t){var r="fs "+i+";f "+n+" @ "+e;r2.cmd(r,function(){})}r2.update_flags()}function address_canonicalize(e){for(e=e.substr(2);"0"==e.substr(0,1);)e=e.substr(1);return e="0x"+e,e=e.toLowerCase()}function contains(e,t){for(var n=0;n0x"+e.toString(16)+"",this.vertices[e].rendered=n}void 0!==t&&(this.vertices[e].len=t,this.vertices[e].rendered=n)},BBGraph.prototype.addEdge=function(e,t,n){this.addVertex(e),this.addVertex(t),this.edges.push({from:e,to:t,color:n}),this.vertices[e].children.push(t),this.vertices[t].parents.push(e)},BBGraph.prototype.makeElement=function(e,t,n,i){this.elements.push(new joint.shapes.html.Element({id:String(e),size:{width:t,height:n},html:i}))},BBGraph.prototype.makeLink=function(e,t,n){this.links.push(new joint.dia.Link({source:{id:String(e)},target:{id:String(t)},attrs:{".marker-target":{d:"M 6 0 L 0 3 L 6 6 z",fill:n,stroke:n},".connection":{"stroke-width":1,stroke:n}},smooth:!0}))},adjustVertices=function(e,t){if(t=t.model||t,t instanceof joint.dia.Element)return void _.chain(e.getConnectedLinks(t)).groupBy(function(e){return _.omit([e.get("source").id,e.get("target").id],t.id)[0]}).each(function(t,n){"undefined"!==n&&adjustVertices(e,_.first(t))});var n=t.get("source").id||t.previous("source").id,i=t.get("target").id||t.previous("target").id,r=_.filter(e.getLinks(),function(e){var t=e.get("source").id,r=e.get("target").id;return t===n&&r===i||t===i&&r===n});if(r.length>1){var a=r2ui.graph.getCell(n).getBBox(),s=r2ui.graph.getCell(i).getBBox();src=a.intersectionWithLineFromCenterToPoint(s.center()),dst=s.intersectionWithLineFromCenterToPoint(a.center());var o=g.line(src,dst).midpoint(),c=src.theta(dst),d=10;_.each(r,function(e,t){var n=d,i=t%2?1:-1,r=g.toRad(c+90*i),l=g.point.fromPolar(n,r,o);a.containsPoint(l)||s.containsPoint(l)?e.unset("vertices"):e.set("vertices",[{x:l.x,y:l.y}])})}},BBGraph.prototype.render=function(){var e=Object.keys(this.vertices).toString(),t=document.createElement("div");t.id="outergbox";var n=document.getElementById("canvas"),i=document.createElement("div");i.id="gbox",i.className=e,t.appendChild(i),n.appendChild(t);for(var r in this.vertices){var a=this.vertices[r].rendered;void 0!==a&&(i.appendChild(a),this.makeElement(r,a.offsetWidth,a.offsetHeight,a.outerHTML))}for(var s=0;s");var o=this.elements.concat(this.links),c=($("#center_panel").width(),new joint.dia.Graph),d=new joint.dia.Paper({el:$("#canvas"),gridSize:1,width:2e3,height:6e3,model:c}),l=200,p=200;$("#minimap").html(""),$("#minimap").html("");var f=new joint.dia.Paper({el:$("#minimap"),gridSize:1,width:l,height:p,model:c});c.resetCells(o),joint.layout.DirectedGraph.layout(c),r2ui.graph=c,reposition_graph(),$("#minimap .basicblock").remove(),c.getCell("minimap_area").attr({rect:{stroke:"transparent"}});var u=$("#canvas svg")[0].getBBox().width,m=$("#canvas svg")[0].getBBox().height;d.setDimensions(u+500,m+500);var g=Math.ceil(u/l),h=Math.ceil(m/p),v=1/Math.max(g,h),b=0;h>g&&(b=l/2-u*v/2),f.scale(v),f.setOrigin(b,0),$("#radareApp_mp").length?($("#minimap").css("left",$("#main_panel").width()-l-$("#main_panel").position().left),$("#minimap").css("top",$("#center_panel").position().top),$("#main_panel").bind("scroll",update_minimap)):$("#main_panel").length&&($("#minimap").css("left",$("#main_panel").width()-l),$("#minimap").css("top",$("#center_panel").position().top-40),$("#center_panel").bind("scroll",update_minimap)),d.on("cell:pointerup",function(e){var t=e.model,n=t.attributes.position,i=String(t.prop("id"));if(void 0!==t&&"minimap_area"!==i){var r=r2ui.get_fcn_BB(r2ui.current_fcn_offset,i);void 0!==r&&null!==r?r.x==String(n.x)&&r.y==String(n.y)||(r.x=n.x,r.y=n.y,r2ui.update_fcn_BB(r2ui.current_fcn_offset,i,r)):void 0!==r&&null!==r&&r2ui.update_fcn_BB(r2ui.current_fcn_offset,i,{x:n.x,y:n.y})}});var y=_.partial(adjustVertices,c);_.each(c.getLinks(),y),d.on("cell:pointerup",y),r2ui._dis.minimap?(update_minimap(),$("#minimap_area").draggable({containment:"parent",stop:function(e,t){var n=t.position.left/v,i=t.position.top/v;0>n&&(n=0),0>i&&(i=0),$("#radareApp_mp").length?$("#main_panel").scrollTo({top:i,left:n-b/v}):$("#center_panel").scrollTo({top:i,left:n-b/v})}})):$("#minimap").hide()};var flag=0,math=["add","sub","mul","imul","div","idiv","neg","adc","sbb","inc","dec",".byte"],bin=["xor","and","or","not"],regs=["EAX","ECX","EDX","EBX","ESP","EBP","ESI","EDI","EIP","RAX","RCX","RDX","RBX","RSP","RBP","RSI","RDI","R0","R1","R2","R3","R4","R5","R6","R7","R8","R9","R10","R11","R12","R13","R14","R15","RIP"],known_types=["fline","help","args","label","flow","prompt","input","btext","swi","comment","fname","flag","offset","other","b0x00","b0x7f","b0xff","math","bin","push","pop","jmp","cjmp","call","nop","ret","trap","invalid","cmp","reg","creg","mov","num"],escapeHTML=function(){"use strict";var e={'"':""","&":"&","<":"<",">":">"};return function(t){return t?t.replace(/[\"&<>]/g,function(t){return e[t]}):""}}();Element.prototype.documentOffsetTop=function(){return this.offsetTop+(this.offsetParent?this.offsetParent.documentOffsetTop():0)}; +function toggle_minimap(){r2ui._dis.minimap?(r2ui._dis.minimap=!1,r2ui.seek(r2ui._dis.selected_offset,!1),$("#minimap").hide()):(r2ui._dis.minimap=!0,r2ui.seek(r2ui._dis.selected_offset,!1),$("#minimap").show())}function update_minimap(){if(r2ui._dis.minimap&&$("#canvas svg").length){var e=200,t=200,n=$("#canvas svg")[0].getBBox().width,i=$("#canvas svg")[0].getBBox().height,r=Math.ceil(n/e),a=Math.ceil(i/t),s=1/Math.max(r,a),o=0;a>r&&(o=e/2-n*s/2);var c=null;$("#radareApp_mp").length?c=$("#main_panel"):$("#main_panel").length&&(c=$("#center_panel")),c.scrollTop()0?(i.addEdge(s,a.fail,"red"),a.jump>0&&i.addEdge(s,a.jump,"green")):a.jump>0&&i.addEdge(s,a.jump,"blue")}}i.render();var u=$("#canvas svg g .element");return u.on("mousedown",function(){flag=0}),u.on("mousemove",function(){flag=1}),u.on("mouseup",function(e){if(0===flag){var t=e.target.parentNode.parentNode.parentNode.getAttribute("model-id");if("minimap_area"!==t){var n=r2ui.get_fcn_BB(r2ui.current_fcn_offset,t);void 0!==n&&null!==n?"red"===n.color?n.color=r2ui.colors[".ec_gui_alt_background"]:n.color="red":n={x:"null",y:"null",color:"red"},r2ui.update_fcn_BB(r2ui.current_fcn_offset,t,n),reposition_graph()}}}),$(".addr").css("-webkit-user-select","text"),!0}function render_instructions(e){var t=document.createElement("div");t.id="outergbox";var n=document.getElementById("canvas");n.innerHTML="";var i=document.createElement("div");i.id="gbox",i.className="ec_gui_background",t.appendChild(i),n.appendChild(t);var r=getOffsetRect(n),a=r2.settings["asm.lines"],s=r2.settings["asm.offset"],o=r.top,c=[],d={},l=e[0].offset,p=e[e.length-1].offset;for(var f in e){var u=e[f];if(("jmp"==u.type||"cjmp"==u.type)&&void 0!==u.jump&&null!==u.jump){var m={};m.from=u.offset,pu.jump?(m.to_end=!1,m.to=l):(m.to_end=!0,m.to=u.jump),"jmp"==u.type?(m.color=r2ui.colors[".ec_flow"],m.dashed=!1):"cjmp"==u.type&&(m.color=r2ui.colors[".ec_gui_cflow"],m.dashed=!0),m.to_start=!0,c[c.length]=m,void 0===d[m.to]&&(d[m.to]=0)}if(void 0===u.comment||null===u.comment)u.comment="";else try{u.comment=atob(u.comment)}catch(_){console.log(u.comment)}var g=document.createElement("div");a?g.className="instructionbox enyo-selectable lines":g.className="instructionbox",g.style.top=o+"px",g.innerHTML=html_for_instruction(u),i.appendChild(g);var h=getOffsetRect(g),v=h.bottom-h.top;o+=v}if(a){var b=document.createElement("canvas");b.width=500,b.height=o,b.id="linecanvas",b.setAttribute("tabindex","1"),b.setAttribute("style","outline: none;"),i.appendChild(b);var y=b.getContext("2d");y.setLineDash||(y.setLineDash=function(){});var x=countProperties(d),k=0,B=100;for(var j in c){var m=c[j],w="0x"+m.from.toString(16),T="0x"+m.to.toString(16);0===d[m.to]&&(d[m.to]=(x-k-1)*(90/(x+1)),k+=1);var M=get_element_by_address(w),E=get_element_by_address(T);if(null!==M&&void 0!==M&&void 0!==E&&null!==E){var S=d[m.to],R=getOffsetRect(M),C=(R.top+R.bottom)/2,L=getOffsetRect(E),z=(L.top+L.bottom)/2;m.to==e[0].offset&&(z=0),y.beginPath(),y.moveTo(S,C),y.lineTo(S,z),y.strokeStyle=m.color,m.dashed&&y.setLineDash([2,3]),y.stroke(),m.to_start&&(y.beginPath(),y.moveTo(S,C),y.lineTo(B-5,C),y.strokeStyle=m.color,m.dashed&&y.setLineDash([2,3]),y.stroke(),y.beginPath(),y.arc(B-5-2,C,2,0,2*Math.PI,!1),y.fillStyle=m.color,y.fill()),m.to_end&&(y.beginPath(),y.moveTo(S,z),y.lineTo(B-5,z),y.strokeStyle=m.color,m.dashed&&y.setLineDash([2,3]),y.stroke(),y.beginPath(),y.moveTo(B-5,z),y.lineTo(B-10,z-5),y.lineTo(B-10,z+5),y.lineWidth=1,y.fillStyle=m.color,y.fill())}}}if(!s){var P=document.getElementsByClassName("insaddr");for(var O in P)P[O].style&&(P[O].style.display="none")}$(".addr").css("-moz-user-select","text"),$(".addr").css("-webkit-user-select","text")}function getOffsetRect(e){var t=e.getBoundingClientRect(),n=$("#gbox").offset().top,i=t.top-n,r=t.bottom-n;return{top:Math.round(i),bottom:Math.round(r)}}function countProperties(e){var t=0;for(var n in e)e.hasOwnProperty(n)&&++t;return t}function toBoolean(e){return"true"===e?!0:"false"===e?!1:void 0}function html_for_instruction(e){var t='
',n="0x"+e.offset.toString(16),i=n,r=r2.settings["asm.flags"],a=r2.settings["asm.bytes"],s=r2.settings["asm.xrefs"],o=r2.settings["asm.cmt.right"];if(e.fcn_addr>0&&n==="0x"+e.fcn_addr.toString(16)){"flat"==r2ui._dis.display&&(t+='
; -----------------------------------------------------------
');var c,d="afij "+n+";afvj "+n+";afaj "+n;r2.cmd(d,function(e){c=e.split("\n")});var l=JSON.parse(c[0]);null!==l&&void 0!==l&&l.length>0&&(t+='
(fcn) '+l[0].name+"
");var p=JSON.parse(c[1]),f=[];for(var u in p)t+='
; '+p[u].kind+" "+p[u].type+" "+escapeHTML(p[u].name)+" @ "+p[u].ref+"
",f[f.length]={name:p[u].name,id:address_canonicalize(n)+"_"+p[u].ref};r2.varMap[e.fcn_addr]=f;var m=JSON.parse(c[2]),_=[];for(var u in m)t+='
; '+m[u].kind+" "+m[u].type+" "+escapeHTML(m[u].name)+" @ "+m[u].ref+"
",_[_.length]={name:m[u].name,id:address_canonicalize(n)+"_"+m[u].ref};r2.argMap[e.fcn_addr]=_}if(r){var g;g=void 0!==e.flags&&null!==e.flags?e.flags.join(";"):r2.get_flag_names(address_canonicalize(n)).join(";"),""!==g&&void 0!==g&&null!==g&&(t+='
;-- '+escapeHTML(g)+":
")}if(e.comment&&!o&&(t+='
; '+escapeHTML(e.comment)+"
"),s&&void 0!==e.xrefs&&null!==e.xrefs&&e.xrefs.length>0){for(var u in e.xrefs){var h=e.xrefs[u],v="",b="0x"+h.addr.toString(16);r2.get_flag_names(address_canonicalize(b)).length>0&&(v=" ("+r2.get_flag_names(address_canonicalize(b)).join(";")+")"),t+='
; '+h.type.toUpperCase()+' XREF from '+b+" "+v+"
"}}if(t+=''+i+" ",a&&void 0!==e.bytes&&null!==e.bytes&&""!==e.bytes){var y=function(e){return"00"==e?'00':"ff"==e?'ff':"7f"==e?'7f':void 0},x=e.bytes.replace(new RegExp("(00)|(ff)|(7f)","g"),y);t+=''+x+" "}var $=highlight_instruction(e.opcode,!0);if(null!==r2.varMap[e.fcn_addr]&&void 0!==r2.varMap[e.fcn_addr]&&r2.varMap[e.fcn_addr].length>0||null!==r2.argMap[e.fcn_addr]&&void 0!==r2.argMap[e.fcn_addr]&&r2.argMap[e.fcn_addr].length>0){for(var u in r2.varMap[e.fcn_addr]){var k=r2.varMap[e.fcn_addr][u].name,B=r2.varMap[e.fcn_addr][u].id;$=$.replace(" "+k+" "," "+escapeHTML(k)+" ")}for(var u in r2.argMap[e.fcn_addr]){var j=r2.argMap[e.fcn_addr][u];r2.argMap[e.fcn_addr][u].id;$=$.replace(" "+j+" "," "+escapeHTML(k)+" ")}}return void 0!==e.type&&null!==e.type?(contains(math,e.type)&&(e.type="math"),contains(bin,e.type)&&(e.type="bin"),"ill"==e.type&&(e.type="invalid"),"null"==e.type&&(e.type="invalid"),"undefined"==e.type&&(e.type="invalid"),"ujmp"==e.type&&(e.type="jmp"),"upush"==e.type&&(e.type="push"),"upop"==e.type&&(e.type="pop"),"ucall"==e.type&&(e.type="call"),"lea"==e.type&&(e.type="mov"),contains(known_types,e.type)||(e.type="other"),t+='
'+$+"
"):t+='
'+$+"
",e.ptr_info&&(t+=''+escapeHTML(e.ptr_info)+""),e.comment&&o&&(t+=' ; '+escapeHTML(e.comment)+""),"ret"==e.type&&(t+="
 
"),t+="
"}function highlight_instruction(e,t){function n(e){if("0x"!=e.substr(0,2))return a[e];var t=r2.get_flag_names(address_canonicalize(e));for(var n in t){if(t[n].indexOf("sym.imp."))return""+t[n]+"";if(t[n].indexOf("fcn."))return""+t[n]+""}var i=get_data_type(e);return""===i?""+e+"":"datainstruction"===i?""+e+"":"datamemory"===i?""+e+"":void 0}if(void 0===e)return"undefined";void 0===t&&(t=!0);var i=escapeHTML(e),r="(0x[0123456789abcdef]+)",a={};if(t){for(var s in regs){var o=''+regs[s]+"";a[regs[s]]=o,o=''+regs[s].toLowerCase()+"",a[regs[s].toLowerCase()]=o}for(s in a)r+="|("+s+")"}return i.replace(new RegExp(r,"g"),n)}function hex2(e){if(void 0===e)return"__";var t=e.toString(16);return 1==t.length?"0"+t:t}function hex(e){return void 0===e?"":(0>e&&(e+=4294967296),"0x"+e.toString(16))}function get_data_type(e,t){var n=r2.get_address_type(e);return""===n?"":void 0!==t?"data"+n+" addr addr_"+e:"data"+n}function fnum(e){return parseInt(e,10)}function get_address_from_class(e,t){void 0===t&&(t="addr");var n=t+"_";if(e){var i=e.className.split(" ").filter(function(e){return e.substr(0,n.length)==t+"_"});if(1==i.length)return i[0].split("_")[1].split(" ")[0]}}function rehighlight_iaddress(e,t){void 0===t&&(t="addr"),$(".autohighlighti").removeClass("autohighlighti"),$("."+t+"_"+e).addClass("autohighlighti"),"addr"===t&&r2.cmd("s "+e,function(){})}function rehighlight_id(e){$(".autohighlighti").removeClass("autohighlighti"),$("#"+e).addClass("autohighlighti")}function get_element_by_address(e){var t=$(".insaddr.addr_"+e);return 1===t.length?t[0]:null}function scroll_to_address(e){var t=$(".insaddr.addr_"+e),n=t[0].documentOffsetTop()-window.innerHeight/2;n=Math.max(0,n),$("#main_panel").scrollTo({top:n,left:0})}function has_scrollbar(e){return e.scrollHeight>e.clientHeight}function on_scroll(e){if(!r2ui._dis.scrolling){var t=!!$("#radareApp").length,n=!1;if(t||(n=0===$("#main_panel").tabs("option","active")),r2ui._dis.scrolling=!0,"flat"==r2ui._dis.display&&(t||n)){var i=null,r=null,a=null;t?(i=$("#main_panel").scrollTop(),r=$("#gbox").height()-$("#main_panel").height()-10,container_element=$("#center_panel")):(i=$("#center_panel").scrollTop(),r=$("#gbox").height()-$("#center_panel").height()-10,container_element=$("#disasm_tab")),has_scrollbar($("#center_panel")[0])&&(0===i?(a="0x"+r2ui._dis.instructions[0].offset.toString(16),r2.get_disasm_before(a,50,function(e){r2ui._dis.instructions=e.concat(r2ui._dis.instructions)}),container_element.html("
"),render_instructions(r2ui._dis.instructions),scroll_to_address(a),rehighlight_iaddress(r2ui._dis.selected_offset)):i>r&&(a="0x"+r2ui._dis.instructions[r2ui._dis.instructions.length-1].offset.toString(16),r2.get_disasm_after(a,100,function(e){r2ui._dis.instructions=r2ui._dis.instructions.slice(0,-1).concat(e)}),container_element.html("
"),render_instructions(r2ui._dis.instructions),scroll_to_address(a),rehighlight_iaddress(r2ui._dis.selected_offset)))}r2ui._dis.scrolling=!1,e.preventDefault()}}function scroll_to_element(e){var t=e.documentOffsetTop()-window.innerHeight/2;t=Math.max(0,t),$("#main_panel").scrollTo({top:t,left:0})}function rename(e,t,n,i){if(void 0===i&&(i="functions"),"functions"==i&&r2.cmdj("pdfj @ "+e,function(t){null!==t&&void 0!==t&&"0x"+t.addr.toString(16)===e&&r2.cmd("afn "+n+" "+e,function(){r2.update_flags()})}),""!==n&&""!==t){var r="fs "+i+";fr "+t+" "+n;r2.cmd(r,function(){})}else if(""===n&&""!==t){var r="fs "+i+";f-@"+e;r2.cmd(r,function(){})}else if(""!==n&&""===t){var r="fs "+i+";f "+n+" @ "+e;r2.cmd(r,function(){})}r2.update_flags()}function address_canonicalize(e){for(e=e.substr(2);"0"==e.substr(0,1);)e=e.substr(1);return e="0x"+e,e=e.toLowerCase()}function contains(e,t){for(var n=0;n0x"+e.toString(16)+"",this.vertices[e].rendered=n}void 0!==t&&(this.vertices[e].len=t,this.vertices[e].rendered=n)},BBGraph.prototype.addEdge=function(e,t,n){this.addVertex(e),this.addVertex(t),this.edges.push({from:e,to:t,color:n}),this.vertices[e].children.push(t),this.vertices[t].parents.push(e)},BBGraph.prototype.makeElement=function(e,t,n,i){this.elements.push(new joint.shapes.html.Element({id:String(e),size:{width:t,height:n},html:i}))},BBGraph.prototype.makeLink=function(e,t,n){this.links.push(new joint.dia.Link({source:{id:String(e)},target:{id:String(t)},attrs:{".marker-target":{d:"M 6 0 L 0 3 L 6 6 z",fill:n,stroke:n},".connection":{"stroke-width":1,stroke:n}},smooth:!0}))},adjustVertices=function(e,t){if(t=t.model||t,t instanceof joint.dia.Element)return void _.chain(e.getConnectedLinks(t)).groupBy(function(e){return _.omit([e.get("source").id,e.get("target").id],t.id)[0]}).each(function(t,n){"undefined"!==n&&adjustVertices(e,_.first(t))});var n=t.get("source").id||t.previous("source").id,i=t.get("target").id||t.previous("target").id,r=_.filter(e.getLinks(),function(e){var t=e.get("source").id,r=e.get("target").id;return t===n&&r===i||t===i&&r===n});if(r.length>1){var a=r2ui.graph.getCell(n).getBBox(),s=r2ui.graph.getCell(i).getBBox();src=a.intersectionWithLineFromCenterToPoint(s.center()),dst=s.intersectionWithLineFromCenterToPoint(a.center());var o=g.line(src,dst).midpoint(),c=src.theta(dst),d=10;_.each(r,function(e,t){var n=d,i=t%2?1:-1,r=g.toRad(c+90*i),l=g.point.fromPolar(n,r,o);a.containsPoint(l)||s.containsPoint(l)?e.unset("vertices"):e.set("vertices",[{x:l.x,y:l.y}])})}},BBGraph.prototype.render=function(){var e=Object.keys(this.vertices).toString(),t=document.createElement("div");t.id="outergbox";var n=document.getElementById("canvas"),i=document.createElement("div");i.id="gbox",i.className=e,t.appendChild(i),n.appendChild(t);for(var r in this.vertices){var a=this.vertices[r].rendered;void 0!==a&&(i.appendChild(a),this.makeElement(r,a.offsetWidth,a.offsetHeight,a.outerHTML))}for(var s=0;s");var o=this.elements.concat(this.links),c=($("#center_panel").width(),new joint.dia.Graph),d=new joint.dia.Paper({el:$("#canvas"),gridSize:1,width:2e3,height:6e3,model:c}),l=200,p=200;$("#minimap").html(""),$("#minimap").html("");var f=new joint.dia.Paper({el:$("#minimap"),gridSize:1,width:l,height:p,model:c});c.resetCells(o),joint.layout.DirectedGraph.layout(c),r2ui.graph=c,reposition_graph(),$("#minimap .basicblock").remove(),c.getCell("minimap_area").attr({rect:{stroke:"transparent"}});var u=$("#canvas svg")[0].getBBox().width,m=$("#canvas svg")[0].getBBox().height;d.setDimensions(u+500,m+500);var g=Math.ceil(u/l),h=Math.ceil(m/p),v=1/Math.max(g,h),b=0;h>g&&(b=l/2-u*v/2),f.scale(v),f.setOrigin(b,0),$("#radareApp_mp").length?($("#minimap").css("left",$("#main_panel").width()-l-$("#main_panel").position().left),$("#minimap").css("top",$("#center_panel").position().top),$("#main_panel").bind("scroll",update_minimap)):$("#main_panel").length&&($("#minimap").css("left",$("#main_panel").width()-l),$("#minimap").css("top",$("#center_panel").position().top-40),$("#center_panel").bind("scroll",update_minimap)),d.on("cell:pointerup",function(e){var t=e.model,n=t.attributes.position,i=String(t.prop("id"));if(void 0!==t&&"minimap_area"!==i){var r=r2ui.get_fcn_BB(r2ui.current_fcn_offset,i);void 0!==r&&null!==r?r.x==String(n.x)&&r.y==String(n.y)||(r.x=n.x,r.y=n.y,r2ui.update_fcn_BB(r2ui.current_fcn_offset,i,r)):void 0!==r&&null!==r&&r2ui.update_fcn_BB(r2ui.current_fcn_offset,i,{x:n.x,y:n.y})}});var y=_.partial(adjustVertices,c);_.each(c.getLinks(),y),d.on("cell:pointerup",y),r2ui._dis.minimap?(update_minimap(),$("#minimap_area").draggable({containment:"parent",stop:function(e,t){var n=t.position.left/v,i=t.position.top/v;0>n&&(n=0),0>i&&(i=0),$("#radareApp_mp").length?$("#main_panel").scrollTo({top:i,left:n-b/v}):$("#center_panel").scrollTo({top:i,left:n-b/v})}})):$("#minimap").hide()};var flag=0,math=["add","sub","mul","imul","div","idiv","neg","adc","sbb","inc","dec",".byte"],bin=["xor","and","or","not"],regs=["EAX","ECX","EDX","EBX","ESP","EBP","ESI","EDI","EIP","RAX","RCX","RDX","RBX","RSP","RBP","RSI","RDI","R0","R1","R2","R3","R4","R5","R6","R7","R8","R9","R10","R11","R12","R13","R14","R15","RIP"],known_types=["fline","help","args","label","flow","prompt","input","btext","swi","comment","fname","flag","offset","other","b0x00","b0x7f","b0xff","math","bin","push","pop","jmp","cjmp","call","nop","ret","trap","invalid","cmp","reg","creg","mov","num"],escapeHTML=function(){"use strict";var e={'"':""","&":"&","<":"<",">":">"};return function(t){return t?t.replace(/[\"&<>]/g,function(t){return e[t]}):""}}();Element.prototype.documentOffsetTop=function(){return this.offsetTop+(this.offsetParent?this.offsetParent.documentOffsetTop():0)}; function asyncLoop(n,r,e){var t=0,o=!1,a={next:function(){o||(n>t?(t++,r(a)):(o=!0,e()))},iteration:function(){return t-1},"break":function(){o=!0,e()}};return a.next(),a}function dump(n){var r="";for(var e in n)r+=e+"\n";alert(r)}function objtostr(n){var r="";for(var e in n)r+=e+": "+n[e]+",\n";return r}function Ajax(n,r,e,t){if("undefined"==typeof XMLHttpRequest)return!1;var o=new XMLHttpRequest;return o?(o.open(n,r,!1),o.setRequestHeader("Accept","text/plain"),o.setRequestHeader("Accept","text/html"),o.setRequestHeader("Content-Type","application/x-ww-form-urlencoded; charset=UTF-8"),o.onreadystatechange=function(){200==o.status?t&&t(o.responseText):console.error("ajax "+o.status)},o.send(e),!0):!1}function _internal_cmd(n,r){if("undefined"!=typeof r2cmd&&(hascmd=r2cmd),hascmd){if("undefined"==typeof r2plugin)return hascmd(n,r);r(r2cmd(n))}else Ajax("GET",r2.root+"/cmd/"+encodeURI(n),"",function(n){r&&r(n)})}var r2={},backward=!1,next_curoff=0,next_lastoff=0,prev_curoff=0,prev_lastoff=0,hascmd=!1;"undefined"!=typeof module&&(module.exports=function(n){return hascmd="function"==typeof n?n:n.cmd,r2}),r2.project_name="",r2.plugin=function(){console.error("r2.plugin is not available in this environment")};try{r2plugin&&(r2.plugin=r2plugin)}catch(e){}r2.root="",r2.analAll=function(){r2.cmd("aa",function(){})},r2.analOp=function(n,r){r2.cmd("aoj 1 @ "+n,function(n){try{r(JSON.parse(n)[0])}catch(e){console.error(e),r(n)}})},r2.varMap=[],r2.argMap=[],r2.assemble=function(n,r,e){var t=n?"@"+n:"";r2.cmd('"pa '+r+'"'+t,e)},r2.disassemble=function(n,r,e){var t=n?"@"+n:"",o="pi @b:"+r+t;r2.cmd(o,e)},r2.get_hexdump=function(n,r,e){r2.cmd("px "+r+"@"+n,e)},r2.get_disasm=function(n,r,e){r2.cmd("pD "+r+"@"+n,e)},r2.get_disasm_before=function(n,r,e){var t=[];r2.cmd("pdj -"+r+"@"+n,function(n){t=JSON.parse(n)}),e(t)},r2.get_disasm_after=function(n,r,e){var t=[];r2.cmd("pdj "+r+"@"+n,function(n){t=JSON.parse(n)}),e(t)},r2.get_disasm_before_after=function(n,r,e,t){var o=[],a=[];r2.cmd("pdj "+r+" @"+n,function(n){o=JSON.parse(n)}),r2.cmd("pdj "+e+"@"+n,function(n){a=JSON.parse(n)});var c=o.concat(a);t(c)},r2.Config=function(n,r,e){return"function"!=typeof r&&r?r2.cmd("e "+n+"="+r,e):r2.cmd("e "+n,e||r),r2},r2.sections={},r2.load_mmap=function(){r2.cmdj("iSj",function(n){void 0!==n&&null!==n&&(r2.sections=n)})},r2.get_address_type=function(n){var r=parseInt(n,16);for(var e in r2.sections)if(r>=r2.sections[e].addr&&r-1?"instruction":"memory";return""},r2.settings={},r2.load_settings=function(){r2.cmd("e asm.arch",function(n){r2.settings["asm.arch"]=n.trim()}),r2.cmd("e asm.bits",function(n){r2.settings["asm.bits"]=n.trim()}),r2.cmd("e asm.bytes",function(n){r2.settings["asm.bytes"]=toBoolean(n.trim())}),r2.cmd("e asm.flags",function(n){r2.settings["asm.flags"]=toBoolean(n.trim())}),r2.cmd("e asm.offset",function(n){r2.settings["asm.offset"]=toBoolean(n.trim())}),r2.cmd("e asm.lines",function(n){r2.settings["asm.lines"]=toBoolean(n.trim())}),r2.cmd("e asm.xrefs",function(n){r2.settings["asm.xrefs"]=toBoolean(n.trim())}),r2.cmd("e asm.cmt.right",function(n){r2.settings["asm.cmt.right"]=toBoolean(n.trim())}),r2.cmd("e asm.pseudo",function(n){r2.settings["asm.pseudo"]=toBoolean(n.trim())})},r2.flags={},r2.update_flags=function(){r2.cmd("fs *;fj",function(n){var r=JSON.parse(n);if(void 0!==r&&null!==r){r2.flags={};for(var e in r){var t="0x"+r[e].offset.toString(16);if(t=address_canonicalize(t),t in r2.flags){var o=r2.flags[t];o[o.length]={name:r[e].name,size:r[e].size},r2.flags[t]=o}else r2.flags[t]=[{name:r[e].name,size:r[e].size}]}}})},r2.get_flag_address=function(n){for(var r in r2.flags)for(var e in r2.flags[r])if(n==r2.flags[r][e].name)return r;return null},r2.get_flag_names=function(n){var r=[];for(var e in r2.flags[n])r[r.length]=r2.flags[n][e].name;return r},r2.set_flag_space=function(n,r){r2.cmd("fs "+n,r)},r2.get_flags=function(n){r2.cmd("fj",function(r){n(r?JSON.parse(r):[])})},r2.get_opcodes=function(n,r,e){r2.cmd("pdj @"+n+"!"+r,function(n){e(JSON.parse(n))})},r2.get_bytes=function(n,r,e){r2.cmd("pcj @"+n+"!"+r,function(n){e(JSON.parse(n))})},r2.asm_config={},r2.store_asm_config=function(){config={},r2.cmd("e",function(n){conf=n.split("\n");for(var r in conf){var e=conf[r].split(" ");3==e.length&&0==e[0].trim().indexOf("asm.")&&(config[e[0].trim()]=e[2].trim())}r2.asm_config=config})},r2.restore_asm_config=function(){cmd="";for(var n in r2.asm_config)cmd+="e "+n+"="+r2.asm_config[n]+";";r2.cmd(cmd,function(){})},r2.get_info=function(n){r2.cmd("ij",function(r){n(JSON.parse(r))})},r2.bin_relocs=function(n){r2.cmd("irj",function(r){n(JSON.parse(r))})},r2.bin_imports=function(n){r2.cmd("iij",function(r){n(JSON.parse(r))})},r2.bin_symbols=function(n){r2.cmd("isj",function(r){n(JSON.parse(r))})},r2.bin_sections=function(n){r2.cmd("iSj",function(r){n(JSON.parse(r))})},r2.cmds=function(n,r){function e(){void 0!=t&&0!=n.length&&(t=n[0],n=n.splice(1),r2.cmd(t,e),r&&r())}if(0!=n.length){var t=n[0];n=n.splice(1),r2.cmd(t,e)}},r2.cmd=function(n,r){if(Array.isArray(n)){var e=[],t=0;asyncLoop(n.length,function(r){_internal_cmd(n[t],function(n){t=r.iteration(),e[t]=n.replace(/\n$/,""),t++,r.next()})},function(){r(e)})}else _internal_cmd(n,r)},r2.cmdj=function(n,r){r2.cmd(n,function(n){try{r(JSON.parse(n))}catch(e){r(null)}})},r2.alive=function(n){r2.cmd("b",function(r){var e=!1;r&&r.length()>0&&(e=!0),n&&n(r)})},r2.getTextLogger=function(n){return"object"!=typeof n&&(n={}),n.last=0,n.events={},n.interval=null,r2.cmd("Tl",function(r){n.last=+r}),n.load=function(r){r2.cmd('"Tj '+(n.last+1)+'"',function(n){r&&r(JSON.parse(n))})},n.clear=function(n){r2.cmd("T-",n)},n.send=function(n,r){r2.cmd('"T '+n+'"',r)},n.refresh=function(r){n.load(function(e){for(var t=0;tn.last&&(n.last=o[0])}r&&r()})},n.autorefresh=function(r){function e(){return n.refresh(function(){}),"Logs"===r2ui.selected_panel?setTimeout(e,1e3*r):console.log("Not in logs :("),!0}return r?void(n.interval=setTimeout(e,1e3*r)):void(n.interval&&n.interval.stop())},n.on=function(r,e){return n.events[r]=e,n},n},r2.filter_asm=function(n,r){function e(n){return"p"==n[0]&&"d"==n[1]?!0:-1!=n.indexOf(";pd")}var t=backward?prev_curoff:next_curoff,o=backward?prev_lastoff:next_lastoff,a=n.split(/\n/g);r2.cmd("s",function(n){t=n});for(var c=a.length-1;c>0;c--){var i=a[c].match(/0x([a-fA-F0-9]+)/);if(i&&i.length>0){o=i[0].replace(/:/g,"");break}}if("afl"==r){for(var s="",c=0;c"+u+"\n")}n=s}}else if("i"==r[0]&&r[1]){for(var s="",c=0;cfunction:"),n=n.replace(/;(\s+)/g,";"),n=n.replace(/;(.*)/g,"// $1"),n=n.replace(/(bl|goto|call)/g,"call"),n=n.replace(/(jmp|bne|beq|js|jnz|jae|jge|jbe|jg|je|jl|jz|jb|ja|jne)/g,"$1"),n=n.replace(/(dword|qword|word|byte|movzx|movsxd|cmovz|mov\ |lea\ )/g,"$1"),n=n.replace(/(hlt|leave|iretd|retn|ret)/g,"$1"),n=n.replace(/(add|sbb|sub|mul|div|shl|shr|and|not|xor|inc|dec|sar|sal)/g,"$1"),n=n.replace(/(push|pop)/g,"$1"),n=n.replace(/(test|cmp)/g,"$1"),n=n.replace(/(outsd|out|string|invalid|int |int3|trap|main|in)/g,"$1"),n=n.replace(/nop/g,"nop"),n=n.replace(/(sym|fcn|str|imp|loc)\.([^:<(\\\/ \|)\->]+)/g,"$1.$2")),n=n.replace(/0x([a-zA-Z0-9]+)/g,"0x$1"),backward?(prev_curoff=t,prev_lastoff=o):(next_curoff=t,next_lastoff=o,prev_curoff||(prev_curoff=next_curoff)),n}; var r2ui={};r2ui.selected_panel="Disassembler",r2ui.history=[],r2ui.history_idx=0,r2ui.colors={},r2ui.load_colors=function(){r2.cmdj("ecj",function(r){for(var i in r)r2ui.colors[".ec_"+i.replace("gui.","gui_")]="rgb("+String(r[i])+")"});for(var r in document.styleSheets){var i=document.styleSheets[r],o=i.cssRules?i.cssRules:i.rules;for(var e in o)if(void 0!==o[e].selectorText&&null!==o[e].selectorText&&0===o[e].selectorText.toLowerCase().indexOf(".ec_")){var u=o[e].selectorText,s=r2ui.colors[u];void 0!==s&&null!==s?".ec_gui_background"==u||".ec_gui_alt_background"==u?o[e].style.backgroundColor=s:".ec_border"==u?o[e].style.borderColor=s:o[e].style.color=s:".ec_gui_background"==u||".ec_gui_alt_background"==u?r2ui.colors[u]=o[e].style.backgroundColor:".ec_gui_border"==u?r2ui.colors[u]=o[e].style.borderColor:r2ui.colors[u]=o[e].style.color}}},r2ui.basic_blocks={},r2ui.use_sdb=!1,r2ui.get_fcn_BB=function(r,i){if(r2ui.use_sdb){var o="webui/graph/"+r+"/"+i,e=void 0;return r2.cmd("k "+o,function(r){var i=decodeURIComponent(r).split("\n");for(var o in i){var u=i[o];if(""!==u){e={};var s=u.split(",");e.x=s[0],e.y=s[1],""!=s[2]&&void 0!==s[2]||(s[2]="transparent"),e.color=s[2].replace(/\*\*/g,",")}}}),e}return r2ui.basic_blocks[i]},r2ui.get_fcn_BBs=function(r){if(r2ui.use_sdb){var i="webui/graph/"+r+"/*",o={};return r2.cmd("k "+i,function(r){var i=decodeURIComponent(r).split("\n");for(var e in i){var u=i[e];if(""!==u){offset=u.split("=")[0],u=u.split("=")[1];var s={},n=u.split(",");s.x=n[0],s.y=n[1],""!=n[2]&&void 0!==n[2]||(n[2]="transparent"),s.color=n[2].replace(/\*\*/g,","),o[offset]=s}}}),o}return r2ui.basic_blocks},r2ui.update_fcn_BB=function(r,i,o){if(r2ui.use_sdb){var e="webui/graph/"+r+"/"+i;void 0===o.color&&(o.color="transparent");var u=o.x+","+o.y+","+o.color.replace(/,/g,"**");r2.cmd("k "+e+"="+encodeURIComponent(u),function(){})}else r2ui.basic_blocks[i]=o},r2ui.current_fcn_offset=null,r2ui.graph=null,r2ui.console_lang="r2",r2ui.toggle_console_lang=function(){"r2"==r2ui.console_lang?r2ui.console_lang="js":"js"==r2ui.console_lang&&(r2ui.console_lang="r2"),$("#cmd_input > label").html(r2ui.console_lang)},r2ui.history_push=function(r){r!=r2ui.history_last()&&(r2ui.history_idx!=r2ui.history.length&&(r2ui.history=r2ui.history.splice(0,r2ui.history_idx)),r2ui.history_idx++,r2ui.history.push(r))},r2ui.history_pop=function(){return r2ui.history_idx==r2ui.history.length&&r2ui.history_idx--,r2ui.history.pop()},r2ui.history_last=function(){return r2ui.history.length>0?r2ui.history[r2ui.history_idx-1]:void 0},r2ui.history_prev=function(){return r2ui.history_idx>1&&r2ui.history_idx--,r2ui.history[r2ui.history_idx-1]},r2ui.history_next=function(){var r=r2ui.history[r2ui.history_idx];return r2ui.history_idx