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);
|
||||
|
||||
Reference in New Issue
Block a user