public static int Main(String[] args) { var doAsync = true; /* * var web = new R2PipeHttp("http://cloud.rada.re/cmd/"); * //r2p.Cmd * web.Cmd("?V", (version) => { * Console.WriteLine ("Version: {0}", version); * }); */ R2Pipe r2p = new R2Pipe("/bin/ls", doAsync); if (doAsync) { //r2p.Cmd ("e scr.color=false;?e pop"); r2p.Cmd("e scr.color=false"); r2p.Cmd("x", (res) => { Console.WriteLine("RESULT 'x' {\n" + res + "\n}"); }); r2p.Cmd("pi 10", (res) => { Console.WriteLine("RESULT 'pi 10' {\n" + res + "\n}"); }); r2p.Quit(); } else { // Cant mix sync and async Console.WriteLine("Hello r2! " + r2p.CmdSync("?V")); Console.WriteLine("Hexdump!\n" + r2p.CmdSync("px")); //r2p.QuitSync (); } return(0); }
static void Main(string[] args) { #if __MonoCS__ using (IR2Pipe pipe = new R2Pipe("/bin/ls")) #else using (IR2Pipe pipe = new R2Pipe(@"C:\Windows\notepad.exe", @"C:\radare2\radare2.exe")) #endif { Console.WriteLine("Hello r2! " + pipe.RunCommand("?V")); Task <string> async = pipe.RunCommandAsync("?V"); // To use non-blocking async stuff in console applications, you need an async context. Google helps you. // calling Result will block ulitmately. Console.WriteLine("Hello async r2!" + async.Result); // We can also issue multiple command sequentially, using a QueuedR2Pipe. // Note however that if we supply the pipe to use we must not call dispose on the pipe. QueuedR2Pipe qr2 = new QueuedR2Pipe(pipe); qr2.Enqueue(new R2Command("x", (string result) => { Console.WriteLine("Result of x:\n {0}", result); })); qr2.Enqueue(new R2Command("pi 10", (string result) => { Console.WriteLine("Result of pi 10:\n {0}", result); })); // note that this can also be done asynchronously via qr2.ExecuteCommandsAsync(); qr2.ExecuteCommands(); } }
public static void Quit(this R2Pipe pipe) { if (pipe.doAsync) { pipe.RunCommandAsync("q!").GetAwaiter().OnCompleted(() => { pipe.Dispose(); return; }); } pipe.Dispose(); }
public static async Task <string> Cmd(this R2Pipe pipe, string c, Action <string> cb) { if (pipe.doAsync) { string s = await pipe.RunCommandAsync(c); cb(s); return(null); } string str = pipe.CmdSync(c); cb(str); return(str); }
public static int Main(String[] args) { Console.WriteLine("Hello r2!"); R2Pipe r2p = new R2Pipe(); //r2p.Cmd ("e scr.color=false;?e pop"); r2p.Cmd("e scr.color=false"); r2p.Cmd("x", (res) => { Console.WriteLine("RESULT 'x' {\n" + res + "\n}"); }); r2p.Cmd("pi 10", (res) => { Console.WriteLine("RESULT 'pi 10' {\n" + res + "\n}"); }); r2p.Quit(); return(0); }
public string ExtractText(string filePath, string extension) { string r2Path = null; if (FilesUtils.ExistsOnPath("radare2.exe")) { r2Path = FilesUtils.GetFullPath("radare2.exe"); } else if (FilesUtils.ExistsOnPath("radare2")) { r2Path = FilesUtils.GetFullPath("radare2"); } else { PrintR2NotFound(); return(null); // No radare } PrintR2Warning(); Console.Error.WriteLine($"Using radare from {r2Path}"); var sb = new StringBuilder(); using (IR2Pipe pipe = new R2Pipe(filePath, r2Path)) { var queue = new QueuedR2Pipe(pipe); queue.Enqueue(new R2Command("?V", (string result) => Console.Error.WriteLine($"Using radare version: {result}"))); queue.Enqueue(new R2Command("e bin.rawstr=1", (no_use) => { /* Do nothing */ })); queue.Enqueue(new R2Command("izj", (string jsonResult) => { List <R2ZString> strings = JsonConvert.DeserializeObject <List <R2ZString> >(jsonResult); foreach (var s in strings) { sb.AppendLine(Base64Decode(s.String)); } })); queue.ExecuteCommands(); } return(sb.ToString()); }
public static string CmdSync(this R2Pipe pipe, string cmd) { return(pipe.RunCommand(cmd)); }
public static void QuitSync(this R2Pipe pipe) { pipe.Dispose(); }