Skip to content

Fetch a match's remote function off the UI thread - #40

Merged
danielplohmann merged 4 commits into
familiary:mainfrom
r0ny123:binja-match-graph-requests
Oct 12, 2026
Merged

danielplohmann merged 4 commits into
familiary:mainfrom
r0ny123:binja-match-graph-requests

Conversation

@r0ny123

@r0ny123 r0ny123 commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

This builds on #35, which builds on #33 and #31; the diff shows their commits until they merge, and only 03b3ece is new. It was rebased onto #35 so that the remote-function request passes the title #35 gives Backend.run_request; on #31 alone, merging #35 afterwards left this request calling it with two arguments, and opening a match's graph raised TypeError on both plugins. #36 builds on this PR and applies its local tint in the callback that runs when the remote function arrives.

Double clicking a function match, a function id in the names table, or a block match opens the remote function's graph. Before it could, the handler downloaded that function with its CFG and then the entry of its sample, both on the UI thread. The table below breaks that down for the largest function of sample e0b6f853… (3,955 instructions, 1,361 blocks), whose match on mcrit.malpedia.io is a function of the same size:

step time
getFunctionById(…, with_xcfg=True) 2.16 s
getSampleById 1.33 s
toSmdaFunction 0.02 s
FunctionCfgMatcher.getColoredMatches 0.09 s
building the graph report about 0.04 s

The network calls are almost all of it. McritInterface.queryRemoteFunction now fetches the function and its sample and touches no widget. The three handlers run it through Backend.run_request, then match and draw when the answer arrives. The sample entry comes from the sample list the plugin already downloaded during Convert, and only a sample missing from it is requested.

sequenceDiagram
  participant UI as UI thread
  participant W as request thread
  participant S as MCRIT server
  UI->>W: double click: queryRemoteFunction(id)
  Note over UI: click returns, Binary Ninja stays usable
  W->>S: GET function with CFG
  S-->>W: function entry
  Note over W: sample entry from the downloaded list
  W-->>UI: (function, SmdaFunction, sample)
  Note over UI: match, colour, show the graph (about 0.1 s)
Loading

Double clicking that match in Binary Ninja 6.0 against mcrit.malpedia.io, three times each:

#31 this PR
click returns after 3.36–3.58 s 0.00 s
graph opens after 3.32–3.54 s 2.07–2.20 s
longest UI stall 3.36–3.58 s 0.11–0.12 s

On IDA, run_request still runs synchronously, so the double click blocks as before, minus the sample request when the sample list is loaded.

tests/core/test_mcrit_interface.py covers queryRemoteFunction in three cases:

  • the sample comes from the downloaded list;
  • a sample missing from the list is requested;
  • a missing function or sample is reported and returns None.

The Binary Ninja GUI test now waits for each of the three graphs. It checks that the click returns before the graph opens and that the remote function is fetched off the UI thread. Against a local MCRIT 1.12.0 it passes all 179 checks. pytest gives 214 passed, and run_quality_checks.py and the sync checks pass. The IDA tests were not run.

Double clicking a function match, a name's function id or a block match
downloaded the remote function with its CFG and then its sample entry,
on the UI thread, before matching it and opening its graph. For the
largest function of a 2,329-function sample (3,955 instructions) against
mcrit.malpedia.io that froze Binary Ninja for about 3.5 s: 2.2 s for the
function, 1.3 s for the sample entry, 0.1 s for the matcher.

McritInterface.queryRemoteFunction fetches both and touches no widget.
The three handlers run it through Backend.run_request and match and
draw when the answer arrives. The sample entry comes from the sample
list already downloaded when it has it, which saves the second request.
On IDA, run_request still runs synchronously, so IDA blocks as before,
minus that request.

Double clicking that match in Binary Ninja 6.0, three times each:

                         before          after
  click returns after    3.36-3.58 s     0.00 s
  graph opens after      3.32-3.54 s     2.07-2.20 s
  longest UI stall       3.36-3.58 s     0.11-0.12 s

The Binary Ninja GUI test waits for each of the three graphs and checks
that the click returns before the graph opens and that the remote
function is fetched off the UI thread.
# Conflicts:
#	mcrit_plugin/ui_qt/widgets/FunctionMatchWidget.py
danielplohmann
danielplohmann previously approved these changes Oct 12, 2026

@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 looks good. The worker touches no widget, and the callbacks keep the local function and the block matches from the click, so a cursor move during the fetch cannot mix up the graph. Both calls pass the title #35 added, and IDA's synchronous path still opens the graph from the callback. Reading sample_infos from the worker is safe, since it is only ever replaced, never changed in place.

It merges into main without conflicts. Lint, the sync checks and the suite (229 tests) pass on the merged tree, and the new queryRemoteFunction tests fail without the change. I could not run the Binary Ninja or IDA integration tests.

A few small points, none blocking:

  • After a successful fetch the activity line still says "Fetching function N for the graph viewer...". show() could replace it when the graph opens.
  • On a failed request, _reportFailure posts the reason and "Failed to fetch function entry N." then overwrites it. That was already so before, but it would be easy to keep the reason now.
  • A second double-click on the same row while the first fetch runs opens two identical graphs. Ignoring a repeat for a function already being fetched would avoid that.
  • The changelog entry could say that on IDA the click still blocks, minus the sample request.

The approval will only count after main is merged in, since #35 moved the merge-base.

@r0ny123
r0ny123 dismissed danielplohmann’s stale review October 12, 2026 09:00

The merge-base changed after approval.

# Conflicts:
#	CHANGELOG.md
danielplohmann
danielplohmann previously approved these changes Oct 12, 2026

@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. The merge of main (6657f1e) keeps every changelog bullet. Lint, the sync checks and the suite (232 tests) pass on it. Approving again; the earlier small points stay optional.

@danielplohmann

Copy link
Copy Markdown
Collaborator

#37 is merged, so this needs main merged in once more. The only conflict is in CHANGELOG.md: keep every Unreleased/Changed bullet, main's first. I'll approve again after your push.

# Conflicts:
#	CHANGELOG.md

@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. The merge of main (1a33418) keeps every changelog bullet. Lint, the sync checks and the suite (240 tests) pass on it. Approving again.

@danielplohmann
danielplohmann merged commit 1fdb120 into familiary:main Oct 12, 2026
10 checks passed
@r0ny123
r0ny123 deleted the binja-match-graph-requests branch October 15, 2026 19:49
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.

2 participants