summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/analysis/ParsedJar.java
diff options
context:
space:
mode:
authorGravatar gegy10002018-07-17 19:14:08 +0200
committerGravatar GitHub2018-07-17 19:14:08 +0200
commita88175ffc95792b88a8724f66db6dda2b8cc32ee (patch)
tree65895bbc6cf1766f4ca01e1257619ab1993e71dc /src/main/java/cuchaz/enigma/analysis/ParsedJar.java
parentMerge pull request #3 from thiakil/src-jar (diff)
downloadenigma-fork-a88175ffc95792b88a8724f66db6dda2b8cc32ee.tar.gz
enigma-fork-a88175ffc95792b88a8724f66db6dda2b8cc32ee.tar.xz
enigma-fork-a88175ffc95792b88a8724f66db6dda2b8cc32ee.zip
ASM Based Class Translator (#1)
* Initial port to ASM * Package updates * Annotation + inner class translation * Fix inner class mapping * More bytecode translation * Signature refactoring * Fix highlighting of mapped names * Fix parameter name offset * Fix anonymous class generation * Fix issues with inner class signature transformation * Fix bridged method detection * Fix compile issues * Resolve all failed tests * Apply deobfuscated name to transformed classes * Fix class signatures not being translated * Fix frame array type translation * Fix frame array type translation * Fix array translation in method calls * Fix method reference and bridge detection * Fix handling of null deobf mappings * Parameter translation in interfaces * Fix enum parameter index offset * Fix parsed local variable indexing * Fix stackoverflow on rebuilding method names * Ignore invalid decompiled variable indices * basic source jar * Output directly to file on source export * Make decompile parallel * fix incorrect super calls * Use previous save state to delete old mapping files * Fix old mappings not properly being removed * Fix old mappings not properly being removed * make isMethodProvider public (cherry picked from commit ebad6a9) * speed up Deobfuscator's getSources by using a single TranslatingTypeloader and caching the ClassLoaderTypeloader * ignore .idea project folders * move SynchronizedTypeLoader to a non-inner * fix signature remap of inners for now * index & resolve method/field references for usages view * Allow reader/writer subclasses to provide the underlying file operations * fix giving obf classes a name not removing them from the panel * buffer the ParsedJar class entry inputstream, allow use with a jarinputstream * make CachingClasspathTypeLoader public * make CachingClasspathTypeLoader public * support enum switches with obfuscated SwitchMaps
Diffstat (limited to 'src/main/java/cuchaz/enigma/analysis/ParsedJar.java')
-rw-r--r--src/main/java/cuchaz/enigma/analysis/ParsedJar.java95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/ParsedJar.java b/src/main/java/cuchaz/enigma/analysis/ParsedJar.java
new file mode 100644
index 0000000..55f2141
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/analysis/ParsedJar.java
@@ -0,0 +1,95 @@
1/*******************************************************************************
2 * Copyright (c) 2015 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser General Public
5 * License v3.0 which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html
7 * <p>
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11
12package cuchaz.enigma.analysis;
13
14import cuchaz.enigma.mapping.entry.ClassEntry;
15import org.objectweb.asm.ClassReader;
16import org.objectweb.asm.tree.ClassNode;
17
18import java.io.BufferedInputStream;
19import java.io.IOException;
20import java.io.InputStream;
21import java.util.*;
22import java.util.function.Consumer;
23import java.util.jar.JarEntry;
24import java.util.jar.JarFile;
25import java.util.jar.JarInputStream;
26
27public class ParsedJar {
28 private final Map<String, ClassNode> nodes = new LinkedHashMap<>();
29
30 public ParsedJar(JarFile jar) throws IOException {
31 try {
32 // get the jar entries that correspond to classes
33 Enumeration<JarEntry> entries = jar.entries();
34 while (entries.hasMoreElements()) {
35 JarEntry entry = entries.nextElement();
36 // is this a class file?
37 if (entry.getName().endsWith(".class")) {
38 try (InputStream input = new BufferedInputStream(jar.getInputStream(entry))) {
39 // read the ClassNode from the jar
40 ClassReader reader = new ClassReader(input);
41 ClassNode node = new ClassNode();
42 reader.accept(node, 0);
43 String path = entry.getName().substring(0, entry.getName().length() - ".class".length());
44 nodes.put(path, node);
45 }
46 }
47 }
48 } finally {
49 jar.close();
50 }
51 }
52
53 public ParsedJar(JarInputStream jar) throws IOException {
54 try {
55 // get the jar entries that correspond to classes
56 JarEntry entry;
57 while ((entry = jar.getNextJarEntry()) != null) {
58 // is this a class file?
59 if (entry.getName().endsWith(".class")) {
60 // read the ClassNode from the jar
61 ClassReader reader = new ClassReader(jar);
62 ClassNode node = new ClassNode();
63 reader.accept(node, 0);
64 String path = entry.getName().substring(0, entry.getName().length() - ".class".length());
65 nodes.put(path, node);
66 jar.closeEntry();
67 }
68 }
69 } finally {
70 jar.close();
71 }
72 }
73
74 public void visit(Consumer<ClassNode> visitor) {
75 for (ClassNode node : nodes.values()) {
76 visitor.accept(node);
77 }
78 }
79
80 public int getClassCount() {
81 return nodes.size();
82 }
83
84 public List<ClassEntry> getClassEntries() {
85 List<ClassEntry> entries = new ArrayList<>(nodes.size());
86 for (ClassNode node : nodes.values()) {
87 entries.add(new ClassEntry(node.name));
88 }
89 return entries;
90 }
91
92 public ClassNode getClassNode(String name) {
93 return nodes.get(name);
94 }
95}