Skip to content

Instantly share code, notes, and snippets.

@psifertex
Last active April 29, 2022 22:41
Show Gist options
  • Save psifertex/4614c016293bc1fe5a76aa1247ba78c3 to your computer and use it in GitHub Desktop.
Save psifertex/4614c016293bc1fe5a76aa1247ba78c3 to your computer and use it in GitHub Desktop.
# Copyright (c) 2022 Vector 35 Inc
#
# 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.
from binaryninjaui import *
from binaryninja import *
Settings().register_setting("ui.firstNavigate", """
{
"title" : "List of common main function names",
"type" : "array",
"elementType": "string",
"default" : ["main", "_main", "WinMain"],
"description" : "Common 'main' function names to try to automatically navigate to when first opening a binary.",
"ignore" : ["SettingsProjectScope", "SettingsResourceScope"]
}
""")
class UINotification(UIContextNotification):
def __init__(self):
if UIContext:
UIContextNotification.__init__(self)
UIContext.registerNotification(self)
def __del__(self):
if UIContext:
UIContext.unregisterNotification(self)
def OnAfterOpenFile(self, context, file, frame):
bv = frame.getCurrentBinaryView()
if bv:
for mainName in Settings().get_string_list("ui.firstNavigate"):
mains = bv.get_functions_by_name(mainName)
if len(mains) > 0:
frame.navigateToFunction(mains[0], mains[0].start, updateInfo=False, addHistoryEntry=False)
return
notif = UINotification()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment