feat: allow to load directories
This commit is contained in:
@@ -85,9 +85,6 @@ public class JadxArgsValidator {
|
||||
if (!file.exists()) {
|
||||
throw new JadxArgsValidateException("File not found " + file.getAbsolutePath());
|
||||
}
|
||||
if (file.isDirectory()) {
|
||||
throw new JadxArgsValidateException("Expected file but found directory instead: " + file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkDir(File dir, String desc) {
|
||||
|
||||
@@ -40,6 +40,7 @@ import jadx.core.dex.visitors.SaveCode;
|
||||
import jadx.core.export.ExportGradleProject;
|
||||
import jadx.core.utils.Utils;
|
||||
import jadx.core.utils.exceptions.JadxRuntimeException;
|
||||
import jadx.core.utils.files.FileUtils;
|
||||
import jadx.core.xmlgen.BinaryXMLParser;
|
||||
import jadx.core.xmlgen.ProtoXMLParser;
|
||||
import jadx.core.xmlgen.ResContainer;
|
||||
@@ -113,8 +114,9 @@ public final class JadxDecompiler implements Closeable {
|
||||
private void loadInputFiles() {
|
||||
loadedInputs.clear();
|
||||
List<Path> inputPaths = Utils.collectionMap(args.getInputFiles(), File::toPath);
|
||||
List<Path> inputFiles = FileUtils.expandDirs(inputPaths);
|
||||
for (JadxInputPlugin inputPlugin : pluginManager.getInputPlugins()) {
|
||||
ILoadResult loadResult = inputPlugin.loadFiles(inputPaths);
|
||||
ILoadResult loadResult = inputPlugin.loadFiles(inputFiles);
|
||||
if (loadResult != null && !loadResult.isEmpty()) {
|
||||
loadedInputs.add(loadResult);
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ public final class ResourcesLoader {
|
||||
}
|
||||
|
||||
private void loadFile(List<ResourceFile> list, File file) {
|
||||
if (file == null) {
|
||||
if (file == null || file.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
if (FileUtils.isZipFile(file)) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.FileVisitOption;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
@@ -41,6 +42,26 @@ public class FileUtils {
|
||||
private FileUtils() {
|
||||
}
|
||||
|
||||
public static List<Path> expandDirs(List<Path> paths) {
|
||||
List<Path> files = new ArrayList<>(paths.size());
|
||||
for (Path path : paths) {
|
||||
if (Files.isDirectory(path)) {
|
||||
expandDir(path, files);
|
||||
} else {
|
||||
files.add(path);
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
private static void expandDir(Path dir, List<Path> files) {
|
||||
try (Stream<Path> walk = Files.walk(dir, FileVisitOption.FOLLOW_LINKS)) {
|
||||
walk.filter(Files::isRegularFile).forEach(files::add);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Failed to list files in directory: {}", dir, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addFileToJar(JarOutputStream jar, File source, String entryName) throws IOException {
|
||||
try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(source))) {
|
||||
JarEntry entry = new JarEntry(entryName);
|
||||
|
||||
@@ -323,6 +323,7 @@ public class MainWindow extends JFrame {
|
||||
fileChooser.setFileFilter(new FileNameExtensionFilter(description, exts));
|
||||
fileChooser.setMultiSelectionEnabled(true);
|
||||
fileChooser.setToolTipText(toolTipText);
|
||||
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
|
||||
Path currentDirectory = settings.getLastOpenFilePath();
|
||||
if (currentDirectory != null) {
|
||||
fileChooser.setCurrentDirectory(currentDirectory.toFile());
|
||||
|
||||
-3
@@ -36,7 +36,6 @@ public class JavaConvertLoader {
|
||||
private static void processJars(List<Path> input, ConvertResult result) {
|
||||
PathMatcher jarMatcher = FileSystems.getDefault().getPathMatcher("glob:**.jar");
|
||||
input.stream()
|
||||
.filter(path -> Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS))
|
||||
.filter(jarMatcher::matches)
|
||||
.forEach(path -> {
|
||||
try {
|
||||
@@ -50,7 +49,6 @@ public class JavaConvertLoader {
|
||||
private static void processClassFiles(List<Path> input, ConvertResult result) {
|
||||
PathMatcher jarMatcher = FileSystems.getDefault().getPathMatcher("glob:**.class");
|
||||
List<Path> clsFiles = input.stream()
|
||||
.filter(path -> Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS))
|
||||
.filter(jarMatcher::matches)
|
||||
.collect(Collectors.toList());
|
||||
if (clsFiles.isEmpty()) {
|
||||
@@ -78,7 +76,6 @@ public class JavaConvertLoader {
|
||||
private static void processAars(List<Path> input, ConvertResult result) {
|
||||
PathMatcher aarMatcher = FileSystems.getDefault().getPathMatcher("glob:**.aar");
|
||||
input.stream()
|
||||
.filter(path -> Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS))
|
||||
.filter(aarMatcher::matches)
|
||||
.forEach(path -> ZipSecurity.readZipEntries(path.toFile(), (entry, in) -> {
|
||||
try {
|
||||
|
||||
+2
-4
@@ -7,7 +7,6 @@ import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.PathMatcher;
|
||||
import java.util.Collections;
|
||||
@@ -32,10 +31,10 @@ public class SmaliConvert implements Closeable {
|
||||
if (smaliFiles.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
LOG.debug("Compiling smali files: {}", smaliFiles.size());
|
||||
try {
|
||||
this.tmpDex = Files.createTempFile("jadx-", ".dex");
|
||||
boolean result = compileSmali(tmpDex, smaliFiles);
|
||||
if (result) {
|
||||
if (compileSmali(tmpDex, smaliFiles)) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -82,7 +81,6 @@ public class SmaliConvert implements Closeable {
|
||||
private List<Path> filterSmaliFiles(List<Path> input) {
|
||||
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:**.smali");
|
||||
return input.stream()
|
||||
.filter(p -> Files.isRegularFile(p, LinkOption.NOFOLLOW_LINKS))
|
||||
.filter(matcher::matches)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user