Skip to content

Commit

Permalink
New JADX implementation can decompile inner classes
Browse files Browse the repository at this point in the history
Also fix checkstyle issues
  • Loading branch information
NebelNidas committed Mar 10, 2024
1 parent 7ebddf6 commit b4286f2
Showing 1 changed file with 25 additions and 31 deletions.
56 changes: 25 additions & 31 deletions src/main/java/matcher/srcprocess/Jadx.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package matcher.srcprocess;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;

Expand All @@ -27,39 +25,35 @@ public String decompile(ClassInstance cls, ClassFeatureExtractor env, NameType n
String errorMessage = null;
final String fullClassName = cls.getName(NameType.PLAIN, true);

if (fullClassName.contains("$")) {
errorMessage = "JADX doesn't support decompiling inner classes!";
} else {
try (JadxDecompiler jadx = new JadxDecompiler(jadxArgs)) {
jadx.addCustomLoad(new ILoadResult() {
@Override
public void close() throws IOException {
return;
}
try (JadxDecompiler jadx = new JadxDecompiler(jadxArgs)) {
jadx.addCustomLoad(new ILoadResult() {
@Override
public void close() throws IOException {
return;
}

@Override
public void visitClasses(Consumer<IClassData> consumer) {
consumer.accept(new JavaClassData(new JavaClassReader(idGenerator.getAndIncrement(),
fullClassName + ".class", cls.serialize(nameType))));
}
@Override
public void visitClasses(Consumer<IClassData> consumer) {
consumer.accept(new JavaClassData(new JavaClassReader(idGenerator.getAndIncrement(),
fullClassName + ".class", cls.serialize(nameType))));
}

@Override
public void visitResources(Consumer<IResourceData> consumer) {
return;
}
@Override
public void visitResources(Consumer<IResourceData> consumer) {
return;
}

@Override
public boolean isEmpty() {
return false;
}
});
jadx.load();
@Override
public boolean isEmpty() {
return false;
}
});
jadx.load();

assert jadx.getClassesWithInners().size() == 1;
return jadx.getClassesWithInners().get(0).getCode();
} catch (Exception e) {
errorMessage = Utils.getStackTrace(e);
}
assert jadx.getClassesWithInners().size() == 1;
return jadx.getClassesWithInners().get(0).getCode();
} catch (Exception e) {
errorMessage = Utils.getStackTrace(e);
}

throw new RuntimeException(errorMessage != null ? errorMessage : "JADX couldn't find the requested class");
Expand Down

0 comments on commit b4286f2

Please sign in to comment.