Skip to content

Commit 7675a43

Browse files
committed
update idb_import idb-rs to 0.1.10
1 parent 52c3e8b commit 7675a43

File tree

4 files changed

+44
-31
lines changed

4 files changed

+44
-31
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/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: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
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>(
19+
id0: &ID0Section<K>,
20+
version: u16,
21+
) -> Result<HashMap<K::Usize, AddrInfo<'_>>> {
22+
use idb_rs::id0::FunctionsAndComments::*;
23+
let mut addr_info: HashMap<K::Usize, AddrInfo> = HashMap::new();
1924

2025
// the old style comments, most likely empty on new versions
21-
let old_comments = id0.functions_and_comments()?.filter_map(|fc| {
22-
use idb_rs::id0::FunctionsAndComments::*;
23-
match fc {
24-
Err(e) => Some(Err(e)),
25-
Ok(Comment { address, comment }) => Some(Ok((address, comment))),
26-
Ok(Name | Function(_) | Unknown { .. }) => None,
27-
}
26+
let old_comments = id0.functions_and_comments()?.filter_map(|fc| match fc {
27+
Err(e) => Some(Err(e)),
28+
Ok(Comment { address, comment }) => Some(Ok((address, comment))),
29+
Ok(Name | Function(_) | Unknown { .. }) => None,
2830
});
2931
for old_comment in old_comments {
3032
let (addr, comment) = old_comment?;
@@ -50,6 +52,7 @@ pub fn get_info(id0: &ID0Section, version: u16) -> Result<HashMap<u64, AddrInfo<
5052
}
5153
}
5254
Other { .. } => {}
55+
DefinedStruct(_) => {}
5356
}
5457
}
5558

plugins/idb_import/src/lib.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod types;
2+
use idb_rs::{IDAKind, IDAUsize};
23
use types::*;
34
mod addr_info;
45
use addr_info::*;
@@ -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::IDBParserVariants::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)?;
@@ -130,7 +131,14 @@ fn parse_idb_info(
130131
trace!("Parsing the ID0 section");
131132
let id0 = parser.read_id0_section(id0_section)?;
132133
// progress 50%-100%
133-
parse_id0_section_info(debug_info, bv, debug_file, &id0)?;
134+
match id0 {
135+
idb_rs::IDAVariants::IDA32(id0) => {
136+
parse_id0_section_info::<idb_rs::IDA32>(debug_info, bv, debug_file, &id0)?
137+
}
138+
idb_rs::IDAVariants::IDA64(id0) => {
139+
parse_id0_section_info::<idb_rs::IDA64>(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,11 +226,11 @@ 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, .. })
@@ -238,9 +246,9 @@ fn parse_id0_section_info(
238246
ty,
239247
} = info;
240248
// TODO set comments to address here
241-
for function in &bv.functions_containing(addr) {
249+
for function in &bv.functions_containing(addr.into_u64()) {
242250
function.set_comment_at(
243-
addr,
251+
addr.into_u64(),
244252
String::from_utf8_lossy(&comments.join(&b"\n"[..])).to_string(),
245253
);
246254
}
@@ -265,35 +273,35 @@ fn parse_id0_section_info(
265273
});
266274

267275
match (label, &ty, bnty) {
268-
(_, Some(ty), bnty) if matches!(&ty.type_variant, TILTypeVariant::Function(_)) => {
276+
(label, Some(ty), bnty) if matches!(&ty.type_variant, TILTypeVariant::Function(_)) => {
269277
if bnty.is_none() {
270278
error!("Unable to convert the function type at {addr:#x}",)
271279
}
272280
if !debug_info.add_function(DebugFunctionInfo::new(
273281
None,
274282
None,
275-
label.map(str::to_string),
283+
label.map(|x| x.to_string()),
276284
bnty,
277-
Some(addr),
285+
Some(addr.into_u64()),
278286
None,
279287
vec![],
280288
vec![],
281289
)) {
282290
error!("Unable to add the function at {addr:#x}")
283291
}
284292
}
285-
(_, Some(_ty), Some(bnty)) => {
286-
if !debug_info.add_data_variable(addr, &bnty, label, &[]) {
293+
(label, Some(_ty), Some(bnty)) => {
294+
if !debug_info.add_data_variable(addr.into_u64(), &bnty, label, &[]) {
287295
error!("Unable to add the type at {addr:#x}")
288296
}
289297
}
290-
(_, Some(_ty), None) => {
298+
(label, Some(_ty), None) => {
291299
// TODO types come from the TIL sections, can we make all types be just NamedTypes?
292300
error!("Unable to convert type {addr:#x}");
293301
// TODO how to add a label without a type associacted with it?
294302
if let Some(name) = label {
295303
if !debug_info.add_data_variable(
296-
addr,
304+
addr.into_u64(),
297305
&binaryninja::types::Type::void(),
298306
Some(name),
299307
&[],
@@ -305,7 +313,7 @@ fn parse_id0_section_info(
305313
(Some(name), None, None) => {
306314
// TODO how to add a label without a type associacted with it?
307315
if !debug_info.add_data_variable(
308-
addr,
316+
addr.into_u64(),
309317
&binaryninja::types::Type::void(),
310318
Some(name),
311319
&[],

0 commit comments

Comments
 (0)