diff options
| -rw-r--r-- | binaryninjaapi.h | 1 | ||||
| -rw-r--r-- | binaryninjacore.h | 2 | ||||
| -rw-r--r-- | docs/guide/migration/migrationguideida.md | 1 | ||||
| -rw-r--r-- | docs/guide/types/basictypes.md | 2 | ||||
| -rw-r--r-- | docs/guide/types/type.md | 2 | ||||
| -rw-r--r-- | python/function.py | 11 | ||||
| -rw-r--r-- | python/types.py | 16 | ||||
| -rw-r--r-- | rust/src/types.rs | 13 | ||||
| -rw-r--r-- | type.cpp | 10 | ||||
| -rw-r--r-- | ui/linearview.h | 1 | ||||
| -rw-r--r-- | ui/tokenizedtextview.h | 1 | ||||
| -rw-r--r-- | ui/util.h | 6 | ||||
| -rw-r--r-- | ui/viewframe.h | 1 |
13 files changed, 64 insertions, 3 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 504c591c..d9e1efc0 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -11217,6 +11217,7 @@ namespace BinaryNinja { Confidence<bool> IsConst() const; Confidence<bool> IsVolatile() const; bool IsSystemCall() const; + BNIntegerDisplayType GetIntegerTypeDisplayType() const; void SetIntegerTypeDisplayType(BNIntegerDisplayType displayType); Confidence<Ref<Type>> GetChildType() const; diff --git a/binaryninjacore.h b/binaryninjacore.h index b3c3e8e0..bb85b11c 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -1097,6 +1097,8 @@ extern "C" DoubleDisplayType, EnumerationDisplayType, InvertedCharacterConstantDisplayType, + UnsignedComplementDecimalDisplayType, + UnsignedComplementHexadecimalDisplayType, }; BN_ENUM(uint8_t, BNFlowGraphOption) diff --git a/docs/guide/migration/migrationguideida.md b/docs/guide/migration/migrationguideida.md index 083d545e..b93cd5db 100644 --- a/docs/guide/migration/migrationguideida.md +++ b/docs/guide/migration/migrationguideida.md @@ -44,6 +44,7 @@ Some major exceptions are: - `T` for Types - `H` to toggle to/from Hex View - `[TAB]` to toggle to/from disassembly +- `0` toggles integer display between hexadecimal and decimal, which is `H` in IDA ## Cross-References diff --git a/docs/guide/types/basictypes.md b/docs/guide/types/basictypes.md index dcfd36f6..0687c2f0 100644 --- a/docs/guide/types/basictypes.md +++ b/docs/guide/types/basictypes.md @@ -112,7 +112,7 @@ the name of a type will take you to its definition. * **Type > Make 16-bit Integer** - Create `uint16_t` members in selection * **Type > Make 32-bit Integer** - Create `uint32_t` members in selection * **Type > Make 64-bit Integer** - Create `uint64_t` members in selection - * **Type > Invert Integer Sign** - Toggle integer signedness, e.g. between `uint8_t` and `int8_t` + * **Type > Toggle Integer Signedness** - Toggle integer signedness, e.g. between `uint8_t` and `int8_t` * **Type > Cycle Integer Size** - Change integer member size in order: `uint8_t`, `uint16_t`, `uint32_t`, `uint64_t` * **Type > Make 32-bit Float** - Create `float` members in selection * **Type > Make 64-bit Float** - Create `double` members in selection diff --git a/docs/guide/types/type.md b/docs/guide/types/type.md index 9b0306b4..c375433c 100644 --- a/docs/guide/types/type.md +++ b/docs/guide/types/type.md @@ -9,6 +9,8 @@ The simplest way to directly manipulate types in disassembly is by viewing an ex - `1`, `2`, `4`, `8`: The number hotkeys will create a data variable at the current location if none exists, and then change the size of the variable to an integer in the size of bytes specified in the hotkey. - `d`: If you want to cycle through the different integer sizes, repeatedly pressing `d` has the same effect as pressing the numbers in order. - `-`: To quickly toggle integers between signed and unsigned integers, you can use the `-` hotkey. + - `0`: To quickly toggle integer display between hexadecimal and decimal, you can use the `0` hotkey. + - `~`: To quickly toggle integer display between normal and bitwise complement, you can use the `~` hotkey. - `a`: This hotkey sets or creates the current variable to a character array up until and including the next null byte. - `o`: `o` will set or create the current variable to be a pointer reference. - `*`: If you have a selection of identical variables, `*` will convert them into an array of elements. If you have no selection, the "Create Array" dialog will be shown allowing you to create an array of specific type and count at the current location. diff --git a/python/function.py b/python/function.py index b2c3ef4c..9f5e89bb 100644 --- a/python/function.py +++ b/python/function.py @@ -4181,6 +4181,17 @@ class DisassemblyTextRenderer: def is_integer_token(token: 'InstructionTextToken') -> bool: return core.BNIsIntegerToken(token.type) + @staticmethod + def get_display_string_for_integer( + binary_view: Optional['binaryview.BinaryView'], display_type: IntegerDisplayType, value: int, input_width: int, + is_signed: bool = True + ) -> str: + if isinstance(display_type, str): + display_type = IntegerDisplayType[display_type] + return core.BNGetDisplayStringForInteger( + binary_view.handle if binary_view is not None else None, display_type, value, input_width, is_signed + ) + def add_integer_token( self, tokens: List['InstructionTextToken'], int_token: 'InstructionTextToken', addr: int, arch: Optional['architecture.Architecture'] = None diff --git a/python/types.py b/python/types.py index b47d98ce..80c70e14 100644 --- a/python/types.py +++ b/python/types.py @@ -32,7 +32,7 @@ from .enums import ( TypeReferenceType, MemberAccess, MemberScope, TypeDefinitionLineType, TokenEscapingType, NameType, PointerSuffix, PointerBaseType, - Endianness + Endianness, IntegerDisplayType ) from . import callingconvention from . import function as _function @@ -904,6 +904,15 @@ class TypeBuilder: core.BNTypeBuilderSetSigned(self._handle, _value) @property + def display_type(self) -> IntegerDisplayType: + """Integer display type for this type.""" + return core.BNGetIntegerTypeDisplayType(self.immutable_copy().handle) + + @display_type.setter + def display_type(self, value: IntegerDisplayType) -> None: + core.BNSetIntegerTypeDisplayType(self._handle, value) + + @property def children(self) -> List['TypeBuilder']: return [] @@ -2145,6 +2154,11 @@ class Type: core.BNFreeTypeAttributeList(attributes, count.value) return result + @property + def display_type(self) -> IntegerDisplayType: + """Integer display type for this type.""" + return core.BNGetIntegerTypeDisplayType(self._handle) + def _to_core_struct(self) -> core.BNTypeWithConfidence: type_conf = core.BNTypeWithConfidence() type_conf.type = self._handle diff --git a/rust/src/types.rs b/rust/src/types.rs index f45d93bc..e6c16f6b 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -171,6 +171,11 @@ impl TypeBuilder { self } + pub fn set_integer_display_type(&self, display_type: IntegerDisplayType) -> &Self { + unsafe { BNSetIntegerTypeDisplayType(self.handle, display_type) }; + self + } + // Readable properties pub fn type_class(&self) -> TypeClass { @@ -189,6 +194,10 @@ impl TypeBuilder { unsafe { BNIsTypeBuilderSigned(self.handle).into() } } + pub fn integer_display_type(&self) -> IntegerDisplayType { + self.finalize().integer_display_type() + } + pub fn is_const(&self) -> Conf<bool> { unsafe { BNIsTypeBuilderConst(self.handle).into() } } @@ -689,6 +698,10 @@ impl Type { unsafe { BNIsTypeSigned(self.handle).into() } } + pub fn integer_display_type(&self) -> IntegerDisplayType { + unsafe { BNGetIntegerTypeDisplayType(self.handle) } + } + pub fn is_const(&self) -> Conf<bool> { unsafe { BNIsTypeConst(self.handle).into() } } @@ -1598,6 +1598,15 @@ Confidence<bool> TypeBuilder::IsVolatile() const } +BNIntegerDisplayType TypeBuilder::GetIntegerTypeDisplayType() const +{ + BNType* type = BNFinalizeTypeBuilder(m_object); + BNIntegerDisplayType result = BNGetIntegerTypeDisplayType(type); + BNFreeType(type); + return result; +} + + void TypeBuilder::SetIntegerTypeDisplayType(BNIntegerDisplayType displayType) { BNSetIntegerTypeDisplayType(m_object, displayType); @@ -3442,4 +3451,3 @@ fmt::format_context::iterator fmt::formatter<BinaryNinja::Type>::format( return fmt::format_to(ctx.out(), "{}{}", obj.GetStringBeforeName(), obj.GetStringAfterName()); } } - diff --git a/ui/linearview.h b/ui/linearview.h index 95abdd8c..d0036aaf 100644 --- a/ui/linearview.h +++ b/ui/linearview.h @@ -399,6 +399,7 @@ private Q_SLOTS: void makeString(size_t charSize = 1); void changeType(const UIActionContext& context); void undefineInRange(); + BNIntegerDisplayType getCurrentDisplayAs(const UIActionContext& context) override; void displayAs(const UIActionContext& context, BNIntegerDisplayType displayType) override; void createStructOrInferStructureType(); bool autoCreateArray(); diff --git a/ui/tokenizedtextview.h b/ui/tokenizedtextview.h index 0843d27a..d328c492 100644 --- a/ui/tokenizedtextview.h +++ b/ui/tokenizedtextview.h @@ -150,6 +150,7 @@ class BINARYNINJAUIAPI TokenizedTextView : virtual BinaryNinja::Ref<HistoryEntry> getHistoryEntry() override; void populateDefaultHistoryEntry(TokenizedTextViewHistoryEntry* entry); virtual void navigateToHistoryEntry(BinaryNinja::Ref<HistoryEntry> entry) override; + virtual bool canDisplayAs(const UIActionContext& context, const BNIntegerDisplayType displayType) override; virtual void OnBinaryDataWritten(BinaryNinja::BinaryView* data, uint64_t offset, size_t len) override; virtual void OnBinaryDataInserted(BinaryNinja::BinaryView* data, uint64_t offset, size_t len) override; @@ -22,7 +22,13 @@ std::string BINARYNINJAUIAPI getStringForRegisterValue(ArchitectureRef arch, Bin std::string BINARYNINJAUIAPI getPossibleValueSetStateName(BNRegisterValueType state); std::string BINARYNINJAUIAPI getStringForIntegerValue(int64_t value); std::string BINARYNINJAUIAPI getStringForUIntegerValue(uint64_t value); +bool BINARYNINJAUIAPI canDisplayIntegerTokenAs(const HighlightTokenState& token, BNIntegerDisplayType displayType); BNIntegerDisplayType BINARYNINJAUIAPI getInvertedIntegerDisplayType(BNIntegerDisplayType displayType, const std::string& text); +BNIntegerDisplayType BINARYNINJAUIAPI getToggledIntegerRadixDisplayType(BNIntegerDisplayType displayType, const std::string& text); +BNIntegerDisplayType BINARYNINJAUIAPI getToggledIntegerComplementDisplayType(BNIntegerDisplayType displayType, const std::string& text); +TypeRef BINARYNINJAUIAPI getIntegerTypePreservingDisplay(TypeRef type, size_t width, BinaryNinja::Confidence<bool> isSigned); +TypeRef BINARYNINJAUIAPI getIntegerTypeWithWidthPreservingAttributes(TypeRef type, size_t width); +TypeRef BINARYNINJAUIAPI getIntegerTypeWithSignPreservingAttributes(TypeRef type, BinaryNinja::Confidence<bool> isSigned); std::string BINARYNINJAUIAPI getStringForPossibleValueSet(ArchitectureRef arch, const BinaryNinja::PossibleValueSet& values, bool pretty = true); std::string BINARYNINJAUIAPI getStringForInstructionDataflowDetails(BinaryViewRef data, ArchitectureRef arch, FunctionRef func, uint64_t address); std::optional<BinaryNinja::PossibleValueSet> BINARYNINJAUIAPI getPossibleValueSetForToken(View* view, BinaryViewRef data, ArchitectureRef arch, diff --git a/ui/viewframe.h b/ui/viewframe.h index 08d4add6..3812afc0 100644 --- a/ui/viewframe.h +++ b/ui/viewframe.h @@ -210,6 +210,7 @@ class BINARYNINJAUIAPI View virtual void writeData(const BinaryNinja::DataBuffer& data, uint64_t addr); virtual bool canDisplayAs(const UIActionContext& context, const BNIntegerDisplayType); + virtual BNIntegerDisplayType getCurrentDisplayAs(const UIActionContext& context); virtual void displayAs(const UIActionContext& context, BNIntegerDisplayType type); virtual BinaryNinja::Ref<HistoryEntry> getHistoryEntry(); |
