Skip to content

Pointer offsets do not persist with type libraries #6237

@WeiN76LQh

Description

@WeiN76LQh

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.

Metadata

Metadata

Assignees

Labels

Component: Type LibrariesCore: TypesIssues involving the representation of typesEffort: LowIssues require < 1 week of workImpact: MediumIssue is impactful with a bad, or no, workaround

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions