diff options
| author | 2015-03-09 11:03:35 -0400 | |
|---|---|---|
| committer | 2015-03-09 11:03:35 -0400 | |
| commit | 93c053803404382163d728e044d6dd49e76a5007 (patch) | |
| tree | a5e8c610185f83550d6ae5df158fe6b619ca096c /src/cuchaz/enigma/Deobfuscator.java | |
| parent | more tweaks, improvements, and bug fixes (diff) | |
| download | enigma-fork-93c053803404382163d728e044d6dd49e76a5007.tar.gz enigma-fork-93c053803404382163d728e044d6dd49e76a5007.tar.xz enigma-fork-93c053803404382163d728e044d6dd49e76a5007.zip | |
add tracking for mismatched fields/methods
Diffstat (limited to 'src/cuchaz/enigma/Deobfuscator.java')
| -rw-r--r-- | src/cuchaz/enigma/Deobfuscator.java | 74 |
1 files changed, 17 insertions, 57 deletions
diff --git a/src/cuchaz/enigma/Deobfuscator.java b/src/cuchaz/enigma/Deobfuscator.java index 9b0d3db..35cfd0b 100644 --- a/src/cuchaz/enigma/Deobfuscator.java +++ b/src/cuchaz/enigma/Deobfuscator.java | |||
| @@ -26,7 +26,6 @@ import java.util.jar.JarOutputStream; | |||
| 26 | import javassist.CtClass; | 26 | import javassist.CtClass; |
| 27 | import javassist.bytecode.Descriptor; | 27 | import javassist.bytecode.Descriptor; |
| 28 | 28 | ||
| 29 | import com.google.common.collect.Lists; | ||
| 30 | import com.google.common.collect.Maps; | 29 | import com.google.common.collect.Maps; |
| 31 | import com.google.common.collect.Sets; | 30 | import com.google.common.collect.Sets; |
| 32 | import com.strobel.assembler.metadata.MetadataSystem; | 31 | import com.strobel.assembler.metadata.MetadataSystem; |
| @@ -43,7 +42,6 @@ import com.strobel.decompiler.languages.java.ast.InsertParenthesesVisitor; | |||
| 43 | import cuchaz.enigma.analysis.EntryReference; | 42 | import cuchaz.enigma.analysis.EntryReference; |
| 44 | import cuchaz.enigma.analysis.JarClassIterator; | 43 | import cuchaz.enigma.analysis.JarClassIterator; |
| 45 | import cuchaz.enigma.analysis.JarIndex; | 44 | import cuchaz.enigma.analysis.JarIndex; |
| 46 | import cuchaz.enigma.analysis.RelatedMethodChecker; | ||
| 47 | import cuchaz.enigma.analysis.SourceIndex; | 45 | import cuchaz.enigma.analysis.SourceIndex; |
| 48 | import cuchaz.enigma.analysis.SourceIndexVisitor; | 46 | import cuchaz.enigma.analysis.SourceIndexVisitor; |
| 49 | import cuchaz.enigma.analysis.Token; | 47 | import cuchaz.enigma.analysis.Token; |
| @@ -53,10 +51,10 @@ import cuchaz.enigma.mapping.ClassEntry; | |||
| 53 | import cuchaz.enigma.mapping.ClassMapping; | 51 | import cuchaz.enigma.mapping.ClassMapping; |
| 54 | import cuchaz.enigma.mapping.ConstructorEntry; | 52 | import cuchaz.enigma.mapping.ConstructorEntry; |
| 55 | import cuchaz.enigma.mapping.Entry; | 53 | import cuchaz.enigma.mapping.Entry; |
| 56 | import cuchaz.enigma.mapping.EntryFactory; | ||
| 57 | import cuchaz.enigma.mapping.FieldEntry; | 54 | import cuchaz.enigma.mapping.FieldEntry; |
| 58 | import cuchaz.enigma.mapping.FieldMapping; | 55 | import cuchaz.enigma.mapping.FieldMapping; |
| 59 | import cuchaz.enigma.mapping.Mappings; | 56 | import cuchaz.enigma.mapping.Mappings; |
| 57 | import cuchaz.enigma.mapping.MappingsChecker; | ||
| 60 | import cuchaz.enigma.mapping.MappingsRenamer; | 58 | import cuchaz.enigma.mapping.MappingsRenamer; |
| 61 | import cuchaz.enigma.mapping.MethodEntry; | 59 | import cuchaz.enigma.mapping.MethodEntry; |
| 62 | import cuchaz.enigma.mapping.MethodMapping; | 60 | import cuchaz.enigma.mapping.MethodMapping; |
| @@ -125,19 +123,26 @@ public class Deobfuscator { | |||
| 125 | } | 123 | } |
| 126 | 124 | ||
| 127 | // drop mappings that don't match the jar | 125 | // drop mappings that don't match the jar |
| 128 | RelatedMethodChecker relatedMethodChecker = new RelatedMethodChecker(m_jarIndex); | 126 | MappingsChecker checker = new MappingsChecker(m_jarIndex); |
| 129 | for (ClassMapping classMapping : Lists.newArrayList(val.classes())) { | 127 | checker.dropBrokenMappings(val); |
| 130 | if (!checkClassMapping(relatedMethodChecker, classMapping, warnAboutDrops)) { | 128 | if (warnAboutDrops) { |
| 131 | if (warnAboutDrops) { | 129 | for (java.util.Map.Entry<ClassEntry,ClassMapping> mapping : checker.getDroppedClassMappings().entrySet()) { |
| 132 | System.err.println("WARNING: unable to find class " + classMapping.getObfFullName() + ". dropping mapping"); | 130 | System.out.println("WARNING: Couldn't find class entry " + mapping.getKey() + " (" + mapping.getValue().getDeobfName() + ") in jar. Mapping was dropped."); |
| 133 | } | 131 | } |
| 134 | val.removeClassMapping(classMapping); | 132 | for (java.util.Map.Entry<ClassEntry,ClassMapping> mapping : checker.getDroppedInnerClassMappings().entrySet()) { |
| 133 | System.out.println("WARNING: Couldn't find inner class entry " + mapping.getKey() + " (" + mapping.getValue().getDeobfName() + ") in jar. Mapping was dropped."); | ||
| 134 | } | ||
| 135 | for (java.util.Map.Entry<FieldEntry,FieldMapping> mapping : checker.getDroppedFieldMappings().entrySet()) { | ||
| 136 | System.out.println("WARNING: Couldn't find field entry " + mapping.getKey() + " (" + mapping.getValue().getDeobfName() + ") in jar. Mapping was dropped."); | ||
| 137 | } | ||
| 138 | for (java.util.Map.Entry<BehaviorEntry,MethodMapping> mapping : checker.getDroppedMethodMappings().entrySet()) { | ||
| 139 | System.out.println("WARNING: Couldn't find behavior entry " + mapping.getKey() + " (" + mapping.getValue().getDeobfName() + ") in jar. Mapping was dropped."); | ||
| 135 | } | 140 | } |
| 136 | } | 141 | } |
| 137 | 142 | ||
| 138 | // check for related method inconsistencies | 143 | // check for related method inconsistencies |
| 139 | if (relatedMethodChecker.hasProblems()) { | 144 | if (checker.getRelatedMethodChecker().hasProblems()) { |
| 140 | throw new Error("Related methods are inconsistent! Need to fix the mappings manually.\n" + relatedMethodChecker.getReport()); | 145 | throw new Error("Related methods are inconsistent! Need to fix the mappings manually.\n" + checker.getRelatedMethodChecker().getReport()); |
| 141 | } | 146 | } |
| 142 | 147 | ||
| 143 | m_mappings = val; | 148 | m_mappings = val; |
| @@ -145,51 +150,6 @@ public class Deobfuscator { | |||
| 145 | m_translatorCache.clear(); | 150 | m_translatorCache.clear(); |
| 146 | } | 151 | } |
| 147 | 152 | ||
| 148 | private boolean checkClassMapping(RelatedMethodChecker relatedMethodChecker, ClassMapping classMapping, boolean warnAboutDrops) { | ||
| 149 | |||
| 150 | // check the class | ||
| 151 | ClassEntry classEntry = EntryFactory.getObfClassEntry(m_jarIndex, classMapping); | ||
| 152 | if (!m_jarIndex.getObfClassEntries().contains(classEntry)) { | ||
| 153 | return false; | ||
| 154 | } | ||
| 155 | |||
| 156 | // check the fields | ||
| 157 | for (FieldMapping fieldMapping : Lists.newArrayList(classMapping.fields())) { | ||
| 158 | FieldEntry fieldEntry = new FieldEntry(classEntry, fieldMapping.getObfName(), fieldMapping.getObfType()); | ||
| 159 | if (!m_jarIndex.containsObfField(fieldEntry)) { | ||
| 160 | if (warnAboutDrops) { | ||
| 161 | System.err.println("WARNING: unable to find field " + fieldEntry + ". dropping mapping."); | ||
| 162 | } | ||
| 163 | classMapping.removeFieldMapping(fieldMapping); | ||
| 164 | } | ||
| 165 | } | ||
| 166 | |||
| 167 | // check methods | ||
| 168 | for (MethodMapping methodMapping : Lists.newArrayList(classMapping.methods())) { | ||
| 169 | BehaviorEntry obfBehaviorEntry = EntryFactory.getObfBehaviorEntry(classEntry, methodMapping); | ||
| 170 | if (!m_jarIndex.containsObfBehavior(obfBehaviorEntry)) { | ||
| 171 | if (warnAboutDrops) { | ||
| 172 | System.err.println("WARNING: unable to find behavior " + obfBehaviorEntry + ". dropping mapping."); | ||
| 173 | } | ||
| 174 | classMapping.removeMethodMapping(methodMapping); | ||
| 175 | } | ||
| 176 | |||
| 177 | relatedMethodChecker.checkMethod(classEntry, methodMapping); | ||
| 178 | } | ||
| 179 | |||
| 180 | // check inner classes | ||
| 181 | for (ClassMapping innerClassMapping : Lists.newArrayList(classMapping.innerClasses())) { | ||
| 182 | if (!checkClassMapping(relatedMethodChecker, innerClassMapping, warnAboutDrops)) { | ||
| 183 | if (warnAboutDrops) { | ||
| 184 | System.err.println("WARNING: unable to find inner class " + EntryFactory.getObfClassEntry(m_jarIndex, classMapping) + ". dropping mapping."); | ||
| 185 | } | ||
| 186 | classMapping.removeInnerClassMapping(innerClassMapping); | ||
| 187 | } | ||
| 188 | } | ||
| 189 | |||
| 190 | return true; | ||
| 191 | } | ||
| 192 | |||
| 193 | public Translator getTranslator(TranslationDirection direction) { | 153 | public Translator getTranslator(TranslationDirection direction) { |
| 194 | Translator translator = m_translatorCache.get(direction); | 154 | Translator translator = m_translatorCache.get(direction); |
| 195 | if (translator == null) { | 155 | if (translator == null) { |