summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/mapping/Signature.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/mapping/Signature.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/mapping/Signature.java')
-rw-r--r--src/main/java/cuchaz/enigma/mapping/Signature.java128
1 files changed, 52 insertions, 76 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/Signature.java b/src/main/java/cuchaz/enigma/mapping/Signature.java
index 78130d6..071e4af 100644
--- a/src/main/java/cuchaz/enigma/mapping/Signature.java
+++ b/src/main/java/cuchaz/enigma/mapping/Signature.java
@@ -1,106 +1,82 @@
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.mapping; 1package cuchaz.enigma.mapping;
13 2
14import com.google.common.collect.Lists; 3import cuchaz.enigma.bytecode.translators.TranslationSignatureVisitor;
15import cuchaz.enigma.utils.Utils; 4import org.objectweb.asm.signature.SignatureReader;
5import org.objectweb.asm.signature.SignatureVisitor;
6import org.objectweb.asm.signature.SignatureWriter;
16 7
17import java.util.List; 8import java.util.function.Function;
9import java.util.regex.Pattern;
18 10
19public class Signature { 11public class Signature {
12 private static final Pattern OBJECT_PATTERN = Pattern.compile(".*:Ljava/lang/Object;:.*");
20 13
21 private List<Type> argumentTypes; 14 private final String signature;
22 private Type returnType; 15 private final boolean isType;
23 16
24 public Signature(String signature) { 17 private Signature(String signature, boolean isType) {
25 try { 18 if (signature != null && OBJECT_PATTERN.matcher(signature).matches()) {
26 this.argumentTypes = Lists.newArrayList(); 19 signature = signature.replaceAll(":Ljava/lang/Object;:", "::");
27 int i = 0;
28 while (i < signature.length()) {
29 char c = signature.charAt(i);
30 if (c == '(') {
31 assert (this.argumentTypes.isEmpty());
32 assert (this.returnType == null);
33 i++;
34 } else if (c == ')') {
35 i++;
36 break;
37 } else {
38 String type = Type.parseFirst(signature.substring(i));
39 this.argumentTypes.add(new Type(type));
40 i += type.length();
41 }
42 }
43 this.returnType = new Type(Type.parseFirst(signature.substring(i)));
44 } catch (Exception ex) {
45 throw new IllegalArgumentException("Unable to parse signature: " + signature, ex);
46 } 20 }
21
22 this.signature = signature;
23 this.isType = isType;
47 } 24 }
48 25
49 public Signature(Signature other, ClassNameReplacer replacer) { 26 public static Signature createTypedSignature(String signature) {
50 this.argumentTypes = Lists.newArrayList(other.argumentTypes); 27 if (signature != null && !signature.isEmpty()) {
51 for (int i = 0; i < this.argumentTypes.size(); i++) { 28 return new Signature(signature, true);
52 this.argumentTypes.set(i, new Type(this.argumentTypes.get(i), replacer));
53 } 29 }
54 this.returnType = new Type(other.returnType, replacer); 30 return new Signature(null, true);
55 } 31 }
56 32
57 public List<Type> getArgumentTypes() { 33 public static Signature createSignature(String signature) {
58 return this.argumentTypes; 34 if (signature != null && !signature.isEmpty()) {
35 return new Signature(signature, false);
36 }
37 return new Signature(null, false);
59 } 38 }
60 39
61 public Type getReturnType() { 40 public String getSignature() {
62 return this.returnType; 41 return signature;
63 } 42 }
64 43
65 @Override 44 public boolean isType() {
66 public String toString() { 45 return isType;
67 StringBuilder buf = new StringBuilder();
68 buf.append("(");
69 for (Type type : this.argumentTypes) {
70 buf.append(type);
71 }
72 buf.append(")");
73 buf.append(this.returnType);
74 return buf.toString();
75 } 46 }
76 47
77 public Iterable<Type> types() { 48 public Signature remap(Function<String, String> remapper) {
78 List<Type> types = Lists.newArrayList(); 49 if (signature == null) {
79 types.addAll(this.argumentTypes); 50 return this;
80 types.add(this.returnType); 51 }
81 return types; 52 SignatureWriter writer = new SignatureWriter();
53 SignatureVisitor visitor = new TranslationSignatureVisitor(remapper, writer);
54 if (isType) {
55 new SignatureReader(signature).acceptType(visitor);
56 } else {
57 new SignatureReader(signature).accept(visitor);
58 }
59 return new Signature(writer.toString(), isType);
82 } 60 }
83 61
84 @Override 62 @Override
85 public boolean equals(Object other) { 63 public boolean equals(Object obj) {
86 return other instanceof Signature && equals((Signature) other); 64 if (obj instanceof Signature) {
87 } 65 Signature other = (Signature) obj;
88 66 return (other.signature == null && signature == null || other.signature != null
89 public boolean equals(Signature other) { 67 && signature != null && other.signature.equals(signature))
90 return this.argumentTypes.equals(other.argumentTypes) && this.returnType.equals(other.returnType); 68 && other.isType == this.isType;
69 }
70 return false;
91 } 71 }
92 72
93 @Override 73 @Override
94 public int hashCode() { 74 public int hashCode() {
95 return Utils.combineHashesOrdered(this.argumentTypes.hashCode(), this.returnType.hashCode()); 75 return signature.hashCode() | (isType ? 1 : 0) << 16;
96 } 76 }
97 77
98 public boolean hasClass(ClassEntry classEntry) { 78 @Override
99 for (Type type : types()) { 79 public String toString() {
100 if (type.hasClass() && type.getClassEntry().equals(classEntry)) { 80 return signature;
101 return true;
102 }
103 }
104 return false;
105 } 81 }
106} 82}