feat: add raung input plugin, use raung in tests
This commit is contained in:
+8
-1
@@ -1,8 +1,11 @@
|
||||
package jadx.plugins.input.java;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import jadx.api.plugins.JadxPluginInfo;
|
||||
import jadx.api.plugins.input.JadxInputPlugin;
|
||||
import jadx.api.plugins.input.data.ILoadResult;
|
||||
@@ -22,10 +25,14 @@ public class JavaInputPlugin implements JadxInputPlugin {
|
||||
|
||||
@Override
|
||||
public ILoadResult loadFiles(List<Path> inputFiles) {
|
||||
return loadClassFiles(inputFiles, null);
|
||||
}
|
||||
|
||||
public static ILoadResult loadClassFiles(List<Path> inputFiles, @Nullable Closeable closeable) {
|
||||
List<JavaClassReader> readers = new JavaFileLoader().collectFiles(inputFiles);
|
||||
if (readers.isEmpty()) {
|
||||
return EmptyLoadResult.INSTANCE;
|
||||
}
|
||||
return new JavaLoadResult(readers);
|
||||
return new JavaLoadResult(readers, closeable);
|
||||
}
|
||||
}
|
||||
|
||||
+11
-2
@@ -1,8 +1,11 @@
|
||||
package jadx.plugins.input.java;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -14,9 +17,12 @@ public class JavaLoadResult implements ILoadResult {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(JavaLoadResult.class);
|
||||
|
||||
private final List<JavaClassReader> readers;
|
||||
@Nullable
|
||||
private final Closeable closeable;
|
||||
|
||||
public JavaLoadResult(List<JavaClassReader> readers) {
|
||||
public JavaLoadResult(List<JavaClassReader> readers, @Nullable Closeable closeable) {
|
||||
this.readers = readers;
|
||||
this.closeable = closeable;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,7 +46,10 @@ public class JavaLoadResult implements ILoadResult {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
public void close() throws IOException {
|
||||
readers.clear();
|
||||
if (closeable != null) {
|
||||
closeable.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
plugins {
|
||||
id 'java-library'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":jadx-plugins:jadx-plugins-api"))
|
||||
|
||||
implementation(project(":jadx-plugins:jadx-java-input"))
|
||||
|
||||
implementation('io.github.skylot:raung-asm:0.0.1')
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package jadx.plugins.input.raung;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.PathMatcher;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.github.skylot.raung.asm.RaungAsm;
|
||||
|
||||
public class RaungConvert implements Closeable {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RaungConvert.class);
|
||||
|
||||
@Nullable
|
||||
private Path tmpJar;
|
||||
|
||||
public boolean execute(List<Path> input) {
|
||||
List<Path> raungInputs = filterRaungFiles(input);
|
||||
if (raungInputs.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
this.tmpJar = Files.createTempFile("jadx-raung-", ".jar");
|
||||
RaungAsm.create()
|
||||
.output(tmpJar)
|
||||
.inputs(input)
|
||||
.execute();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOG.error("Raung process error", e);
|
||||
}
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<Path> filterRaungFiles(List<Path> input) {
|
||||
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:**.raung");
|
||||
return input.stream()
|
||||
.filter(matcher::matches)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Path> getFiles() {
|
||||
if (tmpJar == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.singletonList(tmpJar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
try {
|
||||
if (tmpJar != null) {
|
||||
Files.deleteIfExists(tmpJar);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Failed to remove tmp jar file: {}", tmpJar, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package jadx.plugins.input.raung;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
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.plugins.input.java.JavaInputPlugin;
|
||||
|
||||
public class RaungInputPlugin implements JadxInputPlugin {
|
||||
|
||||
@Override
|
||||
public JadxPluginInfo getPluginInfo() {
|
||||
return new JadxPluginInfo(
|
||||
"raung-input",
|
||||
"RaungInput",
|
||||
"Load .raung files");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILoadResult loadFiles(List<Path> input) {
|
||||
RaungConvert convert = new RaungConvert();
|
||||
if (!convert.execute(input)) {
|
||||
return EmptyLoadResult.INSTANCE;
|
||||
}
|
||||
return JavaInputPlugin.loadClassFiles(convert.getFiles(), convert);
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
jadx.plugins.input.raung.RaungInputPlugin
|
||||
Reference in New Issue
Block a user