### Complete JADX Configuration Example Source: https://github.com/skylot/jadx/blob/master/_autodocs/02-jadx-args.md Demonstrates setting various JADX arguments for input/output, processing, decompilation, formatting, deobfuscation, and filtering. This example shows how to initialize `JadxArgs` and use `JadxDecompiler`. ```java import jadx.api.*; import java.io.File; import java.nio.file.Paths; public class JadxArgsExample { public static void main(String[] args) { JadxArgs jadxArgs = new JadxArgs(); // Input/Output jadxArgs.getInputFiles().add(new File("app.apk")); jadxArgs.setOutDir(new File("decompiled")); // Processing jadxArgs.setThreadsCount(8); jadxArgs.setSkipResources(false); jadxArgs.setSkipSources(false); // Decompilation jadxArgs.setDecompilationMode(DecompilationMode.AUTO); jadxArgs.setUseImports(true); jadxArgs.setExtractFinally(true); jadxArgs.setInlineAnonymousClasses(true); // Formatting jadxArgs.setCodeIndentStr(" "); // 2 spaces jadxArgs.setCodeNewLineStr("\n"); jadxArgs.setCommentsLevel(CommentsLevel.INFO); jadxArgs.setIntegerFormat(IntegerFormat.HEXADECIMAL); // Deobfuscation jadxArgs.setDeobfuscationOn(true); jadxArgs.setDeobfuscationMinLength(0); jadxArgs.setDeobfuscationMaxLength(Integer.MAX_VALUE); // Filtering jadxArgs.setClassFilter(name -> { // Only decompile app code, not framework return !name.startsWith("android.") && !name.startsWith("java.") && !name.startsWith("kotlin."); }); try (JadxDecompiler jadx = new JadxDecompiler(jadxArgs)) { jadx.load(); jadx.save(); } } } ``` -------------------------------- ### Complete Metadata Navigation Example Source: https://github.com/skylot/jadx/blob/master/_autodocs/05-code-info-and-metadata.md This example shows how to load an APK, iterate through its classes, and extract detailed metadata including code information, line mappings, and annotations. It also demonstrates how to find method references within the code. ```java import jadx.api.*; import jadx.api.metadata.*; import java.io.File; import java.util.Map; public class MetadataExample { public static void main(String[] args) { JadxArgs jadxArgs = new JadxArgs(); jadxArgs.getInputFiles().add(new File("app.apk")); jadxArgs.setOutDir(new File("output")); try (JadxDecompiler jadx = new JadxDecompiler(jadxArgs)) { jadx.load(); for (JavaClass cls : jadx.getClasses()) { ICodeInfo codeInfo = cls.getCodeInfo(); if (!codeInfo.hasMetadata()) { System.out.println("No metadata for " + cls.getFullName()); continue; } System.out.println("\n=== " + cls.getFullName() + " ==="); String code = codeInfo.getCodeStr(); System.out.println("Code length: " + code.length()); // Print line mapping Map lineMap = codeInfo.getCodeMetadata().getLineMapping(); System.out.println("Line mappings: " + lineMap.size()); for (Map.Entry entry : lineMap.entrySet()) { System.out.println(" Decompiled " + entry.getKey() + " ← Source " + entry.getValue()); } // Print all annotations Map annotations = codeInfo.getCodeMetadata().getAsMap(); System.out.println("Annotations: " + annotations.size()); for (Map.Entry entry : annotations.entrySet()) { int pos = entry.getKey(); ICodeAnnotation ann = entry.getValue(); String snippet = code.substring(pos, Math.min(pos + 30, code.length())); System.out.println(" @" + pos + " [" + ann.getAnnType() + "]: " + snippet.replace("\n", "\\n")); // Try to get JavaNode JavaNode node = jadx.getJavaNodeByCodeAnnotation(codeInfo, ann); if (node != null) { System.out.println(" → " + node.getFullName()); } } // Example: find all method references System.out.println("\nMethod references:"); annotations.forEach((pos, ann) -> { if (ann.getAnnType() == ICodeAnnotation.AnnType.METHOD) { String snippet = code.substring(pos, Math.min(pos + 20, code.length())); JavaNode node = jadx.getJavaNodeByRef((ICodeNodeRef) ann); System.out.println(" @" + pos + ": " + node.getFullName()); } }); } } } } ``` -------------------------------- ### Example: Get JavaNode at Position Source: https://github.com/skylot/jadx/blob/master/_autodocs/01-jadx-decompiler.md Demonstrates how to obtain code information for a class and then find a Java node at a specific character offset within that code. ```java JavaClass cls = jadx.getClasses().get(0); ICodeInfo code = cls.getCodeInfo(); JavaNode node = jadx.getJavaNodeAtPosition(code, 42); ``` -------------------------------- ### Complete Robust Decompilation Example Source: https://github.com/skylot/jadx/blob/master/_autodocs/07-error-handling.md A comprehensive example demonstrating how to decompile an APK file robustly, handling various JADX-specific exceptions and validating inputs/outputs. ```java import jadx.api.*; import jadx.core.utils.exceptions.*; import java.io.File; public class RobustDecompilation { public static void main(String[] args) { try { decompileApp("app.apk", "output"); } catch (JadxArgsValidateException e) { System.err.println("Configuration error: " + e.getMessage()); System.exit(1); } catch (DecodeException e) { System.err.println("Failed to decode input file: " + e.getMessage()); System.exit(2); } catch (JadxOverflowException e) { System.err.println("Resource exhausted: " + e.getMessage()); System.exit(3); } catch (JadxException e) { System.err.println("Decompilation error: " + e.getMessage()); e.printStackTrace(); System.exit(4); } catch (JadxRuntimeException e) { System.err.println("Internal error: " + e.getMessage()); e.printStackTrace(); System.exit(5); } } private static void decompileApp(String inputPath, String outputPath) throws JadxException { JadxArgs args = new JadxArgs(); // Validate input File inputFile = new File(inputPath); if (!inputFile.exists()) { throw new JadxArgsValidateException("Input file not found: " + inputPath); } args.getInputFiles().add(inputFile); // Validate output File outDir = new File(outputPath); args.setOutDir(outDir); // Configure safely args.setThreadsCount(Math.min(4, Runtime.getRuntime().availableProcessors())); args.setDecompilationMode(DecompilationMode.AUTO); try (JadxDecompiler jadx = new JadxDecompiler(args)) { System.out.println("Loading " + inputPath + "..."); jadx.load(); // Check for parse errors if (jadx.getErrorsCount() > 0) { System.out.println("Warning: " + jadx.getErrorsCount() + " errors during parsing"); } System.out.println("Found " + jadx.getClasses().size() + " classes"); // Try to access a few classes to detect decompilation issues int tested = 0; for (JavaClass cls : jadx.getClasses()) { try { if (!cls.loadingWouldRequireDecompilation()) { continue; // Already decompiled } cls.decompile(); tested++; if (tested > 10) break; } catch (Exception e) { System.out.println("Note: Class " + cls.getFullName() + " has decompilation issues"); } } System.out.println("Saving to " + outputPath + "..."); jadx.save(); System.out.println("Decompilation complete."); if (jadx.getErrorsCount() > 0) { System.out.println("\n--- Error Report ---"); jadx.printErrorsReport(); } } } } ``` -------------------------------- ### Example: Filter Android Classes Source: https://github.com/skylot/jadx/blob/master/_autodocs/02-jadx-args.md This example demonstrates how to set a class filter to exclude classes that start with 'android.'. ```java args.setClassFilter(name -> !name.startsWith("android.")); ``` -------------------------------- ### Complete JADX Decompiler Usage Example Source: https://github.com/skylot/jadx/blob/master/_autodocs/01-jadx-decompiler.md This example demonstrates how to initialize JADX, load an APK, access decompiled class information, and save the output. Ensure you have the JADX library included in your project. ```java import jadx.api.*; import java.io.File; public class JadxExample { public static void main(String[] args) throws Exception { JadxArgs jadxArgs = new JadxArgs(); jadxArgs.getInputFiles().add(new File("app.apk")); jadxArgs.setOutDir(new File("decompiled")); jadxArgs.setThreadsCount(4); jadxArgs.setDeobfuscationOn(true); try (JadxDecompiler jadx = new JadxDecompiler(jadxArgs)) { jadx.load(); // Access decompiled classes for (JavaClass cls : jadx.getClasses()) { System.out.println("Class: " + cls.getFullName()); System.out.println("Fields: " + cls.getFields().size()); System.out.println("Methods: " + cls.getMethods().size()); } // Save to disk jadx.save(); // Print errors System.out.println("Errors: " + jadx.getErrorsCount()); System.out.println("Warnings: " + jadx.getWarnsCount()); } } } ``` -------------------------------- ### Minimal JADX Decompilation Example Source: https://github.com/skylot/jadx/blob/master/_autodocs/09-quick-start.md Use this example for a straightforward decompilation of an APK file. It sets the input APK and output directory, then loads and saves the decompiled code. ```java import jadx.api.*; import java.io.File; public class JadxQuickStart { public static void main(String[] args) { JadxArgs jadxArgs = new JadxArgs(); jadxArgs.getInputFiles().add(new File("app.apk")); jadxArgs.setOutDir(new File("output")); try (JadxDecompiler jadx = new JadxDecompiler(jadxArgs)) { jadx.load(); jadx.save(); System.out.println("Decompilation complete!"); } } } ``` -------------------------------- ### Example: Registering a Decompilation Pass Source: https://github.com/skylot/jadx/blob/master/_autodocs/06-plugins-and-extensions.md Shows an example of how to register a specific decompilation pass, such as MethodInliningPass, using the JadxPluginContext. ```java context.addPass(MethodInliningPass.class); ``` -------------------------------- ### Install Plugin via CLI Source: https://github.com/skylot/jadx/wiki/Jadx-plugins-guide Install a Jadx plugin JAR file using the Jadx command-line interface. ```bash jadx plugins --install-jar jadx-example-plugin.jar ``` -------------------------------- ### Complete Plugin Example with Analysis Pass Source: https://github.com/skylot/jadx/blob/master/_autodocs/06-plugins-and-extensions.md A comprehensive example of a JADX plugin that implements `JadxPlugin` and `JadxAfterLoadPass`. It includes plugin information, initialization, and a custom analysis pass to find native methods and potential secrets. ```java import jadx.api.*; import jadx.api.plugins.*; import jadx.api.plugins.pass.types.JadxAfterLoadPass; import jadx.api.plugins.pass.JadxPassInfo; public class AnalysisPlugin implements JadxPlugin, JadxAfterLoadPass { @Override public JadxPluginInfo getPluginInfo() { return JadxPluginInfoBuilder.defaults() .name("Code Analysis Plugin") .description("Analyzes decompiled code for patterns") .version("1.0.0") .author("Your Name") .build(); } @Override public void init(JadxPluginContext context) { context.addPass(this.getClass()); } @Override public JadxPassInfo getInfo() { return JadxPassInfo.builder("code-analysis") .name("Code Analysis") .description("Analyzes classes for security patterns") .build(); } @Override public void init(JadxDecompiler jadx) { System.out.println("Starting code analysis..."); for (JavaClass cls : jadx.getClasses()) { analyzeClass(cls); } System.out.println("Analysis complete."); } private void analyzeClass(JavaClass cls) { // Example analysis: find classes with native methods boolean hasNativeMethods = false; for (JavaMethod method : cls.getMethods()) { if (method.getAccessFlags().isNative()) { hasNativeMethods = true; System.out.println("Native method found: " + method.getFullName()); } } if (hasNativeMethods) { System.out.println("Class " + cls.getFullName() + " uses native code"); } // Example: find hardcoded strings String code = cls.getCode(); if (code.contains("api_key") || code.contains("password")) { System.out.println("Potential secrets in: " + cls.getFullName()); } } } ``` -------------------------------- ### Install JADX on Flathub Source: https://github.com/skylot/jadx/blob/master/README.md Install JADX from Flathub using flatpak. ```bash flatpak install flathub com.github.skylot.jadx ``` -------------------------------- ### Example Custom Resource Loader Implementation Source: https://github.com/skylot/jadx/blob/master/_autodocs/06-plugins-and-extensions.md An example implementation of `CustomResourcesLoader`. Add your custom resource loading logic within the `load` method and any necessary cleanup in the `close` method. ```java public class MyResourceLoader implements CustomResourcesLoader { @Override public List load(JadxDecompiler jadx) { List resources = new ArrayList<>(); // Load custom resources // resources.add(...); return resources; } @Override public void close() { // cleanup } } ``` -------------------------------- ### JADX Plugin Management: List and Availability Source: https://github.com/skylot/jadx/blob/master/README.md View installed and available plugins. Use '-l' to list installed plugins, '-a' to list available plugins from the marketplace, and '--list-all' for a comprehensive list. ```bash plugins -l ``` ```bash plugins -a ``` ```bash plugins --list-all ``` -------------------------------- ### Install Plugin from GitHub Release (CLI) Source: https://github.com/skylot/jadx/wiki/Jadx-plugins-guide Use this command to install a plugin directly from a GitHub release using the Jadx CLI. Ensure the plugin repository owner and name are correctly specified. ```bash jadx plugins --install "github::" ``` -------------------------------- ### Install JADX on Arch Linux Source: https://github.com/skylot/jadx/blob/master/README.md Use pacman to install JADX on Arch Linux systems. ```bash sudo pacman -S jadx ``` -------------------------------- ### Install JADX on macOS Source: https://github.com/skylot/jadx/blob/master/README.md Install JADX using Homebrew on macOS. ```bash brew install jadx ``` -------------------------------- ### JADX Plugin Management: Install Source: https://github.com/skylot/jadx/blob/master/README.md Manage JADX plugins using the 'plugins' command. Use '-i' to install a plugin by its location ID or '-j' to install from a local JAR file. ```bash plugins -i ``` ```bash plugins -j ``` -------------------------------- ### Example: Print JADX Version Source: https://github.com/skylot/jadx/blob/master/_autodocs/01-jadx-decompiler.md Demonstrates how to call the getVersion() method and print the JADX library version to the console. ```java System.out.println("JADX version: " + JadxDecompiler.getVersion()); ``` -------------------------------- ### Complete Resource Processing Example Source: https://github.com/skylot/jadx/blob/master/_autodocs/04-resources.md Demonstrates how to load an APK, iterate through its resources, and process them based on their type. Includes saving processed resources. ```java import jadx.api.*; import java.io.File; public class ResourceExample { public static void main(String[] args) { JadxArgs jadxArgs = new JadxArgs(); jadxArgs.getInputFiles().add(new File("app.apk")); jadxArgs.setOutDir(new File("output")); jadxArgs.setSkipSources(true); // Only resources try (JadxDecompiler jadx = new JadxDecompiler(jadxArgs)) { jadx.load(); // Process resources for (ResourceFile res : jadx.getResources()) { ResourceType type = res.getType(); String name = res.getDeobfName(); String original = res.getOriginalName(); System.out.println("Resource: " + name); System.out.println(" Type: " + type); System.out.println(" Original: " + original); // Load and process based on type switch (type) { case MANIFEST: case XML: ResContainer content = res.loadContent(); if (content.isTextContent()) { String xml = content.getText(); System.out.println(" XML content: " + xml.substring(0, 100) + "..."); } break; case ARSC: ResContainer arsc = res.loadContent(); System.out.println(" ARSC resource table decoded"); break; case IMG: System.out.println(" Image resource"); break; case LIB: System.out.println(" Native library"); break; default: System.out.println(" Other resource"); break; } } // Save all resources jadx.save(); } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### Example: Get JavaField Type Name Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Demonstrates how to get the class name of a field's type and print it. This example requires a JavaClass object and assumes it has at least one field. ```java JavaField field = javaClass.getFields().get(0); String typeName = field.getType().getClassName(); System.out.println(typeName); // e.g., "java.lang.String" ``` -------------------------------- ### Example: Load and Print Resource Content Source: https://github.com/skylot/jadx/blob/master/_autodocs/04-resources.md Demonstrates how to load resource content and print it to the console if it is text-based. Assumes the resource is already loaded into a ResourceFile object. ```java ResourceFile res = jadx.getResources().get(0); ResContainer content = res.loadContent(); if (content.isTextContent()) { String xml = content.getText(); System.out.println(xml); } ``` -------------------------------- ### Usage Example for a JADX Plugin Source: https://github.com/skylot/jadx/blob/master/_autodocs/06-plugins-and-extensions.md Demonstrates how to instantiate `JadxDecompiler` with custom arguments, register a plugin, load the decompilation process, and save the output. ```java import java.io.File; public class Main { public static void main(String[] args) { JadxArgs jadxArgs = new JadxArgs(); jadxArgs.getInputFiles().add(new File("app.apk")); jadxArgs.setOutDir(new File("output")); try (JadxDecompiler jadx = new JadxDecompiler(jadxArgs)) { // Register plugin jadx.registerPlugin(new AnalysisPlugin()); jadx.load(); jadx.save(); } } } ``` -------------------------------- ### Get File Extensions for Resource Type Source: https://github.com/skylot/jadx/blob/master/_autodocs/04-resources.md Returns an array of file extensions associated with a specific resource type. For example, XML resources have the extension ".xml". ```java public String[] getExts() ``` -------------------------------- ### Check Available Plugins via CLI Source: https://github.com/skylot/jadx/wiki/Jadx-plugins-guide View a list of available plugins that can be installed using the Jadx command-line interface. ```bash jadx plugins --available ``` -------------------------------- ### Get String Representation of ArgType Source: https://github.com/skylot/jadx/blob/master/_autodocs/08-types.md Returns a string representation of the ArgType suitable for direct use in decompiled code. Examples include 'int', 'java.lang.String[]', and 'List'. ```java @Override public String toString() ``` -------------------------------- ### Decompile DEX to Output Directory Source: https://github.com/skylot/jadx/wiki/Use-jadx-as-a-library Basic example to decompile a DEX file and save the output to a specified directory. Ensure the 'output' directory exists or is created. ```java import java.io.File; import jadx.api.JadxArgs; import jadx.api.JadxDecompiler; public class App { public static void main(String[] args) { JadxArgs jadxArgs = new JadxArgs(); jadxArgs.setInputFile(new File("classes.dex")); jadxArgs.setOutDir(new File("output")); try (JadxDecompiler jadx = new JadxDecompiler(jadxArgs)) { jadx.load(); jadx.save(); } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### Example Jadx GUI Exe and Config File Naming Source: https://github.com/skylot/jadx/wiki/Troubleshooting-Q&A Illustrates how the Jadx GUI executable filename relates to its corresponding configuration file name for the .l4j.ini settings. ```text Jadx file-name: jadx-gui-1.1.0-b1279-2207cd7b.exe Jadx config file name: jadx-gui-1.1.0-b1279-2207cd7b.l4j.ini. ``` -------------------------------- ### Get Plugin Description - JadxPluginInfo Source: https://github.com/skylot/jadx/blob/master/_autodocs/06-plugins-and-extensions.md Retrieves the description of the plugin. ```java public String getDescription() ``` -------------------------------- ### Catching JadxException Source: https://github.com/skylot/jadx/blob/master/_autodocs/07-error-handling.md Example of how to use a try-catch block to handle potential JadxException errors during decompilation. ```APIDOC ```java try { jadx.load(); } catch (JadxException e) { System.err.println("Decompilation error: " + e.getMessage()); e.printStackTrace(); } ``` ``` -------------------------------- ### Create a Custom Jadx Plugin Source: https://github.com/skylot/jadx/blob/master/_autodocs/INDEX.md Example of creating a custom plugin for Jadx by implementing the JadxPlugin interface. Used for extending Jadx functionality. ```java public class MyPlugin implements JadxPlugin { public void init(JadxPluginContext ctx) { // Register passes, loaders, etc. } } jadx.registerPlugin(new MyPlugin()); ``` -------------------------------- ### Implement Custom Code Input Loader Source: https://github.com/skylot/jadx/blob/master/_autodocs/06-plugins-and-extensions.md Example implementation of a custom code input loader. This loader parses files with a '.custom' extension and returns them as ClassData. ```java public class CustomCodeInput implements JadxCodeInput { @Override public ICodeLoader loadFiles(List inputPaths) throws Exception { List classes = new ArrayList<>(); for (Path path : inputPaths) { if (path.toString().endsWith(".custom")) { // Parse custom file format ClassData classData = parseCustomFile(path); classes.add(classData); } } return new ICodeLoader() { @Override public List getClassData() { return classes; } @Override public boolean isEmpty() { return classes.isEmpty(); } @Override public void close() { // cleanup } }; } } ``` -------------------------------- ### Get Code Cache Source: https://github.com/skylot/jadx/blob/master/_autodocs/02-jadx-args.md Retrieves the currently configured code cache implementation. ```java public ICodeCache getCodeCache() ``` -------------------------------- ### Implement a Custom JadxAfterLoadPass Source: https://github.com/skylot/jadx/blob/master/_autodocs/06-plugins-and-extensions.md Example implementation of a custom decompilation pass that runs after all classes are loaded. It iterates through classes and prints their full names. ```java public class MyCustomPass implements JadxAfterLoadPass { @Override public JadxPassInfo getInfo() { return JadxPassInfo.builder("my-custom-pass") .name("My Custom Pass") .description("Performs custom transformations") .runOrder(100) .build(); } @Override public void init(JadxDecompiler jadx) { for (JavaClass cls : jadx.getClasses()) { // Transform the class System.out.println("Processing: " + cls.getFullName()); } } } ``` -------------------------------- ### ICodeAnnotation Example Usage Source: https://github.com/skylot/jadx/blob/master/_autodocs/05-code-info-and-metadata.md Demonstrates how to retrieve and process ICodeAnnotation objects based on their type. This pattern is common when analyzing code metadata. ```java ICodeAnnotation ann = codeInfo.getCodeMetadata().getAt(pos); switch (ann.getAnnType()) { case CLASS: // This is a class reference break; case METHOD: // This is a method reference break; case FIELD: // This is a field reference break; // ... } ``` -------------------------------- ### Get Decompiled Code for a Specific Class Source: https://github.com/skylot/jadx/blob/master/_autodocs/09-quick-start.md Retrieve the decompiled source code for a specific Java class. This example assumes at least one class has been loaded. ```java JavaClass cls = jadx.getClasses().get(0); String code = cls.getCode(); System.out.println(code); ``` -------------------------------- ### Basic Jadx Script Example Source: https://github.com/skylot/jadx/wiki/Jadx-scripts-guide A simple Jadx script demonstrating logging, instance retrieval, option adjustment, class renaming, and GUI integration. Scripts should be named with the `.jadx.kts` extension. ```kotlin log.info { "Hello from jadx script!" } // get jadx decompiler script instance val jadx = getJadxInstance() // adjust options if needed jadx.args.isDeobfuscationOn = false // rename example jadx.rename.all { name -> when (name) { "HelloWorld" -> "HelloJadx" else -> null } } // run some code after loading is finished jadx.afterLoad { log.info { "Loaded classes: ${jadx.classes.size}" } // print class code jadx.classes.firstOrNull()?.let { cls -> log.info { "Class: '${cls.name}'" } log.info { cls.code } } } jadx.gui.ifAvailable { // if a script is running in jadx-gui, // we can add menu entry to run custom code addMenuAction("Decompile All") { jadx.decompile.allThreaded() } } ``` -------------------------------- ### Process Resources in Decompiled Code Source: https://github.com/skylot/jadx/blob/master/_autodocs/09-quick-start.md Iterate through all resources within the decompiled code. This example specifically targets and prints the content of the AndroidManifest.xml. ```java for (ResourceFile res : jadx.getResources()) { if (res.getType() == ResourceType.MANIFEST) { ResContainer content = res.loadContent(); String xml = content.getText(); System.out.println(xml); } } ``` -------------------------------- ### Checking Access Modifiers in JADX Source: https://github.com/skylot/jadx/blob/master/_autodocs/08-types.md Example of how to get AccessInfo for classes, methods, and fields and check their modifiers. This is useful for analyzing code structure and identifying specific types of members. ```java JavaClass cls = jadx.getClasses().get(0); AccessInfo classAccess = cls.getAccessInfo(); if (classAccess.isPublic() && classAccess.isAbstract()) { System.out.println("Public abstract class"); } for (JavaMethod method : cls.getMethods()) { AccessInfo methodAccess = method.getAccessFlags(); if (methodAccess.isStatic()) { System.out.println("Static method: " + method.getName()); } if (methodAccess.isPrivate()) { System.out.println("Private method: " + method.getName()); } } for (JavaField field : cls.getFields()) { AccessInfo fieldAccess = field.getAccessFlags(); if (fieldAccess.isStaticFinal()) { System.out.println("Constant: " + field.getName()); } } ``` -------------------------------- ### Get Method Arguments - JavaMethod API Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Retrieves a list of argument types for the method. The list is unmodifiable and empty if the method has no parameters. Example shows how to iterate and print class names of arguments. ```java public List getArguments() ``` ```java for (ArgType argType : method.getArguments()) { System.out.println(argType.getClassName()); // e.g., "android.os.Bundle" } ``` -------------------------------- ### Get Generic Type Parameters Source: https://github.com/skylot/jadx/blob/master/_autodocs/08-types.md Retrieves a list of ArgType objects representing the type parameters of a generic type. For example, for `List`, this would return a list containing the ArgType for `String`. ```java public List getGenericTypes() ``` -------------------------------- ### Complete Navigation Example in Java Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Use this snippet to load an APK, iterate through classes, fields, and methods, and access decompiled code. It also demonstrates package navigation. Ensure Jadx API and Java IO are imported. ```java import jadx.api.*; import java.io.File; public class NavigationExample { public static void main(String[] args) { JadxArgs jadxArgs = new JadxArgs(); jadxArgs.getInputFiles().add(new File("app.apk")); jadxArgs.setOutDir(new File("output")); try (JadxDecompiler jadx = new JadxDecompiler(jadxArgs)) { jadx.load(); // Iterate classes for (JavaClass cls : jadx.getClasses()) { System.out.println("Class: " + cls.getFullName()); // Access fields for (JavaField field : cls.getFields()) { System.out.println(" Field: " + field.getName() + " : " + field.getType()); } // Access methods for (JavaMethod method : cls.getMethods()) { System.out.println(" Method: " + method.getName()); System.out.println(" Args: " + method.getArguments().size()); System.out.println(" Return: " + method.getReturnType()); } // Get code ICodeInfo codeInfo = cls.getCodeInfo(); String code = codeInfo.getCodeStr(); // Navigate code positions // ... } // Navigate packages for (JavaPackage pkg : jadx.getPackages()) { System.out.println("Package: " + pkg.getFullName()); for (JavaClass cls : pkg.getClassesNoDup()) { System.out.println(" " + cls.getName()); } } } } } ``` -------------------------------- ### Complete Type System Analysis Example Source: https://github.com/skylot/jadx/blob/master/_autodocs/08-types.md Demonstrates how to use the Jadx API to load an APK, iterate through its classes, and analyze fields and methods, including their types, access flags, and generic information. ```java import jadx.api.*; import java.io.File; import java.util.List; public class TypeSystemExample { public static void main(String[] args) { JadxArgs jadxArgs = new JadxArgs(); jadxArgs.getInputFiles().add(new File("app.apk")); try (JadxDecompiler jadx = new JadxDecompiler(jadxArgs)) { jadx.load(); for (JavaClass cls : jadx.getClasses()) { System.out.println("\n=== " + cls.getFullName() + " ==="); analyzeClass(cls); } } } private static void analyzeClass(JavaClass cls) { // Analyze fields System.out.println("\nFields:"); for (JavaField field : cls.getFields()) { ArgType type = field.getType(); AccessInfo access = field.getAccessFlags(); System.out.println(" " + access + " " + type + " " + field.getName()); if (type.isArray()) { ArgType elem = type.getArrayElement(); int dim = type.getArrayDimension(); System.out.println(" (Array: " + dim + "D of " + elem + ")"); } if (type.isGeneric()) { System.out.println(" (Generic with " + type.getGenericTypes().size() + " type parameters)"); } } // Analyze methods System.out.println("\nMethods:"); for (JavaMethod method : cls.getMethods()) { AccessInfo access = method.getAccessFlags(); ArgType returnType = method.getReturnType(); List paramTypes = method.getArguments(); StringBuilder sig = new StringBuilder(); sig.append(access).append(" "); if (access.isStatic()) sig.append("static "); sig.append(returnType).append(" ").append(method.getName()).append("("); for (int i = 0; i < paramTypes.size(); i++) { if (i > 0) sig.append(", "); sig.append(paramTypes.get(i)); } sig.append(")"); System.out.println(" " + sig); if (method.isConstructor()) { System.out.println(" (Constructor)"); } if (method.isClassInit()) { System.out.println(" (Class initializer)"); } } } } ``` -------------------------------- ### JADX Plugin Options Source: https://github.com/skylot/jadx/blob/master/README.md Configure JADX plugins using the -P option followed by the plugin name and its setting. This example disables checksum verification for DEX input. ```bash jadx -Pdex-input.verify-checksum=no app.apk ``` -------------------------------- ### Get Method Name - JavaMethod API Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Retrieves the name of a method or constructor. Use this to get the identifier for methods, or special names like '' for constructors and '' for class initializers. ```java public String getName() ``` -------------------------------- ### Initialize Plugin and Register Components Source: https://github.com/skylot/jadx/blob/master/_autodocs/06-plugins-and-extensions.md Implement `init` to initialize the plugin by registering custom passes, code loaders, and options using the provided `JadxPluginContext`. ```java public void init(JadxPluginContext context) { // Register a custom pass context.addPass(MyCustomPass.class); // Register a code loader context.addCodeInput(MyCodeLoader::new); // Register options context.addOption(new OptionDescription("my-option", "Option description")); } ``` -------------------------------- ### Build JadxPluginInfo using Builder Source: https://github.com/skylot/jadx/blob/master/_autodocs/06-plugins-and-extensions.md Demonstrates how to use the JadxPluginInfoBuilder to create a plugin metadata object. ```java JadxPluginInfo info = JadxPluginInfoBuilder.defaults() .name("My Plugin") .description("Does something useful") .version("1.0.0") .author("My Name") .build(); ``` -------------------------------- ### Build JADX from Source Source: https://github.com/skylot/jadx/blob/master/README.md Clone the JADX repository and build the project using Gradle. Ensure JDK 17 or higher is installed. Scripts for running JADX will be placed in 'build/jadx/bin'. ```bash git clone https://github.com/skylot/jadx.git cd jadx ./gradlew dist ``` -------------------------------- ### Get Code with Fallback to Smali Source: https://github.com/skylot/jadx/blob/master/_autodocs/09-quick-start.md Attempt to get the decompiled Java code for a class. If decompilation fails with `CodegenException`, it falls back to retrieving the Smali bytecode. Returns an error message if both attempts fail. ```java public String getCode(JavaClass cls) { try { return cls.getCode(); } catch (CodegenException e) { try { // Fallback to Smali bytecode view return cls.getSmali(); } catch (Exception e2) { return "// Failed to decompile: " + e.getMessage(); } } } ``` -------------------------------- ### Apply Code Formatting with Spotless Source: https://github.com/skylot/jadx/wiki/Code-Formatting Use this command to automatically reformat all code according to the project's style configuration. This is typically run before committing changes. ```bash ./gradlew spotlessApply ``` -------------------------------- ### Build JADX from Source (Windows) Source: https://github.com/skylot/jadx/blob/master/README.md Clone the JADX repository and build the project using Gradle on Windows. Ensure JDK 17 or higher is installed. Scripts for running JADX will be placed in 'build/jadx/bin'. ```bash git clone https://github.com/skylot/jadx.git cd jadx gradlew.bat dist ``` -------------------------------- ### Get Plugin Author - JadxPluginInfo Source: https://github.com/skylot/jadx/blob/master/_autodocs/06-plugins-and-extensions.md Retrieves the author of the plugin. ```java public String getAuthor() ``` -------------------------------- ### Get Plugin Version - JadxPluginInfo Source: https://github.com/skylot/jadx/blob/master/_autodocs/06-plugins-and-extensions.md Retrieves the version of the plugin. ```java public String getVersion() ``` -------------------------------- ### Running Jadx Script from CLI Source: https://github.com/skylot/jadx/wiki/Jadx-scripts-guide Demonstrates how to execute a Jadx script using the jadx command-line interface by providing the script file as an additional input. ```bash jadx classes.dex hello.jadx.kts ``` -------------------------------- ### getClosestJavaNode Source: https://github.com/skylot/jadx/blob/master/_autodocs/01-jadx-decompiler.md Gets the closest enclosing Java node above a specified position. ```APIDOC ## getClosestJavaNode(ICodeInfo codeInfo, int pos) ### Description Get the closest enclosing Java node above a position. ### Method Signature ```java @Nullable public JavaNode getClosestJavaNode(ICodeInfo codeInfo, int pos) ``` ### Parameters #### Path Parameters - **codeInfo** (`ICodeInfo`) - Required - Code to search - **pos** (`int`) - Required - Character position ### Returns - `JavaNode` - enclosing node or null ``` -------------------------------- ### Get Class Dependencies Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Retrieves a list of all Java classes that this class depends on. ```java public List getDependencies() ``` -------------------------------- ### JavaClass - Get Package Name Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Retrieves the package name of the decompiled class. ```java public String getPackage() ``` -------------------------------- ### Get JavaVariable Containing Method Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Retrieves the JavaMethod object that contains this local variable. ```java public JavaMethod getMth() ``` -------------------------------- ### Get JavaVariable Register Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Retrieves the register number associated with this variable in Dalvik bytecode. ```java public int getReg() ``` -------------------------------- ### Get JavaField Type Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Retrieves the ArgType object representing the field's type. ```java public ArgType getType() ``` -------------------------------- ### Create Default JadxArgs Source: https://github.com/skylot/jadx/blob/master/_autodocs/02-jadx-args.md Instantiate JadxArgs with default settings. Add input files to the list for decompilation. ```java JadxArgs args = new JadxArgs(); args.getInputFiles().add(new File("app.apk")); ``` -------------------------------- ### JavaClass - Get Smali Bytecode Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Retrieves the disassembled Smali bytecode representation of the class. ```java public synchronized String getSmali() ``` -------------------------------- ### Output Directory Configuration Source: https://github.com/skylot/jadx/blob/master/_autodocs/02-jadx-args.md Configure the root output directory and specific subdirectories for source files and resources. ```APIDOC ## setOutDir(File outDir) ### Description Set the root output directory. ### Parameters #### Path Parameters - **outDir** (`File`) - Required - Output root directory ### Returns void ## getOutDir() ### Description Get the root output directory. ### Returns `File` ## setOutDirSrc(File outDir) ### Description Set output directory for source files specifically. ### Returns void ## getOutDirSrc() ### Description Get source output directory. Defaults to `/sources`. ### Returns `File` ## setOutDirRes(File outDir) ### Description Set output directory for resources. ### Returns void ## getOutDirRes() ### Description Get resource output directory. Defaults to `/resources`. ### Returns `File` ``` -------------------------------- ### JavaClass - Get Class Name Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Retrieves the short, unqualified name of the decompiled class. ```java public String getName() ``` -------------------------------- ### Handle Binary Image and Media Resources Source: https://github.com/skylot/jadx/blob/master/_autodocs/04-resources.md Load binary image or media files from a ResourceFile and access their raw byte data. This is used for resources that are not text-based and should be passed through unchanged. ```java ResourceFile image = // get a .png file ResContainer container = image.loadContent(); byte[] imageData = container.getData(); Files.write(Paths.get(outputPath), imageData); ``` -------------------------------- ### Basic APK Decompilation Source: https://github.com/skylot/jadx/blob/master/_autodocs/00-START-HERE.md This snippet demonstrates the fundamental steps to decompile an APK file using JADX. It shows how to configure input files and output directories, load the APK, and save the decompiled sources. ```java JadxArgs args = new JadxArgs(); args.getInputFiles().add(new File("app.apk")); args.setOutDir(new File("output")); try (JadxDecompiler jadx = new JadxDecompiler(args)) { jadx.load(); jadx.save(); } ``` -------------------------------- ### Get JavaVariable SSA Index Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Retrieves the Static Single Assignment (SSA) index for this variable. ```java public int getSsa() ``` -------------------------------- ### JadxPluginContext Source: https://github.com/skylot/jadx/blob/master/_autodocs/06-plugins-and-extensions.md Provides context for plugin initialization and registration. ```APIDOC ## JadxPluginContext Context for plugin initialization and registration. ### Methods #### addPass(Class passClass) ```java public void addPass(Class passClass) ``` Register a decompilation pass. Parameters: - **passClass** (`Class`) - Required - Pass class Returns: void Example: ```java context.addPass(MethodInliningPass.class); ``` #### addCodeInput(Supplier supplier) ```java public void addCodeInput(Supplier supplier) ``` Register a custom code loader. Returns: void #### addCustomResourceLoader(CustomResourcesLoader loader) ```java public void addCustomResourceLoader(CustomResourcesLoader loader) ``` Register a custom resource loader. Returns: void #### addOption(OptionDescription option) ```java public void addOption(OptionDescription option) ``` Register a plugin option. Returns: void #### getJadxDecompiler() ```java public JadxDecompiler getJadxDecompiler() ``` Access the parent decompiler. Returns: `JadxDecompiler` ``` -------------------------------- ### Create JadxDecompiler with Default Arguments Source: https://github.com/skylot/jadx/blob/master/_autodocs/01-jadx-decompiler.md Instantiate JadxDecompiler using default configuration. This is suitable for basic decompilation tasks. ```java JadxDecompiler jadx = new JadxDecompiler(); ``` -------------------------------- ### Get JavaField Raw Name Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Retrieves the original obfuscated name of a class field or constant. ```java public String getRawName() ``` -------------------------------- ### Get Outermost Parent Class Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Retrieves the outermost parent class, regardless of nesting or inlining. ```java public JavaClass getTopParentClass() ``` -------------------------------- ### JADX Decompilation with Error Handling Source: https://github.com/skylot/jadx/blob/master/_autodocs/09-quick-start.md This example shows how to decompile an APK while handling potential JADX exceptions. It includes loading, counting classes, saving, and reporting any errors encountered during the process. ```java import jadx.api.*; import jadx.core.utils.exceptions.*; import java.io.File; public class JadxWithErrors { public static void main(String[] args) { try { decompile("app.apk", "output"); } catch (JadxException e) { System.err.println("Error: " + e.getMessage()); e.printStackTrace(); System.exit(1); } } private static void decompile(String input, String output) throws JadxException { JadxArgs args = new JadxArgs(); args.getInputFiles().add(new File(input)); args.setOutDir(new File(output)); try (JadxDecompiler jadx = new JadxDecompiler(args)) { System.out.println("Loading..."); jadx.load(); System.out.println("Found " + jadx.getClasses().size() + " classes"); System.out.println("Saving..."); jadx.save(); if (jadx.getErrorsCount() > 0) { System.out.println("Completed with " + jadx.getErrorsCount() + " errors"); } else { System.out.println("Completed successfully"); } } } } ``` -------------------------------- ### ResourceFile Factory Methods Source: https://github.com/skylot/jadx/blob/master/_autodocs/04-resources.md Methods for creating ResourceFile instances from files or names. ```APIDOC ## createResourceFile(JadxDecompiler decompiler, File file, ResourceType type) ### Description Create a resource from a file on disk. ### Method static factory method ### Parameters #### Path Parameters - **decompiler** (JadxDecompiler) - Required - Parent decompiler - **file** (File) - Required - File to wrap - **type** (ResourceType) - Required - Resource type ### Returns `ResourceFile` ## createResourceFile(JadxDecompiler decompiler, String name, ResourceType type) ### Description Create a resource from a name string. ### Method static factory method ### Parameters #### Path Parameters - **decompiler** (JadxDecompiler) - Required - Parent decompiler - **name** (String) - Required - Resource path/name - **type** (ResourceType) - Required - Resource type ### Returns `ResourceFile` or null if name fails security validation ``` -------------------------------- ### Get Text Content from ResContainer Source: https://github.com/skylot/jadx/blob/master/_autodocs/04-resources.md Retrieves the text content from a ResContainer, applicable only to text resources. ```java public String getText() ``` -------------------------------- ### JavaClass - Get JavaPackage Node Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Retrieves the JavaPackage node corresponding to the class's package. ```java public JavaPackage getJavaPackage() ``` -------------------------------- ### Provide Plugin Metadata Source: https://github.com/skylot/jadx/blob/master/_autodocs/06-plugins-and-extensions.md Implement `getPluginInfo` to return plugin metadata such as name, description, and version using `JadxPluginInfoBuilder`. ```java public JadxPluginInfo getPluginInfo() { return JadxPluginInfoBuilder.defaults() .name("My Custom Plugin") .description("Adds custom decompilation passes") .build(); } ``` -------------------------------- ### JavaClass - Get Original Obfuscated Name Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Retrieves the original, obfuscated name of the class before decompilation. ```java public String getRawName() ``` -------------------------------- ### Apply Formatting and Run Checks Source: https://github.com/skylot/jadx/wiki/Code-Formatting A combined command to first apply all code formatting and then run style checks, excluding tests. This ensures code is formatted and style-compliant before committing. ```bash ./gradlew spotlessApply ./gradlew check -x test ``` -------------------------------- ### Get Inlined Classes Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Retrieves an unmodifiable list of classes that have been inlined into this class. The list may be empty. ```java public List getInlinedClasses() ``` -------------------------------- ### load() Source: https://github.com/skylot/jadx/blob/master/_autodocs/01-jadx-decompiler.md Loads and initializes the decompilation process. This method must be called after creating a `JadxDecompiler` instance and before accessing decompiled classes or resources. ```APIDOC ## load() ### Description Load and initialize decompilation. This method: - Validates arguments - Loads plugins - Parses input files (APK, DEX, JAR, etc.) - Initializes class hierarchy and passes - Prepares for decompilation Must be called before accessing classes or resources. ### Returns void ### Throws `JadxRuntimeException` on validation or loading errors ### Example ```java JadxDecompiler jadx = new JadxDecompiler(args); jadx.load(); // Now can access classes via getClasses() ``` ``` -------------------------------- ### Get Methods Declared in Class Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Retrieves an unmodifiable list of all methods declared in this class, sorted by name. ```java public List getMethods() ``` -------------------------------- ### Automatic Plugin Discovery Source: https://github.com/skylot/jadx/blob/master/_autodocs/06-plugins-and-extensions.md Register your plugin automatically by creating a `META-INF/services/jadx.api.plugins.JadxPlugin` file containing your plugin's fully qualified class name. ```properties com.example.MyPlugin ``` -------------------------------- ### Get Binary Data from ResContainer Source: https://github.com/skylot/jadx/blob/master/_autodocs/04-resources.md Retrieves the raw byte data from a ResContainer, applicable only to binary resources. ```java public byte[] getData() ``` -------------------------------- ### Get Jadx Decompiler Instance - JadxPluginContext Source: https://github.com/skylot/jadx/blob/master/_autodocs/06-plugins-and-extensions.md Provides access to the parent JadxDecompiler instance from the plugin context. ```java public JadxDecompiler getJadxDecompiler() ``` -------------------------------- ### Create ResourceFile from File Source: https://github.com/skylot/jadx/blob/master/_autodocs/04-resources.md Factory method to create a ResourceFile instance from a given file on disk. Requires the parent decompiler, the file object, and the resource type. ```java public static ResourceFile createResourceFile( JadxDecompiler decompiler, File file, ResourceType type ) ``` -------------------------------- ### Dependencies Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Methods for retrieving dependency information. ```APIDOC ## getDependencies() ### Description Get all classes that this class depends on. ### Returns `List` ``` ```APIDOC ## getTotalDepsCount() ### Description Get total dependency count (for filtering decisions). ### Returns `int` ``` -------------------------------- ### JavaClass - Get Access Modifiers Source: https://github.com/skylot/jadx/blob/master/_autodocs/03-java-nodes.md Retrieves the access modifiers (e.g., public, private, final) for the class. ```java public AccessInfo getAccessInfo() ``` -------------------------------- ### Get Annotation Type Source: https://github.com/skylot/jadx/blob/master/_autodocs/05-code-info-and-metadata.md Retrieves the type of an ICodeAnnotation. This is useful for performing type-specific actions based on the annotation. ```java public AnnType getAnnType() ``` -------------------------------- ### Use Simple Decompilation Mode Source: https://github.com/skylot/jadx/blob/master/_autodocs/09-quick-start.md Employ SIMPLE mode for decompiling problematic APKs that may cause issues with the default mode. ```java args.setDecompilationMode(DecompilationMode.SIMPLE); ```