diff options
| author | 2019-01-30 21:05:32 +0200 | |
|---|---|---|
| committer | 2019-01-30 21:05:32 +0200 | |
| commit | ba7a354efae7d49833c887cf147ac940c975a1fa (patch) | |
| tree | 02e14fda81dd5984e24f2df392c57c6e829fc875 /src/main/java/cuchaz/enigma/analysis/ParsedJar.java | |
| parent | Rewrite the Jenkinsfile to use the new declarative pipeline syntax, lets hope... (diff) | |
| download | enigma-fork-ba7a354efae7d49833c887cf147ac940c975a1fa.tar.gz enigma-fork-ba7a354efae7d49833c887cf147ac940c975a1fa.tar.xz enigma-fork-ba7a354efae7d49833c887cf147ac940c975a1fa.zip | |
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
Diffstat (limited to 'src/main/java/cuchaz/enigma/analysis/ParsedJar.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/analysis/ParsedJar.java | 34 |
1 files changed, 21 insertions, 13 deletions
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 @@ | |||
| 12 | package cuchaz.enigma.analysis; | 12 | package cuchaz.enigma.analysis; |
| 13 | 13 | ||
| 14 | import com.google.common.io.ByteStreams; | 14 | import com.google.common.io.ByteStreams; |
| 15 | import cuchaz.enigma.CompiledSource; | ||
| 16 | import cuchaz.enigma.bytecode.translators.LocalVariableFixVisitor; | ||
| 15 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 17 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 16 | import org.objectweb.asm.ClassReader; | 18 | import org.objectweb.asm.ClassReader; |
| 17 | import org.objectweb.asm.ClassVisitor; | 19 | import org.objectweb.asm.ClassVisitor; |
| 20 | import org.objectweb.asm.Opcodes; | ||
| 18 | import org.objectweb.asm.tree.ClassNode; | 21 | import org.objectweb.asm.tree.ClassNode; |
| 19 | 22 | ||
| 20 | import javax.annotation.Nullable; | 23 | import javax.annotation.Nullable; |
| @@ -28,12 +31,12 @@ import java.util.jar.JarEntry; | |||
| 28 | import java.util.jar.JarFile; | 31 | import java.util.jar.JarFile; |
| 29 | import java.util.jar.JarInputStream; | 32 | import java.util.jar.JarInputStream; |
| 30 | 33 | ||
| 31 | public class ParsedJar { | 34 | public class ParsedJar implements CompiledSource { |
| 32 | private final Map<String, byte[]> classBytes; | 35 | private final Map<String, byte[]> classBytes; |
| 33 | private final Map<String, ClassNode> nodeCache = new HashMap<>(); | 36 | private final Map<String, ClassNode> nodeCache = new HashMap<>(); |
| 34 | 37 | ||
| 35 | public ParsedJar(JarFile jar) throws IOException { | 38 | public ParsedJar(JarFile jar) throws IOException { |
| 36 | Map<String, byte[]> uClassBytes = new LinkedHashMap<>();; | 39 | Map<String, byte[]> uClassBytes = new LinkedHashMap<>(); |
| 37 | try { | 40 | try { |
| 38 | // get the jar entries that correspond to classes | 41 | // get the jar entries that correspond to classes |
| 39 | Enumeration<JarEntry> entries = jar.entries(); | 42 | Enumeration<JarEntry> entries = jar.entries(); |
| @@ -93,29 +96,34 @@ public class ParsedJar { | |||
| 93 | return classBytes.size(); | 96 | return classBytes.size(); |
| 94 | } | 97 | } |
| 95 | 98 | ||
| 96 | public List<ClassEntry> getClassEntries() { | ||
| 97 | List<ClassEntry> entries = new ArrayList<>(classBytes.size()); | ||
| 98 | for (String s : classBytes.keySet()) { | ||
| 99 | entries.add(new ClassEntry(s)); | ||
| 100 | } | ||
| 101 | return entries; | ||
| 102 | } | ||
| 103 | |||
| 104 | @Nullable | 99 | @Nullable |
| 100 | @Override | ||
| 105 | public ClassNode getClassNode(String name) { | 101 | public ClassNode getClassNode(String name) { |
| 106 | return nodeCache.computeIfAbsent(name, (n) -> { | 102 | return nodeCache.computeIfAbsent(name, (n) -> { |
| 107 | byte[] bytes = classBytes.get(name); | 103 | byte[] bytes = classBytes.get(name); |
| 108 | if (bytes == null) { | 104 | if (bytes == null) { |
| 109 | return null; | 105 | return null; |
| 110 | } | 106 | } |
| 107 | |||
| 111 | ClassReader reader = new ClassReader(bytes); | 108 | ClassReader reader = new ClassReader(bytes); |
| 112 | ClassNode node = new ClassNode(); | 109 | ClassNode node = new ClassNode(); |
| 113 | reader.accept(node, 0); | 110 | |
| 111 | LocalVariableFixVisitor visitor = new LocalVariableFixVisitor(Opcodes.ASM5, node); | ||
| 112 | reader.accept(visitor, 0); | ||
| 113 | |||
| 114 | return node; | 114 | return node; |
| 115 | }); | 115 | }); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | public Map<String, byte[]> getClassDataMap() { | 118 | public List<ClassEntry> getClassEntries() { |
| 119 | List<ClassEntry> entries = new ArrayList<>(classBytes.size()); | ||
| 120 | for (String s : classBytes.keySet()) { | ||
| 121 | entries.add(new ClassEntry(s)); | ||
| 122 | } | ||
| 123 | return entries; | ||
| 124 | } | ||
| 125 | |||
| 126 | public Map<String, byte[]> getClassDataMap() { | ||
| 119 | return classBytes; | 127 | return classBytes; |
| 120 | } | 128 | } |
| 121 | } | 129 | } |