Skip to content

Add a Settings button so the server is easy to set - #56

Open
r0ny123 wants to merge 10 commits into
familiary:mainfrom
r0ny123:settings-button
Open

r0ny123 wants to merge 10 commits into
familiary:mainfrom
r0ny123:settings-button

Conversation

@r0ny123

@r0ny123 r0ny123 commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

After installing, the plugin points at http://127.0.0.1:8000/ and nothing in IDA or Binja tells you where to change that. Now there are three ways to get to the settings:

  • a Settings button on the toolbar
  • a Change... link next to the server name
  • a Settings entry in the menus (IDA: Edit → Plugins → MCRIT4IDA Settings..., Binja: Plugins → MCRIT → Settings)

In IDA it opens the Plugin Settings Manager on mcrit-ida if you have ida-settings-editor. Otherwise it shows a small form for the server, token, username and timeout. In Binja it goes straight to the MCRIT group in Settings. When you close it, the plugin reconnects right away. If you already have results from the old server, it keeps them and asks you to reopen before switching.

Also made the toolbar and tab icons follow the theme colour, since they were nearly invisible on dark themes. Tried it in IDA 9.4 and Binja 6.0 against a real MCRIT server.

How the Settings button decides what to open
flowchart TD
    A[Settings button, Change link or menu] --> B{Which app?}
    B -->|IDA with ida-settings-editor| C[Plugin Settings Manager on mcrit-ida]
    B -->|IDA without it| D[Small form: server, token, username, timeout]
    B -->|Binja| E[Settings, MCRIT group]
    C --> F[Closed or saved]
    D --> F
    E --> F
    F --> G{Results from the old server already loaded?}
    G -->|No| H[Reconnect right away]
    G -->|Yes| I[Keep them, ask to reopen to switch]
Loading
Screenshots (IDA 9.4 and Binja 6.0)

IDA, connected: the Settings button and the Change link

MCRIT form in IDA connected to an MCRIT 1.15.0 server, with the Settings button and the Change link

IDA, still on the default server: the hint points at the button

MCRIT form in IDA with a failed connection check and the hint to use the Settings button

IDA with ida-settings-editor: opens the Plugin Settings Manager on mcrit-ida

Plugin Settings Manager opened on mcrit-ida next to the MCRIT form

IDA without it: the built-in form

Built-in MCRIT settings form with server, API token, username and timeout

Binja: the sidebar, then Settings on the MCRIT group

MCRIT sidebar in Binary Ninja connected to an MCRIT 1.15.0 server, with the Settings button and the Change link Binary Ninja Settings opened on the MCRIT group

Closes #32

After installing, the plugin points at http://127.0.0.1:8000/ and
nothing inside IDA or Binary Ninja said where to change that.

There's now a Settings button on the toolbar, a "Change..." link on the
server line, and a Settings entry in the menus. In IDA it opens the
Plugin Settings Manager on mcrit-ida when ida-settings-editor is
installed, and otherwise a small form for the server, token, username
and timeout. In Binary Ninja it opens Settings on the MCRIT group.
Closing the settings, or saving the form, reconnects without reopening
the plugin. A new server only takes over while the plugin holds nothing
from the old one; otherwise it says to reopen.

The toolbar and tab icons now use the theme's text colour, so they show
up on dark themes.
The new waker test stubs the IDA modules itself, so it needs ida_expr, which IdaBackend now imports.
main added the Ghidra frontend, which has no Settings button, so the hint
after a failed connection check now names each frontend's own place to set
the server: Ghidra's is Tool Options > MCRIT.

@danielplohmann danielplohmann left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a much-needed fix for the first-run experience, and it is well built: connection checks run off the UI thread, stale checks are dropped by id, the fallback form saves only changed fields and greys out what config_override.json forces, and the keychain path is tested. Gates are green on 601ac73: ruff, 399 tests, and the three sync scripts.

Two things need fixing before merge; both are about what happens when the server changes while the session is busy.

1. An answer from the old server is stored after the switch. reloadSettings switches whenever _holdsServerData() is false, but a request that is still running counts as nothing held. Only querySampleSha256 and the family/sample downloads check client is not self.mcrit_client before storing. uploadReport (remote_sample_id = sample_entry.sample_id, McritInterface.py:269), getMatchingJobById and querySmdaFunctionMatches store unconditionally. Scenario: Upload against a slow server A, open Settings, switch to B, close. Nothing was held, so the client switches to B; then the upload returns and remote_sample_id holds A's id, which every following matching job and query sends to B. Reproduced with a test that swaps the client while addReport runs: remote_sample_id ends up set. Fix: the same identity guard in every method that writes session state, or count requests in flight and treat a non-zero count as held data, so the switch waits for them.

Inline: the token goes to the old server on a deferred switch (2), a token-only change drops valid answers (3), a palette read that may come too early in IDA (4), the menu action's __del__ (6), and CHANGELOG scoping.

Not verified on my side, so please confirm by hand before merge: the ida-settings-editor hook (ida_settings_show_plugin_settings, the "Plugin Settings Manager" caption, and that it opens non-modally so the close is noticed) and Binary Ninja's executeAction("Settings") plus the destroyed signal on closing the Settings tab; the tests only mock both.

Small things, fine as follow-ups: the fallback form shows a stored timeout outside 0..3600 as the clamped value; accept() validates the server field even when config_override.json forces it and the field is greyed out, so a malformed forced server blocks saving the other fields; a failed save keeps the keys already written but skips reloadSettings; after a server switch the remote sample is not looked up again; and https://x/api vs https://x/api/ count as different servers, also for SERVER_IS_DEFAULT.

Ghidra: only the hint text is in here, which is fine while Ghidra is unreleased. I'll add a Tool Options action plus an options listener calling reloadSettings() as a Ghidra follow-up.

🤖 Generated with Claude Code

Comment thread mcrit_plugin/core/McritInterface.py Resolved
Comment thread mcrit_plugin/core/McritInterface.py Resolved
Comment thread mcrit_plugin/ida/ida_mcrit.py Resolved
Comment thread CHANGELOG.md Resolved
Comment thread mcrit_plugin/ghidra/GhidraBackend.py Resolved
A request still running when the server changed stored its answer from the
old server: the upload's sample id, a matching result, function matches and
entries. Every request now pins the client and a server generation and drops
an answer whose server was replaced meanwhile, including the block-hash and
remote-function lookups the widgets cache.

The generation only moves with the server, so a token, username or timeout
change no longer throws away answers from the same server. While a new server
waits for a reopen, the session keeps the current server's token and username
too; only the timeout applies at once.

The toolbar and tab icons are tinted again when the palette or style changes,
so a theme switch while MCRIT is open recolors them.

IDA registers the Settings menu action once per process and finds the current
database's plugmod through a weak reference; tying it to a plugmod let a late
__del__ remove the next database's entry.

The changelog scopes the new entries to IDA and Binary Ninja, and Ghidra's
hint names Edit > Tool Options > MCRIT.
@r0ny123

r0ny123 commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for the thorough review! All of it is in e1dd145.

For (1), every request now pins its client plus a server generation and drops its answer if the server changed while it ran. That covers the upload, the matching result, function matches and entries, block matches and the remote function lookup. There's a test for each that switches the server mid-request.

On the two things you couldn't check: I tried both in the real apps. In IDA 9.4 with ida-settings-editor installed, the button opens the Plugin Settings Manager on mcrit-ida without blocking, and closing it reloads the settings. In Binja 6.0 the Settings tab opens on the MCRIT group, and closing the tab reconnects. Today on e1dd145 I also rechecked IDA without the editor: the menu entry opens our own form, in both the light and dark theme.

I also ran the PyGhidra integration against a local MCRIT on Ghidra 12.1.2 and today's 12.2, and both pass.

Happy to take the smaller follow-ups in a separate PR.

An answer could still slip in between the switch's check for held data and
its new client: the check runs on the UI thread while a worker stores its
answer. The check and the new client now happen under one lock, and every
request stores its answer under it too (_storing), so the switch sees the
stored answer and waits, or the answer sees the switch and is dropped.

The default-server hint asks about the session's server; with a switch
waiting, the settings hold the new one. When IDA's settings window opens but
cannot be found to watch, the status line says to reopen MCRIT to apply a
changed connection. The connection form also turns down a URL without a host
or with a port that is not a number up to 65535.

Tests cover the remote-function lookup, decode the results they store instead
of passing through a decoding error, and check that a stale connection check
really reached its result.
The earlier test only showed the switch side: removing the lock from
_storing left it passing. The session now refuses writes made without the
lock, for every request that stores an answer. The client-before-generation
write order is commented again, since _pinConnection reads both without the
lock.
Turning live tracking on queries the function the cursor is on, so the
Function Scope table could fill with that function's matches before the
jump to the target was handled; the run then failed its check that the
cursor move reached the Function Scope. It now waits until the table shows
the target function.
Moving either out of the lock left the tests green; now each has a test that
fails when it is.

@danielplohmann danielplohmann left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this round closes everything from the last review. The pinned client plus server generation, with the check and the store under _switch_lock, is the right shape: a switch either sees a stored answer and waits, or the answer sees the switch and is dropped. The deferred switch keeps the old token and username, a token-only change keeps answers from the same server, and the tint, __del__, CHANGELOG and Ghidra hint points are all addressed. CI is green on 5e71c40, and thanks for the IDA and Binja checks by hand.

One path is still outside the guard, and it is the same scenario as (1), so it has to go in before the next release:

Block matches are cached outside _storing. getMatchesForPicBlockHash checks _isStale when each lookup returns, but _lookupBlockHashes writes into self.parent.blockhash_matches afterwards, in the loop over pool.map (mcrit_plugin/ui_qt/widgets/BlockMatchWidget.py:298, same in mcrit_plugin/ghidra/ui/BlockMatchPanel.py:245), and without the lock. On a function's first block query the cache is still empty, so _holdsServerData() is false and a switch goes ahead. A lookup that returned before the switch has passed its staleness check, is stored after it, and the new session holds block matches from the old server. AGENTS.md now says every method that writes session state has to store inside _storing, and these two are the ones that do not yet. Suggest pinning once at the top of _lookupBlockHashes (or having getMatchesForPicBlockHash take a connection like queryFunctionEntriesById does) and doing the cache writes under with self.parent.mcrit_interface._storing(generation), with a test that switches the server between the lookups and the store. Both files are outside this PR's diff, which is why this is not an inline comment.

The small follow-ups from the last review (the clamped timeout display, accept() validating a forced server, the skipped reloadSettings after a failed save, the remote sample not looked up again after a switch, and the trailing-slash server comparison) are still fine in a separate PR, as you offered.

🤖 Generated with Claude Code

Block Scope cached its lookups after they all returned, outside the
lock. On a function's first block query the cache was still empty, so a
server switch could go ahead in between and the new session ended up
with block matches from the old server.

The Qt widget and the Ghidra panel now pin one connection for all their
lookups and hand the results to McritInterface.storeBlockMatches, which
writes them inside _storing and drops them if the server changed.
The first synthetic press on a tab header can land before the docked
MCRIT window takes input, which timed out once on CI. Press again up to
three times; a click that doesn't work at all still fails.
@r0ny123

r0ny123 commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

Good catch, fixed in 0514b73. Both block panels now pin one connection for all lookups and write the cache through storeBlockMatches, under _storing, so a switch in between drops them. Added a test that switches between the lookups and the store. The small follow-ups are in #60.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a Settings button that opens the Plugin Settings Manager, or explains how to configure the plugin

2 participants