diff options
| author | KyleMiles <krm504@nyu.edu> | 2022-08-16 11:46:55 -0400 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2022-08-16 11:52:00 -0400 |
| commit | 6b1078bd7e59eb35536b4147bb7134fd3cc68884 (patch) | |
| tree | 99365bd4916dfb239c57e340176e6e68be59c9dc /rust/src | |
| parent | dbaead2b359db5ee86118cc6bbca4c440b35a89b (diff) | |
Rust API : Implement more of the core enum `InstructionTextTokenType` in `InstructionTextTokenContents`; Fix some functions in types.rs not following the `T:
Into<Conf<...>>` convention
Diffstat (limited to 'rust/src')
| -rw-r--r-- | rust/src/disassembly.rs | 62 | ||||
| -rw-r--r-- | rust/src/types.rs | 17 |
2 files changed, 72 insertions, 7 deletions
diff --git a/rust/src/disassembly.rs b/rust/src/disassembly.rs index 82ca60dd..9f86a72b 100644 --- a/rust/src/disassembly.rs +++ b/rust/src/disassembly.rs @@ -28,6 +28,50 @@ use std::ptr; pub type InstructionTextTokenType = BNInstructionTextTokenType; pub type InstructionTextTokenContext = BNInstructionTextTokenContext; +// InstructionTextTokenType's; * = Implemented +// *TextToken = 0, +// *InstructionToken = 1, +// *OperandSeparatorToken = 2, +// *RegisterToken = 3, +// *IntegerToken = 4, +// *PossibleAddressToken = 5, +// *BeginMemoryOperandToken = 6, +// *EndMemoryOperandToken = 7, +// *FloatingPointToken = 8, +// AnnotationToken = 9, +// *CodeRelativeAddressToken = 10, +// ArgumentNameToken = 11, +// HexDumpByteValueToken = 12, +// HexDumpSkippedByteToken = 13, +// HexDumpInvalidByteToken = 14, +// HexDumpTextToken = 15, +// OpcodeToken = 16, +// *StringToken = 17, +// CharacterConstantToken = 18, +// *KeywordToken = 19, +// *TypeNameToken = 20, +// *FieldNameToken = 21, +// *NameSpaceToken = 22, +// NameSpaceSeparatorToken = 23, +// TagToken = 24, +// StructOffsetToken = 25, +// StructOffsetByteValueToken = 26, +// StructureHexDumpTextToken = 27, +// *GotoLabelToken = 28, +// CommentToken = 29, +// PossibleValueToken = 30, +// PossibleValueTypeToken = 31, +// ArrayIndexToken = 32, +// *IndentationToken = 33, +// UnknownMemoryToken = 34, +// CodeSymbolToken = 64, +// DataSymbolToken = 65, +// LocalVariableToken = 66, +// ImportToken = 67, +// AddressDisplayToken = 68, +// IndirectImportToken = 69, +// ExternalSymbolToken = 70, + #[repr(C)] pub struct InstructionTextToken(pub(crate) BNInstructionTextToken); @@ -43,6 +87,13 @@ pub enum InstructionTextTokenContents { EndMemoryOperand, FloatingPoint, CodeRelativeAddress(u64), + String(u64), + Keyword, + TypeName, + FieldName, + NameSpace, + GotoLabel(u64), + Indentation, } impl InstructionTextToken { @@ -54,7 +105,9 @@ impl InstructionTextToken { let (value, address) = match contents { InstructionTextTokenContents::Integer(v) => (v, 0), InstructionTextTokenContents::PossibleAddress(v) - | InstructionTextTokenContents::CodeRelativeAddress(v) => (v, v), + | InstructionTextTokenContents::CodeRelativeAddress(v) + | InstructionTextTokenContents::GotoLabel(v) => (v, v), + InstructionTextTokenContents::String(v) => (v, 0), _ => (0, 0), }; @@ -81,6 +134,13 @@ impl InstructionTextToken { InstructionTextTokenContents::CodeRelativeAddress(_) => { InstructionTextTokenType::CodeRelativeAddressToken } + InstructionTextTokenContents::String(_) => InstructionTextTokenType::StringToken, + InstructionTextTokenContents::Keyword => InstructionTextTokenType::KeywordToken, + InstructionTextTokenContents::TypeName => InstructionTextTokenType::TypeNameToken, + InstructionTextTokenContents::FieldName => InstructionTextTokenType::FieldNameToken, + InstructionTextTokenContents::NameSpace => InstructionTextTokenType::NameSpaceToken, + InstructionTextTokenContents::GotoLabel(_) => InstructionTextTokenType::GotoLabelToken, + InstructionTextTokenContents::Indentation => InstructionTextTokenType::IndentationToken, }; let width = text.len() as u64; diff --git a/rust/src/types.rs b/rust/src/types.rs index 9648f300..34b1e597 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -395,7 +395,11 @@ impl TypeBuilder { unsafe { Self::from_raw(BNCreateArrayTypeBuilder(&t.into().into(), count)) } } - pub fn enumeration(enumeration: &Enumeration, width: usize, is_signed: Conf<bool>) -> Self { + pub fn enumeration<T: Into<Conf<bool>>>( + enumeration: &Enumeration, + width: usize, + is_signed: T, + ) -> Self { //! The C/C++ APIs require an associated architecture, but in the core we only query the default_int_size if the given width is 0 //! For simplicity's sake, that convention isn't followed and you can query the default_int_size from an arch, if you have it, if you need to @@ -406,7 +410,7 @@ impl TypeBuilder { &mut fake_arch, enumeration.handle, width, - &mut is_signed.into(), + &mut is_signed.into().into(), )) } } @@ -630,7 +634,8 @@ impl Type { pub fn parameters(&self) -> Result<Vec<FunctionParameter<BnString>>> { unsafe { let mut count: usize = mem::zeroed(); - let parameters_raw: *mut BNFunctionParameter = BNGetTypeParameters(self.handle, &mut count); + let parameters_raw: *mut BNFunctionParameter = + BNGetTypeParameters(self.handle, &mut count); if parameters_raw.is_null() { Err(()) } else { @@ -764,10 +769,10 @@ impl Type { unsafe { Self::ref_from_raw(BNCreateArrayType(&t.into().into(), count)) } } - pub fn enumeration( + pub fn enumeration<T: Into<Conf<bool>>>( enumeration: &Enumeration, width: usize, - is_signed: Conf<bool>, + is_signed: T, ) -> Ref<Self> { //! The C/C++ APIs require an associated architecture, but in the core we only query the default_int_size if the given width is 0 //! For simplicity's sake, that convention isn't followed and you can query the default_int_size from an arch, if you have it, if you need to @@ -778,7 +783,7 @@ impl Type { &mut fake_arch, enumeration.handle, width, - &mut is_signed.into(), + &mut is_signed.into().into(), )) } } |
