Skip to content

Commit 3b2d131

Browse files
committed
Bump IDB import to use idb-rs 0.1.10
1 parent 6ac5236 commit 3b2d131

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
lines changed

Cargo.lock

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/dwarf/shared/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ license = "Apache-2.0"
99
binaryninja.workspace = true
1010
binaryninjacore-sys.workspace = true
1111
gimli = "0.31"
12-
zstd = "0.13.2"
12+
zstd = "0.13.3"
1313
thiserror = "2.0"

plugins/idb_import/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ crate-type = ["cdylib"]
1212
anyhow = { version = "1.0.86", features = ["backtrace"] }
1313
binaryninja.workspace = true
1414
binaryninjacore-sys.workspace = true
15-
idb-rs = { git = "https://github.com/Vector35/idb-rs", tag = "0.1.9" }
15+
idb-rs = { git = "https://github.com/Vector35/idb-rs", tag = "0.1.10" }
1616
log = "0.4"

plugins/idb_import/src/addr_info.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1+
use std::borrow::Cow;
12
use std::collections::HashMap;
23

34
use anyhow::Result;
45

56
use idb_rs::id0::ID0Section;
6-
use idb_rs::til;
7+
use idb_rs::{til, IDAKind};
78

89
#[derive(Default)]
910
pub struct AddrInfo<'a> {
1011
// TODO does binja diferenciate comments types on the API?
1112
pub comments: Vec<&'a [u8]>,
12-
pub label: Option<&'a str>,
13+
pub label: Option<Cow<'a, str>>,
1314
// TODO make this a ref
1415
pub ty: Option<til::Type>,
1516
}
1617

17-
pub fn get_info(id0: &ID0Section, version: u16) -> Result<HashMap<u64, AddrInfo<'_>>> {
18-
let mut addr_info: HashMap<u64, AddrInfo> = HashMap::new();
18+
pub fn get_info<K: IDAKind>(id0: &ID0Section<K>, version: u16) -> Result<HashMap<K::Usize, AddrInfo<'_>>> {
19+
let mut addr_info: HashMap<K::Usize, AddrInfo> = HashMap::new();
1920

2021
// the old style comments, most likely empty on new versions
2122
let old_comments = id0.functions_and_comments()?.filter_map(|fc| {
@@ -49,6 +50,7 @@ pub fn get_info(id0: &ID0Section, version: u16) -> Result<HashMap<u64, AddrInfo<
4950
panic!("Duplicated type for an address should be impossible this is most likelly a programing error")
5051
}
5152
}
53+
DefinedStruct(_) => {}
5254
Other { .. } => {}
5355
}
5456
}

plugins/idb_import/src/lib.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ use binaryninja::debuginfo::{
88
CustomDebugInfoParser, DebugFunctionInfo, DebugInfo, DebugInfoParser,
99
};
1010

11-
use idb_rs::id0::{ID0Section, IDBParam1, IDBParam2};
11+
use idb_rs::id0::{ID0Section, ID0SectionVariants, IDBParam1, IDBParam2};
1212
use idb_rs::til::section::TILSection;
1313
use idb_rs::til::TypeVariant as TILTypeVariant;
1414

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

1717
use anyhow::Result;
18+
use idb_rs::{IDAKind, IDAUsize};
1819
use binaryninja::logger::Logger;
1920

2021
struct IDBDebugInfoParser;
@@ -118,7 +119,7 @@ fn parse_idb_info(
118119
};
119120
trace!("Parsing a IDB file");
120121
let file = std::io::BufReader::new(file);
121-
let mut parser = idb_rs::IDBParser::new(file)?;
122+
let mut parser = idb_rs::IDAVariants::new(file)?;
122123
if let Some(til_section) = parser.til_section_offset() {
123124
trace!("Parsing the TIL section");
124125
let til = parser.read_til_section(til_section)?;
@@ -128,9 +129,16 @@ fn parse_idb_info(
128129

129130
if let Some(id0_section) = parser.id0_section_offset() {
130131
trace!("Parsing the ID0 section");
131-
let id0 = parser.read_id0_section(id0_section)?;
132+
let id0_variant = parser.read_id0_section(id0_section)?;
132133
// progress 50%-100%
133-
parse_id0_section_info(debug_info, bv, debug_file, &id0)?;
134+
match id0_variant {
135+
ID0SectionVariants::IDA32(id0) => {
136+
parse_id0_section_info(debug_info, bv, debug_file, &id0)?;
137+
}
138+
ID0SectionVariants::IDA64(id0) => {
139+
parse_id0_section_info(debug_info, bv, debug_file, &id0)?;
140+
}
141+
}
134142
}
135143

136144
Ok(())
@@ -148,7 +156,7 @@ fn parse_til_info(
148156
};
149157
let mut file = std::io::BufReader::new(file);
150158
trace!("Parsing the TIL section");
151-
let til = TILSection::read(&mut file, idb_rs::IDBSectionCompression::None)?;
159+
let til = TILSection::read(&mut file)?;
152160
import_til_section(debug_info, debug_file, &til, progress)
153161
}
154162

@@ -218,18 +226,19 @@ pub fn import_til_section(
218226
Ok(())
219227
}
220228

221-
fn parse_id0_section_info(
229+
fn parse_id0_section_info<K: IDAKind>(
222230
debug_info: &mut DebugInfo,
223231
bv: &BinaryView,
224232
debug_file: &BinaryView,
225-
id0: &ID0Section,
233+
id0: &ID0Section<K>,
226234
) -> Result<()> {
227235
let version = match id0.ida_info()? {
228236
idb_rs::id0::IDBParam::V1(IDBParam1 { version, .. })
229237
| idb_rs::id0::IDBParam::V2(IDBParam2 { version, .. }) => version,
230238
};
231239

232240
for (addr, info) in get_info(id0, version)? {
241+
let addr = addr.into_u64();
233242
// just in case we change this struct in the future, this line will for us to review this code
234243
// TODO merge this data with folder locations
235244
let AddrInfo {
@@ -264,15 +273,15 @@ fn parse_id0_section_info(
264273
}
265274
});
266275

267-
match (label, &ty, bnty) {
276+
match (&label, &ty, bnty) {
268277
(_, Some(ty), bnty) if matches!(&ty.type_variant, TILTypeVariant::Function(_)) => {
269278
if bnty.is_none() {
270279
error!("Unable to convert the function type at {addr:#x}",)
271280
}
272281
if !debug_info.add_function(&DebugFunctionInfo::new(
273282
None,
274283
None,
275-
label.map(str::to_string),
284+
label.as_deref().map(str::to_string),
276285
bnty,
277286
Some(addr),
278287
None,
@@ -283,15 +292,15 @@ fn parse_id0_section_info(
283292
}
284293
}
285294
(_, Some(_ty), Some(bnty)) => {
286-
if !debug_info.add_data_variable(addr, &bnty, label, &[]) {
295+
if !debug_info.add_data_variable(addr, &bnty, label.as_deref(), &[]) {
287296
error!("Unable to add the type at {addr:#x}")
288297
}
289298
}
290299
(_, Some(_ty), None) => {
291300
// TODO types come from the TIL sections, can we make all types be just NamedTypes?
292301
error!("Unable to convert type {addr:#x}");
293302
// TODO how to add a label without a type associacted with it?
294-
if let Some(name) = label {
303+
if let Some(name) = label.as_deref() {
295304
if !debug_info.add_data_variable(
296305
addr,
297306
&binaryninja::types::Type::void(),

0 commit comments

Comments
 (0)