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
Keep auth mandatory, fix DPI wParam/lParam bug
duty1g228d06c8d59d
diff --git a/src/core/config.zig b/src/core/config.zigindex 76c5ad1..d5aaa76 100644--- a/src/core/config.zig+++ b/src/core/config.zig@@ -115,7 +115,6 @@ const SWP_NOZORDER: u32 = 0x0004;const SWP_NOSIZE: u32 = 0x0001;const SWP_NOACTIVATE: u32 = 0x0010;const WM_DPICHANGED: u32 = 0x02E0;-const WM_DPICHANGED_AFTERPARENT: u32 = 0x02E3;const USER_DEFAULT_SCREEN_DPI: u32 = 96;const GENERIC_READ: u32 = 0x80000000;const GENERIC_WRITE: u32 = 0x40000000;@@ -132,7 +131,6 @@ const IDC_AUTOSTART: c_int = 104;const IDC_TOKEN: c_int = 105;const IDC_GENERATE: c_int = 106;const IDC_COPY_TOKEN: c_int = 107;-const IDC_AUTHENABLE: c_int = 108;const IDC_SAVE: c_int = 1;const IDC_CANCEL: c_int = 2;const BN_CLICKED: u32 = 0;@@ -177,7 +175,6 @@ pub const Config = struct {ip_len: usize = 0,port: u16 = 0,auto_start: bool = true,- auth_enabled: bool = true,auth_token: [64]u8 = undefined,auth_token_len: usize = 0,@@ -190,7 +187,7 @@ pub const Config = struct {}pub fn hasAuth(self: *const Config) bool {- return self.auth_enabled and self.auth_token_len > 0;+ return self.auth_token_len > 0;}};@@ -260,14 +257,6 @@ pub fn load() Config {cfg.auto_start = val;}- // Parse "AuthEnabled":true/false. Legacy configs have no such field:- // keep the old behavior (auth on, token auto-generated).- var auth_enabled_found = false;- if (findJsonBool(json_data, "AuthEnabled")) |val| {- cfg.auth_enabled = val;- auth_enabled_found = true;- }-// Parse "AuthToken":"<value>"if (findJsonString(json_data, "AuthToken")) |token_val| {if (token_val.len > 0 and token_val.len <= 64) {@@ -275,14 +264,12 @@ pub fn load() Config {cfg.auth_token_len = token_val.len;}}- // New config file (no AuthEnabled field) with no token: keep legacy default = enabled.- if (!auth_enabled_found and cfg.auth_token_len == 0) cfg.auth_enabled = true;return ensureToken(&cfg);}fn ensureToken(cfg: *Config) Config {- if (cfg.auth_enabled and cfg.auth_token_len == 0) {+ if (cfg.auth_token_len == 0) {var tok: [32]u8 = undefined;generateToken(&tok);@memcpy(cfg.auth_token[0..32], tok[0..32]);@@ -383,10 +370,6 @@ pub fn save(cfg: *const Config) void {@memcpy(buf[pos .. pos + auto_str.len], auto_str);pos += auto_str.len;- const auth_str = if (cfg.auth_enabled) ",\"AuthEnabled\":true" else ",\"AuthEnabled\":false";- @memcpy(buf[pos .. pos + auth_str.len], auth_str);- pos += auth_str.len;-if (cfg.auth_token_len > 0) {const tok_prefix = ",\"AuthToken\":\"";@memcpy(buf[pos .. pos + tok_prefix.len], tok_prefix);@@ -431,9 +414,6 @@ var edit_port: HWND = null;var edit_token: HWND = null;var lbl_url: HWND = null;var chk_autostart: HWND = null;-var chk_auth: HWND = null;-var btn_generate: HWND = null;-var btn_copy: HWND = null;var ui_font: HFONT = null;var ui_font_bold: HFONT = null;var ui_font_small: HFONT = null;@@ -441,7 +421,7 @@ var class_registered: bool = false;var parent_hwnd: HWND = null;const DLG_W = 450;-const DLG_H = 410;+const DLG_H = 370;const CLASS_NAME = "MCPServerConfig\x00";var cur_dpi: u32 = 96;@@ -579,37 +559,32 @@ fn wndProc(hwnd: HWND, msg: u32, wParam: WPARAM, lParam: LPARAM) callconv(.winapif (chk_autostart != null and cfg.auto_start)_ = SendMessageA(chk_autostart, BM_SETCHECK, BST_CHECKED, 0);- // Row 4: Require auth checkbox- chk_auth = createCtrl("BUTTON\x00", "Require Bearer token authentication\x00", WS_TABSTOP | BS_AUTOCHECKBOX, 20, 132, 280, 20, IDC_AUTHENABLE);- if (chk_auth != null and cfg.auth_enabled)- _ = SendMessageA(chk_auth, BM_SETCHECK, BST_CHECKED, 0);-- // Row 5: Auth Token- _ = createCtrl("STATIC\x00", "Auth Token:\x00", 0, 20, 168, 85, 20, 0);- edit_token = createCtrl("EDIT\x00", null, WS_TABSTOP | ES_AUTOHSCROLL | ES_READONLY, 112, 164, 190, 24, IDC_TOKEN);- btn_generate = createCtrl("BUTTON\x00", "Generate\x00", WS_TABSTOP, 310, 164, 65, 24, IDC_GENERATE);- btn_copy = createCtrl("BUTTON\x00", "Copy\x00", WS_TABSTOP, 380, 164, 45, 24, IDC_COPY_TOKEN);+ // Row 4: Auth Token+ _ = createCtrl("STATIC\x00", "Auth Token:\x00", 0, 20, 132, 85, 20, 0);+ edit_token = createCtrl("EDIT\x00", null, WS_TABSTOP | ES_AUTOHSCROLL | ES_READONLY, 112, 128, 190, 24, IDC_TOKEN);+ _ = createCtrl("BUTTON\x00", "Generate\x00", WS_TABSTOP, 310, 128, 65, 24, IDC_GENERATE);+ _ = createCtrl("BUTTON\x00", "Copy\x00", WS_TABSTOP, 380, 128, 45, 24, IDC_COPY_TOKEN);- const auth_hint = createCtrl("STATIC\x00", "Token is auto-generated on first run and persists across restarts.\x00", 0, 112, 191, 320, 16, 0);+ const auth_hint = createCtrl("STATIC\x00", "Token is auto-generated on first run and persists across restarts.\x00", 0, 112, 155, 320, 16, 0);if (auth_hint != null and ui_font_small != null)_ = SendMessageA(auth_hint, WM_SETFONT, @intFromPtr(ui_font_small.?), 1);- // Row 6: URL preview- _ = createCtrl("STATIC\x00", "Server URL:\x00", 0, 20, 221, 85, 20, 0);- lbl_url = createCtrl("STATIC\x00", null, 0, 112, 221, 310, 20, IDC_URL);+ // Row 5: URL preview+ _ = createCtrl("STATIC\x00", "Server URL:\x00", 0, 20, 185, 85, 20, 0);+ lbl_url = createCtrl("STATIC\x00", null, 0, 112, 185, 310, 20, IDC_URL);if (lbl_url != null and ui_font_bold != null)_ = SendMessageA(lbl_url, WM_SETFONT, @intFromPtr(ui_font_bold.?), 1);// Help notesconst notes = createCtrl("STATIC\x00","Use 0.0.0.0 to listen on all interfaces (for WSL/remote access).\r\nUse 127.0.0.1 for local-only access.\r\nSave will automatically restart the MCP server.\x00",- 0, 20, 246, 400, 52, 0);+ 0, 20, 210, 400, 52, 0);if (notes != null and ui_font_small != null)_ = SendMessageA(notes, WM_SETFONT, @intFromPtr(ui_font_small.?), 1);// Buttons- _ = createCtrl("BUTTON\x00", "Save\x00", WS_TABSTOP | BS_DEFPUSHBUTTON, 240, 316, 90, 30, IDC_SAVE);- _ = createCtrl("BUTTON\x00", "Cancel\x00", WS_TABSTOP, 340, 316, 90, 30, IDC_CANCEL);+ _ = createCtrl("BUTTON\x00", "Save\x00", WS_TABSTOP | BS_DEFPUSHBUTTON, 240, 280, 90, 30, IDC_SAVE);+ _ = createCtrl("BUTTON\x00", "Cancel\x00", WS_TABSTOP, 340, 280, 90, 30, IDC_CANCEL);// Set initial valuesif (edit_ip != null) {var ip_z: [65]u8 = undefined;@@ -630,7 +605,6 @@ fn wndProc(hwnd: HWND, msg: u32, wParam: WPARAM, lParam: LPARAM) callconv(.winap_ = SendMessageA(edit_token, WM_SETTEXT, 0, @bitCast(@intFromPtr(&tok_z)));}updateUrlPreview();- updateAuthControls();if (edit_ip != null) _ = SetFocus(edit_ip);return 0;@@ -682,10 +656,6 @@ fn wndProc(hwnd: HWND, msg: u32, wParam: WPARAM, lParam: LPARAM) callconv(.winap}return 0;}- if (id == IDC_AUTHENABLE and notify == BN_CLICKED) {- updateAuthControls();- return 0;- }// Update URL preview on text change (EN_CHANGE = 0x0300)if (notify == 0x0300 and (id == IDC_IP or id == IDC_PORT)) {updateUrlPreview();@@ -702,8 +672,7 @@ fn wndProc(hwnd: HWND, msg: u32, wParam: WPARAM, lParam: LPARAM) callconv(.winapreturn DefWindowProcA(hwnd, msg, wParam, lParam);},WM_DPICHANGED => {- // wParam HIWORD = new DPI; lParam = suggested window rect.- const new_dpi: u32 = @intCast(@as(u32, @truncate(@as(usize, @bitCast(lParam)) >> 16)) & 0xFFFF);+ const new_dpi: u32 = @intCast(wParam & 0xFFFF);if (new_dpi == 0 or new_dpi == cur_dpi) return 0;cur_dpi = new_dpi;const rect: *const RECT = @ptrCast(@alignCast(@as([*]const u8, @ptrFromInt(@as(usize, @bitCast(lParam))))[0..@sizeOf(RECT)].ptr));@@ -748,25 +717,20 @@ fn moveCtrl(h: HWND, x: c_int, y: c_int, w: c_int, hgt: c_int) void {}fn relayoutChildren() void {- // Row 1: IP AddressmoveCtrl(edit_ip, 112, 20, 190, 24);- // Row 2: PortmoveCtrl(edit_port, 112, 56, 100, 24);- // Row 3-4: checkboxesmoveCtrl(chk_autostart, 20, 96, 250, 20);- moveCtrl(chk_auth, 20, 132, 280, 20);- // Row 5: Auth Token- moveCtrl(edit_token, 112, 164, 190, 24);- moveCtrl(btn_generate, 310, 164, 65, 24);- moveCtrl(btn_copy, 380, 164, 45, 24);- // Row 6: URL preview- moveCtrl(lbl_url, 112, 221, 310, 20);- // Buttons (moved via enum by walking children is overkill; move by known ids)+ moveCtrl(edit_token, 112, 128, 190, 24);+ moveCtrl(lbl_url, 112, 185, 310, 20);if (dlg_hwnd != null) {var h: HWND = GetDlgItem(dlg_hwnd, IDC_SAVE);- moveCtrl(h, 240, 316, 90, 30);+ moveCtrl(h, 240, 280, 90, 30);h = GetDlgItem(dlg_hwnd, IDC_CANCEL);- moveCtrl(h, 340, 316, 90, 30);+ moveCtrl(h, 340, 280, 90, 30);+ h = GetDlgItem(dlg_hwnd, IDC_GENERATE);+ moveCtrl(h, 310, 128, 65, 24);+ h = GetDlgItem(dlg_hwnd, IDC_COPY_TOKEN);+ moveCtrl(h, 380, 128, 45, 24);}}@@ -810,13 +774,6 @@ fn updateUrlPreview() void {_ = SendMessageA(lbl_url, WM_SETTEXT, 0, @bitCast(@intFromPtr(&url)));}-fn updateAuthControls() void {- const enabled: BOOL = if (chk_auth != null and SendMessageA(chk_auth, BM_GETCHECK, 0, 0) == BST_CHECKED) 1 else 0;- if (edit_token != null) _ = EnableWindow(edit_token, enabled);- if (btn_generate != null) _ = EnableWindow(btn_generate, enabled);- if (btn_copy != null) _ = EnableWindow(btn_copy, enabled);-}-fn onSave(hwnd: HWND) void {var ip_buf: [64]u8 = undefined;const ip_len: usize = @intCast(GetWindowTextA(edit_ip, &ip_buf, 64));@@ -838,27 +795,13 @@ fn onSave(hwnd: HWND) void {elsetrue;- const auth_enabled = if (chk_auth != null)- SendMessageA(chk_auth, BM_GETCHECK, 0, 0) == BST_CHECKED- else- true;-var tok_buf: [64]u8 = undefined;- var tok_len: usize = if (edit_token != null)+ const tok_len: usize = if (edit_token != null)@intCast(GetWindowTextA(edit_token, &tok_buf, 64))else0;- if (auth_enabled and tok_len == 0) {- // Never save an enabled-but-empty token (would lock out all clients).- var tok: [32]u8 = undefined;- generateToken(&tok);- @memcpy(tok_buf[0..32], tok[0..32]);- tok_len = 32;- }- if (!auth_enabled) tok_len = 0;-- var cfg = Config{ .port = port, .auto_start = auto_start, .auth_enabled = auth_enabled };+ var cfg = Config{ .port = port, .auto_start = auto_start };@memcpy(cfg.ip[0..ip_len], ip_buf[0..ip_len]);cfg.ip_len = ip_len;if (tok_len > 0) {@@ -868,7 +811,7 @@ fn onSave(hwnd: HWND) void {save(&cfg);mcp.stop();- mcp.setConfig(cfg.ip[0..cfg.ip_len], cfg.port, cfg.tokenSlice(), cfg.auth_enabled);+ mcp.setConfig(cfg.ip[0..cfg.ip_len], cfg.port, cfg.tokenSlice());if (cfg.auto_start) mcp.start();bridge.logPuts("[x64dbg-MCP Server] Configuration saved.\x00");diff --git a/src/core/mcp_server.zig b/src/core/mcp_server.zigindex a37d44f..7201070 100644--- a/src/core/mcp_server.zig+++ b/src/core/mcp_server.zig@@ -37,11 +37,9 @@ var server_ip: [64]u8 = .{ '1', '2', '7', '.', '0', '.', '0', '.', '1' } ++ .{0}var server_ip_len: usize = 9;var auth_token: [64]u8 = .{0} ** 64;var auth_token_len: usize = 0;-var auth_enabled: bool = true;-pub fn setConfig(ip: []const u8, port: u16, token: []const u8, auth: bool) void {+pub fn setConfig(ip: []const u8, port: u16, token: []const u8) void {server_port = port;- auth_enabled = auth;if (ip.len > 0 and ip.len < 64) {@memcpy(server_ip[0..ip.len], ip);server_ip_len = ip.len;@@ -452,7 +450,7 @@ fn handleClient(sock: SOCKET) void {return;}- if (auth_enabled) {+ {const headers_slice = if (findHeaderEnd(request)) |he| request[0..he] else request;const tok = parseHeaderValue(headers_slice, "Authorization");var authorized = false;diff --git a/src/main.zig b/src/main.zigindex 5733d8a..6a9e16b 100644--- a/src/main.zig+++ b/src/main.zig@@ -134,7 +134,7 @@ export fn plugsetup(setupStruct: *bridge.PLUG_SETUPSTRUCT) callconv(.c) void {// Load saved config or use defaultsconst cfg = config.load();- mcp.setConfig(cfg.ip[0..cfg.ip_len], cfg.port, cfg.tokenSlice(), cfg.auth_enabled);+ mcp.setConfig(cfg.ip[0..cfg.ip_len], cfg.port, cfg.tokenSlice());// Log plugin handlelogPluginHandle();