Skip to content
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

Pointer offsets do not persist with type libraries #6237

Open
WeiN76LQh opened this issue Dec 7, 2024 · 0 comments
Open

Pointer offsets do not persist with type libraries #6237

WeiN76LQh opened this issue Dec 7, 2024 · 0 comments

Comments

@WeiN76LQh
Copy link

Version and Platform (required):

  • Binary Ninja Version: 4.3.6541-dev (2a7e8df1)
  • OS: macOS
  • OS Version: 15.1.1
  • CPU Architecture: M1

Bug Description:
Offset pointers do not maintain their offsets when stored in a type library. If I define a pointer type that has an offset and then store that type in a type library, when the type is loaded from the type library, its offset is 0. Its not obvious if this is because the offset is not being written into the type library or not being loaded from the library.

Steps To Reproduce:
The following python code will define an offset pointer and store it in a type library and then import it from the type library. It prints the offset on the pointer when its first defined and then again once it has been imported from the type library. This can be copied, pasted and run in the integrated python terminal in the BN UI.

# Define a 256 byte struct and an offset pointer to that struct
parsed_types = bv.platform.parse_types_from_source("struct Foo { char Bar[0x100]; }; typedef void* __offset(Foo, 0x10) Baz;").types
# Print the actual offset of the pointer
print(f"Original offset = {parsed_types['Baz'].offset}")
# Create the type library
typelib = binaryninja.TypeLibrary.new(bv.arch, f"test")
typelib.add_platform(bv.platform)
# Add the struct definition to the type library
typelib.add_named_type("Foo", parsed_types["Foo"])
# Add the offset pointer to the struct to the type library
typelib.add_named_type("Baz", parsed_types["Baz"])
# Import the type library into BN
bv.add_type_library(typelib)
# Import the types from the type library
bv.import_library_type("Foo")
bv.import_library_type("Baz")
# Print the offset of the offset pointer
print(f"Offset after type library = {bv.get_type_by_name('Baz').offset}")

Expected Behavior:
The offset for the pointer should be maintained across storing and loading from a type library.

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

No branches or pull requests

1 participant