refactor: make input plugin api similar to pass plugins
This commit is contained in:
+4
-4
@@ -3,7 +3,6 @@ package jadx.plugins.input.dex;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import jadx.api.plugins.options.OptionDescription;
|
||||
import jadx.api.plugins.options.impl.BaseOptionsParser;
|
||||
@@ -15,11 +14,12 @@ public class DexInputOptions extends BaseOptionsParser {
|
||||
|
||||
private boolean verifyChecksum = true;
|
||||
|
||||
public void apply(Map<String, String> options) {
|
||||
verifyChecksum = getBooleanOption(options, VERIFY_CHECKSUM_OPT, true);
|
||||
@Override
|
||||
public void parseOptions() {
|
||||
verifyChecksum = getBooleanOption(VERIFY_CHECKSUM_OPT, true);
|
||||
}
|
||||
|
||||
public List<OptionDescription> buildOptionsDescriptions() {
|
||||
public List<OptionDescription> getOptionsDescriptions() {
|
||||
return Collections.singletonList(
|
||||
new JadxOptionDescription(
|
||||
VERIFY_CHECKSUM_OPT,
|
||||
|
||||
+15
-22
@@ -5,19 +5,17 @@ import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import jadx.api.plugins.JadxPlugin;
|
||||
import jadx.api.plugins.JadxPluginContext;
|
||||
import jadx.api.plugins.JadxPluginInfo;
|
||||
import jadx.api.plugins.input.JadxInputPlugin;
|
||||
import jadx.api.plugins.input.data.ILoadResult;
|
||||
import jadx.api.plugins.input.data.impl.EmptyLoadResult;
|
||||
import jadx.api.plugins.options.JadxPluginOptions;
|
||||
import jadx.api.plugins.options.OptionDescription;
|
||||
import jadx.api.plugins.input.ICodeLoader;
|
||||
import jadx.api.plugins.input.data.impl.EmptyCodeLoader;
|
||||
import jadx.api.plugins.utils.CommonFileUtils;
|
||||
|
||||
public class DexInputPlugin implements JadxInputPlugin, JadxPluginOptions {
|
||||
public class DexInputPlugin implements JadxPlugin {
|
||||
public static final String PLUGIN_ID = "dex-input";
|
||||
|
||||
private final DexInputOptions options = new DexInputOptions();
|
||||
@@ -29,39 +27,34 @@ public class DexInputPlugin implements JadxInputPlugin, JadxPluginOptions {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILoadResult loadFiles(List<Path> input) {
|
||||
public void init(JadxPluginContext context) {
|
||||
context.registerOptions(options);
|
||||
context.addCodeInput(this::loadFiles);
|
||||
}
|
||||
|
||||
public ICodeLoader loadFiles(List<Path> input) {
|
||||
return loadFiles(input, null);
|
||||
}
|
||||
|
||||
public ILoadResult loadFiles(List<Path> inputFiles, @Nullable Closeable closeable) {
|
||||
public ICodeLoader loadFiles(List<Path> inputFiles, @Nullable Closeable closeable) {
|
||||
List<DexReader> dexReaders = loader.collectDexFiles(inputFiles);
|
||||
if (dexReaders.isEmpty()) {
|
||||
return EmptyLoadResult.INSTANCE;
|
||||
return EmptyCodeLoader.INSTANCE;
|
||||
}
|
||||
return new DexLoadResult(dexReaders, closeable);
|
||||
}
|
||||
|
||||
public ILoadResult loadDex(byte[] content, @Nullable String fileName) {
|
||||
public ICodeLoader loadDex(byte[] content, @Nullable String fileName) {
|
||||
String fileLabel = fileName == null ? "input.dex" : fileName;
|
||||
DexReader dexReader = loader.loadDexReader(fileLabel, content);
|
||||
return new DexLoadResult(Collections.singletonList(dexReader), null);
|
||||
}
|
||||
|
||||
public ILoadResult loadDexFromInputStream(InputStream in, @Nullable String fileLabel) {
|
||||
public ICodeLoader loadDexFromInputStream(InputStream in, @Nullable String fileLabel) {
|
||||
try {
|
||||
return loadDex(CommonFileUtils.loadBytes(in), fileLabel);
|
||||
} catch (Exception e) {
|
||||
throw new DexException("Failed to read input stream", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOptions(Map<String, String> options) {
|
||||
this.options.apply(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OptionDescription> getOptionsDescriptions() {
|
||||
return this.options.buildOptionsDescriptions();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,10 @@ import java.util.function.Consumer;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import jadx.api.plugins.input.ICodeLoader;
|
||||
import jadx.api.plugins.input.data.IClassData;
|
||||
import jadx.api.plugins.input.data.ILoadResult;
|
||||
import jadx.api.plugins.input.data.IResourceData;
|
||||
|
||||
public class DexLoadResult implements ILoadResult {
|
||||
public class DexLoadResult implements ICodeLoader {
|
||||
private final List<DexReader> dexReaders;
|
||||
@Nullable
|
||||
private final Closeable closeable;
|
||||
@@ -28,10 +27,6 @@ public class DexLoadResult implements ILoadResult {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitResources(Consumer<IResourceData> consumer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (closeable != null) {
|
||||
|
||||
+2
-2
@@ -9,10 +9,10 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jadx.api.plugins.input.ICodeLoader;
|
||||
import jadx.api.plugins.input.data.AccessFlags;
|
||||
import jadx.api.plugins.input.data.AccessFlagsScope;
|
||||
import jadx.api.plugins.input.data.ICodeReader;
|
||||
import jadx.api.plugins.input.data.ILoadResult;
|
||||
import jadx.plugins.input.dex.utils.SmaliTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -38,7 +38,7 @@ class DexInputPluginTest {
|
||||
System.out.println("Input file: " + sample.toAbsolutePath());
|
||||
long start = System.currentTimeMillis();
|
||||
List<Path> files = Collections.singletonList(sample);
|
||||
try (ILoadResult result = new DexInputPlugin().loadFiles(files)) {
|
||||
try (ICodeLoader result = new DexInputPlugin().loadFiles(files)) {
|
||||
AtomicInteger count = new AtomicInteger();
|
||||
result.visitClasses(cls -> {
|
||||
System.out.println();
|
||||
|
||||
Reference in New Issue
Block a user