Skip to content
F0RSV1NNAPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

MemCP

License: MIT Node.js Version Platform MCP

MemCP is a Model Context Protocol (MCP) server that gives AI agents direct access to read and write process memory on Windows. It provides a comprehensive toolset for memory inspection, modification, scanning, and analysis—enabling AI to perform advanced debugging, reverse engineering, process analysis, and memory forensics.

Quick Summary

MemCP bridges the gap between AI agents and low-level process memory. Built with TypeScript and Node.js, it uses direct NT syscall layer access (via koffi FFI) for reliable memory operations. The server exposes 23+ MCP tools organized into 8 categories, allowing Claude and other MCP clients to programmatically inspect and manipulate live process memory with full type safety and safety controls.

Use cases:

  • Interactive debugging and process analysis
  • Memory-level reverse engineering and exploration
  • Live memory forensics and inspection
  • Dynamic process behavior analysis
  • Pointer chain resolution and structure reading
  • Memory pattern scanning and value searching

Features

Process Management (4 tools)

  • list_processes — Enumerate running processes with optional name filtering
  • attach — Attach to a target process by PID or name (single attachment at a time)
  • detach — Release the currently attached process
  • process_info — Get detailed info about the attached process (PID, name, base address, architecture)

Memory Reading (5 tools)

  • read_bytes — Read raw bytes with hex and ASCII preview
  • read_int — Read signed/unsigned 8–64-bit integers
  • read_float — Read 32-bit floats or 64-bit doubles
  • read_string — Read null-terminated strings (ASCII, UTF-8, UTF-16LE)
  • read_pointer — Read pointers and optionally follow chains

Memory Writing (4 tools)

  • write_bytes — Write raw hex-encoded bytes
  • write_int — Write typed integer values
  • write_float — Write typed float/double values
  • write_string — Write strings with optional null termination

Module & Region Inspection (3 tools)

  • get_modules — List loaded DLLs and executables with base addresses and sizes
  • get_base_address — Resolve module base address by name or partial match
  • get_regions — Query memory regions (committed, reserved, protection status, type)

Memory Scanning (2 tools)

  • scan_memory — Search for byte patterns (hex with ?? wildcards) across process memory
  • scan_value — Search for typed values (integers, floats) with region filtering

Advanced Analysis (3 tools)

  • read_struct — Read typed structures by defining field offsets (C-like struct reading)
  • diff_memory — Snapshot memory and detect changes between reads
  • watch_address — Poll a memory address and return when its value changes

Virtual Memory Operations (3 tools)

  • allocate_memory — Allocate new memory regions in the target process
  • protect_memory — Change memory protection flags (R, RW, RX, RWX, etc.)
  • create_thread — Create a remote thread at a specified address (for code injection)

Architecture

MCP Client (Claude, etc.) ← stdio MCP protocol → MemCP Server
                                                    ↓
                            MCP Tool Handlers (index.ts)
                                    ↓
                         Safety Validator & Audit Logger
                                    ↓
                            MemoryEngine (core ops)
                                    ↓
                    ProcessManager + NT Syscall Layer
                                    ↓
                          Windows Kernel (ntdll.dll)

Key design choices:

  1. Direct NT Syscalls — Uses NtReadVirtualMemory, NtWriteVirtualMemory, NtQueryVirtualMemory, and NtProtectVirtualMemory from ntdll.dll for stealth and reliability, bypassing kernel32 hooks.

  2. FFI via koffi — Zero-compilation Foreign Function Interface to Windows APIs. No native module build required.

  3. Single Process Attachment — Only one process can be attached at a time, eliminating confused-deputy vulnerabilities.

  4. Type Safety — All types defined with Zod validation; addresses are hex strings (no BigInt precision issues).

  5. Safety-First — Configurable read/write size limits, blocked system processes, audit logging, optional write protection, and address space validation (user-mode only).

  6. Layered Architecture — MCP Protocol → Tool Handlers → Safety → Memory Engine → WinAPI Bindings, allowing for future kernel-mode driver support and platform expansion.

Requirements

  • OS: Windows 10/11 (x64)
  • Node.js: 20+ (see package.json engines field)
  • npm: 9+
  • Privileges: Administrator rights (for protected/elevated targets)
  • MCP Client: Copilot CLI, Claude Desktop with MCP config, or other MCP-compatible client

Installation

Recommended: One-Command Setup

From the repository root:

cd MCP-Memory
.\build.bat

This script will:

  1. Install dependencies (npm install)
  2. Build the TypeScript (npm run build)
  3. Install to Copilot MCP config (npm run install:copilot)

Custom MCP config path:

.\build.bat "C:\path\to\your\mcp-config.json"

Manual Setup

cd MCP-Memory
npm install
npm run build
npm run install:copilot  # or manually add to %USERPROFILE%\.copilot\mcp-config.json

MCP Configuration

After setup, the MCP config will look like:

{
  "mcpServers": {
    "memcp": {
      "type": "stdio",
      "command": "node",
      "args": ["C:\\Users\\<user>\\Desktop\\MemCP\\MCP-Memory\\dist\\index.js"],
      "env": {
        "MEMCP_WRITE_ENABLED": "true",
        "MEMCP_AUDIT_LOG": "true",
        "MEMCP_MAX_READ_SIZE": "65536",
        "MEMCP_MAX_WRITE_SIZE": "4096"
      }
    }
  }
}

Restart/reconnect your MCP client to load MemCP.

Usage Examples

Example 1: Inspect a Process

User: "List all running processes"

MemCP: Uses list_processes tool → returns process names and PIDs

User: "Attach to notepad.exe"

MemCP: Uses attach tool → connects to the process

User: "Show me the first 64 bytes at the process base address"

MemCP: Uses process_info to get base address, then read_bytes → displays memory contents

Example 2: Memory Scanning

User: "Scan for the byte pattern 48 89 5C 24 ?? in the .text section"

MemCP: Uses get_modules to find .text section, then scan_memory → returns all matching addresses

Example 3: Pointer Chain Resolution

User: "Get the module base for kernel32.dll, then read a pointer chain from that address"

MemCP: Uses get_base_address, then resolve_pointer_chain with specified offsets → 
       follows the pointer chain and returns the final resolved address

Example 4: Watching for Changes

User: "Watch the value at 0x12345678 and let me know when it changes"

MemCP: Uses watch_address with polling → returns old value, new value, and elapsed time
       when the address changes

Project Structure

MemCP/
├── README.md                     (this file)
├── MCP-Memory/
│   ├── package.json              (project metadata, Node.js 20+)
│   ├── tsconfig.json             (TypeScript config)
│   ├── build.bat                 (one-command setup script)
│   ├── ARCHITECTURE.md           (detailed design document)
│   ├── src/
│   │   ├── index.ts              (CLI entry point)
│   │   ├── server.ts             (MCP server setup)
│   │   ├── types.ts              (shared type definitions)
│   │   ├── memory/
│   │   │   ├── index.ts          (MemoryEngine: core read/write/scan)
│   │   │   ├── process-manager.ts (process attachment & handle mgmt)
│   │   │   ├── winapi.ts         (NT syscall bindings via koffi)
│   │   │   ├── peb-walker.ts     (module enumeration)
│   │   │   └── timing.ts         (jitter and cache-line alignment)
│   │   ├── tools/
│   │   │   ├── index.ts          (tool registration hub)
│   │   │   ├── process.ts        (process tools)
│   │   │   ├── read.ts           (memory read tools)
│   │   │   ├── write.ts          (memory write tools)
│   │   │   ├── modules.ts        (module/region tools)
│   │   │   ├── scan.ts           (pattern/value scan tools)
│   │   │   ├── struct.ts         (struct reading tool)
│   │   │   ├── analysis.ts       (diff, watch, resolve chain)
│   │   │   ├── virtual.ts        (allocate, protect, create_thread)
│   │   │   └── utils.ts          (shared tool utilities)
│   │   └── safety/
│   │       ├── limits.ts         (load config from env vars)
│   │       ├── validator.ts      (input validation)
│   │       └── audit.ts          (write operation logging)
│   ├── scripts/
│   │   └── install-copilot-mcp.mjs (MCP config installation)
│   └── dist/                     (compiled JavaScript, created by `npm run build`)
└── .squad/                       (team coordination files)

Configuration

All configuration is via environment variables (with sensible defaults):

Variable Default Purpose
MEMCP_TRANSPORT stdio Server transport (stdio only)
MEMCP_MAX_READ_SIZE 65536 Maximum bytes per single read (64 KB)
MEMCP_MAX_WRITE_SIZE 4096 Maximum bytes per single write (4 KB)
MEMCP_MAX_SCAN_RESULTS 1000 Maximum scan hits returned per scan
MEMCP_MAX_SCAN_REGION 67108864 Maximum region size for scanning (64 MB)
MEMCP_AUDIT_LOG true Enable/disable write operation audit logging to stderr
MEMCP_WRITE_ENABLED false Enable/disable all memory write tools (default: disabled for safety)
MEMCP_TIMING_JITTER_MS 0 Optional random per-operation delay (milliseconds) for analysis evasion
MEMCP_SCAN_TIMEOUT_MS 30000 Maximum scan operation duration (milliseconds)

Safety and Operational Notes

Safety Controls

  • Address Validation: Blocks null, guard regions, and kernel-space addresses (user-mode only)
  • Process Blocking: Prevents attachment to critical system processes (csrss.exe, lsass.exe, etc.)
  • Single Attachment: Only one process can be attached at a time
  • Size Limits: All reads, writes, and scans are size-bounded by configuration
  • Write Protection: Write tools can be globally disabled via MEMCP_WRITE_ENABLED=false
  • Audit Logging: All write operations are logged in JSON format to stderr for compliance
  • Handle Escalation: Process handles start read-only and only escalate when first write is attempted

Limitations

  • Windows x64 only in v1 (Linux and ARM support possible in future with kernel-mode driver)
  • User-mode access only (kernel-mode memory not accessible without a kernel driver)
  • Protected/System Processes: Requires elevated privileges; some processes may still deny access
  • Pointer reads: 8 bytes (x64); structure reading requires manual offset specification
  • Timing side-channels: Optional jitter available via MEMCP_TIMING_JITTER_MS for evasion scenarios

Development & Testing

Build & Run

cd MCP-Memory

# Install dependencies
npm install

# Build TypeScript
npm run build

# Run in dev mode (with tsx, no build step)
npm run dev

# Start the built server
npm run start

# Run linter
npm run lint

# Run tests
npm run test

# Watch mode for tests
npm run test:watch

# Clean build artifacts
npm run clean

Development Notes

  • TypeScript: Full type safety via Zod validation and static analysis
  • MCP SDK: @modelcontextprotocol/sdk v1.12.1+
  • Testing: Vitest with minimal test coverage (expand as needed)
  • Linting: ESLint v9 (ESLint config file not currently present)

License

MIT License — see LICENSE file for details.


Disclaimer: MemCP is designed for legitimate purposes including debugging, reverse engineering, process analysis, and memory forensics. Users are responsible for ensuring their use complies with applicable laws and policies. Do not use this tool for unauthorized access to systems or data.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages