android-renef-mcp 0.1.0__py3-none-any.whl

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.
Files changed (51) hide show
  1. android_renef_mcp-0.1.0.dist-info/METADATA +216 -0
  2. android_renef_mcp-0.1.0.dist-info/RECORD +51 -0
  3. android_renef_mcp-0.1.0.dist-info/WHEEL +4 -0
  4. android_renef_mcp-0.1.0.dist-info/entry_points.txt +2 -0
  5. android_renef_mcp-0.1.0.dist-info/licenses/LICENSE +201 -0
  6. renef_mcp/__init__.py +3 -0
  7. renef_mcp/__main__.py +6 -0
  8. renef_mcp/adb.py +143 -0
  9. renef_mcp/client.py +628 -0
  10. renef_mcp/config.py +65 -0
  11. renef_mcp/lua.py +83 -0
  12. renef_mcp/scripts/LICENSE +21 -0
  13. renef_mcp/scripts/dere_0x9.lua +36 -0
  14. renef_mcp/scripts/flutter_ssl.lua +110 -0
  15. renef_mcp/scripts/hexdump.lua +64 -0
  16. renef_mcp/scripts/hook_native_lib.lua +5 -0
  17. renef_mcp/scripts/java_api_example.lua +73 -0
  18. renef_mcp/scripts/java_hook.lua +43 -0
  19. renef_mcp/scripts/kcov_test.lua +163 -0
  20. renef_mcp/scripts/memory_scan.lua +15 -0
  21. renef_mcp/scripts/module.lua +21 -0
  22. renef_mcp/scripts/multi_hook_test.lua +42 -0
  23. renef_mcp/scripts/root_bypass.lua +632 -0
  24. renef_mcp/scripts/simple_fopen_test.lua +40 -0
  25. renef_mcp/scripts/ssl_unpin.lua +1174 -0
  26. renef_mcp/scripts/strace_custom.lua +20 -0
  27. renef_mcp/scripts/strace_file.lua +11 -0
  28. renef_mcp/scripts/strace_network.lua +21 -0
  29. renef_mcp/scripts/syscall_test.lua +173 -0
  30. renef_mcp/scripts/thread_test.lua +30 -0
  31. renef_mcp/scripts.py +28 -0
  32. renef_mcp/server.py +938 -0
  33. renef_mcp/session.py +114 -0
  34. renef_mcp/techniques/LICENSE +21 -0
  35. renef_mcp/techniques/ssl_pinning/README.md +143 -0
  36. renef_mcp/techniques/ssl_pinning/advanced_bypass_techniques.md +309 -0
  37. renef_mcp/techniques/ssl_pinning/android_native.md +610 -0
  38. renef_mcp/techniques/ssl_pinning/certificate_pinning_fundamentals.md +50 -0
  39. renef_mcp/techniques/ssl_pinning/cordova_ionic.md +192 -0
  40. renef_mcp/techniques/ssl_pinning/detection_anti_tampering.md +158 -0
  41. renef_mcp/techniques/ssl_pinning/flutter.md +518 -0
  42. renef_mcp/techniques/ssl_pinning/how_ssl_tls_works.md +65 -0
  43. renef_mcp/techniques/ssl_pinning/introduction_to_ssl_pinning.md +27 -0
  44. renef_mcp/techniques/ssl_pinning/network_security_configuration.md +190 -0
  45. renef_mcp/techniques/ssl_pinning/platform_mapping.json +160 -0
  46. renef_mcp/techniques/ssl_pinning/react_native.md +329 -0
  47. renef_mcp/techniques/ssl_pinning/summary.md +34 -0
  48. renef_mcp/techniques/ssl_pinning/third_party_libraries.md +191 -0
  49. renef_mcp/techniques/ssl_pinning/unity.md +262 -0
  50. renef_mcp/techniques/ssl_pinning/xamarin.md +246 -0
  51. renef_mcp/techniques.py +74 -0
@@ -0,0 +1,216 @@
1
+ Metadata-Version: 2.5
2
+ Name: android-renef-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP server for Renef - dynamic instrumentation toolkit for Android ARM64
5
+ Project-URL: Homepage, https://renef.io
6
+ Project-URL: Repository, https://github.com/FlyPhantomFly/android-renef-mcp
7
+ Project-URL: Issues, https://github.com/FlyPhantomFly/android-renef-mcp/issues
8
+ Author: android-renef-mcp contributors
9
+ License: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: android,frida,instrumentation,lua,mcp,renef,reverse-engineering
12
+ Requires-Python: >=3.10
13
+ Requires-Dist: mcp<2,>=1.12.0
14
+ Description-Content-Type: text/markdown
15
+
16
+ # android-renef-mcp
17
+
18
+ An MCP server for [Renef](https://renef.io), a Frida-like dynamic instrumentation
19
+ toolkit for Android ARM64. With it, an AI agent can attach to a process on a
20
+ rooted device (or spawn one, held paused at startup), run Lua inside the target,
21
+ hook native and Java methods, read and write process memory, and collect hook
22
+ output.
23
+
24
+ Renef is not Frida: the agent runs Lua instead of JavaScript, the API is its own
25
+ (`hook()`, `Module.*`, `Memory.*`, `Java.use`, `Syscall.trace`), and nothing
26
+ frida-related has to be on the device. Just `renef_server` and a rooted handset.
27
+ That matters for apps whose protections look for Frida.
28
+
29
+ ```
30
+ ┌──────────────┐ stdio/MCP ┌─────────────┐ TCP :1907 ┌───────────────┐
31
+ │ MCP client │ ◄───────────► │ renef-mcp │ ◄──────────► │ renef_server │
32
+ │ (AI agent) │ │ (this pkg) │ (adb fwd) │ on device(adb)│
33
+ └──────────────┘ └─────────────┘ └──────┬────────┘
34
+ │ agent socket
35
+ ▼
36
+ ┌─────────────────┐
37
+ │ libagent.so │
38
+ │ inside target │
39
+ │ app (Lua VM) │
40
+ └─────────────────┘
41
+ ```
42
+
43
+ ## Tools (38)
44
+
45
+ **Status and discovery** (no target needed)
46
+
47
+ - `renef_status()` — adb devices, port forward, server ping/pong, session state
48
+ - `renef_list_apps(third_party_only)` — installed packages
49
+ - `renef_list_processes()` — running processes, for `renef_attach`
50
+
51
+ **Server lifecycle** (no session needed)
52
+
53
+ - `renef_server_deploy()` — push the built `renef_server` and `libagent.so` to the
54
+ device, set permissions and the SELinux context the agent needs, verify by md5
55
+ - `renef_server_start()` / `renef_server_stop()` / `renef_server_restart()` —
56
+ root-managed lifecycle with ping verification
57
+ - `renef_server_logs(lines)` — tail the server log on the device
58
+
59
+ **Session**
60
+
61
+ - `renef_attach(pid)` — inject the agent into a running process
62
+ - `renef_spawn(package)` — spawn an app gated at startup (ptrace pause) and
63
+ inject the agent. The first exec auto-resumes it, or call `renef_resume`
64
+ without a script
65
+ - `renef_resume()` — resume a spawn-gated process
66
+ - `renef_disconnect()` — close the session; the target keeps running
67
+
68
+ **Execution**
69
+
70
+ - `renef_exec(lua)` — run Lua in the target and get back its `print()` output.
71
+ The workhorse, and multi-line Lua is fine
72
+ - `renef_load_script(path)` — run a Lua file from the host machine
73
+
74
+ **Memory**
75
+
76
+ - `renef_mem_scan(pattern, module)` — scan for a hex pattern. Prefer
77
+ `module="libfoo.so"`, which uses Lua `Memory.search` and takes spaces and `??`
78
+ wildcards. Without a module it's the upstream full-process scan: compact hex
79
+ only, and big processes can outrun the server's ~10s response cap
80
+ - `renef_mem_read(addr, size)` — hexdump, up to 4096 bytes
81
+ - `renef_mem_read_value(addr, size, signed)` — integer read, 1/2/4/8 bytes
82
+ - `renef_mem_read_string(addr, max_len)` — NUL-terminated C string
83
+ - `renef_mem_write(addr, hex_bytes)` — write raw bytes
84
+ - `renef_mem_write_value(addr, value, size)` — write an integer, verified by
85
+ reading it back
86
+ - `renef_mem_patch(addr, hex_bytes)` — like `mem_write` but via `Memory.patch`,
87
+ which handles `mprotect` itself, so read-only code pages are fair game
88
+
89
+ **Modules**
90
+
91
+ - `renef_module_list()` and `renef_module_find(name)` — loaded libraries, base
92
+ addresses
93
+ - `renef_module_exports(name, filter, limit)` / `renef_module_symbols(name, filter, limit)`
94
+ - `renef_sections(lib)` — ELF sections of a loaded library
95
+ - `renef_framework_detect()` — flags Flutter, React Native, Unity, Xamarin or
96
+ Cordova by their characteristic libraries
97
+ - `renef_hook_generate(lib, symbol_or_offset)` — server-generated Lua hook
98
+ template; give it a symbol and it resolves the offset first
99
+
100
+ **Hooks**
101
+
102
+ - `renef_hook_native(lib, offset, on_enter, on_leave, caller)` — trampoline hook
103
+ by default; pass `caller="libtarget.so"` for the PLT/GOT backend. Callbacks
104
+ are Lua statements over `args[0..7]` (onEnter) and `retval` (onLeave). Find
105
+ offsets with `renef_module_exports` first
106
+ - `renef_hook_java(class, method, signature, on_enter, on_leave)` — ART method
107
+ hook. Classes in slash form (`com/example/Class`), JNI signatures. `args[0]`
108
+ is the ArtMethod pointer, `args[1]` is `this`, `args[2..]` are the parameters,
109
+ and `args.skip = true` bypasses a void method
110
+ - `renef_list_hooks()` / `renef_unhook(hook_id | "all")` — native hooks only.
111
+ Java hooks aren't in the upstream registry; they're cleared on the next
112
+ attach/spawn
113
+ - `renef_watch(seconds)` — capture hook/strace output for a window. Blocks the
114
+ session exclusively, capped at 60s, and shows nothing if the app does nothing
115
+
116
+ **Diagnostics**
117
+
118
+ - `renef_backtrace()` — current-thread call stack
119
+
120
+ **Script library** (vendored from [ahmeth4n/renef-mcp](https://github.com/ahmeth4n/renef-mcp), MIT)
121
+
122
+ - `renef_list_scripts()` — 18 bundled examples: hook demos, tracing, and working
123
+ bypasses like `flutter_ssl`, `ssl_unpin` and `root_bypass`
124
+ - `renef_get_script(name)` — the Lua source, ready for `renef_load_script`
125
+
126
+ **Technique knowledge base** (vendored from ahmeth4n/renef-mcp, MIT)
127
+
128
+ - `renef_technique_list()` — categories and platforms; currently `ssl_pinning`
129
+ for android_native, flutter, react_native, unity, xamarin and cordova_ionic
130
+ - `renef_technique(category, platform)` — the assembled guide, e.g.
131
+ `renef_technique("ssl_pinning", "flutter")`
132
+
133
+ Resources: `renef://status` for live chain status, `renef://docs/lua-api` for the
134
+ full Lua API reference (read from the Renef checkout). There's also a
135
+ `renef_expert(task)` prompt that keeps agents from accidentally writing Frida
136
+ code.
137
+
138
+ ## Usage
139
+
140
+ Requirements: Python 3.10+, `adb`, and Renef built for the device. Build once:
141
+
142
+ ```bash
143
+ cd ~/github/renef
144
+ make # produces build/android/renef_server and libagent.so
145
+ ```
146
+
147
+ Then install this package and register it with your MCP client. Once it's on
148
+ PyPI this is just:
149
+
150
+ ```bash
151
+ pip install android-renef-mcp
152
+ claude mcp add renef -- android-renef-mcp
153
+ ```
154
+
155
+ From a source checkout meanwhile:
156
+
157
+ ```bash
158
+ cd ~/github/android-renef-mcp
159
+ uv sync
160
+ claude mcp add renef -- uv run --directory ~/github/android-renef-mcp android-renef-mcp
161
+ ```
162
+
163
+ Or the JSON form most clients accept:
164
+
165
+ ```json
166
+ {
167
+ "mcpServers": {
168
+ "renef": {
169
+ "command": "uv",
170
+ "args": ["run", "--directory", "/home/<you>/github/android-renef-mcp", "android-renef-mcp"]
171
+ }
172
+ }
173
+ }
174
+ ```
175
+
176
+ After that you don't need to touch adb yourself: `renef_server_deploy()` pushes
177
+ the built binaries, `renef_server_start()` starts the server as root and sets up
178
+ the port forward, and `renef_status()` confirms the chain. If you'd rather do it
179
+ by hand, the old route still works:
180
+
181
+ ```bash
182
+ adb shell "su -c '/data/local/tmp/renef_server'" # start the server (root)
183
+ ```
184
+
185
+ The server takes no arguments. Environment variables, should you need them:
186
+ `RENEF_HOME` (Renef checkout, used for the Lua API docs resource; default
187
+ `~/github/renef`), `RENEF_BIN_DIR` (where `renef_server_deploy` finds the built
188
+ binaries; default `<RENEF_HOME>/build/android`), `RENEF_HOST`/`RENEF_PORT`
189
+ (server address, default `127.0.0.1:1907` over the adb forward) and `RENEF_ADB`
190
+ (adb binary path).
191
+
192
+ A session then looks like this:
193
+
194
+ ```
195
+ renef_status
196
+ renef_spawn("com.example.app")
197
+ renef_module_exports("libtarget.so", filter="crypt")
198
+ renef_hook_native("libtarget.so", "0x1a2b3",
199
+ on_enter="print('arg:', Memory.readString(args[0]))")
200
+ renef_watch(5)
201
+ renef_unhook("all")
202
+ renef_disconnect()
203
+ ```
204
+
205
+ ## Planned integration
206
+
207
+ This server is planned for integration into
208
+ [android-re-mcp](https://github.com/FlyPhantomFly/android-re-mcp) as its
209
+ Frida-alternative dynamic instrumentation layer. Until then, this repo is the
210
+ standalone source.
211
+
212
+ ## License
213
+
214
+ Apache-2.0 for the code. The bundled Lua scripts and technique documents come
215
+ from [ahmeth4n/renef-mcp](https://github.com/ahmeth4n/renef-mcp) and are MIT
216
+ (license texts live in `renef_mcp/scripts/` and `renef_mcp/techniques/`).
@@ -0,0 +1,51 @@
1
+ renef_mcp/__init__.py,sha256=2rRkaxlNmusAY6edKfdIllH8kOJpYiNxuw0CVNGfhD4,122
2
+ renef_mcp/__main__.py,sha256=iTOkfLPPHBfmco_5BGi40BJRfMQelYWvfPMqWNtYbAQ,95
3
+ renef_mcp/adb.py,sha256=vkGddcQo2XsVcZ3IdslZAHHAPU6WwOk-xRFfyAiocRc,4652
4
+ renef_mcp/client.py,sha256=prnKoueca3ou1fu5C7INWydcWHU4bfgFUV3MVtoXCwc,25373
5
+ renef_mcp/config.py,sha256=TZC5b9hr2IDyDApff_ig88lupX5Rz11x-PyU5qIiqT4,1796
6
+ renef_mcp/lua.py,sha256=K-3eaky8Bgfalt3PomL9EQw9DoHjJeG2xZJYVzGoVWA,2771
7
+ renef_mcp/scripts.py,sha256=0xKE8BanvqR3fhcGpueTah0T4Vax1cpvi-dgZfXq9gY,1043
8
+ renef_mcp/server.py,sha256=3eQAzezc4hmAfT9Q9sE_5u89ZIyW5f5-JOFlSIKH7ok,36669
9
+ renef_mcp/session.py,sha256=SYy5aUo5EK894cHYIXpC7-aukQ_VIaYAT16v4aYA11M,3861
10
+ renef_mcp/techniques.py,sha256=A6Yd8Ear6UhfLNZ8U6_omCqmrN1iYfZQIySKZG6Id6w,2675
11
+ renef_mcp/scripts/LICENSE,sha256=SlT7B6ld5tmCUu539tHQBHYY5KzKsbES1tp-tapHhNI,1064
12
+ renef_mcp/scripts/dere_0x9.lua,sha256=vtHKKMlHkQaeLLhY4Ttqk2hLXNa-8oxSilOYL5KnoOQ,916
13
+ renef_mcp/scripts/flutter_ssl.lua,sha256=fu3ljRKJI2Sw3Jdk63isKfv4aNvYqN2xLHUTihXNTDQ,3813
14
+ renef_mcp/scripts/hexdump.lua,sha256=phxUgAmggsX25K__oeaeTzLgdRUFCfFI2ujvKIue0Po,2219
15
+ renef_mcp/scripts/hook_native_lib.lua,sha256=1KtUjSVuoxxtlteyXmvn6_IgPShLCVhMgpI-oA9C5KI,101
16
+ renef_mcp/scripts/java_api_example.lua,sha256=r2KJnMZMK8kDtJdg8y76nmnWyU3wI93sPHb9BK0HmHg,2497
17
+ renef_mcp/scripts/java_hook.lua,sha256=eO9eQNjkliohAOhJCj0ra25VgIUPhxgT4C8ruyp4BnE,1578
18
+ renef_mcp/scripts/kcov_test.lua,sha256=1Z-XPSaV5bxRQMIXry0iRsiOONZR-ZLD5a-8QBWDrxM,4666
19
+ renef_mcp/scripts/memory_scan.lua,sha256=JLpqy5-2Lot2WtuKGyrU8JIczcyr5uh0k32RKe1nBcg,463
20
+ renef_mcp/scripts/module.lua,sha256=UXFfEjwrBksiLGUSCSKAanOJMVpvCCPDIDMARo13vGg,474
21
+ renef_mcp/scripts/multi_hook_test.lua,sha256=GOAo1_3fZg7G42JqqxXScPIJZFWNC2Bf6bW4cJTum78,1165
22
+ renef_mcp/scripts/root_bypass.lua,sha256=KOplh-1F57fcm_YnKjI5gQzYzbyJud73aIgca-JIeMo,22257
23
+ renef_mcp/scripts/simple_fopen_test.lua,sha256=pyeP0mHggK_stOWDC7rZOIjdYzT0QMqpot8fzitsS3I,947
24
+ renef_mcp/scripts/ssl_unpin.lua,sha256=lWQZIfA0R5dzvdgVfIEXd_os9A8dSrRV4nA-FrIJvzs,37124
25
+ renef_mcp/scripts/strace_custom.lua,sha256=8JtNx0SBHrVlYkNHfzDbBLfhJDrRB65hreOG3fQ0EtE,625
26
+ renef_mcp/scripts/strace_file.lua,sha256=87_TA5LdGY9qXrX1bfoJyafo0tSnRQFEOKYG8ZZVNVg,337
27
+ renef_mcp/scripts/strace_network.lua,sha256=x-LOwpZPxCgI9c_ZwOtMmfdicJHhsGq4K7kngk0Y82s,672
28
+ renef_mcp/scripts/syscall_test.lua,sha256=KuwvH3VbTmeAABV_gUQiZYwSKkk9OKA4QrNy7z128Rc,4805
29
+ renef_mcp/scripts/thread_test.lua,sha256=ueNNMgxQ3zRnxvwveOagodorSjMwwotwaYnI0U2Ij2c,779
30
+ renef_mcp/techniques/LICENSE,sha256=SlT7B6ld5tmCUu539tHQBHYY5KzKsbES1tp-tapHhNI,1064
31
+ renef_mcp/techniques/ssl_pinning/README.md,sha256=gWE8wKMwnNY2nPXzt-F_MT6nyBU8IRUNeSQwJxjFZJY,5159
32
+ renef_mcp/techniques/ssl_pinning/advanced_bypass_techniques.md,sha256=1YWaZj2VHHjA7_532ZPTCvBMVHQuOPBHH2M3dkSmmys,10556
33
+ renef_mcp/techniques/ssl_pinning/android_native.md,sha256=e7Sd2nVgMMBN_xOpO3O9xf52RQzIG2BQNvQrDxNhQIE,20609
34
+ renef_mcp/techniques/ssl_pinning/certificate_pinning_fundamentals.md,sha256=o4KVThRchH_aSiorrDg7zAyGjdQpMTGa5KrYonXiJtE,1208
35
+ renef_mcp/techniques/ssl_pinning/cordova_ionic.md,sha256=xKdgL_m9vmwurHTMNBUCsQoPZ5lPQ01yWaU_hAS2dZc,6549
36
+ renef_mcp/techniques/ssl_pinning/detection_anti_tampering.md,sha256=_9QwBLuUgXVoG20dhBV5MR7XCd-dkTyfRga2h1-7Geg,4535
37
+ renef_mcp/techniques/ssl_pinning/flutter.md,sha256=9Ctbh74wpcIEdu3wT9SkUrLI0rJV0a8aZFxt0QnrZh4,17027
38
+ renef_mcp/techniques/ssl_pinning/how_ssl_tls_works.md,sha256=ONzkM4LUm6f6nbkEbK1l-7etiqgoNn-yWIlWDDHSSbE,3495
39
+ renef_mcp/techniques/ssl_pinning/introduction_to_ssl_pinning.md,sha256=lJW_G4W8Reoz-4S9ErqxsgubtNE7SF8oaRmXOHl8AOw,1446
40
+ renef_mcp/techniques/ssl_pinning/network_security_configuration.md,sha256=k7pG3sHBGxLlNL57yypyFssnakQrLRs5dvC7vcqMoD4,5950
41
+ renef_mcp/techniques/ssl_pinning/platform_mapping.json,sha256=PCg9QI1nWqdbFMKOgf6BvOGdb53HaD86M6_q865HrUw,4531
42
+ renef_mcp/techniques/ssl_pinning/react_native.md,sha256=ITCfUCuoBhU_K4W-OBimzu2ehyGLFaOrGQ3xTte8bZQ,10797
43
+ renef_mcp/techniques/ssl_pinning/summary.md,sha256=OlV0LMffHD7ZIPVZxkFeQB4tDmzaLhXMKj9vZ-u-dAc,1558
44
+ renef_mcp/techniques/ssl_pinning/third_party_libraries.md,sha256=fXpkPNTJqMPDa6XVS9dmaPEHz-1bL9ULRqfWquZFlwc,5768
45
+ renef_mcp/techniques/ssl_pinning/unity.md,sha256=r2YWuga5x0z8Bof0n7mMY3Vnh2aVYFDDc3MSuhIr5Lg,8761
46
+ renef_mcp/techniques/ssl_pinning/xamarin.md,sha256=PwY9kFgAYCkRypsgVQ_PxvbTtZqckMqkJX4oTcjXHwE,7950
47
+ android_renef_mcp-0.1.0.dist-info/METADATA,sha256=KQiOK4RhQVyhfr4jp6SRCXpYUMVTKa3vbuzC3CTxFAM,9290
48
+ android_renef_mcp-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
49
+ android_renef_mcp-0.1.0.dist-info/entry_points.txt,sha256=0Jov-vBU3WCo4sivJRnK98uM0yPwVUnnrWTAJcH_tIY,60
50
+ android_renef_mcp-0.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
51
+ android_renef_mcp-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ android-renef-mcp = renef_mcp.server:main
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
renef_mcp/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """android-renef-mcp: MCP server exposing Renef (Android dynamic instrumentation) to AI agents."""
2
+
3
+ __version__ = "0.1.0"
renef_mcp/__main__.py ADDED
@@ -0,0 +1,6 @@
1
+ import sys
2
+
3
+ from renef_mcp.server import main
4
+
5
+ if __name__ == "__main__":
6
+ sys.exit(main())
renef_mcp/adb.py ADDED
@@ -0,0 +1,143 @@
1
+ """adb + raw-TCP helpers for talking to renef_server."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ import socket
7
+ import subprocess
8
+ from functools import lru_cache
9
+
10
+ from renef_mcp import config
11
+
12
+
13
+ class AdbError(RuntimeError):
14
+ pass
15
+
16
+
17
+ def run_adb(*args: str, timeout: float = 20.0) -> str:
18
+ """Run an adb command, raise AdbError on failure. Returns stdout."""
19
+ try:
20
+ proc = subprocess.run(
21
+ [config.adb_binary(), *args],
22
+ capture_output=True,
23
+ text=True,
24
+ timeout=timeout,
25
+ )
26
+ except FileNotFoundError as e:
27
+ raise AdbError(f"adb binary not found: {config.adb_binary()!r}") from e
28
+ except subprocess.TimeoutExpired as e:
29
+ raise AdbError(f"adb {' '.join(args)} timed out") from e
30
+ if proc.returncode != 0:
31
+ raise AdbError(f"adb {' '.join(args)} failed: {proc.stderr.strip() or proc.stdout.strip()}")
32
+ return proc.stdout
33
+
34
+
35
+ @lru_cache(maxsize=8)
36
+ def device_serials() -> tuple[str, ...]:
37
+ """Serials of devices in 'device' state (cached per process, short-lived)."""
38
+ out = run_adb("devices")
39
+ serials = []
40
+ for line in out.splitlines()[1:]:
41
+ line = line.strip()
42
+ if not line:
43
+ continue
44
+ parts = line.split()
45
+ if len(parts) >= 2 and parts[1] == "device":
46
+ serials.append(parts[0])
47
+ return tuple(serials)
48
+
49
+
50
+ def first_device() -> str | None:
51
+ serials = device_serials()
52
+ return serials[0] if serials else None
53
+
54
+
55
+ def ensure_forward() -> str:
56
+ """Make sure tcp:<RENEF_PORT> is forwarded to the device server socket.
57
+
58
+ Returns a short human description of what was done. Skips entirely when
59
+ RENEF_HOST points at a remote (non-loopback) server.
60
+ """
61
+ if not config.uses_local_forward():
62
+ return f"direct TCP mode (RENEF_HOST={config.host()}), no adb forward needed"
63
+
64
+ port = config.port()
65
+ local = f"tcp:{port}"
66
+ out = run_adb("forward", "--list")
67
+ for line in out.splitlines():
68
+ parts = line.split()
69
+ if len(parts) >= 3 and parts[1] == local:
70
+ return f"adb forward already set: {parts[0]} {local} -> {parts[2]}"
71
+
72
+ serial = first_device()
73
+ if serial is None:
74
+ raise AdbError(
75
+ "No adb device in 'device' state found. Connect a device and enable USB debugging."
76
+ )
77
+ run_adb("-s", serial, "forward", local, config.FORWARD_REMOTE)
78
+ return f"adb forward set: {serial} {local} -> {config.FORWARD_REMOTE}"
79
+
80
+
81
+ def ping_server(timeout: float = 3.0) -> bool:
82
+ """Raw protocol ping: connect to renef_server, send 'ping', expect 'pong'."""
83
+ try:
84
+ with socket.create_connection((config.host(), config.port()), timeout=timeout) as s:
85
+ s.settimeout(timeout)
86
+ s.sendall(b"ping\n")
87
+ data = s.recv(64)
88
+ return b"pong" in data
89
+ except OSError:
90
+ return False
91
+
92
+
93
+ def raw_command(command: str, timeout: float = 5.0) -> str:
94
+ """Send a raw server-level command (e.g. 'resume') and collect the response."""
95
+ with socket.create_connection((config.host(), config.port()), timeout=timeout) as s:
96
+ s.settimeout(timeout)
97
+ s.sendall(command.rstrip("\n").encode() + b"\n")
98
+ chunks = []
99
+ try:
100
+ while True:
101
+ data = s.recv(4096)
102
+ if not data:
103
+ break
104
+ chunks.append(data.decode(errors="replace"))
105
+ if b"\n" in data:
106
+ break
107
+ except socket.timeout:
108
+ pass
109
+ return "".join(chunks).strip()
110
+
111
+
112
+ def list_packages(third_party_only: bool = False) -> list[str]:
113
+ """Installed packages via adb (no server required)."""
114
+ args = ["shell", "pm", "list", "packages"]
115
+ if third_party_only:
116
+ args.append("-3")
117
+ out = run_adb(*args, timeout=30.0)
118
+ pkgs = []
119
+ for line in out.splitlines():
120
+ line = line.strip()
121
+ if line.startswith("package:"):
122
+ pkgs.append(line[len("package:") :])
123
+ return sorted(pkgs)
124
+
125
+
126
+ def list_processes(limit: int = 300) -> list[dict]:
127
+ """Running userland processes via adb: [{'pid': int, 'name': str}, ...]."""
128
+ out = run_adb("shell", "ps", "-A", "-o", "PID,NAME", timeout=30.0)
129
+ procs = []
130
+ for line in out.splitlines()[1:]:
131
+ line = line.strip()
132
+ if not line:
133
+ continue
134
+ m = re.match(r"^\s*(\d+)\s+(\S+)$", line)
135
+ if not m:
136
+ continue
137
+ pid_s, name = m.group(1), m.group(2)
138
+ if name.startswith("["): # kernel thread
139
+ continue
140
+ procs.append({"pid": int(pid_s), "name": name})
141
+ if len(procs) >= limit:
142
+ break
143
+ return procs