diff options
| author | Rubens Brandao <git@rubens.io> | 2024-04-06 16:32:00 -0300 |
|---|---|---|
| committer | Kyle Martin <krm504@nyu.edu> | 2024-04-09 13:39:49 -0400 |
| commit | 193dea95daedde471e6f1fbcbeaf1932c6fbd50c (patch) | |
| tree | 99be67d81a899543ed5e4636eea3d589583e48a5 /rust/examples | |
| parent | a6b48153b64a227c3492d77a96e679b8c469034c (diff) | |
replace BStr with str
Diffstat (limited to 'rust/examples')
| -rw-r--r-- | rust/examples/basic_script/src/main.rs | 4 | ||||
| -rw-r--r-- | rust/examples/dwarf/dwarf_export/src/lib.rs | 2 | ||||
| -rw-r--r-- | rust/examples/dwarf/dwarf_import/src/die_handlers.rs | 8 | ||||
| -rw-r--r-- | rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs | 2 | ||||
| -rw-r--r-- | rust/examples/dwarf/dwarfdump/src/lib.rs | 41 | ||||
| -rw-r--r-- | rust/examples/flowgraph/src/lib.rs | 7 | ||||
| -rw-r--r-- | rust/examples/template/src/main.rs | 4 |
7 files changed, 29 insertions, 39 deletions
diff --git a/rust/examples/basic_script/src/main.rs b/rust/examples/basic_script/src/main.rs index b979c156..c5c1414a 100644 --- a/rust/examples/basic_script/src/main.rs +++ b/rust/examples/basic_script/src/main.rs @@ -26,9 +26,7 @@ fn main() { .get_data(), addr, ) { - tokens - .iter() - .for_each(|token| print!("{}", token.text().as_str())); + tokens.iter().for_each(|token| print!("{}", token.text())); println!(); } } diff --git a/rust/examples/dwarf/dwarf_export/src/lib.rs b/rust/examples/dwarf/dwarf_export/src/lib.rs index 6af9afe2..7143f6dd 100644 --- a/rust/examples/dwarf/dwarf_export/src/lib.rs +++ b/rust/examples/dwarf/dwarf_export/src/lib.rs @@ -739,7 +739,7 @@ fn export_dwarf(bv: &BinaryView) { } else { BnString::new("Unknown") }; - let responses = present_form(&arch_name); + let responses = present_form(arch_name.as_str()); let encoding = gimli::Encoding { format: gimli::Format::Dwarf32, diff --git a/rust/examples/dwarf/dwarf_import/src/die_handlers.rs b/rust/examples/dwarf/dwarf_import/src/die_handlers.rs index 125038dd..bcc6be66 100644 --- a/rust/examples/dwarf/dwarf_import/src/die_handlers.rs +++ b/rust/examples/dwarf/dwarf_import/src/die_handlers.rs @@ -301,17 +301,13 @@ pub(crate) fn handle_function<R: Reader<Offset = usize>>( name.clone(), Type::named_type_from_type( name, - &Type::function::<String, &binaryninja::types::Type>( - return_type.as_ref(), - &[], - false, - ), + &Type::function::<&binaryninja::types::Type>(return_type.as_ref(), &[], false), ), false, ); } - let mut parameters: Vec<FunctionParameter<String>> = vec![]; + let mut parameters: Vec<FunctionParameter> = vec![]; let mut variable_arguments = false; // Get all the children and populate diff --git a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs index 4b0f9350..b1b91c1d 100644 --- a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs +++ b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs @@ -316,7 +316,7 @@ impl DebugInfoBuilder { _ => Conf::new(binaryninja::types::Type::void(), 0), }; - let parameters: Vec<FunctionParameter<String>> = function + let parameters: Vec<FunctionParameter> = function .parameters .iter() .filter_map(|parameter| match parameter { diff --git a/rust/examples/dwarf/dwarfdump/src/lib.rs b/rust/examples/dwarf/dwarfdump/src/lib.rs index d1a415d7..8c6b32b7 100644 --- a/rust/examples/dwarf/dwarfdump/src/lib.rs +++ b/rust/examples/dwarf/dwarfdump/src/lib.rs @@ -17,7 +17,6 @@ use binaryninja::{ command::{register, Command}, disassembly::{DisassemblyTextLine, InstructionTextToken, InstructionTextTokenContents}, flowgraph::{BranchType, EdgeStyle, FlowGraph, FlowGraphNode, FlowGraphOption}, - string::BnString, }; use dwarfreader::is_valid; @@ -77,14 +76,14 @@ fn get_info_string<R: Reader>( let label_string = format!("#0x{:08x}", label_value); disassembly_lines.push(DisassemblyTextLine::from(vec![ InstructionTextToken::new( - BnString::new(label_string), + &label_string, InstructionTextTokenContents::GotoLabel(label_value), ), - InstructionTextToken::new(BnString::new(":"), InstructionTextTokenContents::Text), + InstructionTextToken::new(":", InstructionTextTokenContents::Text), ])); disassembly_lines.push(DisassemblyTextLine::from(vec![InstructionTextToken::new( - BnString::new(die_node.tag().static_string().unwrap()), + die_node.tag().static_string().unwrap(), InstructionTextTokenContents::TypeName, // TODO : KeywordToken? )])); @@ -92,7 +91,7 @@ fn get_info_string<R: Reader>( while let Some(attr) = attrs.next().unwrap() { let mut attr_line: Vec<InstructionTextToken> = Vec::with_capacity(5); attr_line.push(InstructionTextToken::new( - BnString::new(" "), + " ", InstructionTextTokenContents::Indentation, )); @@ -100,14 +99,14 @@ fn get_info_string<R: Reader>( if let Some(n) = attr.name().static_string() { len = n.len(); attr_line.push(InstructionTextToken::new( - BnString::new(n), + n, InstructionTextTokenContents::FieldName, )); } else { // This is rather unlikely, I think len = 1; attr_line.push(InstructionTextToken::new( - BnString::new("?"), + "?", InstructionTextTokenContents::FieldName, )); } @@ -115,25 +114,25 @@ fn get_info_string<R: Reader>( // On command line the magic number that looks good is 22, but that's too much whitespace in a basic block, so I chose 18 (22 is the max with the current padding provided) if len < 18 { attr_line.push(InstructionTextToken::new( - BnString::new(PADDING[18 - len]), + PADDING[18 - len], InstructionTextTokenContents::Text, )); } attr_line.push(InstructionTextToken::new( - BnString::new(" = "), + " = ", InstructionTextTokenContents::Text, )); 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), + &addr_string, InstructionTextTokenContents::Integer(addr), )); } 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()), + attr_string.as_ref(), InstructionTextTokenContents::String({ let (_, id, offset) = dwarf.lookup_offset_id(attr_reader.offset_id()).unwrap(); @@ -142,13 +141,13 @@ fn get_info_string<R: Reader>( )); } else { attr_line.push(InstructionTextToken::new( - BnString::new("??"), + "??", InstructionTextTokenContents::Text, )); } } else if let Encoding(type_class) = attr.value() { attr_line.push(InstructionTextToken::new( - BnString::new(type_class.static_string().unwrap()), + type_class.static_string().unwrap(), InstructionTextTokenContents::TypeName, )); } else if let UnitRef(offset) = attr.value() { @@ -159,17 +158,17 @@ fn get_info_string<R: Reader>( .into_u64(); let addr_string = format!("#0x{:08x}", addr); attr_line.push(InstructionTextToken::new( - BnString::new(addr_string), + &addr_string, InstructionTextTokenContents::GotoLabel(addr), )); } else if let Flag(true) = attr.value() { attr_line.push(InstructionTextToken::new( - BnString::new("true"), + "true", InstructionTextTokenContents::Integer(1), )); } else if let Flag(false) = attr.value() { attr_line.push(InstructionTextToken::new( - BnString::new("false"), + "false", InstructionTextTokenContents::Integer(1), )); @@ -177,31 +176,31 @@ fn get_info_string<R: Reader>( } else if let Some(value) = attr.u8_value() { let value_string = format!("{}", value); attr_line.push(InstructionTextToken::new( - BnString::new(value_string), + &value_string, InstructionTextTokenContents::Integer(value.into()), )); } else if let Some(value) = attr.u16_value() { let value_string = format!("{}", value); attr_line.push(InstructionTextToken::new( - BnString::new(value_string), + &value_string, InstructionTextTokenContents::Integer(value.into()), )); } else if let Some(value) = attr.udata_value() { let value_string = format!("{}", value); attr_line.push(InstructionTextToken::new( - BnString::new(value_string), + &value_string, InstructionTextTokenContents::Integer(value.into()), )); } else if let Some(value) = attr.sdata_value() { let value_string = format!("{}", value); attr_line.push(InstructionTextToken::new( - BnString::new(value_string), + &value_string, InstructionTextTokenContents::Integer(value as u64), )); } else { let attr_string = format!("{:?}", attr.value()); attr_line.push(InstructionTextToken::new( - BnString::new(attr_string), + &attr_string, InstructionTextTokenContents::Text, )); } diff --git a/rust/examples/flowgraph/src/lib.rs b/rust/examples/flowgraph/src/lib.rs index f80879e5..0375705d 100644 --- a/rust/examples/flowgraph/src/lib.rs +++ b/rust/examples/flowgraph/src/lib.rs @@ -3,16 +3,15 @@ use binaryninja::{ command::register, disassembly::{DisassemblyTextLine, InstructionTextToken, InstructionTextTokenContents}, flowgraph::{BranchType, EdgePenStyle, EdgeStyle, FlowGraph, FlowGraphNode, ThemeColor}, - string::BnString, }; fn test_graph(view: &BinaryView) { let graph = FlowGraph::new(); let disassembly_lines_a = vec![DisassemblyTextLine::from(vec![ - InstructionTextToken::new(BnString::new("Li"), InstructionTextTokenContents::Text), - InstructionTextToken::new(BnString::new("ne"), InstructionTextTokenContents::Text), - InstructionTextToken::new(BnString::new(" 1"), InstructionTextTokenContents::Text), + InstructionTextToken::new("Li", InstructionTextTokenContents::Text), + InstructionTextToken::new("ne", InstructionTextTokenContents::Text), + InstructionTextToken::new(" 1", InstructionTextTokenContents::Text), ])]; let node_a = FlowGraphNode::new(&graph); diff --git a/rust/examples/template/src/main.rs b/rust/examples/template/src/main.rs index 5b21efb3..4a1bab2c 100644 --- a/rust/examples/template/src/main.rs +++ b/rust/examples/template/src/main.rs @@ -31,9 +31,7 @@ fn main() { .get_data(), addr, ) { - tokens - .iter() - .for_each(|token| print!("{}", token.text().as_str())); + tokens.iter().for_each(|token| print!("{}", token.text())); println!(); } } |
