Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions ext_bn/retsync/retsync/rswidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
import binaryninjaui
if 'qt_major_version' in binaryninjaui.__dict__ and binaryninjaui.qt_major_version == 6:
from PySide6 import QtCore
from PySide6.QtCore import Qt
from PySide6.QtCore import Qt, QRectF
from PySide6.QtWidgets import QApplication, QHBoxLayout, QVBoxLayout, QLabel, QWidget
from PySide6.QtGui import QKeySequence
from PySide6.QtGui import QKeySequence, QImage, QPainter, QFont, QColor
else:
from PySide2 import QtCore
from PySide2.QtCore import Qt
from PySide2.QtCore import Qt, QRectF
from PySide2.QtWidgets import QApplication, QHBoxLayout, QVBoxLayout, QLabel, QWidget
from PySide2.QtGui import QKeySequence
from PySide2.QtGui import QKeySequence, QImage, QPainter, QFont, QColor

from binaryninjaui import UIAction, UIActionHandler
from binaryninjaui import DockContextHandler
from binaryninjaui import SidebarWidget, SidebarWidgetType, SidebarWidgetLocation, SidebarContextSensitivity


from .rsconfig import rs_log
Expand All @@ -48,12 +48,11 @@ class SyncStatus(object):
RUNNING = "connected"


# based on hellodockwidget.py
# based on hellosidebar.py
# from https://github.com/Vector35/binaryninja-api/
class SyncDockWidget(QWidget, DockContextHandler):
def __init__(self, parent, name, data):
QWidget.__init__(self, parent)
DockContextHandler.__init__(self, self, name)
class SyncDockWidget(SidebarWidget):
def __init__(self, name, frame, data):
SidebarWidget.__init__(self, name)
self.actionHandler = UIActionHandler()
self.actionHandler.setupActionHandler(self)

Expand Down Expand Up @@ -119,6 +118,28 @@ def reset_status(self):
self.client_pgm.setText('n/a')
self.client_dbg.setText('n/a')

@staticmethod
def create_widget(name, parent, data=None):
return SyncDockWidget(parent, name, data)
class SyncDockWidgetType(SidebarWidgetType):
def __init__(self, plugin):
self.plugin = plugin
icon = QImage(56, 56, QImage.Format_RGB32)
icon.fill(0)
# Render an "H" as the example icon
p = QPainter()
p.begin(icon)
p.setFont(QFont("Open Sans", 56))
p.setPen(QColor(255, 255, 255, 255))
p.drawText(QRectF(0, 0, 56, 56), Qt.AlignCenter, "R")
p.end()

SidebarWidgetType.__init__(self, icon, "RetSync")

def createWidget(self, frame, data):
widget = SyncDockWidget("RetSync", frame, data)
self.plugin.widget = widget
return widget

def defaultLocation(self):
return SidebarWidgetLocation.RightContent

def contextSensitivity(self):
return SidebarContextSensitivity.SelfManagedSidebarContext
33 changes: 17 additions & 16 deletions ext_bn/retsync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@
from PySide2 import QtCore
from PySide2.QtCore import Qt

from binaryninjaui import DockHandler
from binaryninjaui import UIAction, UIActionHandler, UIContext, UIContextNotification
from binaryninjaui import ViewFrame
from binaryninjaui import ViewFrame, Sidebar

from binaryninja.plugin import BackgroundTaskThread, PluginCommand

Expand All @@ -52,7 +51,7 @@

from .retsync import rsconfig as rsconfig
from .retsync.rsconfig import rs_encode, rs_decode, rs_log, rs_debug, load_configuration
from .retsync.rswidget import SyncDockWidget
from .retsync.rswidget import SyncDockWidgetType


class SyncHandler(object):
Expand Down Expand Up @@ -362,7 +361,7 @@ def run(self):
rs_log('server started')
asyncore.loop()
except Exception as e:
rs_log('server initialization failed')
rs_log(f'server initialization failed: {e}')
self.cancel()
self.plugin.cmd_syncoff()

Expand Down Expand Up @@ -435,9 +434,10 @@ def as_list(self):

def list_dyn(self):
self.opened = {}
dock = DockHandler.getActiveDockHandler()
view_frame = dock.getViewFrame()

ui_ctx = UIContext.activeContext()
view_frame = None
if ui_ctx:
view_frame = ui_ctx.getCurrentViewFrame()
if view_frame:
frames = view_frame.parent()
for i in range(frames.count()):
Expand Down Expand Up @@ -479,10 +479,7 @@ def __init__(self):
self.cb_trace_enabled = False

def init_widget(self):
dock_handler = DockHandler.getActiveDockHandler()
parent = dock_handler.parent()
self.widget = SyncDockWidget.create_widget("ret-sync plugin", parent)
dock_handler.addDockWidget(self.widget, Qt.BottomDockWidgetArea, Qt.Horizontal, True, False)
Sidebar.addSidebarWidgetType(SyncDockWidgetType(self))

def OnAfterOpenFile(self, context, file, frame):
self.pgm_mgr.add(file.getRawData().file.original_filename)
Expand Down Expand Up @@ -524,8 +521,9 @@ def OnViewChange(self, context, frame, type):
self.current_tab = None

def bootstrap(self, dialect):
self.pgm_mgr.reset_bases()
self.widget.set_connected(dialect)
self.pgm_mgr.reset_bases()
if self.widget:
self.widget.set_connected(dialect)

if dialect in rsconfig.DBG_DIALECTS:
self.dbg_dialect = rsconfig.DBG_DIALECTS[dialect]
Expand All @@ -535,14 +533,16 @@ def reset_client(self):
self.sync_enabled = False
self.cb_trace_enabled = False
self.current_pgm = None
self.widget.reset_client()
if self.widget:
self.widget.reset_client()

def broadcast(self, msg):
self.client.send(rs_encode(msg))
rs_log(msg)

def set_program(self, pgm):
self.widget.set_program(pgm)
if self.widget:
self.widget.set_program(pgm)
if not self.pgm_mgr.exists(pgm):
return
self.sync_enabled = True
Expand Down Expand Up @@ -786,6 +786,7 @@ def cmd_syncoff(self, ctx=None):
if self.client_listener:
self.client_listener.cancel()
self.client_listener = None
self.widget.reset_status()
if self.widget:
self.widget.reset_status()
else:
rs_log('not listening')