Skip to content
Open
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
28 changes: 19 additions & 9 deletions rust/src/disassembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ use std::fmt::{Display, Formatter};
use std::ptr;
use std::ptr::NonNull;

const INVALID_OPERAND: usize = 0xffffffff;

pub type DisassemblyOption = BNDisassemblyOption;
pub type InstructionTextTokenType = BNInstructionTextTokenType;

Expand Down Expand Up @@ -612,15 +614,15 @@ impl InstructionTextTokenKind {
0 => None,
size => Some(size),
},
operand: Some(value.operand),
operand: (value.operand != INVALID_OPERAND).then_some(value.operand),
},
BNInstructionTextTokenType::PossibleAddressToken => Self::PossibleAddress {
value: value.value,
size: match value.size {
0 => None,
size => Some(size),
},
operand: Some(value.operand),
operand: (value.operand != INVALID_OPERAND).then_some(value.operand),
},
BNInstructionTextTokenType::BeginMemoryOperandToken => Self::BeginMemoryOperand,
BNInstructionTextTokenType::EndMemoryOperandToken => Self::EndMemoryOperand,
Expand All @@ -638,7 +640,7 @@ impl InstructionTextTokenKind {
0 => None,
size => Some(size),
},
operand: Some(value.operand),
operand: (value.operand != INVALID_OPERAND).then_some(value.operand),
},
BNInstructionTextTokenType::ArgumentNameToken => {
Self::ArgumentName { value: value.value }
Expand Down Expand Up @@ -677,7 +679,7 @@ impl InstructionTextTokenKind {
_ => Self::String { value: value.value },
},
BNInstructionTextTokenType::CharacterConstantToken => Self::CharacterConstant {
operand: Some(value.operand),
operand: (value.operand != INVALID_OPERAND).then_some(value.operand),
},
BNInstructionTextTokenType::KeywordToken => Self::Keyword { value: value.value },
BNInstructionTextTokenType::TypeNameToken => Self::TypeName,
Expand Down Expand Up @@ -837,10 +839,18 @@ impl InstructionTextTokenKind {
/// Mapping to the [`BNInstructionTextTokenType::operand`] field.
fn try_operand(&self) -> Option<usize> {
match self {
InstructionTextTokenKind::Integer { operand, .. } => *operand,
InstructionTextTokenKind::PossibleAddress { operand, .. } => *operand,
InstructionTextTokenKind::CodeRelativeAddress { operand, .. } => *operand,
InstructionTextTokenKind::CharacterConstant { operand, .. } => *operand,
InstructionTextTokenKind::Integer { operand, .. } => {
Some(operand.unwrap_or(INVALID_OPERAND))
}
InstructionTextTokenKind::PossibleAddress { operand, .. } => {
Some(operand.unwrap_or(INVALID_OPERAND))
}
InstructionTextTokenKind::CodeRelativeAddress { operand, .. } => {
Some(operand.unwrap_or(INVALID_OPERAND))
}
InstructionTextTokenKind::CharacterConstant { operand, .. } => {
Some(operand.unwrap_or(INVALID_OPERAND))
}
InstructionTextTokenKind::LocalVariable { ssa_version, .. } => Some(*ssa_version),
InstructionTextTokenKind::IndirectImport { source_operand, .. } => {
Some(*source_operand)
Expand Down Expand Up @@ -1262,7 +1272,7 @@ impl DisassemblyTextRenderer {
size: usize,
operand: Option<usize>,
) -> Option<Array<InstructionTextToken>> {
let operand = operand.unwrap_or(0xffffffff);
let operand = operand.unwrap_or(INVALID_OPERAND);
let mut count = 0;
let mut tokens: *mut BNInstructionTextToken = ptr::null_mut();
let result = unsafe {
Expand Down
Loading