Skip to content
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Lint, tests, packaging and metadata checks are listed in
## Architecture primer

- **Entry** (`mcrit_plugin/ida/ida_mcrit.py`) registers IDA menus/actions/hotkeys and the MCRIT widget subviews.
- **`McritInterface`** owns the connection to the MCRIT server. Uploads, the Function and Block Scope queries, fetching a matching result and fetching labels go through `Backend.run_request`: on Binary Ninja they run as background tasks, named in the status bar; on IDA they run on a small worker pool and a queued Qt signal hands each result back to the main thread (not an IDA timer: requests start inside the cursor-settle timer's callback, and IDA 9.4 hangs in `register_timer` called there); headless runs them synchronously. The widgets drop a live query's answer once the cursor has moved to another function. The connection check, the family and sample list download and the lookup of the converted sample also run in the background. IDA's API is main-thread only: on IDA, `run_background` work runs on a worker too, the backend methods that read the database run on the main thread through `execute_sync`, and the export reads the database into a snapshot there (`SmdaInterfaceSnapshot`, through smda's IDAPython backend rather than its slower ida_domain one) before disassembling and hashing it on the worker.
- **`McritInterface`** owns the connection to the MCRIT server. Uploads, the Function and Block Scope queries, fetching a matching result and fetching labels go through `Backend.run_request`: on Binary Ninja they run as background tasks, named in the status bar; on IDA they run on a small worker pool and a queued Qt signal hands each result back to the main thread (not an IDA timer: requests start inside the cursor-settle timer's callback, and IDA 9.4 hangs in `register_timer` called there); headless runs them synchronously. The widgets drop a live query's answer once the cursor has moved to another function. The connection check, the family and sample list download and the lookup of the converted sample also run in the background. IDA's API is main-thread only: on IDA, `run_background` work runs on a worker too, the backend methods that read the database run on the main thread through `execute_sync`, and the export reads the database into a snapshot there (`SmdaInterfaceSnapshot`, through smda's IDAPython backend rather than its slower ida_domain one) before disassembling and hashing it on the worker. A request pins its client and server generation with `_pinConnection` and stores its answer inside `with self._storing(generation)`, so an answer from a server the session left is dropped; every new method that writes session state has to do the same.
- **`McritClient`** (internalized under `mcrit_plugin/core/minimcrit/`) is the HTTP client speaking the MCRIT REST API. The plugin intentionally vendors a minified copy of the core client so it has no hard dependency on the `mcrit` package.
- **IDB→SMDA conversion** uses SMDA (optionally as the analysis backend via `use_smda_for_analysis`); results feed matching and label sync.
- **Widgets** render matches/blocks/functions/overview and are built on PySide6 through `QtShim`.
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ Ninja or Ghidra applies to that plugin only.
CFGs open in Ghidra's graph view, and the settings are under Tool Options > MCRIT. It runs from
this repository's `ghidra_scripts` folder; see the README for setup. Not released yet; versioned
on its own from 0.1.0.
- IDA and Binary Ninja: a Settings button on the toolbar, a "Change..." link on the remote server
line, and a Settings entry in the menus (IDA: Edit → Plugins → MCRIT4IDA Settings...; Binary
Ninja: Plugins → MCRIT → Settings). In IDA they open the Plugin Settings Manager on mcrit-ida when
`ida-settings-editor` is installed; in Binary Ninja, Settings on the MCRIT group. Without the
settings editor, IDA shows the plugin's own form for the server, API token, username and timeout;
it saves only the fields you changed, greys out the ones `config_override.json` forces, and
connects again at once. Closing the settings window or tab opened this way also picks up a
changed token, username or timeout without reopening the plugin. A changed server is picked up
the same way until the plugin holds results from the current one; after that, it says so, keeps
the current server with its token and username, and reopening the plugin switches. An answer
that arrives from the previous server after a switch is dropped.
- A failed connection check while the server is still the default `http://127.0.0.1:8000/` points
at the Settings button (Ghidra: Edit > Tool Options > MCRIT).

### Fixed

Expand All @@ -26,6 +39,9 @@ Ninja or Ghidra applies to that plugin only.
example, branch targets kept their exact bytes. The escaping now follows the report's
architecture; one without an SMDA escaper keeps its raw bytes. Copy Escaped Bytes falls back to
raw bytes like the rule text when escaping fails, instead of copying nothing.
- IDA and Binary Ninja: the toolbar and tab icons take the theme's text color, also after a theme
change, so they are visible on dark themes; disabled toolbar icons show dimmed instead of almost
black.

## [2.1.1] - 2026-10-15

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ For offline machines, each release has a wheelhouse bundle: unpack it and run `p
Settings are handled by [ida-settings](https://github.com/williballenthin/ida-settings):

- HCLI: `hcli plugin config mcrit-ida set mcrit_server https://mcrit.example.com/api/` (`list`, `get`, `export` and `import` also work)
- GUI: install `ida-settings-editor` and use Edit → Plugins → Plugin Settings Manager
- GUI: the Settings button on the MCRIT toolbar (also Edit → Plugins → MCRIT4IDA Settings...). With `ida-settings-editor` installed it opens the Plugin Settings Manager on mcrit-ida; without it, a small form for the server, API token, username and timeout.
- File: put a `config_override.json` next to `ida_mcrit.py`. Its keys take precedence over the other two, so keep only the ones you want to force; `docs/config_override.json.template` shows the format, and the plugin prints the keys it forces when it loads.

### Use
Expand All @@ -79,7 +79,7 @@ Install MCRIT from the Extension Manager, or clone this repository into your Bin

### Configure

Settings are under Settings → MCRIT, with the same keys as the IDA plugin. Where a system keychain is available, an API token entered there is moved into it and the field is cleared; otherwise the token stays in the Settings entry. Plugins → MCRIT → Clear Stored API Token removes it. The sidebar reads the connection settings (server, token, username, timeout) when it opens for a file, so reopen the file after changing them. A `config_override.json` in the plugin's folder, next to `plugin.json`, takes precedence as it does in IDA.
Settings are under Settings → MCRIT, with the same keys as the IDA plugin; the Settings button on the sidebar toolbar and Plugins → MCRIT → Settings open them there. Where a system keychain is available, an API token entered there is moved into it and the field is cleared; otherwise the token stays in the Settings entry. Plugins → MCRIT → Clear Stored API Token removes it. The sidebar reads the connection settings (server, token, username, timeout) when it opens for a file, and again when you close the Settings tab its button opened (a different server only until the sidebar holds results from the current one); after changing them any other way, reopen the file. A `config_override.json` in the plugin's folder, next to `plugin.json`, takes precedence as it does in IDA.

### Use

Expand Down
Binary file added icons/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions mcrit_plugin/binja/BinjaBackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
class BinjaBackend(Backend):
name = "Binary Ninja"
plugin_name = "MCRIT4BinaryNinja"
reopen_hint = "reopen the file"

def __init__(self, bv):
self.bv = bv
Expand Down Expand Up @@ -247,6 +248,31 @@ def show_warning(self, message):
TITLE, message, MessageBoxButtonSet.OKButtonSet, MessageBoxIcon.WarningIcon
)

def open_settings(self, config):
from binaryninjaui import SettingsView, UIContext
from PySide6.QtWidgets import QApplication

from mcrit_plugin.binja.config import GROUP

context = UIContext.activeContext() or next(iter(UIContext.allContexts()), None)
if context is not None:
# the "Settings" action opens the Settings tab, or brings an open one to the front
context.globalActions().executeAction("Settings")
views = [w for w in QApplication.allWidgets() if isinstance(w, SettingsView)]
# with several windows open, watch the tab this window just showed
views.sort(key=lambda view: not context.mainWindow().isAncestorOf(view))
for view in views:
view.setDefaultGroupSelection(GROUP)
if views:
return views[0]
return None

def save_settings(self, values):
from mcrit_plugin.binja.config import set_setting

for key, value in values.items():
set_setting(key, value)

def theme_color(self, role, default):
try:
from binaryninjaui import getThemeColor
Expand Down
1 change: 1 addition & 0 deletions mcrit_plugin/binja/McritSidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def _has_report(session):
# (action name, handler(session) or None to only open the sidebar, enabled(session) or None when always available)
_ACTIONS = [
("MCRIT\\Show Sidebar", None, None),
("MCRIT\\Settings", lambda session: session.main_widget._onSettingsButtonClicked(), None),
(
"MCRIT\\Convert to SMDA Report",
lambda session: session.main_widget._onConvertSmdaButtonClicked(),
Expand Down
19 changes: 19 additions & 0 deletions mcrit_plugin/binja/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ def _get_secret(key, settings):
raise KeyError(key)


def set_setting(key, value):
full_key = f"{GROUP}.{key}"
settings = Settings()
if key in SECRET_SETTINGS:
provider = SecretsProvider.get(KEYCHAIN_PROVIDER)
if provider is not None and provider.has_data(full_key):
provider.delete_data(full_key)
settings.reset(full_key)
if value:
# moved into the keychain by the next read, as for a value typed into Settings
settings.set_string(full_key, value)
elif key in NUMBER_SETTINGS:
settings.set_integer(full_key, int(value))
elif isinstance(value, bool):
settings.set_bool(full_key, value)
else:
settings.set_string(full_key, value)


def clear_stored_secrets():
provider = SecretsProvider.get(KEYCHAIN_PROVIDER)
settings = Settings()
Expand Down
19 changes: 19 additions & 0 deletions mcrit_plugin/core/Backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,25 @@ def ask_yes_no(self, prompt):
def show_warning(self, message):
"""Modal warning."""

# shown under the plugin's own connection form, e.g. where the remaining settings live
settings_hint = ""
# what rebuilds the session, so a new server can take over
reopen_hint = "reopen MCRIT"
# where the user changes the server, named in the hint after a failed connection check
settings_location = "the Settings button"

def open_settings(self, config):
"""Open the disassembler's own settings UI on this plugin and return its QWidget, or True
when it opened but cannot be watched for closing.

None means there is none, and the plugin shows its own connection form instead.
"""
return None

def save_settings(self, values):
"""Store the connection form's values (setting key -> value) in the settings store."""
raise NotImplementedError

def theme_color(self, role, default):
"""RGB tuple for a ScoreColorProvider.ThemeRole; None keeps the widget's own color and is
valid only for TEXT_ON_TINT.
Expand Down
1 change: 1 addition & 0 deletions mcrit_plugin/core/HeadlessMcritContext.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ def __init__(self, config, backend):
self.family_infos = None
self.function_id_to_offset = {}
self.function_matches = {}
self.blockhash_matches = {}
self.mcrit_interface = McritInterface(self, backend)
Loading
Loading