cxiao / rust_type_layout_helper_bn Goto Github PK
View Code? Open in Web Editor NEWAn extremely experimental Binary Ninja importer for the type layout information emitted by the -Zprint-type-sizes flag of the Rust compiler.
License: MIT License
An extremely experimental Binary Ninja importer for the type layout information emitted by the -Zprint-type-sizes flag of the Rust compiler.
License: MIT License
When importing the following types:
print-type-size type: `std::sys_common::net::SocketAddrCRepr`: 28 bytes, alignment: 4 bytes
print-type-size variant `SocketAddrCRepr`: 28 bytes
print-type-size field `.v4`: 16 bytes
print-type-size field `.v6`: 28 bytes, offset: 0 bytes, alignment: 4 bytes
print-type-size type: `std::sys::windows::c::IO_STATUS_BLOCK_union`: 8 bytes, alignment: 8 bytes
print-type-size variant `IO_STATUS_BLOCK_union`: 8 bytes
print-type-size field `.Status`: 4 bytes
print-type-size field `.Pointer`: 8 bytes, offset: 0 bytes, alignment: 8 bytes
We see the following errors regarding size mismatches:
Size of created variant struct (44 bytes) does not match size of parsed Rust variant struct (28 bytes)
Created struct for Rust type std::sys_common::net::SocketAddrCRepr has size (44 bytes) which does not match size of parsed Rust type (28 bytes)
Size of created variant struct (12 bytes) does not match size of parsed Rust variant struct (8 bytes)
Created struct for Rust type std::sys::windows::c::IO_STATUS_BLOCK_union has size (12 bytes) which does not match size of parsed Rust type (8 bytes)
The original types definitions in Rust are:
#[repr(C)]
pub(crate) union SocketAddrCRepr {
v4: c::sockaddr_in,
v6: c::sockaddr_in6,
}
#[repr(C)]
union IO_STATUS_BLOCK_union {
Status: NTSTATUS,
Pointer: *mut c_void,
}
Source for SocketAddrCRepr
(Rust 1.67.1): https://github.com/rust-lang/rust/blob/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/net.rs#L720
Source for IO_STATUS_BLOCK_union
(Rust 1.67.1): https://github.com/rust-lang/rust/blob/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys/windows/c.rs#LL335C8-L335C8
The created type definitions in Binary Ninja are the following. Rather than being created as an union with two members, these types are incorrectly created as a union containing a struct with two members. This causes the created type size to be too large.
struct std::sys_common::net::SocketAddrCRepr __packed
{
union __packed
{
struct std::sys_common::net::SocketAddrCRepr::SocketAddrCRepr SocketAddrCRepr;
} std::sys_common::net::SocketAddrCRepr::variants;
};
struct std::sys_common::net::SocketAddrCRepr::SocketAddrCRepr __packed
{
int128_t .v4;
char .v6[0x1c];
};
struct std::sys::windows::c::IO_STATUS_BLOCK_union __packed
{
union __packed
{
struct std::sys::windows::c::IO_STATUS_BLOCK_union::IO_STATUS_BLOCK_union IO_STATUS_BLOCK_union;
} std::sys::windows::c::IO_STATUS_BLOCK_union::variants;
};
struct std::sys::windows::c::IO_STATUS_BLOCK_union::IO_STATUS_BLOCK_union __packed
{
int32_t .Status;
int64_t .Pointer;
};
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.