Skip to content

Commit

Permalink
Add VariableSourceType type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrasnitski committed Jul 22, 2024
1 parent 7d9d9d4 commit 75a2781
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
5 changes: 2 additions & 3 deletions rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ use binaryninja::{
rc::*,
symbol::SymbolType,
templatesimplifier::simplify_str_to_fqn,
types::{Conf, FunctionParameter, NamedTypedVariable, Type, Variable},
binaryninjacore_sys::BNVariableSourceType,
types::{Conf, FunctionParameter, NamedTypedVariable, Type, Variable, VariableSourceType},
};

use gimli::{DebuggingInformationEntry, Dwarf, Unit};
Expand Down Expand Up @@ -415,7 +414,7 @@ impl DebugInfoBuilder {
return;
}

let var = Variable::new(BNVariableSourceType::StackVariableSourceType, 0, adjusted_offset);
let var = Variable::new(VariableSourceType::StackVariableSourceType, 0, adjusted_offset);
function.stack_variables.push(NamedTypedVariable::new(var, name, t, false));

}
Expand Down
17 changes: 8 additions & 9 deletions rust/examples/pdb-ng/src/symbol_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ use pdb::{
};

use binaryninja::architecture::{Architecture, ArchitectureExt, Register};
use binaryninja::binaryninjacore_sys::BNVariableSourceType;
use binaryninja::binaryview::BinaryViewBase;
use binaryninja::demangle::demangle_ms;
use binaryninja::rc::Ref;
use binaryninja::types::{
max_confidence, min_confidence, Conf, ConfMergable, FunctionParameter, QualifiedName,
StructureBuilder, Type, TypeClass, Variable,
StructureBuilder, Type, TypeClass, Variable, VariableSourceType,
};

use crate::PDBParserInstance;
Expand Down Expand Up @@ -736,7 +735,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
let storage = if let Some(reg) = self.convert_register(data.register) {
vec![ParsedLocation {
location: Variable {
t: BNVariableSourceType::RegisterVariableSourceType,
t: VariableSourceType::RegisterVariableSourceType,
index: 0,
storage: reg,
},
Expand Down Expand Up @@ -1425,7 +1424,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
type_: self.lookup_type_conf(&data.type_index, false)?,
storage: vec![ParsedLocation {
location: Variable {
t: BNVariableSourceType::StackVariableSourceType,
t: VariableSourceType::StackVariableSourceType,
index: 0,
storage: data.offset as i64,
},
Expand All @@ -1443,7 +1442,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
type_: self.lookup_type_conf(&data.type_index, false)?,
storage: vec![ParsedLocation {
location: Variable {
t: BNVariableSourceType::StackVariableSourceType,
t: VariableSourceType::StackVariableSourceType,
index: 0,
storage: data.offset as i64,
},
Expand Down Expand Up @@ -1587,7 +1586,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
if let Some(reg) = self.convert_register(data.register) {
Ok(Some(ParsedSymbol::Location(ParsedLocation {
location: Variable {
t: BNVariableSourceType::RegisterVariableSourceType,
t: VariableSourceType::RegisterVariableSourceType,
index: 0,
storage: reg,
},
Expand Down Expand Up @@ -1654,7 +1653,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
type_: self.lookup_type_conf(&data.type_index, false)?,
storage: vec![ParsedLocation {
location: Variable {
t: BNVariableSourceType::StackVariableSourceType,
t: VariableSourceType::StackVariableSourceType,
index: 0,
storage: data.offset as i64,
},
Expand Down Expand Up @@ -1696,14 +1695,14 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
for loc in &new_storage {
match loc {
Variable {
t: BNVariableSourceType::RegisterVariableSourceType,
t: VariableSourceType::RegisterVariableSourceType,
..
} => {
// Assume register vars are always parameters
really_is_param = true;
}
Variable {
t: BNVariableSourceType::StackVariableSourceType,
t: VariableSourceType::StackVariableSourceType,
storage,
..
} if *storage >= 0 => {
Expand Down
9 changes: 5 additions & 4 deletions rust/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub type MemberAccess = BNMemberAccess;
pub type MemberScope = BNMemberScope;
pub type ILBranchDependence = BNILBranchDependence;
pub type DataFlowQueryOption = BNDataFlowQueryOption;
pub type VariableSourceType = BNVariableSourceType;

////////////////
// Confidence
Expand Down Expand Up @@ -1378,9 +1379,9 @@ impl FunctionParameter {

pub(crate) fn from_raw(member: BNFunctionParameter) -> Self {
let name = if member.name.is_null() {
if member.location.type_ == BNVariableSourceType::RegisterVariableSourceType {
if member.location.type_ == VariableSourceType::RegisterVariableSourceType {
format!("reg_{}", member.location.storage)
} else if member.location.type_ == BNVariableSourceType::StackVariableSourceType {
} else if member.location.type_ == VariableSourceType::StackVariableSourceType {
format!("arg_{}", member.location.storage)
} else {
String::new()
Expand Down Expand Up @@ -1412,13 +1413,13 @@ impl FunctionParameter {

#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
pub struct Variable {
pub t: BNVariableSourceType,
pub t: VariableSourceType,
pub index: u32,
pub storage: i64,
}

impl Variable {
pub fn new(t: BNVariableSourceType, index: u32, storage: i64) -> Self {
pub fn new(t: VariableSourceType, index: u32, storage: i64) -> Self {
Self { t, index, storage }
}

Expand Down

0 comments on commit 75a2781

Please sign in to comment.