ce-mcp-server 5.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,444 @@
1
+ English | [中文](README_CN.md)
2
+
3
+ # CE MCP v5.8.4 - AI-Assisted Reverse Engineering
4
+
5
+ MCP bridge enabling AI assistants to directly control Cheat Engine for game hacking and reverse engineering.
6
+
7
+ ## Architecture
8
+
9
+ ```
10
+ AI <--MCP/JSON-RPC--> ce_mcp_server.py <--Named Pipe--> ce_mcp_bridge.lua (CE)
11
+
12
+ Background auto-reconnect
13
+ ```
14
+
15
+ ## Installation
16
+
17
+ 1. **Install Dependencies**: `pip install pywin32`
18
+
19
+ 2. **Load in CE** (choose one):
20
+ - **Auto-load**: Copy `ce_mcp_bridge.lua` to CE's `autorun` folder (e.g. `D:\Cheat Engine\autorun\`)
21
+ - **Manual**: Press `Ctrl+Alt+L`, execute:
22
+ ```lua
23
+ dofile([[D:\path\to\ce_mcp_bridge.lua]])
24
+ ```
25
+
26
+ 3. **Configure MCP** (`.kiro/settings/mcp.json`):
27
+ ```json
28
+ {
29
+ "mcpServers": {
30
+ "cheat-engine": {
31
+ "command": "python",
32
+ "args": ["D:/path/to/ce_mcp/ce_mcp_server.py"]
33
+ }
34
+ }
35
+ }
36
+ ```
37
+
38
+ ## Connection Features
39
+
40
+ - **Auto-reconnect**: MCP Server automatically reconnects when CE restarts
41
+ - **Background retry**: Connection attempts run in background with exponential backoff
42
+ - **Diagnostic on failure**: `ce_ping` returns detailed diagnostic info when connection fails
43
+ - **Thread-safe**: All pipe operations are protected by locks
44
+
45
+ ## Security Features
46
+
47
+ ### Authentication Token
48
+
49
+ Optional authentication layer for pipe communication. When enabled, all requests must include a valid token.
50
+
51
+ **Setup:**
52
+ 1. Set the same environment variable on both sides:
53
+ ```bash
54
+ # Windows CMD
55
+ set CE_MCP_AUTH_TOKEN=your_secret_token_here
56
+
57
+ # PowerShell
58
+ $env:CE_MCP_AUTH_TOKEN = "your_secret_token_here"
59
+ ```
60
+
61
+ 2. Start CE and load the bridge
62
+ 3. Start the MCP server
63
+
64
+ If tokens don't match, requests will be rejected with "Authentication failed" error.
65
+
66
+ ### Custom Pipe Name
67
+
68
+ For anti-detection, you can customize the pipe name:
69
+ ```bash
70
+ set CE_MCP_PIPE_NAME=my_custom_pipe_name
71
+ ```
72
+
73
+ ### Hook Name Validation
74
+
75
+ Hook names are validated to prevent AA script injection:
76
+ - Must start with letter or underscore
77
+ - Can only contain alphanumeric characters and underscores
78
+ - Pattern: `^[a-zA-Z_][a-zA-Z0-9_]*$`
79
+
80
+ Invalid names like `"my hook"` or `"hook;inject"` will be rejected.
81
+
82
+ ---
83
+
84
+ ## Tool Reference
85
+
86
+ ### System & Connection
87
+
88
+ #### `ce_ping`
89
+ Test connection to CE bridge. **Returns diagnostic info with troubleshooting suggestions on failure.**
90
+
91
+ #### `ce_get_process_info`
92
+ Get attached process info and refresh symbol handler. Also clears address cache.
93
+
94
+ #### `ce_attach_process(target)`
95
+ Attach to a process by PID or name. Clears caches and scan sessions after attaching.
96
+
97
+ **Parameters:**
98
+ - `target` (string, required): Process ID (number) or process name (e.g. `"game.exe"`)
99
+
100
+ #### `ce_auto_assemble(script, target_self?)`
101
+ Execute an Auto Assembler script. Supports enable/disable scripts, code injection, etc.
102
+
103
+ **Parameters:**
104
+ - `script` (string, required): Auto Assembler script content
105
+ - `target_self` (boolean, optional): Target CE process itself (default: false)
106
+
107
+ #### `ce_execute_lua(code)`
108
+ Execute arbitrary Lua code in CE.
109
+
110
+ **Parameters:**
111
+ - `code` (string, required): Lua code to execute
112
+
113
+ ---
114
+
115
+ ### Memory Read/Write
116
+
117
+ #### `ce_read_memory(address, type, size?)`
118
+ Read a single memory value.
119
+
120
+ **Parameters:**
121
+ - `address` (string, required): Address expression (e.g. `"game.exe+0x1234"`, `"0x140001000"`)
122
+ - `type` (string, required): `byte`, `word`, `dword`, `qword`, `float`, `double`, `string`, `bytes`
123
+ - `size` (integer, optional): Size for string/bytes type (default: 100)
124
+
125
+ #### `ce_read_memory_batch(requests)`
126
+ Read multiple addresses in one call. **Always prefer this over multiple ce_read_memory calls.**
127
+
128
+ **Parameters:**
129
+ - `requests` (array, required): Array of `{address, type, id?, size?}`
130
+
131
+ #### `ce_write_memory(address, type, value)`
132
+ Write a value to memory.
133
+
134
+ **Parameters:**
135
+ - `address` (string, required): Address expression
136
+ - `type` (string, required): Value type
137
+ - `value` (string, required): Value to write
138
+
139
+ ---
140
+
141
+ ### Scanning & Search
142
+
143
+ #### `ce_aob_scan(aob_string, module?, protection?, max_results?)`
144
+ Scan memory for Array of Bytes pattern. Supports `??` wildcards.
145
+
146
+ **Parameters:**
147
+ - `aob_string` (string, required): Pattern like `"48 89 5C 24 ?? 48 83 EC 20"`
148
+ - `module` (string, optional): Limit scan to module (e.g. `"game.exe"`)
149
+ - `protection` (string, optional): Memory protection flags (default: `"-C+X"`)
150
+ - `max_results` (integer, optional): Maximum results (default: 100)
151
+
152
+ #### `ce_value_scan(value, type, module?, protection?)`
153
+ Scan for a specific value. Useful for pointer tracing. **One-shot scan - for iterative scanning use Scan Sessions.**
154
+
155
+ **Parameters:**
156
+ - `value` (string, required): Value to search (e.g. `"0x255D5E758"` or `"12345"`)
157
+ - `type` (string, required): `byte`, `word`, `dword`, `qword`, `float`, `double`, `string`
158
+ - `module` (string, optional): Limit to module
159
+ - `protection` (string, optional): Default `"+W-C"` for writable memory
160
+
161
+ ---
162
+
163
+ ### Scan Sessions
164
+
165
+ Implements CE's core "First Scan → Next Scan" workflow with session management. Sessions auto-expire after 5 minutes of inactivity.
166
+
167
+ #### `ce_scan_new(value, type, module?, protection?)`
168
+ Start a new scan session.
169
+
170
+ #### `ce_scan_next(session_id, value, scan_type?, value2?)`
171
+ Continue scanning (filter) an existing session.
172
+
173
+ **scan_type options:**
174
+ - `exact` - Exact value match
175
+ - `increased` / `decreased` - Value increased/decreased
176
+ - `changed` / `unchanged` - Value changed/unchanged
177
+ - `bigger_than` / `smaller_than` - Greater/less than
178
+ - `between` - Between value and value2
179
+
180
+ #### `ce_scan_results(session_id, start_index?, limit?)`
181
+ Get paginated results from a scan session.
182
+
183
+ #### `ce_scan_close(session_id)`
184
+ Close a scan session and release resources.
185
+
186
+ #### `ce_scan_list`
187
+ List all active scan sessions.
188
+
189
+ #### `ce_enum_modules`
190
+ List all loaded modules (DLLs).
191
+
192
+ ---
193
+
194
+ ### Symbols & Addresses
195
+
196
+ #### `ce_get_address(expression)`
197
+ Resolve address expression to numeric address.
198
+
199
+ **Parameters:**
200
+ - `expression` (string, required): e.g. `"game.exe+0x1234"`, `"[[game.exe+100]+20]+8"`
201
+
202
+ #### `ce_get_symbol(address, include_module?)`
203
+ Get symbol name from address, with RTTI class info.
204
+
205
+ #### `ce_resolve_pointer(base, offsets, read_value?, value_type?)`
206
+ Resolve multi-level pointer chain with CE notation support.
207
+
208
+ **Parameters:**
209
+ - `base` (string, required): Base address or symbol (e.g. `"game.exe+1234"`)
210
+ - `offsets` (array, required): Array of offsets, e.g. `[0x100, 0x20, 0x8]`
211
+ - `read_value` (boolean, optional): Read value at final address (default: false)
212
+ - `value_type` (string, optional): Value type (default: "dword")
213
+
214
+ **Returns:** Includes `ceNotation` (CE-compatible pointer notation) that can be directly used in CE address list.
215
+
216
+ #### `ce_auto_guess(address)`
217
+ Guess the value type at an address.
218
+
219
+ ---
220
+
221
+ ### Disassembly & Code Analysis
222
+
223
+ #### `ce_disassemble(address, count?, direction?)`
224
+ Disassemble instructions.
225
+
226
+ **Parameters:**
227
+ - `address` (string, required): Start address
228
+ - `count` (integer, optional): Number of instructions (default: 10)
229
+ - `direction` (string, optional): `"forward"` or `"backward"` (default: forward)
230
+
231
+ #### `ce_get_instruction_info(address)`
232
+ Get detailed info about a single instruction.
233
+
234
+ #### `ce_analyze_code(address, count?)`
235
+ Static analysis of code block (calls, jumps, refs).
236
+
237
+ ---
238
+
239
+ ### Debugging & Breakpoints
240
+
241
+ #### `ce_set_breakpoint(address, type?, size?)`
242
+ Set a hardware breakpoint.
243
+
244
+ **Parameters:**
245
+ - `address` (string, required): Address expression
246
+ - `type` (string, optional): `"execute"`, `"write"`, `"access"` (default: execute)
247
+ - `size` (integer, optional): Size for write/access breakpoints (default: 1)
248
+
249
+ #### `ce_break_and_get_regs(address, timeout?, include_xmm?, stack_depth?)`
250
+ Set breakpoint and capture registers when hit. Also returns call stack.
251
+
252
+ #### `ce_break_and_trace(address, max_steps?, timeout?, stop_on_ret?, trace_into_call?, end_address?, initial_regs?)`
253
+ **Multi-step execution trace.** Most powerful debugging tool - traces code execution step by step, capturing full register state at each instruction.
254
+
255
+ **Parameters:**
256
+ - `address` (string, required): Start address (breakpoint location)
257
+ - `max_steps` (integer, optional): Maximum instructions to trace (default: 100)
258
+ - `timeout` (integer, optional): Timeout in ms (default: 10000)
259
+ - `stop_on_ret` (boolean, optional): Stop when `ret` is encountered (default: true)
260
+ - `trace_into_call` (boolean, optional): Step into calls vs step over (default: false)
261
+ - `end_address` (string, optional): Stop when this address is reached
262
+ - `initial_regs` (object, optional): Set register values at first hit
263
+
264
+ **Stop reasons:** `"ret"`, `"end_address"`, `"max_steps"`, `"timeout"`
265
+
266
+ #### `ce_cleanup`
267
+ Remove all breakpoints and traces. Use when game freezes.
268
+
269
+ ---
270
+
271
+ ### Analysis Tools
272
+
273
+ #### `ce_find_what_accesses(address, size?, duration_ms?, max_records?)`
274
+ Find what code accesses this address (like CE's F5 feature). Monitors reads and writes.
275
+
276
+ #### `ce_find_what_writes(address, size?, duration_ms?, max_records?)`
277
+ Find what writes to this address (like CE's F6 feature). Monitors only writes.
278
+
279
+ #### `ce_find_pointer_path(address, max_depth?, strategy?)`
280
+ **Automatic pointer chain tracing.** Finds static base address for dynamic addresses.
281
+
282
+ **Parameters:**
283
+ - `address` (string, required): Dynamic address to trace
284
+ - `max_depth` (integer, optional): Max pointer depth 1-10 (default: 7)
285
+ - `strategy` (string, optional): `"hybrid"`, `"f5"`, `"value_scan"` (default: hybrid)
286
+
287
+ #### `ce_find_references(address, limit?)`
288
+ Find all code locations that reference a specific address.
289
+
290
+ #### `ce_find_call_references(address, module?, limit?)`
291
+ Find all CALL instructions that target a specific function.
292
+
293
+ #### `ce_find_function_boundaries(address, max_search?)`
294
+ Detect function start and end by analyzing prologue/epilogue patterns.
295
+
296
+ #### `ce_generate_signature(address)`
297
+ Generate unique AOB signature for an address. Useful for game updates.
298
+
299
+ ---
300
+
301
+ ### Advanced Analysis
302
+
303
+ #### `ce_build_cfg(address, max_blocks?, max_instructions?, detect_loops?)`
304
+ Build Control Flow Graph for a function.
305
+
306
+ #### `ce_detect_patterns(address, max_instructions?, patterns?)`
307
+ Detect common code patterns: switch tables, virtual calls, string refs, crypto constants.
308
+
309
+ #### `ce_compare_functions(address1, address2, max_instructions?)`
310
+ Compare two functions for similarity.
311
+
312
+ #### `ce_trace_dataflow(address, register, direction?, max_instructions?)`
313
+ Trace data flow for a register within a function.
314
+
315
+ #### `ce_program_slice(address, criterion, direction?, max_instructions?)`
316
+ Compute program slice - find all instructions affecting or affected by a variable.
317
+
318
+ ---
319
+
320
+ ### Code Emulation
321
+
322
+ #### `ce_symbolic_trace(address, count?, initial_state?, stop_on_call?, stop_on_ret?)`
323
+ Lightweight symbolic execution. Interprets instruction semantics without executing.
324
+
325
+ **Parameters:**
326
+ - `address` (string, required): Start address
327
+ - `count` (integer, optional): Instructions to trace (default: 30)
328
+ - `initial_state` (object, optional): Initial register symbols, e.g. `{"rcx": "this_ptr", "rdx": "arg1"}`
329
+
330
+ #### `ce_call_function(address, args?, return_type?, timeout?)`
331
+ Call a function in the target process. **WARNING: Executes real code!**
332
+
333
+ ---
334
+
335
+ ### Function Hooking
336
+
337
+ #### `ce_hook_function(address, name, capture_args?, calling_convention?)`
338
+ Hook a function to intercept calls and capture arguments.
339
+
340
+ **Parameters:**
341
+ - `address` (string, required): Function address
342
+ - `name` (string, required): Hook identifier
343
+ - `capture_args` (integer, optional): Number of args to capture 0-4 (default: 4)
344
+ - `calling_convention` (string, optional): `"auto"`, `"fastcall"`, `"stdcall"`, `"cdecl"`
345
+
346
+ #### `ce_get_hook_log(name, limit?, clear?)`
347
+ Get captured function call arguments.
348
+
349
+ #### `ce_unhook_function(name)`
350
+ Remove a function hook.
351
+
352
+ #### `ce_list_hooks`
353
+ List all active hooks.
354
+
355
+ ---
356
+
357
+ ### Cheat Table
358
+
359
+ #### `ce_get_address_list(include_script?)`
360
+ Get all records from Cheat Table.
361
+
362
+ #### `ce_add_address_record(description, address, value_type?, script?)`
363
+ Add a new record to Cheat Table.
364
+
365
+ ---
366
+
367
+ ## Recommended Workflows
368
+
369
+ ### Pointer Tracing
370
+ ```python
371
+ # Automatic (preferred)
372
+ result = ce_find_pointer_path(address="0x255D5E758")
373
+ # Returns: base_address, offsets, ce_pointer_notation
374
+
375
+ # Manual (if automatic fails)
376
+ # 1. Find what accesses the address
377
+ accesses = ce_find_what_accesses(address="0x255D5E758")
378
+ # 2. Get register value (e.g., rcx = 0x255D5E658)
379
+ # 3. Search for pointer storing that value
380
+ pointers = ce_value_scan(value="0x255D5E658", type="qword")
381
+ # 4. Repeat until finding game.exe+offset
382
+ ```
383
+
384
+ ### Function Analysis
385
+ ```python
386
+ # 1. Find function boundaries
387
+ bounds = ce_find_function_boundaries(address="0x14587EDB0")
388
+
389
+ # 2. Trace execution
390
+ trace = ce_break_and_trace(address="0x14587EDB0", max_steps=100)
391
+
392
+ # 3. Generate signature for updates
393
+ sig = ce_generate_signature(address="0x14587EDB0")
394
+ ```
395
+
396
+ ### Reverse Engineering Unknown Code
397
+ ```python
398
+ # 1. Disassemble
399
+ code = ce_disassemble(address="0x14587EDB0", count=20)
400
+
401
+ # 2. Symbolic trace to understand logic
402
+ symbolic = ce_symbolic_trace(address="0x14587EDB0", initial_state={"rcx": "this"})
403
+
404
+ # 3. Build CFG for complex functions
405
+ cfg = ce_build_cfg(address="0x14587EDB0")
406
+
407
+ # 4. Detect patterns
408
+ patterns = ce_detect_patterns(address="0x14587EDB0")
409
+ ```
410
+
411
+ ---
412
+
413
+ ## Troubleshooting
414
+
415
+ | Issue | Solution |
416
+ |-------|----------|
417
+ | Connection failed | Use `ce_ping` - it returns diagnostic info with specific suggestions |
418
+ | CE restarted | MCP Server auto-reconnects, just reload the Lua script in CE |
419
+ | Pipe error | Run `CE_MCP.stop()` then `CE_MCP.start()` in CE |
420
+ | Permission denied | Run CE as administrator |
421
+ | Game frozen | Use `ce_cleanup()` to remove all breakpoints |
422
+ | Breakpoint not triggering | Ensure code path is executed in game |
423
+
424
+ ## Status Check
425
+
426
+ ```lua
427
+ CE_MCP.stats() -- Check bridge status in CE
428
+ reloadMcpBridge() -- Reload bridge after code changes
429
+ ```
430
+
431
+ ## Version History
432
+
433
+ - **v5.8.4**: Connection improvements - Background auto-reconnect thread; Auto-reconnect when CE restarts; `ce_ping` returns diagnostic info on failure; Thread-safe pipe operations
434
+ - **v5.8.3**: Improved tool descriptions for better AI recognition
435
+ - **v5.8.1**: Security improvements - Added optional authentication token; Added hook name validation
436
+ - **v5.8.0**: Added Scan Sessions, `ce_attach_process`, `ce_auto_assemble`
437
+ - **v5.0**: Added `ce_break_and_trace` with multi-step tracing
438
+ - **v4.2**: Added CFG, pattern detection, dataflow analysis
439
+ - **v4.0**: Added function hooking, symbolic trace
440
+ - **v3.0**: Added pointer path finding, structure analysis
441
+
442
+ ## References
443
+
444
+ - [CE Wiki](https://wiki.cheatengine.org/)