diff options
| author | rbran <git@rubens.io> | 2025-05-22 21:12:43 +0000 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2025-05-27 09:44:36 -0400 |
| commit | 8820fd7a7a553d8bceea870997cce3c12eeb9427 (patch) | |
| tree | cf7e53ba62f215d5652198a0ae7ca0d52b0af8c5 /plugins/idb_import | |
| parent | ff04e7fbbbd6ccbdd6ed35a4e243699eca99935a (diff) | |
update idb_import idb-rs to 0.1.10
Diffstat (limited to 'plugins/idb_import')
| -rw-r--r-- | plugins/idb_import/Cargo.toml | 2 | ||||
| -rw-r--r-- | plugins/idb_import/src/addr_info.rs | 25 | ||||
| -rw-r--r-- | plugins/idb_import/src/lib.rs | 48 |
3 files changed, 45 insertions, 30 deletions
diff --git a/plugins/idb_import/Cargo.toml b/plugins/idb_import/Cargo.toml index db41d40a..9456aaba 100644 --- a/plugins/idb_import/Cargo.toml +++ b/plugins/idb_import/Cargo.toml @@ -12,5 +12,5 @@ crate-type = ["cdylib"] anyhow = { version = "1.0.86", features = ["backtrace"] } binaryninja.workspace = true binaryninjacore-sys.workspace = true -idb-rs = { git = "https://github.com/Vector35/idb-rs", tag = "0.1.9" } +idb-rs = { git = "https://github.com/Vector35/idb-rs", tag = "0.1.10" } log = "0.4" diff --git a/plugins/idb_import/src/addr_info.rs b/plugins/idb_import/src/addr_info.rs index 8d1b1c1b..cb977496 100644 --- a/plugins/idb_import/src/addr_info.rs +++ b/plugins/idb_import/src/addr_info.rs @@ -1,30 +1,32 @@ +use std::borrow::Cow; use std::collections::HashMap; use anyhow::Result; use idb_rs::id0::ID0Section; -use idb_rs::til; +use idb_rs::{til, IDAKind}; #[derive(Default)] pub struct AddrInfo<'a> { // TODO does binja diferenciate comments types on the API? pub comments: Vec<&'a [u8]>, - pub label: Option<&'a str>, + pub label: Option<Cow<'a, str>>, // TODO make this a ref pub ty: Option<til::Type>, } -pub fn get_info(id0: &ID0Section, version: u16) -> Result<HashMap<u64, AddrInfo<'_>>> { - let mut addr_info: HashMap<u64, AddrInfo> = HashMap::new(); +pub fn get_info<K: IDAKind>( + id0: &ID0Section<K>, + version: u16, +) -> Result<HashMap<K::Usize, AddrInfo<'_>>> { + use idb_rs::id0::FunctionsAndComments::*; + let mut addr_info: HashMap<K::Usize, AddrInfo> = HashMap::new(); // the old style comments, most likely empty on new versions - let old_comments = id0.functions_and_comments()?.filter_map(|fc| { - use idb_rs::id0::FunctionsAndComments::*; - match fc { - Err(e) => Some(Err(e)), - Ok(Comment { address, comment }) => Some(Ok((address, comment))), - Ok(Name | Function(_) | Unknown { .. }) => None, - } + let old_comments = id0.functions_and_comments()?.filter_map(|fc| match fc { + Err(e) => Some(Err(e)), + Ok(Comment { address, comment }) => Some(Ok((address, comment))), + Ok(Name | Function(_) | Unknown { .. }) => None, }); for old_comment in old_comments { let (addr, comment) = old_comment?; @@ -50,6 +52,7 @@ pub fn get_info(id0: &ID0Section, version: u16) -> Result<HashMap<u64, AddrInfo< } } Other { .. } => {} + DefinedStruct(_) => {} } } diff --git a/plugins/idb_import/src/lib.rs b/plugins/idb_import/src/lib.rs index 46acfd42..e0af22fd 100644 --- a/plugins/idb_import/src/lib.rs +++ b/plugins/idb_import/src/lib.rs @@ -1,4 +1,5 @@ mod types; +use idb_rs::{IDAKind, IDAUsize}; use types::*; mod addr_info; use addr_info::*; @@ -82,7 +83,7 @@ impl std::io::Read for BinaryViewReader<'_> { if !self.bv.offset_valid(self.offset) { return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "")); } - let len = self.bv.read(buf, self.offset); + let len = BinaryView::read(&self.bv, buf, self.offset); self.offset += u64::try_from(len).unwrap(); Ok(len) } @@ -118,7 +119,7 @@ fn parse_idb_info( }; trace!("Parsing a IDB file"); let file = std::io::BufReader::new(file); - let mut parser = idb_rs::IDBParser::new(file)?; + let mut parser = idb_rs::IDBParserVariants::new(file)?; if let Some(til_section) = parser.til_section_offset() { trace!("Parsing the TIL section"); let til = parser.read_til_section(til_section)?; @@ -130,7 +131,14 @@ fn parse_idb_info( trace!("Parsing the ID0 section"); let id0 = parser.read_id0_section(id0_section)?; // progress 50%-100% - parse_id0_section_info(debug_info, bv, debug_file, &id0)?; + match id0 { + idb_rs::IDAVariants::IDA32(id0) => { + parse_id0_section_info::<idb_rs::IDA32>(debug_info, bv, debug_file, &id0)? + } + idb_rs::IDAVariants::IDA64(id0) => { + parse_id0_section_info::<idb_rs::IDA64>(debug_info, bv, debug_file, &id0)? + } + } } Ok(()) @@ -148,7 +156,7 @@ fn parse_til_info( }; let mut file = std::io::BufReader::new(file); trace!("Parsing the TIL section"); - let til = TILSection::read(&mut file, idb_rs::IDBSectionCompression::None)?; + let til = TILSection::read(&mut file)?; import_til_section(debug_info, debug_file, &til, progress) } @@ -218,11 +226,11 @@ pub fn import_til_section( Ok(()) } -fn parse_id0_section_info( +fn parse_id0_section_info<K: IDAKind>( debug_info: &mut DebugInfo, bv: &BinaryView, debug_file: &BinaryView, - id0: &ID0Section, + id0: &ID0Section<K>, ) -> Result<()> { let version = match id0.ida_info()? { idb_rs::id0::IDBParam::V1(IDBParam1 { version, .. }) @@ -238,8 +246,11 @@ fn parse_id0_section_info( ty, } = info; // TODO set comments to address here - for function in &bv.functions_containing(addr) { - function.set_comment_at(addr, &String::from_utf8_lossy(&comments.join(&b"\n"[..]))); + for function in &bv.functions_containing(addr.into_u64()) { + function.set_comment_at( + addr.into_u64(), + &String::from_utf8_lossy(&comments.join(&b"\n"[..])), + ); } let bnty = ty @@ -262,16 +273,16 @@ fn parse_id0_section_info( }); match (label, &ty, bnty) { - (_, Some(ty), bnty) if matches!(&ty.type_variant, TILTypeVariant::Function(_)) => { + (label, Some(ty), bnty) if matches!(&ty.type_variant, TILTypeVariant::Function(_)) => { if bnty.is_none() { error!("Unable to convert the function type at {addr:#x}",) } if !debug_info.add_function(&DebugFunctionInfo::new( None, None, - label.map(str::to_string), + label.map(|x| x.to_string()), bnty, - Some(addr), + Some(addr.into_u64()), None, vec![], vec![], @@ -279,20 +290,21 @@ fn parse_id0_section_info( error!("Unable to add the function at {addr:#x}") } } - (_, Some(_ty), Some(bnty)) => { - if !debug_info.add_data_variable(addr, &bnty, label, &[]) { + (label, Some(_ty), Some(bnty)) => { + let label: Option<&str> = label.as_ref().map(|x| x.as_ref()); + if !debug_info.add_data_variable(addr.into_u64(), &bnty, label, &[]) { error!("Unable to add the type at {addr:#x}") } } - (_, Some(_ty), None) => { + (label, Some(_ty), None) => { // TODO types come from the TIL sections, can we make all types be just NamedTypes? error!("Unable to convert type {addr:#x}"); // TODO how to add a label without a type associacted with it? if let Some(name) = label { if !debug_info.add_data_variable( - addr, + addr.into_u64(), &binaryninja::types::Type::void(), - Some(name), + Some(&name), &[], ) { error!("Unable to add the label at {addr:#x}") @@ -302,9 +314,9 @@ fn parse_id0_section_info( (Some(name), None, None) => { // TODO how to add a label without a type associacted with it? if !debug_info.add_data_variable( - addr, + addr.into_u64(), &binaryninja::types::Type::void(), - Some(name), + Some(&name), &[], ) { error!("Unable to add the label at {addr:#x}") |
