diff options
Diffstat (limited to 'src/cuchaz/enigma/Deobfuscator.java')
| -rw-r--r-- | src/cuchaz/enigma/Deobfuscator.java | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/cuchaz/enigma/Deobfuscator.java b/src/cuchaz/enigma/Deobfuscator.java index b4ac501..b54a94a 100644 --- a/src/cuchaz/enigma/Deobfuscator.java +++ b/src/cuchaz/enigma/Deobfuscator.java | |||
| @@ -42,16 +42,17 @@ import com.strobel.decompiler.languages.java.ast.InsertParenthesesVisitor; | |||
| 42 | import cuchaz.enigma.analysis.EntryReference; | 42 | import cuchaz.enigma.analysis.EntryReference; |
| 43 | import cuchaz.enigma.analysis.JarClassIterator; | 43 | import cuchaz.enigma.analysis.JarClassIterator; |
| 44 | import cuchaz.enigma.analysis.JarIndex; | 44 | import cuchaz.enigma.analysis.JarIndex; |
| 45 | import cuchaz.enigma.analysis.RelatedMethodChecker; | ||
| 45 | import cuchaz.enigma.analysis.SourceIndex; | 46 | import cuchaz.enigma.analysis.SourceIndex; |
| 46 | import cuchaz.enigma.analysis.SourceIndexVisitor; | 47 | import cuchaz.enigma.analysis.SourceIndexVisitor; |
| 47 | import cuchaz.enigma.analysis.Token; | 48 | import cuchaz.enigma.analysis.Token; |
| 48 | import cuchaz.enigma.mapping.ArgumentEntry; | 49 | import cuchaz.enigma.mapping.ArgumentEntry; |
| 49 | import cuchaz.enigma.mapping.BehaviorEntry; | 50 | import cuchaz.enigma.mapping.BehaviorEntry; |
| 50 | import cuchaz.enigma.mapping.BehaviorEntryFactory; | ||
| 51 | import cuchaz.enigma.mapping.ClassEntry; | 51 | import cuchaz.enigma.mapping.ClassEntry; |
| 52 | import cuchaz.enigma.mapping.ClassMapping; | 52 | import cuchaz.enigma.mapping.ClassMapping; |
| 53 | import cuchaz.enigma.mapping.ConstructorEntry; | 53 | import cuchaz.enigma.mapping.ConstructorEntry; |
| 54 | import cuchaz.enigma.mapping.Entry; | 54 | import cuchaz.enigma.mapping.Entry; |
| 55 | import cuchaz.enigma.mapping.EntryFactory; | ||
| 55 | import cuchaz.enigma.mapping.FieldEntry; | 56 | import cuchaz.enigma.mapping.FieldEntry; |
| 56 | import cuchaz.enigma.mapping.FieldMapping; | 57 | import cuchaz.enigma.mapping.FieldMapping; |
| 57 | import cuchaz.enigma.mapping.Mappings; | 58 | import cuchaz.enigma.mapping.Mappings; |
| @@ -115,25 +116,27 @@ public class Deobfuscator { | |||
| 115 | } | 116 | } |
| 116 | 117 | ||
| 117 | // drop mappings that don't match the jar | 118 | // drop mappings that don't match the jar |
| 119 | RelatedMethodChecker relatedMethodChecker = new RelatedMethodChecker(m_jarIndex); | ||
| 118 | for (ClassMapping classMapping : Lists.newArrayList(val.classes())) { | 120 | for (ClassMapping classMapping : Lists.newArrayList(val.classes())) { |
| 119 | if (!checkClassMapping(classMapping)) { | 121 | if (!checkClassMapping(relatedMethodChecker, classMapping)) { |
| 120 | val.removeClassMapping(classMapping); | 122 | val.removeClassMapping(classMapping); |
| 121 | } | 123 | } |
| 122 | } | 124 | } |
| 123 | 125 | ||
| 126 | // check for related method inconsistencies | ||
| 127 | if (relatedMethodChecker.hasProblems()) { | ||
| 128 | throw new Error("Related methods are inconsistent! Need to fix the mappings manually.\n" + relatedMethodChecker.getReport()); | ||
| 129 | } | ||
| 130 | |||
| 124 | m_mappings = val; | 131 | m_mappings = val; |
| 125 | m_renamer = new MappingsRenamer(m_jarIndex, val); | 132 | m_renamer = new MappingsRenamer(m_jarIndex, val); |
| 126 | m_translatorCache.clear(); | 133 | m_translatorCache.clear(); |
| 127 | } | 134 | } |
| 128 | 135 | ||
| 129 | private boolean checkClassMapping(ClassMapping classMapping) { | 136 | private boolean checkClassMapping(RelatedMethodChecker relatedMethodChecker, ClassMapping classMapping) { |
| 130 | 137 | ||
| 131 | // check the class | 138 | // check the class |
| 132 | ClassEntry classEntry = new ClassEntry(classMapping.getObfName()); | 139 | ClassEntry classEntry = EntryFactory.getObfClassEntry(m_jarIndex, classMapping); |
| 133 | String outerClassName = m_jarIndex.getOuterClass(classEntry.getSimpleName()); | ||
| 134 | if (outerClassName != null) { | ||
| 135 | classEntry = new ClassEntry(outerClassName + "$" + classMapping.getObfName()); | ||
| 136 | } | ||
| 137 | if (!m_jarIndex.getObfClassEntries().contains(classEntry)) { | 140 | if (!m_jarIndex.getObfClassEntries().contains(classEntry)) { |
| 138 | return false; | 141 | return false; |
| 139 | } | 142 | } |
| @@ -149,16 +152,18 @@ public class Deobfuscator { | |||
| 149 | 152 | ||
| 150 | // check methods | 153 | // check methods |
| 151 | for (MethodMapping methodMapping : Lists.newArrayList(classMapping.methods())) { | 154 | for (MethodMapping methodMapping : Lists.newArrayList(classMapping.methods())) { |
| 152 | BehaviorEntry obfBehaviorEntry = BehaviorEntryFactory.createObf(classEntry, methodMapping); | 155 | BehaviorEntry obfBehaviorEntry = EntryFactory.getObfBehaviorEntry(classEntry, methodMapping); |
| 153 | if (!m_jarIndex.containsObfBehavior(obfBehaviorEntry)) { | 156 | if (!m_jarIndex.containsObfBehavior(obfBehaviorEntry)) { |
| 154 | System.err.println("WARNING: unable to find behavior " + obfBehaviorEntry + ". dropping mapping."); | 157 | System.err.println("WARNING: unable to find behavior " + obfBehaviorEntry + ". dropping mapping."); |
| 155 | classMapping.removeMethodMapping(methodMapping); | 158 | classMapping.removeMethodMapping(methodMapping); |
| 156 | } | 159 | } |
| 160 | |||
| 161 | relatedMethodChecker.checkMethod(classEntry, methodMapping); | ||
| 157 | } | 162 | } |
| 158 | 163 | ||
| 159 | // check inner classes | 164 | // check inner classes |
| 160 | for (ClassMapping innerClassMapping : classMapping.innerClasses()) { | 165 | for (ClassMapping innerClassMapping : classMapping.innerClasses()) { |
| 161 | if (!checkClassMapping(innerClassMapping)) { | 166 | if (!checkClassMapping(relatedMethodChecker, innerClassMapping)) { |
| 162 | System.err.println("WARNING: unable to find inner class " + innerClassMapping + ". dropping mapping."); | 167 | System.err.println("WARNING: unable to find inner class " + innerClassMapping + ". dropping mapping."); |
| 163 | classMapping.removeInnerClassMapping(innerClassMapping); | 168 | classMapping.removeInnerClassMapping(innerClassMapping); |
| 164 | } | 169 | } |