summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/analysis/ParsedJar.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/analysis/ParsedJar.java')
-rw-r--r--src/main/java/cuchaz/enigma/analysis/ParsedJar.java34
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 @@
12package cuchaz.enigma.analysis; 12package cuchaz.enigma.analysis;
13 13
14import com.google.common.io.ByteStreams; 14import com.google.common.io.ByteStreams;
15import cuchaz.enigma.CompiledSource;
16import cuchaz.enigma.bytecode.translators.LocalVariableFixVisitor;
15import cuchaz.enigma.translation.representation.entry.ClassEntry; 17import cuchaz.enigma.translation.representation.entry.ClassEntry;
16import org.objectweb.asm.ClassReader; 18import org.objectweb.asm.ClassReader;
17import org.objectweb.asm.ClassVisitor; 19import org.objectweb.asm.ClassVisitor;
20import org.objectweb.asm.Opcodes;
18import org.objectweb.asm.tree.ClassNode; 21import org.objectweb.asm.tree.ClassNode;
19 22
20import javax.annotation.Nullable; 23import javax.annotation.Nullable;
@@ -28,12 +31,12 @@ import java.util.jar.JarEntry;
28import java.util.jar.JarFile; 31import java.util.jar.JarFile;
29import java.util.jar.JarInputStream; 32import java.util.jar.JarInputStream;
30 33
31public class ParsedJar { 34public 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}