diff options
| author | 2016-07-02 18:04:57 +1000 | |
|---|---|---|
| committer | 2016-07-02 18:04:57 +1000 | |
| commit | 64c359d3c1d2347001e5c6becb1d7561457f52cc (patch) | |
| tree | bc2f37325b770475237437d204e95254dbfa0b3d /src/main/java | |
| parent | Fixed Null.json and #4 (diff) | |
| download | enigma-64c359d3c1d2347001e5c6becb1d7561457f52cc.tar.gz enigma-64c359d3c1d2347001e5c6becb1d7561457f52cc.tar.xz enigma-64c359d3c1d2347001e5c6becb1d7561457f52cc.zip | |
Renamed Fields
Diffstat (limited to 'src/main/java')
55 files changed, 750 insertions, 814 deletions
diff --git a/src/main/java/cuchaz/enigma/CommandMain.java b/src/main/java/cuchaz/enigma/CommandMain.java index 69f56849..b715c6e2 100644 --- a/src/main/java/cuchaz/enigma/CommandMain.java +++ b/src/main/java/cuchaz/enigma/CommandMain.java | |||
| @@ -11,7 +11,6 @@ | |||
| 11 | package cuchaz.enigma; | 11 | package cuchaz.enigma; |
| 12 | 12 | ||
| 13 | import java.io.File; | 13 | import java.io.File; |
| 14 | import java.io.FileReader; | ||
| 15 | import java.util.jar.JarFile; | 14 | import java.util.jar.JarFile; |
| 16 | 15 | ||
| 17 | import cuchaz.enigma.Deobfuscator.ProgressListener; | 16 | import cuchaz.enigma.Deobfuscator.ProgressListener; |
diff --git a/src/main/java/cuchaz/enigma/ConvertMain.java b/src/main/java/cuchaz/enigma/ConvertMain.java index 409a2692..a68ab614 100644 --- a/src/main/java/cuchaz/enigma/ConvertMain.java +++ b/src/main/java/cuchaz/enigma/ConvertMain.java | |||
| @@ -11,8 +11,6 @@ | |||
| 11 | package cuchaz.enigma; | 11 | package cuchaz.enigma; |
| 12 | 12 | ||
| 13 | import java.io.File; | 13 | import java.io.File; |
| 14 | import java.io.FileReader; | ||
| 15 | import java.io.FileWriter; | ||
| 16 | import java.io.IOException; | 14 | import java.io.IOException; |
| 17 | import java.util.jar.JarFile; | 15 | import java.util.jar.JarFile; |
| 18 | 16 | ||
| @@ -42,7 +40,7 @@ public class ConvertMain { | |||
| 42 | //Get the mapping files | 40 | //Get the mapping files |
| 43 | File inMappingsFile = new File(OldMappings); | 41 | File inMappingsFile = new File(OldMappings); |
| 44 | File outMappingsFile = new File(NewMappings); | 42 | File outMappingsFile = new File(NewMappings); |
| 45 | Mappings mappings = new MappingsReader().read( inMappingsFile); | 43 | Mappings mappings = new MappingsReader().read(inMappingsFile); |
| 46 | //Make the Match Files.. | 44 | //Make the Match Files.. |
| 47 | File classMatchesFile = new File(ClassMatches); | 45 | File classMatchesFile = new File(ClassMatches); |
| 48 | File fieldMatchesFile = new File(FieldMatches); | 46 | File fieldMatchesFile = new File(FieldMatches); |
| @@ -187,7 +185,7 @@ public class ConvertMain { | |||
| 187 | checker.dropBrokenMappings(destMappings); | 185 | checker.dropBrokenMappings(destMappings); |
| 188 | deobfuscators.dest.setMappings(destMappings); | 186 | deobfuscators.dest.setMappings(destMappings); |
| 189 | 187 | ||
| 190 | new MemberMatchingGui<FieldEntry>(classMatches, fieldMatches, deobfuscators.source, deobfuscators.dest).setSaveListener(new MemberMatchingGui.SaveListener<FieldEntry>() { | 188 | new MemberMatchingGui<>(classMatches, fieldMatches, deobfuscators.source, deobfuscators.dest).setSaveListener(new MemberMatchingGui.SaveListener<FieldEntry>() { |
| 191 | @Override | 189 | @Override |
| 192 | public void save(MemberMatches<FieldEntry> matches) { | 190 | public void save(MemberMatches<FieldEntry> matches) { |
| 193 | try { | 191 | try { |
| @@ -260,7 +258,7 @@ public class ConvertMain { | |||
| 260 | checker.dropBrokenMappings(destMappings); | 258 | checker.dropBrokenMappings(destMappings); |
| 261 | deobfuscators.dest.setMappings(destMappings); | 259 | deobfuscators.dest.setMappings(destMappings); |
| 262 | 260 | ||
| 263 | new MemberMatchingGui<BehaviorEntry>(classMatches, methodMatches, deobfuscators.source, deobfuscators.dest).setSaveListener(new MemberMatchingGui.SaveListener<BehaviorEntry>() { | 261 | new MemberMatchingGui<>(classMatches, methodMatches, deobfuscators.source, deobfuscators.dest).setSaveListener(new MemberMatchingGui.SaveListener<BehaviorEntry>() { |
| 264 | @Override | 262 | @Override |
| 265 | public void save(MemberMatches<BehaviorEntry> matches) { | 263 | public void save(MemberMatches<BehaviorEntry> matches) { |
| 266 | try { | 264 | try { |
diff --git a/src/main/java/cuchaz/enigma/Main.java b/src/main/java/cuchaz/enigma/Main.java index b135de77..d52e390a 100644 --- a/src/main/java/cuchaz/enigma/Main.java +++ b/src/main/java/cuchaz/enigma/Main.java | |||
| @@ -12,6 +12,7 @@ package cuchaz.enigma; | |||
| 12 | 12 | ||
| 13 | import java.io.File; | 13 | import java.io.File; |
| 14 | import java.util.jar.JarFile; | 14 | import java.util.jar.JarFile; |
| 15 | |||
| 15 | import javax.swing.UIManager; | 16 | import javax.swing.UIManager; |
| 16 | 17 | ||
| 17 | import cuchaz.enigma.gui.Gui; | 18 | import cuchaz.enigma.gui.Gui; |
diff --git a/src/main/java/cuchaz/enigma/MainFormatConverter.java b/src/main/java/cuchaz/enigma/MainFormatConverter.java index 29e334ec..712b0f89 100644 --- a/src/main/java/cuchaz/enigma/MainFormatConverter.java +++ b/src/main/java/cuchaz/enigma/MainFormatConverter.java | |||
| @@ -13,8 +13,6 @@ package cuchaz.enigma; | |||
| 13 | import com.google.common.collect.Maps; | 13 | import com.google.common.collect.Maps; |
| 14 | 14 | ||
| 15 | import java.io.File; | 15 | import java.io.File; |
| 16 | import java.io.FileReader; | ||
| 17 | import java.io.FileWriter; | ||
| 18 | import java.lang.reflect.Field; | 16 | import java.lang.reflect.Field; |
| 19 | import java.util.Map; | 17 | import java.util.Map; |
| 20 | import java.util.jar.JarFile; | 18 | import java.util.jar.JarFile; |
diff --git a/src/main/java/cuchaz/enigma/analysis/BehaviorReferenceTreeNode.java b/src/main/java/cuchaz/enigma/analysis/BehaviorReferenceTreeNode.java index 776f0909..39ff449e 100644 --- a/src/main/java/cuchaz/enigma/analysis/BehaviorReferenceTreeNode.java +++ b/src/main/java/cuchaz/enigma/analysis/BehaviorReferenceTreeNode.java | |||
| @@ -31,50 +31,50 @@ public class BehaviorReferenceTreeNode extends DefaultMutableTreeNode implements | |||
| 31 | private Access m_access; | 31 | private Access m_access; |
| 32 | 32 | ||
| 33 | public BehaviorReferenceTreeNode(Translator deobfuscatingTranslator, BehaviorEntry entry) { | 33 | public BehaviorReferenceTreeNode(Translator deobfuscatingTranslator, BehaviorEntry entry) { |
| 34 | m_deobfuscatingTranslator = deobfuscatingTranslator; | 34 | this.m_deobfuscatingTranslator = deobfuscatingTranslator; |
| 35 | m_entry = entry; | 35 | this.m_entry = entry; |
| 36 | m_reference = null; | 36 | this.m_reference = null; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | public BehaviorReferenceTreeNode(Translator deobfuscatingTranslator, EntryReference<BehaviorEntry, BehaviorEntry> reference, Access access) { | 39 | public BehaviorReferenceTreeNode(Translator deobfuscatingTranslator, EntryReference<BehaviorEntry, BehaviorEntry> reference, Access access) { |
| 40 | m_deobfuscatingTranslator = deobfuscatingTranslator; | 40 | this.m_deobfuscatingTranslator = deobfuscatingTranslator; |
| 41 | m_entry = reference.entry; | 41 | this.m_entry = reference.entry; |
| 42 | m_reference = reference; | 42 | this.m_reference = reference; |
| 43 | m_access = access; | 43 | this.m_access = access; |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | @Override | 46 | @Override |
| 47 | public BehaviorEntry getEntry() { | 47 | public BehaviorEntry getEntry() { |
| 48 | return m_entry; | 48 | return this.m_entry; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | @Override | 51 | @Override |
| 52 | public EntryReference<BehaviorEntry, BehaviorEntry> getReference() { | 52 | public EntryReference<BehaviorEntry, BehaviorEntry> getReference() { |
| 53 | return m_reference; | 53 | return this.m_reference; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | @Override | 56 | @Override |
| 57 | public String toString() { | 57 | public String toString() { |
| 58 | if (m_reference != null) { | 58 | if (this.m_reference != null) { |
| 59 | return String.format("%s (%s)", m_deobfuscatingTranslator.translateEntry(m_reference.context), m_access); | 59 | return String.format("%s (%s)", this.m_deobfuscatingTranslator.translateEntry(this.m_reference.context), this.m_access); |
| 60 | } | 60 | } |
| 61 | return m_deobfuscatingTranslator.translateEntry(m_entry).toString(); | 61 | return this.m_deobfuscatingTranslator.translateEntry(this.m_entry).toString(); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | public void load(JarIndex index, boolean recurse) { | 64 | public void load(JarIndex index, boolean recurse) { |
| 65 | // get all the child nodes | 65 | // get all the child nodes |
| 66 | for (EntryReference<BehaviorEntry, BehaviorEntry> reference : index.getBehaviorReferences(m_entry)) { | 66 | for (EntryReference<BehaviorEntry, BehaviorEntry> reference : index.getBehaviorReferences(this.m_entry)) { |
| 67 | add(new BehaviorReferenceTreeNode(m_deobfuscatingTranslator, reference, index.getAccess(m_entry))); | 67 | add(new BehaviorReferenceTreeNode(this.m_deobfuscatingTranslator, reference, index.getAccess(this.m_entry))); |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | if (recurse && children != null) { | 70 | if (recurse && this.children != null) { |
| 71 | for (Object child : children) { | 71 | for (Object child : this.children) { |
| 72 | if (child instanceof BehaviorReferenceTreeNode) { | 72 | if (child instanceof BehaviorReferenceTreeNode) { |
| 73 | BehaviorReferenceTreeNode node = (BehaviorReferenceTreeNode) child; | 73 | BehaviorReferenceTreeNode node = (BehaviorReferenceTreeNode) child; |
| 74 | 74 | ||
| 75 | // don't recurse into ancestor | 75 | // don't recurse into ancestor |
| 76 | Set<Entry> ancestors = Sets.newHashSet(); | 76 | Set<Entry> ancestors = Sets.newHashSet(); |
| 77 | TreeNode n = (TreeNode) node; | 77 | TreeNode n = node; |
| 78 | while (n.getParent() != null) { | 78 | while (n.getParent() != null) { |
| 79 | n = n.getParent(); | 79 | n = n.getParent(); |
| 80 | if (n instanceof BehaviorReferenceTreeNode) { | 80 | if (n instanceof BehaviorReferenceTreeNode) { |
diff --git a/src/main/java/cuchaz/enigma/analysis/BridgeMarker.java b/src/main/java/cuchaz/enigma/analysis/BridgeMarker.java index 1df76255..cd185846 100644 --- a/src/main/java/cuchaz/enigma/analysis/BridgeMarker.java +++ b/src/main/java/cuchaz/enigma/analysis/BridgeMarker.java | |||
| @@ -21,7 +21,7 @@ public class BridgeMarker { | |||
| 21 | private JarIndex m_jarIndex; | 21 | private JarIndex m_jarIndex; |
| 22 | 22 | ||
| 23 | public BridgeMarker(JarIndex jarIndex) { | 23 | public BridgeMarker(JarIndex jarIndex) { |
| 24 | m_jarIndex = jarIndex; | 24 | this.m_jarIndex = jarIndex; |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | public void markBridges(CtClass c) { | 27 | public void markBridges(CtClass c) { |
| @@ -30,7 +30,7 @@ public class BridgeMarker { | |||
| 30 | MethodEntry methodEntry = EntryFactory.getMethodEntry(method); | 30 | MethodEntry methodEntry = EntryFactory.getMethodEntry(method); |
| 31 | 31 | ||
| 32 | // is this a bridge method? | 32 | // is this a bridge method? |
| 33 | MethodEntry bridgedMethodEntry = m_jarIndex.getBridgedMethod(methodEntry); | 33 | MethodEntry bridgedMethodEntry = this.m_jarIndex.getBridgedMethod(methodEntry); |
| 34 | if (bridgedMethodEntry != null) { | 34 | if (bridgedMethodEntry != null) { |
| 35 | 35 | ||
| 36 | // it's a bridge method! add the bridge flag | 36 | // it's a bridge method! add the bridge flag |
diff --git a/src/main/java/cuchaz/enigma/analysis/ClassImplementationsTreeNode.java b/src/main/java/cuchaz/enigma/analysis/ClassImplementationsTreeNode.java index 8f8986c1..3420cd6d 100644 --- a/src/main/java/cuchaz/enigma/analysis/ClassImplementationsTreeNode.java +++ b/src/main/java/cuchaz/enigma/analysis/ClassImplementationsTreeNode.java | |||
| @@ -24,27 +24,27 @@ public class ClassImplementationsTreeNode extends DefaultMutableTreeNode { | |||
| 24 | 24 | ||
| 25 | private static final long serialVersionUID = 3112703459157851912L; | 25 | private static final long serialVersionUID = 3112703459157851912L; |
| 26 | 26 | ||
| 27 | private Translator m_deobfuscatingTranslator; | 27 | private Translator deobfuscatingTranslator; |
| 28 | private ClassEntry m_entry; | 28 | private ClassEntry entry; |
| 29 | 29 | ||
| 30 | public ClassImplementationsTreeNode(Translator deobfuscatingTranslator, ClassEntry entry) { | 30 | public ClassImplementationsTreeNode(Translator deobfuscatingTranslator, ClassEntry entry) { |
| 31 | m_deobfuscatingTranslator = deobfuscatingTranslator; | 31 | this.deobfuscatingTranslator = deobfuscatingTranslator; |
| 32 | m_entry = entry; | 32 | this.entry = entry; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | public ClassEntry getClassEntry() { | 35 | public ClassEntry getClassEntry() { |
| 36 | return m_entry; | 36 | return this.entry; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | public String getDeobfClassName() { | 39 | public String getDeobfClassName() { |
| 40 | return m_deobfuscatingTranslator.translateClass(m_entry.getClassName()); | 40 | return this.deobfuscatingTranslator.translateClass(this.entry.getClassName()); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | @Override | 43 | @Override |
| 44 | public String toString() { | 44 | public String toString() { |
| 45 | String className = getDeobfClassName(); | 45 | String className = getDeobfClassName(); |
| 46 | if (className == null) { | 46 | if (className == null) { |
| 47 | className = m_entry.getClassName(); | 47 | className = this.entry.getClassName(); |
| 48 | } | 48 | } |
| 49 | return className; | 49 | return className; |
| 50 | } | 50 | } |
| @@ -52,8 +52,8 @@ public class ClassImplementationsTreeNode extends DefaultMutableTreeNode { | |||
| 52 | public void load(JarIndex index) { | 52 | public void load(JarIndex index) { |
| 53 | // get all method implementations | 53 | // get all method implementations |
| 54 | List<ClassImplementationsTreeNode> nodes = Lists.newArrayList(); | 54 | List<ClassImplementationsTreeNode> nodes = Lists.newArrayList(); |
| 55 | for (String implementingClassName : index.getImplementingClasses(m_entry.getClassName())) { | 55 | for (String implementingClassName : index.getImplementingClasses(this.entry.getClassName())) { |
| 56 | nodes.add(new ClassImplementationsTreeNode(m_deobfuscatingTranslator, new ClassEntry(implementingClassName))); | 56 | nodes.add(new ClassImplementationsTreeNode(this.deobfuscatingTranslator, new ClassEntry(implementingClassName))); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | // add them to this node | 59 | // add them to this node |
| @@ -62,7 +62,7 @@ public class ClassImplementationsTreeNode extends DefaultMutableTreeNode { | |||
| 62 | 62 | ||
| 63 | public static ClassImplementationsTreeNode findNode(ClassImplementationsTreeNode node, MethodEntry entry) { | 63 | public static ClassImplementationsTreeNode findNode(ClassImplementationsTreeNode node, MethodEntry entry) { |
| 64 | // is this the node? | 64 | // is this the node? |
| 65 | if (node.m_entry.equals(entry)) { | 65 | if (node.entry.equals(entry)) { |
| 66 | return node; | 66 | return node; |
| 67 | } | 67 | } |
| 68 | 68 | ||
diff --git a/src/main/java/cuchaz/enigma/analysis/ClassInheritanceTreeNode.java b/src/main/java/cuchaz/enigma/analysis/ClassInheritanceTreeNode.java index ca2b8215..beac9d5d 100644 --- a/src/main/java/cuchaz/enigma/analysis/ClassInheritanceTreeNode.java +++ b/src/main/java/cuchaz/enigma/analysis/ClassInheritanceTreeNode.java | |||
| @@ -23,20 +23,20 @@ public class ClassInheritanceTreeNode extends DefaultMutableTreeNode { | |||
| 23 | 23 | ||
| 24 | private static final long serialVersionUID = 4432367405826178490L; | 24 | private static final long serialVersionUID = 4432367405826178490L; |
| 25 | 25 | ||
| 26 | private Translator m_deobfuscatingTranslator; | 26 | private Translator deobfuscatingTranslator; |
| 27 | private String m_obfClassName; | 27 | private String obfClassName; |
| 28 | 28 | ||
| 29 | public ClassInheritanceTreeNode(Translator deobfuscatingTranslator, String obfClassName) { | 29 | public ClassInheritanceTreeNode(Translator deobfuscatingTranslator, String obfClassName) { |
| 30 | m_deobfuscatingTranslator = deobfuscatingTranslator; | 30 | this.deobfuscatingTranslator = deobfuscatingTranslator; |
| 31 | m_obfClassName = obfClassName; | 31 | this.obfClassName = obfClassName; |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | public String getObfClassName() { | 34 | public String getObfClassName() { |
| 35 | return m_obfClassName; | 35 | return this.obfClassName; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | public String getDeobfClassName() { | 38 | public String getDeobfClassName() { |
| 39 | return m_deobfuscatingTranslator.translateClass(m_obfClassName); | 39 | return this.deobfuscatingTranslator.translateClass(this.obfClassName); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | @Override | 42 | @Override |
| @@ -45,14 +45,14 @@ public class ClassInheritanceTreeNode extends DefaultMutableTreeNode { | |||
| 45 | if (deobfClassName != null) { | 45 | if (deobfClassName != null) { |
| 46 | return deobfClassName; | 46 | return deobfClassName; |
| 47 | } | 47 | } |
| 48 | return m_obfClassName; | 48 | return this.obfClassName; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | public void load(TranslationIndex ancestries, boolean recurse) { | 51 | public void load(TranslationIndex ancestries, boolean recurse) { |
| 52 | // get all the child nodes | 52 | // get all the child nodes |
| 53 | List<ClassInheritanceTreeNode> nodes = Lists.newArrayList(); | 53 | List<ClassInheritanceTreeNode> nodes = Lists.newArrayList(); |
| 54 | for (ClassEntry subclassEntry : ancestries.getSubclass(new ClassEntry(m_obfClassName))) { | 54 | for (ClassEntry subclassEntry : ancestries.getSubclass(new ClassEntry(this.obfClassName))) { |
| 55 | nodes.add(new ClassInheritanceTreeNode(m_deobfuscatingTranslator, subclassEntry.getName())); | 55 | nodes.add(new ClassInheritanceTreeNode(this.deobfuscatingTranslator, subclassEntry.getName())); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | // add them to this node | 58 | // add them to this node |
diff --git a/src/main/java/cuchaz/enigma/analysis/EntryReference.java b/src/main/java/cuchaz/enigma/analysis/EntryReference.java index eb58388c..6a7a4bf0 100644 --- a/src/main/java/cuchaz/enigma/analysis/EntryReference.java +++ b/src/main/java/cuchaz/enigma/analysis/EntryReference.java | |||
| @@ -24,7 +24,7 @@ public class EntryReference<E extends Entry, C extends Entry> { | |||
| 24 | public E entry; | 24 | public E entry; |
| 25 | public C context; | 25 | public C context; |
| 26 | 26 | ||
| 27 | private boolean m_isNamed; | 27 | private boolean sourceName; |
| 28 | 28 | ||
| 29 | public EntryReference(E entry, String sourceName) { | 29 | public EntryReference(E entry, String sourceName) { |
| 30 | this(entry, sourceName, null); | 30 | this(entry, sourceName, null); |
| @@ -38,16 +38,16 @@ public class EntryReference<E extends Entry, C extends Entry> { | |||
| 38 | this.entry = entry; | 38 | this.entry = entry; |
| 39 | this.context = context; | 39 | this.context = context; |
| 40 | 40 | ||
| 41 | m_isNamed = sourceName != null && sourceName.length() > 0; | 41 | this.sourceName = sourceName != null && sourceName.length() > 0; |
| 42 | if (entry instanceof ConstructorEntry && ConstructorNonNames.contains(sourceName)) { | 42 | if (entry instanceof ConstructorEntry && ConstructorNonNames.contains(sourceName)) { |
| 43 | m_isNamed = false; | 43 | this.sourceName = false; |
| 44 | } | 44 | } |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | public EntryReference(E entry, C context, EntryReference<E, C> other) { | 47 | public EntryReference(E entry, C context, EntryReference<E, C> other) { |
| 48 | this.entry = entry; | 48 | this.entry = entry; |
| 49 | this.context = context; | 49 | this.context = context; |
| 50 | m_isNamed = other.m_isNamed; | 50 | this.sourceName = other.sourceName; |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | public ClassEntry getLocationClassEntry() { | 53 | public ClassEntry getLocationClassEntry() { |
| @@ -58,7 +58,7 @@ public class EntryReference<E extends Entry, C extends Entry> { | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | public boolean isNamed() { | 60 | public boolean isNamed() { |
| 61 | return m_isNamed; | 61 | return this.sourceName; |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | public Entry getNameableEntry() { | 64 | public Entry getNameableEntry() { |
| @@ -91,10 +91,7 @@ public class EntryReference<E extends Entry, C extends Entry> { | |||
| 91 | 91 | ||
| 92 | @Override | 92 | @Override |
| 93 | public boolean equals(Object other) { | 93 | public boolean equals(Object other) { |
| 94 | if (other instanceof EntryReference) { | 94 | return other instanceof EntryReference && equals((EntryReference<?, ?>) other); |
| 95 | return equals((EntryReference<?, ?>) other); | ||
| 96 | } | ||
| 97 | return false; | ||
| 98 | } | 95 | } |
| 99 | 96 | ||
| 100 | public boolean equals(EntryReference<?, ?> other) { | 97 | public boolean equals(EntryReference<?, ?> other) { |
diff --git a/src/main/java/cuchaz/enigma/analysis/EntryRenamer.java b/src/main/java/cuchaz/enigma/analysis/EntryRenamer.java index b99537cc..9c3d051b 100644 --- a/src/main/java/cuchaz/enigma/analysis/EntryRenamer.java +++ b/src/main/java/cuchaz/enigma/analysis/EntryRenamer.java | |||
| @@ -36,7 +36,7 @@ public class EntryRenamer { | |||
| 36 | // for each key/value pair... | 36 | // for each key/value pair... |
| 37 | Set<Map.Entry<Key, Val>> entriesToAdd = Sets.newHashSet(); | 37 | Set<Map.Entry<Key, Val>> entriesToAdd = Sets.newHashSet(); |
| 38 | for (Map.Entry<Key, Val> entry : map.entrySet()) { | 38 | for (Map.Entry<Key, Val> entry : map.entrySet()) { |
| 39 | entriesToAdd.add(new AbstractMap.SimpleEntry<Key, Val>( | 39 | entriesToAdd.add(new AbstractMap.SimpleEntry<>( |
| 40 | renameClassesInThing(renames, entry.getKey()), | 40 | renameClassesInThing(renames, entry.getKey()), |
| 41 | renameClassesInThing(renames, entry.getValue()) | 41 | renameClassesInThing(renames, entry.getValue()) |
| 42 | )); | 42 | )); |
| @@ -51,7 +51,7 @@ public class EntryRenamer { | |||
| 51 | // for each key/value pair... | 51 | // for each key/value pair... |
| 52 | Set<Map.Entry<Key, Val>> entriesToAdd = Sets.newHashSet(); | 52 | Set<Map.Entry<Key, Val>> entriesToAdd = Sets.newHashSet(); |
| 53 | for (Map.Entry<Key, Val> entry : map.entries()) { | 53 | for (Map.Entry<Key, Val> entry : map.entries()) { |
| 54 | entriesToAdd.add(new AbstractMap.SimpleEntry<Key, Val>( | 54 | entriesToAdd.add(new AbstractMap.SimpleEntry<>( |
| 55 | renameClassesInThing(renames, entry.getKey()), | 55 | renameClassesInThing(renames, entry.getKey()), |
| 56 | renameClassesInThing(renames, entry.getValue()) | 56 | renameClassesInThing(renames, entry.getValue()) |
| 57 | )); | 57 | )); |
| @@ -66,7 +66,7 @@ public class EntryRenamer { | |||
| 66 | // for each key/value pair... | 66 | // for each key/value pair... |
| 67 | Set<Map.Entry<Key, Val>> entriesToAdd = Sets.newHashSet(); | 67 | Set<Map.Entry<Key, Val>> entriesToAdd = Sets.newHashSet(); |
| 68 | for (Map.Entry<Key, Val> entry : map.entries()) { | 68 | for (Map.Entry<Key, Val> entry : map.entries()) { |
| 69 | entriesToAdd.add(new AbstractMap.SimpleEntry<Key, Val>( | 69 | entriesToAdd.add(new AbstractMap.SimpleEntry<>( |
| 70 | renameMethodsInThing(renames, entry.getKey()), | 70 | renameMethodsInThing(renames, entry.getKey()), |
| 71 | renameMethodsInThing(renames, entry.getValue()) | 71 | renameMethodsInThing(renames, entry.getValue()) |
| 72 | )); | 72 | )); |
| @@ -81,7 +81,7 @@ public class EntryRenamer { | |||
| 81 | // for each key/value pair... | 81 | // for each key/value pair... |
| 82 | Set<Map.Entry<Key, Val>> entriesToAdd = Sets.newHashSet(); | 82 | Set<Map.Entry<Key, Val>> entriesToAdd = Sets.newHashSet(); |
| 83 | for (Map.Entry<Key, Val> entry : map.entrySet()) { | 83 | for (Map.Entry<Key, Val> entry : map.entrySet()) { |
| 84 | entriesToAdd.add(new AbstractMap.SimpleEntry<Key, Val>( | 84 | entriesToAdd.add(new AbstractMap.SimpleEntry<>( |
| 85 | renameMethodsInThing(renames, entry.getKey()), | 85 | renameMethodsInThing(renames, entry.getKey()), |
| 86 | renameMethodsInThing(renames, entry.getValue()) | 86 | renameMethodsInThing(renames, entry.getValue()) |
| 87 | )); | 87 | )); |
| @@ -164,19 +164,9 @@ public class EntryRenamer { | |||
| 164 | reference.context = renameClassesInThing(renames, reference.context); | 164 | reference.context = renameClassesInThing(renames, reference.context); |
| 165 | return thing; | 165 | return thing; |
| 166 | } else if (thing instanceof Signature) { | 166 | } else if (thing instanceof Signature) { |
| 167 | return (T) new Signature((Signature) thing, new ClassNameReplacer() { | 167 | return (T) new Signature((Signature) thing, className -> renameClassesInThing(renames, className)); |
| 168 | @Override | ||
| 169 | public String replace(String className) { | ||
| 170 | return renameClassesInThing(renames, className); | ||
| 171 | } | ||
| 172 | }); | ||
| 173 | } else if (thing instanceof Type) { | 168 | } else if (thing instanceof Type) { |
| 174 | return (T) new Type((Type) thing, new ClassNameReplacer() { | 169 | return (T) new Type((Type) thing, className -> renameClassesInThing(renames, className)); |
| 175 | @Override | ||
| 176 | public String replace(String className) { | ||
| 177 | return renameClassesInThing(renames, className); | ||
| 178 | } | ||
| 179 | }); | ||
| 180 | } | 170 | } |
| 181 | 171 | ||
| 182 | return thing; | 172 | return thing; |
diff --git a/src/main/java/cuchaz/enigma/analysis/FieldReferenceTreeNode.java b/src/main/java/cuchaz/enigma/analysis/FieldReferenceTreeNode.java index 4b302e05..05d9c13f 100644 --- a/src/main/java/cuchaz/enigma/analysis/FieldReferenceTreeNode.java +++ b/src/main/java/cuchaz/enigma/analysis/FieldReferenceTreeNode.java | |||
| @@ -20,51 +20,51 @@ public class FieldReferenceTreeNode extends DefaultMutableTreeNode implements Re | |||
| 20 | 20 | ||
| 21 | private static final long serialVersionUID = -7934108091928699835L; | 21 | private static final long serialVersionUID = -7934108091928699835L; |
| 22 | 22 | ||
| 23 | private Translator m_deobfuscatingTranslator; | 23 | private Translator deobfuscatingTranslator; |
| 24 | private FieldEntry m_entry; | 24 | private FieldEntry entry; |
| 25 | private EntryReference<FieldEntry, BehaviorEntry> m_reference; | 25 | private EntryReference<FieldEntry, BehaviorEntry> reference; |
| 26 | private Access m_access; | 26 | private Access access; |
| 27 | 27 | ||
| 28 | public FieldReferenceTreeNode(Translator deobfuscatingTranslator, FieldEntry entry) { | 28 | public FieldReferenceTreeNode(Translator deobfuscatingTranslator, FieldEntry entry) { |
| 29 | m_deobfuscatingTranslator = deobfuscatingTranslator; | 29 | this.deobfuscatingTranslator = deobfuscatingTranslator; |
| 30 | m_entry = entry; | 30 | this.entry = entry; |
| 31 | m_reference = null; | 31 | this.reference = null; |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | private FieldReferenceTreeNode(Translator deobfuscatingTranslator, EntryReference<FieldEntry, BehaviorEntry> reference, Access access) { | 34 | private FieldReferenceTreeNode(Translator deobfuscatingTranslator, EntryReference<FieldEntry, BehaviorEntry> reference, Access access) { |
| 35 | m_deobfuscatingTranslator = deobfuscatingTranslator; | 35 | this.deobfuscatingTranslator = deobfuscatingTranslator; |
| 36 | m_entry = reference.entry; | 36 | this.entry = reference.entry; |
| 37 | m_reference = reference; | 37 | this.reference = reference; |
| 38 | m_access = access; | 38 | this.access = access; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | @Override | 41 | @Override |
| 42 | public FieldEntry getEntry() { | 42 | public FieldEntry getEntry() { |
| 43 | return m_entry; | 43 | return this.entry; |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | @Override | 46 | @Override |
| 47 | public EntryReference<FieldEntry, BehaviorEntry> getReference() { | 47 | public EntryReference<FieldEntry, BehaviorEntry> getReference() { |
| 48 | return m_reference; | 48 | return this.reference; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | @Override | 51 | @Override |
| 52 | public String toString() { | 52 | public String toString() { |
| 53 | if (m_reference != null) { | 53 | if (this.reference != null) { |
| 54 | return String.format("%s (%s)", m_deobfuscatingTranslator.translateEntry(m_reference.context), m_access); | 54 | return String.format("%s (%s)", this.deobfuscatingTranslator.translateEntry(this.reference.context), this.access); |
| 55 | } | 55 | } |
| 56 | return m_deobfuscatingTranslator.translateEntry(m_entry).toString(); | 56 | return this.deobfuscatingTranslator.translateEntry(this.entry).toString(); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | public void load(JarIndex index, boolean recurse) { | 59 | public void load(JarIndex index, boolean recurse) { |
| 60 | // get all the child nodes | 60 | // get all the child nodes |
| 61 | if (m_reference == null) { | 61 | if (this.reference == null) { |
| 62 | for (EntryReference<FieldEntry, BehaviorEntry> reference : index.getFieldReferences(m_entry)) { | 62 | for (EntryReference<FieldEntry, BehaviorEntry> reference : index.getFieldReferences(this.entry)) { |
| 63 | add(new FieldReferenceTreeNode(m_deobfuscatingTranslator, reference, index.getAccess(m_entry))); | 63 | add(new FieldReferenceTreeNode(this.deobfuscatingTranslator, reference, index.getAccess(this.entry))); |
| 64 | } | 64 | } |
| 65 | } else { | 65 | } else { |
| 66 | for (EntryReference<BehaviorEntry, BehaviorEntry> reference : index.getBehaviorReferences(m_reference.context)) { | 66 | for (EntryReference<BehaviorEntry, BehaviorEntry> reference : index.getBehaviorReferences(this.reference.context)) { |
| 67 | add(new BehaviorReferenceTreeNode(m_deobfuscatingTranslator, reference, index.getAccess(m_reference.context))); | 67 | add(new BehaviorReferenceTreeNode(this.deobfuscatingTranslator, reference, index.getAccess(this.reference.context))); |
| 68 | } | 68 | } |
| 69 | } | 69 | } |
| 70 | 70 | ||
diff --git a/src/main/java/cuchaz/enigma/analysis/JarClassIterator.java b/src/main/java/cuchaz/enigma/analysis/JarClassIterator.java index 17a17151..04004270 100644 --- a/src/main/java/cuchaz/enigma/analysis/JarClassIterator.java +++ b/src/main/java/cuchaz/enigma/analysis/JarClassIterator.java | |||
| @@ -31,15 +31,15 @@ import javassist.bytecode.Descriptor; | |||
| 31 | 31 | ||
| 32 | public class JarClassIterator implements Iterator<CtClass> { | 32 | public class JarClassIterator implements Iterator<CtClass> { |
| 33 | 33 | ||
| 34 | private JarFile m_jar; | 34 | private JarFile jar; |
| 35 | private Iterator<JarEntry> m_iter; | 35 | private Iterator<JarEntry> iter; |
| 36 | 36 | ||
| 37 | public JarClassIterator(JarFile jar) { | 37 | public JarClassIterator(JarFile jar) { |
| 38 | m_jar = jar; | 38 | this.jar = jar; |
| 39 | 39 | ||
| 40 | // get the jar entries that correspond to classes | 40 | // get the jar entries that correspond to classes |
| 41 | List<JarEntry> classEntries = Lists.newArrayList(); | 41 | List<JarEntry> classEntries = Lists.newArrayList(); |
| 42 | Enumeration<JarEntry> entries = m_jar.entries(); | 42 | Enumeration<JarEntry> entries = this.jar.entries(); |
| 43 | while (entries.hasMoreElements()) { | 43 | while (entries.hasMoreElements()) { |
| 44 | JarEntry entry = entries.nextElement(); | 44 | JarEntry entry = entries.nextElement(); |
| 45 | 45 | ||
| @@ -48,19 +48,19 @@ public class JarClassIterator implements Iterator<CtClass> { | |||
| 48 | classEntries.add(entry); | 48 | classEntries.add(entry); |
| 49 | } | 49 | } |
| 50 | } | 50 | } |
| 51 | m_iter = classEntries.iterator(); | 51 | this.iter = classEntries.iterator(); |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | @Override | 54 | @Override |
| 55 | public boolean hasNext() { | 55 | public boolean hasNext() { |
| 56 | return m_iter.hasNext(); | 56 | return this.iter.hasNext(); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | @Override | 59 | @Override |
| 60 | public CtClass next() { | 60 | public CtClass next() { |
| 61 | JarEntry entry = m_iter.next(); | 61 | JarEntry entry = this.iter.next(); |
| 62 | try { | 62 | try { |
| 63 | return getClass(m_jar, entry); | 63 | return getClass(this.jar, entry); |
| 64 | } catch (IOException | NotFoundException ex) { | 64 | } catch (IOException | NotFoundException ex) { |
| 65 | throw new Error("Unable to load class: " + entry.getName()); | 65 | throw new Error("Unable to load class: " + entry.getName()); |
| 66 | } | 66 | } |
| @@ -86,12 +86,7 @@ public class JarClassIterator implements Iterator<CtClass> { | |||
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | public static Iterable<CtClass> classes(final JarFile jar) { | 88 | public static Iterable<CtClass> classes(final JarFile jar) { |
| 89 | return new Iterable<CtClass>() { | 89 | return () -> new JarClassIterator(jar); |
| 90 | @Override | ||
| 91 | public Iterator<CtClass> iterator() { | ||
| 92 | return new JarClassIterator(jar); | ||
| 93 | } | ||
| 94 | }; | ||
| 95 | } | 90 | } |
| 96 | 91 | ||
| 97 | public static CtClass getClass(JarFile jar, ClassEntry classEntry) { | 92 | public static CtClass getClass(JarFile jar, ClassEntry classEntry) { |
diff --git a/src/main/java/cuchaz/enigma/analysis/JarIndex.java b/src/main/java/cuchaz/enigma/analysis/JarIndex.java index 848d8511..8b30f9eb 100644 --- a/src/main/java/cuchaz/enigma/analysis/JarIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/JarIndex.java | |||
| @@ -26,32 +26,32 @@ import javassist.expr.*; | |||
| 26 | 26 | ||
| 27 | public class JarIndex { | 27 | public class JarIndex { |
| 28 | 28 | ||
| 29 | private Set<ClassEntry> m_obfClassEntries; | 29 | private Set<ClassEntry> obfClassEntries; |
| 30 | private TranslationIndex m_translationIndex; | 30 | private TranslationIndex translationIndex; |
| 31 | private Map<Entry, Access> m_access; | 31 | private Map<Entry, Access> access; |
| 32 | private Multimap<ClassEntry, FieldEntry> m_fields; | 32 | private Multimap<ClassEntry, FieldEntry> fields; |
| 33 | private Multimap<ClassEntry, BehaviorEntry> m_behaviors; | 33 | private Multimap<ClassEntry, BehaviorEntry> behaviors; |
| 34 | private Multimap<String, MethodEntry> m_methodImplementations; | 34 | private Multimap<String, MethodEntry> methodImplementations; |
| 35 | private Multimap<BehaviorEntry, EntryReference<BehaviorEntry, BehaviorEntry>> m_behaviorReferences; | 35 | private Multimap<BehaviorEntry, EntryReference<BehaviorEntry, BehaviorEntry>> behaviorReferences; |
| 36 | private Multimap<FieldEntry, EntryReference<FieldEntry, BehaviorEntry>> m_fieldReferences; | 36 | private Multimap<FieldEntry, EntryReference<FieldEntry, BehaviorEntry>> fieldReferences; |
| 37 | private Multimap<ClassEntry, ClassEntry> m_innerClassesByOuter; | 37 | private Multimap<ClassEntry, ClassEntry> innerClassesByOuter; |
| 38 | private Map<ClassEntry, ClassEntry> m_outerClassesByInner; | 38 | private Map<ClassEntry, ClassEntry> outerClassesByInner; |
| 39 | private Map<ClassEntry, BehaviorEntry> m_anonymousClasses; | 39 | private Map<ClassEntry, BehaviorEntry> anonymousClasses; |
| 40 | private Map<MethodEntry, MethodEntry> m_bridgedMethods; | 40 | private Map<MethodEntry, MethodEntry> bridgedMethods; |
| 41 | 41 | ||
| 42 | public JarIndex() { | 42 | public JarIndex() { |
| 43 | m_obfClassEntries = Sets.newHashSet(); | 43 | this.obfClassEntries = Sets.newHashSet(); |
| 44 | m_translationIndex = new TranslationIndex(); | 44 | this.translationIndex = new TranslationIndex(); |
| 45 | m_access = Maps.newHashMap(); | 45 | this.access = Maps.newHashMap(); |
| 46 | m_fields = HashMultimap.create(); | 46 | this.fields = HashMultimap.create(); |
| 47 | m_behaviors = HashMultimap.create(); | 47 | this.behaviors = HashMultimap.create(); |
| 48 | m_methodImplementations = HashMultimap.create(); | 48 | this.methodImplementations = HashMultimap.create(); |
| 49 | m_behaviorReferences = HashMultimap.create(); | 49 | this.behaviorReferences = HashMultimap.create(); |
| 50 | m_fieldReferences = HashMultimap.create(); | 50 | this.fieldReferences = HashMultimap.create(); |
| 51 | m_innerClassesByOuter = HashMultimap.create(); | 51 | this.innerClassesByOuter = HashMultimap.create(); |
| 52 | m_outerClassesByInner = Maps.newHashMap(); | 52 | this.outerClassesByInner = Maps.newHashMap(); |
| 53 | m_anonymousClasses = Maps.newHashMap(); | 53 | this.anonymousClasses = Maps.newHashMap(); |
| 54 | m_bridgedMethods = Maps.newHashMap(); | 54 | this.bridgedMethods = Maps.newHashMap(); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | public void indexJar(JarFile jar, boolean buildInnerClasses) { | 57 | public void indexJar(JarFile jar, boolean buildInnerClasses) { |
| @@ -62,7 +62,7 @@ public class JarIndex { | |||
| 62 | // move out of default package | 62 | // move out of default package |
| 63 | classEntry = new ClassEntry(Constants.NonePackage + "/" + classEntry.getName()); | 63 | classEntry = new ClassEntry(Constants.NonePackage + "/" + classEntry.getName()); |
| 64 | } | 64 | } |
| 65 | m_obfClassEntries.add(classEntry); | 65 | this.obfClassEntries.add(classEntry); |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | // step 2: index field/method/constructor access | 68 | // step 2: index field/method/constructor access |
| @@ -70,20 +70,20 @@ public class JarIndex { | |||
| 70 | ClassRenamer.moveAllClassesOutOfDefaultPackage(c, Constants.NonePackage); | 70 | ClassRenamer.moveAllClassesOutOfDefaultPackage(c, Constants.NonePackage); |
| 71 | for (CtField field : c.getDeclaredFields()) { | 71 | for (CtField field : c.getDeclaredFields()) { |
| 72 | FieldEntry fieldEntry = EntryFactory.getFieldEntry(field); | 72 | FieldEntry fieldEntry = EntryFactory.getFieldEntry(field); |
| 73 | m_access.put(fieldEntry, Access.get(field)); | 73 | this.access.put(fieldEntry, Access.get(field)); |
| 74 | m_fields.put(fieldEntry.getClassEntry(), fieldEntry); | 74 | this.fields.put(fieldEntry.getClassEntry(), fieldEntry); |
| 75 | } | 75 | } |
| 76 | for (CtBehavior behavior : c.getDeclaredBehaviors()) { | 76 | for (CtBehavior behavior : c.getDeclaredBehaviors()) { |
| 77 | BehaviorEntry behaviorEntry = EntryFactory.getBehaviorEntry(behavior); | 77 | BehaviorEntry behaviorEntry = EntryFactory.getBehaviorEntry(behavior); |
| 78 | m_access.put(behaviorEntry, Access.get(behavior)); | 78 | this.access.put(behaviorEntry, Access.get(behavior)); |
| 79 | m_behaviors.put(behaviorEntry.getClassEntry(), behaviorEntry); | 79 | this.behaviors.put(behaviorEntry.getClassEntry(), behaviorEntry); |
| 80 | } | 80 | } |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | // step 3: index extends, implements, fields, and methods | 83 | // step 3: index extends, implements, fields, and methods |
| 84 | for (CtClass c : JarClassIterator.classes(jar)) { | 84 | for (CtClass c : JarClassIterator.classes(jar)) { |
| 85 | ClassRenamer.moveAllClassesOutOfDefaultPackage(c, Constants.NonePackage); | 85 | ClassRenamer.moveAllClassesOutOfDefaultPackage(c, Constants.NonePackage); |
| 86 | m_translationIndex.indexClass(c); | 86 | this.translationIndex.indexClass(c); |
| 87 | String className = Descriptor.toJvmName(c.getName()); | 87 | String className = Descriptor.toJvmName(c.getName()); |
| 88 | for (String interfaceName : c.getClassFile().getInterfaces()) { | 88 | for (String interfaceName : c.getClassFile().getInterfaces()) { |
| 89 | className = Descriptor.toJvmName(className); | 89 | className = Descriptor.toJvmName(className); |
| @@ -113,13 +113,13 @@ public class JarIndex { | |||
| 113 | ClassEntry innerClassEntry = EntryFactory.getClassEntry(c); | 113 | ClassEntry innerClassEntry = EntryFactory.getClassEntry(c); |
| 114 | ClassEntry outerClassEntry = findOuterClass(c); | 114 | ClassEntry outerClassEntry = findOuterClass(c); |
| 115 | if (outerClassEntry != null) { | 115 | if (outerClassEntry != null) { |
| 116 | m_innerClassesByOuter.put(outerClassEntry, innerClassEntry); | 116 | this.innerClassesByOuter.put(outerClassEntry, innerClassEntry); |
| 117 | boolean innerWasAdded = m_outerClassesByInner.put(innerClassEntry, outerClassEntry) == null; | 117 | boolean innerWasAdded = this.outerClassesByInner.put(innerClassEntry, outerClassEntry) == null; |
| 118 | assert (innerWasAdded); | 118 | assert (innerWasAdded); |
| 119 | 119 | ||
| 120 | BehaviorEntry enclosingBehavior = isAnonymousClass(c, outerClassEntry); | 120 | BehaviorEntry enclosingBehavior = isAnonymousClass(c, outerClassEntry); |
| 121 | if (enclosingBehavior != null) { | 121 | if (enclosingBehavior != null) { |
| 122 | m_anonymousClasses.put(innerClassEntry, enclosingBehavior); | 122 | this.anonymousClasses.put(innerClassEntry, enclosingBehavior); |
| 123 | 123 | ||
| 124 | // DEBUG | 124 | // DEBUG |
| 125 | //System.out.println("ANONYMOUS: " + outerClassEntry.getName() + "$" + innerClassEntry.getSimpleName()); | 125 | //System.out.println("ANONYMOUS: " + outerClassEntry.getName() + "$" + innerClassEntry.getSimpleName()); |
| @@ -132,7 +132,7 @@ public class JarIndex { | |||
| 132 | 132 | ||
| 133 | // step 6: update other indices with inner class info | 133 | // step 6: update other indices with inner class info |
| 134 | Map<String, String> renames = Maps.newHashMap(); | 134 | Map<String, String> renames = Maps.newHashMap(); |
| 135 | for (ClassEntry innerClassEntry : m_innerClassesByOuter.values()) { | 135 | for (ClassEntry innerClassEntry : this.innerClassesByOuter.values()) { |
| 136 | String newName = innerClassEntry.buildClassEntry(getObfClassChain(innerClassEntry)).getName(); | 136 | String newName = innerClassEntry.buildClassEntry(getObfClassChain(innerClassEntry)).getName(); |
| 137 | if (!innerClassEntry.getName().equals(newName)) { | 137 | if (!innerClassEntry.getName().equals(newName)) { |
| 138 | // DEBUG | 138 | // DEBUG |
| @@ -140,12 +140,12 @@ public class JarIndex { | |||
| 140 | renames.put(innerClassEntry.getName(), newName); | 140 | renames.put(innerClassEntry.getName(), newName); |
| 141 | } | 141 | } |
| 142 | } | 142 | } |
| 143 | EntryRenamer.renameClassesInSet(renames, m_obfClassEntries); | 143 | EntryRenamer.renameClassesInSet(renames, this.obfClassEntries); |
| 144 | m_translationIndex.renameClasses(renames); | 144 | this.translationIndex.renameClasses(renames); |
| 145 | EntryRenamer.renameClassesInMultimap(renames, m_methodImplementations); | 145 | EntryRenamer.renameClassesInMultimap(renames, this.methodImplementations); |
| 146 | EntryRenamer.renameClassesInMultimap(renames, m_behaviorReferences); | 146 | EntryRenamer.renameClassesInMultimap(renames, this.behaviorReferences); |
| 147 | EntryRenamer.renameClassesInMultimap(renames, m_fieldReferences); | 147 | EntryRenamer.renameClassesInMultimap(renames, this.fieldReferences); |
| 148 | EntryRenamer.renameClassesInMap(renames, m_access); | 148 | EntryRenamer.renameClassesInMap(renames, this.access); |
| 149 | } | 149 | } |
| 150 | } | 150 | } |
| 151 | 151 | ||
| @@ -156,12 +156,12 @@ public class JarIndex { | |||
| 156 | MethodEntry methodEntry = (MethodEntry) behaviorEntry; | 156 | MethodEntry methodEntry = (MethodEntry) behaviorEntry; |
| 157 | 157 | ||
| 158 | // index implementation | 158 | // index implementation |
| 159 | m_methodImplementations.put(behaviorEntry.getClassName(), methodEntry); | 159 | this.methodImplementations.put(behaviorEntry.getClassName(), methodEntry); |
| 160 | 160 | ||
| 161 | // look for bridge and bridged methods | 161 | // look for bridge and bridged methods |
| 162 | CtMethod bridgedMethod = getBridgedMethod((CtMethod) behavior); | 162 | CtMethod bridgedMethod = getBridgedMethod((CtMethod) behavior); |
| 163 | if (bridgedMethod != null) { | 163 | if (bridgedMethod != null) { |
| 164 | m_bridgedMethods.put(methodEntry, EntryFactory.getMethodEntry(bridgedMethod)); | 164 | this.bridgedMethods.put(methodEntry, EntryFactory.getMethodEntry(bridgedMethod)); |
| 165 | } | 165 | } |
| 166 | } | 166 | } |
| 167 | // looks like we don't care about constructors here | 167 | // looks like we don't care about constructors here |
| @@ -175,7 +175,7 @@ public class JarIndex { | |||
| 175 | @Override | 175 | @Override |
| 176 | public void edit(MethodCall call) { | 176 | public void edit(MethodCall call) { |
| 177 | MethodEntry calledMethodEntry = EntryFactory.getMethodEntry(call); | 177 | MethodEntry calledMethodEntry = EntryFactory.getMethodEntry(call); |
| 178 | ClassEntry resolvedClassEntry = m_translationIndex.resolveEntryClass(calledMethodEntry); | 178 | ClassEntry resolvedClassEntry = translationIndex.resolveEntryClass(calledMethodEntry); |
| 179 | if (resolvedClassEntry != null && !resolvedClassEntry.equals(calledMethodEntry.getClassEntry())) { | 179 | if (resolvedClassEntry != null && !resolvedClassEntry.equals(calledMethodEntry.getClassEntry())) { |
| 180 | calledMethodEntry = new MethodEntry( | 180 | calledMethodEntry = new MethodEntry( |
| 181 | resolvedClassEntry, | 181 | resolvedClassEntry, |
| @@ -188,13 +188,13 @@ public class JarIndex { | |||
| 188 | call.getMethodName(), | 188 | call.getMethodName(), |
| 189 | behaviorEntry | 189 | behaviorEntry |
| 190 | ); | 190 | ); |
| 191 | m_behaviorReferences.put(calledMethodEntry, reference); | 191 | behaviorReferences.put(calledMethodEntry, reference); |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | @Override | 194 | @Override |
| 195 | public void edit(FieldAccess call) { | 195 | public void edit(FieldAccess call) { |
| 196 | FieldEntry calledFieldEntry = EntryFactory.getFieldEntry(call); | 196 | FieldEntry calledFieldEntry = EntryFactory.getFieldEntry(call); |
| 197 | ClassEntry resolvedClassEntry = m_translationIndex.resolveEntryClass(calledFieldEntry); | 197 | ClassEntry resolvedClassEntry = translationIndex.resolveEntryClass(calledFieldEntry); |
| 198 | if (resolvedClassEntry != null && !resolvedClassEntry.equals(calledFieldEntry.getClassEntry())) { | 198 | if (resolvedClassEntry != null && !resolvedClassEntry.equals(calledFieldEntry.getClassEntry())) { |
| 199 | calledFieldEntry = new FieldEntry(calledFieldEntry, resolvedClassEntry); | 199 | calledFieldEntry = new FieldEntry(calledFieldEntry, resolvedClassEntry); |
| 200 | } | 200 | } |
| @@ -203,7 +203,7 @@ public class JarIndex { | |||
| 203 | call.getFieldName(), | 203 | call.getFieldName(), |
| 204 | behaviorEntry | 204 | behaviorEntry |
| 205 | ); | 205 | ); |
| 206 | m_fieldReferences.put(calledFieldEntry, reference); | 206 | fieldReferences.put(calledFieldEntry, reference); |
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | @Override | 209 | @Override |
| @@ -214,7 +214,7 @@ public class JarIndex { | |||
| 214 | call.getMethodName(), | 214 | call.getMethodName(), |
| 215 | behaviorEntry | 215 | behaviorEntry |
| 216 | ); | 216 | ); |
| 217 | m_behaviorReferences.put(calledConstructorEntry, reference); | 217 | behaviorReferences.put(calledConstructorEntry, reference); |
| 218 | } | 218 | } |
| 219 | 219 | ||
| 220 | @Override | 220 | @Override |
| @@ -225,7 +225,7 @@ public class JarIndex { | |||
| 225 | call.getClassName(), | 225 | call.getClassName(), |
| 226 | behaviorEntry | 226 | behaviorEntry |
| 227 | ); | 227 | ); |
| 228 | m_behaviorReferences.put(calledConstructorEntry, reference); | 228 | behaviorReferences.put(calledConstructorEntry, reference); |
| 229 | } | 229 | } |
| 230 | }); | 230 | }); |
| 231 | } catch (CannotCompileException ex) { | 231 | } catch (CannotCompileException ex) { |
| @@ -314,7 +314,7 @@ public class JarIndex { | |||
| 314 | 314 | ||
| 315 | // is the entry a superclass of the context? | 315 | // is the entry a superclass of the context? |
| 316 | ClassEntry calledClassEntry = reference.entry.getClassEntry(); | 316 | ClassEntry calledClassEntry = reference.entry.getClassEntry(); |
| 317 | ClassEntry superclassEntry = m_translationIndex.getSuperclass(reference.context.getClassEntry()); | 317 | ClassEntry superclassEntry = this.translationIndex.getSuperclass(reference.context.getClassEntry()); |
| 318 | if (superclassEntry != null && superclassEntry.equals(calledClassEntry)) { | 318 | if (superclassEntry != null && superclassEntry.equals(calledClassEntry)) { |
| 319 | // it's a super call, skip | 319 | // it's a super call, skip |
| 320 | continue; | 320 | continue; |
| @@ -360,7 +360,7 @@ public class JarIndex { | |||
| 360 | } | 360 | } |
| 361 | 361 | ||
| 362 | // is the outer class in the jar? | 362 | // is the outer class in the jar? |
| 363 | return m_obfClassEntries.contains(outerClassEntry); | 363 | return this.obfClassEntries.contains(outerClassEntry); |
| 364 | 364 | ||
| 365 | } | 365 | } |
| 366 | 366 | ||
| @@ -500,31 +500,31 @@ public class JarIndex { | |||
| 500 | } | 500 | } |
| 501 | 501 | ||
| 502 | public Set<ClassEntry> getObfClassEntries() { | 502 | public Set<ClassEntry> getObfClassEntries() { |
| 503 | return m_obfClassEntries; | 503 | return this.obfClassEntries; |
| 504 | } | 504 | } |
| 505 | 505 | ||
| 506 | public Collection<FieldEntry> getObfFieldEntries() { | 506 | public Collection<FieldEntry> getObfFieldEntries() { |
| 507 | return m_fields.values(); | 507 | return this.fields.values(); |
| 508 | } | 508 | } |
| 509 | 509 | ||
| 510 | public Collection<FieldEntry> getObfFieldEntries(ClassEntry classEntry) { | 510 | public Collection<FieldEntry> getObfFieldEntries(ClassEntry classEntry) { |
| 511 | return m_fields.get(classEntry); | 511 | return this.fields.get(classEntry); |
| 512 | } | 512 | } |
| 513 | 513 | ||
| 514 | public Collection<BehaviorEntry> getObfBehaviorEntries() { | 514 | public Collection<BehaviorEntry> getObfBehaviorEntries() { |
| 515 | return m_behaviors.values(); | 515 | return this.behaviors.values(); |
| 516 | } | 516 | } |
| 517 | 517 | ||
| 518 | public Collection<BehaviorEntry> getObfBehaviorEntries(ClassEntry classEntry) { | 518 | public Collection<BehaviorEntry> getObfBehaviorEntries(ClassEntry classEntry) { |
| 519 | return m_behaviors.get(classEntry); | 519 | return this.behaviors.get(classEntry); |
| 520 | } | 520 | } |
| 521 | 521 | ||
| 522 | public TranslationIndex getTranslationIndex() { | 522 | public TranslationIndex getTranslationIndex() { |
| 523 | return m_translationIndex; | 523 | return this.translationIndex; |
| 524 | } | 524 | } |
| 525 | 525 | ||
| 526 | public Access getAccess(Entry entry) { | 526 | public Access getAccess(Entry entry) { |
| 527 | return m_access.get(entry); | 527 | return this.access.get(entry); |
| 528 | } | 528 | } |
| 529 | 529 | ||
| 530 | public ClassInheritanceTreeNode getClassInheritance(Translator deobfuscatingTranslator, ClassEntry obfClassEntry) { | 530 | public ClassInheritanceTreeNode getClassInheritance(Translator deobfuscatingTranslator, ClassEntry obfClassEntry) { |
| @@ -532,7 +532,7 @@ public class JarIndex { | |||
| 532 | // get the root node | 532 | // get the root node |
| 533 | List<String> ancestry = Lists.newArrayList(); | 533 | List<String> ancestry = Lists.newArrayList(); |
| 534 | ancestry.add(obfClassEntry.getName()); | 534 | ancestry.add(obfClassEntry.getName()); |
| 535 | for (ClassEntry classEntry : m_translationIndex.getAncestry(obfClassEntry)) { | 535 | for (ClassEntry classEntry : this.translationIndex.getAncestry(obfClassEntry)) { |
| 536 | if (containsObfClass(classEntry)) { | 536 | if (containsObfClass(classEntry)) { |
| 537 | ancestry.add(classEntry.getName()); | 537 | ancestry.add(classEntry.getName()); |
| 538 | } | 538 | } |
| @@ -543,7 +543,7 @@ public class JarIndex { | |||
| 543 | ); | 543 | ); |
| 544 | 544 | ||
| 545 | // expand all children recursively | 545 | // expand all children recursively |
| 546 | rootNode.load(m_translationIndex, true); | 546 | rootNode.load(this.translationIndex, true); |
| 547 | 547 | ||
| 548 | return rootNode; | 548 | return rootNode; |
| 549 | } | 549 | } |
| @@ -563,7 +563,7 @@ public class JarIndex { | |||
| 563 | 563 | ||
| 564 | // travel to the ancestor implementation | 564 | // travel to the ancestor implementation |
| 565 | ClassEntry baseImplementationClassEntry = obfMethodEntry.getClassEntry(); | 565 | ClassEntry baseImplementationClassEntry = obfMethodEntry.getClassEntry(); |
| 566 | for (ClassEntry ancestorClassEntry : m_translationIndex.getAncestry(obfMethodEntry.getClassEntry())) { | 566 | for (ClassEntry ancestorClassEntry : this.translationIndex.getAncestry(obfMethodEntry.getClassEntry())) { |
| 567 | MethodEntry ancestorMethodEntry = new MethodEntry( | 567 | MethodEntry ancestorMethodEntry = new MethodEntry( |
| 568 | new ClassEntry(ancestorClassEntry), | 568 | new ClassEntry(ancestorClassEntry), |
| 569 | obfMethodEntry.getName(), | 569 | obfMethodEntry.getName(), |
| @@ -664,13 +664,13 @@ public class JarIndex { | |||
| 664 | } | 664 | } |
| 665 | 665 | ||
| 666 | public Collection<EntryReference<FieldEntry, BehaviorEntry>> getFieldReferences(FieldEntry fieldEntry) { | 666 | public Collection<EntryReference<FieldEntry, BehaviorEntry>> getFieldReferences(FieldEntry fieldEntry) { |
| 667 | return m_fieldReferences.get(fieldEntry); | 667 | return this.fieldReferences.get(fieldEntry); |
| 668 | } | 668 | } |
| 669 | 669 | ||
| 670 | public Collection<FieldEntry> getReferencedFields(BehaviorEntry behaviorEntry) { | 670 | public Collection<FieldEntry> getReferencedFields(BehaviorEntry behaviorEntry) { |
| 671 | // linear search is fast enough for now | 671 | // linear search is fast enough for now |
| 672 | Set<FieldEntry> fieldEntries = Sets.newHashSet(); | 672 | Set<FieldEntry> fieldEntries = Sets.newHashSet(); |
| 673 | for (EntryReference<FieldEntry, BehaviorEntry> reference : m_fieldReferences.values()) { | 673 | for (EntryReference<FieldEntry, BehaviorEntry> reference : this.fieldReferences.values()) { |
| 674 | if (reference.context == behaviorEntry) { | 674 | if (reference.context == behaviorEntry) { |
| 675 | fieldEntries.add(reference.entry); | 675 | fieldEntries.add(reference.entry); |
| 676 | } | 676 | } |
| @@ -679,13 +679,13 @@ public class JarIndex { | |||
| 679 | } | 679 | } |
| 680 | 680 | ||
| 681 | public Collection<EntryReference<BehaviorEntry, BehaviorEntry>> getBehaviorReferences(BehaviorEntry behaviorEntry) { | 681 | public Collection<EntryReference<BehaviorEntry, BehaviorEntry>> getBehaviorReferences(BehaviorEntry behaviorEntry) { |
| 682 | return m_behaviorReferences.get(behaviorEntry); | 682 | return this.behaviorReferences.get(behaviorEntry); |
| 683 | } | 683 | } |
| 684 | 684 | ||
| 685 | public Collection<BehaviorEntry> getReferencedBehaviors(BehaviorEntry behaviorEntry) { | 685 | public Collection<BehaviorEntry> getReferencedBehaviors(BehaviorEntry behaviorEntry) { |
| 686 | // linear search is fast enough for now | 686 | // linear search is fast enough for now |
| 687 | Set<BehaviorEntry> behaviorEntries = Sets.newHashSet(); | 687 | Set<BehaviorEntry> behaviorEntries = Sets.newHashSet(); |
| 688 | for (EntryReference<BehaviorEntry, BehaviorEntry> reference : m_behaviorReferences.values()) { | 688 | for (EntryReference<BehaviorEntry, BehaviorEntry> reference : this.behaviorReferences.values()) { |
| 689 | if (reference.context == behaviorEntry) { | 689 | if (reference.context == behaviorEntry) { |
| 690 | behaviorEntries.add(reference.entry); | 690 | behaviorEntries.add(reference.entry); |
| 691 | } | 691 | } |
| @@ -694,27 +694,27 @@ public class JarIndex { | |||
| 694 | } | 694 | } |
| 695 | 695 | ||
| 696 | public Collection<ClassEntry> getInnerClasses(ClassEntry obfOuterClassEntry) { | 696 | public Collection<ClassEntry> getInnerClasses(ClassEntry obfOuterClassEntry) { |
| 697 | return m_innerClassesByOuter.get(obfOuterClassEntry); | 697 | return this.innerClassesByOuter.get(obfOuterClassEntry); |
| 698 | } | 698 | } |
| 699 | 699 | ||
| 700 | public ClassEntry getOuterClass(ClassEntry obfInnerClassEntry) { | 700 | public ClassEntry getOuterClass(ClassEntry obfInnerClassEntry) { |
| 701 | return m_outerClassesByInner.get(obfInnerClassEntry); | 701 | return this.outerClassesByInner.get(obfInnerClassEntry); |
| 702 | } | 702 | } |
| 703 | 703 | ||
| 704 | public boolean isAnonymousClass(ClassEntry obfInnerClassEntry) { | 704 | public boolean isAnonymousClass(ClassEntry obfInnerClassEntry) { |
| 705 | return m_anonymousClasses.containsKey(obfInnerClassEntry); | 705 | return this.anonymousClasses.containsKey(obfInnerClassEntry); |
| 706 | } | 706 | } |
| 707 | 707 | ||
| 708 | public BehaviorEntry getAnonymousClassCaller(ClassEntry obfInnerClassName) { | 708 | public BehaviorEntry getAnonymousClassCaller(ClassEntry obfInnerClassName) { |
| 709 | return m_anonymousClasses.get(obfInnerClassName); | 709 | return this.anonymousClasses.get(obfInnerClassName); |
| 710 | } | 710 | } |
| 711 | 711 | ||
| 712 | public Set<ClassEntry> getInterfaces(String className) { | 712 | public Set<ClassEntry> getInterfaces(String className) { |
| 713 | ClassEntry classEntry = new ClassEntry(className); | 713 | ClassEntry classEntry = new ClassEntry(className); |
| 714 | Set<ClassEntry> interfaces = new HashSet<ClassEntry>(); | 714 | Set<ClassEntry> interfaces = new HashSet<ClassEntry>(); |
| 715 | interfaces.addAll(m_translationIndex.getInterfaces(classEntry)); | 715 | interfaces.addAll(this.translationIndex.getInterfaces(classEntry)); |
| 716 | for (ClassEntry ancestor : m_translationIndex.getAncestry(classEntry)) { | 716 | for (ClassEntry ancestor : this.translationIndex.getAncestry(classEntry)) { |
| 717 | interfaces.addAll(m_translationIndex.getInterfaces(ancestor)); | 717 | interfaces.addAll(this.translationIndex.getInterfaces(ancestor)); |
| 718 | } | 718 | } |
| 719 | return interfaces; | 719 | return interfaces; |
| 720 | } | 720 | } |
| @@ -723,31 +723,31 @@ public class JarIndex { | |||
| 723 | 723 | ||
| 724 | // linear search is fast enough for now | 724 | // linear search is fast enough for now |
| 725 | Set<String> classNames = Sets.newHashSet(); | 725 | Set<String> classNames = Sets.newHashSet(); |
| 726 | for (Map.Entry<ClassEntry, ClassEntry> entry : m_translationIndex.getClassInterfaces()) { | 726 | for (Map.Entry<ClassEntry, ClassEntry> entry : this.translationIndex.getClassInterfaces()) { |
| 727 | ClassEntry classEntry = entry.getKey(); | 727 | ClassEntry classEntry = entry.getKey(); |
| 728 | ClassEntry interfaceEntry = entry.getValue(); | 728 | ClassEntry interfaceEntry = entry.getValue(); |
| 729 | if (interfaceEntry.getName().equals(targetInterfaceName)) { | 729 | if (interfaceEntry.getName().equals(targetInterfaceName)) { |
| 730 | classNames.add(classEntry.getClassName()); | 730 | classNames.add(classEntry.getClassName()); |
| 731 | m_translationIndex.getSubclassNamesRecursively(classNames, classEntry); | 731 | this.translationIndex.getSubclassNamesRecursively(classNames, classEntry); |
| 732 | } | 732 | } |
| 733 | } | 733 | } |
| 734 | return classNames; | 734 | return classNames; |
| 735 | } | 735 | } |
| 736 | 736 | ||
| 737 | public boolean isInterface(String className) { | 737 | public boolean isInterface(String className) { |
| 738 | return m_translationIndex.isInterface(new ClassEntry(className)); | 738 | return this.translationIndex.isInterface(new ClassEntry(className)); |
| 739 | } | 739 | } |
| 740 | 740 | ||
| 741 | public boolean containsObfClass(ClassEntry obfClassEntry) { | 741 | public boolean containsObfClass(ClassEntry obfClassEntry) { |
| 742 | return m_obfClassEntries.contains(obfClassEntry); | 742 | return this.obfClassEntries.contains(obfClassEntry); |
| 743 | } | 743 | } |
| 744 | 744 | ||
| 745 | public boolean containsObfField(FieldEntry obfFieldEntry) { | 745 | public boolean containsObfField(FieldEntry obfFieldEntry) { |
| 746 | return m_access.containsKey(obfFieldEntry); | 746 | return this.access.containsKey(obfFieldEntry); |
| 747 | } | 747 | } |
| 748 | 748 | ||
| 749 | public boolean containsObfBehavior(BehaviorEntry obfBehaviorEntry) { | 749 | public boolean containsObfBehavior(BehaviorEntry obfBehaviorEntry) { |
| 750 | return m_access.containsKey(obfBehaviorEntry); | 750 | return this.access.containsKey(obfBehaviorEntry); |
| 751 | } | 751 | } |
| 752 | 752 | ||
| 753 | public boolean containsObfArgument(ArgumentEntry obfArgumentEntry) { | 753 | public boolean containsObfArgument(ArgumentEntry obfArgumentEntry) { |
| @@ -776,7 +776,7 @@ public class JarIndex { | |||
| 776 | } | 776 | } |
| 777 | 777 | ||
| 778 | public MethodEntry getBridgedMethod(MethodEntry bridgeMethodEntry) { | 778 | public MethodEntry getBridgedMethod(MethodEntry bridgeMethodEntry) { |
| 779 | return m_bridgedMethods.get(bridgeMethodEntry); | 779 | return this.bridgedMethods.get(bridgeMethodEntry); |
| 780 | } | 780 | } |
| 781 | 781 | ||
| 782 | public List<ClassEntry> getObfClassChain(ClassEntry obfClassEntry) { | 782 | public List<ClassEntry> getObfClassChain(ClassEntry obfClassEntry) { |
diff --git a/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java b/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java index 2ee3ec1f..1cf80d91 100644 --- a/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java +++ b/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java | |||
| @@ -24,40 +24,40 @@ public class MethodImplementationsTreeNode extends DefaultMutableTreeNode { | |||
| 24 | 24 | ||
| 25 | private static final long serialVersionUID = 3781080657461899915L; | 25 | private static final long serialVersionUID = 3781080657461899915L; |
| 26 | 26 | ||
| 27 | private Translator m_deobfuscatingTranslator; | 27 | private Translator deobfuscatingTranslator; |
| 28 | private MethodEntry m_entry; | 28 | private MethodEntry entry; |
| 29 | 29 | ||
| 30 | public MethodImplementationsTreeNode(Translator deobfuscatingTranslator, MethodEntry entry) { | 30 | public MethodImplementationsTreeNode(Translator deobfuscatingTranslator, MethodEntry entry) { |
| 31 | if (entry == null) { | 31 | if (entry == null) { |
| 32 | throw new IllegalArgumentException("entry cannot be null!"); | 32 | throw new IllegalArgumentException("Entry cannot be null!"); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | m_deobfuscatingTranslator = deobfuscatingTranslator; | 35 | this.deobfuscatingTranslator = deobfuscatingTranslator; |
| 36 | m_entry = entry; | 36 | this.entry = entry; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | public MethodEntry getMethodEntry() { | 39 | public MethodEntry getMethodEntry() { |
| 40 | return m_entry; | 40 | return this.entry; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | public String getDeobfClassName() { | 43 | public String getDeobfClassName() { |
| 44 | return m_deobfuscatingTranslator.translateClass(m_entry.getClassName()); | 44 | return this.deobfuscatingTranslator.translateClass(this.entry.getClassName()); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | public String getDeobfMethodName() { | 47 | public String getDeobfMethodName() { |
| 48 | return m_deobfuscatingTranslator.translate(m_entry); | 48 | return this.deobfuscatingTranslator.translate(this.entry); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | @Override | 51 | @Override |
| 52 | public String toString() { | 52 | public String toString() { |
| 53 | String className = getDeobfClassName(); | 53 | String className = getDeobfClassName(); |
| 54 | if (className == null) { | 54 | if (className == null) { |
| 55 | className = m_entry.getClassName(); | 55 | className = this.entry.getClassName(); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | String methodName = getDeobfMethodName(); | 58 | String methodName = getDeobfMethodName(); |
| 59 | if (methodName == null) { | 59 | if (methodName == null) { |
| 60 | methodName = m_entry.getName(); | 60 | methodName = this.entry.getName(); |
| 61 | } | 61 | } |
| 62 | return className + "." + methodName + "()"; | 62 | return className + "." + methodName + "()"; |
| 63 | } | 63 | } |
| @@ -66,14 +66,11 @@ public class MethodImplementationsTreeNode extends DefaultMutableTreeNode { | |||
| 66 | 66 | ||
| 67 | // get all method implementations | 67 | // get all method implementations |
| 68 | List<MethodImplementationsTreeNode> nodes = Lists.newArrayList(); | 68 | List<MethodImplementationsTreeNode> nodes = Lists.newArrayList(); |
| 69 | for (String implementingClassName : index.getImplementingClasses(m_entry.getClassName())) { | 69 | for (String implementingClassName : index.getImplementingClasses(this.entry.getClassName())) { |
| 70 | MethodEntry methodEntry = new MethodEntry( | 70 | MethodEntry methodEntry = new MethodEntry(new ClassEntry(implementingClassName), this.entry.getName(), this.entry.getSignature() |
| 71 | new ClassEntry(implementingClassName), | ||
| 72 | m_entry.getName(), | ||
| 73 | m_entry.getSignature() | ||
| 74 | ); | 71 | ); |
| 75 | if (index.containsObfBehavior(methodEntry)) { | 72 | if (index.containsObfBehavior(methodEntry)) { |
| 76 | nodes.add(new MethodImplementationsTreeNode(m_deobfuscatingTranslator, methodEntry)); | 73 | nodes.add(new MethodImplementationsTreeNode(this.deobfuscatingTranslator, methodEntry)); |
| 77 | } | 74 | } |
| 78 | } | 75 | } |
| 79 | 76 | ||
diff --git a/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java b/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java index cf42ac77..a3bed6ed 100644 --- a/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java +++ b/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java | |||
| @@ -24,45 +24,45 @@ public class MethodInheritanceTreeNode extends DefaultMutableTreeNode { | |||
| 24 | 24 | ||
| 25 | private static final long serialVersionUID = 1096677030991810007L; | 25 | private static final long serialVersionUID = 1096677030991810007L; |
| 26 | 26 | ||
| 27 | private Translator m_deobfuscatingTranslator; | 27 | private Translator deobfuscatingTranslator; |
| 28 | private MethodEntry m_entry; | 28 | private MethodEntry entry; |
| 29 | private boolean m_isImplemented; | 29 | private boolean isImplemented; |
| 30 | 30 | ||
| 31 | public MethodInheritanceTreeNode(Translator deobfuscatingTranslator, MethodEntry entry, boolean isImplemented) { | 31 | public MethodInheritanceTreeNode(Translator deobfuscatingTranslator, MethodEntry entry, boolean isImplemented) { |
| 32 | m_deobfuscatingTranslator = deobfuscatingTranslator; | 32 | this.deobfuscatingTranslator = deobfuscatingTranslator; |
| 33 | m_entry = entry; | 33 | this.entry = entry; |
| 34 | m_isImplemented = isImplemented; | 34 | this.isImplemented = isImplemented; |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | public MethodEntry getMethodEntry() { | 37 | public MethodEntry getMethodEntry() { |
| 38 | return m_entry; | 38 | return this.entry; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | public String getDeobfClassName() { | 41 | public String getDeobfClassName() { |
| 42 | return m_deobfuscatingTranslator.translateClass(m_entry.getClassName()); | 42 | return this.deobfuscatingTranslator.translateClass(this.entry.getClassName()); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | public String getDeobfMethodName() { | 45 | public String getDeobfMethodName() { |
| 46 | return m_deobfuscatingTranslator.translate(m_entry); | 46 | return this.deobfuscatingTranslator.translate(this.entry); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | public boolean isImplemented() { | 49 | public boolean isImplemented() { |
| 50 | return m_isImplemented; | 50 | return this.isImplemented; |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | @Override | 53 | @Override |
| 54 | public String toString() { | 54 | public String toString() { |
| 55 | String className = getDeobfClassName(); | 55 | String className = getDeobfClassName(); |
| 56 | if (className == null) { | 56 | if (className == null) { |
| 57 | className = m_entry.getClassName(); | 57 | className = this.entry.getClassName(); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | if (!m_isImplemented) { | 60 | if (!this.isImplemented) { |
| 61 | return className; | 61 | return className; |
| 62 | } else { | 62 | } else { |
| 63 | String methodName = getDeobfMethodName(); | 63 | String methodName = getDeobfMethodName(); |
| 64 | if (methodName == null) { | 64 | if (methodName == null) { |
| 65 | methodName = m_entry.getName(); | 65 | methodName = this.entry.getName(); |
| 66 | } | 66 | } |
| 67 | return className + "." + methodName + "()"; | 67 | return className + "." + methodName + "()"; |
| 68 | } | 68 | } |
| @@ -71,16 +71,10 @@ public class MethodInheritanceTreeNode extends DefaultMutableTreeNode { | |||
| 71 | public void load(JarIndex index, boolean recurse) { | 71 | public void load(JarIndex index, boolean recurse) { |
| 72 | // get all the child nodes | 72 | // get all the child nodes |
| 73 | List<MethodInheritanceTreeNode> nodes = Lists.newArrayList(); | 73 | List<MethodInheritanceTreeNode> nodes = Lists.newArrayList(); |
| 74 | for (ClassEntry subclassEntry : index.getTranslationIndex().getSubclass(m_entry.getClassEntry())) { | 74 | for (ClassEntry subclassEntry : index.getTranslationIndex().getSubclass(this.entry.getClassEntry())) { |
| 75 | MethodEntry methodEntry = new MethodEntry( | 75 | MethodEntry methodEntry = new MethodEntry(subclassEntry, this.entry.getName(), this.entry.getSignature() |
| 76 | subclassEntry, | ||
| 77 | m_entry.getName(), | ||
| 78 | m_entry.getSignature() | ||
| 79 | ); | 76 | ); |
| 80 | nodes.add(new MethodInheritanceTreeNode( | 77 | nodes.add(new MethodInheritanceTreeNode(this.deobfuscatingTranslator, methodEntry, index.containsObfBehavior(methodEntry) |
| 81 | m_deobfuscatingTranslator, | ||
| 82 | methodEntry, | ||
| 83 | index.containsObfBehavior(methodEntry) | ||
| 84 | )); | 78 | )); |
| 85 | } | 79 | } |
| 86 | 80 | ||
diff --git a/src/main/java/cuchaz/enigma/analysis/SourceIndex.java b/src/main/java/cuchaz/enigma/analysis/SourceIndex.java index a20fbb44..cbc2945c 100644 --- a/src/main/java/cuchaz/enigma/analysis/SourceIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/SourceIndex.java | |||
| @@ -28,36 +28,36 @@ import cuchaz.enigma.mapping.Entry; | |||
| 28 | 28 | ||
| 29 | public class SourceIndex { | 29 | public class SourceIndex { |
| 30 | 30 | ||
| 31 | private String m_source; | 31 | private String source; |
| 32 | private TreeMap<Token, EntryReference<Entry, Entry>> m_tokenToReference; | 32 | private TreeMap<Token, EntryReference<Entry, Entry>> tokenToReference; |
| 33 | private Multimap<EntryReference<Entry, Entry>, Token> m_referenceToTokens; | 33 | private Multimap<EntryReference<Entry, Entry>, Token> referenceToTokens; |
| 34 | private Map<Entry, Token> m_declarationToToken; | 34 | private Map<Entry, Token> declarationToToken; |
| 35 | private List<Integer> m_lineOffsets; | 35 | private List<Integer> lineOffsets; |
| 36 | private boolean m_ignoreBadTokens; | 36 | private boolean ignoreBadTokens; |
| 37 | 37 | ||
| 38 | public SourceIndex(String source) { | 38 | public SourceIndex(String source) { |
| 39 | this(source, true); | 39 | this(source, true); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | public SourceIndex(String source, boolean ignoreBadTokens) { | 42 | public SourceIndex(String source, boolean ignoreBadTokens) { |
| 43 | m_source = source; | 43 | this.source = source; |
| 44 | m_ignoreBadTokens = ignoreBadTokens; | 44 | this.ignoreBadTokens = ignoreBadTokens; |
| 45 | m_tokenToReference = Maps.newTreeMap(); | 45 | this.tokenToReference = Maps.newTreeMap(); |
| 46 | m_referenceToTokens = HashMultimap.create(); | 46 | this.referenceToTokens = HashMultimap.create(); |
| 47 | m_declarationToToken = Maps.newHashMap(); | 47 | this.declarationToToken = Maps.newHashMap(); |
| 48 | m_lineOffsets = Lists.newArrayList(); | 48 | this.lineOffsets = Lists.newArrayList(); |
| 49 | 49 | ||
| 50 | // count the lines | 50 | // count the lines |
| 51 | m_lineOffsets.add(0); | 51 | this.lineOffsets.add(0); |
| 52 | for (int i = 0; i < source.length(); i++) { | 52 | for (int i = 0; i < source.length(); i++) { |
| 53 | if (source.charAt(i) == '\n') { | 53 | if (source.charAt(i) == '\n') { |
| 54 | m_lineOffsets.add(i + 1); | 54 | this.lineOffsets.add(i + 1); |
| 55 | } | 55 | } |
| 56 | } | 56 | } |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | public String getSource() { | 59 | public String getSource() { |
| 60 | return m_source; | 60 | return this.source; |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | public Token getToken(AstNode node) { | 63 | public Token getToken(AstNode node) { |
| @@ -75,11 +75,7 @@ public class SourceIndex { | |||
| 75 | System.err.println(String.format("WARNING: %s \"%s\" has invalid region: %s", node.getNodeType(), name, region)); | 75 | System.err.println(String.format("WARNING: %s \"%s\" has invalid region: %s", node.getNodeType(), name, region)); |
| 76 | return null; | 76 | return null; |
| 77 | } | 77 | } |
| 78 | Token token = new Token( | 78 | Token token = new Token(toPos(region.getBeginLine(), region.getBeginColumn()), toPos(region.getEndLine(), region.getEndColumn()), this.source); |
| 79 | toPos(region.getBeginLine(), region.getBeginColumn()), | ||
| 80 | toPos(region.getEndLine(), region.getEndColumn()), | ||
| 81 | m_source | ||
| 82 | ); | ||
| 83 | if (token.start == 0) { | 79 | if (token.start == 0) { |
| 84 | // DEBUG | 80 | // DEBUG |
| 85 | System.err.println(String.format("WARNING: %s \"%s\" has invalid start: %s", node.getNodeType(), name, region)); | 81 | System.err.println(String.format("WARNING: %s \"%s\" has invalid start: %s", node.getNodeType(), name, region)); |
| @@ -90,7 +86,7 @@ public class SourceIndex { | |||
| 90 | // System.out.println( String.format( "%s \"%s\" region: %s", node.getNodeType(), name, region ) ); | 86 | // System.out.println( String.format( "%s \"%s\" region: %s", node.getNodeType(), name, region ) ); |
| 91 | 87 | ||
| 92 | // if the token has a $ in it, something's wrong. Ignore this token | 88 | // if the token has a $ in it, something's wrong. Ignore this token |
| 93 | if (name.lastIndexOf('$') >= 0 && m_ignoreBadTokens) { | 89 | if (name.lastIndexOf('$') >= 0 && this.ignoreBadTokens) { |
| 94 | // DEBUG | 90 | // DEBUG |
| 95 | System.err.println(String.format("WARNING: %s \"%s\" is probably a bad token. It was ignored", node.getNodeType(), name)); | 91 | System.err.println(String.format("WARNING: %s \"%s\" is probably a bad token. It was ignored", node.getNodeType(), name)); |
| 96 | return null; | 92 | return null; |
| @@ -103,8 +99,8 @@ public class SourceIndex { | |||
| 103 | Token token = getToken(node); | 99 | Token token = getToken(node); |
| 104 | if (token != null) { | 100 | if (token != null) { |
| 105 | EntryReference<Entry, Entry> deobfReference = new EntryReference<Entry, Entry>(deobfEntry, token.text, deobfContext); | 101 | EntryReference<Entry, Entry> deobfReference = new EntryReference<Entry, Entry>(deobfEntry, token.text, deobfContext); |
| 106 | m_tokenToReference.put(token, deobfReference); | 102 | this.tokenToReference.put(token, deobfReference); |
| 107 | m_referenceToTokens.put(deobfReference, token); | 103 | this.referenceToTokens.put(deobfReference, token); |
| 108 | } | 104 | } |
| 109 | } | 105 | } |
| 110 | 106 | ||
| @@ -112,14 +108,14 @@ public class SourceIndex { | |||
| 112 | Token token = getToken(node); | 108 | Token token = getToken(node); |
| 113 | if (token != null) { | 109 | if (token != null) { |
| 114 | EntryReference<Entry, Entry> reference = new EntryReference<Entry, Entry>(deobfEntry, token.text); | 110 | EntryReference<Entry, Entry> reference = new EntryReference<Entry, Entry>(deobfEntry, token.text); |
| 115 | m_tokenToReference.put(token, reference); | 111 | this.tokenToReference.put(token, reference); |
| 116 | m_referenceToTokens.put(reference, token); | 112 | this.referenceToTokens.put(reference, token); |
| 117 | m_declarationToToken.put(deobfEntry, token); | 113 | this.declarationToToken.put(deobfEntry, token); |
| 118 | } | 114 | } |
| 119 | } | 115 | } |
| 120 | 116 | ||
| 121 | public Token getReferenceToken(int pos) { | 117 | public Token getReferenceToken(int pos) { |
| 122 | Token token = m_tokenToReference.floorKey(new Token(pos, pos, null)); | 118 | Token token = this.tokenToReference.floorKey(new Token(pos, pos, null)); |
| 123 | if (token != null && token.contains(pos)) { | 119 | if (token != null && token.contains(pos)) { |
| 124 | return token; | 120 | return token; |
| 125 | } | 121 | } |
| @@ -127,44 +123,44 @@ public class SourceIndex { | |||
| 127 | } | 123 | } |
| 128 | 124 | ||
| 129 | public Collection<Token> getReferenceTokens(EntryReference<Entry, Entry> deobfReference) { | 125 | public Collection<Token> getReferenceTokens(EntryReference<Entry, Entry> deobfReference) { |
| 130 | return m_referenceToTokens.get(deobfReference); | 126 | return this.referenceToTokens.get(deobfReference); |
| 131 | } | 127 | } |
| 132 | 128 | ||
| 133 | public EntryReference<Entry, Entry> getDeobfReference(Token token) { | 129 | public EntryReference<Entry, Entry> getDeobfReference(Token token) { |
| 134 | if (token == null) { | 130 | if (token == null) { |
| 135 | return null; | 131 | return null; |
| 136 | } | 132 | } |
| 137 | return m_tokenToReference.get(token); | 133 | return this.tokenToReference.get(token); |
| 138 | } | 134 | } |
| 139 | 135 | ||
| 140 | public void replaceDeobfReference(Token token, EntryReference<Entry, Entry> newDeobfReference) { | 136 | public void replaceDeobfReference(Token token, EntryReference<Entry, Entry> newDeobfReference) { |
| 141 | EntryReference<Entry, Entry> oldDeobfReference = m_tokenToReference.get(token); | 137 | EntryReference<Entry, Entry> oldDeobfReference = this.tokenToReference.get(token); |
| 142 | m_tokenToReference.put(token, newDeobfReference); | 138 | this.tokenToReference.put(token, newDeobfReference); |
| 143 | Collection<Token> tokens = m_referenceToTokens.get(oldDeobfReference); | 139 | Collection<Token> tokens = this.referenceToTokens.get(oldDeobfReference); |
| 144 | m_referenceToTokens.removeAll(oldDeobfReference); | 140 | this.referenceToTokens.removeAll(oldDeobfReference); |
| 145 | m_referenceToTokens.putAll(newDeobfReference, tokens); | 141 | this.referenceToTokens.putAll(newDeobfReference, tokens); |
| 146 | } | 142 | } |
| 147 | 143 | ||
| 148 | public Iterable<Token> referenceTokens() { | 144 | public Iterable<Token> referenceTokens() { |
| 149 | return m_tokenToReference.keySet(); | 145 | return this.tokenToReference.keySet(); |
| 150 | } | 146 | } |
| 151 | 147 | ||
| 152 | public Iterable<Token> declarationTokens() { | 148 | public Iterable<Token> declarationTokens() { |
| 153 | return m_declarationToToken.values(); | 149 | return this.declarationToToken.values(); |
| 154 | } | 150 | } |
| 155 | 151 | ||
| 156 | public Iterable<Entry> declarations() { | 152 | public Iterable<Entry> declarations() { |
| 157 | return m_declarationToToken.keySet(); | 153 | return this.declarationToToken.keySet(); |
| 158 | } | 154 | } |
| 159 | 155 | ||
| 160 | public Token getDeclarationToken(Entry deobfEntry) { | 156 | public Token getDeclarationToken(Entry deobfEntry) { |
| 161 | return m_declarationToToken.get(deobfEntry); | 157 | return this.declarationToToken.get(deobfEntry); |
| 162 | } | 158 | } |
| 163 | 159 | ||
| 164 | public int getLineNumber(int pos) { | 160 | public int getLineNumber(int pos) { |
| 165 | // line number is 1-based | 161 | // line number is 1-based |
| 166 | int line = 0; | 162 | int line = 0; |
| 167 | for (Integer offset : m_lineOffsets) { | 163 | for (Integer offset : this.lineOffsets) { |
| 168 | if (offset > pos) { | 164 | if (offset > pos) { |
| 169 | break; | 165 | break; |
| 170 | } | 166 | } |
| @@ -175,11 +171,11 @@ public class SourceIndex { | |||
| 175 | 171 | ||
| 176 | public int getColumnNumber(int pos) { | 172 | public int getColumnNumber(int pos) { |
| 177 | // column number is 1-based | 173 | // column number is 1-based |
| 178 | return pos - m_lineOffsets.get(getLineNumber(pos) - 1) + 1; | 174 | return pos - this.lineOffsets.get(getLineNumber(pos) - 1) + 1; |
| 179 | } | 175 | } |
| 180 | 176 | ||
| 181 | private int toPos(int line, int col) { | 177 | private int toPos(int line, int col) { |
| 182 | // line and col are 1-based | 178 | // line and col are 1-based |
| 183 | return m_lineOffsets.get(line - 1) + col - 1; | 179 | return this.lineOffsets.get(line - 1) + col - 1; |
| 184 | } | 180 | } |
| 185 | } | 181 | } |
diff --git a/src/main/java/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java b/src/main/java/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java index e2b567e8..4a468e7e 100644 --- a/src/main/java/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java +++ b/src/main/java/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java | |||
| @@ -14,16 +14,16 @@ import com.strobel.assembler.metadata.*; | |||
| 14 | import com.strobel.decompiler.languages.TextLocation; | 14 | import com.strobel.decompiler.languages.TextLocation; |
| 15 | import com.strobel.decompiler.languages.java.ast.*; | 15 | import com.strobel.decompiler.languages.java.ast.*; |
| 16 | 16 | ||
| 17 | import cuchaz.enigma.mapping.*; | ||
| 18 | |||
| 19 | import java.lang.Error; | 17 | import java.lang.Error; |
| 20 | 18 | ||
| 19 | import cuchaz.enigma.mapping.*; | ||
| 20 | |||
| 21 | public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { | 21 | public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { |
| 22 | 22 | ||
| 23 | private BehaviorEntry m_behaviorEntry; | 23 | private BehaviorEntry behaviorEntry; |
| 24 | 24 | ||
| 25 | public SourceIndexBehaviorVisitor(BehaviorEntry behaviorEntry) { | 25 | public SourceIndexBehaviorVisitor(BehaviorEntry behaviorEntry) { |
| 26 | m_behaviorEntry = behaviorEntry; | 26 | this.behaviorEntry = behaviorEntry; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | @Override | 29 | @Override |
| @@ -54,7 +54,7 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { | |||
| 54 | tokenNode = node.getTarget(); | 54 | tokenNode = node.getTarget(); |
| 55 | } | 55 | } |
| 56 | if (tokenNode != null) { | 56 | if (tokenNode != null) { |
| 57 | index.addReference(tokenNode, behaviorEntry, m_behaviorEntry); | 57 | index.addReference(tokenNode, behaviorEntry, this.behaviorEntry); |
| 58 | } | 58 | } |
| 59 | } | 59 | } |
| 60 | 60 | ||
| @@ -72,7 +72,7 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { | |||
| 72 | 72 | ||
| 73 | ClassEntry classEntry = new ClassEntry(ref.getDeclaringType().getInternalName()); | 73 | ClassEntry classEntry = new ClassEntry(ref.getDeclaringType().getInternalName()); |
| 74 | FieldEntry fieldEntry = new FieldEntry(classEntry, ref.getName(), new Type(ref.getErasedSignature())); | 74 | FieldEntry fieldEntry = new FieldEntry(classEntry, ref.getName(), new Type(ref.getErasedSignature())); |
| 75 | index.addReference(node.getMemberNameToken(), fieldEntry, m_behaviorEntry); | 75 | index.addReference(node.getMemberNameToken(), fieldEntry, this.behaviorEntry); |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | return recurse(node, index); | 78 | return recurse(node, index); |
| @@ -83,7 +83,7 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { | |||
| 83 | TypeReference ref = node.getUserData(Keys.TYPE_REFERENCE); | 83 | TypeReference ref = node.getUserData(Keys.TYPE_REFERENCE); |
| 84 | if (node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY) { | 84 | if (node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY) { |
| 85 | ClassEntry classEntry = new ClassEntry(ref.getInternalName()); | 85 | ClassEntry classEntry = new ClassEntry(ref.getInternalName()); |
| 86 | index.addReference(node.getIdentifierToken(), classEntry, m_behaviorEntry); | 86 | index.addReference(node.getIdentifierToken(), classEntry, this.behaviorEntry); |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | return recurse(node, index); | 89 | return recurse(node, index); |
| @@ -108,7 +108,7 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { | |||
| 108 | if (ref != null) { | 108 | if (ref != null) { |
| 109 | ClassEntry classEntry = new ClassEntry(ref.getDeclaringType().getInternalName()); | 109 | ClassEntry classEntry = new ClassEntry(ref.getDeclaringType().getInternalName()); |
| 110 | FieldEntry fieldEntry = new FieldEntry(classEntry, ref.getName(), new Type(ref.getErasedSignature())); | 110 | FieldEntry fieldEntry = new FieldEntry(classEntry, ref.getName(), new Type(ref.getErasedSignature())); |
| 111 | index.addReference(node.getIdentifierToken(), fieldEntry, m_behaviorEntry); | 111 | index.addReference(node.getIdentifierToken(), fieldEntry, this.behaviorEntry); |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | return recurse(node, index); | 114 | return recurse(node, index); |
| @@ -122,7 +122,7 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { | |||
| 122 | ConstructorEntry constructorEntry = new ConstructorEntry(classEntry, new Signature(ref.getErasedSignature())); | 122 | ConstructorEntry constructorEntry = new ConstructorEntry(classEntry, new Signature(ref.getErasedSignature())); |
| 123 | if (node.getType() instanceof SimpleType) { | 123 | if (node.getType() instanceof SimpleType) { |
| 124 | SimpleType simpleTypeNode = (SimpleType) node.getType(); | 124 | SimpleType simpleTypeNode = (SimpleType) node.getType(); |
| 125 | index.addReference(simpleTypeNode.getIdentifierToken(), constructorEntry, m_behaviorEntry); | 125 | index.addReference(simpleTypeNode.getIdentifierToken(), constructorEntry, this.behaviorEntry); |
| 126 | } | 126 | } |
| 127 | } | 127 | } |
| 128 | 128 | ||
diff --git a/src/main/java/cuchaz/enigma/analysis/SourceIndexClassVisitor.java b/src/main/java/cuchaz/enigma/analysis/SourceIndexClassVisitor.java index 0a3bad51..06ce042b 100644 --- a/src/main/java/cuchaz/enigma/analysis/SourceIndexClassVisitor.java +++ b/src/main/java/cuchaz/enigma/analysis/SourceIndexClassVisitor.java | |||
| @@ -21,10 +21,10 @@ import cuchaz.enigma.mapping.*; | |||
| 21 | 21 | ||
| 22 | public class SourceIndexClassVisitor extends SourceIndexVisitor { | 22 | public class SourceIndexClassVisitor extends SourceIndexVisitor { |
| 23 | 23 | ||
| 24 | private ClassEntry m_classEntry; | 24 | private ClassEntry classEntry; |
| 25 | 25 | ||
| 26 | public SourceIndexClassVisitor(ClassEntry classEntry) { | 26 | public SourceIndexClassVisitor(ClassEntry classEntry) { |
| 27 | m_classEntry = classEntry; | 27 | this.classEntry = classEntry; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | @Override | 30 | @Override |
| @@ -32,7 +32,7 @@ public class SourceIndexClassVisitor extends SourceIndexVisitor { | |||
| 32 | // is this this class, or a subtype? | 32 | // is this this class, or a subtype? |
| 33 | TypeDefinition def = node.getUserData(Keys.TYPE_DEFINITION); | 33 | TypeDefinition def = node.getUserData(Keys.TYPE_DEFINITION); |
| 34 | ClassEntry classEntry = new ClassEntry(def.getInternalName()); | 34 | ClassEntry classEntry = new ClassEntry(def.getInternalName()); |
| 35 | if (!classEntry.equals(m_classEntry)) { | 35 | if (!classEntry.equals(this.classEntry)) { |
| 36 | // it's a sub-type, recurse | 36 | // it's a sub-type, recurse |
| 37 | index.addDeclaration(node.getNameToken(), classEntry); | 37 | index.addDeclaration(node.getNameToken(), classEntry); |
| 38 | return node.acceptVisitor(new SourceIndexClassVisitor(classEntry), index); | 38 | return node.acceptVisitor(new SourceIndexClassVisitor(classEntry), index); |
| @@ -46,7 +46,7 @@ public class SourceIndexClassVisitor extends SourceIndexVisitor { | |||
| 46 | TypeReference ref = node.getUserData(Keys.TYPE_REFERENCE); | 46 | TypeReference ref = node.getUserData(Keys.TYPE_REFERENCE); |
| 47 | if (node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY) { | 47 | if (node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY) { |
| 48 | ClassEntry classEntry = new ClassEntry(ref.getInternalName()); | 48 | ClassEntry classEntry = new ClassEntry(ref.getInternalName()); |
| 49 | index.addReference(node.getIdentifierToken(), classEntry, m_classEntry); | 49 | index.addReference(node.getIdentifierToken(), classEntry, this.classEntry); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | return recurse(node, index); | 52 | return recurse(node, index); |
diff --git a/src/main/java/cuchaz/enigma/analysis/Token.java b/src/main/java/cuchaz/enigma/analysis/Token.java index 0103df2e..575c373f 100644 --- a/src/main/java/cuchaz/enigma/analysis/Token.java +++ b/src/main/java/cuchaz/enigma/analysis/Token.java | |||
| @@ -39,10 +39,7 @@ public class Token implements Comparable<Token> { | |||
| 39 | 39 | ||
| 40 | @Override | 40 | @Override |
| 41 | public boolean equals(Object other) { | 41 | public boolean equals(Object other) { |
| 42 | if (other instanceof Token) { | 42 | return other instanceof Token && equals((Token) other); |
| 43 | return equals((Token) other); | ||
| 44 | } | ||
| 45 | return false; | ||
| 46 | } | 43 | } |
| 47 | 44 | ||
| 48 | public boolean equals(Token other) { | 45 | public boolean equals(Token other) { |
diff --git a/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java b/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java index 0261a96a..f020ae2c 100644 --- a/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java | |||
| @@ -30,50 +30,47 @@ public class TranslationIndex implements Serializable { | |||
| 30 | 30 | ||
| 31 | private static final long serialVersionUID = 738687982126844179L; | 31 | private static final long serialVersionUID = 738687982126844179L; |
| 32 | 32 | ||
| 33 | private Map<ClassEntry, ClassEntry> m_superclasses; | 33 | private Map<ClassEntry, ClassEntry> superclasses; |
| 34 | private Multimap<ClassEntry, FieldEntry> m_fieldEntries; | 34 | private Multimap<ClassEntry, FieldEntry> fieldEntries; |
| 35 | private Multimap<ClassEntry, BehaviorEntry> m_behaviorEntries; | 35 | private Multimap<ClassEntry, BehaviorEntry> behaviorEntries; |
| 36 | private Multimap<ClassEntry, ClassEntry> m_interfaces; | 36 | private Multimap<ClassEntry, ClassEntry> interfaces; |
| 37 | 37 | ||
| 38 | public TranslationIndex() { | 38 | public TranslationIndex() { |
| 39 | m_superclasses = Maps.newHashMap(); | 39 | this.superclasses = Maps.newHashMap(); |
| 40 | m_fieldEntries = HashMultimap.create(); | 40 | this.fieldEntries = HashMultimap.create(); |
| 41 | m_behaviorEntries = HashMultimap.create(); | 41 | this.behaviorEntries = HashMultimap.create(); |
| 42 | m_interfaces = HashMultimap.create(); | 42 | this.interfaces = HashMultimap.create(); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | public TranslationIndex(TranslationIndex other, Translator translator) { | 45 | public TranslationIndex(TranslationIndex other, Translator translator) { |
| 46 | 46 | ||
| 47 | // translate the superclasses | 47 | // translate the superclasses |
| 48 | m_superclasses = Maps.newHashMap(); | 48 | this.superclasses = Maps.newHashMap(); |
| 49 | for (Map.Entry<ClassEntry, ClassEntry> mapEntry : other.m_superclasses.entrySet()) { | 49 | for (Map.Entry<ClassEntry, ClassEntry> mapEntry : other.superclasses.entrySet()) { |
| 50 | m_superclasses.put( | 50 | this.superclasses.put(translator.translateEntry(mapEntry.getKey()), translator.translateEntry(mapEntry.getValue())); |
| 51 | translator.translateEntry(mapEntry.getKey()), | ||
| 52 | translator.translateEntry(mapEntry.getValue()) | ||
| 53 | ); | ||
| 54 | } | 51 | } |
| 55 | 52 | ||
| 56 | // translate the interfaces | 53 | // translate the interfaces |
| 57 | m_interfaces = HashMultimap.create(); | 54 | this.interfaces = HashMultimap.create(); |
| 58 | for (Map.Entry<ClassEntry, ClassEntry> mapEntry : other.m_interfaces.entries()) { | 55 | for (Map.Entry<ClassEntry, ClassEntry> mapEntry : other.interfaces.entries()) { |
| 59 | m_interfaces.put( | 56 | this.interfaces.put( |
| 60 | translator.translateEntry(mapEntry.getKey()), | 57 | translator.translateEntry(mapEntry.getKey()), |
| 61 | translator.translateEntry(mapEntry.getValue()) | 58 | translator.translateEntry(mapEntry.getValue()) |
| 62 | ); | 59 | ); |
| 63 | } | 60 | } |
| 64 | 61 | ||
| 65 | // translate the fields | 62 | // translate the fields |
| 66 | m_fieldEntries = HashMultimap.create(); | 63 | this.fieldEntries = HashMultimap.create(); |
| 67 | for (Map.Entry<ClassEntry, FieldEntry> mapEntry : other.m_fieldEntries.entries()) { | 64 | for (Map.Entry<ClassEntry, FieldEntry> mapEntry : other.fieldEntries.entries()) { |
| 68 | m_fieldEntries.put( | 65 | this.fieldEntries.put( |
| 69 | translator.translateEntry(mapEntry.getKey()), | 66 | translator.translateEntry(mapEntry.getKey()), |
| 70 | translator.translateEntry(mapEntry.getValue()) | 67 | translator.translateEntry(mapEntry.getValue()) |
| 71 | ); | 68 | ); |
| 72 | } | 69 | } |
| 73 | 70 | ||
| 74 | m_behaviorEntries = HashMultimap.create(); | 71 | this.behaviorEntries = HashMultimap.create(); |
| 75 | for (Map.Entry<ClassEntry, BehaviorEntry> mapEntry : other.m_behaviorEntries.entries()) { | 72 | for (Map.Entry<ClassEntry, BehaviorEntry> mapEntry : other.behaviorEntries.entries()) { |
| 76 | m_behaviorEntries.put( | 73 | this.behaviorEntries.put( |
| 77 | translator.translateEntry(mapEntry.getKey()), | 74 | translator.translateEntry(mapEntry.getKey()), |
| 78 | translator.translateEntry(mapEntry.getValue()) | 75 | translator.translateEntry(mapEntry.getValue()) |
| 79 | ); | 76 | ); |
| @@ -94,14 +91,14 @@ public class TranslationIndex implements Serializable { | |||
| 94 | // add the superclass | 91 | // add the superclass |
| 95 | ClassEntry superclassEntry = EntryFactory.getSuperclassEntry(c); | 92 | ClassEntry superclassEntry = EntryFactory.getSuperclassEntry(c); |
| 96 | if (superclassEntry != null) { | 93 | if (superclassEntry != null) { |
| 97 | m_superclasses.put(classEntry, superclassEntry); | 94 | this.superclasses.put(classEntry, superclassEntry); |
| 98 | } | 95 | } |
| 99 | 96 | ||
| 100 | // add the interfaces | 97 | // add the interfaces |
| 101 | for (String interfaceClassName : c.getClassFile().getInterfaces()) { | 98 | for (String interfaceClassName : c.getClassFile().getInterfaces()) { |
| 102 | ClassEntry interfaceClassEntry = new ClassEntry(Descriptor.toJvmName(interfaceClassName)); | 99 | ClassEntry interfaceClassEntry = new ClassEntry(Descriptor.toJvmName(interfaceClassName)); |
| 103 | if (!isJre(interfaceClassEntry)) { | 100 | if (!isJre(interfaceClassEntry)) { |
| 104 | m_interfaces.put(classEntry, interfaceClassEntry); | 101 | this.interfaces.put(classEntry, interfaceClassEntry); |
| 105 | } | 102 | } |
| 106 | } | 103 | } |
| 107 | 104 | ||
| @@ -109,25 +106,25 @@ public class TranslationIndex implements Serializable { | |||
| 109 | // add fields | 106 | // add fields |
| 110 | for (CtField field : c.getDeclaredFields()) { | 107 | for (CtField field : c.getDeclaredFields()) { |
| 111 | FieldEntry fieldEntry = EntryFactory.getFieldEntry(field); | 108 | FieldEntry fieldEntry = EntryFactory.getFieldEntry(field); |
| 112 | m_fieldEntries.put(fieldEntry.getClassEntry(), fieldEntry); | 109 | this.fieldEntries.put(fieldEntry.getClassEntry(), fieldEntry); |
| 113 | } | 110 | } |
| 114 | 111 | ||
| 115 | // add behaviors | 112 | // add behaviors |
| 116 | for (CtBehavior behavior : c.getDeclaredBehaviors()) { | 113 | for (CtBehavior behavior : c.getDeclaredBehaviors()) { |
| 117 | BehaviorEntry behaviorEntry = EntryFactory.getBehaviorEntry(behavior); | 114 | BehaviorEntry behaviorEntry = EntryFactory.getBehaviorEntry(behavior); |
| 118 | m_behaviorEntries.put(behaviorEntry.getClassEntry(), behaviorEntry); | 115 | this.behaviorEntries.put(behaviorEntry.getClassEntry(), behaviorEntry); |
| 119 | } | 116 | } |
| 120 | } | 117 | } |
| 121 | } | 118 | } |
| 122 | 119 | ||
| 123 | public void renameClasses(Map<String, String> renames) { | 120 | public void renameClasses(Map<String, String> renames) { |
| 124 | EntryRenamer.renameClassesInMap(renames, m_superclasses); | 121 | EntryRenamer.renameClassesInMap(renames, this.superclasses); |
| 125 | EntryRenamer.renameClassesInMultimap(renames, m_fieldEntries); | 122 | EntryRenamer.renameClassesInMultimap(renames,this.fieldEntries); |
| 126 | EntryRenamer.renameClassesInMultimap(renames, m_behaviorEntries); | 123 | EntryRenamer.renameClassesInMultimap(renames, this.behaviorEntries); |
| 127 | } | 124 | } |
| 128 | 125 | ||
| 129 | public ClassEntry getSuperclass(ClassEntry classEntry) { | 126 | public ClassEntry getSuperclass(ClassEntry classEntry) { |
| 130 | return m_superclasses.get(classEntry); | 127 | return this.superclasses.get(classEntry); |
| 131 | } | 128 | } |
| 132 | 129 | ||
| 133 | public List<ClassEntry> getAncestry(ClassEntry classEntry) { | 130 | public List<ClassEntry> getAncestry(ClassEntry classEntry) { |
| @@ -145,7 +142,7 @@ public class TranslationIndex implements Serializable { | |||
| 145 | 142 | ||
| 146 | // linear search is fast enough for now | 143 | // linear search is fast enough for now |
| 147 | List<ClassEntry> subclasses = Lists.newArrayList(); | 144 | List<ClassEntry> subclasses = Lists.newArrayList(); |
| 148 | for (Map.Entry<ClassEntry, ClassEntry> entry : m_superclasses.entrySet()) { | 145 | for (Map.Entry<ClassEntry, ClassEntry> entry : this.superclasses.entrySet()) { |
| 149 | ClassEntry subclass = entry.getKey(); | 146 | ClassEntry subclass = entry.getKey(); |
| 150 | ClassEntry superclass = entry.getValue(); | 147 | ClassEntry superclass = entry.getValue(); |
| 151 | if (classEntry.equals(superclass)) { | 148 | if (classEntry.equals(superclass)) { |
| @@ -170,15 +167,15 @@ public class TranslationIndex implements Serializable { | |||
| 170 | } | 167 | } |
| 171 | 168 | ||
| 172 | public Collection<Map.Entry<ClassEntry, ClassEntry>> getClassInterfaces() { | 169 | public Collection<Map.Entry<ClassEntry, ClassEntry>> getClassInterfaces() { |
| 173 | return m_interfaces.entries(); | 170 | return this.interfaces.entries(); |
| 174 | } | 171 | } |
| 175 | 172 | ||
| 176 | public Collection<ClassEntry> getInterfaces(ClassEntry classEntry) { | 173 | public Collection<ClassEntry> getInterfaces(ClassEntry classEntry) { |
| 177 | return m_interfaces.get(classEntry); | 174 | return this.interfaces.get(classEntry); |
| 178 | } | 175 | } |
| 179 | 176 | ||
| 180 | public boolean isInterface(ClassEntry classEntry) { | 177 | public boolean isInterface(ClassEntry classEntry) { |
| 181 | return m_interfaces.containsValue(classEntry); | 178 | return this.interfaces.containsValue(classEntry); |
| 182 | } | 179 | } |
| 183 | 180 | ||
| 184 | public boolean entryExists(Entry entry) { | 181 | public boolean entryExists(Entry entry) { |
| @@ -193,11 +190,11 @@ public class TranslationIndex implements Serializable { | |||
| 193 | } | 190 | } |
| 194 | 191 | ||
| 195 | public boolean fieldExists(FieldEntry fieldEntry) { | 192 | public boolean fieldExists(FieldEntry fieldEntry) { |
| 196 | return m_fieldEntries.containsEntry(fieldEntry.getClassEntry(), fieldEntry); | 193 | return this.fieldEntries.containsEntry(fieldEntry.getClassEntry(), fieldEntry); |
| 197 | } | 194 | } |
| 198 | 195 | ||
| 199 | public boolean behaviorExists(BehaviorEntry behaviorEntry) { | 196 | public boolean behaviorExists(BehaviorEntry behaviorEntry) { |
| 200 | return m_behaviorEntries.containsEntry(behaviorEntry.getClassEntry(), behaviorEntry); | 197 | return this.behaviorEntries.containsEntry(behaviorEntry.getClassEntry(), behaviorEntry); |
| 201 | } | 198 | } |
| 202 | 199 | ||
| 203 | public ClassEntry resolveEntryClass(Entry entry) { | 200 | public ClassEntry resolveEntryClass(Entry entry) { |
| @@ -243,7 +240,7 @@ public class TranslationIndex implements Serializable { | |||
| 243 | 240 | ||
| 244 | // the interfaces for any class is a forest | 241 | // the interfaces for any class is a forest |
| 245 | // so let's look at all the trees | 242 | // so let's look at all the trees |
| 246 | for (ClassEntry interfaceEntry : m_interfaces.get(entry.getClassEntry())) { | 243 | for (ClassEntry interfaceEntry : this.interfaces.get(entry.getClassEntry())) { |
| 247 | ClassEntry resolvedClassEntry = resolveSuperclass(entry.cloneToNewClass(interfaceEntry)); | 244 | ClassEntry resolvedClassEntry = resolveSuperclass(entry.cloneToNewClass(interfaceEntry)); |
| 248 | if (resolvedClassEntry != null) { | 245 | if (resolvedClassEntry != null) { |
| 249 | return resolvedClassEntry; | 246 | return resolvedClassEntry; |
| @@ -261,9 +258,9 @@ public class TranslationIndex implements Serializable { | |||
| 261 | throws IOException { | 258 | throws IOException { |
| 262 | GZIPOutputStream gzipout = new GZIPOutputStream(out); | 259 | GZIPOutputStream gzipout = new GZIPOutputStream(out); |
| 263 | ObjectOutputStream oout = new ObjectOutputStream(gzipout); | 260 | ObjectOutputStream oout = new ObjectOutputStream(gzipout); |
| 264 | oout.writeObject(m_superclasses); | 261 | oout.writeObject(this.superclasses); |
| 265 | oout.writeObject(m_fieldEntries); | 262 | oout.writeObject(this.fieldEntries); |
| 266 | oout.writeObject(m_behaviorEntries); | 263 | oout.writeObject(this.behaviorEntries); |
| 267 | gzipout.finish(); | 264 | gzipout.finish(); |
| 268 | } | 265 | } |
| 269 | 266 | ||
| @@ -272,9 +269,9 @@ public class TranslationIndex implements Serializable { | |||
| 272 | throws IOException { | 269 | throws IOException { |
| 273 | try { | 270 | try { |
| 274 | ObjectInputStream oin = new ObjectInputStream(new GZIPInputStream(in)); | 271 | ObjectInputStream oin = new ObjectInputStream(new GZIPInputStream(in)); |
| 275 | m_superclasses = (HashMap<ClassEntry, ClassEntry>) oin.readObject(); | 272 | this.superclasses = (HashMap<ClassEntry, ClassEntry>) oin.readObject(); |
| 276 | m_fieldEntries = (HashMultimap<ClassEntry, FieldEntry>) oin.readObject(); | 273 | this.fieldEntries = (HashMultimap<ClassEntry, FieldEntry>) oin.readObject(); |
| 277 | m_behaviorEntries = (HashMultimap<ClassEntry, BehaviorEntry>) oin.readObject(); | 274 | this.behaviorEntries = (HashMultimap<ClassEntry, BehaviorEntry>) oin.readObject(); |
| 278 | } catch (ClassNotFoundException ex) { | 275 | } catch (ClassNotFoundException ex) { |
| 279 | throw new Error(ex); | 276 | throw new Error(ex); |
| 280 | } | 277 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java b/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java index 8058d0ea..19c39d3c 100644 --- a/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java +++ b/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java | |||
| @@ -31,29 +31,29 @@ public class CheckCastIterator implements Iterator<CheckCast> { | |||
| 31 | } | 31 | } |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | private ConstPool m_constants; | 34 | private ConstPool constants; |
| 35 | private CodeAttribute m_attribute; | 35 | private CodeAttribute attribute; |
| 36 | private CodeIterator m_iter; | 36 | private CodeIterator iter; |
| 37 | private CheckCast m_next; | 37 | private CheckCast next; |
| 38 | 38 | ||
| 39 | public CheckCastIterator(CodeAttribute codeAttribute) throws BadBytecode { | 39 | public CheckCastIterator(CodeAttribute codeAttribute) throws BadBytecode { |
| 40 | m_constants = codeAttribute.getConstPool(); | 40 | this.constants = codeAttribute.getConstPool(); |
| 41 | m_attribute = codeAttribute; | 41 | this.attribute = codeAttribute; |
| 42 | m_iter = m_attribute.iterator(); | 42 | this.iter = this.attribute.iterator(); |
| 43 | 43 | ||
| 44 | m_next = getNext(); | 44 | this.next = getNext(); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | @Override | 47 | @Override |
| 48 | public boolean hasNext() { | 48 | public boolean hasNext() { |
| 49 | return m_next != null; | 49 | return this.next != null; |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | @Override | 52 | @Override |
| 53 | public CheckCast next() { | 53 | public CheckCast next() { |
| 54 | CheckCast out = m_next; | 54 | CheckCast out = this.next; |
| 55 | try { | 55 | try { |
| 56 | m_next = getNext(); | 56 | this.next = getNext(); |
| 57 | } catch (BadBytecode ex) { | 57 | } catch (BadBytecode ex) { |
| 58 | throw new Error(ex); | 58 | throw new Error(ex); |
| 59 | } | 59 | } |
| @@ -67,16 +67,16 @@ public class CheckCastIterator implements Iterator<CheckCast> { | |||
| 67 | 67 | ||
| 68 | private CheckCast getNext() throws BadBytecode { | 68 | private CheckCast getNext() throws BadBytecode { |
| 69 | int prevPos = 0; | 69 | int prevPos = 0; |
| 70 | while (m_iter.hasNext()) { | 70 | while (this.iter.hasNext()) { |
| 71 | int pos = m_iter.next(); | 71 | int pos = this.iter.next(); |
| 72 | int opcode = m_iter.byteAt(pos); | 72 | int opcode = this.iter.byteAt(pos); |
| 73 | switch (opcode) { | 73 | switch (opcode) { |
| 74 | case Opcode.CHECKCAST: | 74 | case Opcode.CHECKCAST: |
| 75 | 75 | ||
| 76 | // get the type of this op code (next two bytes are a classinfo index) | 76 | // get the type of this op code (next two bytes are a classinfo index) |
| 77 | MethodEntry prevMethodEntry = getMethodEntry(prevPos); | 77 | MethodEntry prevMethodEntry = getMethodEntry(prevPos); |
| 78 | if (prevMethodEntry != null) { | 78 | if (prevMethodEntry != null) { |
| 79 | return new CheckCast(m_constants.getClassInfo(m_iter.s16bitAt(pos + 1)), prevMethodEntry); | 79 | return new CheckCast(this.constants.getClassInfo(this.iter.s16bitAt(pos + 1)), prevMethodEntry); |
| 80 | } | 80 | } |
| 81 | break; | 81 | break; |
| 82 | } | 82 | } |
| @@ -86,25 +86,25 @@ public class CheckCastIterator implements Iterator<CheckCast> { | |||
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | private MethodEntry getMethodEntry(int pos) { | 88 | private MethodEntry getMethodEntry(int pos) { |
| 89 | switch (m_iter.byteAt(pos)) { | 89 | switch (this.iter.byteAt(pos)) { |
| 90 | case Opcode.INVOKEVIRTUAL: | 90 | case Opcode.INVOKEVIRTUAL: |
| 91 | case Opcode.INVOKESTATIC: | 91 | case Opcode.INVOKESTATIC: |
| 92 | case Opcode.INVOKEDYNAMIC: | 92 | case Opcode.INVOKEDYNAMIC: |
| 93 | case Opcode.INVOKESPECIAL: { | 93 | case Opcode.INVOKESPECIAL: { |
| 94 | int index = m_iter.s16bitAt(pos + 1); | 94 | int index = this.iter.s16bitAt(pos + 1); |
| 95 | return new MethodEntry( | 95 | return new MethodEntry( |
| 96 | new ClassEntry(Descriptor.toJvmName(m_constants.getMethodrefClassName(index))), | 96 | new ClassEntry(Descriptor.toJvmName(this.constants.getMethodrefClassName(index))), |
| 97 | m_constants.getMethodrefName(index), | 97 | this.constants.getMethodrefName(index), |
| 98 | new Signature(m_constants.getMethodrefType(index)) | 98 | new Signature(this.constants.getMethodrefType(index)) |
| 99 | ); | 99 | ); |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | case Opcode.INVOKEINTERFACE: { | 102 | case Opcode.INVOKEINTERFACE: { |
| 103 | int index = m_iter.s16bitAt(pos + 1); | 103 | int index = this.iter.s16bitAt(pos + 1); |
| 104 | return new MethodEntry( | 104 | return new MethodEntry( |
| 105 | new ClassEntry(Descriptor.toJvmName(m_constants.getInterfaceMethodrefClassName(index))), | 105 | new ClassEntry(Descriptor.toJvmName(this.constants.getInterfaceMethodrefClassName(index))), |
| 106 | m_constants.getInterfaceMethodrefName(index), | 106 | this.constants.getInterfaceMethodrefName(index), |
| 107 | new Signature(m_constants.getInterfaceMethodrefType(index)) | 107 | new Signature(this.constants.getInterfaceMethodrefType(index)) |
| 108 | ); | 108 | ); |
| 109 | } | 109 | } |
| 110 | } | 110 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java b/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java index 548bea75..d8e79711 100644 --- a/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java +++ b/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java | |||
| @@ -51,8 +51,6 @@ public class ClassRenamer { | |||
| 51 | 51 | ||
| 52 | private static class ReplacerClassMap extends HashMap<String, String> { | 52 | private static class ReplacerClassMap extends HashMap<String, String> { |
| 53 | 53 | ||
| 54 | private static final long serialVersionUID = 317915213205066168L; | ||
| 55 | |||
| 56 | private ClassNameReplacer m_replacer; | 54 | private ClassNameReplacer m_replacer; |
| 57 | 55 | ||
| 58 | public ReplacerClassMap(ClassNameReplacer replacer) { | 56 | public ReplacerClassMap(ClassNameReplacer replacer) { |
| @@ -151,7 +149,7 @@ public class ClassRenamer { | |||
| 151 | } | 149 | } |
| 152 | 150 | ||
| 153 | /* DEBUG | 151 | /* DEBUG |
| 154 | System.out.println(String.format("\tDEOBF: %s-> ATTR: %s,%s,%s", classEntry, attr.outerClass(i), attr.innerClass(i), attr.innerName(i))); | 152 | System.out.println(String.format("\tDEOBF: %s-> ATTR: %s,%s,%s", classEntry, attr.outerClass(i), attr.innerClass(i), attr.innerName(i))); |
| 155 | */ | 153 | */ |
| 156 | } | 154 | } |
| 157 | } | 155 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/ClassTranslator.java b/src/main/java/cuchaz/enigma/bytecode/ClassTranslator.java index ef197cbe..8fdd8513 100644 --- a/src/main/java/cuchaz/enigma/bytecode/ClassTranslator.java +++ b/src/main/java/cuchaz/enigma/bytecode/ClassTranslator.java | |||
| @@ -22,10 +22,10 @@ import javassist.bytecode.SourceFileAttribute; | |||
| 22 | 22 | ||
| 23 | public class ClassTranslator { | 23 | public class ClassTranslator { |
| 24 | 24 | ||
| 25 | private Translator m_translator; | 25 | private Translator translator; |
| 26 | 26 | ||
| 27 | public ClassTranslator(Translator translator) { | 27 | public ClassTranslator(Translator translator) { |
| 28 | m_translator = translator; | 28 | this.translator = translator; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | public void translate(CtClass c) { | 31 | public void translate(CtClass c) { |
| @@ -46,7 +46,7 @@ public class ClassTranslator { | |||
| 46 | constants.getFieldrefName(i), | 46 | constants.getFieldrefName(i), |
| 47 | constants.getFieldrefType(i) | 47 | constants.getFieldrefType(i) |
| 48 | ); | 48 | ); |
| 49 | FieldEntry translatedEntry = m_translator.translateEntry(entry); | 49 | FieldEntry translatedEntry = this.translator.translateEntry(entry); |
| 50 | if (!entry.equals(translatedEntry)) { | 50 | if (!entry.equals(translatedEntry)) { |
| 51 | editor.changeMemberrefNameAndType(i, translatedEntry.getName(), translatedEntry.getType().toString()); | 51 | editor.changeMemberrefNameAndType(i, translatedEntry.getName(), translatedEntry.getType().toString()); |
| 52 | } | 52 | } |
| @@ -62,7 +62,7 @@ public class ClassTranslator { | |||
| 62 | editor.getMemberrefName(i), | 62 | editor.getMemberrefName(i), |
| 63 | editor.getMemberrefType(i) | 63 | editor.getMemberrefType(i) |
| 64 | ); | 64 | ); |
| 65 | BehaviorEntry translatedEntry = m_translator.translateEntry(entry); | 65 | BehaviorEntry translatedEntry = this.translator.translateEntry(entry); |
| 66 | if (!entry.equals(translatedEntry)) { | 66 | if (!entry.equals(translatedEntry)) { |
| 67 | editor.changeMemberrefNameAndType(i, translatedEntry.getName(), translatedEntry.getSignature().toString()); | 67 | editor.changeMemberrefNameAndType(i, translatedEntry.getName(), translatedEntry.getSignature().toString()); |
| 68 | } | 68 | } |
| @@ -78,13 +78,13 @@ public class ClassTranslator { | |||
| 78 | 78 | ||
| 79 | // translate the name | 79 | // translate the name |
| 80 | FieldEntry entry = EntryFactory.getFieldEntry(field); | 80 | FieldEntry entry = EntryFactory.getFieldEntry(field); |
| 81 | String translatedName = m_translator.translate(entry); | 81 | String translatedName = this.translator.translate(entry); |
| 82 | if (translatedName != null) { | 82 | if (translatedName != null) { |
| 83 | field.setName(translatedName); | 83 | field.setName(translatedName); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | // translate the type | 86 | // translate the type |
| 87 | Type translatedType = m_translator.translateType(entry.getType()); | 87 | Type translatedType = this.translator.translateType(entry.getType()); |
| 88 | field.getFieldInfo().setDescriptor(translatedType.toString()); | 88 | field.getFieldInfo().setDescriptor(translatedType.toString()); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| @@ -97,7 +97,7 @@ public class ClassTranslator { | |||
| 97 | CtMethod method = (CtMethod) behavior; | 97 | CtMethod method = (CtMethod) behavior; |
| 98 | 98 | ||
| 99 | // translate the name | 99 | // translate the name |
| 100 | String translatedName = m_translator.translate(entry); | 100 | String translatedName = this.translator.translate(entry); |
| 101 | if (translatedName != null) { | 101 | if (translatedName != null) { |
| 102 | method.setName(translatedName); | 102 | method.setName(translatedName); |
| 103 | } | 103 | } |
| @@ -105,7 +105,7 @@ public class ClassTranslator { | |||
| 105 | 105 | ||
| 106 | if (entry.getSignature() != null) { | 106 | if (entry.getSignature() != null) { |
| 107 | // translate the signature | 107 | // translate the signature |
| 108 | Signature translatedSignature = m_translator.translateSignature(entry.getSignature()); | 108 | Signature translatedSignature = this.translator.translateSignature(entry.getSignature()); |
| 109 | behavior.getMethodInfo().setDescriptor(translatedSignature.toString()); | 109 | behavior.getMethodInfo().setDescriptor(translatedSignature.toString()); |
| 110 | } | 110 | } |
| 111 | } | 111 | } |
| @@ -116,7 +116,7 @@ public class ClassTranslator { | |||
| 116 | 116 | ||
| 117 | if (enclosingMethodAttr.methodIndex() == 0) { | 117 | if (enclosingMethodAttr.methodIndex() == 0) { |
| 118 | BehaviorEntry obfBehaviorEntry = EntryFactory.getBehaviorEntry(Descriptor.toJvmName(enclosingMethodAttr.className())); | 118 | BehaviorEntry obfBehaviorEntry = EntryFactory.getBehaviorEntry(Descriptor.toJvmName(enclosingMethodAttr.className())); |
| 119 | BehaviorEntry deobfBehaviorEntry = m_translator.translateEntry(obfBehaviorEntry); | 119 | BehaviorEntry deobfBehaviorEntry = this.translator.translateEntry(obfBehaviorEntry); |
| 120 | c.getClassFile().addAttribute(new EnclosingMethodAttribute( | 120 | c.getClassFile().addAttribute(new EnclosingMethodAttribute( |
| 121 | constants, | 121 | constants, |
| 122 | deobfBehaviorEntry.getClassName() | 122 | deobfBehaviorEntry.getClassName() |
| @@ -127,7 +127,7 @@ public class ClassTranslator { | |||
| 127 | enclosingMethodAttr.methodName(), | 127 | enclosingMethodAttr.methodName(), |
| 128 | enclosingMethodAttr.methodDescriptor() | 128 | enclosingMethodAttr.methodDescriptor() |
| 129 | ); | 129 | ); |
| 130 | BehaviorEntry deobfBehaviorEntry = m_translator.translateEntry(obfBehaviorEntry); | 130 | BehaviorEntry deobfBehaviorEntry = this.translator.translateEntry(obfBehaviorEntry); |
| 131 | c.getClassFile().addAttribute(new EnclosingMethodAttribute( | 131 | c.getClassFile().addAttribute(new EnclosingMethodAttribute( |
| 132 | constants, | 132 | constants, |
| 133 | deobfBehaviorEntry.getClassName(), | 133 | deobfBehaviorEntry.getClassName(), |
| @@ -139,10 +139,10 @@ public class ClassTranslator { | |||
| 139 | 139 | ||
| 140 | // translate all the class names referenced in the code | 140 | // translate all the class names referenced in the code |
| 141 | // the above code only changed method/field/reference names and types, but not the rest of the class references | 141 | // the above code only changed method/field/reference names and types, but not the rest of the class references |
| 142 | ClassRenamer.renameClasses(c, m_translator); | 142 | ClassRenamer.renameClasses(c, this.translator); |
| 143 | 143 | ||
| 144 | // translate the source file attribute too | 144 | // translate the source file attribute too |
| 145 | ClassEntry deobfClassEntry = m_translator.translateEntry(classEntry); | 145 | ClassEntry deobfClassEntry = this.translator.translateEntry(classEntry); |
| 146 | if (deobfClassEntry != null) { | 146 | if (deobfClassEntry != null) { |
| 147 | String sourceFile = Descriptor.toJvmName(deobfClassEntry.getOutermostClassEntry().getSimpleName()) + ".java"; | 147 | String sourceFile = Descriptor.toJvmName(deobfClassEntry.getOutermostClassEntry().getSimpleName()) + ".java"; |
| 148 | c.getClassFile().addAttribute(new SourceFileAttribute(constants, sourceFile)); | 148 | c.getClassFile().addAttribute(new SourceFileAttribute(constants, sourceFile)); |
diff --git a/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java b/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java index 0082a72c..256df61e 100644 --- a/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java +++ b/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java | |||
| @@ -25,62 +25,62 @@ import javassist.bytecode.Descriptor; | |||
| 25 | 25 | ||
| 26 | public class ConstPoolEditor { | 26 | public class ConstPoolEditor { |
| 27 | 27 | ||
| 28 | private static Method m_getItem; | 28 | private static Method getItem; |
| 29 | private static Method m_addItem; | 29 | private static Method addItem; |
| 30 | private static Method m_addItem0; | 30 | private static Method addItem0; |
| 31 | private static Field m_items; | 31 | private static Field items; |
| 32 | private static Field m_cache; | 32 | private static Field cache; |
| 33 | private static Field m_numItems; | 33 | private static Field numItems; |
| 34 | private static Field m_objects; | 34 | private static Field objects; |
| 35 | private static Field m_elements; | 35 | private static Field elements; |
| 36 | private static Method m_methodWritePool; | 36 | private static Method methodWritePool; |
| 37 | private static Constructor<ConstPool> m_constructorPool; | 37 | private static Constructor<ConstPool> constructorPool; |
| 38 | 38 | ||
| 39 | static { | 39 | static { |
| 40 | try { | 40 | try { |
| 41 | m_getItem = ConstPool.class.getDeclaredMethod("getItem", int.class); | 41 | getItem = ConstPool.class.getDeclaredMethod("getItem", int.class); |
| 42 | m_getItem.setAccessible(true); | 42 | getItem.setAccessible(true); |
| 43 | 43 | ||
| 44 | m_addItem = ConstPool.class.getDeclaredMethod("addItem", Class.forName("javassist.bytecode.ConstInfo")); | 44 | addItem = ConstPool.class.getDeclaredMethod("addItem", Class.forName("javassist.bytecode.ConstInfo")); |
| 45 | m_addItem.setAccessible(true); | 45 | addItem.setAccessible(true); |
| 46 | 46 | ||
| 47 | m_addItem0 = ConstPool.class.getDeclaredMethod("addItem0", Class.forName("javassist.bytecode.ConstInfo")); | 47 | addItem0 = ConstPool.class.getDeclaredMethod("addItem0", Class.forName("javassist.bytecode.ConstInfo")); |
| 48 | m_addItem0.setAccessible(true); | 48 | addItem0.setAccessible(true); |
| 49 | 49 | ||
| 50 | m_items = ConstPool.class.getDeclaredField("items"); | 50 | items = ConstPool.class.getDeclaredField("items"); |
| 51 | m_items.setAccessible(true); | 51 | items.setAccessible(true); |
| 52 | 52 | ||
| 53 | m_cache = ConstPool.class.getDeclaredField("itemsCache"); | 53 | cache = ConstPool.class.getDeclaredField("itemsCache"); |
| 54 | m_cache.setAccessible(true); | 54 | cache.setAccessible(true); |
| 55 | 55 | ||
| 56 | m_numItems = ConstPool.class.getDeclaredField("numOfItems"); | 56 | numItems = ConstPool.class.getDeclaredField("numOfItems"); |
| 57 | m_numItems.setAccessible(true); | 57 | numItems.setAccessible(true); |
| 58 | 58 | ||
| 59 | m_objects = Class.forName("javassist.bytecode.LongVector").getDeclaredField("objects"); | 59 | objects = Class.forName("javassist.bytecode.LongVector").getDeclaredField("objects"); |
| 60 | m_objects.setAccessible(true); | 60 | objects.setAccessible(true); |
| 61 | 61 | ||
| 62 | m_elements = Class.forName("javassist.bytecode.LongVector").getDeclaredField("elements"); | 62 | elements = Class.forName("javassist.bytecode.LongVector").getDeclaredField("elements"); |
| 63 | m_elements.setAccessible(true); | 63 | elements.setAccessible(true); |
| 64 | 64 | ||
| 65 | m_methodWritePool = ConstPool.class.getDeclaredMethod("write", DataOutputStream.class); | 65 | methodWritePool = ConstPool.class.getDeclaredMethod("write", DataOutputStream.class); |
| 66 | m_methodWritePool.setAccessible(true); | 66 | methodWritePool.setAccessible(true); |
| 67 | 67 | ||
| 68 | m_constructorPool = ConstPool.class.getDeclaredConstructor(DataInputStream.class); | 68 | constructorPool = ConstPool.class.getDeclaredConstructor(DataInputStream.class); |
| 69 | m_constructorPool.setAccessible(true); | 69 | constructorPool.setAccessible(true); |
| 70 | } catch (Exception ex) { | 70 | } catch (Exception ex) { |
| 71 | throw new Error(ex); | 71 | throw new Error(ex); |
| 72 | } | 72 | } |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | private ConstPool m_pool; | 75 | private ConstPool pool; |
| 76 | 76 | ||
| 77 | public ConstPoolEditor(ConstPool pool) { | 77 | public ConstPoolEditor(ConstPool pool) { |
| 78 | m_pool = pool; | 78 | this.pool = pool; |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | public void writePool(DataOutputStream out) { | 81 | public void writePool(DataOutputStream out) { |
| 82 | try { | 82 | try { |
| 83 | m_methodWritePool.invoke(m_pool, out); | 83 | methodWritePool.invoke(this.pool, out); |
| 84 | } catch (Exception ex) { | 84 | } catch (Exception ex) { |
| 85 | throw new Error(ex); | 85 | throw new Error(ex); |
| 86 | } | 86 | } |
| @@ -88,27 +88,27 @@ public class ConstPoolEditor { | |||
| 88 | 88 | ||
| 89 | public static ConstPool readPool(DataInputStream in) { | 89 | public static ConstPool readPool(DataInputStream in) { |
| 90 | try { | 90 | try { |
| 91 | return m_constructorPool.newInstance(in); | 91 | return constructorPool.newInstance(in); |
| 92 | } catch (Exception ex) { | 92 | } catch (Exception ex) { |
| 93 | throw new Error(ex); | 93 | throw new Error(ex); |
| 94 | } | 94 | } |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | public String getMemberrefClassname(int memberrefIndex) { | 97 | public String getMemberrefClassname(int memberrefIndex) { |
| 98 | return Descriptor.toJvmName(m_pool.getClassInfo(m_pool.getMemberClass(memberrefIndex))); | 98 | return Descriptor.toJvmName(this.pool.getClassInfo(this.pool.getMemberClass(memberrefIndex))); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | public String getMemberrefName(int memberrefIndex) { | 101 | public String getMemberrefName(int memberrefIndex) { |
| 102 | return m_pool.getUtf8Info(m_pool.getNameAndTypeName(m_pool.getMemberNameAndType(memberrefIndex))); | 102 | return this.pool.getUtf8Info(this.pool.getNameAndTypeName(this.pool.getMemberNameAndType(memberrefIndex))); |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | public String getMemberrefType(int memberrefIndex) { | 105 | public String getMemberrefType(int memberrefIndex) { |
| 106 | return m_pool.getUtf8Info(m_pool.getNameAndTypeDescriptor(m_pool.getMemberNameAndType(memberrefIndex))); | 106 | return this.pool.getUtf8Info(this.pool.getNameAndTypeDescriptor(this.pool.getMemberNameAndType(memberrefIndex))); |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | public ConstInfoAccessor getItem(int index) { | 109 | public ConstInfoAccessor getItem(int index) { |
| 110 | try { | 110 | try { |
| 111 | Object entry = m_getItem.invoke(m_pool, index); | 111 | Object entry = getItem.invoke(this.pool, index); |
| 112 | if (entry == null) { | 112 | if (entry == null) { |
| 113 | return null; | 113 | return null; |
| 114 | } | 114 | } |
| @@ -120,7 +120,7 @@ public class ConstPoolEditor { | |||
| 120 | 120 | ||
| 121 | public int addItem(Object item) { | 121 | public int addItem(Object item) { |
| 122 | try { | 122 | try { |
| 123 | return (Integer) m_addItem.invoke(m_pool, item); | 123 | return (Integer) addItem.invoke(this.pool, item); |
| 124 | } catch (Exception ex) { | 124 | } catch (Exception ex) { |
| 125 | throw new Error(ex); | 125 | throw new Error(ex); |
| 126 | } | 126 | } |
| @@ -128,7 +128,7 @@ public class ConstPoolEditor { | |||
| 128 | 128 | ||
| 129 | public int addItemForceNew(Object item) { | 129 | public int addItemForceNew(Object item) { |
| 130 | try { | 130 | try { |
| 131 | return (Integer) m_addItem0.invoke(m_pool, item); | 131 | return (Integer) addItem0.invoke(this.pool, item); |
| 132 | } catch (Exception ex) { | 132 | } catch (Exception ex) { |
| 133 | throw new Error(ex); | 133 | throw new Error(ex); |
| 134 | } | 134 | } |
| @@ -140,22 +140,22 @@ public class ConstPoolEditor { | |||
| 140 | // remove the item from the cache | 140 | // remove the item from the cache |
| 141 | HashMap cache = getCache(); | 141 | HashMap cache = getCache(); |
| 142 | if (cache != null) { | 142 | if (cache != null) { |
| 143 | Object item = getItem(m_pool.getSize() - 1); | 143 | Object item = getItem(this.pool.getSize() - 1); |
| 144 | cache.remove(item); | 144 | cache.remove(item); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | // remove the actual item | 147 | // remove the actual item |
| 148 | // based off of LongVector.addElement() | 148 | // based off of LongVector.addElement() |
| 149 | Object items = m_items.get(m_pool); | 149 | Object item = items.get(this.pool); |
| 150 | Object[][] objects = (Object[][]) m_objects.get(items); | 150 | Object[][] object = (Object[][]) objects.get(items); |
| 151 | int numElements = (Integer) m_elements.get(items) - 1; | 151 | int numElements = (Integer) elements.get(items) - 1; |
| 152 | int nth = numElements >> 7; | 152 | int nth = numElements >> 7; |
| 153 | int offset = numElements & (128 - 1); | 153 | int offset = numElements & (128 - 1); |
| 154 | objects[nth][offset] = null; | 154 | object[nth][offset] = null; |
| 155 | 155 | ||
| 156 | // decrement the number of items | 156 | // decrement the number of items |
| 157 | m_elements.set(items, numElements); | 157 | elements.set(item, numElements); |
| 158 | m_numItems.set(m_pool, (Integer) m_numItems.get(m_pool) - 1); | 158 | numItems.set(this.pool, (Integer) numItems.get(this.pool) - 1); |
| 159 | } catch (Exception ex) { | 159 | } catch (Exception ex) { |
| 160 | throw new Error(ex); | 160 | throw new Error(ex); |
| 161 | } | 161 | } |
| @@ -164,7 +164,7 @@ public class ConstPoolEditor { | |||
| 164 | @SuppressWarnings("rawtypes") | 164 | @SuppressWarnings("rawtypes") |
| 165 | public HashMap getCache() { | 165 | public HashMap getCache() { |
| 166 | try { | 166 | try { |
| 167 | return (HashMap) m_cache.get(m_pool); | 167 | return (HashMap) cache.get(this.pool); |
| 168 | } catch (Exception ex) { | 168 | } catch (Exception ex) { |
| 169 | throw new Error(ex); | 169 | throw new Error(ex); |
| 170 | } | 170 | } |
| @@ -183,7 +183,7 @@ public class ConstPoolEditor { | |||
| 183 | cache.remove(item); | 183 | cache.remove(item); |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | new MemberRefInfoAccessor(item).setNameAndTypeIndex(m_pool.addNameAndTypeInfo(newName, newType)); | 186 | new MemberRefInfoAccessor(item).setNameAndTypeIndex(this.pool.addNameAndTypeInfo(newName, newType)); |
| 187 | 187 | ||
| 188 | // update the cache | 188 | // update the cache |
| 189 | if (cache != null) { | 189 | if (cache != null) { |
| @@ -212,7 +212,7 @@ public class ConstPoolEditor { | |||
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | // add the new name and repoint the name-and-type to it | 214 | // add the new name and repoint the name-and-type to it |
| 215 | new ClassInfoAccessor(item).setNameIndex(m_pool.addUtf8Info(newName)); | 215 | new ClassInfoAccessor(item).setNameIndex(this.pool.addUtf8Info(newName)); |
| 216 | 216 | ||
| 217 | // update the cache | 217 | // update the cache |
| 218 | if (cache != null) { | 218 | if (cache != null) { |
| @@ -252,7 +252,7 @@ public class ConstPoolEditor { | |||
| 252 | 252 | ||
| 253 | public String dump() { | 253 | public String dump() { |
| 254 | StringBuilder buf = new StringBuilder(); | 254 | StringBuilder buf = new StringBuilder(); |
| 255 | for (int i = 1; i < m_pool.getSize(); i++) { | 255 | for (int i = 1; i < this.pool.getSize(); i++) { |
| 256 | buf.append(String.format("%4d", i)); | 256 | buf.append(String.format("%4d", i)); |
| 257 | buf.append(" "); | 257 | buf.append(" "); |
| 258 | buf.append(getItem(i).toString()); | 258 | buf.append(getItem(i).toString()); |
diff --git a/src/main/java/cuchaz/enigma/bytecode/InfoType.java b/src/main/java/cuchaz/enigma/bytecode/InfoType.java index 89940d9e..86e57ab5 100644 --- a/src/main/java/cuchaz/enigma/bytecode/InfoType.java +++ b/src/main/java/cuchaz/enigma/bytecode/InfoType.java | |||
| @@ -213,29 +213,29 @@ public enum InfoType { | |||
| 213 | } | 213 | } |
| 214 | }; | 214 | }; |
| 215 | 215 | ||
| 216 | private static Map<Integer, InfoType> m_types; | 216 | private static Map<Integer, InfoType> types; |
| 217 | 217 | ||
| 218 | static { | 218 | static { |
| 219 | m_types = Maps.newTreeMap(); | 219 | types = Maps.newTreeMap(); |
| 220 | for (InfoType type : values()) { | 220 | for (InfoType type : values()) { |
| 221 | m_types.put(type.getTag(), type); | 221 | types.put(type.getTag(), type); |
| 222 | } | 222 | } |
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | private int m_tag; | 225 | private int tag; |
| 226 | private int m_level; | 226 | private int level; |
| 227 | 227 | ||
| 228 | InfoType(int tag, int level) { | 228 | InfoType(int tag, int level) { |
| 229 | m_tag = tag; | 229 | this.tag = tag; |
| 230 | m_level = level; | 230 | this.level = level; |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | public int getTag() { | 233 | public int getTag() { |
| 234 | return m_tag; | 234 | return this.tag; |
| 235 | } | 235 | } |
| 236 | 236 | ||
| 237 | public int getLevel() { | 237 | public int getLevel() { |
| 238 | return m_level; | 238 | return this.level; |
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | public void gatherIndexTree(Collection<Integer> indices, ConstPoolEditor editor, ConstInfoAccessor entry) { | 241 | public void gatherIndexTree(Collection<Integer> indices, ConstPoolEditor editor, ConstInfoAccessor entry) { |
| @@ -260,7 +260,7 @@ public enum InfoType { | |||
| 260 | } | 260 | } |
| 261 | 261 | ||
| 262 | public static InfoType getByTag(int tag) { | 262 | public static InfoType getByTag(int tag) { |
| 263 | return m_types.get(tag); | 263 | return types.get(tag); |
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | public static List<InfoType> getByLevel(int level) { | 266 | public static List<InfoType> getByLevel(int level) { |
diff --git a/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java b/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java index 25ac7d67..6d926106 100644 --- a/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java +++ b/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java | |||
| @@ -27,10 +27,10 @@ import javassist.bytecode.InnerClassesAttribute; | |||
| 27 | 27 | ||
| 28 | public class InnerClassWriter { | 28 | public class InnerClassWriter { |
| 29 | 29 | ||
| 30 | private JarIndex m_index; | 30 | private JarIndex index; |
| 31 | 31 | ||
| 32 | public InnerClassWriter(JarIndex index) { | 32 | public InnerClassWriter(JarIndex index) { |
| 33 | m_index = index; | 33 | this.index = index; |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | public void write(CtClass c) { | 36 | public void write(CtClass c) { |
| @@ -43,7 +43,7 @@ public class InnerClassWriter { | |||
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | ClassEntry obfClassEntry = EntryFactory.getClassEntry(c); | 45 | ClassEntry obfClassEntry = EntryFactory.getClassEntry(c); |
| 46 | List<ClassEntry> obfClassChain = m_index.getObfClassChain(obfClassEntry); | 46 | List<ClassEntry> obfClassChain = this.index.getObfClassChain(obfClassEntry); |
| 47 | 47 | ||
| 48 | boolean isInnerClass = obfClassChain.size() > 1; | 48 | boolean isInnerClass = obfClassChain.size() > 1; |
| 49 | if (isInnerClass) { | 49 | if (isInnerClass) { |
| @@ -51,7 +51,7 @@ public class InnerClassWriter { | |||
| 51 | // it's an inner class, rename it to the fully qualified name | 51 | // it's an inner class, rename it to the fully qualified name |
| 52 | c.setName(obfClassEntry.buildClassEntry(obfClassChain).getName()); | 52 | c.setName(obfClassEntry.buildClassEntry(obfClassChain).getName()); |
| 53 | 53 | ||
| 54 | BehaviorEntry caller = m_index.getAnonymousClassCaller(obfClassEntry); | 54 | BehaviorEntry caller = this.index.getAnonymousClassCaller(obfClassEntry); |
| 55 | if (caller != null) { | 55 | if (caller != null) { |
| 56 | 56 | ||
| 57 | // write the enclosing method attribute | 57 | // write the enclosing method attribute |
| @@ -64,7 +64,7 @@ public class InnerClassWriter { | |||
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | // does this class have any inner classes? | 66 | // does this class have any inner classes? |
| 67 | Collection<ClassEntry> obfInnerClassEntries = m_index.getInnerClasses(obfClassEntry); | 67 | Collection<ClassEntry> obfInnerClassEntries = this.index.getInnerClasses(obfClassEntry); |
| 68 | 68 | ||
| 69 | if (isInnerClass || !obfInnerClassEntries.isEmpty()) { | 69 | if (isInnerClass || !obfInnerClassEntries.isEmpty()) { |
| 70 | 70 | ||
| @@ -112,14 +112,14 @@ public class InnerClassWriter { | |||
| 112 | int innerClassNameIndex = 0; | 112 | int innerClassNameIndex = 0; |
| 113 | int accessFlags = AccessFlag.PUBLIC; | 113 | int accessFlags = AccessFlag.PUBLIC; |
| 114 | // TODO: need to figure out if we can put static or not | 114 | // TODO: need to figure out if we can put static or not |
| 115 | if (!m_index.isAnonymousClass(obfClassEntry)) { | 115 | if (!this.index.isAnonymousClass(obfClassEntry)) { |
| 116 | innerClassNameIndex = constPool.addUtf8Info(obfInnerClassEntry.getInnermostClassName()); | 116 | innerClassNameIndex = constPool.addUtf8Info(obfInnerClassEntry.getInnermostClassName()); |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | attr.append(innerClassIndex, parentClassIndex, innerClassNameIndex, accessFlags); | 119 | attr.append(innerClassIndex, parentClassIndex, innerClassNameIndex, accessFlags); |
| 120 | 120 | ||
| 121 | /* DEBUG | 121 | /* DEBUG |
| 122 | System.out.println(String.format("\tOBF: %s -> ATTR: %s,%s,%s (replace %s with %s)", | 122 | System.out.println(String.format("\tOBF: %s -> ATTR: %s,%s,%s (replace %s with %s)", |
| 123 | obfClassEntry, | 123 | obfClassEntry, |
| 124 | attr.innerClass(attr.tableLength() - 1), | 124 | attr.innerClass(attr.tableLength() - 1), |
| 125 | attr.outerClass(attr.tableLength() - 1), | 125 | attr.outerClass(attr.tableLength() - 1), |
diff --git a/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java b/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java index d0ce107f..8edea16e 100644 --- a/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java +++ b/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java | |||
| @@ -21,10 +21,10 @@ import javassist.bytecode.*; | |||
| 21 | 21 | ||
| 22 | public class LocalVariableRenamer { | 22 | public class LocalVariableRenamer { |
| 23 | 23 | ||
| 24 | private Translator m_translator; | 24 | private Translator translator; |
| 25 | 25 | ||
| 26 | public LocalVariableRenamer(Translator translator) { | 26 | public LocalVariableRenamer(Translator translator) { |
| 27 | m_translator = translator; | 27 | this.translator = translator; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | public void rename(CtClass c) { | 30 | public void rename(CtClass c) { |
| @@ -81,7 +81,7 @@ public class LocalVariableRenamer { | |||
| 81 | numArgs = behaviorEntry.getSignature().getArgumentTypes().size(); | 81 | numArgs = behaviorEntry.getSignature().getArgumentTypes().size(); |
| 82 | for (int i = starti; i < starti + numArgs && i < table.tableLength(); i++) { | 82 | for (int i = starti; i < starti + numArgs && i < table.tableLength(); i++) { |
| 83 | int argi = i - starti; | 83 | int argi = i - starti; |
| 84 | String argName = m_translator.translate(new ArgumentEntry(behaviorEntry, argi, "")); | 84 | String argName = this.translator.translate(new ArgumentEntry(behaviorEntry, argi, "")); |
| 85 | if (argName == null) { | 85 | if (argName == null) { |
| 86 | argName = "a" + (argi + 1); | 86 | argName = "a" + (argi + 1); |
| 87 | } | 87 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java b/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java index e53e8e70..17ecbbe9 100644 --- a/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java +++ b/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java | |||
| @@ -21,10 +21,10 @@ import javassist.bytecode.LocalVariableAttribute; | |||
| 21 | 21 | ||
| 22 | public class MethodParameterWriter { | 22 | public class MethodParameterWriter { |
| 23 | 23 | ||
| 24 | private Translator m_translator; | 24 | private Translator translator; |
| 25 | 25 | ||
| 26 | public MethodParameterWriter(Translator translator) { | 26 | public MethodParameterWriter(Translator translator) { |
| 27 | m_translator = translator; | 27 | this.translator = translator; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | public void writeMethodArguments(CtClass c) { | 30 | public void writeMethodArguments(CtClass c) { |
| @@ -56,7 +56,7 @@ public class MethodParameterWriter { | |||
| 56 | // get the list of argument names | 56 | // get the list of argument names |
| 57 | List<String> names = new ArrayList<String>(numParams); | 57 | List<String> names = new ArrayList<String>(numParams); |
| 58 | for (int i = 0; i < numParams; i++) { | 58 | for (int i = 0; i < numParams; i++) { |
| 59 | names.add(m_translator.translate(new ArgumentEntry(behaviorEntry, i, ""))); | 59 | names.add(this.translator.translate(new ArgumentEntry(behaviorEntry, i, ""))); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | // save the mappings to the class | 62 | // save the mappings to the class |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java index fd987f53..66f22839 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java | |||
| @@ -14,32 +14,18 @@ import java.lang.reflect.Field; | |||
| 14 | 14 | ||
| 15 | public class ClassInfoAccessor { | 15 | public class ClassInfoAccessor { |
| 16 | 16 | ||
| 17 | private static Class<?> m_class; | 17 | private Object item; |
| 18 | private static Field m_nameIndex; | ||
| 19 | 18 | ||
| 20 | static { | 19 | private static Class<?> clazz; |
| 21 | try { | 20 | private static Field nameIndex; |
| 22 | m_class = Class.forName("javassist.bytecode.ClassInfo"); | ||
| 23 | m_nameIndex = m_class.getDeclaredField("name"); | ||
| 24 | m_nameIndex.setAccessible(true); | ||
| 25 | } catch (Exception ex) { | ||
| 26 | throw new Error(ex); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 31 | return m_class.isAssignableFrom(accessor.getItem().getClass()); | ||
| 32 | } | ||
| 33 | |||
| 34 | private Object m_item; | ||
| 35 | 21 | ||
| 36 | public ClassInfoAccessor(Object item) { | 22 | public ClassInfoAccessor(Object item) { |
| 37 | m_item = item; | 23 | this.item = item; |
| 38 | } | 24 | } |
| 39 | 25 | ||
| 40 | public int getNameIndex() { | 26 | public int getNameIndex() { |
| 41 | try { | 27 | try { |
| 42 | return (Integer) m_nameIndex.get(m_item); | 28 | return (Integer) nameIndex.get(this.item); |
| 43 | } catch (Exception ex) { | 29 | } catch (Exception ex) { |
| 44 | throw new Error(ex); | 30 | throw new Error(ex); |
| 45 | } | 31 | } |
| @@ -47,7 +33,21 @@ public class ClassInfoAccessor { | |||
| 47 | 33 | ||
| 48 | public void setNameIndex(int val) { | 34 | public void setNameIndex(int val) { |
| 49 | try { | 35 | try { |
| 50 | m_nameIndex.set(m_item, val); | 36 | nameIndex.set(this.item, val); |
| 37 | } catch (Exception ex) { | ||
| 38 | throw new Error(ex); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 43 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 44 | } | ||
| 45 | |||
| 46 | static { | ||
| 47 | try { | ||
| 48 | clazz = Class.forName("javassist.bytecode.ClassInfo"); | ||
| 49 | nameIndex = clazz.getDeclaredField("name"); | ||
| 50 | nameIndex.setAccessible(true); | ||
| 51 | } catch (Exception ex) { | 51 | } catch (Exception ex) { |
| 52 | throw new Error(ex); | 52 | throw new Error(ex); |
| 53 | } | 53 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java index 2692c069..ea775e9c 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java | |||
| @@ -19,29 +19,17 @@ import cuchaz.enigma.bytecode.InfoType; | |||
| 19 | 19 | ||
| 20 | public class ConstInfoAccessor { | 20 | public class ConstInfoAccessor { |
| 21 | 21 | ||
| 22 | private static Class<?> m_class; | 22 | private static Class<?> clazz; |
| 23 | private static Field m_index; | 23 | private static Field index; |
| 24 | private static Method m_getTag; | 24 | private static Method getTag; |
| 25 | 25 | ||
| 26 | static { | 26 | private Object item; |
| 27 | try { | ||
| 28 | m_class = Class.forName("javassist.bytecode.ConstInfo"); | ||
| 29 | m_index = m_class.getDeclaredField("index"); | ||
| 30 | m_index.setAccessible(true); | ||
| 31 | m_getTag = m_class.getMethod("getTag"); | ||
| 32 | m_getTag.setAccessible(true); | ||
| 33 | } catch (Exception ex) { | ||
| 34 | throw new Error(ex); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | private Object m_item; | ||
| 39 | 27 | ||
| 40 | public ConstInfoAccessor(Object item) { | 28 | public ConstInfoAccessor(Object item) { |
| 41 | if (item == null) { | 29 | if (item == null) { |
| 42 | throw new IllegalArgumentException("item cannot be null!"); | 30 | throw new IllegalArgumentException("item cannot be null!"); |
| 43 | } | 31 | } |
| 44 | m_item = item; | 32 | this.item = item; |
| 45 | } | 33 | } |
| 46 | 34 | ||
| 47 | public ConstInfoAccessor(DataInputStream in) throws IOException { | 35 | public ConstInfoAccessor(DataInputStream in) throws IOException { |
| @@ -56,7 +44,7 @@ public class ConstInfoAccessor { | |||
| 56 | 44 | ||
| 57 | Constructor<?> constructor = Class.forName(className).getConstructor(DataInputStream.class, int.class); | 45 | Constructor<?> constructor = Class.forName(className).getConstructor(DataInputStream.class, int.class); |
| 58 | constructor.setAccessible(true); | 46 | constructor.setAccessible(true); |
| 59 | m_item = constructor.newInstance(in, oldIndex); | 47 | this.item = constructor.newInstance(in, oldIndex); |
| 60 | } catch (IOException ex) { | 48 | } catch (IOException ex) { |
| 61 | throw ex; | 49 | throw ex; |
| 62 | } catch (Exception ex) { | 50 | } catch (Exception ex) { |
| @@ -65,12 +53,12 @@ public class ConstInfoAccessor { | |||
| 65 | } | 53 | } |
| 66 | 54 | ||
| 67 | public Object getItem() { | 55 | public Object getItem() { |
| 68 | return m_item; | 56 | return this.item; |
| 69 | } | 57 | } |
| 70 | 58 | ||
| 71 | public int getIndex() { | 59 | public int getIndex() { |
| 72 | try { | 60 | try { |
| 73 | return (Integer) m_index.get(m_item); | 61 | return (Integer) index.get(this.item); |
| 74 | } catch (Exception ex) { | 62 | } catch (Exception ex) { |
| 75 | throw new Error(ex); | 63 | throw new Error(ex); |
| 76 | } | 64 | } |
| @@ -78,7 +66,7 @@ public class ConstInfoAccessor { | |||
| 78 | 66 | ||
| 79 | public void setIndex(int val) { | 67 | public void setIndex(int val) { |
| 80 | try { | 68 | try { |
| 81 | m_index.set(m_item, val); | 69 | index.set(this.item, val); |
| 82 | } catch (Exception ex) { | 70 | } catch (Exception ex) { |
| 83 | throw new Error(ex); | 71 | throw new Error(ex); |
| 84 | } | 72 | } |
| @@ -86,7 +74,7 @@ public class ConstInfoAccessor { | |||
| 86 | 74 | ||
| 87 | public int getTag() { | 75 | public int getTag() { |
| 88 | try { | 76 | try { |
| 89 | return (Integer) m_getTag.invoke(m_item); | 77 | return (Integer) getTag.invoke(this.item); |
| 90 | } catch (Exception ex) { | 78 | } catch (Exception ex) { |
| 91 | throw new Error(ex); | 79 | throw new Error(ex); |
| 92 | } | 80 | } |
| @@ -117,12 +105,12 @@ public class ConstInfoAccessor { | |||
| 117 | 105 | ||
| 118 | public void write(DataOutputStream out) throws IOException { | 106 | public void write(DataOutputStream out) throws IOException { |
| 119 | try { | 107 | try { |
| 120 | out.writeUTF(m_item.getClass().getName()); | 108 | out.writeUTF(this.item.getClass().getName()); |
| 121 | out.writeInt(getIndex()); | 109 | out.writeInt(getIndex()); |
| 122 | 110 | ||
| 123 | Method method = m_item.getClass().getMethod("write", DataOutputStream.class); | 111 | Method method = this.item.getClass().getMethod("write", DataOutputStream.class); |
| 124 | method.setAccessible(true); | 112 | method.setAccessible(true); |
| 125 | method.invoke(m_item, out); | 113 | method.invoke(this.item, out); |
| 126 | } catch (IOException ex) { | 114 | } catch (IOException ex) { |
| 127 | throw ex; | 115 | throw ex; |
| 128 | } catch (Exception ex) { | 116 | } catch (Exception ex) { |
| @@ -135,9 +123,9 @@ public class ConstInfoAccessor { | |||
| 135 | try { | 123 | try { |
| 136 | ByteArrayOutputStream buf = new ByteArrayOutputStream(); | 124 | ByteArrayOutputStream buf = new ByteArrayOutputStream(); |
| 137 | PrintWriter out = new PrintWriter(buf); | 125 | PrintWriter out = new PrintWriter(buf); |
| 138 | Method print = m_item.getClass().getMethod("print", PrintWriter.class); | 126 | Method print = this.item.getClass().getMethod("print", PrintWriter.class); |
| 139 | print.setAccessible(true); | 127 | print.setAccessible(true); |
| 140 | print.invoke(m_item, out); | 128 | print.invoke(this.item, out); |
| 141 | out.close(); | 129 | out.close(); |
| 142 | return buf.toString().replace("\n", ""); | 130 | return buf.toString().replace("\n", ""); |
| 143 | } catch (Exception ex) { | 131 | } catch (Exception ex) { |
| @@ -148,4 +136,16 @@ public class ConstInfoAccessor { | |||
| 148 | public InfoType getType() { | 136 | public InfoType getType() { |
| 149 | return InfoType.getByTag(getTag()); | 137 | return InfoType.getByTag(getTag()); |
| 150 | } | 138 | } |
| 139 | |||
| 140 | static { | ||
| 141 | try { | ||
| 142 | clazz = Class.forName("javassist.bytecode.ConstInfo"); | ||
| 143 | index = clazz.getDeclaredField("index"); | ||
| 144 | index.setAccessible(true); | ||
| 145 | getTag = clazz.getMethod("getTag"); | ||
| 146 | getTag.setAccessible(true); | ||
| 147 | } catch (Exception ex) { | ||
| 148 | throw new Error(ex); | ||
| 149 | } | ||
| 150 | } | ||
| 151 | } | 151 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java index 0ca82b78..69aee160 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java | |||
| @@ -14,35 +14,20 @@ import java.lang.reflect.Field; | |||
| 14 | 14 | ||
| 15 | public class InvokeDynamicInfoAccessor { | 15 | public class InvokeDynamicInfoAccessor { |
| 16 | 16 | ||
| 17 | private static Class<?> m_class; | 17 | private static Class<?> clazz; |
| 18 | private static Field m_bootstrapIndex; | 18 | private static Field bootstrapIndex; |
| 19 | private static Field m_nameAndTypeIndex; | 19 | private static Field nameAndTypeIndex; |
| 20 | 20 | ||
| 21 | static { | ||
| 22 | try { | ||
| 23 | m_class = Class.forName("javassist.bytecode.InvokeDynamicInfo"); | ||
| 24 | m_bootstrapIndex = m_class.getDeclaredField("bootstrap"); | ||
| 25 | m_bootstrapIndex.setAccessible(true); | ||
| 26 | m_nameAndTypeIndex = m_class.getDeclaredField("nameAndType"); | ||
| 27 | m_nameAndTypeIndex.setAccessible(true); | ||
| 28 | } catch (Exception ex) { | ||
| 29 | throw new Error(ex); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | 21 | ||
| 33 | public static boolean isType(ConstInfoAccessor accessor) { | 22 | private Object item; |
| 34 | return m_class.isAssignableFrom(accessor.getItem().getClass()); | ||
| 35 | } | ||
| 36 | |||
| 37 | private Object m_item; | ||
| 38 | 23 | ||
| 39 | public InvokeDynamicInfoAccessor(Object item) { | 24 | public InvokeDynamicInfoAccessor(Object item) { |
| 40 | m_item = item; | 25 | this.item = item; |
| 41 | } | 26 | } |
| 42 | 27 | ||
| 43 | public int getBootstrapIndex() { | 28 | public int getBootstrapIndex() { |
| 44 | try { | 29 | try { |
| 45 | return (Integer) m_bootstrapIndex.get(m_item); | 30 | return (Integer) bootstrapIndex.get(this.item); |
| 46 | } catch (Exception ex) { | 31 | } catch (Exception ex) { |
| 47 | throw new Error(ex); | 32 | throw new Error(ex); |
| 48 | } | 33 | } |
| @@ -50,7 +35,7 @@ public class InvokeDynamicInfoAccessor { | |||
| 50 | 35 | ||
| 51 | public void setBootstrapIndex(int val) { | 36 | public void setBootstrapIndex(int val) { |
| 52 | try { | 37 | try { |
| 53 | m_bootstrapIndex.set(m_item, val); | 38 | bootstrapIndex.set(this.item, val); |
| 54 | } catch (Exception ex) { | 39 | } catch (Exception ex) { |
| 55 | throw new Error(ex); | 40 | throw new Error(ex); |
| 56 | } | 41 | } |
| @@ -58,7 +43,7 @@ public class InvokeDynamicInfoAccessor { | |||
| 58 | 43 | ||
| 59 | public int getNameAndTypeIndex() { | 44 | public int getNameAndTypeIndex() { |
| 60 | try { | 45 | try { |
| 61 | return (Integer) m_nameAndTypeIndex.get(m_item); | 46 | return (Integer) nameAndTypeIndex.get(this.item); |
| 62 | } catch (Exception ex) { | 47 | } catch (Exception ex) { |
| 63 | throw new Error(ex); | 48 | throw new Error(ex); |
| 64 | } | 49 | } |
| @@ -66,7 +51,23 @@ public class InvokeDynamicInfoAccessor { | |||
| 66 | 51 | ||
| 67 | public void setNameAndTypeIndex(int val) { | 52 | public void setNameAndTypeIndex(int val) { |
| 68 | try { | 53 | try { |
| 69 | m_nameAndTypeIndex.set(m_item, val); | 54 | nameAndTypeIndex.set(this.item, val); |
| 55 | } catch (Exception ex) { | ||
| 56 | throw new Error(ex); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 61 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 62 | } | ||
| 63 | |||
| 64 | static { | ||
| 65 | try { | ||
| 66 | clazz = Class.forName("javassist.bytecode.InvokeDynamicInfo"); | ||
| 67 | bootstrapIndex = clazz.getDeclaredField("bootstrap"); | ||
| 68 | bootstrapIndex.setAccessible(true); | ||
| 69 | nameAndTypeIndex = clazz.getDeclaredField("nameAndType"); | ||
| 70 | nameAndTypeIndex.setAccessible(true); | ||
| 70 | } catch (Exception ex) { | 71 | } catch (Exception ex) { |
| 71 | throw new Error(ex); | 72 | throw new Error(ex); |
| 72 | } | 73 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java index bb9d16bc..0e0297be 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java | |||
| @@ -14,35 +14,19 @@ import java.lang.reflect.Field; | |||
| 14 | 14 | ||
| 15 | public class MemberRefInfoAccessor { | 15 | public class MemberRefInfoAccessor { |
| 16 | 16 | ||
| 17 | private static Class<?> m_class; | 17 | private static Class<?> clazz; |
| 18 | private static Field m_classIndex; | 18 | private static Field classIndex; |
| 19 | private static Field m_nameAndTypeIndex; | 19 | private static Field nameAndTypeIndex; |
| 20 | 20 | ||
| 21 | static { | 21 | private Object item; |
| 22 | try { | ||
| 23 | m_class = Class.forName("javassist.bytecode.MemberrefInfo"); | ||
| 24 | m_classIndex = m_class.getDeclaredField("classIndex"); | ||
| 25 | m_classIndex.setAccessible(true); | ||
| 26 | m_nameAndTypeIndex = m_class.getDeclaredField("nameAndTypeIndex"); | ||
| 27 | m_nameAndTypeIndex.setAccessible(true); | ||
| 28 | } catch (Exception ex) { | ||
| 29 | throw new Error(ex); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 34 | return m_class.isAssignableFrom(accessor.getItem().getClass()); | ||
| 35 | } | ||
| 36 | |||
| 37 | private Object m_item; | ||
| 38 | 22 | ||
| 39 | public MemberRefInfoAccessor(Object item) { | 23 | public MemberRefInfoAccessor(Object item) { |
| 40 | m_item = item; | 24 | this.item = item; |
| 41 | } | 25 | } |
| 42 | 26 | ||
| 43 | public int getClassIndex() { | 27 | public int getClassIndex() { |
| 44 | try { | 28 | try { |
| 45 | return (Integer) m_classIndex.get(m_item); | 29 | return (Integer) classIndex.get(this.item); |
| 46 | } catch (Exception ex) { | 30 | } catch (Exception ex) { |
| 47 | throw new Error(ex); | 31 | throw new Error(ex); |
| 48 | } | 32 | } |
| @@ -50,7 +34,7 @@ public class MemberRefInfoAccessor { | |||
| 50 | 34 | ||
| 51 | public void setClassIndex(int val) { | 35 | public void setClassIndex(int val) { |
| 52 | try { | 36 | try { |
| 53 | m_classIndex.set(m_item, val); | 37 | classIndex.set(this.item, val); |
| 54 | } catch (Exception ex) { | 38 | } catch (Exception ex) { |
| 55 | throw new Error(ex); | 39 | throw new Error(ex); |
| 56 | } | 40 | } |
| @@ -58,7 +42,7 @@ public class MemberRefInfoAccessor { | |||
| 58 | 42 | ||
| 59 | public int getNameAndTypeIndex() { | 43 | public int getNameAndTypeIndex() { |
| 60 | try { | 44 | try { |
| 61 | return (Integer) m_nameAndTypeIndex.get(m_item); | 45 | return (Integer) nameAndTypeIndex.get(this.item); |
| 62 | } catch (Exception ex) { | 46 | } catch (Exception ex) { |
| 63 | throw new Error(ex); | 47 | throw new Error(ex); |
| 64 | } | 48 | } |
| @@ -66,7 +50,23 @@ public class MemberRefInfoAccessor { | |||
| 66 | 50 | ||
| 67 | public void setNameAndTypeIndex(int val) { | 51 | public void setNameAndTypeIndex(int val) { |
| 68 | try { | 52 | try { |
| 69 | m_nameAndTypeIndex.set(m_item, val); | 53 | nameAndTypeIndex.set(this.item, val); |
| 54 | } catch (Exception ex) { | ||
| 55 | throw new Error(ex); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 60 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 61 | } | ||
| 62 | |||
| 63 | static { | ||
| 64 | try { | ||
| 65 | clazz = Class.forName("javassist.bytecode.MemberrefInfo"); | ||
| 66 | classIndex = clazz.getDeclaredField("classIndex"); | ||
| 67 | classIndex.setAccessible(true); | ||
| 68 | nameAndTypeIndex = clazz.getDeclaredField("nameAndTypeIndex"); | ||
| 69 | nameAndTypeIndex.setAccessible(true); | ||
| 70 | } catch (Exception ex) { | 70 | } catch (Exception ex) { |
| 71 | throw new Error(ex); | 71 | throw new Error(ex); |
| 72 | } | 72 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java index 88e42f46..9a7dd698 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java | |||
| @@ -14,35 +14,19 @@ import java.lang.reflect.Field; | |||
| 14 | 14 | ||
| 15 | public class MethodHandleInfoAccessor { | 15 | public class MethodHandleInfoAccessor { |
| 16 | 16 | ||
| 17 | private static Class<?> m_class; | 17 | private static Class<?> clazz; |
| 18 | private static Field m_kindIndex; | 18 | private static Field kindIndex; |
| 19 | private static Field m_indexIndex; | 19 | private static Field indexIndex; |
| 20 | 20 | ||
| 21 | static { | 21 | private Object item; |
| 22 | try { | ||
| 23 | m_class = Class.forName("javassist.bytecode.MethodHandleInfo"); | ||
| 24 | m_kindIndex = m_class.getDeclaredField("refKind"); | ||
| 25 | m_kindIndex.setAccessible(true); | ||
| 26 | m_indexIndex = m_class.getDeclaredField("refIndex"); | ||
| 27 | m_indexIndex.setAccessible(true); | ||
| 28 | } catch (Exception ex) { | ||
| 29 | throw new Error(ex); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 34 | return m_class.isAssignableFrom(accessor.getItem().getClass()); | ||
| 35 | } | ||
| 36 | |||
| 37 | private Object m_item; | ||
| 38 | 22 | ||
| 39 | public MethodHandleInfoAccessor(Object item) { | 23 | public MethodHandleInfoAccessor(Object item) { |
| 40 | m_item = item; | 24 | this.item = item; |
| 41 | } | 25 | } |
| 42 | 26 | ||
| 43 | public int getTypeIndex() { | 27 | public int getTypeIndex() { |
| 44 | try { | 28 | try { |
| 45 | return (Integer) m_kindIndex.get(m_item); | 29 | return (Integer) kindIndex.get(this.item); |
| 46 | } catch (Exception ex) { | 30 | } catch (Exception ex) { |
| 47 | throw new Error(ex); | 31 | throw new Error(ex); |
| 48 | } | 32 | } |
| @@ -50,7 +34,7 @@ public class MethodHandleInfoAccessor { | |||
| 50 | 34 | ||
| 51 | public void setTypeIndex(int val) { | 35 | public void setTypeIndex(int val) { |
| 52 | try { | 36 | try { |
| 53 | m_kindIndex.set(m_item, val); | 37 | kindIndex.set(this.item, val); |
| 54 | } catch (Exception ex) { | 38 | } catch (Exception ex) { |
| 55 | throw new Error(ex); | 39 | throw new Error(ex); |
| 56 | } | 40 | } |
| @@ -58,7 +42,7 @@ public class MethodHandleInfoAccessor { | |||
| 58 | 42 | ||
| 59 | public int getMethodRefIndex() { | 43 | public int getMethodRefIndex() { |
| 60 | try { | 44 | try { |
| 61 | return (Integer) m_indexIndex.get(m_item); | 45 | return (Integer) indexIndex.get(this.item); |
| 62 | } catch (Exception ex) { | 46 | } catch (Exception ex) { |
| 63 | throw new Error(ex); | 47 | throw new Error(ex); |
| 64 | } | 48 | } |
| @@ -66,7 +50,23 @@ public class MethodHandleInfoAccessor { | |||
| 66 | 50 | ||
| 67 | public void setMethodRefIndex(int val) { | 51 | public void setMethodRefIndex(int val) { |
| 68 | try { | 52 | try { |
| 69 | m_indexIndex.set(m_item, val); | 53 | indexIndex.set(this.item, val); |
| 54 | } catch (Exception ex) { | ||
| 55 | throw new Error(ex); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 60 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 61 | } | ||
| 62 | |||
| 63 | static { | ||
| 64 | try { | ||
| 65 | clazz = Class.forName("javassist.bytecode.MethodHandleInfo"); | ||
| 66 | kindIndex = clazz.getDeclaredField("refKind"); | ||
| 67 | kindIndex.setAccessible(true); | ||
| 68 | indexIndex = clazz.getDeclaredField("refIndex"); | ||
| 69 | indexIndex.setAccessible(true); | ||
| 70 | } catch (Exception ex) { | 70 | } catch (Exception ex) { |
| 71 | throw new Error(ex); | 71 | throw new Error(ex); |
| 72 | } | 72 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java index 1d039f6c..5ec9c3b4 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java | |||
| @@ -14,32 +14,18 @@ import java.lang.reflect.Field; | |||
| 14 | 14 | ||
| 15 | public class MethodTypeInfoAccessor { | 15 | public class MethodTypeInfoAccessor { |
| 16 | 16 | ||
| 17 | private static Class<?> m_class; | 17 | private static Class<?> clazz; |
| 18 | private static Field m_descriptorIndex; | 18 | private static Field descriptorIndex; |
| 19 | 19 | ||
| 20 | static { | 20 | private Object item; |
| 21 | try { | ||
| 22 | m_class = Class.forName("javassist.bytecode.MethodTypeInfo"); | ||
| 23 | m_descriptorIndex = m_class.getDeclaredField("descriptor"); | ||
| 24 | m_descriptorIndex.setAccessible(true); | ||
| 25 | } catch (Exception ex) { | ||
| 26 | throw new Error(ex); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 31 | return m_class.isAssignableFrom(accessor.getItem().getClass()); | ||
| 32 | } | ||
| 33 | |||
| 34 | private Object m_item; | ||
| 35 | 21 | ||
| 36 | public MethodTypeInfoAccessor(Object item) { | 22 | public MethodTypeInfoAccessor(Object item) { |
| 37 | m_item = item; | 23 | this.item = item; |
| 38 | } | 24 | } |
| 39 | 25 | ||
| 40 | public int getTypeIndex() { | 26 | public int getTypeIndex() { |
| 41 | try { | 27 | try { |
| 42 | return (Integer) m_descriptorIndex.get(m_item); | 28 | return (Integer) descriptorIndex.get(this.item); |
| 43 | } catch (Exception ex) { | 29 | } catch (Exception ex) { |
| 44 | throw new Error(ex); | 30 | throw new Error(ex); |
| 45 | } | 31 | } |
| @@ -47,9 +33,24 @@ public class MethodTypeInfoAccessor { | |||
| 47 | 33 | ||
| 48 | public void setTypeIndex(int val) { | 34 | public void setTypeIndex(int val) { |
| 49 | try { | 35 | try { |
| 50 | m_descriptorIndex.set(m_item, val); | 36 | descriptorIndex.set(this.item, val); |
| 51 | } catch (Exception ex) { | 37 | } catch (Exception ex) { |
| 52 | throw new Error(ex); | 38 | throw new Error(ex); |
| 53 | } | 39 | } |
| 54 | } | 40 | } |
| 41 | |||
| 42 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 43 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 44 | } | ||
| 45 | |||
| 46 | static { | ||
| 47 | try { | ||
| 48 | clazz = Class.forName("javassist.bytecode.MethodTypeInfo"); | ||
| 49 | descriptorIndex = clazz.getDeclaredField("descriptor"); | ||
| 50 | descriptorIndex.setAccessible(true); | ||
| 51 | } catch (Exception ex) { | ||
| 52 | throw new Error(ex); | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 55 | } | 56 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java index acba7799..95df37c1 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java | |||
| @@ -14,35 +14,19 @@ import java.lang.reflect.Field; | |||
| 14 | 14 | ||
| 15 | public class NameAndTypeInfoAccessor { | 15 | public class NameAndTypeInfoAccessor { |
| 16 | 16 | ||
| 17 | private static Class<?> m_class; | 17 | private static Class<?> clazz; |
| 18 | private static Field m_nameIndex; | 18 | private static Field nameIndex; |
| 19 | private static Field m_typeIndex; | 19 | private static Field typeIndex; |
| 20 | 20 | ||
| 21 | static { | 21 | private Object item; |
| 22 | try { | ||
| 23 | m_class = Class.forName("javassist.bytecode.NameAndTypeInfo"); | ||
| 24 | m_nameIndex = m_class.getDeclaredField("memberName"); | ||
| 25 | m_nameIndex.setAccessible(true); | ||
| 26 | m_typeIndex = m_class.getDeclaredField("typeDescriptor"); | ||
| 27 | m_typeIndex.setAccessible(true); | ||
| 28 | } catch (Exception ex) { | ||
| 29 | throw new Error(ex); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 34 | return m_class.isAssignableFrom(accessor.getItem().getClass()); | ||
| 35 | } | ||
| 36 | |||
| 37 | private Object m_item; | ||
| 38 | 22 | ||
| 39 | public NameAndTypeInfoAccessor(Object item) { | 23 | public NameAndTypeInfoAccessor(Object item) { |
| 40 | m_item = item; | 24 | this.item = item; |
| 41 | } | 25 | } |
| 42 | 26 | ||
| 43 | public int getNameIndex() { | 27 | public int getNameIndex() { |
| 44 | try { | 28 | try { |
| 45 | return (Integer) m_nameIndex.get(m_item); | 29 | return (Integer) nameIndex.get(this.item); |
| 46 | } catch (Exception ex) { | 30 | } catch (Exception ex) { |
| 47 | throw new Error(ex); | 31 | throw new Error(ex); |
| 48 | } | 32 | } |
| @@ -50,7 +34,7 @@ public class NameAndTypeInfoAccessor { | |||
| 50 | 34 | ||
| 51 | public void setNameIndex(int val) { | 35 | public void setNameIndex(int val) { |
| 52 | try { | 36 | try { |
| 53 | m_nameIndex.set(m_item, val); | 37 | nameIndex.set(this.item, val); |
| 54 | } catch (Exception ex) { | 38 | } catch (Exception ex) { |
| 55 | throw new Error(ex); | 39 | throw new Error(ex); |
| 56 | } | 40 | } |
| @@ -58,7 +42,7 @@ public class NameAndTypeInfoAccessor { | |||
| 58 | 42 | ||
| 59 | public int getTypeIndex() { | 43 | public int getTypeIndex() { |
| 60 | try { | 44 | try { |
| 61 | return (Integer) m_typeIndex.get(m_item); | 45 | return (Integer) typeIndex.get(this.item); |
| 62 | } catch (Exception ex) { | 46 | } catch (Exception ex) { |
| 63 | throw new Error(ex); | 47 | throw new Error(ex); |
| 64 | } | 48 | } |
| @@ -66,7 +50,23 @@ public class NameAndTypeInfoAccessor { | |||
| 66 | 50 | ||
| 67 | public void setTypeIndex(int val) { | 51 | public void setTypeIndex(int val) { |
| 68 | try { | 52 | try { |
| 69 | m_typeIndex.set(m_item, val); | 53 | typeIndex.set(this.item, val); |
| 54 | } catch (Exception ex) { | ||
| 55 | throw new Error(ex); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 60 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 61 | } | ||
| 62 | |||
| 63 | static { | ||
| 64 | try { | ||
| 65 | clazz = Class.forName("javassist.bytecode.NameAndTypeInfo"); | ||
| 66 | nameIndex = clazz.getDeclaredField("memberName"); | ||
| 67 | nameIndex.setAccessible(true); | ||
| 68 | typeIndex = clazz.getDeclaredField("typeDescriptor"); | ||
| 69 | typeIndex.setAccessible(true); | ||
| 70 | } catch (Exception ex) { | 70 | } catch (Exception ex) { |
| 71 | throw new Error(ex); | 71 | throw new Error(ex); |
| 72 | } | 72 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java index b40e0eb2..1c55a443 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java | |||
| @@ -14,32 +14,18 @@ import java.lang.reflect.Field; | |||
| 14 | 14 | ||
| 15 | public class StringInfoAccessor { | 15 | public class StringInfoAccessor { |
| 16 | 16 | ||
| 17 | private static Class<?> m_class; | 17 | private static Class<?> clazz; |
| 18 | private static Field m_stringIndex; | 18 | private static Field stringIndex; |
| 19 | 19 | ||
| 20 | static { | 20 | private Object item; |
| 21 | try { | ||
| 22 | m_class = Class.forName("javassist.bytecode.StringInfo"); | ||
| 23 | m_stringIndex = m_class.getDeclaredField("string"); | ||
| 24 | m_stringIndex.setAccessible(true); | ||
| 25 | } catch (Exception ex) { | ||
| 26 | throw new Error(ex); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 31 | return m_class.isAssignableFrom(accessor.getItem().getClass()); | ||
| 32 | } | ||
| 33 | |||
| 34 | private Object m_item; | ||
| 35 | 21 | ||
| 36 | public StringInfoAccessor(Object item) { | 22 | public StringInfoAccessor(Object item) { |
| 37 | m_item = item; | 23 | this.item = item; |
| 38 | } | 24 | } |
| 39 | 25 | ||
| 40 | public int getStringIndex() { | 26 | public int getStringIndex() { |
| 41 | try { | 27 | try { |
| 42 | return (Integer) m_stringIndex.get(m_item); | 28 | return (Integer) stringIndex.get(this.item); |
| 43 | } catch (Exception ex) { | 29 | } catch (Exception ex) { |
| 44 | throw new Error(ex); | 30 | throw new Error(ex); |
| 45 | } | 31 | } |
| @@ -47,7 +33,21 @@ public class StringInfoAccessor { | |||
| 47 | 33 | ||
| 48 | public void setStringIndex(int val) { | 34 | public void setStringIndex(int val) { |
| 49 | try { | 35 | try { |
| 50 | m_stringIndex.set(m_item, val); | 36 | stringIndex.set(this.item, val); |
| 37 | } catch (Exception ex) { | ||
| 38 | throw new Error(ex); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 43 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 44 | } | ||
| 45 | |||
| 46 | static { | ||
| 47 | try { | ||
| 48 | clazz = Class.forName("javassist.bytecode.StringInfo"); | ||
| 49 | stringIndex = clazz.getDeclaredField("string"); | ||
| 50 | stringIndex.setAccessible(true); | ||
| 51 | } catch (Exception ex) { | 51 | } catch (Exception ex) { |
| 52 | throw new Error(ex); | 52 | throw new Error(ex); |
| 53 | } | 53 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java index 9303b41a..7a2cb667 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java | |||
| @@ -12,17 +12,17 @@ package cuchaz.enigma.bytecode.accessors; | |||
| 12 | 12 | ||
| 13 | public class Utf8InfoAccessor { | 13 | public class Utf8InfoAccessor { |
| 14 | 14 | ||
| 15 | private static Class<?> m_class; | 15 | private static Class<?> clazz; |
| 16 | 16 | ||
| 17 | static { | 17 | static { |
| 18 | try { | 18 | try { |
| 19 | m_class = Class.forName("javassist.bytecode.Utf8Info"); | 19 | clazz = Class.forName("javassist.bytecode.Utf8Info"); |
| 20 | } catch (Exception ex) { | 20 | } catch (Exception ex) { |
| 21 | throw new Error(ex); | 21 | throw new Error(ex); |
| 22 | } | 22 | } |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | public static boolean isType(ConstInfoAccessor accessor) { | 25 | public static boolean isType(ConstInfoAccessor accessor) { |
| 26 | return m_class.isAssignableFrom(accessor.getItem().getClass()); | 26 | return clazz.isAssignableFrom(accessor.getItem().getClass()); |
| 27 | } | 27 | } |
| 28 | } | 28 | } |
diff --git a/src/main/java/cuchaz/enigma/convert/ClassForest.java b/src/main/java/cuchaz/enigma/convert/ClassForest.java index 7123bbfb..b08d48fb 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassForest.java +++ b/src/main/java/cuchaz/enigma/convert/ClassForest.java | |||
| @@ -20,12 +20,12 @@ import cuchaz.enigma.mapping.ClassEntry; | |||
| 20 | 20 | ||
| 21 | public class ClassForest { | 21 | public class ClassForest { |
| 22 | 22 | ||
| 23 | private ClassIdentifier m_identifier; | 23 | private ClassIdentifier identifier; |
| 24 | private Multimap<ClassIdentity, ClassEntry> m_forest; | 24 | private Multimap<ClassIdentity, ClassEntry> forest; |
| 25 | 25 | ||
| 26 | public ClassForest(ClassIdentifier identifier) { | 26 | public ClassForest(ClassIdentifier identifier) { |
| 27 | m_identifier = identifier; | 27 | this.identifier = identifier; |
| 28 | m_forest = HashMultimap.create(); | 28 | this.forest = HashMultimap.create(); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | public void addAll(Iterable<ClassEntry> entries) { | 31 | public void addAll(Iterable<ClassEntry> entries) { |
| @@ -36,25 +36,25 @@ public class ClassForest { | |||
| 36 | 36 | ||
| 37 | public void add(ClassEntry entry) { | 37 | public void add(ClassEntry entry) { |
| 38 | try { | 38 | try { |
| 39 | m_forest.put(m_identifier.identify(entry), entry); | 39 | this.forest.put(this.identifier.identify(entry), entry); |
| 40 | } catch (ClassNotFoundException ex) { | 40 | } catch (ClassNotFoundException ex) { |
| 41 | throw new Error("Unable to find class " + entry.getName()); | 41 | throw new Error("Unable to find class " + entry.getName()); |
| 42 | } | 42 | } |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | public Collection<ClassIdentity> identities() { | 45 | public Collection<ClassIdentity> identities() { |
| 46 | return m_forest.keySet(); | 46 | return this.forest.keySet(); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | public Collection<ClassEntry> classes() { | 49 | public Collection<ClassEntry> classes() { |
| 50 | return m_forest.values(); | 50 | return this.forest.values(); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | public Collection<ClassEntry> getClasses(ClassIdentity identity) { | 53 | public Collection<ClassEntry> getClasses(ClassIdentity identity) { |
| 54 | return m_forest.get(identity); | 54 | return this.forest.get(identity); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | public boolean containsIdentity(ClassIdentity identity) { | 57 | public boolean containsIdentity(ClassIdentity identity) { |
| 58 | return m_forest.containsKey(identity); | 58 | return this.forest.containsKey(identity); |
| 59 | } | 59 | } |
| 60 | } | 60 | } |
diff --git a/src/main/java/cuchaz/enigma/convert/ClassIdentifier.java b/src/main/java/cuchaz/enigma/convert/ClassIdentifier.java index e1153a6d..cc7f25b8 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassIdentifier.java +++ b/src/main/java/cuchaz/enigma/convert/ClassIdentifier.java | |||
| @@ -24,30 +24,30 @@ import javassist.CtClass; | |||
| 24 | 24 | ||
| 25 | public class ClassIdentifier { | 25 | public class ClassIdentifier { |
| 26 | 26 | ||
| 27 | private JarIndex m_index; | 27 | private JarIndex index; |
| 28 | private SidedClassNamer m_namer; | 28 | private SidedClassNamer namer; |
| 29 | private boolean m_useReferences; | 29 | private boolean useReferences; |
| 30 | private TranslatingTypeLoader m_loader; | 30 | private TranslatingTypeLoader loader; |
| 31 | private Map<ClassEntry, ClassIdentity> m_cache; | 31 | private Map<ClassEntry, ClassIdentity> cache; |
| 32 | 32 | ||
| 33 | public ClassIdentifier(JarFile jar, JarIndex index, SidedClassNamer namer, boolean useReferences) { | 33 | public ClassIdentifier(JarFile jar, JarIndex index, SidedClassNamer namer, boolean useReferences) { |
| 34 | m_index = index; | 34 | this.index = index; |
| 35 | m_namer = namer; | 35 | this.namer = namer; |
| 36 | m_useReferences = useReferences; | 36 | this.useReferences = useReferences; |
| 37 | m_loader = new TranslatingTypeLoader(jar, index); | 37 | this.loader = new TranslatingTypeLoader(jar, index); |
| 38 | m_cache = Maps.newHashMap(); | 38 | this.cache = Maps.newHashMap(); |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | public ClassIdentity identify(ClassEntry classEntry) | 41 | public ClassIdentity identify(ClassEntry classEntry) |
| 42 | throws ClassNotFoundException { | 42 | throws ClassNotFoundException { |
| 43 | ClassIdentity identity = m_cache.get(classEntry); | 43 | ClassIdentity identity = this.cache.get(classEntry); |
| 44 | if (identity == null) { | 44 | if (identity == null) { |
| 45 | CtClass c = m_loader.loadClass(classEntry.getName()); | 45 | CtClass c = this.loader.loadClass(classEntry.getName()); |
| 46 | if (c == null) { | 46 | if (c == null) { |
| 47 | throw new ClassNotFoundException(classEntry.getName()); | 47 | throw new ClassNotFoundException(classEntry.getName()); |
| 48 | } | 48 | } |
| 49 | identity = new ClassIdentity(c, m_namer, m_index, m_useReferences); | 49 | identity = new ClassIdentity(c, this.namer, this.index, this.useReferences); |
| 50 | m_cache.put(classEntry, identity); | 50 | this.cache.put(classEntry, identity); |
| 51 | } | 51 | } |
| 52 | return identity; | 52 | return identity; |
| 53 | } | 53 | } |
diff --git a/src/main/java/cuchaz/enigma/convert/ClassIdentity.java b/src/main/java/cuchaz/enigma/convert/ClassIdentity.java index 76c48ab6..2317a3d9 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassIdentity.java +++ b/src/main/java/cuchaz/enigma/convert/ClassIdentity.java | |||
| @@ -36,18 +36,18 @@ import javassist.expr.*; | |||
| 36 | 36 | ||
| 37 | public class ClassIdentity { | 37 | public class ClassIdentity { |
| 38 | 38 | ||
| 39 | private ClassEntry m_classEntry; | 39 | private ClassEntry classEntry; |
| 40 | private SidedClassNamer m_namer; | 40 | private SidedClassNamer namer; |
| 41 | private Multiset<String> m_fields; | 41 | private Multiset<String> fields; |
| 42 | private Multiset<String> m_methods; | 42 | private Multiset<String> methods; |
| 43 | private Multiset<String> m_constructors; | 43 | private Multiset<String> constructors; |
| 44 | private String m_staticInitializer; | 44 | private String staticInitializer; |
| 45 | private String m_extends; | 45 | private String extendz; |
| 46 | private Multiset<String> m_implements; | 46 | private Multiset<String> implementz; |
| 47 | private Set<String> m_stringLiterals; | 47 | private Set<String> stringLiterals; |
| 48 | private Multiset<String> m_implementations; | 48 | private Multiset<String> implementations; |
| 49 | private Multiset<String> m_references; | 49 | private Multiset<String> references; |
| 50 | private String m_outer; | 50 | private String outer; |
| 51 | 51 | ||
| 52 | private final ClassNameReplacer m_classNameReplacer = new ClassNameReplacer() { | 52 | private final ClassNameReplacer m_classNameReplacer = new ClassNameReplacer() { |
| 53 | 53 | ||
| @@ -63,13 +63,13 @@ public class ClassIdentity { | |||
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | // is this class ourself? | 65 | // is this class ourself? |
| 66 | if (className.equals(m_classEntry.getName())) { | 66 | if (className.equals(classEntry.getName())) { |
| 67 | return "CSelf"; | 67 | return "CSelf"; |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | // try the namer | 70 | // try the namer |
| 71 | if (m_namer != null) { | 71 | if (namer != null) { |
| 72 | String newName = m_namer.getName(className); | 72 | String newName = namer.getName(className); |
| 73 | if (newName != null) { | 73 | if (newName != null) { |
| 74 | return newName; | 74 | return newName; |
| 75 | } | 75 | } |
| @@ -88,58 +88,58 @@ public class ClassIdentity { | |||
| 88 | }; | 88 | }; |
| 89 | 89 | ||
| 90 | public ClassIdentity(CtClass c, SidedClassNamer namer, JarIndex index, boolean useReferences) { | 90 | public ClassIdentity(CtClass c, SidedClassNamer namer, JarIndex index, boolean useReferences) { |
| 91 | m_namer = namer; | 91 | this.namer = namer; |
| 92 | 92 | ||
| 93 | // stuff from the bytecode | 93 | // stuff from the bytecode |
| 94 | 94 | ||
| 95 | m_classEntry = EntryFactory.getClassEntry(c); | 95 | this.classEntry = EntryFactory.getClassEntry(c); |
| 96 | m_fields = HashMultiset.create(); | 96 | this.fields = HashMultiset.create(); |
| 97 | for (CtField field : c.getDeclaredFields()) { | 97 | for (CtField field : c.getDeclaredFields()) { |
| 98 | m_fields.add(scrubType(field.getSignature())); | 98 | this.fields.add(scrubType(field.getSignature())); |
| 99 | } | 99 | } |
| 100 | m_methods = HashMultiset.create(); | 100 | this.methods = HashMultiset.create(); |
| 101 | for (CtMethod method : c.getDeclaredMethods()) { | 101 | for (CtMethod method : c.getDeclaredMethods()) { |
| 102 | m_methods.add(scrubSignature(method.getSignature()) + "0x" + getBehaviorSignature(method)); | 102 | this.methods.add(scrubSignature(method.getSignature()) + "0x" + getBehaviorSignature(method)); |
| 103 | } | 103 | } |
| 104 | m_constructors = HashMultiset.create(); | 104 | this.constructors = HashMultiset.create(); |
| 105 | for (CtConstructor constructor : c.getDeclaredConstructors()) { | 105 | for (CtConstructor constructor : c.getDeclaredConstructors()) { |
| 106 | m_constructors.add(scrubSignature(constructor.getSignature()) + "0x" + getBehaviorSignature(constructor)); | 106 | this.constructors.add(scrubSignature(constructor.getSignature()) + "0x" + getBehaviorSignature(constructor)); |
| 107 | } | 107 | } |
| 108 | m_staticInitializer = ""; | 108 | this.staticInitializer = ""; |
| 109 | if (c.getClassInitializer() != null) { | 109 | if (c.getClassInitializer() != null) { |
| 110 | m_staticInitializer = getBehaviorSignature(c.getClassInitializer()); | 110 | this.staticInitializer = getBehaviorSignature(c.getClassInitializer()); |
| 111 | } | 111 | } |
| 112 | m_extends = ""; | 112 | this.extendz = ""; |
| 113 | if (c.getClassFile().getSuperclass() != null) { | 113 | if (c.getClassFile().getSuperclass() != null) { |
| 114 | m_extends = scrubClassName(Descriptor.toJvmName(c.getClassFile().getSuperclass())); | 114 | this.extendz = scrubClassName(Descriptor.toJvmName(c.getClassFile().getSuperclass())); |
| 115 | } | 115 | } |
| 116 | m_implements = HashMultiset.create(); | 116 | this.implementz = HashMultiset.create(); |
| 117 | for (String interfaceName : c.getClassFile().getInterfaces()) { | 117 | for (String interfaceName : c.getClassFile().getInterfaces()) { |
| 118 | m_implements.add(scrubClassName(Descriptor.toJvmName(interfaceName))); | 118 | this.implementz.add(scrubClassName(Descriptor.toJvmName(interfaceName))); |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | m_stringLiterals = Sets.newHashSet(); | 121 | this.stringLiterals = Sets.newHashSet(); |
| 122 | ConstPool constants = c.getClassFile().getConstPool(); | 122 | ConstPool constants = c.getClassFile().getConstPool(); |
| 123 | for (int i = 1; i < constants.getSize(); i++) { | 123 | for (int i = 1; i < constants.getSize(); i++) { |
| 124 | if (constants.getTag(i) == ConstPool.CONST_String) { | 124 | if (constants.getTag(i) == ConstPool.CONST_String) { |
| 125 | m_stringLiterals.add(constants.getStringInfo(i)); | 125 | this.stringLiterals.add(constants.getStringInfo(i)); |
| 126 | } | 126 | } |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | // stuff from the jar index | 129 | // stuff from the jar index |
| 130 | 130 | ||
| 131 | m_implementations = HashMultiset.create(); | 131 | this.implementations = HashMultiset.create(); |
| 132 | ClassImplementationsTreeNode implementationsNode = index.getClassImplementations(null, m_classEntry); | 132 | ClassImplementationsTreeNode implementationsNode = index.getClassImplementations(null, this.classEntry); |
| 133 | if (implementationsNode != null) { | 133 | if (implementationsNode != null) { |
| 134 | @SuppressWarnings("unchecked") | 134 | @SuppressWarnings("unchecked") |
| 135 | Enumeration<ClassImplementationsTreeNode> implementations = implementationsNode.children(); | 135 | Enumeration<ClassImplementationsTreeNode> implementations = implementationsNode.children(); |
| 136 | while (implementations.hasMoreElements()) { | 136 | while (implementations.hasMoreElements()) { |
| 137 | ClassImplementationsTreeNode node = implementations.nextElement(); | 137 | ClassImplementationsTreeNode node = implementations.nextElement(); |
| 138 | m_implementations.add(scrubClassName(node.getClassEntry().getName())); | 138 | this.implementations.add(scrubClassName(node.getClassEntry().getName())); |
| 139 | } | 139 | } |
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | m_references = HashMultiset.create(); | 142 | this.references = HashMultiset.create(); |
| 143 | if (useReferences) { | 143 | if (useReferences) { |
| 144 | for (CtField field : c.getDeclaredFields()) { | 144 | for (CtField field : c.getDeclaredFields()) { |
| 145 | FieldEntry fieldEntry = EntryFactory.getFieldEntry(field); | 145 | FieldEntry fieldEntry = EntryFactory.getFieldEntry(field); |
| @@ -151,79 +151,79 @@ public class ClassIdentity { | |||
| 151 | } | 151 | } |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | m_outer = null; | 154 | this.outer = null; |
| 155 | if (m_classEntry.isInnerClass()) { | 155 | if (this.classEntry.isInnerClass()) { |
| 156 | m_outer = m_classEntry.getOuterClassName(); | 156 | this.outer = this.classEntry.getOuterClassName(); |
| 157 | } | 157 | } |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | private void addReference(EntryReference<? extends Entry, BehaviorEntry> reference) { | 160 | private void addReference(EntryReference<? extends Entry, BehaviorEntry> reference) { |
| 161 | if (reference.context.getSignature() != null) { | 161 | if (reference.context.getSignature() != null) { |
| 162 | m_references.add(String.format("%s_%s", | 162 | this.references.add(String.format("%s_%s", |
| 163 | scrubClassName(reference.context.getClassName()), | 163 | scrubClassName(reference.context.getClassName()), |
| 164 | scrubSignature(reference.context.getSignature()) | 164 | scrubSignature(reference.context.getSignature()) |
| 165 | )); | 165 | )); |
| 166 | } else { | 166 | } else { |
| 167 | m_references.add(String.format("%s_<clinit>", | 167 | this.references.add(String.format("%s_<clinit>", |
| 168 | scrubClassName(reference.context.getClassName()) | 168 | scrubClassName(reference.context.getClassName()) |
| 169 | )); | 169 | )); |
| 170 | } | 170 | } |
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | public ClassEntry getClassEntry() { | 173 | public ClassEntry getClassEntry() { |
| 174 | return m_classEntry; | 174 | return this.classEntry; |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | @Override | 177 | @Override |
| 178 | public String toString() { | 178 | public String toString() { |
| 179 | StringBuilder buf = new StringBuilder(); | 179 | StringBuilder buf = new StringBuilder(); |
| 180 | buf.append("class: "); | 180 | buf.append("class: "); |
| 181 | buf.append(m_classEntry.getName()); | 181 | buf.append(this.classEntry.getName()); |
| 182 | buf.append(" "); | 182 | buf.append(" "); |
| 183 | buf.append(hashCode()); | 183 | buf.append(hashCode()); |
| 184 | buf.append("\n"); | 184 | buf.append("\n"); |
| 185 | for (String field : m_fields) { | 185 | for (String field : this.fields) { |
| 186 | buf.append("\tfield "); | 186 | buf.append("\tfield "); |
| 187 | buf.append(field); | 187 | buf.append(field); |
| 188 | buf.append("\n"); | 188 | buf.append("\n"); |
| 189 | } | 189 | } |
| 190 | for (String method : m_methods) { | 190 | for (String method : this.methods) { |
| 191 | buf.append("\tmethod "); | 191 | buf.append("\tmethod "); |
| 192 | buf.append(method); | 192 | buf.append(method); |
| 193 | buf.append("\n"); | 193 | buf.append("\n"); |
| 194 | } | 194 | } |
| 195 | for (String constructor : m_constructors) { | 195 | for (String constructor : this.constructors) { |
| 196 | buf.append("\tconstructor "); | 196 | buf.append("\tconstructor "); |
| 197 | buf.append(constructor); | 197 | buf.append(constructor); |
| 198 | buf.append("\n"); | 198 | buf.append("\n"); |
| 199 | } | 199 | } |
| 200 | if (m_staticInitializer.length() > 0) { | 200 | if (this.staticInitializer.length() > 0) { |
| 201 | buf.append("\tinitializer "); | 201 | buf.append("\tinitializer "); |
| 202 | buf.append(m_staticInitializer); | 202 | buf.append(this.staticInitializer); |
| 203 | buf.append("\n"); | 203 | buf.append("\n"); |
| 204 | } | 204 | } |
| 205 | if (m_extends.length() > 0) { | 205 | if (this.extendz.length() > 0) { |
| 206 | buf.append("\textends "); | 206 | buf.append("\textends "); |
| 207 | buf.append(m_extends); | 207 | buf.append(this.extendz); |
| 208 | buf.append("\n"); | 208 | buf.append("\n"); |
| 209 | } | 209 | } |
| 210 | for (String interfaceName : m_implements) { | 210 | for (String interfaceName : this.implementz) { |
| 211 | buf.append("\timplements "); | 211 | buf.append("\timplements "); |
| 212 | buf.append(interfaceName); | 212 | buf.append(interfaceName); |
| 213 | buf.append("\n"); | 213 | buf.append("\n"); |
| 214 | } | 214 | } |
| 215 | for (String implementation : m_implementations) { | 215 | for (String implementation : this.implementations) { |
| 216 | buf.append("\timplemented by "); | 216 | buf.append("\timplemented by "); |
| 217 | buf.append(implementation); | 217 | buf.append(implementation); |
| 218 | buf.append("\n"); | 218 | buf.append("\n"); |
| 219 | } | 219 | } |
| 220 | for (String reference : m_references) { | 220 | for (String reference : this.references) { |
| 221 | buf.append("\treference "); | 221 | buf.append("\treference "); |
| 222 | buf.append(reference); | 222 | buf.append(reference); |
| 223 | buf.append("\n"); | 223 | buf.append("\n"); |
| 224 | } | 224 | } |
| 225 | buf.append("\touter "); | 225 | buf.append("\touter "); |
| 226 | buf.append(m_outer); | 226 | buf.append(this.outer); |
| 227 | buf.append("\n"); | 227 | buf.append("\n"); |
| 228 | return buf.toString(); | 228 | return buf.toString(); |
| 229 | } | 229 | } |
| @@ -253,7 +253,7 @@ public class ClassIdentity { | |||
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | private boolean isClassMatchedUniquely(String className) { | 255 | private boolean isClassMatchedUniquely(String className) { |
| 256 | return m_namer != null && m_namer.getName(Descriptor.toJvmName(className)) != null; | 256 | return this.namer != null && this.namer.getName(Descriptor.toJvmName(className)) != null; |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | private String getBehaviorSignature(CtBehavior behavior) { | 259 | private String getBehaviorSignature(CtBehavior behavior) { |
| @@ -361,56 +361,53 @@ public class ClassIdentity { | |||
| 361 | 361 | ||
| 362 | @Override | 362 | @Override |
| 363 | public boolean equals(Object other) { | 363 | public boolean equals(Object other) { |
| 364 | if (other instanceof ClassIdentity) { | 364 | return other instanceof ClassIdentity && equals((ClassIdentity) other); |
| 365 | return equals((ClassIdentity) other); | ||
| 366 | } | ||
| 367 | return false; | ||
| 368 | } | 365 | } |
| 369 | 366 | ||
| 370 | public boolean equals(ClassIdentity other) { | 367 | public boolean equals(ClassIdentity other) { |
| 371 | return m_fields.equals(other.m_fields) | 368 | return this.fields.equals(other.fields) |
| 372 | && m_methods.equals(other.m_methods) | 369 | && this.methods.equals(other.methods) |
| 373 | && m_constructors.equals(other.m_constructors) | 370 | && this.constructors.equals(other.constructors) |
| 374 | && m_staticInitializer.equals(other.m_staticInitializer) | 371 | && this.staticInitializer.equals(other.staticInitializer) |
| 375 | && m_extends.equals(other.m_extends) | 372 | && this.extendz.equals(other.extendz) |
| 376 | && m_implements.equals(other.m_implements) | 373 | && this.implementz.equals(other.implementz) |
| 377 | && m_implementations.equals(other.m_implementations) | 374 | && this.implementations.equals(other.implementations) |
| 378 | && m_references.equals(other.m_references); | 375 | && this.references.equals(other.references); |
| 379 | } | 376 | } |
| 380 | 377 | ||
| 381 | @Override | 378 | @Override |
| 382 | public int hashCode() { | 379 | public int hashCode() { |
| 383 | List<Object> objs = Lists.newArrayList(); | 380 | List<Object> objs = Lists.newArrayList(); |
| 384 | objs.addAll(m_fields); | 381 | objs.addAll(this.fields); |
| 385 | objs.addAll(m_methods); | 382 | objs.addAll(this.methods); |
| 386 | objs.addAll(m_constructors); | 383 | objs.addAll(this.constructors); |
| 387 | objs.add(m_staticInitializer); | 384 | objs.add(this.staticInitializer); |
| 388 | objs.add(m_extends); | 385 | objs.add(this.extendz); |
| 389 | objs.addAll(m_implements); | 386 | objs.addAll(this.implementz); |
| 390 | objs.addAll(m_implementations); | 387 | objs.addAll(this.implementations); |
| 391 | objs.addAll(m_references); | 388 | objs.addAll(this.references); |
| 392 | return Util.combineHashesOrdered(objs); | 389 | return Util.combineHashesOrdered(objs); |
| 393 | } | 390 | } |
| 394 | 391 | ||
| 395 | public int getMatchScore(ClassIdentity other) { | 392 | public int getMatchScore(ClassIdentity other) { |
| 396 | return 2 * getNumMatches(m_extends, other.m_extends) | 393 | return 2 * getNumMatches(this.extendz, other.extendz) |
| 397 | + 2 * getNumMatches(m_outer, other.m_outer) | 394 | + 2 * getNumMatches(this.outer, other.outer) |
| 398 | + 2 * getNumMatches(m_implements, other.m_implements) | 395 | + 2 * getNumMatches(this.implementz, other.implementz) |
| 399 | + getNumMatches(m_stringLiterals, other.m_stringLiterals) | 396 | + getNumMatches(this.stringLiterals, other.stringLiterals) |
| 400 | + getNumMatches(m_fields, other.m_fields) | 397 | + getNumMatches(this.fields, other.fields) |
| 401 | + getNumMatches(m_methods, other.m_methods) | 398 | + getNumMatches(this.methods, other.methods) |
| 402 | + getNumMatches(m_constructors, other.m_constructors); | 399 | + getNumMatches(this.constructors, other.constructors); |
| 403 | } | 400 | } |
| 404 | 401 | ||
| 405 | public int getMaxMatchScore() { | 402 | public int getMaxMatchScore() { |
| 406 | return 2 + 2 + 2 * m_implements.size() + m_stringLiterals.size() + m_fields.size() + m_methods.size() + m_constructors.size(); | 403 | return 2 + 2 + 2 * this.implementz.size() + this.stringLiterals.size() + this.fields.size() + this.methods.size() + this.constructors.size(); |
| 407 | } | 404 | } |
| 408 | 405 | ||
| 409 | public boolean matches(CtClass c) { | 406 | public boolean matches(CtClass c) { |
| 410 | // just compare declaration counts | 407 | // just compare declaration counts |
| 411 | return m_fields.size() == c.getDeclaredFields().length | 408 | return this.fields.size() == c.getDeclaredFields().length |
| 412 | && m_methods.size() == c.getDeclaredMethods().length | 409 | && this.methods.size() == c.getDeclaredMethods().length |
| 413 | && m_constructors.size() == c.getDeclaredConstructors().length; | 410 | && this.constructors.size() == c.getDeclaredConstructors().length; |
| 414 | } | 411 | } |
| 415 | 412 | ||
| 416 | private int getNumMatches(Set<String> a, Set<String> b) { | 413 | private int getNumMatches(Set<String> a, Set<String> b) { |
diff --git a/src/main/java/cuchaz/enigma/convert/ClassMatch.java b/src/main/java/cuchaz/enigma/convert/ClassMatch.java index f3530ed4..422529ec 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassMatch.java +++ b/src/main/java/cuchaz/enigma/convert/ClassMatch.java | |||
| @@ -75,14 +75,10 @@ public class ClassMatch { | |||
| 75 | 75 | ||
| 76 | @Override | 76 | @Override |
| 77 | public boolean equals(Object other) { | 77 | public boolean equals(Object other) { |
| 78 | if (other instanceof ClassMatch) { | 78 | return other instanceof ClassMatch && equals((ClassMatch) other); |
| 79 | return equals((ClassMatch) other); | ||
| 80 | } | ||
| 81 | return false; | ||
| 82 | } | 79 | } |
| 83 | 80 | ||
| 84 | public boolean equals(ClassMatch other) { | 81 | public boolean equals(ClassMatch other) { |
| 85 | return this.sourceClasses.equals(other.sourceClasses) | 82 | return this.sourceClasses.equals(other.sourceClasses) && this.destClasses.equals(other.destClasses); |
| 86 | && this.destClasses.equals(other.destClasses); | ||
| 87 | } | 83 | } |
| 88 | } | 84 | } |
diff --git a/src/main/java/cuchaz/enigma/convert/ClassMatches.java b/src/main/java/cuchaz/enigma/convert/ClassMatches.java index 2c5f6a57..3a254357 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassMatches.java +++ b/src/main/java/cuchaz/enigma/convert/ClassMatches.java | |||
| @@ -32,7 +32,7 @@ public class ClassMatches implements Iterable<ClassMatch> { | |||
| 32 | Set<ClassEntry> m_unmatchedDestClasses; | 32 | Set<ClassEntry> m_unmatchedDestClasses; |
| 33 | 33 | ||
| 34 | public ClassMatches() { | 34 | public ClassMatches() { |
| 35 | this(new ArrayList<ClassMatch>()); | 35 | this(new ArrayList<>()); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | public ClassMatches(Collection<ClassMatch> matches) { | 38 | public ClassMatches(Collection<ClassMatch> matches) { |
diff --git a/src/main/java/cuchaz/enigma/convert/ClassMatching.java b/src/main/java/cuchaz/enigma/convert/ClassMatching.java index 14f8e2a3..9350ea7f 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassMatching.java +++ b/src/main/java/cuchaz/enigma/convert/ClassMatching.java | |||
| @@ -69,7 +69,7 @@ public class ClassMatching { | |||
| 69 | for (ClassIdentity identity : m_destClasses.identities()) { | 69 | for (ClassIdentity identity : m_destClasses.identities()) { |
| 70 | if (!m_sourceClasses.containsIdentity(identity)) { | 70 | if (!m_sourceClasses.containsIdentity(identity)) { |
| 71 | matches.add(new ClassMatch( | 71 | matches.add(new ClassMatch( |
| 72 | new ArrayList<ClassEntry>(), | 72 | new ArrayList<>(), |
| 73 | m_destClasses.getClasses(identity) | 73 | m_destClasses.getClasses(identity) |
| 74 | )); | 74 | )); |
| 75 | } | 75 | } |
diff --git a/src/main/java/cuchaz/enigma/convert/ClassNamer.java b/src/main/java/cuchaz/enigma/convert/ClassNamer.java index f1d98200..e471c7dd 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassNamer.java +++ b/src/main/java/cuchaz/enigma/convert/ClassNamer.java | |||
| @@ -23,27 +23,27 @@ public class ClassNamer { | |||
| 23 | String getName(String name); | 23 | String getName(String name); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | private Map<String, String> m_sourceNames; | 26 | private Map<String, String> sourceNames; |
| 27 | private Map<String, String> m_destNames; | 27 | private Map<String, String> destNames; |
| 28 | 28 | ||
| 29 | public ClassNamer(BiMap<ClassEntry, ClassEntry> mappings) { | 29 | public ClassNamer(BiMap<ClassEntry, ClassEntry> mappings) { |
| 30 | // convert the identity mappings to name maps | 30 | // convert the identity mappings to name maps |
| 31 | m_sourceNames = Maps.newHashMap(); | 31 | this.sourceNames = Maps.newHashMap(); |
| 32 | m_destNames = Maps.newHashMap(); | 32 | this.destNames = Maps.newHashMap(); |
| 33 | int i = 0; | 33 | int i = 0; |
| 34 | for (Map.Entry<ClassEntry, ClassEntry> entry : mappings.entrySet()) { | 34 | for (Map.Entry<ClassEntry, ClassEntry> entry : mappings.entrySet()) { |
| 35 | String name = String.format("M%04d", i++); | 35 | String name = String.format("M%04d", i++); |
| 36 | m_sourceNames.put(entry.getKey().getName(), name); | 36 | this.sourceNames.put(entry.getKey().getName(), name); |
| 37 | m_destNames.put(entry.getValue().getName(), name); | 37 | this.destNames.put(entry.getValue().getName(), name); |
| 38 | } | 38 | } |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | public String getSourceName(String name) { | 41 | public String getSourceName(String name) { |
| 42 | return m_sourceNames.get(name); | 42 | return this.sourceNames.get(name); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | public String getDestName(String name) { | 45 | public String getDestName(String name) { |
| 46 | return m_destNames.get(name); | 46 | return this.destNames.get(name); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | public SidedClassNamer getSourceNamer() { | 49 | public SidedClassNamer getSourceNamer() { |
diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java index aa6acdc5..a6a2ec52 100644 --- a/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -17,7 +17,6 @@ import com.strobel.decompiler.languages.java.ast.CompilationUnit; | |||
| 17 | 17 | ||
| 18 | import java.io.File; | 18 | import java.io.File; |
| 19 | import java.io.FileReader; | 19 | import java.io.FileReader; |
| 20 | import java.io.FileWriter; | ||
| 21 | import java.io.IOException; | 20 | import java.io.IOException; |
| 22 | import java.util.Collection; | 21 | import java.util.Collection; |
| 23 | import java.util.Deque; | 22 | import java.util.Deque; |
diff --git a/src/main/java/cuchaz/enigma/json/JsonConstructor.java b/src/main/java/cuchaz/enigma/json/JsonConstructor.java index cfac372a..8cbecf7b 100644 --- a/src/main/java/cuchaz/enigma/json/JsonConstructor.java +++ b/src/main/java/cuchaz/enigma/json/JsonConstructor.java | |||
| @@ -8,7 +8,7 @@ public class JsonConstructor { | |||
| 8 | private boolean statics; | 8 | private boolean statics; |
| 9 | 9 | ||
| 10 | public JsonConstructor(String signature, List<JsonArgument> args, boolean statics) { | 10 | public JsonConstructor(String signature, List<JsonArgument> args, boolean statics) { |
| 11 | this.signature=signature; | 11 | this.signature = signature; |
| 12 | this.args = args; | 12 | this.args = args; |
| 13 | this.statics = statics; | 13 | this.statics = statics; |
| 14 | } | 14 | } |
diff --git a/src/main/java/cuchaz/enigma/json/JsonField.java b/src/main/java/cuchaz/enigma/json/JsonField.java index 195f2874..c55a5e93 100644 --- a/src/main/java/cuchaz/enigma/json/JsonField.java +++ b/src/main/java/cuchaz/enigma/json/JsonField.java | |||
| @@ -8,18 +8,18 @@ public class JsonField { | |||
| 8 | public JsonField(String obf, String name, String type) { | 8 | public JsonField(String obf, String name, String type) { |
| 9 | this.obf = obf; | 9 | this.obf = obf; |
| 10 | this.name = name; | 10 | this.name = name; |
| 11 | this.type=type; | 11 | this.type = type; |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | public String getObf() { | 14 | public String getObf() { |
| 15 | return obf; | 15 | return this.obf; |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | public String getName() { | 18 | public String getName() { |
| 19 | return name; | 19 | return this.name; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | public String getType() { | 22 | public String getType() { |
| 23 | return type; | 23 | return this.type; |
| 24 | } | 24 | } |
| 25 | } | 25 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/ClassEntry.java b/src/main/java/cuchaz/enigma/mapping/ClassEntry.java index 2e7711b7..c9304d45 100644 --- a/src/main/java/cuchaz/enigma/mapping/ClassEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/ClassEntry.java | |||
| @@ -67,10 +67,7 @@ public class ClassEntry implements Entry, Serializable { | |||
| 67 | 67 | ||
| 68 | @Override | 68 | @Override |
| 69 | public boolean equals(Object other) { | 69 | public boolean equals(Object other) { |
| 70 | if (other instanceof ClassEntry) { | 70 | return other instanceof ClassEntry && equals((ClassEntry) other); |
| 71 | return equals((ClassEntry) other); | ||
| 72 | } | ||
| 73 | return false; | ||
| 74 | } | 71 | } |
| 75 | 72 | ||
| 76 | public boolean equals(ClassEntry other) { | 73 | public boolean equals(ClassEntry other) { |
diff --git a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java index 9258ec78..84fb6dd8 100644 --- a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java | |||
| @@ -403,7 +403,7 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> { | |||
| 403 | public boolean renameObfClass(String oldObfClassName, String newObfClassName) { | 403 | public boolean renameObfClass(String oldObfClassName, String newObfClassName) { |
| 404 | 404 | ||
| 405 | // rename inner classes | 405 | // rename inner classes |
| 406 | for (ClassMapping innerClassMapping : new ArrayList<ClassMapping>(m_innerClassesByObfSimple.values())) { | 406 | for (ClassMapping innerClassMapping : new ArrayList<>(m_innerClassesByObfSimple.values())) { |
| 407 | if (innerClassMapping.renameObfClass(oldObfClassName, newObfClassName)) { | 407 | if (innerClassMapping.renameObfClass(oldObfClassName, newObfClassName)) { |
| 408 | boolean wasRemoved = m_innerClassesByObfSimple.remove(oldObfClassName) != null; | 408 | boolean wasRemoved = m_innerClassesByObfSimple.remove(oldObfClassName) != null; |
| 409 | assert (wasRemoved); | 409 | assert (wasRemoved); |
| @@ -413,7 +413,7 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> { | |||
| 413 | } | 413 | } |
| 414 | 414 | ||
| 415 | // rename field types | 415 | // rename field types |
| 416 | for (FieldMapping fieldMapping : new ArrayList<FieldMapping>(m_fieldsByObf.values())) { | 416 | for (FieldMapping fieldMapping : new ArrayList<>(m_fieldsByObf.values())) { |
| 417 | String oldFieldKey = getFieldKey(fieldMapping.getObfName(), fieldMapping.getObfType()); | 417 | String oldFieldKey = getFieldKey(fieldMapping.getObfName(), fieldMapping.getObfType()); |
| 418 | if (fieldMapping.renameObfClass(oldObfClassName, newObfClassName)) { | 418 | if (fieldMapping.renameObfClass(oldObfClassName, newObfClassName)) { |
| 419 | boolean wasRemoved = m_fieldsByObf.remove(oldFieldKey) != null; | 419 | boolean wasRemoved = m_fieldsByObf.remove(oldFieldKey) != null; |
| @@ -424,7 +424,7 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> { | |||
| 424 | } | 424 | } |
| 425 | 425 | ||
| 426 | // rename method signatures | 426 | // rename method signatures |
| 427 | for (MethodMapping methodMapping : new ArrayList<MethodMapping>(m_methodsByObf.values())) { | 427 | for (MethodMapping methodMapping : new ArrayList<>(m_methodsByObf.values())) { |
| 428 | String oldMethodKey = getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature()); | 428 | String oldMethodKey = getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature()); |
| 429 | if (methodMapping.renameObfClass(oldObfClassName, newObfClassName)) { | 429 | if (methodMapping.renameObfClass(oldObfClassName, newObfClassName)) { |
| 430 | boolean wasRemoved = m_methodsByObf.remove(oldMethodKey) != null; | 430 | boolean wasRemoved = m_methodsByObf.remove(oldMethodKey) != null; |
diff --git a/src/main/java/cuchaz/enigma/mapping/FieldEntry.java b/src/main/java/cuchaz/enigma/mapping/FieldEntry.java index 3de72239..bebc5045 100644 --- a/src/main/java/cuchaz/enigma/mapping/FieldEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/FieldEntry.java | |||
| @@ -80,10 +80,7 @@ public class FieldEntry implements Entry, Serializable { | |||
| 80 | 80 | ||
| 81 | @Override | 81 | @Override |
| 82 | public boolean equals(Object other) { | 82 | public boolean equals(Object other) { |
| 83 | if (other instanceof FieldEntry) { | 83 | return other instanceof FieldEntry && equals((FieldEntry) other); |
| 84 | return equals((FieldEntry) other); | ||
| 85 | } | ||
| 86 | return false; | ||
| 87 | } | 84 | } |
| 88 | 85 | ||
| 89 | public boolean equals(FieldEntry other) { | 86 | public boolean equals(FieldEntry other) { |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java b/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java index ab686827..5e2b40b2 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java | |||
| @@ -90,8 +90,6 @@ public class MappingsChecker { | |||
| 90 | classMapping.removeMethodMapping(methodMapping); | 90 | classMapping.removeMethodMapping(methodMapping); |
| 91 | m_droppedMethodMappings.put(obfBehaviorEntry, methodMapping); | 91 | m_droppedMethodMappings.put(obfBehaviorEntry, methodMapping); |
| 92 | } | 92 | } |
| 93 | |||
| 94 | m_relatedMethodChecker.checkMethod(classEntry, methodMapping); | ||
| 95 | } | 93 | } |
| 96 | 94 | ||
| 97 | // check inner classes | 95 | // check inner classes |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsReader.java b/src/main/java/cuchaz/enigma/mapping/MappingsReader.java index 7110d40c..b2c3a5c0 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsReader.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsReader.java | |||
| @@ -42,14 +42,14 @@ public class MappingsReader { | |||
| 42 | 42 | ||
| 43 | public void readFile(Mappings mappings, BufferedReader in) throws IOException, MappingParseException { | 43 | public void readFile(Mappings mappings, BufferedReader in) throws IOException, MappingParseException { |
| 44 | 44 | ||
| 45 | String builder = ""; | 45 | StringBuffer buf = new StringBuffer(); |
| 46 | String line = null; | 46 | String line = null; |
| 47 | while ((line = in.readLine()) != null) { | 47 | while ((line = in.readLine()) != null) { |
| 48 | builder += line; | 48 | buf.append(line); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); | 51 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); |
| 52 | JsonClass jsonClass = gson.fromJson(builder, JsonClass.class); | 52 | JsonClass jsonClass = gson.fromJson(buf.toString(), JsonClass.class); |
| 53 | load(null, jsonClass, mappings); | 53 | load(null, jsonClass, mappings); |
| 54 | } | 54 | } |
| 55 | 55 | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java b/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java index 89fee4e8..aaab22fa 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java | |||
| @@ -24,7 +24,6 @@ import cuchaz.enigma.json.*; | |||
| 24 | 24 | ||
| 25 | public class MappingsWriter { | 25 | public class MappingsWriter { |
| 26 | 26 | ||
| 27 | |||
| 28 | public void write(File file, Mappings mappings) throws IOException { | 27 | public void write(File file, Mappings mappings) throws IOException { |
| 29 | if (!file.isDirectory()) { | 28 | if (!file.isDirectory()) { |
| 30 | return; | 29 | return; |
diff --git a/src/main/java/cuchaz/enigma/mapping/MethodEntry.java b/src/main/java/cuchaz/enigma/mapping/MethodEntry.java index 301da615..01a5c43d 100644 --- a/src/main/java/cuchaz/enigma/mapping/MethodEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/MethodEntry.java | |||
| @@ -85,10 +85,7 @@ public class MethodEntry implements BehaviorEntry, Serializable { | |||
| 85 | 85 | ||
| 86 | @Override | 86 | @Override |
| 87 | public boolean equals(Object other) { | 87 | public boolean equals(Object other) { |
| 88 | if (other instanceof MethodEntry) { | 88 | return other instanceof MethodEntry && equals((MethodEntry) other); |
| 89 | return equals((MethodEntry) other); | ||
| 90 | } | ||
| 91 | return false; | ||
| 92 | } | 89 | } |
| 93 | 90 | ||
| 94 | public boolean equals(MethodEntry other) { | 91 | public boolean equals(MethodEntry other) { |
diff --git a/src/main/java/cuchaz/enigma/mapping/MethodMapping.java b/src/main/java/cuchaz/enigma/mapping/MethodMapping.java index d1beddde..ff14ccd3 100644 --- a/src/main/java/cuchaz/enigma/mapping/MethodMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/MethodMapping.java | |||
| @@ -36,62 +36,62 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 36 | if (obfSignature == null) { | 36 | if (obfSignature == null) { |
| 37 | throw new IllegalArgumentException("obf signature cannot be null!"); | 37 | throw new IllegalArgumentException("obf signature cannot be null!"); |
| 38 | } | 38 | } |
| 39 | m_obfName = obfName; | 39 | this.m_obfName = obfName; |
| 40 | m_deobfName = NameValidator.validateMethodName(deobfName); | 40 | this.m_deobfName = NameValidator.validateMethodName(deobfName); |
| 41 | m_obfSignature = obfSignature; | 41 | this.m_obfSignature = obfSignature; |
| 42 | m_arguments = Maps.newTreeMap(); | 42 | this.m_arguments = Maps.newTreeMap(); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | public MethodMapping(MethodMapping other, ClassNameReplacer obfClassNameReplacer) { | 45 | public MethodMapping(MethodMapping other, ClassNameReplacer obfClassNameReplacer) { |
| 46 | m_obfName = other.m_obfName; | 46 | this.m_obfName = other.m_obfName; |
| 47 | m_deobfName = other.m_deobfName; | 47 | this.m_deobfName = other.m_deobfName; |
| 48 | m_obfSignature = new Signature(other.m_obfSignature, obfClassNameReplacer); | 48 | this.m_obfSignature = new Signature(other.m_obfSignature, obfClassNameReplacer); |
| 49 | m_arguments = Maps.newTreeMap(); | 49 | this.m_arguments = Maps.newTreeMap(); |
| 50 | for (Entry<Integer, ArgumentMapping> entry : other.m_arguments.entrySet()) { | 50 | for (Entry<Integer, ArgumentMapping> entry : other.m_arguments.entrySet()) { |
| 51 | m_arguments.put(entry.getKey(), new ArgumentMapping(entry.getValue())); | 51 | this.m_arguments.put(entry.getKey(), new ArgumentMapping(entry.getValue())); |
| 52 | } | 52 | } |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | @Override | 55 | @Override |
| 56 | public String getObfName() { | 56 | public String getObfName() { |
| 57 | return m_obfName; | 57 | return this.m_obfName; |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | public void setObfName(String val) { | 60 | public void setObfName(String val) { |
| 61 | m_obfName = NameValidator.validateMethodName(val); | 61 | this.m_obfName = NameValidator.validateMethodName(val); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | public String getDeobfName() { | 64 | public String getDeobfName() { |
| 65 | return m_deobfName; | 65 | return this.m_deobfName; |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | public void setDeobfName(String val) { | 68 | public void setDeobfName(String val) { |
| 69 | m_deobfName = NameValidator.validateMethodName(val); | 69 | this.m_deobfName = NameValidator.validateMethodName(val); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | public Signature getObfSignature() { | 72 | public Signature getObfSignature() { |
| 73 | return m_obfSignature; | 73 | return this.m_obfSignature; |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | public void setObfSignature(Signature val) { | 76 | public void setObfSignature(Signature val) { |
| 77 | m_obfSignature = val; | 77 | this.m_obfSignature = val; |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | public Iterable<ArgumentMapping> arguments() { | 80 | public Iterable<ArgumentMapping> arguments() { |
| 81 | return m_arguments.values(); | 81 | return this.m_arguments.values(); |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | public boolean isConstructor() { | 84 | public boolean isConstructor() { |
| 85 | return m_obfName.startsWith("<"); | 85 | return this.m_obfName.startsWith("<"); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | public void addArgumentMapping(ArgumentMapping argumentMapping) { | 88 | public void addArgumentMapping(ArgumentMapping argumentMapping) { |
| 89 | boolean wasAdded = m_arguments.put(argumentMapping.getIndex(), argumentMapping) == null; | 89 | boolean wasAdded = this.m_arguments.put(argumentMapping.getIndex(), argumentMapping) == null; |
| 90 | assert (wasAdded); | 90 | assert (wasAdded); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | public String getObfArgumentName(int index) { | 93 | public String getObfArgumentName(int index) { |
| 94 | ArgumentMapping argumentMapping = m_arguments.get(index); | 94 | ArgumentMapping argumentMapping = this.m_arguments.get(index); |
| 95 | if (argumentMapping != null) { | 95 | if (argumentMapping != null) { |
| 96 | return argumentMapping.getName(); | 96 | return argumentMapping.getName(); |
| 97 | } | 97 | } |
| @@ -100,7 +100,7 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | public String getDeobfArgumentName(int index) { | 102 | public String getDeobfArgumentName(int index) { |
| 103 | ArgumentMapping argumentMapping = m_arguments.get(index); | 103 | ArgumentMapping argumentMapping = this.m_arguments.get(index); |
| 104 | if (argumentMapping != null) { | 104 | if (argumentMapping != null) { |
| 105 | return argumentMapping.getName(); | 105 | return argumentMapping.getName(); |
| 106 | } | 106 | } |
| @@ -109,10 +109,10 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | public void setArgumentName(int index, String name) { | 111 | public void setArgumentName(int index, String name) { |
| 112 | ArgumentMapping argumentMapping = m_arguments.get(index); | 112 | ArgumentMapping argumentMapping = this.m_arguments.get(index); |
| 113 | if (argumentMapping == null) { | 113 | if (argumentMapping == null) { |
| 114 | argumentMapping = new ArgumentMapping(index, name); | 114 | argumentMapping = new ArgumentMapping(index, name); |
| 115 | boolean wasAdded = m_arguments.put(index, argumentMapping) == null; | 115 | boolean wasAdded = this.m_arguments.put(index, argumentMapping) == null; |
| 116 | assert (wasAdded); | 116 | assert (wasAdded); |
| 117 | } else { | 117 | } else { |
| 118 | argumentMapping.setName(name); | 118 | argumentMapping.setName(name); |
| @@ -120,7 +120,7 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | public void removeArgumentName(int index) { | 122 | public void removeArgumentName(int index) { |
| 123 | boolean wasRemoved = m_arguments.remove(index) != null; | 123 | boolean wasRemoved = this.m_arguments.remove(index) != null; |
| 124 | assert (wasRemoved); | 124 | assert (wasRemoved); |
| 125 | } | 125 | } |
| 126 | 126 | ||
| @@ -136,7 +136,7 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 136 | buf.append(m_obfSignature); | 136 | buf.append(m_obfSignature); |
| 137 | buf.append("\n"); | 137 | buf.append("\n"); |
| 138 | buf.append("\tArguments:\n"); | 138 | buf.append("\tArguments:\n"); |
| 139 | for (ArgumentMapping argumentMapping : m_arguments.values()) { | 139 | for (ArgumentMapping argumentMapping : this.m_arguments.values()) { |
| 140 | buf.append("\t\t"); | 140 | buf.append("\t\t"); |
| 141 | buf.append(argumentMapping.getIndex()); | 141 | buf.append(argumentMapping.getIndex()); |
| 142 | buf.append(" -> "); | 142 | buf.append(" -> "); |
| @@ -148,31 +148,28 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 148 | 148 | ||
| 149 | @Override | 149 | @Override |
| 150 | public int compareTo(MethodMapping other) { | 150 | public int compareTo(MethodMapping other) { |
| 151 | return (m_obfName + m_obfSignature).compareTo(other.m_obfName + other.m_obfSignature); | 151 | return (this.m_obfName + this.m_obfSignature).compareTo(other.m_obfName + other.m_obfSignature); |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | public boolean renameObfClass(final String oldObfClassName, final String newObfClassName) { | 154 | public boolean renameObfClass(final String oldObfClassName, final String newObfClassName) { |
| 155 | 155 | ||
| 156 | // rename obf classes in the signature | 156 | // rename obf classes in the signature |
| 157 | Signature newSignature = new Signature(m_obfSignature, new ClassNameReplacer() { | 157 | Signature newSignature = new Signature(this.m_obfSignature, className -> { |
| 158 | @Override | 158 | if (className.equals(oldObfClassName)) { |
| 159 | public String replace(String className) { | 159 | return newObfClassName; |
| 160 | if (className.equals(oldObfClassName)) { | ||
| 161 | return newObfClassName; | ||
| 162 | } | ||
| 163 | return null; | ||
| 164 | } | 160 | } |
| 161 | return null; | ||
| 165 | }); | 162 | }); |
| 166 | 163 | ||
| 167 | if (!newSignature.equals(m_obfSignature)) { | 164 | if (!newSignature.equals(this.m_obfSignature)) { |
| 168 | m_obfSignature = newSignature; | 165 | this.m_obfSignature = newSignature; |
| 169 | return true; | 166 | return true; |
| 170 | } | 167 | } |
| 171 | return false; | 168 | return false; |
| 172 | } | 169 | } |
| 173 | 170 | ||
| 174 | public boolean containsArgument(String name) { | 171 | public boolean containsArgument(String name) { |
| 175 | for (ArgumentMapping argumentMapping : m_arguments.values()) { | 172 | for (ArgumentMapping argumentMapping : this.m_arguments.values()) { |
| 176 | if (argumentMapping.getName().equals(name)) { | 173 | if (argumentMapping.getName().equals(name)) { |
| 177 | return true; | 174 | return true; |
| 178 | } | 175 | } |
| @@ -183,9 +180,9 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 183 | @Override | 180 | @Override |
| 184 | public BehaviorEntry getObfEntry(ClassEntry classEntry) { | 181 | public BehaviorEntry getObfEntry(ClassEntry classEntry) { |
| 185 | if (isConstructor()) { | 182 | if (isConstructor()) { |
| 186 | return new ConstructorEntry(classEntry, m_obfSignature); | 183 | return new ConstructorEntry(classEntry, this.m_obfSignature); |
| 187 | } else { | 184 | } else { |
| 188 | return new MethodEntry(classEntry, m_obfName, m_obfSignature); | 185 | return new MethodEntry(classEntry, this.m_obfName, this.m_obfSignature); |
| 189 | } | 186 | } |
| 190 | } | 187 | } |
| 191 | } | 188 | } |