From c17b562736dba5a2d042b2c7979f5dc32507388c Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Sun, 15 May 2016 20:21:19 -0400 Subject: sample plugin to view all release notes or downgrade --- python/examples/version-switcher.py | 91 +++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 python/examples/version-switcher.py (limited to 'python') diff --git a/python/examples/version-switcher.py b/python/examples/version-switcher.py new file mode 100644 index 00000000..7f85d6a7 --- /dev/null +++ b/python/examples/version-switcher.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python +import sys +import binaryninja +import datetime + +chandefault="private-beta" +channel=0 +up=0 +versions=0 + +def load_channel(newchannel): + global up + global channel + global versions + if (newchannel == channel): + print "Same channel, not updating." + else: + try: + print "Loading channel %s" % newchannel + up = binaryninja.UpdateChannel(newchannel, "", "") + channel = newchannel + print "Loading versions..." + versions = up.versions + except Exception: + print "%s is not a valid channel name. Defaulting to " % chandefault + channel = chandefault + up = binaryninja.UpdateChannel(channel, "", "") + +def select(version): + done = False + date = datetime.datetime.fromtimestamp(version.time).strftime('%c') + while not done: + print "Version:\t%s" % version.version + print "Updated:\t%s" % date + print "Notes:\t%s" % version.notes + print "-----" + print "\t1)\tSwitch to version" + print "\t2)\tMain Menu" + selection = int(input('Choice: ')) + if (selection == 2): + done = True + elif (selection == 1): + print "Updating..." + print version.update() + #forward updating won't work without reloading + sys.exit() + else: + print "Invalid selection" + +def list_channels(): + done = False + while not done: + channel_list = binaryninja.UpdateChannel.list + for index, item in enumerate(channel_list): + print "\t%d)\t%s" % (index+1, item.name) + print "\t%d)\t%s" % (len(channel_list)+1, "Main Menu") + selection = input('Choice: ') + if (int(selection) <= 0 or int(selection) > len(channel_list)+1): + print "%s is an invalid choice.\n\n" % selection + else: + selection = int(selection) + done = True + if (selection != len(channel_list) + 1): + load_channel(channel_list[selection-1].name) + +def main(): + done = False + load_channel(chandefault) + while not done: + print "Binary Ninja Version Switcher" + print "Current Channel: %s " % channel + for index, version in enumerate(versions): + date = datetime.datetime.fromtimestamp(version.time).strftime('%c') + print "\t%d)\t%s (%s)" % (index+1, version.version, date) + print "\t%d)\t%s" % (len(versions)+1, "Switch Channel") + print "\t%d)\t%s" % (len(versions)+2, "Exit") + selection = input('Choice: ') + if (int(selection) <= 0 or int(selection) > len(versions)+2): + print "%s is an invalid choice.\n\n" % selection + else: + selection = int(selection) + if (selection == len(versions) + 2): + done = True + elif (selection == len(versions) + 1): + list_channels() + else: + select(versions[selection-1]) + + +if __name__ == "__main__": + main() -- cgit v1.3.1 From 8bafa835a3f86b3db50ecf2675ba872b58adff58 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Sun, 15 May 2016 20:52:19 -0400 Subject: small tweaks and add current version to main menu --- python/examples/version-switcher.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'python') diff --git a/python/examples/version-switcher.py b/python/examples/version-switcher.py index 7f85d6a7..da2942d4 100644 --- a/python/examples/version-switcher.py +++ b/python/examples/version-switcher.py @@ -32,11 +32,11 @@ def select(version): while not done: print "Version:\t%s" % version.version print "Updated:\t%s" % date - print "Notes:\t%s" % version.notes + print "Notes:\n\n%s" % version.notes print "-----" print "\t1)\tSwitch to version" print "\t2)\tMain Menu" - selection = int(input('Choice: ')) + selection = int("0" + raw_input('Choice: ')) if (selection == 2): done = True elif (selection == 1): @@ -54,37 +54,37 @@ def list_channels(): for index, item in enumerate(channel_list): print "\t%d)\t%s" % (index+1, item.name) print "\t%d)\t%s" % (len(channel_list)+1, "Main Menu") - selection = input('Choice: ') - if (int(selection) <= 0 or int(selection) > len(channel_list)+1): - print "%s is an invalid choice.\n\n" % selection + selection = int("0" + raw_input('Choice: ')) + if (selection <= 0 or selection > len(channel_list)+1): + print "%s is an invalid choice." % selection else: selection = int(selection) done = True if (selection != len(channel_list) + 1): - load_channel(channel_list[selection-1].name) + load_channel(channel_list[selection - 1].name) def main(): done = False load_channel(chandefault) while not done: - print "Binary Ninja Version Switcher" - print "Current Channel: %s " % channel + print "\n\tBinary Ninja Version Switcher" + print "\t\tCurrent Channel: %s" % channel + print "\t\tCurrent Version: %s\n" % binaryninja.core_version for index, version in enumerate(versions): date = datetime.datetime.fromtimestamp(version.time).strftime('%c') - print "\t%d)\t%s (%s)" % (index+1, version.version, date) - print "\t%d)\t%s" % (len(versions)+1, "Switch Channel") - print "\t%d)\t%s" % (len(versions)+2, "Exit") - selection = input('Choice: ') - if (int(selection) <= 0 or int(selection) > len(versions)+2): - print "%s is an invalid choice.\n\n" % selection + print "\t%d)\t%s (%s)" % (index + 1, version.version, date) + print "\t%d)\t%s" % (len(versions) + 1, "Switch Channel") + print "\t%d)\t%s" % (len(versions) + 2, "Exit") + selection = int("0" + raw_input('Choice: ')) + if (selection <= 0 or selection > len(versions) + 2): + print "%d is an invalid choice.\n\n" % selection else: - selection = int(selection) if (selection == len(versions) + 2): done = True elif (selection == len(versions) + 1): list_channels() else: - select(versions[selection-1]) + select(versions[selection - 1]) if __name__ == "__main__": -- cgit v1.3.1 From fc6873c2b34ff8df7c0cf4947d95a553d6f7d72c Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Sun, 15 May 2016 20:56:39 -0400 Subject: updated readme --- python/examples/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'python') diff --git a/python/examples/README.md b/python/examples/README.md index 4ad4ac03..7fd3ab6b 100644 --- a/python/examples/README.md +++ b/python/examples/README.md @@ -1,11 +1,12 @@ # Binary Ninja Python API Examples -The following examples demonstrate the Binary Ninja API. They include both stand-alone examples that directly call into the core, as well as examples meant to be loaded as plugins. +The following examples demonstrate some of the Binary Ninja API. They include both stand-alone examples that directly call into the core without a GUI, as well as examples meant to be loaded as plugins available from the UI. ## Stand-alone * bin-info.py - general binary information * arm-syscall.py - extract syscall numbers from IL for arm Mach-O files +* version-switcher.py - uses the update API to see raw version notes and manually downgrade or upgrade To use the stand-alone Python examples, make sure your `PYTHON_PATH` includes the API, like: @@ -17,6 +18,7 @@ PYTHONPATH=$PYTHONPATH:/Applications/Binary\ Ninja.app/Contents/Resources/python * nes.py - 6502 CPU architecture including LLIL lifting and `.NES` file format parser * breakpoint.py - small example showing how to modify a file and register a GUI menu item +* jump-table.py - stop-gap jump table plugin triggered via right-click menu at an indirect jump Plugins are meant to be loaded into a running Binary Ninja GUI and should either be copied or symlinked into the appropriate plugin folder. You'll need to then re-start Binary Ninja. -- cgit v1.3.1 From 3a56ec2358d4812b18745847baeba1b486291a9f Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Mon, 16 May 2016 17:07:13 -0400 Subject: add support for auto updates --- python/examples/version-switcher.py | 74 +++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 23 deletions(-) (limited to 'python') diff --git a/python/examples/version-switcher.py b/python/examples/version-switcher.py index da2942d4..a1936a52 100644 --- a/python/examples/version-switcher.py +++ b/python/examples/version-switcher.py @@ -5,26 +5,22 @@ import datetime chandefault="private-beta" channel=0 -up=0 versions=0 def load_channel(newchannel): - global up global channel global versions - if (newchannel == channel): + if (channel != 0 and newchannel == channel.name): print "Same channel, not updating." else: try: print "Loading channel %s" % newchannel - up = binaryninja.UpdateChannel(newchannel, "", "") - channel = newchannel + channel = binaryninja.UpdateChannel[newchannel] print "Loading versions..." - versions = up.versions + versions = channel.versions except Exception: print "%s is not a valid channel name. Defaulting to " % chandefault - channel = chandefault - up = binaryninja.UpdateChannel(channel, "", "") + channel = binaryninja.UpdateChannel[chandefault] def select(version): done = False @@ -32,55 +28,87 @@ def select(version): while not done: print "Version:\t%s" % version.version print "Updated:\t%s" % date - print "Notes:\n\n%s" % version.notes + print "Notes:\n\n-----\n%s" % version.notes print "-----" - print "\t1)\tSwitch to version" + print "\t1)\tSwitch to version" print "\t2)\tMain Menu" - selection = int("0" + raw_input('Choice: ')) + selection = raw_input('Choice: ') + if selection.isdigit(): + selection = int(selection) + else: + selection = 0 if (selection == 2): done = True elif (selection == 1): - print "Updating..." - print version.update() - #forward updating won't work without reloading - sys.exit() + if (version.version == channel.latest_version.version): + print "Requesting update to latest version." + else: + print "Requesting update to prior version." + if binaryninja.are_auto_updates_enabled(): + print "Disabling automatic updates." + binaryninja.set_auto_updates_enabled(False) + if (version.version == binaryninja.core_version): + print "Already running %s" % version.version + else: + print "version.version %s" % version.version + print "binaryninja.core_version %s" % binaryninja.core_version + print "Updating..." + print version.update() + #forward updating won't work without reloading + sys.exit() else: print "Invalid selection" def list_channels(): done = False + print "\tSelect channel:\n" while not done: channel_list = binaryninja.UpdateChannel.list for index, item in enumerate(channel_list): print "\t%d)\t%s" % (index+1, item.name) print "\t%d)\t%s" % (len(channel_list)+1, "Main Menu") - selection = int("0" + raw_input('Choice: ')) + selection = raw_input('Choice: ') + if selection.isdigit(): + selection = int(selection) + else: + selection = 0 if (selection <= 0 or selection > len(channel_list)+1): print "%s is an invalid choice." % selection else: - selection = int(selection) done = True if (selection != len(channel_list) + 1): load_channel(channel_list[selection - 1].name) +def toggle_updates(): + binaryninja.set_auto_updates_enabled(not binaryninja.are_auto_updates_enabled()) + def main(): + global channel done = False load_channel(chandefault) while not done: print "\n\tBinary Ninja Version Switcher" - print "\t\tCurrent Channel: %s" % channel - print "\t\tCurrent Version: %s\n" % binaryninja.core_version + print "\t\tCurrent Channel:\t%s" % channel.name + print "\t\tCurrent Version:\t%s" % binaryninja.core_version + print "\t\tAuto-Updates On:\t%s\n" % binaryninja.are_auto_updates_enabled() for index, version in enumerate(versions): date = datetime.datetime.fromtimestamp(version.time).strftime('%c') print "\t%d)\t%s (%s)" % (index + 1, version.version, date) print "\t%d)\t%s" % (len(versions) + 1, "Switch Channel") - print "\t%d)\t%s" % (len(versions) + 2, "Exit") - selection = int("0" + raw_input('Choice: ')) - if (selection <= 0 or selection > len(versions) + 2): + print "\t%d)\t%s" % (len(versions) + 2, "Toggle Auto Updates") + print "\t%d)\t%s" % (len(versions) + 3, "Exit") + selection = raw_input('Choice: ') + if selection.isdigit(): + selection = int(selection) + else: + selection = 0 + if (selection <= 0 or selection > len(versions) + 3): print "%d is an invalid choice.\n\n" % selection else: - if (selection == len(versions) + 2): + if (selection == len(versions) + 3): done = True + elif (selection == len(versions) + 2): + toggle_updates() elif (selection == len(versions) + 1): list_channels() else: -- cgit v1.3.1