binaryninja-api icon indicating copy to clipboard operation
binaryninja-api copied to clipboard

Implement functions from python Function

Open rbran opened this issue 1 year ago • 3 comments

TODO:

  • [x] Improve how to pass QualifiedNameAndType to Function::add_user_type_ref and Function::remove_user_type_ref
  • [x] Does binja ignore the alpha in a BNHighlightColor{style: StandardHighlightColor, color: NoHighlightColor, alpha: value, ..zeroed}?
  • [x] Diff of RegisterListand RegisterSet, can both be merged? Does BNFreeRegisterSet just calls BNFreeRegisterList?
  • [x] method Function::set_user_type receive a Type parameter, should it be &Type or Ref<Type> instead?
  • [x] merge int_display_type/int_enum_display_typeid and int_display_type_and_typeid?
  • [x] add other functions

Implemented:

⭕: Deprecated 🔀: Belongs in other struct 🐍: Pythonism, shold not be part of rust 🟢: Implemented by this PR 🟡: Exists on dev 🔴: Will not implement on this PR

Obs CoreAPI Function Python Function Rust Function
🟢 BNAddTag add_tag add_tag
🟢 BNAddAutoFunctionTag add_tag add_tag
🟢 BNAddAutoAddressTag add_tag add_tag
🟢 BNAddUserFunctionTag add_tag add_tag
🟢 BNAddUserAddressTag add_tag add_tag
🟢 BNAddAutoFunctionTag add_tag add_tag
🟡 BNGetFunctionAddressRanges address_ranges address_ranges
🟢 BNGetAddressTagReferences tags tags
🟢 BNAddUserCodeReference add_user_code_ref add_user_code_ref
🟢 BNAddUserTypeFieldReference add_user_type_field_ref add_user_type_field_ref
🟢 BNAddUserTypeReference add_user_type_ref add_user_type_ref
🟢 BNGetFunctionAnalysisPerformanceInfo analysis_performance_info analysis_performance_info
🟢 BNGetFunctionAnalysisSkipOverride analysis_skip_override analysis_skip_override
🟢 BNSetFunctionAnalysisSkipOverride analysis_skip_override set_analysis_skip_override
🟢 BNIsFunctionAnalysisSkipped analysis_skipped analysis_skipped
🟢 BNSetFunctionAnalysisSkipOverride analysis_skipped set_analysis_skipped
🟢 BNSetFunctionAnalysisSkipOverride set_analysis_skip_override set_analysis_skip_override
🟢 BNGetAnalysisSkipReason analysis_skip_reason analysis_skip_reason
🟢 BNApplyAutoDiscoveredFunctionType apply_auto_discovered_type apply_auto_discovered_type
🟢 BNApplyImportedTypes apply_imported_types apply_imported_types
🟡 BNGetFunctionArchitecture arch arch
🟢 BNWasFunctionAutomaticallyDiscovered auto auto
BNGetAutoAddressTagReferences auto_address_tags
🟡 BNGetFunctionBasicBlockList basic_blocks basic_blocks
🐍 callees
🐍 callee_addresses
🐍 callers
🐍 caller_sites
🟢 BNGetFunctionCallSites call_sites call_sites
🟢 BNGetFunctionCallingConvention calling_convention calling_convention
🟢 BNSetUserFunctionCallingConvention calling_convention set_user_calling_convention
🟢 BNSetAutoFunctionCallingConvention set_auto_calling_convention set_auto_calling_convention
🟢 BNGetFunctionCallSites call_sites call_sites
🟢 BNCanFunctionReturn can_return can_return
🟢 BNSetUserFunctionCanReturn can_return set_user_can_return
🟢 BNSetAutoFunctionCanReturn set_auto_can_return set_auto_can_return
🟢 BNGetFunctionClobberedRegisters clobbered_regs clobbered_registers
🟢 BNSetUserFunctionClobberedRegisters clobbered_regs set_clobbered_registers
🟢 BNSetUserFunctionClobberedRegisters set_user_clobbered_regs set_user_clobbered_registers
🟢 BNSetAutoFunctionClobberedRegisters set_auto_clobbered_regs set_auto_clobbered_registers
🟢 BNGetFunctionComment comment comment
🟢 BNSetFunctionComment comment set_comment
🟢 BNGetCommentedAddresses comments comments
🐍 components
🟢 BNGetFunctionVariables core_vars variables
🟢 BNGetStackLayout core_var_stack_layout stack_layout
🟢 BNCreateFunctionGraph create_graph create_graph
🟡 BNGetFunctionBasicBlockAtAddress get_basic_block_at basic_block_containing
🟢 BNGetFunctionBlockAnnotations get_block_annotations block_annotations
🟢 BNGetCallRegisterStackAdjustment get_call_reg_stack_adjustment call_reg_stack_adjustment
🟢 BNGetCallRegisterStackAdjustmentForRegisterStack get_call_reg_stack_adjustment_for_reg_stack call_reg_stack_adjustment_for_reg_stack
🟢 BNGetCallStackAdjustment get_call_stack_adjustment call_stack_adjustment
🟢 BNGetCallTypeAdjustment get_call_type_adjustment call_type_adjustment
🟡 BNGetCommentForAddress get_comment_at comment_at
🟢 BNGetConstantData get_constant_data constant_data
🟢 BNGetConstantsReferencedByInstruction get_constants_referenced_by constants_referenced_by
🟢 BNGetConstantsReferencedByInstructionIfAvailable get_constants_referenced_by_address_if_available constants_referenced_by_address_if_available
🔀 BNGetFlagsReadByLiftedILInstruction get_flags_read_by_lifted_il_instruction
🔀 BNGetFlagsWrittenByLiftedILInstruction get_flags_written_by_lifted_il_instruction
🟢 BNGetFunctionTagsOfType get_function_tags function_tags
🟢 BNGetAutoFunctionTagsOfType get_function_tags function_tags
🟢 BNGetUserFunctionTagsOfType get_function_tags function_tags
🟢 BNGetFunctionTags get_function_tags function_tags
🟢 BNGetAutoFunctionTags get_function_tags function_tags
🟢 BNGetUserFunctionTags get_function_tags function_tags
🔀 BNGetHighLevelILVariableReferences get_hlil_var_refs
🔀 BNGetHighLevelILVariableReferencesFrom get_hlil_var_refs_from
🔀 BNGetHighLevelILVariableReferencesInRange get_hlil_var_refs_from
🟢 BNGetIndirectBranchesAt get_indirect_branches_at indirect_branches_at
🟢 BNGetInstructionHighlight get_instr_highlight instr_highlight
🟢 BNGetInstructionContainingAddress get_instruction_containing_address instruction_containing_address
🟢 BNGetIntegerConstantDisplayType get_int_display_type int_display_type
🟢 BNGetIntegerConstantDisplayTypeEnumerationType get_int_enum_display_typeid int_enum_display_typeid
🟢 get_int_display_type_and_typeid int_display_type_and_typeid
🔀 BNGetLiftedILForInstruction get_lifted_il_at
🔀 BNGetLiftedILFlagDefinitionsForUse get_lifted_il_flag_definitions_for_use
🔀 BNGetLiftedILFlagUsesForDefinition get_lifted_il_flag_uses_for_definition
🔀 BNGetLiftedILInstructionsForAddress get_lifted_ils_at
🐍 get_llil_at
🔀 BNGetLowLevelILInstructionsForAddress get_llils_at
🔀 BNGetLowLevelILForInstruction get_low_level_il_at
🔀 BNGetLowLevelILExitsForInstruction get_low_level_il_exits_at
🟢 BNGetParameterValueAtInstruction get_parameter_at parameter_at
🟢 BNGetParameterValueAtLowLevelILInstruction get_parameter_at_low_level_il_instruction parameter_at_low_level_il_instruction
🟢 BNGetRegistersReadByInstruction get_regs_read_by registers_read_by
🟢 BNGetRegistersWrittenByInstruction get_regs_written_by registers_written_by
🟢 BNGetRegisterValueAfterInstruction get_reg_value_after reg_value_after
🟢 BNGetRegisterValueAtInstruction get_reg_value_at reg_value_at
🟢 BNGetFunctionRegisterValueAtExit get_reg_value_at_exit reg_value_at_exit
🟢 BNGetStackContentsAfterInstruction get_stack_contents_after stack_contents_after
🟢 BNGetStackContentsAtInstruction get_stack_contents_at stack_contents_at
🟢 BNGetStackVariableAtFrameOffset get_stack_var_at_frame_offset stack_var_at_frame_offset
🟢 BNGetStackVariablesReferencedByInstruction get_stack_vars_referenced_by stack_variables_referenced_by
🟢 BNGetStackVariablesReferencedByInstructionIfAvailable get_stack_vars_referenced_by_address_if_available stack_variables_referenced_by_address_if_available
🟢 BNGetAddressTags get_tags_at tags_at
🟢 BNGetAutoAddressTags get_tags_at tags_at
🟢 BNGetUserAddressTags get_tags_at tags_at
🟢 BNGetAddressTagsInRange get_tags_in_range tags_in_range
🟢 BNGetAutoAddressTagsInRange get_tags_in_range tags_in_range
🟢 BNGetUserAddressTagsInRange get_tags_in_range tags_in_range
🟢 BNGetFunctionTypeTokens get_type_tokens type_tokens
🐍 get_variable_by_name
🟢 BNGetFunctionGlobalPointerValue global_pointer_value global_pointer_value
🟢 BNFunctionHasExplicitlyDefinedType has_explicitly_defined_type has_explicitly_defined_type
🟢 BNHasUnresolvedIndirectBranches has_unresolved_indirect_branches has_unresolved_indirect_branches
🟢 BNFunctionHasUserAnnotations has_user_annotations has_user_annotations
🟢 BNFunctionHasUserType has_user_type has_user_type
🟢 BNFunctionHasVariableArguments has_variable_arguments has_variable_arguments
🟢 BNSetUserFunctionHasVariableArguments has_variable_arguments set_user_has_variable_arguments
🟢 BNSetAutoFunctionHasVariableArguments set_auto_has_variable_arguments set_auto_has_variable_arguments
🟢 BNGetFunctionLowestAddress lowest_address lowest_address
🟡 BNGetFunctionHighestAddress highest_address highest_address
🟡 BNGetFunctionLiftedIL lifted_il lifted_il
🟢 BNGetFunctionLiftedILIfAvailable lifted_il_if_available lifted_il_if_available
🟡 BNGetFunctionMediumLevelIL medium_level_il medium_level_il
🟢 BNGetFunctionMappedMediumLevelIL mapped_medium_level_il mapped_medium_level_il
🟢 BNGetFunctionMappedMediumLevelILIfAvailable mmlil_if_available mapped_medium_level_il_if_available
🟢 BNGetFunctionMediumLevelILIfAvailable mlil_if_available medium_level_il_if_available
🟡 BNGetFunctionHighLevelIL high_level_il high_level_il
🟢 BNGetFunctionHighLevelILIfAvailable hlil_if_available high_level_il_if_available
🟢 BNGetIndirectBranches indirect_branches indirect_branches
🟢 BNIsFunctionInlinedDuringAnalysis inline_during_analysis inline_during_analysis
🟢 BNSetUserFunctionInlinedDuringAnalysis set_user_inline_during_analysis set_user_inline_during_analysis
🟢 BNSetAutoFunctionInlinedDuringAnalysis set_auto_inline_during_analysis set_auto_inline_during_analysis
🐍 instructions
🟢 BNIsCallInstruction is_call_instruction is_call_instruction
🟢 BNIsFunctionPure is_pure is_pure
🟢 BNSetUserFunctionPure is_pure set_is_pure
🔀 is_thunk
🟢 BNIsVariableUserDefined is_var_user_defined is_variable_user_defined
🐍 llil_basic_blocks
🐍 llil_instructions
🟢 BNMarkCallerUpdatesRequired mark_caller_updates_required mark_caller_updates_required
🟢 BNMarkFunctionAsRecentlyUsed mark_recent_use mark_recent_use
🟢 BNMarkUpdatesRequired mark_updates_required mark_updates_required
🟢 BNGetMergedVariables merged_vars merged_variables
🟢 BNMergeVariables merge_vars merge_variables
🔀 mlil_basic_blocks
🔀 mlil_instructions
🔴 name
🟢 BNIsFunctionUpdateNeeded needs_update is_update_needed
🟡 BNGetFunctionParameterVariables parameter_vars parameter_variables
🟢 BNSetUserFunctionParameterVariables parameter_vars set_user_parameter_variables
🟢 BNSetAutoFunctionParameterVariables set_auto_parameter_vars set_auto_parameter_variables
🟡 BNGetFunctionPlatform platform platform
🟢 BNGetProvenanceString provenance provenance
🟢 BNReanalyzeFunction reanalyze reanalyze
🟢 BNGetFunctionRegisterStackAdjustments reg_stack_adjustments reg_stack_adjustments
🟢 BNSetUserFunctionRegisterStackAdjustments reg_stack_adjustments set_user_reg_stack_adjustments
🟢 BNSetAutoFunctionRegisterStackAdjustments set_auto_reg_stack_adjustments set_auto_reg_stack_adjustments
🔴 BNRequestAdvancedFunctionAnalysisData release_advanced_analysis_data
🔴 BNReleaseAdvancedFunctionAnalysisData request_advanced_analysis_data
🟢 BNRemoveAutoFunctionTag remove_auto_function_tag remove_tag
🟢 BNRemoveAutoAddressTag remove_auto_address_tag remove_tag
🟢 BNRemoveUserFunctionTag remove_user_function_tag remove_tag
🟢 BNRemoveUserAddressTag remove_user_address_tag remove_tag
🟢 BNRemoveAutoFunctionTagsOfType remove_auto_function_tags_of_type remove_tags_of_type
🟢 BNRemoveAutoAddressTagsOfType remove_auto_address_tags_of_type remove_tags_of_type
🟢 BNRemoveUserFunctionTagsOfType remove_user_function_tags_of_type remove_tags_of_type
🟢 BNRemoveUserAddressTagsOfType remove_user_address_tags_of_type remove_tags_of_type
🟢 BNRemoveUserCodeReference remove_user_code_ref remove_user_code_ref
🟢 BNRemoveUserTypeReference remove_user_type_ref remove_user_type_ref
🟢 BNRequestFunctionDebugReport request_debug_report request_debug_report
🟢 BNGetFunctionReturnRegisters return_regs return_registers
🟢 BNSetUserFunctionReturnRegisters return_regs set_user_return_registers
🟢 BNSetAutoFunctionReturnRegisters set_auto_return_regs set_auto_return_registers
🟢 BNGetFunctionReturnType return_type return_type
🟢 BNSetUserFunctionReturnType return_type set_user_return_type
🟢 BNSetAutoFunctionReturnType set_auto_return_type set_auto_return_type
🐍 session_data
🐍 set_default_session_data
🟢 BNSetAutoFunctionCallingConvention set_auto_calling_convention set_auto_calling_convention
🟢 BNSetAutoCallRegisterStackAdjustment set_auto_call_reg_stack_adjustment set_auto_call_reg_stack_adjustment
🟢 BNSetAutoCallRegisterStackAdjustmentForRegisterStack set_auto_call_reg_stack_adjustment_for_reg_stack set_auto_call_reg_stack_adjustment_for_reg_stack
🟢 BNSetAutoCallStackAdjustment set_auto_call_stack_adjustment set_auto_call_stack_adjustment
🟢 BNSetAutoFunctionCanReturn set_auto_can_return set_auto_can_return
🟢 BNSetAutoFunctionHasVariableArguments set_auto_has_variable_arguments set_auto_has_variable_arguments
🟢 BNSetAutoIndirectBranches set_auto_indirect_branches set_auto_indirect_branches
🟢 BNSetAutoFunctionInlinedDuringAnalysis set_auto_inline_during_analysis set_auto_inline_during_analysis
🟢 BNSetAutoInstructionHighlight set_auto_instr_highlight set_auto_instr_highlight
🟢 BNSetAutoFunctionParameterVariables set_auto_parameter_vars set_auto_parameter_variables
🟢 BNSetAutoFunctionPure set_auto_pure set_auto_pure
🟢 BNSetAutoFunctionRegisterStackAdjustments set_auto_reg_stack_adjustments set_auto_reg_stack_adjustments
🟢 BNSetAutoFunctionReturnRegisters set_auto_return_regs set_auto_return_regs
🟢 BNSetAutoFunctionReturnType set_auto_return_type set_auto_return_type
🟢 BNSetAutoFunctionStackAdjustment set_auto_stack_adjustment set_auto_stack_adjustment
🟢 BNSetFunctionAutoType set_auto_type set_auto_type
🟢 BNSetUserCallRegisterStackAdjustment set_call_reg_stack_adjustment set_user_call_reg_stack_adjustment
🟢 BNSetUserCallRegisterStackAdjustmentForRegisterStack set_call_reg_stack_adjustment_for_reg_stack set_user_call_reg_stack_adjustment_for_reg_stack
🟢 BNSetUserCallStackAdjustment set_call_stack_adjustment set_user_call_stack_adjustment
🟢 BNSetUserCallTypeAdjustment set_call_type_adjustment set_user_call_type_adjustment
🟢 BNSetCommentForAddress set_comment_at set_comment_at
🟢 BNSetIntegerConstantDisplayType set_int_display_type set_int_display_type
🟢 BNSetUserIndirectBranches set_user_indirect_branches set_user_indirect_branches
🟢 BNSetUserFunctionInlinedDuringAnalysis set_user_inline_during_analysis set_user_inline_during_analysis
🟢 BNSetUserInstructionHighlight set_user_instr_highlight set_user_instr_highlight
🟢 BNGetSplitVariables split_vars split_variables
🟢 BNSplitVariable split_var split_variable
🟢 BNGetFunctionStackAdjustment stack_adjustment stack_adjustment
🟢 BNSetUserFunctionStackAdjustment stack_adjustment set_user_stack_adjustment
🟢 BNSetAutoFunctionStackAdjustment set_auto_stack_adjustment set_auto_stack_adjustment
🟢 BNGetStackLayout stack_layout stack_layout
🟡 BNGetFunctionStart start start
🟡 BNGetFunctionSymbol symbol symbol
🟢 BNGetAddressTagReferences tags tags
🟢 BNIsFunctionTooLarge too_large too_large
🔴 total_bytes
🟡 BNGetFunctionType type type
🟢 BNSetFunctionUserType type set_user_type
🟢 BNGetFunctionTypeTokens type_tokens type_tokens
🟢 BNUnmergeVariables unmerge_vars unmerge_variables
🟢 BNGetUnresolvedIndirectBranches unresolved_indirect_branches unresolved_indirect_branches
🟢 BNGetUnresolvedStackAdjustmentGraph unresolved_stack_adjustment_graph unresolved_stack_adjustment_graph
🟢 BNUnsplitVariable unsplit_var unsplit_variable
BNGetUserAddressTagReferences user_address_tags
🟢 BNGetFunctionVariables vars variables
🟢 BNGetFunctionData view view
🔴 BNGetWorkflowForFunction workflow

Mlil

Some functions belong to the mlil mod, and should not being part of this PR, but I only noticed that after those functions where written...

CoreAPI Function Python Function Rust Function
clear_all_user_var_values clear_user_var_values
BNClearUserVariableValue clear_user_var_value clear_user_var_value
BNCreateUserVariable create_user_var create_user_var
BNCreateAutoVariable create_auto_var create_auto_var
BNCreateUserStackVariable create_user_stack_var create_user_stack_var
BNCreateAutoStackVariable create_auto_stack_var create_auto_stack_var
BNDeleteUserStackVariable delete_user_stack_var delete_user_stack_var
BNDeleteAutoStackVariable delete_auto_stack_var delete_auto_stack_var
BNDeleteUserVariable delete_user_var delete_user_var
BNGetAllUserVariableValues get_all_user_var_values user_var_values
BNClearUserVariableValue clear_user_var_value clear_user_var_value
BNClearUserVariableValue clear_user_var_value clear_user_var_value
BNSetUserVariableValue set_user_var_value set_user_var_value
BNGetMediumLevelILVariableReferences get_mlil_var_refs var_refs
BNGetMediumLevelILVariableReferencesFrom get_mlil_var_refs_from var_refs_from
BNGetMediumLevelILVariableReferencesInRange get_mlil_var_refs_from var_refs_from
BNGetDefaultIndexForMediumLevelILVariableDefinition get_split_var_for_definition get_split_var_for_definition

rbran avatar May 08 '24 12:05 rbran

Tests being written at: https://github.com/rbran/binaryninja-test mostly on mlil_vars

rbran avatar May 09 '24 13:05 rbran

At least for basic blocks, the UI does the following with highlight colors:

QColor blockColor = m_render.getHighlightColor(line.block->GetBasicBlockHighlight());
blockColor.setAlpha((blockColor.alpha() * 80) / 255);
if (blockColor.alpha() != 0)
{
	p.setPen(QColor(0, 0, 0, 0));
	p.setBrush(blockColor);
	p.drawRect(xoffset, 2 + (y * charHeight), viewportWidth, charHeight);
}

ElykDeer avatar May 10 '24 16:05 ElykDeer

I guess it all depends on the getHighlightColor, just in case I added an alpha value for HighlightColor::NoHighlightColor

rbran avatar May 11 '24 10:05 rbran