Skip to content

Commit

Permalink
rebase GAT changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rbran committed May 10, 2024
1 parent 7513d8d commit 7c82a00
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 53 deletions.
14 changes: 4 additions & 10 deletions rust/src/disassembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,12 @@ impl Drop for InstructionTextToken {
impl CoreArrayProvider for InstructionTextToken {
type Raw = BNInstructionTextToken;
type Context = ();
type Wrapped<'a> = Self;
}
unsafe impl CoreOwnedArrayProvider for InstructionTextToken {
unsafe impl CoreArrayProviderInner for InstructionTextToken {
unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) {
BNFreeInstructionText(raw, count)
}
}
unsafe impl CoreArrayWrapper for InstructionTextToken {
type Wrapped<'a> = Self;

unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
Self(*raw)
}
Expand All @@ -285,15 +282,12 @@ unsafe impl CoreArrayWrapper for InstructionTextToken {
impl CoreArrayProvider for Array<InstructionTextToken> {
type Raw = BNInstructionTextLine;
type Context = ();
type Wrapped<'a> = Self;
}
unsafe impl CoreOwnedArrayProvider for Array<InstructionTextToken> {
unsafe impl CoreArrayProviderInner for Array<InstructionTextToken> {
unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) {
BNFreeInstructionTextLines(raw, count)
}
}
unsafe impl CoreArrayWrapper for Array<InstructionTextToken> {
type Wrapped<'a> = Self;

unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
Self::new(raw.tokens, raw.count, ())
}
Expand Down
4 changes: 1 addition & 3 deletions rust/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,7 @@ impl Function {
) -> DataBuffer {
let size = size.unwrap_or(0);
let state_raw = state.into_raw_value();
return DataBuffer::from_raw(unsafe {
BNGetConstantData(self.handle, state_raw, value, size)
});
DataBuffer::from_raw(unsafe { BNGetConstantData(self.handle, state_raw, value, size) })
}

pub fn constants_referenced_by(
Expand Down
21 changes: 5 additions & 16 deletions rust/src/mlil/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use binaryninjacore_sys::*;
use crate::architecture::CoreArchitecture;
use crate::basicblock::BasicBlock;
use crate::function::{Function, Location};
use crate::rc::{
Array, CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Ref, RefCountable,
};
use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Ref, RefCountable};
use crate::string::BnStrCompatible;
use crate::types::{Conf, PossibleValueSet, Type, UserVariableValues, Variable};

Expand Down Expand Up @@ -476,17 +474,12 @@ impl ILReferenceSource {
impl CoreArrayProvider for ILReferenceSource {
type Raw = BNILReferenceSource;
type Context = Ref<MediumLevelILFunction>;
type Wrapped<'a> = Self;
}

unsafe impl CoreOwnedArrayProvider for ILReferenceSource {
unsafe impl CoreArrayProviderInner for ILReferenceSource {
unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) {
BNFreeILReferences(raw, count)
}
}

unsafe impl CoreArrayWrapper for ILReferenceSource {
type Wrapped<'a> = Self;

unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> {
Self::from_raw(*raw, context.to_owned())
}
Expand All @@ -512,17 +505,13 @@ impl VariableReferenceSource {
impl CoreArrayProvider for VariableReferenceSource {
type Raw = BNVariableReferenceSource;
type Context = Ref<MediumLevelILFunction>;
type Wrapped<'a> = Self;
}

unsafe impl CoreOwnedArrayProvider for VariableReferenceSource {
unsafe impl CoreArrayProviderInner for VariableReferenceSource {
unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) {
BNFreeVariableReferenceSourceList(raw, count)
}
}

unsafe impl CoreArrayWrapper for VariableReferenceSource {
type Wrapped<'a> = Self;

unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> {
Self {
var: Variable::from_raw(raw.var),
Expand Down
7 changes: 2 additions & 5 deletions rust/src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,13 @@ impl ToOwned for Tag {
impl CoreArrayProvider for Tag {
type Raw = *mut BNTag;
type Context = ();
type Wrapped<'a> = Guard<'a, Self>;
}

unsafe impl CoreOwnedArrayProvider for Tag {
unsafe impl CoreArrayProviderInner for Tag {
unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) {
BNFreeTagList(raw, count)
}
}

unsafe impl CoreArrayWrapper for Tag {
type Wrapped<'a> = Guard<'a, Self>;
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> {
Guard::new(Self { handle: *raw }, &context)
}
Expand Down
32 changes: 13 additions & 19 deletions rust/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,7 @@ impl StructureBuilder {
&self,
members: impl IntoIterator<Item = (T, S)>,
) -> &Self {
for (t, name) in members.into_iter() {
for (t, name) in members {
self.append(t, name, MemberAccess::NoAccess, MemberScope::NoScope);
}
self
Expand Down Expand Up @@ -3204,7 +3204,7 @@ impl UserVariableValues {
result
}
pub fn all(&self) -> impl Iterator<Item = (Variable, ArchAndAddr, PossibleValueSet)> {
unsafe { &*self.vars }.into_iter().map(|var_val| {
unsafe { &*self.vars }.iter().map(|var_val| {
let var = unsafe { Variable::from_raw(var_val.var) };
let def_site = ArchAndAddr {
arch: unsafe { CoreArchitecture::from_raw(var_val.defSite.arch) },
Expand Down Expand Up @@ -3263,16 +3263,13 @@ impl ConstantReference {
impl CoreArrayProvider for ConstantReference {
type Raw = BNConstantReference;
type Context = ();
type Wrapped<'a> = Self;
}

unsafe impl CoreOwnedArrayProvider for ConstantReference {
unsafe impl CoreArrayProviderInner for ConstantReference {
unsafe fn free(raw: *mut Self::Raw, _count: usize, _context: &Self::Context) {
BNFreeConstantReferenceList(raw)
}
}

unsafe impl CoreArrayWrapper for ConstantReference {
type Wrapped<'a> = Self;
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
Self::from_raw(*raw)
}
Expand Down Expand Up @@ -3313,16 +3310,13 @@ impl IndirectBranchInfo {
impl CoreArrayProvider for IndirectBranchInfo {
type Raw = BNIndirectBranchInfo;
type Context = ();
type Wrapped<'a> = Self;
}

unsafe impl CoreOwnedArrayProvider for IndirectBranchInfo {
unsafe impl CoreArrayProviderInner for IndirectBranchInfo {
unsafe fn free(raw: *mut Self::Raw, _count: usize, _context: &Self::Context) {
BNFreeIndirectBranchList(raw)
}
}

unsafe impl CoreArrayWrapper for IndirectBranchInfo {
type Wrapped<'a> = Self;
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
Self::from_raw(*raw)
}
Expand Down Expand Up @@ -3452,7 +3446,7 @@ impl HighlightColor {
Self::StandardHighlightColor { color, alpha } => BNHighlightColor {
style: BNHighlightColorStyle::StandardHighlightColor,
color: color.into_raw(),
alpha: alpha,
alpha,
..zeroed
},
Self::MixedHighlightColor {
Expand All @@ -3463,15 +3457,15 @@ impl HighlightColor {
} => BNHighlightColor {
color: color.into_raw(),
mixColor: mix_color.into_raw(),
mix: mix,
alpha: alpha,
mix,
alpha,
..zeroed
},
Self::CustomHighlightColor { r, g, b, alpha } => BNHighlightColor {
r: r,
g: g,
b: b,
alpha: alpha,
r,
g,
b,
alpha,
..zeroed
},
}
Expand Down

0 comments on commit 7c82a00

Please sign in to comment.