Skip to content

update idb_import idb-rs to 0.1.12 #7236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

rbran
Copy link
Contributor

@rbran rbran commented Aug 5, 2025

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
Copy link
Contributor Author

rbran commented Aug 12, 2025

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

@emesare
Copy link
Member

emesare commented Aug 12, 2025

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
Copy link
Contributor Author

rbran commented Aug 12, 2025

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
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
Copy link
Contributor Author

rbran commented Aug 13, 2025

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
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