Skip to content

Commit

Permalink
Remove JADX repackaging top-level classes workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
NebelNidas committed Mar 10, 2024
1 parent 449789c commit 85820c5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/main/java/matcher/gui/tab/SourcecodeTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import matcher.gui.Gui;
import matcher.gui.ISelectionProvider;
import matcher.srcprocess.HtmlUtil;
import matcher.srcprocess.Jadx;
import matcher.srcprocess.SrcDecorator;
import matcher.srcprocess.SrcDecorator.SrcParseException;
import matcher.type.ClassInstance;
Expand Down Expand Up @@ -89,7 +88,7 @@ private void update() {
NameType nameType = gui.getNameType().withUnmatchedTmp(unmatchedTmp);

//Gui.runAsyncTask(() -> gui.getEnv().decompile(selectedClass, true))
Gui.runAsyncTask(() -> SrcDecorator.decorate(gui.getEnv().decompile(gui.getDecompiler().get(), selectedClass, nameType), selectedClass, nameType, gui.getDecompiler().get() instanceof Jadx))
Gui.runAsyncTask(() -> SrcDecorator.decorate(gui.getEnv().decompile(gui.getDecompiler().get(), selectedClass, nameType), selectedClass, nameType))
.whenComplete((res, exc) -> {
if (cDecompId == decompId) {
if (exc != null) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/matcher/srcprocess/Jadx.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void close() {
jadxArgs.setInlineAnonymousClasses(false);
jadxArgs.setInlineMethods(false);
jadxArgs.setSkipResources(true);
jadxArgs.setRenameValid(false);
jadxArgs.setRespectBytecodeAccModifiers(true);
jadxArgs.setCommentsLevel(CommentsLevel.INFO);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/matcher/srcprocess/SrcDecorator.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import matcher.type.MethodVarInstance;

public class SrcDecorator {
public static String decorate(String src, ClassInstance cls, NameType nameType, boolean decompiledByJadx) {
public static String decorate(String src, ClassInstance cls, NameType nameType) {
String name = cls.getName(nameType);

if (cls.getOuterClass() != null && name.contains("$")) {
Expand Down Expand Up @@ -93,7 +93,7 @@ public static String decorate(String src, ClassInstance cls, NameType nameType,
}
}

TypeResolver resolver = new TypeResolver(decompiledByJadx);
TypeResolver resolver = new TypeResolver();
resolver.setup(cls, nameType, cu);

cu.accept(remapVisitor, resolver);
Expand Down
17 changes: 2 additions & 15 deletions src/main/java/matcher/srcprocess/TypeResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
import matcher.type.MethodInstance;

class TypeResolver {
TypeResolver(boolean decmpiledByJadx) {
this.decompiledByJadx = decmpiledByJadx;
}

public void setup(ClassInstance rootCls, NameType nameType, CompilationUnit cu) {
this.rootCls = rootCls;
this.env = rootCls.getEnv();
Expand Down Expand Up @@ -65,19 +61,11 @@ public void setup(ClassInstance rootCls, NameType nameType, CompilationUnit cu)
}
}

// TODO: Clean up once you can disable JADX repackaging orphaned classes
public ClassInstance getCls(Node node) {
StringBuilder sb = new StringBuilder();
String jadxDefaultPackage = jadx.core.Consts.DEFAULT_PACKAGE_NAME;

if (pkg != null && (!decompiledByJadx || !pkg.equals(jadxDefaultPackage))) {
String pkgCleaned = pkg;

if (decompiledByJadx && pkg.startsWith(jadxDefaultPackage)) {
pkgCleaned = pkg.substring(jadxDefaultPackage.length() + 1);
}

sb.append(pkgCleaned);
if (pkg != null) {
sb.append(pkg);
sb.append('/');
}

Expand Down Expand Up @@ -279,5 +267,4 @@ public String getName(Matchable<?> e) {
private String pkg;
private final Map<String, String> imports = new HashMap<>();
private final List<String> wildcardImports = new ArrayList<>();
private final boolean decompiledByJadx;
}

0 comments on commit 85820c5

Please sign in to comment.