Skip to content

Commit 9341808

Browse files
committed
Default enable state setting
1 parent 1107976 commit 9341808

File tree

6 files changed

+45
-3
lines changed

6 files changed

+45
-3
lines changed

binaryninjaapi.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19131,6 +19131,19 @@ namespace BinaryNinja {
1913119131
*/
1913219132
std::string GetName() const;
1913319133

19134+
/*! Get whether the Render Layer is enabled by default
19135+
19136+
\return Default enable state
19137+
*/
19138+
BNRenderLayerDefaultEnableState GetDefaultEnableState() const;
19139+
19140+
/*! Set whether the Render Layer is enabled by default.
19141+
Defaults to Disabled by Default
19142+
19143+
\param state New default enable state
19144+
*/
19145+
void SetDefaultEnableState(BNRenderLayerDefaultEnableState state);
19146+
1913419147
/*! Apply this Render Layer to a single Basic Block of Disassembly lines.
1913519148
Subclasses should modify the input `lines` list to make modifications to
1913619149
the presentation of the block.

binaryninjacore.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
// Current ABI version for linking to the core. This is incremented any time
3838
// there are changes to the API that affect linking, including new functions,
3939
// new types, or modifications to existing functions or types.
40-
#define BN_CURRENT_CORE_ABI_VERSION 89
40+
#define BN_CURRENT_CORE_ABI_VERSION 90
4141

4242
// Minimum ABI version that is supported for loading of plugins. Plugins that
4343
// are linked to an ABI version less than this will not be able to load and
@@ -3580,6 +3580,13 @@ extern "C"
35803580
void (*freeLines)(void* ctxt, BNLinearDisassemblyLine* lines, size_t count);
35813581
} BNRenderLayerCallbacks;
35823582

3583+
typedef enum BNRenderLayerDefaultEnableState
3584+
{
3585+
DisabledByDefaultRenderLayerDefaultEnableState,
3586+
EnabledByDefaultRenderLayerDefaultEnableState,
3587+
AlwaysEnabledRenderLayerDefaultEnableState,
3588+
} BNRenderLayerDefaultEnableState;
3589+
35833590
BINARYNINJACOREAPI char* BNAllocString(const char* contents);
35843591
BINARYNINJACOREAPI char* BNAllocStringWithLength(const char* contents, size_t len);
35853592
BINARYNINJACOREAPI void BNFreeString(char* str);
@@ -8142,6 +8149,8 @@ extern "C"
81428149
BINARYNINJACOREAPI void BNFreeRenderLayerList(BNRenderLayer** renderLayers);
81438150
BINARYNINJACOREAPI BNRenderLayer* BNGetRenderLayerByName(const char* name);
81448151
BINARYNINJACOREAPI char* BNGetRenderLayerName(BNRenderLayer* renderLayer);
8152+
BINARYNINJACOREAPI BNRenderLayerDefaultEnableState BNGetRenderLayerDefaultEnableState(BNRenderLayer* renderLayer);
8153+
BINARYNINJACOREAPI void BNSetRenderLayerDefaultEnableState(BNRenderLayer* renderLayer, BNRenderLayerDefaultEnableState state);
81458154

81468155
BINARYNINJACOREAPI void BNApplyRenderLayerToFlowGraph(BNRenderLayer* renderLayer, BNFlowGraph* graph);
81478156
BINARYNINJACOREAPI void BNApplyRenderLayerToLinearViewObject(

plugins/stack_render_layer/plugin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ extern "C" {
101101
{
102102
static StackRenderLayer* layer = new StackRenderLayer();
103103
RenderLayer::Register(layer);
104+
layer->SetDefaultEnableState(AlwaysEnabledRenderLayerDefaultEnableState);
104105
return true;
105106
}
106107
}

python/examples/args_render_layer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
MediumLevelILCallSsa, MediumLevelILVarSsa, MediumLevelILConstBase, \
77
MediumLevelILInstruction, MediumLevelILTailcallSsa, MediumLevelILOperation, \
88
MediumLevelILVarPhi, log_debug, RenderLayer, BasicBlock, InstructionTextTokenType, FlowGraph, \
9-
LinearViewObject, LinearDisassemblyLine
9+
LinearViewObject, LinearDisassemblyLine, RenderLayerDefaultEnableState
1010

1111
"""
1212
Render Layer that shows you where the arguments to calls are set.
@@ -167,6 +167,7 @@ def apply_to_lines(lines, get_instr, renderer):
167167
comment = f"Tailcall at {llil_instr.address:#x}"
168168
else:
169169
comment = f"Call at {llil_instr.address:#x}"
170+
# Creating comments is a bit unwieldy at the moment
170171
renderer.wrap_comment(new_lines, line, comment, False, " ", "")
171172
for j, token in enumerate(line.tokens):
172173
if token.type == InstructionTextTokenType.AddressSeparatorToken:
@@ -184,12 +185,14 @@ def apply_to_lines(lines, get_instr, renderer):
184185

185186
class ArgumentsRenderLayer(RenderLayer):
186187
name = "Annotate Call Parameters"
188+
default_enable_state = RenderLayerDefaultEnableState.EnabledByDefaultRenderLayerDefaultEnableState
187189

188190
def apply_to_disassembly_block(
189191
self,
190192
block: BasicBlock,
191193
lines: List['DisassemblyTextLine']
192194
):
195+
# Break this out into a helper so we don't have to write it twice
193196
renderer = DisassemblyTextRenderer(block.function)
194197
return apply_to_lines(lines, lambda line: block.function.get_llil_at(line.address), renderer)
195198

@@ -198,6 +201,7 @@ def apply_to_low_level_il_block(
198201
block: BasicBlock,
199202
lines: List['DisassemblyTextLine']
200203
):
204+
# Break this out into a helper so we don't have to write it twice
201205
renderer = DisassemblyTextRenderer(block.function)
202206
return apply_to_lines(lines, lambda line: line.il_instruction, renderer)
203207

python/renderlayer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# Binary Ninja components
2525
import binaryninja
2626
from . import _binaryninjacore as core, LinearDisassemblyLine
27-
from .enums import LinearDisassemblyLineType
27+
from .enums import LinearDisassemblyLineType, RenderLayerDefaultEnableState
2828
from . import binaryview
2929
from . import types
3030
from .log import log_error
@@ -64,13 +64,15 @@ class RenderLayer(metaclass=_RenderLayerMetaclass):
6464
"""
6565

6666
name = None
67+
default_enable_state = RenderLayerDefaultEnableState.DisabledByDefaultRenderLayerDefaultEnableState
6768
_registered_instances = {}
6869
_pending_lines = {}
6970

7071
def __init__(self, handle=None):
7172
if handle is not None:
7273
self.handle = core.handle_of_type(handle, core.BNRenderLayer)
7374
self.__dict__["name"] = core.BNGetRenderLayerName(handle)
75+
self.__dict__["default_enable_state"] = core.BNGetRenderLayerDefaultEnableState(handle)
7476
else:
7577
self.handle = None
7678

@@ -90,6 +92,7 @@ def register(cls):
9092
layer._cb.applyToLinearViewObject = layer._cb.applyToLinearViewObject.__class__(layer._apply_to_linear_view_object)
9193
layer._cb.freeLines = layer._cb.freeLines.__class__(layer._free_lines)
9294
layer.handle = core.BNRegisterRenderLayer(layer.__class__.name, layer._cb)
95+
core.BNSetRenderLayerDefaultEnableState(layer.handle, layer.default_enable_state)
9396
handle_ptr = ctypes.cast(layer.handle, ctypes.c_void_p)
9497
cls._registered_instances[handle_ptr.value] = layer
9598

renderlayer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ Ref<RenderLayer> RenderLayer::GetByName(const std::string& name)
123123
}
124124

125125

126+
BNRenderLayerDefaultEnableState RenderLayer::GetDefaultEnableState() const
127+
{
128+
return BNGetRenderLayerDefaultEnableState(m_object);
129+
}
130+
131+
132+
void RenderLayer::SetDefaultEnableState(BNRenderLayerDefaultEnableState state)
133+
{
134+
BNSetRenderLayerDefaultEnableState(m_object, state);
135+
}
136+
137+
126138
std::string RenderLayer::GetName() const
127139
{
128140
char* name = BNGetRenderLayerName(m_object);

0 commit comments

Comments
 (0)