Skip to content

Commit

Permalink
More rust cleanup
Browse files Browse the repository at this point in the history
- Normalized modules
- Split some code out into own files
- Fixed some UB in type archive and projects
- Improved API around type archives and projects substantially
- Added ProgressExecutor abstraction for functions which have a progress callback
- Improved background task documentation and added unit tests
- Added worker thread api and unit tests
- Moved some owned types to ref types, this is still not complete, but this is the path forward.
- Add external location/library accessors to the binary view
- Added some misc documentation
- Replaced mod.rs with the module name source file

Still need to normalize some paths and also update some documentation surrounding that change.
  • Loading branch information
emesare committed Jan 18, 2025
1 parent 6405576 commit 6341003
Show file tree
Hide file tree
Showing 130 changed files with 2,653 additions and 2,182 deletions.
4 changes: 2 additions & 2 deletions arch/msp430/src/architecture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use msp430_asm::{
use binaryninja::architecture::{
BranchKind, FlagClassId, FlagGroupId, FlagId, FlagWriteId, RegisterId,
};
use binaryninja::lowlevelil::expression::ValueExpr;
use binaryninja::lowlevelil::{MutableLiftedILExpr, MutableLiftedILFunction};
use binaryninja::low_level_il::expression::ValueExpr;
use binaryninja::low_level_il::{MutableLiftedILExpr, MutableLiftedILFunction};
use log::error;

const MIN_MNEMONIC: usize = 9;
Expand Down
8 changes: 4 additions & 4 deletions arch/msp430/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ extern crate msp430_asm;
use binaryninja::{
add_optional_plugin_dependency,
architecture::ArchitectureExt,
callingconvention,
custombinaryview::{BinaryViewType, BinaryViewTypeExt},
calling_convention,
custom_binary_view::{BinaryViewType, BinaryViewTypeExt},
Endianness,
};
use log::LevelFilter;
Expand Down Expand Up @@ -36,13 +36,13 @@ pub extern "C" fn CorePluginInit() -> bool {
// https://www.ti.com/lit/an/slaa664/slaa664.pdf?ts=1613210655081. MSPGCC
// appears to be a legacy calling convention while EABI is the newer
// standardized one that is compatible with TI's compiler
let default = callingconvention::ConventionBuilder::new(arch)
let default = calling_convention::ConventionBuilder::new(arch)
.is_eligible_for_heuristics(true)
.int_arg_registers(&["r15", "r14", "r13", "r12"])
.return_int_reg("r15")
.return_hi_int_reg("r14")
.register("default");
callingconvention::ConventionBuilder::new(arch)
calling_convention::ConventionBuilder::new(arch)
.is_eligible_for_heuristics(true)
.return_int_reg("r15")
.return_hi_int_reg("r14")
Expand Down
6 changes: 3 additions & 3 deletions arch/msp430/src/lift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::flag::{Flag, FlagWrite};
use crate::register::Register;
use crate::Msp430;

use binaryninja::{architecture::FlagCondition, lowlevelil::lifting::Label};
use binaryninja::{architecture::FlagCondition, low_level_il::lifting::Label};

use msp430_asm::emulate::Emulated;
use msp430_asm::instruction::Instruction;
Expand All @@ -12,8 +12,8 @@ use msp430_asm::operand::{Operand, OperandWidth};
use msp430_asm::single_operand::SingleOperand;
use msp430_asm::two_operand::TwoOperand;

use binaryninja::lowlevelil::expression::ValueExpr;
use binaryninja::lowlevelil::{MutableLiftedILExpr, MutableLiftedILFunction};
use binaryninja::low_level_il::expression::ValueExpr;
use binaryninja::low_level_il::{MutableLiftedILExpr, MutableLiftedILFunction};
use log::info;

macro_rules! auto_increment {
Expand Down
2 changes: 1 addition & 1 deletion arch/msp430/src/register.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use binaryninja::architecture;
use binaryninja::architecture::{ImplicitRegisterExtend, RegisterId};

use binaryninja::lowlevelil::LowLevelILRegister;
use binaryninja::low_level_il::LowLevelILRegister;
use std::borrow::Cow;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand Down
16 changes: 8 additions & 8 deletions arch/riscv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ use binaryninja::{
LlvmServicesRelocMode, Register as Reg, RegisterInfo, UnusedFlag, UnusedRegisterStack,
UnusedRegisterStackInfo,
},
binaryview::{BinaryView, BinaryViewExt},
callingconvention::{register_calling_convention, CallingConventionBase, ConventionBuilder},
custombinaryview::{BinaryViewType, BinaryViewTypeExt},
binary_view::{BinaryView, BinaryViewExt},
calling_convention::{register_calling_convention, CallingConventionBase, ConventionBuilder},
custom_binary_view::{BinaryViewType, BinaryViewTypeExt},
disassembly::{InstructionTextToken, InstructionTextTokenKind},
function::Function,
functionrecognizer::FunctionRecognizer,
function_recognizer::FunctionRecognizer,
rc::Ref,
relocation::{
CoreRelocationHandler, CustomRelocationHandlerHandle, RelocationHandler, RelocationInfo,
Expand All @@ -37,10 +37,10 @@ use std::marker::PhantomData;
use binaryninja::architecture::{BranchKind, IntrinsicId, RegisterId};
use binaryninja::confidence::{Conf, MAX_CONFIDENCE, MIN_CONFIDENCE};
use binaryninja::logger::Logger;
use binaryninja::lowlevelil::expression::{LowLevelILExpressionKind, ValueExpr};
use binaryninja::lowlevelil::instruction::LowLevelILInstructionKind;
use binaryninja::lowlevelil::lifting::{Label, LiftableLowLevelIL, LiftableLowLevelILWithSize};
use binaryninja::lowlevelil::{
use binaryninja::low_level_il::expression::{LowLevelILExpressionKind, ValueExpr};
use binaryninja::low_level_il::instruction::LowLevelILInstructionKind;
use binaryninja::low_level_il::lifting::{Label, LiftableLowLevelIL, LiftableLowLevelILWithSize};
use binaryninja::low_level_il::{
expression::ExpressionHandler, instruction::InstructionHandler, LowLevelILRegister,
MutableLiftedILExpr, MutableLiftedILFunction, RegularLowLevelILFunction,
};
Expand Down
2 changes: 1 addition & 1 deletion plugins/dwarf/dwarf_export/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::fs;

use binaryninja::logger::Logger;
use binaryninja::{
binaryview::{BinaryView, BinaryViewBase, BinaryViewExt},
binary_view::{BinaryView, BinaryViewBase, BinaryViewExt},
command::{register, Command},
confidence::Conf,
interaction,
Expand Down
4 changes: 2 additions & 2 deletions plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ use crate::{
};

use binaryninja::{
binaryview::{BinaryView, BinaryViewBase, BinaryViewExt},
binary_view::{BinaryView, BinaryViewBase, BinaryViewExt},
debuginfo::{DebugFunctionInfo, DebugInfo},
platform::Platform,
rc::*,
symbol::SymbolType,
templatesimplifier::simplify_str_to_fqn,
template_simplifier::simplify_str_to_fqn,
types::{FunctionParameter, Type},
variable::NamedVariableWithType,
};
Expand Down
2 changes: 1 addition & 1 deletion plugins/dwarf/dwarf_import/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::dwarfdebuginfo::{DebugInfoBuilder, DebugInfoBuilderContext, TypeUID};
use crate::types::get_type;
use crate::{helpers::*, ReaderType};

use binaryninja::templatesimplifier::simplify_str_to_str;
use binaryninja::template_simplifier::simplify_str_to_str;
use cpp_demangle::DemangleOptions;
use gimli::{constants, AttributeValue, DebuggingInformationEntry, Dwarf, Operation, Unit};
use log::{debug, error};
Expand Down
8 changes: 4 additions & 4 deletions plugins/dwarf/dwarf_import/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ use std::path::{Path, PathBuf};
use std::{collections::HashMap, ops::Deref, str::FromStr, sync::mpsc};

use crate::{DebugInfoBuilderContext, ReaderType};
use binaryninja::binaryview::BinaryViewBase;
use binaryninja::filemetadata::FileMetadata;
use binaryninja::binary_view::BinaryViewBase;
use binaryninja::file_metadata::FileMetadata;
use binaryninja::Endianness;
use binaryninja::{
binaryview::{BinaryView, BinaryViewExt},
downloadprovider::{DownloadInstanceInputOutputCallbacks, DownloadProvider},
binary_view::{BinaryView, BinaryViewExt},
download_provider::{DownloadInstanceInputOutputCallbacks, DownloadProvider},
rc::Ref,
settings::Settings,
};
Expand Down
6 changes: 3 additions & 3 deletions plugins/dwarf/dwarf_import/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ use crate::functions::parse_function_entry;
use crate::helpers::{get_attr_die, get_name, get_uid, DieReference};
use crate::types::parse_variable;

use binaryninja::binaryview::BinaryViewBase;
use binaryninja::binary_view::BinaryViewBase;
use binaryninja::{
binaryview::{BinaryView, BinaryViewExt},
binary_view::{BinaryView, BinaryViewExt},
debuginfo::{CustomDebugInfoParser, DebugInfo, DebugInfoParser},
settings::Settings,
templatesimplifier::simplify_str_to_str,
template_simplifier::simplify_str_to_str,
};
use dwarfreader::{
create_section_reader, get_endian, is_dwo_dwarf, is_non_dwo_dwarf, is_raw_dwo_dwarf,
Expand Down
2 changes: 1 addition & 1 deletion plugins/dwarf/dwarfdump/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

use binaryninja::{
binaryview::{BinaryView, BinaryViewExt},
binary_view::{BinaryView, BinaryViewExt},
command::{register, Command},
disassembly::{DisassemblyTextLine, InstructionTextToken, InstructionTextTokenKind},
flowgraph::{BranchType, EdgeStyle, FlowGraph, FlowGraphNode, FlowGraphOption},
Expand Down
2 changes: 1 addition & 1 deletion plugins/dwarf/shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use gimli::{EndianRcSlice, Endianity, RunTimeEndian, SectionId};

use binaryninja::{
binaryview::{BinaryView, BinaryViewBase, BinaryViewExt},
binary_view::{BinaryView, BinaryViewBase, BinaryViewExt},
settings::Settings,
Endianness,
};
Expand Down
2 changes: 1 addition & 1 deletion plugins/idb_import/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use types::*;
mod addr_info;
use addr_info::*;

use binaryninja::binaryview::{BinaryView, BinaryViewBase, BinaryViewExt};
use binaryninja::binary_view::{BinaryView, BinaryViewBase, BinaryViewExt};
use binaryninja::debuginfo::{
CustomDebugInfoParser, DebugFunctionInfo, DebugInfo, DebugInfoParser,
};
Expand Down
2 changes: 1 addition & 1 deletion plugins/idb_import/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::collections::HashMap;

use anyhow::{anyhow, Result};
use binaryninja::architecture::CoreArchitecture;
use binaryninja::binary_view::{BinaryView, BinaryViewExt};
use binaryninja::binaryninjacore_sys::{BNMemberAccess, BNMemberScope};
use binaryninja::binaryview::{BinaryView, BinaryViewExt};
use binaryninja::confidence::Conf;
use binaryninja::rc::Ref;
use binaryninja::types::{
Expand Down
4 changes: 2 additions & 2 deletions plugins/pdb-ng/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ use anyhow::{anyhow, Result};
use log::{debug, error, info};
use pdb::PDB;

use binaryninja::binaryview::{BinaryView, BinaryViewBase, BinaryViewExt};
use binaryninja::binary_view::{BinaryView, BinaryViewBase, BinaryViewExt};
use binaryninja::debuginfo::{CustomDebugInfoParser, DebugInfo, DebugInfoParser};
use binaryninja::downloadprovider::{DownloadInstanceInputOutputCallbacks, DownloadProvider};
use binaryninja::download_provider::{DownloadInstanceInputOutputCallbacks, DownloadProvider};
use binaryninja::interaction::{MessageBoxButtonResult, MessageBoxButtonSet};
use binaryninja::logger::Logger;
use binaryninja::settings::Settings;
Expand Down
4 changes: 2 additions & 2 deletions plugins/pdb-ng/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use pdb::*;
use crate::symbol_parser::{ParsedDataSymbol, ParsedProcedure, ParsedSymbol};
use crate::type_parser::ParsedType;
use binaryninja::architecture::{Architecture, CoreArchitecture};
use binaryninja::binaryview::{BinaryView, BinaryViewExt};
use binaryninja::callingconvention::CallingConvention;
use binaryninja::binary_view::{BinaryView, BinaryViewExt};
use binaryninja::calling_convention::CallingConvention;
use binaryninja::confidence::{Conf, MIN_CONFIDENCE};
use binaryninja::debuginfo::{DebugFunctionInfo, DebugInfo};
use binaryninja::platform::Platform;
Expand Down
2 changes: 1 addition & 1 deletion plugins/pdb-ng/src/symbol_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use pdb::{

use crate::PDBParserInstance;
use binaryninja::architecture::{Architecture, ArchitectureExt, Register, RegisterId};
use binaryninja::binaryview::BinaryViewBase;
use binaryninja::binary_view::BinaryViewBase;
use binaryninja::confidence::{Conf, MAX_CONFIDENCE, MIN_CONFIDENCE};
use binaryninja::demangle::demangle_ms;
use binaryninja::rc::Ref;
Expand Down
4 changes: 2 additions & 2 deletions plugins/pdb-ng/src/type_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::struct_grouper::group_structure;
use crate::PDBParserInstance;
use anyhow::{anyhow, Result};
use binaryninja::architecture::{Architecture, CoreArchitecture};
use binaryninja::binaryview::BinaryViewExt;
use binaryninja::callingconvention::CallingConvention;
use binaryninja::binary_view::BinaryViewExt;
use binaryninja::calling_convention::CallingConvention;
use binaryninja::confidence::{Conf, MAX_CONFIDENCE};
use binaryninja::platform::Platform;
use binaryninja::rc::Ref;
Expand Down
2 changes: 1 addition & 1 deletion plugins/warp/benches/convert.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use binaryninja::binaryview::BinaryViewExt;
use binaryninja::binary_view::BinaryViewExt;
use binaryninja::headless::Session;
use criterion::{criterion_group, criterion_main, Criterion};
use std::path::PathBuf;
Expand Down
2 changes: 1 addition & 1 deletion plugins/warp/benches/function.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use binaryninja::binaryview::BinaryViewExt;
use binaryninja::binary_view::BinaryViewExt;
use binaryninja::headless::Session;
use criterion::{criterion_group, criterion_main, Criterion};
use rayon::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion plugins/warp/benches/guid.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use binaryninja::binaryview::BinaryViewExt;
use binaryninja::binary_view::BinaryViewExt;
use binaryninja::headless::Session;
use criterion::{criterion_group, criterion_main, Criterion};
use warp_ninja::function_guid;
Expand Down
9 changes: 2 additions & 7 deletions plugins/warp/src/bin/sigem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ar::Archive;
use clap::{arg, Parser};
use rayon::prelude::*;

use binaryninja::binaryview::{BinaryView, BinaryViewExt};
use binaryninja::binary_view::{BinaryView, BinaryViewExt};
use binaryninja::function::Function as BNFunction;
use binaryninja::rc::Guard as BNGuard;
use binaryninja::settings::Settings;
Expand Down Expand Up @@ -99,12 +99,7 @@ fn main() {
let bn_settings = Settings::new("");
let worker_count = rayon::current_num_threads() * 4;
log::debug!("Adjusting Binary Ninja worker count to {}...", worker_count);
bn_settings.set_integer(
"analysis.limits.workerThreadCount",
worker_count as u64,
None,
None,
);
binaryninja::worker_thread::set_worker_thread_count(worker_count);

// Make sure caches are flushed when the views get destructed.
register_cache_destructor();
Expand Down
6 changes: 3 additions & 3 deletions plugins/warp/src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::convert::{from_bn_symbol, from_bn_type_internal};
use crate::{build_function, function_guid};
use binaryninja::architecture::Architecture;
use binaryninja::binaryview::{BinaryView, BinaryViewExt};
use binaryninja::binary_view::{BinaryView, BinaryViewExt};
use binaryninja::confidence::MAX_CONFIDENCE;
use binaryninja::function::Function as BNFunction;
use binaryninja::lowlevelil::function::{
use binaryninja::low_level_il::function::{
FunctionMutability, LowLevelILFunction, NonSSA, RegularNonSSA,
};
use binaryninja::lowlevelil::RegularLowLevelILFunction;
use binaryninja::low_level_il::RegularLowLevelILFunction;
use binaryninja::rc::Guard;
use binaryninja::rc::Ref as BNRef;
use binaryninja::symbol::Symbol as BNSymbol;
Expand Down
6 changes: 3 additions & 3 deletions plugins/warp/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::collections::HashSet;

use binaryninja::architecture::Architecture as BNArchitecture;
use binaryninja::architecture::ArchitectureExt;
use binaryninja::binaryview::{BinaryView, BinaryViewExt};
use binaryninja::callingconvention::CallingConvention as BNCallingConvention;
use binaryninja::binary_view::{BinaryView, BinaryViewExt};
use binaryninja::calling_convention::CallingConvention as BNCallingConvention;
use binaryninja::confidence::{Conf as BNConf, MAX_CONFIDENCE};
use binaryninja::rc::Ref as BNRef;
use binaryninja::symbol::{Symbol as BNSymbol, SymbolType as BNSymbolType};
Expand Down Expand Up @@ -573,7 +573,7 @@ pub fn to_bn_type<A: BNArchitecture>(arch: &A, ty: &Type) -> BNRef<BNType> {
#[cfg(test)]
mod tests {
use super::*;
use binaryninja::binaryview::BinaryViewExt;
use binaryninja::binary_view::BinaryViewExt;
use binaryninja::headless::Session;
use std::path::PathBuf;
use std::sync::OnceLock;
Expand Down
14 changes: 7 additions & 7 deletions plugins/warp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ use crate::convert::{from_bn_symbol, from_bn_type};
use binaryninja::architecture::{
Architecture, ImplicitRegisterExtend, Register as BNRegister, RegisterInfo,
};
use binaryninja::basicblock::BasicBlock as BNBasicBlock;
use binaryninja::binaryview::BinaryViewExt;
use binaryninja::basic_block::BasicBlock as BNBasicBlock;
use binaryninja::binary_view::BinaryViewExt;
use binaryninja::confidence::MAX_CONFIDENCE;
use binaryninja::function::{Function as BNFunction, NativeBlock};
use binaryninja::lowlevelil::expression::{ExpressionHandler, LowLevelILExpressionKind};
use binaryninja::lowlevelil::function::{
use binaryninja::low_level_il::expression::{ExpressionHandler, LowLevelILExpressionKind};
use binaryninja::low_level_il::function::{
FunctionMutability, LowLevelILFunction, NonSSA, RegularNonSSA,
};
use binaryninja::lowlevelil::instruction::{
use binaryninja::low_level_il::instruction::{
InstructionHandler, LowLevelILInstruction, LowLevelILInstructionKind,
};
use binaryninja::lowlevelil::{LowLevelILRegister, VisitorAction};
use binaryninja::low_level_il::{LowLevelILRegister, VisitorAction};
use binaryninja::rc::Ref as BNRef;
use std::path::PathBuf;
use warp::signature::basic_block::BasicBlockGUID;
Expand Down Expand Up @@ -183,7 +183,7 @@ pub fn basic_block_guid<A: Architecture, M: FunctionMutability>(
#[cfg(test)]
mod tests {
use crate::cache::cached_function_guid;
use binaryninja::binaryview::BinaryViewExt;
use binaryninja::binary_view::BinaryViewExt;
use binaryninja::headless::Session;
use std::path::PathBuf;
use std::sync::OnceLock;
Expand Down
2 changes: 1 addition & 1 deletion plugins/warp/src/matcher.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use binaryninja::architecture::Architecture as BNArchitecture;
use binaryninja::binaryview::{BinaryView, BinaryViewExt};
use binaryninja::binary_view::{BinaryView, BinaryViewExt};
use binaryninja::function::Function as BNFunction;
use binaryninja::platform::Platform;
use binaryninja::rc::Guard;
Expand Down
2 changes: 1 addition & 1 deletion plugins/warp/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::matcher::{
invalidate_function_matcher_cache, Matcher, MatcherSettings, PlatformID, PLAT_MATCHER_CACHE,
};
use crate::{build_function, cache};
use binaryninja::binaryview::{BinaryView, BinaryViewExt};
use binaryninja::binary_view::{BinaryView, BinaryViewExt};
use binaryninja::command::{Command, FunctionCommand};
use binaryninja::function::{Function, FunctionUpdateType};
use binaryninja::logger::Logger;
Expand Down
2 changes: 1 addition & 1 deletion plugins/warp/src/plugin/add.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::cache::{cached_function, cached_type_references};
use crate::matcher::invalidate_function_matcher_cache;
use crate::user_signature_dir;
use binaryninja::binaryview::BinaryView;
use binaryninja::binary_view::BinaryView;
use binaryninja::command::FunctionCommand;
use binaryninja::function::Function;
use std::thread;
Expand Down
2 changes: 1 addition & 1 deletion plugins/warp/src/plugin/copy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use binaryninja::binaryview::BinaryView;
use binaryninja::binary_view::BinaryView;
use binaryninja::command::FunctionCommand;
use binaryninja::function::Function;

Expand Down
Loading

0 comments on commit 6341003

Please sign in to comment.