public string Cmd(string cmd) { if (r2 != null) { return(r2.RunCommand(cmd)); } return(""); }
public string run(String cmds, String controlName, Boolean append = false, List <string> cols = null) { string res = ""; dynamic json_obj = null; if (!controls.ContainsKey(controlName)) { MessageBox.Show(string.Format("Wops!\n{0}\ncontrol not found...", controlName), "run", MessageBoxButtons.OK, MessageBoxIcon.Information); return(null); } if (controls.ContainsKey("output")) { setText("output", string.Format("r2.RunCommand(\"{1}\"): target='{0}' type='{2}' cols='{3}'\n", controlName, cmds, controls[controlName].GetType(), cols != null ? string.Join(", ", cols) : ""), true); } res = r2.RunCommand(cmds).Replace("\r", ""); try { json_obj = JsonConvert.DeserializeObject(res); } catch (Exception e) { Console.WriteLine(e.ToString()); } setText(controlName, res, append, json_obj, cols); return(res); }
/// <summary> /// Executes the commands. /// </summary> public void ExecuteCommands() { while (this.Count > 0) { R2Command cmd = this.Dequeue(); string result = pipe.RunCommand(cmd.Command); cmd.Callback(result); } }
/*public string run(String cmds, String controlName=null, Boolean append = false, List<string> cols = null) * { * if (r2 == null) return null; // may happend if gui closed when sending commands (r2.exit) * var task = Task.Run(() => run_task(cmds,controlName, append, cols)); * if (task.Wait(TimeSpan.FromSeconds(int.Parse(rconfig.load<int>("r2.cmd_timeout",6))))) * return task.Result; * else * Show(string.Format("run: {0} Timed out",cmds),"run"); * return null; * }*/ public string run(String cmds, String controlName = null, Boolean append = false, List <string> cols = null) { string res = ""; dynamic json_obj = null; if (controls.ContainsKey("output")) { string control_type = "unknown"; if (controlName != null && controls.ContainsKey(controlName)) { control_type = controls[controlName].GetType().ToString(); } setText("output", string.Format("r2.RunCommand(\"{1}\"): target='{0}' type='{2}' cols='{3}'\n", controlName, cmds, control_type, cols != null ? string.Join(", ", cols) : ""), true); } if (r2 == null) { Show(string.Format("{0}\nR2PIPE_WRAPPER: run(): {1}: IR2Pipe is null", cmds, controlName), "Wops!"); return(null); } if (controlName != null && !controls.ContainsKey(controlName)) { add_control_tab(controlName, cmds); } if (controlName != null && !controls.ContainsKey(controlName)) { Show(string.Format("{0}\ncontrols: control '{1}' not found...", cmds, controlName), "Wops!"); return(null); } res = r2.RunCommand(cmds).Replace("\r", ""); if (res.StartsWith("[") || res.StartsWith("{")) { try { json_obj = JsonConvert.DeserializeObject(res); } catch (Exception) {} } if (controlName != null) { setText(controlName, res, append, json_obj, cols); } return(res); }
/* // some problems found at dynamic tab append * public string run(String cmds, String controlName=null, Boolean append = false, List<string> cols = null) * { * if (r2 == null) return null; // may happend if gui closed when sending commands (r2.exit) * var task = Task.Run(() => run_task(cmds,controlName, append, cols)); * if (task.Wait(TimeSpan.FromSeconds(int.Parse(rconfig.load<int>("r2.cmd_timeout",6))))) * return task.Result; * else * Show(string.Format("run: {0} Timed out",cmds),"run"); * return null; * }*/ public string run(String cmds, String controlName = null, Boolean append = false, List <string> cols = null) { string res = ""; dynamic json_obj = null; if (controls.ContainsKey("output")) { string control_type = "unknown"; if (controlName != null && controls.ContainsKey(controlName)) { control_type = controls[controlName].GetType().ToString(); } setText("output", "", string.Format("{2} r2.RunCommand(\"{1}\"): target='{0}' type='{3}' cols='{4}'\n", controlName, cmds, current_shell, control_type, cols != null ? string.Join(", ", cols) : ""), true); } if (r2 == null) { Show(string.Format("{0}\nR2PIPE_WRAPPER: run(): {1}: IR2Pipe is null", cmds, controlName), "Wops!"); return(null); } if (controlName != null && !controls.ContainsKey(controlName)) { add_control_tab(controlName, cmds); } if (controlName != null && !controls.ContainsKey(controlName)) { Show(string.Format("{0}\ncontrols: control '{1}' not found...", cmds, controlName), "Wops!"); return(null); } Cursor.Current = Cursors.WaitCursor; this.guicontrol.show_message(cmds); switch (current_shell) { case "radare2": res = r2.RunCommand(cmds).Replace("\r", ""); break; case "javascript": res = invokeJavascript(cmds); break; default: Show(string.Format("R2PIPE_WRAPPER: run(): current_shell='{0}'", current_shell), "unknown shell"); break; } Cursor.Current = Cursors.Default; if (res == null) { return(res); } if (res.StartsWith("[") || res.StartsWith("{")) { try { json_obj = JsonConvert.DeserializeObject(res); } catch (Exception) {} } if (controlName != null) { setText(controlName, cmds, res, append, json_obj, cols); if (cached_results.ContainsKey(controlName)) { cached_results.Remove(controlName); } cached_results.Add(controlName, res); } return(res); }