amenallahbarkaoui-github/APK_AGI
GitHub: amenallahbarkaoui-github/APK_AGI
一个基于 LangGraph 与 NetworkX 的自主智能体系统,专为 Android APK 的自动化反编译、安全审计与修补签名提供端到端解决方案。
Stars: 1 | Forks: 0
🧠 APK AGI
AI-Powered Autonomous Android Reverse-Engineering Agent
A fully autonomous agentic system that decompiles, analyzes, patches, rebuilds & signs Android APKs — driven entirely by natural language.
Features • Architecture • Tools • Getting Started • Usage • Credits
## 🎯 什么是 APK AGI? **APK AGI** is a state-of-the-art autonomous agent that performs professional-grade Android APK security analysis and modification through natural language conversation. Powered by a **LangGraph ReAct state machine**, a **NetworkX code graph**, and armed with **70 specialized tools**, it can: - 🔍 **Decompile** APKs into Smali bytecode, Java source, and JAR archives - 🛡️ **Detect** 25+ vulnerability patterns (SSL bypass, root detection, weak crypto, WebView RCE, etc.) - 🧬 **Reverse-engineer** encrypted payloads, obfuscated strings, and native bridges - 🔧 **Patch** Smali bytecode to bypass protections (SSL pinning, anti-tamper, anti-debug) - 🤖 **Auto-bypass** 50+ protection patterns across 11 categories in a single call - 🗺️ **Map** the entire codebase into a NetworkX call graph for instant tracing - 📦 **Rebuild & sign** fully functional, installable APKs - 📝 **Generate** detailed forensic Markdown reports All through a single chat prompt: *"Bypass SSL pinning and disable root detection in this APK."* ## ✨ 特性 ### 核心能力 | Category | Capabilities | |:---------|:-------------| | **Decompilation** | Smali (apktool), Java source (JADX), JAR archive (dex2jar) | | **Code Graph** | NetworkX-powered call graph — instant caller/callee tracing, path finding, security scan, class info, persistent `.pickle` cache | | **Code Index** | Persistent class/method/string/package lookup — instant search from JSON index cache | | **Vulnerability Scanning** | 25+ patterns — SSL bypass, root/emulator detection, weak crypto, hardcoded secrets, WebView RCE, SQL injection, logging leaks, dynamic code loading, IPC issues | | **Protection Detection** | Root detection, emulator checks, anti-debug, anti-tamper, obfuscation, SSL pinning, certificate validation | | **Crypto Analysis** | ECB mode usage, hardcoded keys, weak hashing (MD5/SHA1), string decryption, XOR/Base64 deobfuscation | | **Network Analysis** | SSL pinning configs, OkHttp/Retrofit interceptor chains, cleartext traffic, trust anchors, network security config | | **Native Code** | JNI declarations, `System.loadLibrary`, `.so` library inventory, React Native & Flutter bridges, native string extraction | | **Dynamic Loading** | `DexClassLoader`, `Class.forName`, reflection, hidden DEX/JAR in assets | | **Attack Surface** | Exported components, deep links, custom permissions, intent filters, risk scoring | | **Package Isolation** | Auto-detect app packages vs third-party SDKs (50+ SDK prefixes), auto-exclude noise from searches | | **Smali Patching** | 6 operation types (replace, insert, delete) with auto-backup, unified diffs, and preview mode | | **Automated Bypass Engine** | One-shot auto-bypass across 11 categories: SSL, VPN, root, license, purchase, ads, screenshot, USB debug, device/package spoof, Flutter binary SSL patch | | **Deep Analysis** | Entry point discovery, class hierarchy mapping, SharedPreferences analysis, asset secret scanning, smali syntax validation, patched file diffing | | **Build Pipeline** | Rebuild → zipalign → sign — outputs a ready-to-install APK | | **Forensic Evidence** | Persistent evidence notebook that survives context compaction | | **Reporting** | Markdown report with executive summary, findings table, patch diffs, and tool execution log | ### 独特之处 - **🤖 Fully Autonomous** — Reasons, plans, executes, and adapts without hand-holding - **🔄 ReAct Loop** — Think → Act → Observe → Re-plan cycle with dynamic strategy adjustment - **🗺️ Code Graph** — NetworkX-powered call graph built from smali for instant caller/callee tracing and security scans - **📇 Code Index** — Persistent class/method/string index for instant lookups without file scanning - **🎯 Package Isolation** — Auto-detects app packages vs 50+ third-party SDKs, excludes noise from all searches - **⚡ Automated Bypass Engine** — 50+ patterns across 11 categories, applied in a single call (SSL, VPN, root, license, ads, Flutter binary patching) - **🧠 Context Compaction** — Automatically summarizes old messages at 90K tokens to maintain coherence in long sessions - **🔒 Human-in-the-Loop** — Interrupts for user approval on high-risk smali patches before applying - **💾 Durable State** — Findings, patches, and evidence survive context compaction via LangGraph state - **⚡ Tool Caching** — Idempotent tools are cached within session to skip redundant re-runs - **📋 Evidence System** — Forensic notebook with categorized, severity-tagged, searchable entries - **🔐 Smart Patch Ordering** — Anti-tamper patches applied first (prevents rebuilt APK crashes) - **🔀 Multi-DEX Support** — Searches all `smali/`, `smali_classes2/`, `smali_classes3/`, etc. directories ## 🏗️ 架构 ``` ┌─────────────────────────────────────────────────────────────────────┐ │ APK AGI — Agent Core │ ├─────────────────────────────────────────────────────────────────────┤ │ │ │ ┌──────────┐ ┌─────────────────┐ ┌──────────────────────┐ │ │ │ User │───▶│ CLI / Rich UI │───▶│ LangGraph Engine │ │ │ │ (Chat) │◀───│ (Interactive) │◀───│ (State Machine) │ │ │ └──────────┘ └─────────────────┘ └──────────┬───────────┘ │ │ │ │ │ ┌───────────────────────────┼──────┐ │ │ ▼ ▼ │ │ │ ┌─────────────┐ ┌────────────┐ │ │ │ │ agent_node │◀──────────▶│ tools │ │ │ │ │ (LLM Call) │ │ (ToolNode)│ │ │ │ └──────┬──────┘ └─────┬──────┘ │ │ │ │ │ │ │ │ ▼ ▼ │ │ │ ┌─────────────┐ ┌────────────┐ │ │ │ │ should_ │ │ tools_ ◀──┘ │ │ │ continue │ │ postproc │ │ │ └──┬───┬──┬──┘ └────────────┘ │ │ │ │ │ │ │ ┌─────────┘ │ └──────────┐ │ │ ▼ ▼ ▼ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ tools │ │ human_ │ │ END │ │ │ │ (loop) │ │ review │ │ │ │ │ └──────────┘ └──────────┘ └──────────┘ │ │ │ ├─────────────────────────────────────────────────────────────────────┤ │ Tool Arsenal (70) │ ├──────────┬──────────┬──────────┬──────────┬──────────┬─────────────┤ │Decompile │ Analysis │ Scanning │ Patching │ Build │ Evidence │ │ apktool │ smali │ vuln_ │ apply_ │ apktool │ save_ │ │ jadx │ deep │ scanner │ patch │ _build │ evidence │ │ dex2jar │ manifest │ detect_ │ preview_ │ zipalign │ load_ │ │ aapt2 │ strings │ protect │ patch │ sign_apk │ evidence │ │ │ network │ targeted │ auto_ │ │ search_ │ │ │ native │ analysis│ bypass │ │ evidence │ │ │ cert │ xref │ flutter │ │ summary │ │ │ componen │ │ manifest │ │ │ │ │ graph │ │ nsc_ │ │ │ │ │ index │ │ inject │ │ │ │ │ deep_ │ │ rm_ads │ │ │ │ │ analysis│ │ │ │ │ │ │ pkg_iso │ │ │ │ │ └──────────┴──────────┴──────────┴──────────┴──────────┴─────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────────┐ │ Persistent Data Layer │ │ Code Graph (NetworkX .pickle) • Code Index (JSON) • Evidence DB │ ├─────────────────────────────────────────────────────────────────────┤ │ External Android Tools │ │ apktool 2.9.3 • JADX 1.5.0 • dex2jar • apksigner • zipalign │ └─────────────────────────────────────────────────────────────────────┘ ``` ### 代理循环流程 ``` ┌──────────────────────┐ │ User Message │ └──────────┬───────────┘ │ ▼ ┌──────────────────────┐ │ 🧠 Agent Node │ ◄─── LLM reasons about task │ (Think + Plan) │ Reviews findings so far └──────────┬───────────┘ Decides next action │ ┌─────────┼──────────┐ │ │ │ ▼ ▼ ▼ ┌──────┐ ┌────────┐ ┌──────┐ │Tools │ │ Human │ │ END │ │Call │ │ Review │ │ │ └──┬───┘ └───┬────┘ └──────┘ │ │ ▼ ▼ ┌──────────┐ User approves │ Execute │ or rejects │ Tool(s) │ the patch └──┬───────┘ │ ▼ ┌───────────────┐ │ Post-Process │ ◄── Extract findings │ (save to state)│ Save evidence └───────┬───────┘ Cache results │ ▼ Back to Agent (Observe + Re-plan) ``` ## 🔧 工具库 ### 完整工具清单(41 个工具)🔨 Decompilation (3)
| Tool | Description | |:-----|:------------| | `apktool_decompile` | Decompile APK → Smali bytecode + resources + AndroidManifest | | `jadx_decompile` | Decompile APK → readable Java source code | | `dex2jar_convert` | Convert DEX → JAR archive for JVM-level analysis |🔎 Quick Reconnaissance (3)
| Tool | Description | |:-----|:------------| | `aapt2_dump` | Extract package name, version, SDK info, permissions, components | | `extract_strings` | Classify strings: URLs, API keys, AWS keys, Firebase, tokens, Base64 | | `analyze_certificate` | Certificate fingerprints (MD5/SHA1/SHA256), debug detection, signature scheme |📋 Manifest & Components (4)
| Tool | Description | |:-----|:------------| | `parse_manifest` | Parse permissions (dangerous set flagged), exported components, security flags | | `analyze_attack_surface` | Exported component risk scores, deep links, custom permissions, intent filters | | `analyze_network_config` | Cleartext traffic, trust anchors, certificate pinning, domain rules | | `score_permissions` | Risk-scored permissions: CRITICAL / HIGH / MEDIUM / LOW with abuse potential |🧬 Smali Deep Analysis (4)
| Tool | Description | |:-----|:------------| | `scan_smali_classes` | Class counts, crypto API usage, method summaries | | `analyze_smali_class` | Parse class info, methods, fields, string constants, security APIs | | `find_string_decryption_patterns` | Detect XOR loops, Base64 decoding, byte-array-to-String obfuscation | | `find_method_xrefs` | All call sites — reverse cross-reference graph |🕵️ Professional Reversing (4)
| Tool | Description | |:-----|:------------| | `analyze_method_deep` | Full disassembly — registers, API calls, strings, branches, try/catch | | `detect_protections` | ALL protections: root, emulator, anti-debug, anti-tamper, DCL, native, obfuscation, SSL | | `trace_call_chain` | Reverse call graph — who calls method → who calls them (configurable depth) | | `reconstruct_strings` | Decode obfuscated byte arrays, char arrays, and string building patterns |🛡️ Vulnerability Scanning (2)
| Tool | Description | |:-----|:------------| | `scan_vulnerabilities` | 25+ patterns: SSL bypass, root detection, weak crypto, hardcoded secrets, WebView RCE, SQL injection, logging, DCL, IPC | | `list_vuln_patterns` | Metadata on all patterns — ID, name, severity, CWE mapping, category |🔍 Advanced Search (4)
| Tool | Description | |:-----|:------------| | `context_search` | Grep with surrounding context lines | | `multi_search` | Multi-pattern AND/OR search across codebase | | `xref_search` | Cross-reference callers/callees of any class or method | | `directory_overview` | File counts, sizes, types for analysis planning |🎯 Targeted Analysis (3)
| Tool | Description | |:-----|:------------| | `search_interceptors` | Find OkHttp/Retrofit interceptors, chain.proceed, crypto+network co-location | | `search_native_code` | JNI declarations, `System.loadLibrary`, React Native/Flutter bridges, `.so` inventory | | `search_dynamic_loaders` | DexClassLoader, Class.forName, reflection, runtime DEX/JAR loading, hidden DEX in assets |📁 File Operations (4)
| Tool | Description | |:-----|:------------| | `read_file` | Read files with 5 fallback path resolutions | | `write_file` | Write/modify files in project | | `search_in_code` | Regex search across `.java`/`.smali`/`.kt` only (no XML/JSON noise) | | `list_files` | Directory structure browsing with configurable depth |🔬 Evidence & Forensics (4)
| Tool | Description | |:-----|:------------| | `save_evidence` | Append to forensic notebook — 12 categories, severity-tagged | | `load_evidence` | Retrieve evidence by category or severity filter | | `search_evidence` | Keyword search within evidence entries | | `get_evidence_summary` | Counts by category/severity, critical findings list |🔧 Patching (2)
| Tool | Description | |:-----|:------------| | `apply_smali_patch` | Apply patch plan with auto-backup + unified diff generation | | `preview_smali_patch` | Preview changes without modifying (validation step) |📦 Build & Sign (3)
| Tool | Description | |:-----|:------------| | `apktool_build` | Rebuild APK from patched Smali | | `zipalign_apk_tool` | 4-byte alignment optimization (pre-signing) | | `sign_apk` | Sign APK with configured keystore |📝 Reporting (1)
| Tool | Description | |:-----|:------------| | `generate_report` | Markdown report: executive summary, findings, patches, tool log, limitations |Built with ❤️ by Amenallah Barkaoui
标签:AI-Powered, AI代理, AI安全研究, Android应用安全, Android逆向工程, APK AGI, APK分析, Autonomous Agent, JAR提取, Java源码, LangGraph, NetworkX, Python3.11+, ReAct状态机, Reverse Engineering, Smali反编译, SSL绕过, v3.0.0, WebView RCE, 云安全监控, 代码图谱, 字节码补丁, 开源安全工具, 弱加密, 根检测, 特权检测, 突变策略, 自动修补, 自然语言控制, 资源提取, 逆向工具, 逆向工程平台, 逆向工程自动化, 防篡改, 防调试, 静态分析