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 Apr 20, 2023
1 parent f00bd7f commit 7df38c5
Showing 1 changed file with 25 additions and 32 deletions.
57 changes: 25 additions & 32 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 All @@ -82,6 +76,5 @@ public void close() {
jadxArgs.setSkipResources(true);
jadxArgs.setRespectBytecodeAccModifiers(true);
jadxArgs.setCommentsLevel(CommentsLevel.INFO);

}
}

0 comments on commit 7df38c5

Please sign in to comment.