From ba7a354efae7d49833c887cf147ac940c975a1fa Mon Sep 17 00:00:00 2001 From: Gegy Date: Wed, 30 Jan 2019 21:05:32 +0200 Subject: Remap sources (#106) * Source remapping beginnings * Fix navigation to remapped classes * Translate identifier info reference * Remap local variables with default names in source * Caching translator * Fix lack of highlighting for first opened class * Fix unicode variable names * Unicode checker shouldn't be checking just alphanumeric * Fix package tree being built from obf names * Don't index `this` as method call for method::reference * Apply proposed names * Fix source export issues * Replace unicode var names at bytecode level uniquely * Drop imports from editor source * Class selector fixes * Delta keep track of base mappings to enable lookup of old names * Optimize source remapping by remapping source with a StringBuffer instead of copying * Bump version --- .../java/cuchaz/enigma/analysis/ParsedJar.java | 34 +++++++++++++--------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'src/main/java/cuchaz/enigma/analysis/ParsedJar.java') diff --git a/src/main/java/cuchaz/enigma/analysis/ParsedJar.java b/src/main/java/cuchaz/enigma/analysis/ParsedJar.java index ad3aceb..ddcda3e 100644 --- a/src/main/java/cuchaz/enigma/analysis/ParsedJar.java +++ b/src/main/java/cuchaz/enigma/analysis/ParsedJar.java @@ -12,9 +12,12 @@ package cuchaz.enigma.analysis; import com.google.common.io.ByteStreams; +import cuchaz.enigma.CompiledSource; +import cuchaz.enigma.bytecode.translators.LocalVariableFixVisitor; import cuchaz.enigma.translation.representation.entry.ClassEntry; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.ClassNode; import javax.annotation.Nullable; @@ -28,12 +31,12 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.jar.JarInputStream; -public class ParsedJar { +public class ParsedJar implements CompiledSource { private final Map classBytes; private final Map nodeCache = new HashMap<>(); public ParsedJar(JarFile jar) throws IOException { - Map uClassBytes = new LinkedHashMap<>();; + Map uClassBytes = new LinkedHashMap<>(); try { // get the jar entries that correspond to classes Enumeration entries = jar.entries(); @@ -93,29 +96,34 @@ public class ParsedJar { return classBytes.size(); } - public List getClassEntries() { - List entries = new ArrayList<>(classBytes.size()); - for (String s : classBytes.keySet()) { - entries.add(new ClassEntry(s)); - } - return entries; - } - @Nullable + @Override public ClassNode getClassNode(String name) { return nodeCache.computeIfAbsent(name, (n) -> { byte[] bytes = classBytes.get(name); if (bytes == null) { return null; } + ClassReader reader = new ClassReader(bytes); ClassNode node = new ClassNode(); - reader.accept(node, 0); + + LocalVariableFixVisitor visitor = new LocalVariableFixVisitor(Opcodes.ASM5, node); + reader.accept(visitor, 0); + return node; }); } - public Map getClassDataMap() { + public List getClassEntries() { + List entries = new ArrayList<>(classBytes.size()); + for (String s : classBytes.keySet()) { + entries.add(new ClassEntry(s)); + } + return entries; + } + + public Map getClassDataMap() { return classBytes; - } + } } -- cgit v1.2.3