Skip to content

Commit 55fd743

Browse files
committed
Changes related to display as/type toggling.
1 parent c097ec9 commit 55fd743

10 files changed

Lines changed: 49 additions & 1 deletion

File tree

binaryninjacore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,8 @@ extern "C"
10971097
DoubleDisplayType,
10981098
EnumerationDisplayType,
10991099
InvertedCharacterConstantDisplayType,
1100+
UnsignedComplementDecimalDisplayType,
1101+
UnsignedComplementHexadecimalDisplayType,
11001102
};
11011103

11021104
BN_ENUM(uint8_t, BNFlowGraphOption)

docs/guide/migration/migrationguideida.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Some major exceptions are:
4444
- `T` for Types
4545
- `H` to toggle to/from Hex View
4646
- `[TAB]` to toggle to/from disassembly
47+
- IDA's `H` hotkey toggles integer display between hexadecimal and decimal. In Binary Ninja, `H` opens the Hex View and `0` toggles integer display between hexadecimal and decimal.
4748

4849
## Cross-References
4950

docs/guide/types/type.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ The simplest way to directly manipulate types in disassembly is by viewing an ex
99
- `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.
1010
- `d`: If you want to cycle through the different integer sizes, repeatedly pressing `d` has the same effect as pressing the numbers in order.
1111
- `-`: To quickly toggle integers between signed and unsigned integers, you can use the `-` hotkey.
12+
- `0`: To quickly toggle integer display between hexadecimal and decimal, you can use the `0` hotkey.
13+
- `~`: To quickly toggle integer display between normal and bitwise complement, you can use the `~` hotkey.
1214
- `a`: This hotkey sets or creates the current variable to a character array up until and including the next null byte.
1315
- `o`: `o` will set or create the current variable to be a pointer reference.
1416
- `*`: 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.

python/function.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4181,6 +4181,17 @@ def add_stack_var_reference_tokens(
41814181
def is_integer_token(token: 'InstructionTextToken') -> bool:
41824182
return core.BNIsIntegerToken(token.type)
41834183

4184+
@staticmethod
4185+
def get_display_string_for_integer(
4186+
binary_view: Optional['binaryview.BinaryView'], display_type: IntegerDisplayType, value: int, input_width: int,
4187+
is_signed: bool = True
4188+
) -> str:
4189+
if isinstance(display_type, str):
4190+
display_type = IntegerDisplayType[display_type]
4191+
return core.BNGetDisplayStringForInteger(
4192+
binary_view.handle if binary_view is not None else None, display_type, value, input_width, is_signed
4193+
)
4194+
41844195
def add_integer_token(
41854196
self, tokens: List['InstructionTextToken'], int_token: 'InstructionTextToken', addr: int,
41864197
arch: Optional['architecture.Architecture'] = None

python/types.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
TypeReferenceType, MemberAccess, MemberScope, TypeDefinitionLineType,
3333
TokenEscapingType,
3434
NameType, PointerSuffix, PointerBaseType,
35-
Endianness
35+
Endianness, IntegerDisplayType
3636
)
3737
from . import callingconvention
3838
from . import function as _function
@@ -903,6 +903,15 @@ def signed(self, value: BoolWithConfidenceType) -> None:
903903
_value = BoolWithConfidence.get_core_struct(value)
904904
core.BNTypeBuilderSetSigned(self._handle, _value)
905905

906+
@property
907+
def display_type(self) -> IntegerDisplayType:
908+
"""Integer display type for this type."""
909+
return core.BNGetIntegerTypeDisplayType(self.immutable_copy().handle)
910+
911+
@display_type.setter
912+
def display_type(self, value: IntegerDisplayType) -> None:
913+
core.BNSetIntegerTypeDisplayType(self._handle, value)
914+
906915
@property
907916
def children(self) -> List['TypeBuilder']:
908917
return []
@@ -2145,6 +2154,11 @@ def attributes(self) -> Dict[str, str]:
21452154
core.BNFreeTypeAttributeList(attributes, count.value)
21462155
return result
21472156

2157+
@property
2158+
def display_type(self) -> IntegerDisplayType:
2159+
"""Integer display type for this type."""
2160+
return core.BNGetIntegerTypeDisplayType(self._handle)
2161+
21482162
def _to_core_struct(self) -> core.BNTypeWithConfidence:
21492163
type_conf = core.BNTypeWithConfidence()
21502164
type_conf.type = self._handle

rust/src/types.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ impl TypeBuilder {
171171
self
172172
}
173173

174+
pub fn set_integer_display_type(&self, display_type: IntegerDisplayType) -> &Self {
175+
unsafe { BNSetIntegerTypeDisplayType(self.handle, display_type) };
176+
self
177+
}
178+
174179
// Readable properties
175180

176181
pub fn type_class(&self) -> TypeClass {
@@ -689,6 +694,10 @@ impl Type {
689694
unsafe { BNIsTypeSigned(self.handle).into() }
690695
}
691696

697+
pub fn integer_display_type(&self) -> IntegerDisplayType {
698+
unsafe { BNGetIntegerTypeDisplayType(self.handle) }
699+
}
700+
692701
pub fn is_const(&self) -> Conf<bool> {
693702
unsafe { BNIsTypeConst(self.handle).into() }
694703
}

ui/linearview.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ private Q_SLOTS:
399399
void makeString(size_t charSize = 1);
400400
void changeType(const UIActionContext& context);
401401
void undefineInRange();
402+
BNIntegerDisplayType getCurrentDisplayAs(const UIActionContext& context) override;
402403
void displayAs(const UIActionContext& context, BNIntegerDisplayType displayType) override;
403404
void createStructOrInferStructureType();
404405
bool autoCreateArray();

ui/tokenizedtextview.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class BINARYNINJAUIAPI TokenizedTextView :
150150
virtual BinaryNinja::Ref<HistoryEntry> getHistoryEntry() override;
151151
void populateDefaultHistoryEntry(TokenizedTextViewHistoryEntry* entry);
152152
virtual void navigateToHistoryEntry(BinaryNinja::Ref<HistoryEntry> entry) override;
153+
virtual bool canDisplayAs(const UIActionContext& context, const BNIntegerDisplayType displayType) override;
153154

154155
virtual void OnBinaryDataWritten(BinaryNinja::BinaryView* data, uint64_t offset, size_t len) override;
155156
virtual void OnBinaryDataInserted(BinaryNinja::BinaryView* data, uint64_t offset, size_t len) override;

ui/util.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ std::string BINARYNINJAUIAPI getStringForRegisterValue(ArchitectureRef arch, Bin
2222
std::string BINARYNINJAUIAPI getPossibleValueSetStateName(BNRegisterValueType state);
2323
std::string BINARYNINJAUIAPI getStringForIntegerValue(int64_t value);
2424
std::string BINARYNINJAUIAPI getStringForUIntegerValue(uint64_t value);
25+
bool BINARYNINJAUIAPI canDisplayIntegerTokenAs(const HighlightTokenState& token, BNIntegerDisplayType displayType);
2526
BNIntegerDisplayType BINARYNINJAUIAPI getInvertedIntegerDisplayType(BNIntegerDisplayType displayType, const std::string& text);
27+
BNIntegerDisplayType BINARYNINJAUIAPI getToggledIntegerRadixDisplayType(BNIntegerDisplayType displayType, const std::string& text);
28+
BNIntegerDisplayType BINARYNINJAUIAPI getToggledIntegerComplementDisplayType(BNIntegerDisplayType displayType, const std::string& text);
29+
TypeRef BINARYNINJAUIAPI getIntegerTypePreservingDisplay(TypeRef type, size_t width, BinaryNinja::Confidence<bool> isSigned);
30+
TypeRef BINARYNINJAUIAPI getIntegerTypeWithWidthPreservingAttributes(TypeRef type, size_t width);
31+
TypeRef BINARYNINJAUIAPI getIntegerTypeWithSignPreservingAttributes(TypeRef type, BinaryNinja::Confidence<bool> isSigned);
2632
std::string BINARYNINJAUIAPI getStringForPossibleValueSet(ArchitectureRef arch, const BinaryNinja::PossibleValueSet& values, bool pretty = true);
2733
std::string BINARYNINJAUIAPI getStringForInstructionDataflowDetails(BinaryViewRef data, ArchitectureRef arch, FunctionRef func, uint64_t address);
2834
std::optional<BinaryNinja::PossibleValueSet> BINARYNINJAUIAPI getPossibleValueSetForToken(View* view, BinaryViewRef data, ArchitectureRef arch,

ui/viewframe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ class BINARYNINJAUIAPI View
210210
virtual void writeData(const BinaryNinja::DataBuffer& data, uint64_t addr);
211211

212212
virtual bool canDisplayAs(const UIActionContext& context, const BNIntegerDisplayType);
213+
virtual BNIntegerDisplayType getCurrentDisplayAs(const UIActionContext& context);
213214
virtual void displayAs(const UIActionContext& context, BNIntegerDisplayType type);
214215

215216
virtual BinaryNinja::Ref<HistoryEntry> getHistoryEntry();

0 commit comments

Comments
 (0)