diff options
| author | KyleMiles <krm504@nyu.edu> | 2023-01-05 17:29:14 -0500 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2023-01-06 16:29:58 -0500 |
| commit | a154e45cce79b0c2264c1e1cd37a3d1bf5bc6154 (patch) | |
| tree | 11f436b720edfdf37819e9e83e7131d220687074 /rust/examples | |
| parent | 52edc39a7081fd6662e14fbcd473adabbbc36c7a (diff) | |
Rust API: Lots and lots of clippy changes
Diffstat (limited to 'rust/examples')
| -rw-r--r-- | rust/examples/basic_script/src/main.rs | 13 | ||||
| -rw-r--r-- | rust/examples/dwarfdump/src/lib.rs | 38 | ||||
| -rw-r--r-- | rust/examples/template/src/main.rs | 13 |
3 files changed, 28 insertions, 36 deletions
diff --git a/rust/examples/basic_script/src/main.rs b/rust/examples/basic_script/src/main.rs index ae4554e8..e535f15f 100644 --- a/rust/examples/basic_script/src/main.rs +++ b/rust/examples/basic_script/src/main.rs @@ -18,19 +18,16 @@ fn main() { // TODO : This is intended to be refactored to be more nice to work with soon(TM) for addr in basic_block.as_ref() { print!(" {} ", addr); - match func.arch().instruction_text( + if let Some((_, tokens)) = func.arch().instruction_text( bv.read_buffer(addr, func.arch().max_instr_len()) .unwrap() .get_data(), addr, ) { - Some((_, tokens)) => { - tokens - .iter() - .for_each(|token| print!("{}", token.text().as_str())); - println!("") - } - _ => (), + tokens + .iter() + .for_each(|token| print!("{}", token.text().as_str())); + println!(); } } } diff --git a/rust/examples/dwarfdump/src/lib.rs b/rust/examples/dwarfdump/src/lib.rs index 7860c5bf..9b3cb376 100644 --- a/rust/examples/dwarfdump/src/lib.rs +++ b/rust/examples/dwarfdump/src/lib.rs @@ -38,7 +38,7 @@ use gimli::{ use std::{fmt, ops::Deref, sync::Arc}; -static PADDING: [&'static str; 23] = [ +static PADDING: [&str; 23] = [ "", " ", " ", @@ -170,13 +170,13 @@ fn get_info_string<R: Reader>( InstructionTextTokenContents::Text, )); - if let Ok(Some(addr)) = dwarf.attr_address(&unit, attr.value()) { + if let Ok(Some(addr)) = dwarf.attr_address(unit, attr.value()) { let addr_string = format!("0x{:08x}", addr); attr_line.push(InstructionTextToken::new( BnString::new(addr_string), InstructionTextTokenContents::Integer(addr), )); - } else if let Ok(attr_reader) = dwarf.attr_string(&unit, attr.value()) { + } else if let Ok(attr_reader) = dwarf.attr_string(unit, attr.value()) { if let Ok(attr_string) = attr_reader.to_string() { attr_line.push(InstructionTextToken::new( BnString::new(attr_string.as_ref()), @@ -236,7 +236,7 @@ fn get_info_string<R: Reader>( let value_string = format!("{}", value); attr_line.push(InstructionTextToken::new( BnString::new(value_string), - InstructionTextTokenContents::Integer(value.into()), + InstructionTextTokenContents::Integer(value), )); } else if let Some(value) = attr.sdata_value() { let value_string = format!("{}", value); @@ -271,7 +271,7 @@ fn process_tree<R: Reader>( // || (die_node.entry().tag() == constants::DW_TAG_compile_unit) // || (die_node.entry().tag() == constants::DW_TAG_subprogram) // { - let new_node = FlowGraphNode::new(&graph); + let new_node = FlowGraphNode::new(graph); let attr_string = get_info_string(view, dwarf, unit, die_node.entry()); new_node.set_disassembly_lines(&attr_string); @@ -291,12 +291,11 @@ fn process_tree<R: Reader>( } fn dump_dwarf(bv: &BinaryView) { - let view; - if bv.section_by_name(".debug_info").is_ok() { - view = bv.to_owned(); + let view = if bv.section_by_name(".debug_info").is_ok() { + bv.to_owned() } else { - view = bv.parent_view().unwrap(); - } + bv.parent_view().unwrap() + }; // TODO : Accommodate Endianity let get_section_data_little = @@ -305,24 +304,23 @@ fn dump_dwarf(bv: &BinaryView) { let offset = section.start(); let len = section.len(); if len == 0 { - return Ok(CustomReader::new( + Ok(CustomReader::new( DataBufferWrapper::new(DataBuffer::default()), LittleEndian, - )); - } - - if let Ok(read_buffer) = view.read_buffer(offset, len as usize) { - return Ok(CustomReader::new( + )) + } else if let Ok(read_buffer) = view.read_buffer(offset, len) { + Ok(CustomReader::new( DataBufferWrapper::new(read_buffer), LittleEndian, - )); + )) + } else { + Err(Error::Io) } - return Err(Error::Io); } else { - return Ok(CustomReader::new( + Ok(CustomReader::new( DataBufferWrapper::new(DataBuffer::default()), LittleEndian, - )); + )) } }; diff --git a/rust/examples/template/src/main.rs b/rust/examples/template/src/main.rs index 1fbe3c83..0c27b6d2 100644 --- a/rust/examples/template/src/main.rs +++ b/rust/examples/template/src/main.rs @@ -23,19 +23,16 @@ fn main() { // TODO : This is intended to be refactored to be more nice to work with soon(TM) for addr in basic_block.as_ref() { print!(" {} ", addr); - match func.arch().instruction_text( + if let Some((_, tokens)) = func.arch().instruction_text( bv.read_buffer(addr, func.arch().max_instr_len()) .unwrap() .get_data(), addr, ) { - Some((_, tokens)) => { - tokens - .iter() - .for_each(|token| print!("{}", token.text().as_str())); - println!("") - } - _ => (), + tokens + .iter() + .for_each(|token| print!("{}", token.text().as_str())); + println!(); } } } |
