This repository has been archived by the owner on Jun 24, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First commit of the Binja plugin gef-binja
- Loading branch information
hugsy
committed
May 12, 2020
0 parents
commit c3f87b1
Showing
9 changed files
with
543 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"python.pythonPath": "C:\\Python38\\python.exe" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2013-2019 crazy rabbidz | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# GEF-Binja | ||
|
||
Author: **@hugsy** | ||
|
||
Interface [GDB-GEF](https://github.com/hugsy/gef) with Binary Ninja | ||
|
||
|
||
## Description | ||
|
||
`gef-binja` is a plugin that is the server-side of the XML-RPC defined for gef for BinaryNinja. | ||
It will spawn a threaded XMLRPC server from your current BN session making it possible for gef to interact with Binary Ninja. | ||
|
||
|
||
|
||
### Linux | ||
|
||
### Windows | ||
|
||
### Darwin | ||
|
||
|
||
|
||
## Minimum Version | ||
|
||
This plugin requires the following minimum version of Binary Ninja: | ||
|
||
* 1200 | ||
|
||
|
||
|
||
## Required Dependencies | ||
|
||
The following dependencies are required for this plugin: | ||
|
||
* apt - gdb 7.7+ (or gdb-multiarch) with Python3 support | ||
* other - https://github.com/hugsy/gef ([easy install](https://github.com/hugsy/gef#instant-setup)) | ||
|
||
|
||
## License | ||
|
||
This plugin is released under a MIT license. | ||
|
||
|
||
## Metadata Version | ||
|
||
2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
# from binaryninja import * | ||
# | ||
# def do_nothing(bv,function): | ||
# show_message_box("Do Nothing", "Congratulations! You have successfully done nothing.\n\n" + | ||
# "Pat yourself on the back.", MessageBoxButtonSet.OKButtonSet, MessageBoxIcon.ErrorIcon) | ||
# | ||
# PluginCommand.register_for_address("Useless Plugin", "Basically does nothing", do_nothing) | ||
|
||
""" | ||
This script is the server-side of the XML-RPC defined for gef for | ||
BinaryNinja. | ||
It will spawn a threaded XMLRPC server from your current BN session | ||
making it possible for gef to interact with Binary Ninja. | ||
To install this script as a plugin: | ||
$ ln -sf /path/to/gef/binja_gef.py ~/.binaryninja/plugins/binaryninja_gef.py | ||
Then run it from Binary Ninja: | ||
- open a disassembly session | ||
- click "Tools" -> "gef : start/stop server" | ||
If all went well, you will see something like | ||
[+] Creating new thread for XMLRPC server: Thread-1 | ||
[+] Starting XMLRPC server: 0.0.0.0:1337 | ||
[+] Registered 10 functions. | ||
@_hugsy_ | ||
""" | ||
|
||
import socket | ||
import threading | ||
import xmlrpc.server, xmlrpc.client | ||
|
||
|
||
|
||
from binaryninja import ( | ||
log_info, | ||
PluginCommand, | ||
show_message_box, | ||
MessageBoxButtonSet, | ||
MessageBoxIcon, | ||
) | ||
|
||
from .helpers import ( | ||
info, | ||
err, | ||
dbg, | ||
add_gef_breakpoint, | ||
delete_gef_breakpoint, | ||
) | ||
|
||
from .constants import ( | ||
HOST, | ||
PORT, | ||
DEBUG, | ||
HL_NO_COLOR, | ||
HL_BP_COLOR, | ||
HL_CUR_INSN_COLOR, | ||
) | ||
|
||
from .gef import ( | ||
Gef, | ||
BinjaGefRequestHandler, | ||
) | ||
|
||
|
||
__service_started = False | ||
__service_thread = None | ||
|
||
|
||
|
||
def create_binja_menu(): | ||
# Binja does not really support menu in its GUI just yet | ||
PluginCommand.register_for_address( | ||
"gef : add breakpoint", | ||
"Add a breakpoint in gef at the specified location.", | ||
add_gef_breakpoint | ||
) | ||
|
||
PluginCommand.register_for_address( | ||
"gef : delete breakpoint", | ||
"Remove a breakpoint in gef at the specified location.", | ||
delete_gef_breakpoint | ||
) | ||
return | ||
|
||
|
||
def start_service(host, port, bv): | ||
info("Starting service on {}:{}".format(host, port)) | ||
server = xmlrpc.server.SimpleXMLRPCServer( | ||
(host, port), | ||
requestHandler=BinjaGefRequestHandler, | ||
logRequests=False, | ||
allow_none=True | ||
) | ||
server.register_introspection_functions() | ||
server.register_instance(Gef(server, bv)) | ||
dbg("Registered {} functions.".format( len(server.system_listMethods()) )) | ||
while True: | ||
if hasattr(server, "shutdown") and server.shutdown==True: break | ||
server.handle_request() | ||
return | ||
|
||
|
||
def gef_start(bv): | ||
global __service_thread, __service_started | ||
__service_thread = threading.Thread(target=start_service, args=(HOST, PORT, bv)) | ||
__service_thread.daemon = True | ||
__service_thread.start() | ||
dbg("Started new thread '{}'".format(__service_thread.name)) | ||
|
||
if not __service_started: | ||
create_binja_menu() | ||
__service_started = True | ||
return | ||
|
||
|
||
def gef_stop(bv): | ||
global __service_thread | ||
__service_thread.join() | ||
__service_thread = None | ||
info("Server stopped") | ||
return | ||
|
||
|
||
def gef_start_stop(bv): | ||
if __service_thread is None: | ||
dbg("Trying to start service thread") | ||
gef_start(bv) | ||
show_message_box( | ||
"GEF", | ||
"Service successfully started, you can now have gef connect to it", | ||
MessageBoxButtonSet.OKButtonSet, | ||
MessageBoxIcon.InformationIcon | ||
) | ||
|
||
else: | ||
dbg("Trying to stop service thread") | ||
try: | ||
cli = xmlrpc.client.ServerProxy("http://{:s}:{:d}".format(HOST, PORT)) | ||
cli.shutdown() | ||
except socket.error: | ||
pass | ||
|
||
gef_stop(bv) | ||
show_message_box( | ||
"GEF", | ||
"Service successfully stopped", | ||
MessageBoxButtonSet.OKButtonSet, | ||
MessageBoxIcon.InformationIcon | ||
) | ||
return | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
PluginCommand.register( | ||
"Start/stop server GEF interaction", | ||
"Start/stop the XMLRPC server for communicating with gef", | ||
gef_start_stop | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from binaryninja import enums | ||
|
||
|
||
DEBUG = True # change to True for a way more verbose output | ||
|
||
# Python XML-RPC is highly insecure as it allows anyone | ||
# to execute code on the server. It is recommended to change | ||
# the host listening IP address to a HostOnly LAN address. | ||
HOST, PORT = "0.0.0.0", 1337 | ||
|
||
# Adjust to your liking between the following colors: | ||
# - HighlightStandardColor.NoHighlightColor | ||
# - HighlightStandardColor.BlueHighlightColor | ||
# - HighlightStandardColor.GreenHighlightColor | ||
# - HighlightStandardColor.CyanHighlightColor | ||
# - HighlightStandardColor.RedHighlightColor | ||
# - HighlightStandardColor.MagentaHighlightColor | ||
# - HighlightStandardColor.YellowHighlightColor | ||
# - HighlightStandardColor.OrangeHighlightColor | ||
# - HighlightStandardColor.WhiteHighlightColor | ||
# - HighlightStandardColor.BlackHighlightColor | ||
HL_NO_COLOR = enums.HighlightStandardColor.NoHighlightColor | ||
HL_BP_COLOR = enums.HighlightStandardColor.RedHighlightColor | ||
HL_CUR_INSN_COLOR = enums.HighlightStandardColor.GreenHighlightColor | ||
|
||
# | ||
# Some runtime constants | ||
# | ||
PAGE_SIZE = 0x1000 |
Oops, something went wrong.