mirror of
https://github.com/radareorg/radeco.git
synced 2026-11-07 06:36:01 -10:00
fixup: radeco: lint fixes
This commit is contained in:
1 parent
a4ba7b95b4
commit
d29bc16d05
4 files changed
+54
-63
No files matched your search
+1
-1
@@ -35,7 +35,7 @@ fn main() {
|
||||
if cargo_lock_path.exists() {
|
||||
let lock_buf = read_to_string(cargo_lock_path).ok().unwrap();
|
||||
let deps = parse_dependencies(&lock_buf);
|
||||
for &(ref crate_name, ref crate_version) in deps.iter() {
|
||||
for (crate_name, crate_version) in deps.iter() {
|
||||
if crate_name == "radeco-lib" {
|
||||
version_str = format!("{}, radeco-lib - v{}", version_str, crate_version);
|
||||
}
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ pub fn parse_args() -> (Option<String>, Option<String>, bool, bool, bool, u32) {
|
||||
let max_it = match matches.value_of("max-iterations") {
|
||||
Some(s) => {
|
||||
// TODO -> Implement error management.
|
||||
match u32::from_str_radix(s.trim(), 10) {
|
||||
match s.trim().parse::<u32>() {
|
||||
Ok(max_it) => max_it,
|
||||
Err(_) => {
|
||||
eprintln!("max-iterations must be a deciamal number");
|
||||
|
||||
+15
-18
@@ -1,4 +1,3 @@
|
||||
use base64;
|
||||
use r2pipe::{R2Pipe, R2};
|
||||
use radeco_lib::analysis::engine::{Engine, RadecoEngine};
|
||||
use radeco_lib::backend::lang_c::c_cfg::ctrl_flow_struct;
|
||||
@@ -15,7 +14,7 @@ use std::rc::Rc;
|
||||
use std::str;
|
||||
|
||||
thread_local!(
|
||||
pub static PROJ: RefCell<Option<RadecoProject>> = RefCell::new(None);
|
||||
pub static PROJ: RefCell<Option<RadecoProject>> = const { RefCell::new(None) };
|
||||
);
|
||||
|
||||
pub fn fn_list(proj: &RadecoProject) -> Vec<String> {
|
||||
@@ -30,8 +29,7 @@ pub fn get_function<'a>(name: &str, proj: &'a RadecoProject) -> Option<&'a Radec
|
||||
proj.iter()
|
||||
.map(|i| i.module)
|
||||
.flat_map(|rmod| rmod.functions.values())
|
||||
.filter(|rfn| rfn.name == name)
|
||||
.next()
|
||||
.find(|rfn| rfn.name == name)
|
||||
}
|
||||
|
||||
pub fn get_function_mut<'a>(
|
||||
@@ -41,12 +39,11 @@ pub fn get_function_mut<'a>(
|
||||
proj.iter_mut()
|
||||
.map(|i| i.module)
|
||||
.flat_map(|rmod| rmod.functions.values_mut())
|
||||
.filter(|rfn| rfn.name == name)
|
||||
.next()
|
||||
.find(|rfn| rfn.name == name)
|
||||
}
|
||||
|
||||
pub fn fn_rename(old_f: &str, new_f: &str, proj: &mut RadecoProject) {
|
||||
if let Some(_) = get_function(new_f, proj) {
|
||||
if get_function(new_f, proj).is_some() {
|
||||
println!("there is already a function called: {}", new_f);
|
||||
return;
|
||||
}
|
||||
@@ -76,7 +73,7 @@ pub fn analyze(rfn: &mut RadecoFunction, max_it: u32) {
|
||||
engine.run_func(rfn);
|
||||
}
|
||||
|
||||
pub fn analyze_all_functions<'a>(proj: &'a mut RadecoProject, max_it: u32) {
|
||||
pub fn analyze_all_functions(proj: &mut RadecoProject, max_it: u32) {
|
||||
let rfns = proj
|
||||
.iter_mut()
|
||||
.map(|i| i.module)
|
||||
@@ -97,11 +94,11 @@ pub fn emit_dot(ssa: &SSAStorage) -> String {
|
||||
dot::emit_dot(ssa)
|
||||
}
|
||||
|
||||
pub fn decompile_all_functions<'a>(proj: &'a RadecoProject) -> String {
|
||||
pub fn decompile_all_functions(proj: &RadecoProject) -> String {
|
||||
let mut decompiled_funcs = Vec::new();
|
||||
let funcs = fn_list(&proj);
|
||||
let funcs = fn_list(proj);
|
||||
for f in &funcs {
|
||||
match decompile(f, &proj) {
|
||||
match decompile(f, proj) {
|
||||
Ok(res) => {
|
||||
decompiled_funcs.push(res);
|
||||
}
|
||||
@@ -113,11 +110,11 @@ pub fn decompile_all_functions<'a>(proj: &'a RadecoProject) -> String {
|
||||
decompiled_funcs.join("\n")
|
||||
}
|
||||
|
||||
pub fn decompile<'a>(name: &str, proj: &'a RadecoProject) -> Result<String, String> {
|
||||
if let Some(rfn) = get_function(name, &proj) {
|
||||
pub fn decompile(name: &str, proj: &RadecoProject) -> Result<String, String> {
|
||||
if let Some(rfn) = get_function(name, proj) {
|
||||
let rmod = proj.iter().map(|i| i.module).next().unwrap();
|
||||
let func_name_map = func_names(&rmod);
|
||||
let strings = strings(&rmod);
|
||||
let func_name_map = func_names(rmod);
|
||||
let strings = strings(rmod);
|
||||
decompile_priv(rfn, &func_name_map, &strings)
|
||||
} else {
|
||||
Err(format!("{} is not found.", name))
|
||||
@@ -161,7 +158,7 @@ pub fn load_proj_by_path(path: &str, max_it: u32) -> RadecoProject {
|
||||
let regfile = p.regfile().clone();
|
||||
for xy in p.iter_mut() {
|
||||
let engine = RadecoEngine::new(max_it);
|
||||
engine.run_module(xy.module, &*regfile.clone());
|
||||
engine.run_module(xy.module, ®file.clone());
|
||||
}
|
||||
p
|
||||
}
|
||||
@@ -183,7 +180,7 @@ pub fn load_project_by_r2pipe(r2p: R2Pipe, max_it: u32) -> RadecoProject {
|
||||
let regfile = p.regfile().clone();
|
||||
for xy in p.iter_mut() {
|
||||
let engine = RadecoEngine::new(max_it);
|
||||
engine.run_module(xy.module, &*regfile.clone());
|
||||
engine.run_module(xy.module, ®file.clone());
|
||||
}
|
||||
p
|
||||
}
|
||||
@@ -198,7 +195,7 @@ pub fn func_names(rmod: &RadecoModule) -> HashMap<u64, String> {
|
||||
pub fn strings(rmod: &RadecoModule) -> HashMap<u64, String> {
|
||||
rmod.strings()
|
||||
.iter()
|
||||
.filter(|ref s| s.paddr.is_some() && s.string.is_some())
|
||||
.filter(|s| s.paddr.is_some() && s.string.is_some())
|
||||
.cloned()
|
||||
.map(|s| {
|
||||
let (addr, _s) = (s.vaddr.unwrap(), s.string.unwrap());
|
||||
|
||||
+37
-43
@@ -26,8 +26,8 @@ use std::fs;
|
||||
use std::process;
|
||||
|
||||
mod scheme {
|
||||
pub const HTTP: &'static str = "http://";
|
||||
pub const TCP: &'static str = "tcp://";
|
||||
pub const HTTP: &str = "http://";
|
||||
pub const TCP: &str = "tcp://";
|
||||
|
||||
pub fn is_http(url: &str) -> bool {
|
||||
url.starts_with(HTTP)
|
||||
@@ -40,7 +40,7 @@ mod scheme {
|
||||
|
||||
// On unix platforms you can use ANSI escape sequences
|
||||
#[cfg(unix)]
|
||||
const PROMPT: &'static str = "\x1b[1;32m>>\x1b[0m ";
|
||||
const PROMPT: &str = "\x1b[1;32m>>\x1b[0m ";
|
||||
// File seperator for *nix based platforms
|
||||
#[cfg(unix)]
|
||||
const FILE_SP: char = '/';
|
||||
@@ -115,9 +115,9 @@ impl Completer for Completes {
|
||||
let mut line_tokens = line.split(' ');
|
||||
line_tokens.next(); // drop the command.
|
||||
|
||||
let to_compl = line_tokens.last().unwrap_or("");
|
||||
let to_compl = line_tokens.next_back().unwrap_or("");
|
||||
|
||||
let mut funcs: Vec<String> = core::fn_list(&proj)
|
||||
let mut funcs: Vec<String> = core::fn_list(proj)
|
||||
.iter()
|
||||
.filter(|f| f.len() > to_compl.len())
|
||||
.filter(|f| &f[0..to_compl.len()] == to_compl)
|
||||
@@ -125,7 +125,7 @@ impl Completer for Completes {
|
||||
format!(
|
||||
"{}{}{}",
|
||||
line,
|
||||
if to_compl.len() == 0 { " " } else { "" },
|
||||
if to_compl.is_empty() { " " } else { "" },
|
||||
&f[to_compl.len()..f.len()]
|
||||
)
|
||||
})
|
||||
@@ -135,21 +135,18 @@ impl Completer for Completes {
|
||||
});
|
||||
}
|
||||
if line.starts_with("load") {
|
||||
match self.file_completer.complete(line, _pos, ctx) {
|
||||
Ok((n, ss)) => {
|
||||
let mut completed_lines = ss
|
||||
.into_iter()
|
||||
.map(|s| {
|
||||
if let Some(sep_loc) = line.rfind(FILE_SP) {
|
||||
format!("{}{}", &line[..sep_loc + 1], s.display)
|
||||
} else {
|
||||
format!("{}{}", &line[..n], s.display)
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
ret.append(&mut completed_lines);
|
||||
}
|
||||
Err(_) => {}
|
||||
if let Ok((n, ss)) = self.file_completer.complete(line, _pos, ctx) {
|
||||
let mut completed_lines = ss
|
||||
.into_iter()
|
||||
.map(|s| {
|
||||
if let Some(sep_loc) = line.rfind(FILE_SP) {
|
||||
format!("{}{}", &line[..sep_loc + 1], s.display)
|
||||
} else {
|
||||
format!("{}{}", &line[..n], s.display)
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
ret.append(&mut completed_lines);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +154,7 @@ impl Completer for Completes {
|
||||
}
|
||||
}
|
||||
|
||||
const SEP: &'static str = "END";
|
||||
const SEP: &str = "END";
|
||||
|
||||
fn main() {
|
||||
#[cfg(feature = "trace_log")]
|
||||
@@ -243,16 +240,16 @@ fn main() {
|
||||
}
|
||||
|
||||
mod command {
|
||||
pub const HELP: &'static str = "help";
|
||||
pub const LOAD: &'static str = "load";
|
||||
pub const CONNECT: &'static str = "connect";
|
||||
pub const FNLIST: &'static str = "fn_list";
|
||||
pub const ANALYZE: &'static str = "analyze";
|
||||
pub const DOT: &'static str = "dot";
|
||||
pub const IR: &'static str = "ir";
|
||||
pub const DECOMPILE: &'static str = "decompile";
|
||||
pub const FUNC_RENAME: &'static str = "fn_rn";
|
||||
pub const QUIT: &'static str = "quit";
|
||||
pub const HELP: &str = "help";
|
||||
pub const LOAD: &str = "load";
|
||||
pub const CONNECT: &str = "connect";
|
||||
pub const FNLIST: &str = "fn_list";
|
||||
pub const ANALYZE: &str = "analyze";
|
||||
pub const DOT: &str = "dot";
|
||||
pub const IR: &str = "ir";
|
||||
pub const DECOMPILE: &str = "decompile";
|
||||
pub const FUNC_RENAME: &str = "fn_rn";
|
||||
pub const QUIT: &str = "quit";
|
||||
|
||||
pub fn help() {
|
||||
let width = 30;
|
||||
@@ -298,10 +295,7 @@ mod command {
|
||||
|
||||
/// Returns true if `cmd` requires a function as parameter.
|
||||
pub fn requires_func(cmd: &str) -> bool {
|
||||
match cmd {
|
||||
ANALYZE | DOT | IR | DECOMPILE | FUNC_RENAME => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(cmd, ANALYZE | DOT | IR | DECOMPILE | FUNC_RENAME)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,9 +325,9 @@ fn cmd(line: String, highlight: bool, max_it: u32) {
|
||||
}
|
||||
}
|
||||
(Some(command::CONNECT), Some(url), _) => {
|
||||
let p_opt = if scheme::is_http(&url) {
|
||||
let p_opt = if scheme::is_http(url) {
|
||||
core::load_proj_http(&url[scheme::HTTP.len()..], max_it)
|
||||
} else if scheme::is_tcp(&url) {
|
||||
} else if scheme::is_tcp(url) {
|
||||
core::load_proj_tcp(&url[scheme::TCP.len()..], max_it)
|
||||
} else {
|
||||
Err("Invalid url")
|
||||
@@ -360,7 +354,7 @@ fn cmd(line: String, highlight: bool, max_it: u32) {
|
||||
core::analyze_all_functions(proj, max_it);
|
||||
}
|
||||
(Some(command::FNLIST), _, _) => {
|
||||
let funcs = core::fn_list(&proj);
|
||||
let funcs = core::fn_list(proj);
|
||||
println!("{}", funcs.join("\n"));
|
||||
}
|
||||
// TODO Show list of dependency information of analyses
|
||||
@@ -373,28 +367,28 @@ fn cmd(line: String, highlight: bool, max_it: u32) {
|
||||
}
|
||||
}
|
||||
(Some(command::DOT), Some(f), _) => {
|
||||
if let Some(rfn) = core::get_function(f, &proj) {
|
||||
if let Some(rfn) = core::get_function(f, proj) {
|
||||
println!("{}", core::emit_dot(rfn.ssa()));
|
||||
} else {
|
||||
println!("{} is not found", f);
|
||||
}
|
||||
}
|
||||
(Some(command::IR), Some(f), _) => {
|
||||
if let Some(rfn) = core::get_function(f, &proj) {
|
||||
if let Some(rfn) = core::get_function(f, proj) {
|
||||
println!("{}", core::emit_ir(rfn));
|
||||
} else {
|
||||
println!("{} is not found", f);
|
||||
}
|
||||
}
|
||||
(Some(command::DECOMPILE), Some("*"), _) => {
|
||||
let decompiled = core::decompile_all_functions(&proj);
|
||||
let decompiled = core::decompile_all_functions(proj);
|
||||
if highlight {
|
||||
highlighting::print_highlighted(&decompiled);
|
||||
} else {
|
||||
println!("{}", decompiled);
|
||||
}
|
||||
}
|
||||
(Some(command::DECOMPILE), Some(f), _) => match core::decompile(f, &proj) {
|
||||
(Some(command::DECOMPILE), Some(f), _) => match core::decompile(f, proj) {
|
||||
Ok(res) => {
|
||||
if highlight {
|
||||
highlighting::print_highlighted(&res);
|
||||
|
||||
Reference in new issue
Block a user