summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-02-11 14:29:32 -0500
committerMason Reed <mason@vector35.com>2025-02-11 14:29:32 -0500
commit5fd6a9e337c848a7fcd5c5111e9eaf396cfc3ad5 (patch)
treeb35494cbcc8cfa769ceac7dfb4ba77a1a9689389 /rust/src
parent2b0afb5bb68f84fdc291ade40af31221636d58d9 (diff)
Fix Rust InstructionTextTokenKind not consulting the string token context
This caused a crash if we visited a builtin with a "fake" string. Where the token value is not actually the string type.
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/disassembly.rs43
1 files changed, 34 insertions, 9 deletions
diff --git a/rust/src/disassembly.rs b/rust/src/disassembly.rs
index d9bb8bdc..290e48d2 100644
--- a/rust/src/disassembly.rs
+++ b/rust/src/disassembly.rs
@@ -421,6 +421,14 @@ pub enum InstructionTextTokenKind {
},
Opcode,
String {
+ // TODO: What is this?
+ // TODO: It seems like people just throw things in here...
+ value: u64,
+ },
+ /// String content is only present for:
+ /// - [`InstructionTextTokenContext::StringReference`]
+ /// - [`InstructionTextTokenContext::StringDisplay`]
+ StringContent {
ty: StringType,
},
CharacterConstant,
@@ -588,14 +596,29 @@ impl InstructionTextTokenKind {
Self::HexDumpText { width: value.value }
}
BNInstructionTextTokenType::OpcodeToken => Self::Opcode,
- BNInstructionTextTokenType::StringToken => Self::String {
- ty: match value.value {
- 0 => StringType::AsciiString,
- 1 => StringType::Utf8String,
- 2 => StringType::Utf16String,
- 3 => StringType::Utf32String,
- _ => unreachable!(),
- },
+ BNInstructionTextTokenType::StringToken => match value.context {
+ BNInstructionTextTokenContext::StringReferenceTokenContext
+ | BNInstructionTextTokenContext::StringDisplayTokenContext => {
+ match value.value {
+ 0 => Self::StringContent {
+ ty: StringType::AsciiString,
+ },
+ 1 => Self::StringContent {
+ ty: StringType::Utf8String,
+ },
+ 2 => Self::StringContent {
+ ty: StringType::Utf16String,
+ },
+ 3 => Self::StringContent {
+ ty: StringType::Utf32String,
+ },
+ // If we reach here all hope is lost.
+ // Reaching here means someone made a ref or display context token with no
+ // StringType and instead some other random value...
+ value => Self::String { value },
+ }
+ }
+ _ => Self::String { value: value.value },
},
BNInstructionTextTokenType::CharacterConstantToken => Self::CharacterConstant,
BNInstructionTextTokenType::KeywordToken => Self::Keyword,
@@ -712,7 +735,8 @@ impl InstructionTextTokenKind {
InstructionTextTokenKind::ArgumentName { value, .. } => Some(*value),
InstructionTextTokenKind::HexDumpByteValue { value, .. } => Some(*value as u64),
InstructionTextTokenKind::HexDumpText { width, .. } => Some(*width),
- InstructionTextTokenKind::String { ty, .. } => Some(*ty as u64),
+ InstructionTextTokenKind::String { value, .. } => Some(*value),
+ InstructionTextTokenKind::StringContent { ty, .. } => Some(*ty as u64),
InstructionTextTokenKind::FieldName { offset, .. } => Some(*offset),
InstructionTextTokenKind::StructOffset { offset, .. } => Some(*offset),
InstructionTextTokenKind::StructureHexDumpText { width, .. } => Some(*width),
@@ -815,6 +839,7 @@ impl From<InstructionTextTokenKind> for BNInstructionTextTokenType {
}
InstructionTextTokenKind::Opcode => BNInstructionTextTokenType::OpcodeToken,
InstructionTextTokenKind::String { .. } => BNInstructionTextTokenType::StringToken,
+ InstructionTextTokenKind::StringContent { .. } => BNInstructionTextTokenType::StringToken,
InstructionTextTokenKind::CharacterConstant => {
BNInstructionTextTokenType::CharacterConstantToken
}