Skip to content

Commit

Permalink
Optimize and comment frame-related stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ThexXTURBOXx committed Jan 16, 2024
1 parent b66663a commit f776c68
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2jar.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.spi.FileSystemProvider;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.HashSet;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.stream.Collectors;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
Expand Down Expand Up @@ -89,28 +89,33 @@ public void doTranslate(final Path dist, final ByteArrayOutputStream baos) {
ClassVisitorFactory cvf = new ClassVisitorFactory() {
@Override
public ClassVisitor create(final String name) {
// If we choose to recompute the stack map frames, we need a special impl
final ClassWriter cw = (readerConfig & DexFileReader.COMPUTE_FRAMES) == 0
? new ClassWriter(ClassWriter.COMPUTE_MAXS)
: new ClassWriter(ClassWriter.COMPUTE_FRAMES) {
@Override
protected String getCommonSuperClass(String type1, String type2) {
if (type1.equals(type2)) return type1;

List<String> parentsOfType1 = new ArrayList<>();
// First collect all the possible parents of type1
Set<String> parentsOfType1 = new HashSet<>();
parentsOfType1.add(type1);
while (parentsByName.containsKey(type1)) {
type1 = parentsByName.get(type1);
parentsOfType1.add(type1);
}

// Then we see whether type2 or any of its parents match
while (parentsByName.containsKey(type2)) {
type2 = parentsByName.get(type2);
if (parentsOfType1.contains(type2)) return type2;
}

try {
// Maybe the default impl can resolve the rest
return super.getCommonSuperClass(type1, type2);
} catch (Throwable t) {
// If all else fails
return "java/util/Object";
}
}
Expand Down

0 comments on commit f776c68

Please sign in to comment.