Skip to content

Commit f3de187

Browse files
committed
Added IsForceLoadable method to BinaryViewType
1 parent 2b3f405 commit f3de187

File tree

7 files changed

+73
-1
lines changed

7 files changed

+73
-1
lines changed

binaryninjaapi.h

+9
Original file line numberDiff line numberDiff line change
@@ -6910,6 +6910,7 @@ namespace BinaryNinja {
69106910
static BNBinaryView* ParseCallback(void* ctxt, BNBinaryView* data);
69116911
static bool IsValidCallback(void* ctxt, BNBinaryView* data);
69126912
static bool IsDeprecatedCallback(void* ctxt);
6913+
static bool IsForceLoadableCallback(void *ctxt);
69136914
static BNSettings* GetSettingsCallback(void* ctxt, BNBinaryView* data);
69146915

69156916
BinaryViewType(BNBinaryViewType* type);
@@ -7047,6 +7048,13 @@ namespace BinaryNinja {
70477048
\return Whether this BinaryViewType is valid for given data
70487049
*/
70497050
virtual bool IsTypeValidForData(BinaryView* data) = 0;
7051+
7052+
/*! Check whether this BinaryViewType can be forced to load a binary, even if IsTypeValidForData returns false
7053+
7054+
\return Whether this BinaryViewType can be forced to load a binary
7055+
*/
7056+
virtual bool IsForceLoadable();
7057+
70507058
virtual Ref<Settings> GetLoadSettingsForData(BinaryView* data);
70517059
Ref<Settings> GetDefaultLoadSettingsForData(BinaryView* data);
70527060

@@ -7069,6 +7077,7 @@ namespace BinaryNinja {
70697077
virtual Ref<BinaryView> Parse(BinaryView* data) override;
70707078
virtual bool IsTypeValidForData(BinaryView* data) override;
70717079
virtual bool IsDeprecated() override;
7080+
virtual bool IsForceLoadable() override;
70727081
virtual Ref<Settings> GetLoadSettingsForData(BinaryView* data) override;
70737082
};
70747083

binaryninjacore.h

+3-1
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 77
40+
#define BN_CURRENT_CORE_ABI_VERSION 78
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
@@ -1657,6 +1657,7 @@ extern "C"
16571657
BNBinaryView* (*parse)(void* ctxt, BNBinaryView* data);
16581658
bool (*isValidForData)(void* ctxt, BNBinaryView* data);
16591659
bool (*isDeprecated)(void* ctxt);
1660+
bool (*isForceLoadable)(void* ctxt);
16601661
BNSettings* (*getLoadSettingsForData)(void* ctxt, BNBinaryView* data);
16611662
} BNCustomBinaryViewType;
16621663

@@ -4001,6 +4002,7 @@ extern "C"
40014002
BINARYNINJACOREAPI BNBinaryView* BNCreateBinaryViewOfType(BNBinaryViewType* type, BNBinaryView* data);
40024003
BINARYNINJACOREAPI BNBinaryView* BNParseBinaryViewOfType(BNBinaryViewType* type, BNBinaryView* data);
40034004
BINARYNINJACOREAPI bool BNIsBinaryViewTypeValidForData(BNBinaryViewType* type, BNBinaryView* data);
4005+
BINARYNINJACOREAPI bool BNIsBinaryViewTypeForceLoadable(BNBinaryViewType* type);
40044006
BINARYNINJACOREAPI BNSettings* BNGetBinaryViewDefaultLoadSettingsForData(
40054007
BNBinaryViewType* type, BNBinaryView* data);
40064008
BINARYNINJACOREAPI BNSettings* BNGetBinaryViewLoadSettingsForData(BNBinaryViewType* type, BNBinaryView* data);

binaryviewtype.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ bool BinaryViewType::IsDeprecatedCallback(void* ctxt)
6161
}
6262

6363

64+
bool BinaryViewType::IsForceLoadableCallback(void* ctxt)
65+
{
66+
CallbackRef<BinaryViewType> type(ctxt);
67+
return type->IsForceLoadable();
68+
}
69+
70+
6471
BNSettings* BinaryViewType::GetSettingsCallback(void* ctxt, BNBinaryView* data)
6572
{
6673
CallbackRef<BinaryViewType> type(ctxt);
@@ -93,6 +100,7 @@ void BinaryViewType::Register(BinaryViewType* type)
93100
callbacks.parse = ParseCallback;
94101
callbacks.isValidForData = IsValidCallback;
95102
callbacks.isDeprecated = IsDeprecatedCallback;
103+
callbacks.isForceLoadable = IsForceLoadableCallback;
96104
callbacks.getLoadSettingsForData = GetSettingsCallback;
97105

98106
type->AddRefForRegistration();
@@ -247,6 +255,12 @@ bool BinaryViewType::IsDeprecated()
247255
}
248256

249257

258+
bool BinaryViewType::IsForceLoadable()
259+
{
260+
return false;
261+
}
262+
263+
250264
void BinaryViewType::RegisterBinaryViewFinalizationEvent(const function<void(BinaryView* view)>& callback)
251265
{
252266
BinaryViewEvent* event = new BinaryViewEvent;
@@ -347,6 +361,12 @@ bool CoreBinaryViewType::IsDeprecated()
347361
}
348362

349363

364+
bool CoreBinaryViewType::IsForceLoadable()
365+
{
366+
return BNIsBinaryViewTypeForceLoadable(m_object);
367+
}
368+
369+
350370
Ref<Settings> CoreBinaryViewType::GetLoadSettingsForData(BinaryView* data)
351371
{
352372
BNSettings* settings = BNGetBinaryViewLoadSettingsForData(m_object, data->GetObject());

python/binaryview.py

+17
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,11 @@ def is_deprecated(self) -> bool:
12711271
"""returns if the BinaryViewType is deprecated (read-only)"""
12721272
return core.BNIsBinaryViewTypeDeprecated(self.handle)
12731273

1274+
@property
1275+
def is_force_loadable(self) -> bool:
1276+
"""returns if the BinaryViewType is force loadable (read-only)"""
1277+
return core.BNIsBinaryViewTypeForceLoadable(self.handle)
1278+
12741279
def create(self, data: 'BinaryView') -> Optional['BinaryView']:
12751280
view = core.BNCreateBinaryViewOfType(self.handle, data.handle)
12761281
if view is None:
@@ -2511,6 +2516,7 @@ def register(cls) -> None:
25112516
cls._registered_cb.parse = cls._registered_cb.parse.__class__(cls._parse)
25122517
cls._registered_cb.isValidForData = cls._registered_cb.isValidForData.__class__(cls._is_valid_for_data)
25132518
cls._registered_cb.isDeprecated = cls._registered_cb.isDeprecated.__class__(cls._is_deprecated)
2519+
cls._registered_cb.isForceLoadable = cls._registered_cb.isForceLoadable.__class__(cls._is_force_loadable)
25142520
cls._registered_cb.getLoadSettingsForData = cls._registered_cb.getLoadSettingsForData.__class__(
25152521
cls._get_load_settings_for_data
25162522
)
@@ -2579,6 +2585,17 @@ def _is_deprecated(cls, ctxt):
25792585
log_error(traceback.format_exc())
25802586
return False
25812587

2588+
@classmethod
2589+
def _is_force_loadable(cls, ctxt):
2590+
if not callable(getattr(cls, 'is_force_loadable', None)):
2591+
return False
2592+
2593+
try:
2594+
return cls.is_force_loadable() # type: ignore
2595+
except:
2596+
log_error(traceback.format_exc())
2597+
return False
2598+
25822599
@classmethod
25832600
def _get_load_settings_for_data(cls, ctxt, data):
25842601
try:

rust/examples/minidump/src/view.rs

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ impl BinaryViewTypeBase for MinidumpBinaryViewType {
4848
false
4949
}
5050

51+
fn is_force_loadable(&self) -> bool {
52+
false
53+
}
54+
5155
fn is_valid_for(&self, data: &BinaryView) -> bool {
5256
let mut magic_number = Vec::<u8>::new();
5357
data.read_into_vec(&mut magic_number, 0, 4);

rust/src/custombinaryview.rs

+19
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ where
6868
})
6969
}
7070

71+
extern "C" fn cb_force_loadable<T>(ctxt: *mut c_void) -> bool
72+
where
73+
T: CustomBinaryViewType,
74+
{
75+
ffi_wrap!("BinaryViewTypeBase::is_force_loadable", unsafe {
76+
let view_type = &*(ctxt as *mut T);
77+
view_type.is_force_loadable()
78+
})
79+
}
80+
7181
extern "C" fn cb_create<T>(ctxt: *mut c_void, data: *mut BNBinaryView) -> *mut BNBinaryView
7282
where
7383
T: CustomBinaryViewType,
@@ -153,6 +163,7 @@ where
153163
parse: Some(cb_parse::<T>),
154164
isValidForData: Some(cb_valid::<T>),
155165
isDeprecated: Some(cb_deprecated::<T>),
166+
isForceLoadable: Some(cb_force_loadable::<T>),
156167
getLoadSettingsForData: Some(cb_load_settings::<T>),
157168
};
158169

@@ -182,6 +193,10 @@ pub trait BinaryViewTypeBase: AsRef<BinaryViewType> {
182193
false
183194
}
184195

196+
fn is_force_loadable(&self) -> bool {
197+
false
198+
}
199+
185200
fn default_load_settings_for_data(&self, data: &BinaryView) -> Option<Ref<Settings>> {
186201
let settings_handle =
187202
unsafe { BNGetBinaryViewDefaultLoadSettingsForData(self.as_ref().0, data.handle) };
@@ -296,6 +311,10 @@ impl BinaryViewTypeBase for BinaryViewType {
296311
unsafe { BNIsBinaryViewTypeDeprecated(self.0) }
297312
}
298313

314+
fn is_force_loadable(&self) -> bool {
315+
unsafe { BNIsBinaryViewTypeForceLoadable(self.0) }
316+
}
317+
299318
fn load_settings_for_data(&self, data: &BinaryView) -> Option<Ref<Settings>> {
300319
let settings_handle = unsafe { BNGetBinaryViewLoadSettingsForData(self.0, data.handle) };
301320

ui/options.h

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class BINARYNINJAUIAPI OptionsDialog : public QDialog
3232
QString m_fileName;
3333
QLabel* m_fileLabel;
3434
QComboBox* m_loadAsCombo;
35+
QLabel* m_loadAsLabel;
3536
QLabel* m_objectLabel;
3637
QComboBox* m_objectCombo;
3738
QTabWidget* m_tab;

0 commit comments

Comments
 (0)