fix(mcp): function pagination drops blank lines at page boundaries

未關閉
#8,717 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 2 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
42/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
cpp

研究方向

The report identifies bn_function_decompile and bn_function_disassembly in the built-in GUI MCP server, whose implementation ships inside the proprietary application. Start by reading the MCP guide’s “Ranges, Queries, and Pagination” section, then inspect the available tool implementation or tests if accessible. Reproduce with the supplied fixture and compare full output, concatenated pages, and counts while retaining the interior blank line.

由索引模型根據 Issue 內容生成。

描述

Summary

bn_function_decompile and bn_function_disassembly report line counts that exceed the lines delivered in their fenced code blocks. For decompilation, concatenating successive pages also loses a blank line present in the unpaged output. This makes the text depend on page boundaries and prevents a client from reconstructing the same rendered function by following nextOffset.

Steps to reproduce

  1. Save the C source below as fixture.c, compile it, and open fixture in Binary Ninja. Enable and start the built-in GUI MCP server, then connect an MCP client and run tools/list.
#include <stdio.h>
volatile int fixture_global = 7;
__attribute__((noinline, used)) int fixture_leaf(int value) { puts("FIXTURE_LEAF"); return value + fixture_global; }
__attribute__((noinline, used)) int fixture_branch(int value) { return value > 3 ? fixture_leaf(value) : fixture_leaf(-value); }
int main(int argc, char **argv) { return fixture_branch(argc); }
clang -arch arm64 -O0 -g -fno-inline fixture.c -o fixture
  1. Call bn_binary_view_list, select the returned Mach-O view with bn_binary_view_set_active, and wait until bn_analysis_status reports IdleState. Use the returned handle unchanged; handle values are session-scoped.

  2. Call bn_function_decompile with {"function":"_fixture_branch","offset":0,"limit":1000} and count lines inside its code fence, excluding the opening/closing fences. Keep interior blank lines.

  3. Request the same function with (offset, limit) values (0, 2), (2, 3), (5, 3), and (8, 5), following each returned nextOffset. Concatenate the code-fence contents without adding separator lines and compare with step 3.

  4. Call bn_function_disassembly with {"function":"_fixture_branch","offset":0,"limit":1000} and compare its metadata with the code-fence line count.

Expected behavior

The tool schemas describe offset as a zero-based line or item offset and limit as the maximum function lines or items returned. The guide instructs clients to continue with nextOffset. Following that pagination should preserve the rendered function, including blank lines that appear inside the unpaged reply, and count should describe the returned lines consistently.

Actual behavior

The full decompile reply reported count: 10, total: 10, but contained eight code lines:

  int32_t _fixture_branch(int value)

{
    if (value <= 3)
        return _fixture_leaf(0 - value);

    return _fixture_leaf(value);
}

The four pages returned these results. Counts below include blank lines inside the fence, but exclude the fences themselves.

offset limit count total nextOffset truncated code lines received
0 2 2 10 2 true 1
2 3 3 10 5 true 2
5 3 3 10 8 true 3
8 5 2 10 null false 1

The concatenated pages contained seven lines: the blank line between the prototype and { disappeared, while the interior blank line in the third page survived. The full disassembly reply similarly reported count: 30, total: 30, but delivered 28 code lines. All observations came from the same analyzed function; the numbers describe this fixture, not a population-wide failure rate.

Evidence

  • Expected source: Installed tools/list schemas for both function rendering tools and the guide's “Ranges, Queries, and Pagination” section; versioned guide links appear under Runtime or environment.
  • Failure source: Direct raw HTTP tools/call replies for the full decompile, four pages, and full disassembly; the exact calls and meaningful results are transcribed above.
  • Evidence provenance: observed
  • Local verification: reproduced
  • Reproduction completeness: complete

Restoration check

For the supplied fixture, compare full and paged code-fence text while retaining blank lines: concatenating all pages must produce the same line sequence as the full reply, and each reply's metadata must consistently account for the lines delivered. Check both decompile and disassembly. Retain an interior blank line as a control so a pass cannot result from discarding every blank line.

Runtime or environment

  • Binary Ninja Version: Free 6.0.10905-Stable; bundle version 6.0.10905_free; built-in GUI HTTP MCP server binaryninja_ui_mcp version 0.1.0.
  • Edition: Free. OS: macOS 27.2; CPU architecture: arm64. Target: thin arm64 Mach-O built with the command above. Analysis status was IdleState before the observations.
  • The official stable release metadata matched the installed build. A fresh profile enabled ui.mcp.enabled; no user plugins or existing databases were involved. The target was analyzed, never executed, and no database was saved.
  • The stable MCP guide and the current default-branch MCP guide were compared. Their relevant calling conventions agree. The implementation ships inside the proprietary application, so public default-branch source inspection does not verify its runtime behavior.
  • The issue template requests development-build testing. That was not performed: Free cannot switch to the development channel. Personal/Commercial editions, development builds, Windows, and Linux are untested.

References

Closed issue #3292 requested adding arbitrary blank lines in the decompiler UI. Its body and full discussion concern rendering customization, not MCP pagination. This report concerns losing a line already present in the MCP tool's own full reply; it does not request that declined UI feature.

Triage assessment

  • Impact level: P2
  • Assessment status: supported
  • Impact basis: Function text changes when retrieved in pages, and reported counts cannot be reconciled with the delivered code lines. The observed loss is blank-line formatting, not missing instructions or changed analysis.
  • Workaround status: available
  • Workaround basis: For this small fixture, a single full decompile request preserves the interior blank line that paging loses. This was verified; the workaround does not establish a way to preserve arbitrary larger functions beyond the tool's 1000-line page cap.
主要語言
C++
星號
1.3k
分支
304
平均合併
2 天 20 小時
30 天內合併 PR
10

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

Vector35/binaryninja-api 的其他 Issue

查看 Vector35/binaryninja-api 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。