Skip to content

Commit 27bc08f

Browse files
rbranElykDeer
authored andcommitted
Implement python Function methods to rust
Squashed: add Function::add_tag method add Function::{add_user_code_ref,remove_user_code_ref} methods add Function::{add_user_type_field_ref, remove_user_type_field_ref} methods add Function::{add_user_type_ref, remove_user_type_ref} methods add Function::apply_auto_discovered_type add Function/MediumLevelILFunction user_var_values and related functions simplify UserVariableValues::values_from_variable cargo fmt fix fix doc and QualifiedName params fix MediumLevelILFunction::is_var_user_defined parameter Remove unecessary Safety comment add Function::{create_auto_stack_var,delete_auto_stack_var} methods add MediumLevelILFunction::create_auto_var method move Function::{create_auto_stack_var,delete_auto_stack_var} methods to MediumLevelILFunction add MediumLevelILFunction::{create_user_stack_var,delete_user_stack_var} methods add Function::block_annotations method add Function::{call_stack_adjustment, call_type_adjustment} method add Function::{constant_data, constants_referenced_by, constants_referenced_by_address_if_available} methods add Function::function_tags method add Function::{indirect_branches, indirect_branches_at} methods add Function::instr_highlight method add Function::instruction_containing_address method add Function::{int_display_type,int_enum_display_typeid,int_display_type_and_typeid} methods add MediumLevelILFunction::{var_refs, var_refs_from} methods add Function::{parameter_at, parameter_at_low_level_il_instruction} methods rebase GAT changes add Function::{reg_value_at, reg_value_after, reg_value_at_exit} methods Add alpha to HighlightColor::NoHighlightColor add Function::{regs_read_by, regs_written_by} methods add Function::{stack_contents_at, stack_contents_after} methods add Function::{stack_vars_referenced_by, stack_vars_referenced_by_address_if_available} methods add Function::{tags_at, tags_at_range} methods add Function::type_tokens method add Function::variables method add Function::{is_call_instruction, is_var_user_defined} methods add Function::{mark_updates_required, mark_caller_updates_required, mark_recent_use} methods add Function::{merge_vars, unmerge_vars, split_var, unsplit_var} methods add Function::reanalyze method add Function::request_debug_report method add Function::remove_tag method add Function::remove_tags_of_type method add Function::analysis_performance_info method add Function::call_sites method add Function::caller_sites method add Function::{calling_convention, set_calling_convention} methods add Function::{can_return, set_can_return} methods add Function::comments method add Function::{clobbered_regs, set_clobbered_regs} methods add Function::{has_explicitly_defined_type, has_user_annotations, has_user_type, has_variable_arguments} methods fix Function::set_can_return_user function add Function::{high_level_il_if_available, medium_level_il_if_available, low_level_il_if_available, lifted_il_if_available} methods add Function::{global_pointer_value, has_unresolved_indirect_branches} methods add Function::lowest_address method add Function::{inline_during_analysis, set_auto_inline_during_analysis, set_user_inline_during_analysis} methods add Function::{is_pure, is_too_large, is_update_needed} methods add Function::{provenance, stack_adjustment, set_user_stack_adjustment, set_auto_stack_adjustment} methods add Function::{set_user_pure, set_auto_pure} methods add Function::set_auto_type method add Function::{return_regs, set_return_regs} methods add Function::{set_auto_return_type, set_user_return_type} methods add Function::unresolved_stack_adjustment_graph method add Function::create_graph method add Function::tags method add Function::split_variables method add Function::{reg_stack_adjustments, set_reg_stack_adjustments} methods add Function::{mapped_medium_level_il, merged_variables} methods add Function::{set_auto_instr_highlight, set_user_instr_highlight} methods add stack_adjustments methods add Function::set_user_call_stack_adjustment add Function::set_auto_call_stack_adjustment add Function::call_type_adjustment add Function::set_user_call_type_adjustment add Function::set_auto_call_type_adjustment add Function::call_reg_stack_adjustment add Function::set_user_call_reg_stack_adjustment add Function::set_auto_call_reg_stack_adjustment add Function::call_reg_stack_adjustment_for_reg_stack add Function::set_user_call_reg_stack_adjustment_for_reg_stack add Function::set_auto_call_reg_stack_adjustment_for_reg_stack add Function::set_user_reg_stack_adjustments add Function::set_auto_reg_stack_adjustments add Function::set_auto_reg_stack_adjustments add Function::set_auto_calling_convention method add Function::set_auto_can_return method add Function::{set_user_has_variable_arguments, set_auto_has_variable_arguments} methods add Function::{set_user_indirect_branches, set_auto_indirect_branches} methods add Function::set_int_display_type method add Function::{set_user_parameter_variables, set_auto_parameter_variables} methods fix documentation add Function::unresolved_indirect_branches method add Function::mapped_medium_level_il_if_available method change methods `Function::{set_user_type, set_auto_type}` to receive `&Type` merge RegisterList and RegisterSet into CoreRegister impl fix function names fix function names fix documentation syntax fix documentation syntax fix Function documentation by adding MediumLevelILInstruction::get_split_var_for_definition fix documentation links rename `VariableDefinitions` to `MediumLevelILInstructionList` fix `PossibleValueSet` switched `NotInSetOfValues` and `ReturnAddressValue`
1 parent 82dd5d4 commit 27bc08f

File tree

9 files changed

+3261
-40
lines changed

9 files changed

+3261
-40
lines changed

rust/src/architecture.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,21 @@ impl Register for CoreRegister {
715715
}
716716
}
717717

718+
impl CoreArrayProvider for CoreRegister {
719+
type Raw = u32;
720+
type Context = CoreArchitecture;
721+
type Wrapped<'a> = Self;
722+
}
723+
724+
unsafe impl CoreArrayProviderInner for CoreRegister {
725+
unsafe fn free(raw: *mut Self::Raw, _count: usize, _context: &Self::Context) {
726+
BNFreeRegisterList(raw)
727+
}
728+
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> {
729+
Self(context.0, *raw)
730+
}
731+
}
732+
718733
pub struct CoreRegisterStackInfo(*mut BNArchitecture, BNRegisterStackInfo);
719734

720735
impl RegisterStackInfo for CoreRegisterStackInfo {
@@ -2419,7 +2434,10 @@ where
24192434
};
24202435

24212436
let inputs = intrinsic.inputs();
2422-
let mut res: Box<[_]> = inputs.into_iter().map(|input| unsafe { Ref::into_raw(input) }.0).collect();
2437+
let mut res: Box<[_]> = inputs
2438+
.into_iter()
2439+
.map(|input| unsafe { Ref::into_raw(input) }.0)
2440+
.collect();
24232441

24242442
unsafe {
24252443
*count = res.len();

rust/src/disassembly.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,35 @@ impl Drop for InstructionTextToken {
265265
}
266266
}
267267

268+
impl CoreArrayProvider for InstructionTextToken {
269+
type Raw = BNInstructionTextToken;
270+
type Context = ();
271+
type Wrapped<'a> = Self;
272+
}
273+
unsafe impl CoreArrayProviderInner for InstructionTextToken {
274+
unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) {
275+
BNFreeInstructionText(raw, count)
276+
}
277+
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
278+
Self(*raw)
279+
}
280+
}
281+
282+
impl CoreArrayProvider for Array<InstructionTextToken> {
283+
type Raw = BNInstructionTextLine;
284+
type Context = ();
285+
type Wrapped<'a> = Self;
286+
}
287+
unsafe impl CoreArrayProviderInner for Array<InstructionTextToken> {
288+
unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) {
289+
BNFreeInstructionTextLines(raw, count)
290+
}
291+
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
292+
Self::new(raw.tokens, raw.count, ())
293+
}
294+
}
295+
296+
#[repr(transparent)]
268297
pub struct DisassemblyTextLine(pub(crate) BNDisassemblyTextLine);
269298

270299
impl DisassemblyTextLine {
@@ -422,6 +451,21 @@ impl Drop for DisassemblyTextLine {
422451
}
423452
}
424453

454+
impl CoreArrayProvider for DisassemblyTextLine {
455+
type Raw = BNDisassemblyTextLine;
456+
type Context = ();
457+
type Wrapped<'a> = &'a Self;
458+
}
459+
460+
unsafe impl CoreArrayProviderInner for DisassemblyTextLine {
461+
unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) {
462+
BNFreeDisassemblyTextLines(raw, count)
463+
}
464+
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
465+
core::mem::transmute(raw)
466+
}
467+
}
468+
425469
pub type DisassemblyOption = BNDisassemblyOption;
426470

427471
#[derive(PartialEq, Eq, Hash)]

0 commit comments

Comments
 (0)