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

add CLI component #305

Merged
merged 5 commits into from
Jun 25, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
cli: sort functions by entry. remove derpin'
  • Loading branch information
m4b committed Jun 24, 2017
commit 2380117024711a3e182792bbd0cf66a8049dcdba
31 changes: 25 additions & 6 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern crate env_logger;
use std::result;
use std::path::Path;
use std::sync::Arc;
use panopticon_core::{Machine, loader};
use panopticon_core::{Machine, Function, ControlFlowTarget, loader};
use panopticon_amd64 as amd64;
use panopticon_avr as avr;
use panopticon_analysis::pipeline;
Expand Down Expand Up @@ -51,6 +51,16 @@ fn exists_path_val(filepath: &str) -> result::Result<(), String> {
}
}

fn get_entry_point(func: &Function) -> Option<u64> {
if let Some(ref entry) = func.entry_point {
if let Some(&ControlFlowTarget::Resolved(ref bb)) = func.cflow_graph.vertex_label(*entry) {
return Some(bb.area.start);
}
}

None
}

fn disassemble(args: Args) -> Result<()> {
let binary = args.binary;
let filter = args.function_filter;
Expand All @@ -73,7 +83,6 @@ fn disassemble(args: Args) -> Result<()> {
match filter {
Some(filter) => {
for function in pipe.wait() {
info!("derp");
if let Ok(function) = function {
if filter == function.name {
println!("{}", function.display_with(&prog.clone()));
Expand All @@ -83,17 +92,27 @@ fn disassemble(args: Args) -> Result<()> {
}
},
None => {
let functions = pipe.wait().filter_map(|function| {
let mut functions = pipe.wait().filter_map(|function| {
if let Ok(function) = function {
info!("{}",function.uuid);
Some(function)
} else {
None
}
}).collect::<Vec<_>>();
// todo: sort by address
// functions.sort_by(|f1, f2| {
// });

functions.sort_by(|f1, f2| {
use std::cmp::Ordering::*;
let entry1 = get_entry_point(f1);
let entry2 = get_entry_point(f2);
match (entry1, entry2) {
(Some(entry1), Some(entry2)) => entry1.cmp(&entry2),
(Some(_), None) => Greater,
(None, Some(_)) => Less,
(None, None) => Equal,
}
});

for function in functions {
println!("{}", function.display_with(&prog.clone()));
}
Expand Down