Skip to content

Commit

Permalink
Update idb_import to 0.1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
rbran authored and emesare committed Jan 27, 2025
1 parent 123bb13 commit 37f4ee4
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 160 deletions.
27 changes: 24 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/idb_import/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,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.6" }
idb-rs = { git = "https://github.com/Vector35/idb-rs", tag = "0.1.8" }
log = "0.4"
34 changes: 13 additions & 21 deletions plugins/idb_import/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use binaryninja::debuginfo::{

use idb_rs::id0::{ID0Section, IDBParam1, IDBParam2};
use idb_rs::til::section::TILSection;
use idb_rs::til::Type as TILType;
use idb_rs::til::TypeVariant as TILTypeVariant;

use log::{error, trace, warn, LevelFilter};

Expand Down Expand Up @@ -92,9 +92,7 @@ impl std::io::Seek for BinaryViewReader<'_> {
fn seek(&mut self, pos: std::io::SeekFrom) -> std::io::Result<u64> {
let new_offset = match pos {
std::io::SeekFrom::Start(offset) => Some(offset),
std::io::SeekFrom::End(end) => u64::try_from(self.bv.len())
.unwrap()
.checked_add_signed(end),
std::io::SeekFrom::End(end) => self.bv.len().checked_add_signed(end),
std::io::SeekFrom::Current(next) => self.offset.checked_add_signed(next),
};
let new_offset =
Expand Down Expand Up @@ -148,9 +146,9 @@ fn parse_til_info(
bv: debug_file,
offset: 0,
};
let file = std::io::BufReader::new(file);
let mut file = std::io::BufReader::new(file);
trace!("Parsing the TIL section");
let til = TILSection::parse(file)?;
let til = TILSection::read(&mut file, idb_rs::IDBSectionCompression::None)?;
import_til_section(debug_info, debug_file, &til, progress)
}

Expand All @@ -168,26 +166,26 @@ pub fn import_til_section(
TranslateTypeResult::NotYet => {
panic!(
"type could not be processed `{}`: {:#?}",
&String::from_utf8_lossy(&ty.name),
ty.name.as_utf8_lossy(),
&ty.og_ty
);
}
TranslateTypeResult::Error(error) => {
error!(
"Unable to parse type `{}`: {error}",
&String::from_utf8_lossy(&ty.name)
ty.name.as_utf8_lossy(),
);
}
TranslateTypeResult::PartiallyTranslated(_, error) => {
if let Some(error) = error {
error!(
"Unable to parse type `{}` correctly: {error}",
&String::from_utf8_lossy(&ty.name)
ty.name.as_utf8_lossy(),
);
} else {
warn!(
"Type `{}` maybe not be fully translated",
&String::from_utf8_lossy(&ty.name)
ty.name.as_utf8_lossy(),
);
}
}
Expand All @@ -200,11 +198,8 @@ pub fn import_til_section(
if let TranslateTypeResult::Translated(bn_ty)
| TranslateTypeResult::PartiallyTranslated(bn_ty, _) = &ty.ty
{
if !debug_info.add_type(String::from_utf8_lossy(&ty.name), bn_ty, &[/* TODO */]) {
error!(
"Unable to add type `{}`",
&String::from_utf8_lossy(&ty.name)
)
if !debug_info.add_type(ty.name.as_utf8_lossy(), bn_ty, &[/* TODO */]) {
error!("Unable to add type `{}`", ty.name.as_utf8_lossy())
}
}
}
Expand All @@ -214,11 +209,8 @@ pub fn import_til_section(
if let TranslateTypeResult::Translated(bn_ty)
| TranslateTypeResult::PartiallyTranslated(bn_ty, _) = &ty.ty
{
if !debug_info.add_type(String::from_utf8_lossy(&ty.name), bn_ty, &[/* TODO */]) {
error!(
"Unable to fix type `{}`",
&String::from_utf8_lossy(&ty.name)
)
if !debug_info.add_type(ty.name.as_utf8_lossy(), bn_ty, &[/* TODO */]) {
error!("Unable to fix type `{}`", ty.name.as_utf8_lossy())
}
}
}
Expand Down Expand Up @@ -273,7 +265,7 @@ fn parse_id0_section_info(
});

match (label, &ty, bnty) {
(_, Some(TILType::Function(_)), bnty) => {
(_, Some(ty), bnty) if matches!(&ty.type_variant, TILTypeVariant::Function(_)) => {
if bnty.is_none() {
error!("Unable to convert the function type at {addr:#x}",)
}
Expand Down
Loading

0 comments on commit 37f4ee4

Please sign in to comment.