pub struct StructureBuilder { /* private fields */ }Implementations§
Source§impl StructureBuilder
// Includes
use binaryninja::types::{MemberAccess, MemberScope, Structure, StructureBuilder, Type};
// Types to use in the members
let field_1_ty = Type::named_int(5, false, "my_weird_int_type");
let field_2_ty = Type::int(4, false);
let field_3_ty = Type::int(8, false);
// Assign those fields
let mut my_custom_struct = StructureBuilder::new();
my_custom_struct
.insert(
&field_1_ty,
"field_1",
0,
false,
MemberAccess::PublicAccess,
MemberScope::NoScope,
)
.insert(
&field_2_ty,
"field_2",
5,
false,
MemberAccess::PublicAccess,
MemberScope::NoScope,
)
.insert(
&field_3_ty,
"field_3",
9,
false,
MemberAccess::PublicAccess,
MemberScope::NoScope,
)
.append(
&field_1_ty,
"field_4",
MemberAccess::PublicAccess,
MemberScope::NoScope,
);
// Convert structure to type
let my_custom_structure_type = Type::structure(&my_custom_struct.finalize());
// Add the struct to the binary view to use in analysis
let bv = binaryninja::load("example").unwrap();
bv.define_user_type("my_custom_struct", &my_custom_structure_type);
impl StructureBuilder
// Includes
use binaryninja::types::{MemberAccess, MemberScope, Structure, StructureBuilder, Type};
// Types to use in the members
let field_1_ty = Type::named_int(5, false, "my_weird_int_type");
let field_2_ty = Type::int(4, false);
let field_3_ty = Type::int(8, false);
// Assign those fields
let mut my_custom_struct = StructureBuilder::new();
my_custom_struct
.insert(
&field_1_ty,
"field_1",
0,
false,
MemberAccess::PublicAccess,
MemberScope::NoScope,
)
.insert(
&field_2_ty,
"field_2",
5,
false,
MemberAccess::PublicAccess,
MemberScope::NoScope,
)
.insert(
&field_3_ty,
"field_3",
9,
false,
MemberAccess::PublicAccess,
MemberScope::NoScope,
)
.append(
&field_1_ty,
"field_4",
MemberAccess::PublicAccess,
MemberScope::NoScope,
);
// Convert structure to type
let my_custom_structure_type = Type::structure(&my_custom_struct.finalize());
// Add the struct to the binary view to use in analysis
let bv = binaryninja::load("example").unwrap();
bv.define_user_type("my_custom_struct", &my_custom_structure_type);pub fn new() -> Self
pub fn finalize(&self) -> Ref<Structure>
Sourcepub fn width(&mut self, width: u64) -> &mut Self
pub fn width(&mut self, width: u64) -> &mut Self
Sets the width of the StructureBuilder to the new width.
This will remove all previously inserted members outside the new width. This is done by computing the member access range (member offset + member width) and if it is larger than the new width it will be removed.
pub fn alignment(&mut self, alignment: usize) -> &mut Self
Sourcepub fn packed(&mut self, packed: bool) -> &mut Self
pub fn packed(&mut self, packed: bool) -> &mut Self
Sets whether the StructureBuilder is packed.
If set the alignment of the structure will be 1. You do not need to set the alignment to 1.
pub fn structure_type(&mut self, t: StructureType) -> &mut Self
pub fn pointer_offset(&mut self, offset: i64) -> &mut Self
pub fn propagates_data_var_refs(&mut self, propagates: bool) -> &mut Self
pub fn base_structures(&mut self, bases: &[BaseStructure]) -> &mut Self
Sourcepub fn append<'a, T: Into<Conf<&'a Type>>>(
&mut self,
ty: T,
name: &str,
access: MemberAccess,
scope: MemberScope,
) -> &mut Self
pub fn append<'a, T: Into<Conf<&'a Type>>>( &mut self, ty: T, name: &str, access: MemberAccess, scope: MemberScope, ) -> &mut Self
Append a member at the next available byte offset.
Otherwise, consider using:
Sourcepub fn insert_member(
&mut self,
member: StructureMember,
overwrite_existing: bool,
) -> &mut Self
pub fn insert_member( &mut self, member: StructureMember, overwrite_existing: bool, ) -> &mut Self
Insert an already constructed StructureMember.
Otherwise, consider using:
Sourcepub fn insert<'a, T: Into<Conf<&'a Type>>>(
&mut self,
ty: T,
name: &str,
offset: u64,
overwrite_existing: bool,
access: MemberAccess,
scope: MemberScope,
) -> &mut Self
pub fn insert<'a, T: Into<Conf<&'a Type>>>( &mut self, ty: T, name: &str, offset: u64, overwrite_existing: bool, access: MemberAccess, scope: MemberScope, ) -> &mut Self
Inserts a member at the offset (in bytes).
If you need to insert a member at a specific bit within a given byte (like a bitfield), you
can use StructureBuilder::insert_bitwise.
Sourcepub fn insert_bitwise<'a, T: Into<Conf<&'a Type>>>(
&mut self,
ty: T,
name: &str,
bit_offset: u64,
bit_width: Option<u8>,
overwrite_existing: bool,
access: MemberAccess,
scope: MemberScope,
) -> &mut Self
pub fn insert_bitwise<'a, T: Into<Conf<&'a Type>>>( &mut self, ty: T, name: &str, bit_offset: u64, bit_width: Option<u8>, overwrite_existing: bool, access: MemberAccess, scope: MemberScope, ) -> &mut Self
Inserts a member at bit_offset with an optional bit_width.
NOTE: The bit_offset is relative to the start of the structure, for example, passing 8 will place
the field at the start of the byte 0x1.
pub fn replace<'a, T: Into<Conf<&'a Type>>>( &mut self, index: usize, ty: T, name: &str, overwrite_existing: bool, ) -> &mut Self
Sourcepub fn current_width(&self) -> u64
pub fn current_width(&self) -> u64
Gets the current unaligned width of the structure.
This cannot be used to accurately get the width of a non-packed structure.