Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VariableSourceType type alias #5784

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading