summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXusheng <xusheng@vector35.com>2021-05-31 15:46:57 +0800
committerXusheng <xusheng@vector35.com>2021-06-11 10:37:10 +0800
commit93f91f8d2f1fef1866b3ee87042ec62f99a8d087 (patch)
tree55a6439dcf66d005eaa3493fe6eb190c6338b47e
parent7954a49df95eba2ec7efeca3b4493a6c51070236 (diff)
Add TypeReferenceChanged notification
-rw-r--r--binaryninjaapi.h3
-rw-r--r--binaryninjacore.h1
-rw-r--r--binaryview.cpp10
-rw-r--r--python/binaryview.py11
-rw-r--r--python/examples/notification_callbacks.py3
-rw-r--r--suite/testcommon.py9
-rw-r--r--ui/typeview.h2
7 files changed, 39 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 08e75d49..efc7e1a6 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -955,6 +955,7 @@ __attribute__ ((format (printf, 1, 2)))
static void StringRemovedCallback(void* ctxt, BNBinaryView* data, BNStringType type, uint64_t offset, size_t len);
static void TypeDefinedCallback(void* ctxt, BNBinaryView* data, BNQualifiedName* name, BNType* type);
static void TypeUndefinedCallback(void* ctxt, BNBinaryView* data, BNQualifiedName* name, BNType* type);
+ static void TypeReferenceChangedCallback(void* ctx, BNBinaryView* data, BNQualifiedName* name, BNType* type);
public:
BinaryDataNotification();
@@ -984,6 +985,8 @@ __attribute__ ((format (printf, 1, 2)))
virtual void OnStringRemoved(BinaryView* data, BNStringType type, uint64_t offset, size_t len) { (void)data; (void)type; (void)offset; (void)len; }
virtual void OnTypeDefined(BinaryView* data, const QualifiedName& name, Type* type) { (void)data; (void)name; (void)type; }
virtual void OnTypeUndefined(BinaryView* data, const QualifiedName& name, Type* type) { (void)data; (void)name; (void)type; }
+ virtual void OnTypeReferenceChanged(BinaryView* data, const QualifiedName&name, Type* type) { (void)data;
+ (void)name; (void)type; }
};
class FileAccessor
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 35f653a2..9d9f3a35 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -1313,6 +1313,7 @@ extern "C"
void (*stringRemoved)(void* ctxt, BNBinaryView* view, BNStringType type, uint64_t offset, size_t len);
void (*typeDefined)(void* ctxt, BNBinaryView* view, BNQualifiedName* name, BNType* type);
void (*typeUndefined)(void* ctxt, BNBinaryView* view, BNQualifiedName* name, BNType* type);
+ void (*typeReferenceChanged)(void* ctxt, BNBinaryView* view, BNQualifiedName* name, BNType* type);
};
struct BNFileAccessor
diff --git a/binaryview.cpp b/binaryview.cpp
index e57b6bf4..476b897b 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -216,6 +216,15 @@ void BinaryDataNotification::TypeUndefinedCallback(void* ctxt, BNBinaryView* dat
}
+void BinaryDataNotification::TypeReferenceChangedCallback(void* ctxt, BNBinaryView* data, BNQualifiedName* name, BNType* type)
+{
+ BinaryDataNotification* notify = (BinaryDataNotification*)ctxt;
+ Ref<BinaryView> view = new BinaryView(BNNewViewReference(data));
+ Ref<Type> typeObj = new Type(BNNewTypeReference(type));
+ notify->OnTypeReferenceChanged(view, QualifiedName::FromAPIObject(name), typeObj);
+}
+
+
BinaryDataNotification::BinaryDataNotification()
{
m_callbacks.context = this;
@@ -241,6 +250,7 @@ BinaryDataNotification::BinaryDataNotification()
m_callbacks.stringRemoved = StringRemovedCallback;
m_callbacks.typeDefined = TypeDefinedCallback;
m_callbacks.typeUndefined = TypeUndefinedCallback;
+ m_callbacks.typeReferenceChanged = TypeReferenceChangedCallback;
}
diff --git a/python/binaryview.py b/python/binaryview.py
index 4b1ebb1f..9dd321c1 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -127,6 +127,9 @@ class BinaryDataNotification(object):
def type_undefined(self, view, name, type):
pass
+ def type_ref_changed(self, view, name, type):
+ pass
+
_decodings = {
StringType.AsciiString: "ascii",
StringType.Utf8String: "utf-8",
@@ -525,6 +528,7 @@ class BinaryDataNotificationCallbacks(object):
self._cb.stringRemoved = self._cb.stringRemoved.__class__(self._string_removed)
self._cb.typeDefined = self._cb.typeDefined.__class__(self._type_defined)
self._cb.typeUndefined = self._cb.typeUndefined.__class__(self._type_undefined)
+ self._cb.typeReferenceChanged = self._cb.typeReferenceChanged.__class__(self._type_ref_changed)
def _register(self):
core.BNRegisterDataNotification(self._view.handle, self._cb)
@@ -714,6 +718,13 @@ class BinaryDataNotificationCallbacks(object):
except:
log.log_error(traceback.format_exc())
+ def _type_ref_changed(self, ctxt, view, name, type_obj):
+ try:
+ qualified_name = types.QualifiedName._from_core_struct(name[0])
+ self._notify.type_ref_changed(self._view, qualified_name, types.Type(core.BNNewTypeReference(type_obj), platform = self._view.platform))
+ except:
+ log.log_error(traceback.format_exc())
+
@property
def view(self):
""" """
diff --git a/python/examples/notification_callbacks.py b/python/examples/notification_callbacks.py
index 3f1a2d41..e299aa06 100644
--- a/python/examples/notification_callbacks.py
+++ b/python/examples/notification_callbacks.py
@@ -94,4 +94,7 @@ class DemoNotification(BinaryDataNotification):
def type_undefined(self, *args):
log.log_info(inspect.stack()[0][3] + str(args))
+ def type_ref_changed(self, *args):
+ log.log_info(inspect.stack()[0][3] + str(args))
+
PluginCommand.register("Register Notification", "", reg_notif)
diff --git a/suite/testcommon.py b/suite/testcommon.py
index 451ff7a4..6941f8b3 100644
--- a/suite/testcommon.py
+++ b/suite/testcommon.py
@@ -968,6 +968,9 @@ class TestBuilder(Builder):
def type_undefined(self, view, name, type):
results.append("type undefined: {0}".format(name))
+ def type_ref_changed(self, view, name, type):
+ results.append("type reference changed: {0}".format(name))
+
test = NotifyTest()
bv.register_notification(test)
sacrificial_addr = 0x84fc
@@ -1001,6 +1004,12 @@ class TestBuilder(Builder):
bv.remove(sacrificial_addr, 4)
bv.update_analysis_and_wait()
+ type, _ = bv.parse_type_string("struct { uint64_t bar; }")
+ bv.define_user_type('foo', type)
+ func = bv.get_function_at(0x8440)
+ func.return_type = binja.Type.named_type_from_type('foo', type)
+ bv.update_analysis_and_wait()
+
bv.unregister_notification(test)
return fixOutput(sorted(results))
diff --git a/ui/typeview.h b/ui/typeview.h
index 47b45d2a..ef8511da 100644
--- a/ui/typeview.h
+++ b/ui/typeview.h
@@ -190,6 +190,8 @@ public:
BinaryNinja::Type* type) override;
virtual void OnTypeUndefined(BinaryNinja::BinaryView* view, const BinaryNinja::QualifiedName& name,
BinaryNinja::Type* type) override;
+ virtual void OnTypeReferenceChanged(BinaryNinja::BinaryView* view, const BinaryNinja::QualifiedName& name,
+ BinaryNinja::Type* type) override;
void MarkUpdatesRequired() { m_updatesRequired = true; }
virtual void updateFonts() override;