Skip to content

Commit 4c278a5

Browse files
committed
Changes related to display as/type toggling.
1 parent 6a1c332 commit 4c278a5

13 files changed

Lines changed: 64 additions & 3 deletions

File tree

binaryninjaapi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11217,6 +11217,7 @@ namespace BinaryNinja {
1121711217
Confidence<bool> IsConst() const;
1121811218
Confidence<bool> IsVolatile() const;
1121911219
bool IsSystemCall() const;
11220+
BNIntegerDisplayType GetIntegerTypeDisplayType() const;
1122011221
void SetIntegerTypeDisplayType(BNIntegerDisplayType displayType);
1122111222

1122211223
Confidence<Ref<Type>> GetChildType() const;

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+
- `0` toggles integer display between hexadecimal and decimal, which is `H` in IDA
4748

4849
## Cross-References
4950

docs/guide/types/basictypes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ the name of a type will take you to its definition.
112112
* **Type > Make 16-bit Integer** - Create `uint16_t` members in selection
113113
* **Type > Make 32-bit Integer** - Create `uint32_t` members in selection
114114
* **Type > Make 64-bit Integer** - Create `uint64_t` members in selection
115-
* **Type > Invert Integer Sign** - Toggle integer signedness, e.g. between `uint8_t` and `int8_t`
115+
* **Type > Toggle Integer Signedness** - Toggle integer signedness, e.g. between `uint8_t` and `int8_t`
116116
* **Type > Cycle Integer Size** - Change integer member size in order: `uint8_t`, `uint16_t`, `uint32_t`, `uint64_t`
117117
* **Type > Make 32-bit Float** - Create `float` members in selection
118118
* **Type > Make 64-bit Float** - Create `double` members in selection

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: 13 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 {
@@ -189,6 +194,10 @@ impl TypeBuilder {
189194
unsafe { BNIsTypeBuilderSigned(self.handle).into() }
190195
}
191196

197+
pub fn integer_display_type(&self) -> IntegerDisplayType {
198+
self.finalize().integer_display_type()
199+
}
200+
192201
pub fn is_const(&self) -> Conf<bool> {
193202
unsafe { BNIsTypeBuilderConst(self.handle).into() }
194203
}
@@ -689,6 +698,10 @@ impl Type {
689698
unsafe { BNIsTypeSigned(self.handle).into() }
690699
}
691700

701+
pub fn integer_display_type(&self) -> IntegerDisplayType {
702+
unsafe { BNGetIntegerTypeDisplayType(self.handle) }
703+
}
704+
692705
pub fn is_const(&self) -> Conf<bool> {
693706
unsafe { BNIsTypeConst(self.handle).into() }
694707
}

type.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,15 @@ Confidence<bool> TypeBuilder::IsVolatile() const
15981598
}
15991599

16001600

1601+
BNIntegerDisplayType TypeBuilder::GetIntegerTypeDisplayType() const
1602+
{
1603+
BNType* type = BNFinalizeTypeBuilder(m_object);
1604+
BNIntegerDisplayType result = BNGetIntegerTypeDisplayType(type);
1605+
BNFreeType(type);
1606+
return result;
1607+
}
1608+
1609+
16011610
void TypeBuilder::SetIntegerTypeDisplayType(BNIntegerDisplayType displayType)
16021611
{
16031612
BNSetIntegerTypeDisplayType(m_object, displayType);
@@ -3442,4 +3451,3 @@ fmt::format_context::iterator fmt::formatter<BinaryNinja::Type>::format(
34423451
return fmt::format_to(ctx.out(), "{}{}", obj.GetStringBeforeName(), obj.GetStringAfterName());
34433452
}
34443453
}
3445-

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();

0 commit comments

Comments
 (0)