patchlens

Rust MCP stdioサーバーを通じた、静的PE64バイナリの差分解析、シグネチャ検証、オフセットのエクスポート、リバースエンジニアリング分析。

ドキュメント

Patchlens

CI Release License: MIT Rust 1.88+ MCP

Patchlens is a Rust CLI and Model Context Protocol (MCP) server for static, function-level comparison of x64 Windows PE binaries. Give it an older build and a newer build to identify unchanged, modified, added, and removed functions; verify AOB or export-name signatures; suggest replacements for broken AOB signatures; explain disassembly changes; and emit CI/modding reports.

Patchlens never executes the analyzed binaries. The MCP server uses MCP over stdio: it reads JSON-RPC messages from stdin and writes protocol responses to stdout, while diagnostic logs go to stderr. It exposes five tools and is suitable for Claude Desktop, OpenCode, or another local MCP client.

Turkish / Türkçe: Patchlens, PE32+ (x64) binary build'lerini statik olarak fonksiyon düzeyinde karşılaştırır; AOB/export imzalarını doğrular, kırık imzalar için öneri üretir ve MCP üzerinden beş araç sunar. Binary'ler çalıştırılmaz.

Features

  • Function-level diffing: staged matching using exact fingerprints, string/import similarity, call-graph propagation, and fuzzy opcode similarity.
  • Signature checking: AOB byte patterns with ?? wildcards and exported-function-name signatures. Results are ok, moved, broken, or ambiguous.
  • Signature suggestions: compare the old and new build and generate a replacement signature for broken signatures when a match can be inferred.
  • Change explanations: inspect an individual function's instruction/disassembly changes with pagination.
  • Reports and exports: JSON, SARIF 2.1.0, C headers, and Cheat Engine .CT output.
  • Read-only analysis: files are opened read-only and memory-mapped; Patchlens does not modify or execute input binaries.

Patchlens accepts PE32+ / x64 files and intentionally rejects PE32 / x86 input. It can run on Linux, Windows, or macOS when built with Rust; the automated release workflow currently packages Linux x86_64 and Windows x86_64 artifacts.

Installation

Download a release

Download the archive for your platform from the GitHub Releases page. Release archives contain both patchlens and patchlens-mcp. On Linux, make the extracted files executable if necessary:

chmod +x patchlens patchlens-mcp

Build and install from source

Requirements: Rust 1.88 or newer and Cargo. From the repository root:

git clone https://github.com/RivaExits0/patchlens.git
cd patchlens

# Install the CLI and the MCP server on Cargo's binary path.
cargo install --path crates/patchlens-cli
cargo install --path crates/patchlens-mcp

For a workspace build without installing:

cargo build --workspace

The binaries are named patchlens and patchlens-mcp (with .exe on Windows).

Quick start

Generate the repository's synthetic PE64 fixtures:

cargo run --bin make_fixtures

Then compare them with the CLI:

patchlens diff tests/fixtures/old.exe tests/fixtures/new.exe --format text
patchlens sigs tests/fixtures/old.exe tests/fixtures/new.exe \
  --signatures tests/fixtures/signatures.toml --suggest
patchlens explain tests/fixtures/old.exe tests/fixtures/new.exe \
  --function 0x140001000
patchlens export tests/fixtures/old.exe tests/fixtures/new.exe \
  --signatures tests/fixtures/signatures.toml --format header --output offsets.h

diff defaults to a minimum match score of 0.75, a result limit of 100, and offset 0. Use --format json or --format sarif for structured output. explain defaults to 200 lines. export writes to stdout unless --output is supplied.

CLI commands

CommandPurpose
patchlens diff OLD NEWCompare two builds. Formats: text, json, sarif; supports --min-score, --limit, and --offset.
patchlens sigs OLD NEW --signatures FILECheck a TOML signature set; --suggest adds replacement suggestions and --sarif FILE writes a SARIF report.
patchlens explain OLD NEW --function ADDR|NAMEExplain one function's change by hexadecimal address or function name; supports --limit and --offset.
patchlens export OLD NEW --signatures FILEExport offsets as header, ct, json, or sarif; use --output FILE to write a file.

Exit codes are 0 for success, 1 when the signature check finds a broken signature, and 2 for usage or I/O errors.

Signature files

A signature file is TOML with a signatures array. Use either an AOB pattern or an exported function name:

[[signatures]]
name = "player_health_get"
kind = "Aob"
pattern = "48 8B 05 ?? ?? ?? ?? 48 85 C0 74 ?? 8B 40 10"
expected_offset = 0x3A20
description = "Player health getter"

[[signatures]]
name = "update_player"
kind = "ExportName"
function_name = "UpdatePlayer"
FieldRequiredNotes
nameYesUnique signature identifier.
kindYesAob or ExportName.
patternFor AobSpace-separated bytes; ?? is a wildcard.
function_nameFor ExportNameExact exported function name.
expected_offsetNoExpected RVA in the old build; a different single match is moved.
descriptionNoHuman-readable description.

MCP server

Start the server directly after building or installing it:

patchlens-mcp

The server uses the rmcp stdio transport. It does not expose an HTTP, SSE, or network listener. Input paths are local filesystem paths visible to the process. Signature sets can be supplied inline as TOML or through signatures_path, depending on the tool.

Claude Desktop

Add the following to claude_desktop_config.json. If the binary is not on PATH, replace patchlens-mcp with its absolute path.

{
  "mcpServers": {
    "patchlens": {
      "command": "patchlens-mcp",
      "args": [],
      "env": {}
    }
  }
}

On Windows, an absolute path uses escaped backslashes, for example C:\\Tools\\patchlens-mcp.exe.

OpenCode

Add the local MCP server to opencode.json:

{
  "mcp": {
    "patchlens": {
      "type": "local",
      "command": ["patchlens-mcp"],
      "enabled": true
    }
  }
}

Available MCP tools

All tools return structured text/JSON results. old_path and new_path are required local paths to PE64 binaries.

ToolInputs and behavior
diff_buildsCompares functions. Optional min_score defaults to 0.75; limit defaults to 50 and is capped at 500; offset defaults to 0.
check_signaturesChecks a TOML signature set supplied through signatures or signatures_path. Set suggest: true to suggest replacements for broken signatures.
explain_changeExplains one function selected by a 0x address, function name, or export name. limit defaults to 200, is capped at 500, and offset defaults to 0.
ci_reportGenerates sarif (the default) or json. A signature set may be supplied inline or by path.
export_offsetsExports header (the default), ct, json, or sarif; a signature set may be supplied inline or by path.

The server keeps an in-process analysis cache keyed by file path, size, and modification time. The cache is not a persistent database and is not shared between processes.

Security and limitations

Patchlens is intended for binaries you own or are authorized to analyze, including single-player modding and security research. It is not an anti-cheat or DRM-bypass tool.

  • Static only: the target binaries are parsed and disassembled; they are never executed.
  • Read-only inputs: the core opens files read-only and uses a read-only memory map. Output files are written only when you explicitly request them through CLI options or redirect output.
  • No application network access: the CLI and MCP server operate on the local paths you provide and do not upload binaries or open a network listener. An MCP host may still have its own permissions and network behavior.
  • Format scope: only PE32+ / x64 is supported; PE32 / x86 and other binary formats are rejected.
  • Resource use: analysis time and memory depend on binary size and function count. Matching can be conservative, and a signature may be ambiguous when multiple matches exist. A suggestion is a candidate to review, not a guarantee of correctness.
  • Path permissions: the process must be able to read the input files and write any requested output path.

Only use Patchlens where permitted by the software license, EULA, and applicable law.

Testing and development

Run the same checks used by CI from the repository root:

cargo fmt --all -- --check
cargo clippy --workspace --all-targets -- -D warnings
cargo build --workspace --all-targets
cargo run --bin make_fixtures
cargo test --workspace --all-targets

Compile benchmarks without running them:

cargo bench --workspace --no-run

For a real-binary integration smoke test (ignored by default), provide two PE64 executables:

PATCHLENS_OLD=/path/to/old.exe PATCHLENS_NEW=/path/to/new.exe \
  cargo test --package patchlens-core --test integration_test real_pe_diff -- --ignored

Run the PE parser fuzz target with the nightly toolchain and cargo-fuzz:

cargo +nightly fuzz run fuzz_pe_parse

The fuzz target is in fuzz/fuzz_targets/fuzz_pe_parse.rs; CI does not run it. The fixture generator writes tests/fixtures/old.exe, tests/fixtures/new.exe, and tests/fixtures/signatures.toml.

Project layout

crates/patchlens-core/   Binary loading, PE parsing, function extraction, diffing,
                         signatures, reports, and cache
crates/patchlens-cli/    `patchlens` CLI
crates/patchlens-mcp/    `patchlens-mcp` stdio MCP server
tools/make_fixtures/     Synthetic PE64 fixture generator
fuzz/                   cargo-fuzz targets
tests/                  Fixtures and integration tests

License

MIT. See LICENSE.

Links