From 96b81a90b2a2f4663dbf0023dbe657a26935172f Mon Sep 17 00:00:00 2001 From: Josh Watson Date: Wed, 12 Oct 2016 13:33:44 -0400 Subject: Added flags parameter to sign_extend --- python/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/__init__.py b/python/__init__.py index 70267678..37edb17a 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -8291,16 +8291,17 @@ class LowLevelILFunction(object): """ return self.expr(core.LLIL_NOT, value.index, size = size, flags = flags) - def sign_extend(self, size, value): + def sign_extend(self, size, value, flags = None): """ ``sign_extend`` two's complement sign-extends the expression in ``value`` to ``size`` bytes :param int size: the size of the result in bytes :param LowLevelILExpr value: the expression to sign extend + :param str flags: optional, flags to set :return: The expression ``sx.(value)`` :rtype: LowLevelILExpr """ - return self.expr(core.LLIL_SX, value.index, size = size) + return self.expr(core.LLIL_SX, value.index, size = size, flags = flags) def zero_extend(self, size, value): """ -- cgit v1.3.1 From 4837ed6a909a3d9d5b7494f0c2f898592eaaba45 Mon Sep 17 00:00:00 2001 From: lucasduffey Date: Mon, 24 Oct 2016 11:48:14 -0700 Subject: Update getting-started.md --- docs/getting-started.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/getting-started.md b/docs/getting-started.md index 82c833a5..72c4796c 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -63,6 +63,7 @@ Switching views happens multiple ways. In some instances, it's automatic (clicki - `i` : Switches between disassembly and low-level il in graph view - `y` : Change type - [1248] : Change type directly to a data variable of the indicated widths + - `a` : Change the data type to an ASCII string - `d` : Switches between data variables of various widths - `r` : Change the data type to single ASCII character - `o` : Create a pointer data type -- cgit v1.3.1 From 9f03125edcfe4feb84a5d284d8003b5cd29715c5 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Sat, 29 Oct 2016 12:59:44 -0400 Subject: switch to new s3 uploader --- docs/.s3_website.yaml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docs/.s3_website.yaml diff --git a/docs/.s3_website.yaml b/docs/.s3_website.yaml new file mode 100644 index 00000000..02c4a996 --- /dev/null +++ b/docs/.s3_website.yaml @@ -0,0 +1,3 @@ +s3_bucket: docs.binary.ninja +site: ../site +s3_reduced_redundancy: True -- cgit v1.3.1 From 24b329b4a1f568f77ce6a44b31cfaab1867b8ff4 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Sat, 29 Oct 2016 12:59:53 -0400 Subject: add KDE notes to troubleshooting --- docs/guide/troubleshooting.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/docs/guide/troubleshooting.md b/docs/guide/troubleshooting.md index 68a4d328..4f761cfd 100644 --- a/docs/guide/troubleshooting.md +++ b/docs/guide/troubleshooting.md @@ -12,19 +12,33 @@ - If experiencing problems with Windows UAC permissions during an update, the easiest fix is to completely un-install and re-download the latest installer. Preferences are saved outside the installation folder and are preserved, though you might want to remove your [license](/getting-started/index.html#license). - If you need to change the email address on your license, contact [support]. -## Arch Linux +## Linux -Arch Linux is not an officially supported operating system, but many of our users have run it, and there are a few pitfalls to watch out for. +Given the diversity of Linux distributions, some work-arounds are required to run Binary Ninja on platforms that are not [officially supported][faq]. + +### Arch Linux - Install python2 from the [official repositories][archrepo] - Install the [libcurl-compat] library from AUR, and run Binary Ninja via `LD_PRELOAD=libcurl.so.3 ~/binaryninja/binaryninja` +### KDE + +To run Binary Ninja in a KDE based environment, set the `QT_PLUGIN_PATH` to the `QT` sub-folder: + +``` +cd ~/binaryninja +QT_PLUGIN_PATH=./qt ./binaryninja +``` + + ## API - - If the GUI launches but the license file is not valid, check that you're using the right version of Python. Only a 64-bit Python 2.7 is supported at this time. + - If the GUI launches but the license file is not valid when launched from the command-line, check that you're using the right version of Python. Only a 64-bit Python 2.7 is supported at this time. Additionally, the [personal][purchase] edition does not support headless operation. [known issues]: https://github.com/Vector35/binaryninja-api/issues?q=is%3Aissue [libcurl-compat]: https://aur.archlinux.org/packages/libcurl-compat/ [archrepo]: https://wiki.archlinux.org/index.php/Official_repositories [recover]: https://binary.ninja/recover.html [support]: https://binary.ninja/support.html +[faq]: https://binary.ninja/faq.html +[purchase]: https://binary.ninja/purchase.html -- cgit v1.3.1 From eef9d1eff05975c31862db4157ac2f1b2bb30502 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Mon, 31 Oct 2016 22:51:44 -0400 Subject: Added APIs for dealing with Thumb more easily --- binaryninjaapi.h | 2 ++ binaryninjacore.h | 3 +++ binaryview.cpp | 7 +++++++ platform.cpp | 9 +++++++++ python/__init__.py | 21 +++++++++++++++++++++ 5 files changed, 42 insertions(+) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 6311271c..a918fc42 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -926,6 +926,7 @@ namespace BinaryNinja std::vector> GetSymbolsOfType(BNSymbolType type, uint64_t start, uint64_t len); void DefineAutoSymbol(Ref sym); + void DefineAutoSymbolAndVariableOrFunction(Ref platform, Ref sym, Ref type); void UndefineAutoSymbol(Ref sym); void DefineUserSymbol(Ref sym); @@ -2243,6 +2244,7 @@ namespace BinaryNinja Ref GetRelatedPlatform(Architecture* arch); void AddRelatedPlatform(Architecture* arch, Platform* platform); + Ref GetAssociatedPlatformByAddress(uint64_t& addr); }; class ScriptingOutputListener diff --git a/binaryninjacore.h b/binaryninjacore.h index ea81c388..b2ed7cd3 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -1877,6 +1877,8 @@ extern "C" BINARYNINJACOREAPI void BNDefineUserSymbol(BNBinaryView* view, BNSymbol* sym); BINARYNINJACOREAPI void BNUndefineUserSymbol(BNBinaryView* view, BNSymbol* sym); BINARYNINJACOREAPI void BNDefineImportedFunction(BNBinaryView* view, BNSymbol* importAddressSym, BNFunction* func); + BINARYNINJACOREAPI void BNDefineAutoSymbolAndVariableOrFunction(BNBinaryView* view, BNPlatform* platform, + BNSymbol* sym, BNType* type); BINARYNINJACOREAPI BNSymbol* BNImportedFunctionFromImportAddressSymbol(BNSymbol* sym, uint64_t addr); @@ -2135,6 +2137,7 @@ extern "C" BINARYNINJACOREAPI BNPlatform* BNGetRelatedPlatform(BNPlatform* platform, BNArchitecture* arch); BINARYNINJACOREAPI void BNAddRelatedPlatform(BNPlatform* platform, BNArchitecture* arch, BNPlatform* related); + BINARYNINJACOREAPI BNPlatform* BNGetAssociatedPlatformByAddress(BNPlatform* platform, uint64_t* addr); //Demangler BINARYNINJACOREAPI bool BNDemangleMS(BNArchitecture* arch, diff --git a/binaryview.cpp b/binaryview.cpp index ff19de18..cc6667c5 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -1156,6 +1156,13 @@ void BinaryView::DefineAutoSymbol(Ref sym) } +void BinaryView::DefineAutoSymbolAndVariableOrFunction(Ref platform, Ref sym, Ref type) +{ + BNDefineAutoSymbolAndVariableOrFunction(m_object, platform ? platform->GetObject() : nullptr, sym->GetObject(), + type ? type->GetObject() : nullptr); +} + + void BinaryView::UndefineAutoSymbol(Ref sym) { BNUndefineAutoSymbol(m_object, sym->GetObject()); diff --git a/platform.cpp b/platform.cpp index 9b4053db..7a6571cc 100644 --- a/platform.cpp +++ b/platform.cpp @@ -244,3 +244,12 @@ void Platform::AddRelatedPlatform(Architecture* arch, Platform* platform) { BNAddRelatedPlatform(m_object, arch->GetObject(), platform->GetObject()); } + + +Ref Platform::GetAssociatedPlatformByAddress(uint64_t& addr) +{ + BNPlatform* platform = BNGetAssociatedPlatformByAddress(m_object, &addr); + if (!platform) + return nullptr; + return new Platform(platform); +} diff --git a/python/__init__.py b/python/__init__.py index 6c7e298c..1751fefa 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -2630,6 +2630,21 @@ class BinaryView(object): """ core.BNDefineAutoSymbol(self.handle, sym.handle) + def define_auto_symbol_and_var_or_function(self, sym, sym_type, platform = None): + """ + ``define_auto_symbol`` adds a symbol to the internal list of automatically discovered Symbol objects. + + :param Symbol sym: the symbol to define + :rtype: None + """ + if platform is None: + platform = self.platform + if platform is not None: + platform = platform.handle + if sym_type is not None: + sym_type = sym_type.handle + core.BNDefineAutoSymbolAndVariableOrFunction(self.handle, platform, sym.handle, sym_type) + def undefine_auto_symbol(self, sym): """ ``undefine_auto_symbol`` removes a symbol from the internal list of automatically discovered Symbol objects. @@ -9730,6 +9745,12 @@ class Platform(object): def add_related_platform(self, arch, platform): core.BNAddRelatedPlatform(self.handle, arch.handle, platform.handle) + def get_associated_platform_by_address(self, addr): + new_addr = ctypes.c_ulonglong() + new_addr.value = addr + result = core.BNGetAssociatedPlatformByAddress(self.handle, new_addr) + return Platform(None, handle = result), new_addr.value + class ScriptingOutputListener(object): def _register(self, handle): self._cb = core.BNScriptingOutputListener() -- cgit v1.3.1 From fdad629b8e9d859607d70d2712eee1684fd31614 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Mon, 7 Nov 2016 19:59:38 -0500 Subject: updated documentation for get_code_refs --- python/__init__.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python/__init__.py b/python/__init__.py index 1751fefa..a855d991 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -2490,6 +2490,19 @@ class BinaryView(object): return BasicBlock(self, block) def get_code_refs(self, addr, length = None): + """ + ``get_code_refs`` returns a list of ReferenceSource objects (xrefs or cross-references) that point to the provided virtual address. + + :param int addr: virtual address to query for references + :return: List of References for the given virtual address + :rtype: list(ReferenceSource) + :Example: + + >>> bv.get_code_refs(here) + [] + >>> + + """ count = ctypes.c_ulonglong(0) if length is None: refs = core.BNGetCodeReferences(self.handle, addr, count) -- cgit v1.3.1 From afdcfb9e1e7ab223da8bb5e4ad412e8852ff3d44 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Wed, 9 Nov 2016 01:16:32 -0500 Subject: tweak some sphinx configs --- api-docs/source/conf.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api-docs/source/conf.py b/api-docs/source/conf.py index 42bcfb87..ac6042b4 100644 --- a/api-docs/source/conf.py +++ b/api-docs/source/conf.py @@ -121,7 +121,7 @@ exclude_patterns = [] # If true, the current module name will be prepended to all description # unit titles (such as .. function::). # -# add_module_names = True +add_module_names = False # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. @@ -211,7 +211,7 @@ html_static_path = ['_static'] # If false, no module index is generated. # -# html_domain_indices = True +html_domain_indices = False # If false, no index is generated. # @@ -219,11 +219,11 @@ html_static_path = ['_static'] # If true, the index is split into individual pages for each letter. # -# html_split_index = False +html_split_index = False # If true, links to the reST sources are added to the pages. # -# html_show_sourcelink = True +html_show_sourcelink = False # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. # -- cgit v1.3.1 From bd3117ef0e09276a77ada277413743776ffc9ce1 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Wed, 9 Nov 2016 01:17:02 -0500 Subject: missing function names --- python/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/__init__.py b/python/__init__.py index a855d991..5e147ad5 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -3996,7 +3996,7 @@ class BinaryWriter(object): def write16(self, value): """ - ```` writes the lowest order two bytes from the integer ``value`` to the current offset, using internal endianness. + ``write16`` writes the lowest order two bytes from the integer ``value`` to the current offset, using internal endianness. :param int value: integer value to write. :return: boolean True on success, False on failure. @@ -4006,7 +4006,7 @@ class BinaryWriter(object): def write32(self, value): """ - ```` writes the lowest order four bytes from the integer ``value`` to the current offset, using internal endianness. + ``write32`` writes the lowest order four bytes from the integer ``value`` to the current offset, using internal endianness. :param int value: integer value to write. :return: boolean True on success, False on failure. @@ -4016,7 +4016,7 @@ class BinaryWriter(object): def write64(self, value): """ - ```` writes the lowest order eight bytes from the integer ``value`` to the current offset, using internal endianness. + ``write64`` writes the lowest order eight bytes from the integer ``value`` to the current offset, using internal endianness. :param int value: integer value to write. :return: boolean True on success, False on failure. -- cgit v1.3.1 From de07cda2227dfa2cd560ebb1187e3aa3946a081f Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Mon, 14 Nov 2016 21:57:57 -0500 Subject: basic NSF loader --- python/examples/nsf.py | 138 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 python/examples/nsf.py diff --git a/python/examples/nsf.py b/python/examples/nsf.py new file mode 100644 index 00000000..9d4ebd5c --- /dev/null +++ b/python/examples/nsf.py @@ -0,0 +1,138 @@ +# Copyright (c) 2015-2016 Vector 35 LLC +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# +# Simple NSF file loader, primarily for analyzing: +# https://scarybeastsecurity.blogspot.com/2016/11/0day-exploit-compromising-linux-desktop.html +# + +from binaryninja import * +import struct +import traceback +import os + +class NSFView(BinaryView): + name = "NSF" + long_name = "Nintendo Sound Format" + + def __init__(self, data): + BinaryView.__init__(self, parent_view = data, file_metadata = data.file) + + @classmethod + def is_valid_for_data(self, data): + hdr = data.read(0, 128) + if len(hdr) < 128: + return False + if hdr[0:5] != "NESM\x1a": + return False + song_count = struct.unpack("B", hdr[6])[0] + if song_count < 1: + log_info("Appears to be an NSF, but no songs.") + return False + return True + + def init(self): + try: + hdr = self.parent_view.read(0, 128) + self.version = struct.unpack("B", hdr[5])[0] + self.song_count = struct.unpack("B", hdr[6])[0] + self.starting_song = struct.unpack("B", hdr[7])[0] + self.load_address = struct.unpack(" Date: Wed, 16 Nov 2016 18:05:49 -0800 Subject: usage for set_default_session_data --- python/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/python/__init__.py b/python/__init__.py index 4c28e822..64763b71 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -1157,6 +1157,16 @@ class BinaryView(object): @classmethod def set_default_session_data(cls, name, value): + """ + ```set_default_session_data``` saves a variable to the BinaryView. + :param name: name of the variable to be saved + :param value: value of the variable to be saved + + :Example: + >>> BinaryView.set_default_session_data("variable_name", "value") + >>> bv.session_data.variable_name + 'value' + """ _BinaryViewAssociatedDataStore.set_default(name, value) def __del__(self): -- cgit v1.3.1 From 0d81eb27c3ca11d00b76c942a9160e598a10fefb Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Sun, 20 Nov 2016 08:44:25 -0500 Subject: add link to recovery page to license troubleshooting --- docs/guide/troubleshooting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide/troubleshooting.md b/docs/guide/troubleshooting.md index 4f761cfd..a74ecb68 100644 --- a/docs/guide/troubleshooting.md +++ b/docs/guide/troubleshooting.md @@ -9,7 +9,7 @@ ## License Problems -- If experiencing problems with Windows UAC permissions during an update, the easiest fix is to completely un-install and re-download the latest installer. Preferences are saved outside the installation folder and are preserved, though you might want to remove your [license](/getting-started/index.html#license). +- If experiencing problems with Windows UAC permissions during an update, the easiest fix is to completely un-install and [recover][recover] the latest installer and license. Preferences are saved outside the installation folder and are preserved, though you might want to remove your [license](/getting-started/index.html#license). - If you need to change the email address on your license, contact [support]. ## Linux -- cgit v1.3.1 From 3b719e990e3e01242918bf66d5a1fb6032517641 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Tue, 29 Nov 2016 15:52:43 -0500 Subject: fix int Type --- python/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/__init__.py b/python/__init__.py index 64763b71..c5b7e5be 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -4342,8 +4342,9 @@ class Type(object): return Type(core.BNCreateBoolType()) @classmethod - def int(self, width, sign = True): - return Type(core.BNCreateIntegerType(width, sign)) + def int(self, width, sign = True, altname = ""): + return Type(core.BNCreateIntegerType(width, sign, + ctypes.create_string_buffer(altname))) @classmethod def float(self, width): -- cgit v1.3.1 From 990cface5a0b9b814f423e45449a7d5f3cb6c19d Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Thu, 1 Dec 2016 17:22:22 -0500 Subject: Adding APIs to manipulate structures --- binaryninjaapi.h | 10 ++++++++++ binaryninjacore.h | 11 +++++++++++ binaryview.cpp | 20 ++++++++++++++++++++ python/__init__.py | 32 ++++++++++++++++++++++++++++++-- type.cpp | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 2 deletions(-) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index a918fc42..1d46bdc5 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -590,6 +590,8 @@ namespace BinaryNinja static void DataVariableUpdatedCallback(void* ctxt, BNBinaryView* data, BNDataVariable* var); static void StringFoundCallback(void* ctxt, BNBinaryView* data, BNStringType type, uint64_t offset, size_t len); static void StringRemovedCallback(void* ctxt, BNBinaryView* data, BNStringType type, uint64_t offset, size_t len); + static void TypeDefinedCallback(void* ctxt, BNBinaryView* data, const char* name, BNType* type); + static void TypeUndefinedCallback(void* ctxt, BNBinaryView* data, const char* name, BNType* type); public: BinaryDataNotification(); @@ -608,6 +610,8 @@ namespace BinaryNinja virtual void OnDataVariableUpdated(BinaryView* view, const DataVariable& var) { (void)view; (void)var; } virtual void OnStringFound(BinaryView* data, BNStringType type, uint64_t offset, size_t len) { (void)data; (void)type; (void)offset; (void)len; } 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 std::string& name, Type* type) { (void)data; (void)name; (void)type; } + virtual void OnTypeUndefined(BinaryView* data, const std::string& name, Type* type) { (void)data; (void)name; (void)type; } }; class FileAccessor @@ -1570,13 +1574,16 @@ namespace BinaryNinja class Structure: public CoreRefCountObject { public: + Structure(); Structure(BNStructure* s); std::vector GetName() const; void SetName(const std::vector& name); std::vector GetMembers() const; uint64_t GetWidth() const; + void SetWidth(size_t width); size_t GetAlignment() const; + void SetAlignment(size_t align); bool IsPacked() const; void SetPacked(bool packed); bool IsUnion() const; @@ -1585,6 +1592,7 @@ namespace BinaryNinja void AddMember(Type* type, const std::string& name); void AddMemberAtOffset(Type* type, const std::string& name, uint64_t offset); void RemoveMember(size_t idx); + void ReplaceMember(size_t idx, Type* type, const std::string& name); }; struct EnumerationMember @@ -1606,6 +1614,8 @@ namespace BinaryNinja void AddMember(const std::string& name); void AddMemberWithValue(const std::string& name, uint64_t value); + void RemoveMember(size_t idx); + void ReplaceMember(size_t idx, const std::string& name, uint64_t value); }; class DisassemblySettings: public CoreRefCountObject view = new BinaryView(BNNewViewReference(data)); + Ref typeObj = new Type(BNNewTypeReference(type)); + notify->OnTypeDefined(view, name, typeObj); +} + + +void BinaryDataNotification::TypeUndefinedCallback(void* ctxt, BNBinaryView* data, const char* name, BNType* type) +{ + BinaryDataNotification* notify = (BinaryDataNotification*)ctxt; + Ref view = new BinaryView(BNNewViewReference(data)); + Ref typeObj = new Type(BNNewTypeReference(type)); + notify->OnTypeUndefined(view, name, typeObj); +} + + BinaryDataNotification::BinaryDataNotification() { m_callbacks.context = this; @@ -143,6 +161,8 @@ BinaryDataNotification::BinaryDataNotification() m_callbacks.dataVariableUpdated = DataVariableUpdatedCallback; m_callbacks.stringFound = StringFoundCallback; m_callbacks.stringRemoved = StringRemovedCallback; + m_callbacks.typeDefined = TypeDefinedCallback; + m_callbacks.typeUndefined = TypeUndefinedCallback; } diff --git a/python/__init__.py b/python/__init__.py index 1751fefa..cc138009 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -576,6 +576,12 @@ class BinaryDataNotification: def string_removed(self, view, string_type, offset, length): pass + def type_defined(self, view, name, type): + pass + + def type_undefined(self, view, name, type): + pass + class UndoAction: name = None action_type = None @@ -671,6 +677,8 @@ class BinaryDataNotificationCallbacks(object): self._cb.dataVariableUpdated = self._cb.dataVariableUpdated.__class__(self._data_var_updated) self._cb.stringFound = self._cb.stringFound.__class__(self._string_found) 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) def _register(self): core.BNRegisterDataNotification(self.view.handle, self._cb) @@ -753,6 +761,18 @@ class BinaryDataNotificationCallbacks(object): except: log_error(traceback.format_exc()) + def _type_defined(self, ctxt, name, type_obj): + try: + self.notify.type_defined(self.view, name, Type(core.BNNewTypeReference(type_obj))) + except: + log_error(traceback.format_exc()) + + def _type_undefined(self, ctxt, name, type_obj): + try: + self.notify.type_undefined(self.view, name, Type(core.BNNewTypeReference(type_obj))) + except: + log_error(traceback.format_exc()) + class _BinaryViewTypeMetaclass(type): @property def list(self): @@ -4447,14 +4467,22 @@ class Structure(object): @property def width(self): - """Structure width (read-only)""" + """Structure width""" return core.BNGetStructureWidth(self.handle) + @width.setter + def width(self, new_width): + core.BNSetStructureWidth(self.handle, new_width) + @property def alignment(self): - """Structure alignment (read-only)""" + """Structure alignment""" return core.BNGetStructureAlignment(self.handle) + @alignment.setter + def alignment(self, align): + core.BNSetStructureAlignment(self.handle, align) + @property def packed(self): return core.BNIsStructurePacked(self.handle) diff --git a/type.cpp b/type.cpp index e0235664..7cc2757a 100644 --- a/type.cpp +++ b/type.cpp @@ -323,6 +323,12 @@ vector UnknownType::GetName() const } +Structure::Structure() +{ + m_object = BNCreateStructure(); +} + + Structure::Structure(BNStructure* s) { m_object = s; @@ -382,12 +388,24 @@ uint64_t Structure::GetWidth() const } +void Structure::SetWidth(size_t width) +{ + BNSetStructureWidth(m_object, width); +} + + size_t Structure::GetAlignment() const { return BNGetStructureAlignment(m_object); } +void Structure::SetAlignment(size_t align) +{ + BNSetStructureAlignment(m_object, align); +} + + bool Structure::IsPacked() const { return BNIsStructurePacked(m_object); @@ -430,6 +448,12 @@ void Structure::RemoveMember(size_t idx) } +void Structure::ReplaceMember(size_t idx, Type* type, const std::string& name) +{ + BNReplaceStructureMember(m_object, idx, type->GetObject(), name.c_str()); +} + + Enumeration::Enumeration(BNEnumeration* e) { m_object = e; @@ -494,6 +518,18 @@ void Enumeration::AddMemberWithValue(const string& name, uint64_t value) } +void Enumeration::RemoveMember(size_t idx) +{ + BNRemoveEnumerationMember(m_object, idx); +} + + +void Enumeration::ReplaceMember(size_t idx, const string& name, uint64_t value) +{ + BNReplaceEnumerationMember(m_object, idx, name.c_str(), value); +} + + bool BinaryNinja::PreprocessSource(const string& source, const string& fileName, string& output, string& errors, const vector& includeDirs) { -- cgit v1.3.1 From 1ae01b140d99f07c86c9f56374e26a062ff34c0c Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Fri, 2 Dec 2016 11:15:50 -0500 Subject: moving linux setup script to public repo --- scripts/linux-setup.sh | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 scripts/linux-setup.sh diff --git a/scripts/linux-setup.sh b/scripts/linux-setup.sh new file mode 100755 index 00000000..08c2a22f --- /dev/null +++ b/scripts/linux-setup.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +# Note is setup script currently does three things: +# +# 1. It creates a binaryninja.desktop file in ~/.local/share/applications and +# copies it to the desktop +# 2. It creates a .xml file to add a mime type for .bndb files. +# 3. It adds a binaryninja: url handler. + + +APP="binaryninja" +FILECOMMENT="Binary Ninja Analysis Database" +APPCOMMENT="Binary Ninja: A Reverse Engineering Platform" +BNPATH=$(dirname $(readlink -f "$0")) +EXEC="${BNPATH}/binaryninja" +PNG="${BNPATH}/docs/images/logo.png" +EXT="bndb" +SHARE=/usr/share #For system +SUDO="sudo" #For system +SHARE=~/.local/share #For user only +SUDO="" #For user only +DESKTOPFILE=$SHARE/applications/${APP}.desktop +MIMEFILE=$SHARE/mime/packages/application-x-$APP.xml +IMAGEPATH=$SHARE/pixmaps + +createdesktopfile() +{ + mkdir -p $SHARE/{mime/packages,applications,pixmaps} + echo Creating .desktop file + + # Desktop File + echo "[Desktop Entry] +Name=$APP +Exec=$EXEC %u +MimeType=application/x-$APP;x-scheme-handler/$APP; +Icon=$PNG +Terminal=false +Type=Application +Categories=Utility; +Comment=$APPCOMMENT +" | $SUDO tee $DESKTOPFILE >/dev/null + $SUDO chmod +x $DESKTOPFILE + + $SUDO update-desktop-database $SHARE/applications +} + +createmime() +{ + echo Creating MIME settings + if [ ! -f $DESKTOPFILE ] + then + createdesktopfile + fi + + echo " + + + $FILECOMMENT + + + + + +"| $SUDO tee $MIMEFILE >/dev/null + + #echo Copying icon + #$SUDO cp $PNG $IMAGEPATH/$APP.png + #$SUDO cp $PNG $IMAGEPATH/application-x-$APP.png + + $SUDO update-mime-database $SHARE/mime +} + +addtodesktop() +{ + cp $DESKTOPFILE ~/Desktop +} + +#TODO: Make these optional... +createdesktopfile +createmime +addtodesktop -- cgit v1.3.1 From 2cf2f651236af81a2b5a94f591bb4072c4c702e9 Mon Sep 17 00:00:00 2001 From: lucasduffey Date: Mon, 5 Dec 2016 14:56:40 -0800 Subject: Update __init__.py --- python/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/__init__.py b/python/__init__.py index c5b7e5be..a64ec6b9 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -5479,7 +5479,7 @@ class FunctionGraphBlock(object): @property def basic_block(self): - """Basic block associated with this part of the funciton graph (read-only)""" + """Basic block associated with this part of the function graph (read-only)""" block = core.BNGetFunctionGraphBasicBlock(self.handle) func = core.BNGetBasicBlockFunction(block) if func is None: -- cgit v1.3.1 From acc41827cad8a7b2bbd66a15ffadd88cd0c31c2e Mon Sep 17 00:00:00 2001 From: lucasduffey Date: Tue, 6 Dec 2016 12:47:23 -0800 Subject: consistently use "BinaryView" --- python/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/python/__init__.py b/python/__init__.py index a64ec6b9..0cc5deeb 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -797,7 +797,7 @@ class BinaryViewType(object): @property def name(self): - """Binary View name (read-only)""" + """BinaryView name (read-only)""" return core.BNGetBinaryViewTypeName(self.handle) @property @@ -2869,7 +2869,7 @@ class BinaryView(object): .. note:: This API performs a binary patch, analysis may need to be updated afterward. Additionally the binary\ file must be saved in order to preserve the changes made. - :param Architecture arch: architecture of the current binary view + :param Architecture arch: architecture of the current BinaryView :param int addr: virtual address of the instruction to be modified :return: True on success, False on falure. :rtype: bool @@ -2893,7 +2893,7 @@ class BinaryView(object): .. note:: This API performs a binary patch, analysis may need to be updated afterward. Additionally the binary\ file must be saved in order to preserve the changes made. - :param Architecture arch: architecture of the current binary view + :param Architecture arch: architecture of the current BinaryView :param int addr: virtual address of the instruction to be modified :return: True on success, False on falure. :rtype: bool @@ -2917,7 +2917,7 @@ class BinaryView(object): .. note:: This API performs a binary patch, analysis may need to be updated afterward. Additionally the binary file must be saved in order to preserve the changes made. - :param Architecture arch: architecture of the current binary view + :param Architecture arch: architecture of the current BinaryView :param int addr: virtual address of the instruction to be modified :return: True on success, False on falure. :rtype: bool @@ -2939,7 +2939,7 @@ class BinaryView(object): ``skip_and_return_value`` convert the ``call`` instruction of architecture ``arch`` at the virtual address ``addr`` to the equivilent of returning a value. - :param Architecture arch: architecture of the current binary view + :param Architecture arch: architecture of the current BinaryView :param int addr: virtual address of the instruction to be modified :param int value: value to make the instruction *return* :return: True on success, False on falure. @@ -2962,7 +2962,7 @@ class BinaryView(object): ``get_instruction_length`` returns the number of bytes in the instruction of Architecture ``arch`` at the virtual address ``addr`` - :param Architecture arch: architecture of the current binary view + :param Architecture arch: architecture of the current BinaryView :param int addr: virtual address of the instruction query :return: Number of bytes in instruction :rtype: int -- cgit v1.3.1 From c49b584d2a71b13840c9a133c8dbbbc5f5ab40e2 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Wed, 7 Dec 2016 21:44:23 -0500 Subject: fix references to BNFreeTypeParserResult --- python/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/__init__.py b/python/__init__.py index c5b7e5be..e9083805 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -7450,7 +7450,7 @@ class Architecture(object): variables[parse.variables[i].name] = Type(core.BNNewTypeReference(parse.variables[i].type)) for i in xrange(0, parse.functionCount): functions[parse.functions[i].name] = Type(core.BNNewTypeReference(parse.functions[i].type)) - BNFreeTypeParserResult(parse) + core.BNFreeTypeParserResult(parse) return (TypeParserResult(types, variables, functions), error_str) def parse_types_from_source_file(self, filename, include_dirs = []): @@ -7491,7 +7491,7 @@ class Architecture(object): variables[parse.variables[i].name] = Type(core.BNNewTypeReference(parse.variables[i].type)) for i in xrange(0, parse.functionCount): functions[parse.functions[i].name] = Type(core.BNNewTypeReference(parse.functions[i].type)) - BNFreeTypeParserResult(parse) + core.BNFreeTypeParserResult(parse) return (TypeParserResult(types, variables, functions), error_str) def register_calling_convention(self, cc): -- cgit v1.3.1 From 9b600c88f5eb37d883cced7c70e4145aa2bb9a33 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Wed, 7 Dec 2016 21:44:35 -0500 Subject: minor typo fixes --- scripts/linux-setup.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/linux-setup.sh b/scripts/linux-setup.sh index 08c2a22f..2f5bd489 100755 --- a/scripts/linux-setup.sh +++ b/scripts/linux-setup.sh @@ -2,7 +2,7 @@ # Note is setup script currently does three things: # -# 1. It creates a binaryninja.desktop file in ~/.local/share/applications and +# 1. It creates a binaryninja.desktop file in ~/.local/share/applications and # copies it to the desktop # 2. It creates a .xml file to add a mime type for .bndb files. # 3. It adds a binaryninja: url handler. @@ -16,9 +16,9 @@ EXEC="${BNPATH}/binaryninja" PNG="${BNPATH}/docs/images/logo.png" EXT="bndb" SHARE=/usr/share #For system -SUDO="sudo" #For system +SUDO="sudo" #For system SHARE=~/.local/share #For user only -SUDO="" #For user only +SUDO="" #For user only DESKTOPFILE=$SHARE/applications/${APP}.desktop MIMEFILE=$SHARE/mime/packages/application-x-$APP.xml IMAGEPATH=$SHARE/pixmaps @@ -26,7 +26,7 @@ IMAGEPATH=$SHARE/pixmaps createdesktopfile() { mkdir -p $SHARE/{mime/packages,applications,pixmaps} - echo Creating .desktop file + echo Creating .desktop file # Desktop File echo "[Desktop Entry] @@ -44,7 +44,7 @@ Comment=$APPCOMMENT $SUDO update-desktop-database $SHARE/applications } -createmime() +createmime() { echo Creating MIME settings if [ ! -f $DESKTOPFILE ] @@ -65,7 +65,7 @@ createmime() #echo Copying icon #$SUDO cp $PNG $IMAGEPATH/$APP.png - #$SUDO cp $PNG $IMAGEPATH/application-x-$APP.png + $SUDO cp $PNG $IMAGEPATH/application-x-$APP.png $SUDO update-mime-database $SHARE/mime } -- cgit v1.3.1 From 9fb0517ff8ad4b2e5374591c15893571d4470557 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Tue, 27 Dec 2016 12:28:09 -0500 Subject: Making exported svg pages have graphs closer to the original --- python/examples/export_svg.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/python/examples/export_svg.py b/python/examples/export_svg.py index a54dc879..5a4d2982 100755 --- a/python/examples/export_svg.py +++ b/python/examples/export_svg.py @@ -56,8 +56,13 @@ def render_svg(function):