Skip to content

Commit 6d54aaa

Browse files
committed
RELEASE: new mcp tool to fetch all class names under main application package, v2.0.0
1 parent 5d37e44 commit 6d54aaa

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

src/main/java/jadx/gui/plugins/JadxAIMCP.java

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public void start(MainWindow mainWindow) {
8989
app.get("/manifest", this::handleManifest);
9090
app.get("/main-application", this::handleMainApplication);
9191
app.get("/main-activity", this::handleMainActivity);
92+
app.get("/main-application-class-names", this::handleMainApplicationClassNames);
9293

9394
logger.info("JADX MCP plugin HTTP server started at http://127.0.0.1:8650/");
9495
} catch (Exception e) {
@@ -352,6 +353,53 @@ private void handleManifest(Context ctx) {
352353
}
353354
}
354355

356+
private void handleMainApplicationClassNames(Context ctx) {
357+
try {
358+
JadxWrapper wrapper = mainWindow.getWrapper();
359+
List<ResourceFile> resources = wrapper.getResources();
360+
361+
// Get the manifest ResourceFile
362+
ResourceFile manifestRes = AndroidManifestParser.getAndroidManifest(resources);
363+
if (manifestRes == null) {
364+
ctx.status(404).json(Map.of("error", "AndroidManifest.xml not found."));
365+
return;
366+
}
367+
368+
// Load manifest content and parse XML
369+
String manifestXml = manifestRes.loadContent().getText().getCodeStr();
370+
Document manifestDoc = parseManifestXml(manifestXml, wrapper.getArgs().getSecurity());
371+
372+
// Extract the package name from the <manifest> tag
373+
Element manifestElement = (Element) manifestDoc.getElementsByTagName("manifest").item(0);
374+
String packageName = manifestElement.getAttribute("package");
375+
376+
if (packageName.isEmpty()) {
377+
ctx.status(404).json(Map.of("error", "Package name not found in manifest."));
378+
return;
379+
}
380+
381+
// Filter classes under this package
382+
List<JavaClass> matchedClasses = wrapper.getDecompiler().getClasses().stream()
383+
.filter(cls -> cls.getFullName().startsWith(packageName))
384+
.collect(Collectors.toList());
385+
386+
List<Map<String, Object>> classesInfo = new ArrayList<>();
387+
for (JavaClass cls : matchedClasses) {
388+
Map<String, Object> classInfo = new HashMap<>();
389+
classInfo.put("name", cls.getFullName());
390+
classesInfo.add(classInfo);
391+
}
392+
393+
Map<String, Object> result = new HashMap<>();
394+
result.put("allClassesInPackageName", classesInfo);
395+
396+
ctx.json(result);
397+
} catch (Exception e) {
398+
logger.error("Error handling main application", e);
399+
ctx.status(500).json(Map.of("error", "Internal error retrieving AndroidManifest.xml: " + e.getMessage()));
400+
}
401+
}
402+
355403
private void handleMainApplication(Context ctx) {
356404
try {
357405
JadxWrapper wrapper = mainWindow.getWrapper();
@@ -402,8 +450,6 @@ private void handleMainApplication(Context ctx) {
402450
}
403451

404452

405-
406-
407453
private void handleMainActivity(Context ctx) {
408454
try {
409455
JadxWrapper wrapper = mainWindow.getWrapper();

0 commit comments

Comments
 (0)