binaryninja::types

Struct StructureBuilder

source
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);
source

pub fn new() -> Self

source

pub fn finalize(&mut self) -> Ref<Structure>

source

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.

source

pub fn alignment(&mut self, alignment: usize) -> &mut Self

source

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.

source

pub fn structure_type(&mut self, t: StructureType) -> &mut Self

source

pub fn pointer_offset(&mut self, offset: i64) -> &mut Self

source

pub fn propagates_data_var_refs(&mut self, propagates: bool) -> &mut Self

source

pub fn base_structures(&mut self, bases: &[BaseStructure]) -> &mut Self

source

pub fn append<'a, S: BnStrCompatible, T: Into<Conf<&'a Type>>>( &mut self, ty: T, name: S, access: MemberAccess, scope: MemberScope, ) -> &mut Self

source

pub fn insert_member( &mut self, member: StructureMember, overwrite_existing: bool, ) -> &mut Self

source

pub fn insert<'a, S: BnStrCompatible, T: Into<Conf<&'a Type>>>( &mut self, ty: T, name: S, offset: u64, overwrite_existing: bool, access: MemberAccess, scope: MemberScope, ) -> &mut Self

source

pub fn replace<'a, S: BnStrCompatible, T: Into<Conf<&'a Type>>>( &mut self, index: usize, ty: T, name: S, overwrite_existing: bool, ) -> &mut Self

source

pub fn remove(&mut self, index: usize) -> &mut Self

source

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.

Trait Implementations§

source§

impl Default for StructureBuilder

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Drop for StructureBuilder

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl From<&Structure> for StructureBuilder

source§

fn from(structure: &Structure) -> StructureBuilder

Converts to this type from the input type.
source§

impl From<Vec<StructureMember>> for StructureBuilder

source§

fn from(members: Vec<StructureMember>) -> StructureBuilder

Converts to this type from the input type.
source§

impl Hash for StructureBuilder

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for StructureBuilder

source§

fn eq(&self, other: &StructureBuilder) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for StructureBuilder

source§

impl StructuralPartialEq for StructureBuilder

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.