x64dbg-MCP Server is a native MCP (Model Context Protocol) plugin for x64dbg that exposes the debugger's full functionality over HTTP. Connect any MCP-compatible AI assistant and control x64dbg programmatically: set breakpoints, step through code, read memory, dump registers, and more. Built with Zig — zero dependencies, single-binary output, cros
Zig ai-agentsai-debuggingbinary-analysisclaudeclaude-codemalware-analysismalware-researchmalware-scannermcpmcp-servermcp-serversx64dbgx64dbg-mcpx64dbg-pluginx64dbg-toolsxdbgzigzig-langziglang
fix: data race, JSON truncation, category filter, conditional bp — v1.8
duty1gfc66a36676bd
diff --git a/build.zig b/build.zigindex 814531d..f789850 100644--- a/build.zig+++ b/build.zig@@ -12,7 +12,6 @@ pub fn build(b: *std.Build) void {.abi = .gnu,}),.optimize = optimize,- .single_threaded = true,});x32_mod.linkSystemLibrary("kernel32", .{});x32_mod.linkSystemLibrary("ws2_32", .{});@@ -40,7 +39,6 @@ pub fn build(b: *std.Build) void {.abi = .gnu,}),.optimize = optimize,- .single_threaded = true,});x64_mod.linkSystemLibrary("kernel32", .{});x64_mod.linkSystemLibrary("ws2_32", .{});diff --git a/src/core/mcp_server.zig b/src/core/mcp_server.zigindex 7c06668..0c76b97 100644--- a/src/core/mcp_server.zig+++ b/src/core/mcp_server.zig@@ -12,7 +12,7 @@ const INVALID_SOCKET = ws2.INVALID_SOCKET;const PROTOCOL_VERSION = "2024-11-05";const SERVER_NAME = "x64dbg-MCP Server";-pub const SERVER_VERSION = "1.7";+pub const SERVER_VERSION = "1.8";// Win32 threadingconst HANDLE = ?*anyopaque;@@ -565,6 +565,10 @@ fn handleToolsCall(sock: SOCKET, id: ?std.json.Value, root: std.json.Value) voidvar buf: [131072]u8 = undefined;var w = JsonWriter.init(&buf);buildToolsCallResult(&w, root);+ if (w.overflow) {+ sendJsonRpcError(sock, id, -32603, "Result too large — response buffer overflow");+ return;+ }const result_str = w.slice();if (std.mem.startsWith(u8, result_str, "{\"error\":")) {sendJsonRpcError(sock, id, -32602, result_str);diff --git a/src/mcp/json.zig b/src/mcp/json.zigindex 3907046..1fdea8d 100644--- a/src/mcp/json.zig+++ b/src/mcp/json.zig@@ -7,13 +7,17 @@ const std = @import("std");pub const JsonWriter = struct {buf: []u8,pos: usize = 0,+ overflow: bool = false,pub fn init(buf: []u8) JsonWriter {- return .{ .buf = buf, .pos = 0 };+ return .{ .buf = buf, .pos = 0, .overflow = false };}pub fn raw(self: *JsonWriter, s: []const u8) void {- if (self.pos + s.len > self.buf.len) return;+ if (self.pos + s.len > self.buf.len) {+ self.overflow = true;+ return;+ }@memcpy(self.buf[self.pos..][0..s.len], s);self.pos += s.len;}diff --git a/src/mcp/tools.zig b/src/mcp/tools.zigindex 6b7c4ba..afaf2b3 100644--- a/src/mcp/tools.zig+++ b/src/mcp/tools.zig@@ -1166,17 +1166,47 @@ fn waitForEvent(params: ?std.json.Value, out: []u8) ToolResult {}// ── ListCommandsByCategory ──────────────────────────────────────────+fn containsInsensitive(haystack: []const u8, needle: []const u8) bool {+ if (needle.len == 0 or needle.len > haystack.len) return false;+ var i: usize = 0;+ while (i + needle.len <= haystack.len) : (i += 1) {+ var match = true;+ for (0..needle.len) |j| {+ if (std.ascii.toLower(haystack[i + j]) != std.ascii.toLower(needle[j])) {+ match = false;+ break;+ }+ }+ if (match) return true;+ }+ return false;+}+fn listCommandsByCategory(params: ?std.json.Value, out: []u8) ToolResult {- _ = params;+ const category = getParamStr(params, "category");var w = JsonWriter.init(out);- w.raw("Available tools:\n");+ w.raw("Available tools");+ if (category) |cat| {+ w.raw(" (filtered by \"");+ w.raw(cat);+ w.raw("\")");+ }+ w.raw(":\n");+ var count: usize = 0;for (&tools) |*t| {+ if (category) |cat| {+ if (!containsInsensitive(t.name, cat) and !containsInsensitive(t.description, cat)) continue;+ }w.raw("- ");w.raw(t.name);if (t.debug_only) w.raw(" [debug-only]");w.raw(": ");w.raw(t.description);w.raw("\n");+ count += 1;+ }+ if (count == 0 and category != null) {+ w.raw("(no tools matched)\n");}return .{ .text = w.slice() };}@@ -2612,16 +2642,19 @@ fn setConditionalBreakpoint(params: ?std.json.Value, out: []u8) ToolResult {const condition = getParamStr(params, "condition") orelsereturn errResult(out, "Error: condition is required.");- var cmd_buf: [512]u8 = undefined;- const cmd_bp = std.fmt.bufPrint(&cmd_buf, "bp {s}\x00", .{addr_str}) catch- return errResult(out, "Error: input too long.");- if (!bridge.cmdExec(@ptrCast(cmd_bp.ptr)))- return errResult(out, "Error: Failed to set breakpoint.");-+ // Try setting condition on an existing breakpoint first (normal or hardware).+ // Only create a new software bp if no breakpoint exists at this address.var cmd2_buf: [512]u8 = undefined;const cmd_cnd = std.fmt.bufPrint(&cmd2_buf, "bpcnd {s}, \"{s}\"\x00", .{ addr_str, condition }) catchreturn errResult(out, "Error: condition too long.");- _ = bridge.cmdExec(@ptrCast(cmd_cnd.ptr));+ if (!bridge.cmdExec(@ptrCast(cmd_cnd.ptr))) {+ var cmd_buf: [512]u8 = undefined;+ const cmd_bp = std.fmt.bufPrint(&cmd_buf, "bp {s}\x00", .{addr_str}) catch+ return errResult(out, "Error: input too long.");+ if (!bridge.cmdExec(@ptrCast(cmd_bp.ptr)))+ return errResult(out, "Error: Failed to set breakpoint.");+ _ = bridge.cmdExec(@ptrCast(cmd_cnd.ptr));+ }if (getParamStr(params, "log")) |log_text| {var cmd3_buf: [512]u8 = undefined;