Skip to content

update idb_import idb-rs to 0.1.12#7236

Closed
rbran wants to merge 2 commits into
Vector35:devfrom
rbran:idb_import_0_1_12
Closed

update idb_import idb-rs to 0.1.12#7236
rbran wants to merge 2 commits into
Vector35:devfrom
rbran:idb_import_0_1_12

Conversation

@rbran

@rbran rbran commented Aug 5, 2025

Copy link
Copy Markdown
Contributor

Unfortunately I'm unable to test this on the latest dev release of Binary Ninja, it seems that something on the BinaryViewReader changed (likely BinaryView::offset_valid) and it broke all the versions of idb_import.

I'm investigating.

@rbran rbran marked this pull request as ready for review August 12, 2025 13:22
@rbran

rbran commented Aug 12, 2025

Copy link
Copy Markdown
Contributor Author

Seems like self.bv.offset_valid(offset) was returning true if offset = [the file size] previously, but now it returns false.

@emesare

emesare commented Aug 12, 2025

Copy link
Copy Markdown
Member

We added a reader / writer impl recently in the rust bindings, maybe those work? I recall you asking for them @rbran

impl Seek for BinaryReader {
/// Seek to the specified position.
fn seek(&mut self, pos: SeekFrom) -> std::io::Result<u64> {
match pos {
SeekFrom::Current(offset) => self.seek_to_relative_offset(offset),
SeekFrom::Start(offset) => self.seek_to_offset(offset),
SeekFrom::End(end_offset) => {
// We do NOT need to add the image base here as
// the reader (unlike the writer) can set the virtual base.
let offset =
self.view
.len()
.checked_add_signed(end_offset)
.ok_or(std::io::Error::new(
ErrorKind::Other,
"Seeking from end overflowed",
))?;
self.seek_to_offset(offset);
}
};
Ok(self.offset())
}
}
impl Read for BinaryReader {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
let len = buf.len();
let result = unsafe { BNReadData(self.handle, buf.as_mut_ptr() as *mut _, len) };
if !result {
Err(std::io::Error::new(ErrorKind::Other, "Read out of bounds"))
} else {
Ok(len)
}
}
}

https://github.com/Vector35/binaryninja-api/blob/dev/rust/tests/binary_reader.rs

@rbran

rbran commented Aug 12, 2025

Copy link
Copy Markdown
Contributor Author

Humm...

I forgot about that, that wold had worked too.

@@ -86,10 +86,9 @@ struct BinaryViewReader<'a> {
impl std::io::Read for BinaryViewReader<'_> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

impl Seek for BinaryReader {
/// Seek to the specified position.
fn seek(&mut self, pos: SeekFrom) -> std::io::Result<u64> {
match pos {
SeekFrom::Current(offset) => self.seek_to_relative_offset(offset),
SeekFrom::Start(offset) => self.seek_to_offset(offset),
SeekFrom::End(end_offset) => {
// We do NOT need to add the image base here as
// the reader (unlike the writer) can set the virtual base.
let offset =
self.view
.len()
.checked_add_signed(end_offset)
.ok_or(std::io::Error::new(
ErrorKind::Other,
"Seeking from end overflowed",
))?;
self.seek_to_offset(offset);
}
};
Ok(self.offset())
}
}
impl Read for BinaryReader {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
let len = buf.len();
let result = unsafe { BNReadData(self.handle, buf.as_mut_ptr() as *mut _, len) };
if !result {
Err(std::io::Error::new(ErrorKind::Other, "Read out of bounds"))
} else {
Ok(len)
}
}
}

As per the discussion we had in this PR swap BinaryViewReader out for the one in bindings

@rbran

rbran commented Aug 13, 2025

Copy link
Copy Markdown
Contributor Author

I'm unable to use BinaryReader, I get a io error: Read out of bounds

@emesare emesare self-assigned this Aug 18, 2025
@emesare emesare added this to the Io milestone Aug 18, 2025
@emesare

emesare commented Sep 3, 2025

Copy link
Copy Markdown
Member

Merged with 8d4fcf6 apologies for the delay!

@emesare emesare closed this Sep 3, 2025
@rbran rbran deleted the idb_import_0_1_12 branch September 4, 2025 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants