Skip to content

Commit 4a8b1a8

Browse files
committed
Added IsForceLoadable method to BinaryViewType
1 parent caf2ae4 commit 4a8b1a8

File tree

7 files changed

+71
-1
lines changed

7 files changed

+71
-1
lines changed

binaryninjaapi.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6905,6 +6905,7 @@ namespace BinaryNinja {
69056905
static BNBinaryView* ParseCallback(void* ctxt, BNBinaryView* data);
69066906
static bool IsValidCallback(void* ctxt, BNBinaryView* data);
69076907
static bool IsDeprecatedCallback(void* ctxt);
6908+
static bool IsForceLoadableCallback(void *ctxt);
69086909
static BNSettings* GetSettingsCallback(void* ctxt, BNBinaryView* data);
69096910

69106911
BinaryViewType(BNBinaryViewType* type);
@@ -7042,6 +7043,13 @@ namespace BinaryNinja {
70427043
\return Whether this BinaryViewType is valid for given data
70437044
*/
70447045
virtual bool IsTypeValidForData(BinaryView* data) = 0;
7046+
7047+
/*! Check whether this BinaryViewType can be forced to load a binary, even if IsTypeValidForData returns false
7048+
7049+
\return Whether this BinaryViewType can be forced to load a binary
7050+
*/
7051+
virtual bool IsForceLoadable();
7052+
70457053
virtual Ref<Settings> GetLoadSettingsForData(BinaryView* data);
70467054
Ref<Settings> GetDefaultLoadSettingsForData(BinaryView* data);
70477055

@@ -7064,6 +7072,7 @@ namespace BinaryNinja {
70647072
virtual Ref<BinaryView> Parse(BinaryView* data) override;
70657073
virtual bool IsTypeValidForData(BinaryView* data) override;
70667074
virtual bool IsDeprecated() override;
7075+
virtual bool IsForceLoadable() override;
70677076
virtual Ref<Settings> GetLoadSettingsForData(BinaryView* data) override;
70687077
};
70697078

binaryninjacore.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
// will require rebuilding. The minimum version is increased when there are
4545
// incompatible changes that break binary compatibility, such as changes to
4646
// existing types or functions.
47-
#define BN_MINIMUM_CORE_ABI_VERSION 72
47+
#define BN_MINIMUM_CORE_ABI_VERSION 73
4848

4949
#ifdef __GNUC__
5050
#ifdef BINARYNINJACORE_LIBRARY
@@ -1656,6 +1656,7 @@ extern "C"
16561656
BNBinaryView* (*parse)(void* ctxt, BNBinaryView* data);
16571657
bool (*isValidForData)(void* ctxt, BNBinaryView* data);
16581658
bool (*isDeprecated)(void* ctxt);
1659+
bool (*isForceLoadable)(void* ctxt);
16591660
BNSettings* (*getLoadSettingsForData)(void* ctxt, BNBinaryView* data);
16601661
} BNCustomBinaryViewType;
16611662

@@ -3994,6 +3995,7 @@ extern "C"
39943995
BINARYNINJACOREAPI BNBinaryView* BNCreateBinaryViewOfType(BNBinaryViewType* type, BNBinaryView* data);
39953996
BINARYNINJACOREAPI BNBinaryView* BNParseBinaryViewOfType(BNBinaryViewType* type, BNBinaryView* data);
39963997
BINARYNINJACOREAPI bool BNIsBinaryViewTypeValidForData(BNBinaryViewType* type, BNBinaryView* data);
3998+
BINARYNINJACOREAPI bool BNIsBinaryViewTypeForceLoadable(BNBinaryViewType* type);
39973999
BINARYNINJACOREAPI BNSettings* BNGetBinaryViewDefaultLoadSettingsForData(
39984000
BNBinaryViewType* type, BNBinaryView* data);
39994001
BINARYNINJACOREAPI BNSettings* BNGetBinaryViewLoadSettingsForData(BNBinaryViewType* type, BNBinaryView* data);

binaryviewtype.cpp

Lines changed: 20 additions & 0 deletions
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

Lines changed: 17 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 17 additions & 0 deletions
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,
@@ -131,6 +141,7 @@ where
131141
parse: Some(cb_parse::<T>),
132142
isValidForData: Some(cb_valid::<T>),
133143
isDeprecated: Some(cb_deprecated::<T>),
144+
isForceLoadable: Some(cb_force_loadable::<T>),
134145
getLoadSettingsForData: Some(cb_load_settings::<T>),
135146
};
136147

@@ -158,6 +169,8 @@ pub trait BinaryViewTypeBase: AsRef<BinaryViewType> {
158169

159170
fn is_deprecated(&self) -> bool;
160171

172+
fn is_force_loadable(&self) -> bool;
173+
161174
fn default_load_settings_for_data(&self, data: &BinaryView) -> Result<Ref<Settings>> {
162175
let settings_handle =
163176
unsafe { BNGetBinaryViewDefaultLoadSettingsForData(self.as_ref().0, data.handle) };
@@ -265,6 +278,10 @@ impl BinaryViewTypeBase for BinaryViewType {
265278
unsafe { BNIsBinaryViewTypeDeprecated(self.0) }
266279
}
267280

281+
fn is_force_loadable(&self) -> bool {
282+
unsafe { BNIsBinaryViewTypeForceLoadable(self.0) }
283+
}
284+
268285
fn default_load_settings_for_data(&self, data: &BinaryView) -> Result<Ref<Settings>> {
269286
let settings_handle =
270287
unsafe { BNGetBinaryViewDefaultLoadSettingsForData(self.0, data.handle) };

ui/options.h

Lines changed: 1 addition & 0 deletions
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)