JADX-AI-MCP

repository·jadx-ai·Indexed 25 days ago

https://github.com/zinja-coder/jadx-ai-mcp

A suite of tools integrating the JADX decompiler with the Model Context Protocol (MCP) to bring LLM capabilities to Android reverse engineering. It consists of a JADX plugin and an MCP server that allow AI agents to analyze decompiled code, perform static analysis, find vulnerabilities, and assist in debugging directly within the JADX environment. The system provides a wide array of MCP tools for fetching class sources, searching methods, analyzing AndroidManifest.xml, and interacting with the JADX debugger.

Tokens
17.5K
Snippets
53
Records
82
Agent score
81%

What's inside JADX-AI-MCP

  1. What is JADX-AI-MCP?

    jadx-ai

    JADX-AI-MCP is a plugin for the JADX decompiler that integrates with the Model Context Protocol (MCP). It enables LLMs (like Claude) to perform live reverse engineering, static code analysis, and real-time code review of Android APKs.

    It works in conjunction with the JADX MCP Server, which acts as the communication bridge between the LLM client and the JADX plugin.

  2. Security considerations for JADX-AI-MCP

    jadx-ai

    When using JADX-AI-MCP, be aware of the following security behaviors:

    • Localhost Binding: By default, the server binds to 127.0.0.1.
    • Remote Access Warning: If you use --host 0.0.0.0 to allow remote access, the MCP server becomes accessible to anyone on your network over unencrypted, unauthenticated plain HTTP. Use a firewall or SSH tunnel for remote access.
    • Proxy Isolation: Internal HTTP requests use trust_env=False to prevent proxy interception.
    • Data Privacy: The project does not collect telemetry or usage data.
  3. Security Model: Network, Input, and Transport

    jadx-ai

    The system implements several security layers:

    • Network Security: The plugin binds strictly to 127.0.0.1 (localhost), preventing remote access. It relies on OS-level user isolation for authentication.
    • Input Validation:
      • Resource paths are validated against the APK root to prevent Path Traversal.
      • Refactoring inputs are validated against Java naming rules to prevent Code Injection.
    • Transport Security:
      • Proxy Isolation: The Python httpx client uses trust_env=False to ensure local 127.0.0.1 traffic is not intercepted or routed through OS-level HTTP/HTTPS proxies.
      • Stdio Integrity: When running as an MCP stdio server, stdout is reserved exclusively for JSON-RPC communication. All logging, health checks, and banners are directed to stderr to prevent protocol corruption.
  4. Handle large datasets with PaginationUtils

    jadx-ai

    The PaginationUtils class provides a framework for consistent pagination across all JADX tools. It handles parameter validation and standardized response formatting.

    Key Constants

    • DEFAULT_PAGE_SIZE = 100
    • MAX_PAGE_SIZE = 10000
    • MAX_OFFSET = 1000000

    get_paginated_data()

    This method fetches paginated data from a JADX endpoint. It accepts a data_extractor (to pull items from the response) and a fetch_function (typically get_from_jadx).

    Response Format: Returns a dictionary with type: "paginated-list", containing items and a pagination object with total, offset, limit, count, has_more, next_offset, and prev_offset.

    # Example: Fetching first 50 classes
    result = await PaginationUtils.get_paginated_data(
        endpoint="all-classes",
        offset=0,
        count=50,
        data_extractor=lambda resp: resp.get("classes", []),
        fetch_function=get_from_jadx
    )
    
    print(f"Got {result['pagination']['count']} of {result['pagination']['total']} classes")
    for class_name in result['items']:
        print(class_name)
    
    if result['pagination']['has_more']:
        # Fetch next page using next_offset
        next_result = await PaginationUtils.get_paginated_data(
            endpoint="all-classes",
            offset=result['pagination']['next_offset'],
            count=50,
            data_extractor=lambda resp: resp.get("classes", []),
            fetch_function=get_from_jadx
        )
  5. Understand the JADX-AI-MCP Core Plugin Architecture

    jadx-ai

    The plugin is built on top of the JADX plugin system and exposes its functionality through an embedded Javalin HTTP server.

    Key architectural components:

    • JadxAIMCP: The main entry point implementing JadxPlugin.
    • PluginServer: Manages an embedded Jetty server using the Javalin framework.
    • Route Handlers: Specialized classes (e.g., ClassRoutes, SearchRoutes) that handle specific HTTP endpoints.
    • Lifecycle: The plugin uses a delayed initialization pattern to ensure the server only starts after JADX has fully loaded the APK content.
    // Delayed initialization pattern
    private void startDelayedInitialization() {
        scheduler.scheduleAtFixedRate(() -> {
            if (isJadxFullyLoaded()) {
                startServer();
                scheduler.shutdown();
            }
        }, 2, 1, TimeUnit.SECONDS);
    }
  6. Handle UI/Data access in the Java Plugin using the EDT Pattern

    jadx-ai

    The JADX Plugin uses a multi-threaded model where the HTTP server (Jetty/Javalin) runs on a worker thread pool. Because JADX is a GUI-based application, any JADX API calls that access UI components or shared data must be executed on the Event Dispatch Thread (EDT) to avoid ConcurrentModificationException or other threading issues.

    To safely access data from a worker thread, wrap the call in SwingUtilities.invokeLater.

    // Wrong: Direct access from worker thread
    String code = javaClass.getCode(); // ConcurrentModificationException
    
    // Correct: Wrap in invokeLater
    SwingUtilities.invokeLater(() -> {
        String code = javaClass.getCode(); // Safe
    });
  7. How JADX-AI-MCP and JADX MCP Server work together

    jadx-ai

    The system follows a specific request flow to allow an LLM to interact with the JADX GUI:

    1. LLM Client invokes an MCP tool via the JADX MCP Server.
    2. JADX MCP Server sends an HTTP request to the JADX AI MCP Plugin.
    3. JADX AI MCP Plugin invokes a request handler.
    4. Request Handlers perform actions or gather data from the JADX GUI.
    5. The data/action result flows back through the plugin and server to the LLM Client.
    sequenceDiagram
    LLM CLIENT->>JADX MCP SERVER: INVOKE MCP TOOL
    JADX MCP SERVER->>JADX AI MCP PLUGIN: INVOKE HTTP REQUEST
    JADX AI MCP PLUGIN->>REQUEST HANDLERS: INVOKE HTTP REQUEST HANDLER
    REQUEST HANDLERS->>JADX GUI: PERFORM ACTION/GATHER DATA
    JADX GUI->>REQUEST HANDLERS: ACTION PERFORMED/DATA GATHERED
    REQUEST HANDLERS->>JADX AI MCP PLUGIN: CRAFT HTTP RESPONSE
    JADX AI MCP PLUGIN->>JADX MCP SERVER:HTTP RESPONSE
    JADX MCP SERVER->>LLM CLIENT: MCP TOOL RESULT
  8. How JADX-AI-MCP works

    jadx-ai

    JADX-AI-MCP is a reverse engineering toolkit that connects the JADX decompiler to Large Language Models (LLMs) using the Model Context Protocol (MCP). It consists of two main components:

    1. JADX-AI-MCP Plugin (Java): A plugin for JADX-GUI that exposes decompiler data (code, resources, debug info) via a local HTTP API.
    2. JADX-MCP-Server (Python): An MCP server that acts as a bridge, translating MCP tool calls from an AI assistant (like Claude) into HTTP requests for the JADX plugin.

    Network Architecture

    The system maintains two distinct connections:

    • Client ↔ MCP Server: The LLM client connects to the MCP server (configured via --host and --port).
    • MCP Server ↔ JADX Plugin: The MCP server connects to the JADX plugin (configured via --jadx-host and --jadx-port).
  9. Understand the JADX-AI-MCP 3-Tier Architecture

    jadx-ai

    JADX-AI-MCP operates using a three-tier architecture to bridge LLM clients with JADX decompilation capabilities:

    1. Presentation Tier: The LLM Client (e.g., Claude, Cherry Studio) that interacts with the user.
    2. Application Tier: The MCP Server (written in Python) which acts as the intermediary using the FastMCP library.
    3. Data Tier: The JADX Plugin (Java) and JADX Core, which handle the actual decompilation and APK analysis.

    The flow of communication is: LLM Client $\rightarrow$ MCP Server (Python) $\rightarrow$ Javalin Server (Java Plugin) $\rightarrow$ JADX API $\rightarrow$ JADX GUI.

  10. Project structure and component locations

    jadx-ai

    The project is split into two main components:

    • JADX-AI-MCP (Plugin): The Java-based plugin files are located within this repository.
    • jadx-mcp-server (MCP Server): The Python-based server files are located in a separate repository: https://github.com/zinja-coder/jadx-mcp-server.
  11. Optimize large APK analysis with Pagination

    jadx-ai

    To prevent JSON serialization overhead, network latency, and LLM client timeouts (which typically occur after 60s), all list endpoints implement a pagination strategy. This is essential when dealing with large APKs containing thousands of classes.

    • Mechanism: Use offset and count parameters.
    • Default page size: 100 items.
    • Maximum page size: 10,000 items.
  12. Configure Custom JADX Plugin Host and Port

    jadx-ai

    If your JADX-GUI plugin is running on a custom port or a different machine, you must configure the MCP server to find it using --jadx-host and --jadx-port.

    Example: Connecting to a remote JADX host

    uv run jadx_mcp_server.py --jadx-host 192.168.1.100 --jadx-port 8650

    Example: Claude Desktop config for custom JADX port

    If the JADX plugin is on port 8652, update your claude_desktop_config.json arguments:

    {
      "mcpServers": {
        "jadx-mcp-server": {
          "command": "/path/to/uv",
          "args": [
            "--directory",
            "/path/to/jadx-mcp-server/",
            "run",
            "jadx_mcp_server.py",
            "--jadx-port",
            "8652"
          ]
        }
      }
    }
    {
      "mcpServers": {
        "jadx-mcp-server": {
          "command": "/path/to/uv",
          "args": [
            "--directory",
            "/path/to/jadx-mcp-server/",
            "run",
            "jadx_mcp_server.py",
            "--jadx-port",
            "8652"
          ]
        }
      }
    }