diff options
| author | 2014-08-11 00:02:00 -0400 | |
|---|---|---|
| committer | 2014-08-11 00:02:00 -0400 | |
| commit | bba7c6a19c15bc82946176c79a4eba3612b25f17 (patch) | |
| tree | f0b55befaa6e7e532e9728dfa6b1c9cb36660594 /src | |
| parent | added backwards navigation (diff) | |
| download | enigma-bba7c6a19c15bc82946176c79a4eba3612b25f17.tar.gz enigma-bba7c6a19c15bc82946176c79a4eba3612b25f17.tar.xz enigma-bba7c6a19c15bc82946176c79a4eba3612b25f17.zip | |
added method inheritance browsing
also finally fixed method renamer to rename all method implementations in the inheritance hierarchy.
Diffstat (limited to 'src')
| -rw-r--r-- | src/cuchaz/enigma/Deobfuscator.java | 4 | ||||
| -rw-r--r-- | src/cuchaz/enigma/analysis/Ancestries.java (renamed from src/cuchaz/enigma/mapping/Ancestries.java) | 83 | ||||
| -rw-r--r-- | src/cuchaz/enigma/analysis/ClassInheritanceTreeNode.java (renamed from src/cuchaz/enigma/gui/ClassInheritanceTreeNode.java) | 24 | ||||
| -rw-r--r-- | src/cuchaz/enigma/analysis/DeobfuscatedAncestries.java (renamed from src/cuchaz/enigma/mapping/DeobfuscatedAncestries.java) | 6 | ||||
| -rw-r--r-- | src/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java | 134 | ||||
| -rw-r--r-- | src/cuchaz/enigma/analysis/TreeDumpVisitor.java | 10 | ||||
| -rw-r--r-- | src/cuchaz/enigma/gui/Gui.java | 61 | ||||
| -rw-r--r-- | src/cuchaz/enigma/gui/GuiController.java | 39 | ||||
| -rw-r--r-- | src/cuchaz/enigma/mapping/Mappings.java | 2 | ||||
| -rw-r--r-- | src/cuchaz/enigma/mapping/Renamer.java | 28 | ||||
| -rw-r--r-- | src/cuchaz/enigma/mapping/Translator.java | 1 |
11 files changed, 349 insertions, 43 deletions
diff --git a/src/cuchaz/enigma/Deobfuscator.java b/src/cuchaz/enigma/Deobfuscator.java index 8d4394cd..5321d2de 100644 --- a/src/cuchaz/enigma/Deobfuscator.java +++ b/src/cuchaz/enigma/Deobfuscator.java | |||
| @@ -31,9 +31,9 @@ import com.strobel.decompiler.languages.java.ast.AstBuilder; | |||
| 31 | import com.strobel.decompiler.languages.java.ast.CompilationUnit; | 31 | import com.strobel.decompiler.languages.java.ast.CompilationUnit; |
| 32 | import com.strobel.decompiler.languages.java.ast.InsertParenthesesVisitor; | 32 | import com.strobel.decompiler.languages.java.ast.InsertParenthesesVisitor; |
| 33 | 33 | ||
| 34 | import cuchaz.enigma.analysis.Ancestries; | ||
| 34 | import cuchaz.enigma.analysis.SourceIndex; | 35 | import cuchaz.enigma.analysis.SourceIndex; |
| 35 | import cuchaz.enigma.analysis.SourceIndexVisitor; | 36 | import cuchaz.enigma.analysis.SourceIndexVisitor; |
| 36 | import cuchaz.enigma.mapping.Ancestries; | ||
| 37 | import cuchaz.enigma.mapping.ArgumentEntry; | 37 | import cuchaz.enigma.mapping.ArgumentEntry; |
| 38 | import cuchaz.enigma.mapping.ClassEntry; | 38 | import cuchaz.enigma.mapping.ClassEntry; |
| 39 | import cuchaz.enigma.mapping.ClassMapping; | 39 | import cuchaz.enigma.mapping.ClassMapping; |
| @@ -207,7 +207,7 @@ public class Deobfuscator | |||
| 207 | } | 207 | } |
| 208 | else if( obfEntry instanceof MethodEntry ) | 208 | else if( obfEntry instanceof MethodEntry ) |
| 209 | { | 209 | { |
| 210 | m_renamer.setMethodName( (MethodEntry)obfEntry, newName ); | 210 | m_renamer.setMethodTreeName( (MethodEntry)obfEntry, newName ); |
| 211 | } | 211 | } |
| 212 | else if( obfEntry instanceof ArgumentEntry ) | 212 | else if( obfEntry instanceof ArgumentEntry ) |
| 213 | { | 213 | { |
diff --git a/src/cuchaz/enigma/mapping/Ancestries.java b/src/cuchaz/enigma/analysis/Ancestries.java index 894cf802..e6c8bbf1 100644 --- a/src/cuchaz/enigma/mapping/Ancestries.java +++ b/src/cuchaz/enigma/analysis/Ancestries.java | |||
| @@ -8,13 +8,14 @@ | |||
| 8 | * Contributors: | 8 | * Contributors: |
| 9 | * Jeff Martin - initial API and implementation | 9 | * Jeff Martin - initial API and implementation |
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma.mapping; | 11 | package cuchaz.enigma.analysis; |
| 12 | 12 | ||
| 13 | import java.io.ByteArrayOutputStream; | 13 | import java.io.ByteArrayOutputStream; |
| 14 | import java.io.IOException; | 14 | import java.io.IOException; |
| 15 | import java.io.InputStream; | 15 | import java.io.InputStream; |
| 16 | import java.io.Serializable; | 16 | import java.io.Serializable; |
| 17 | import java.util.ArrayList; | 17 | import java.util.ArrayList; |
| 18 | import java.util.Collection; | ||
| 18 | import java.util.List; | 19 | import java.util.List; |
| 19 | import java.util.Map; | 20 | import java.util.Map; |
| 20 | import java.util.zip.ZipEntry; | 21 | import java.util.zip.ZipEntry; |
| @@ -25,23 +26,32 @@ import javassist.ClassPool; | |||
| 25 | import javassist.CtClass; | 26 | import javassist.CtClass; |
| 26 | import javassist.NotFoundException; | 27 | import javassist.NotFoundException; |
| 27 | import javassist.bytecode.Descriptor; | 28 | import javassist.bytecode.Descriptor; |
| 29 | import javassist.bytecode.MethodInfo; | ||
| 28 | 30 | ||
| 31 | import com.google.common.collect.HashMultimap; | ||
| 29 | import com.google.common.collect.Lists; | 32 | import com.google.common.collect.Lists; |
| 30 | import com.google.common.collect.Maps; | 33 | import com.google.common.collect.Maps; |
| 34 | import com.google.common.collect.Multimap; | ||
| 31 | 35 | ||
| 32 | import cuchaz.enigma.Constants; | 36 | import cuchaz.enigma.Constants; |
| 37 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 38 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 39 | import cuchaz.enigma.mapping.Translator; | ||
| 33 | 40 | ||
| 34 | public class Ancestries implements Serializable | 41 | public class Ancestries implements Serializable |
| 35 | { | 42 | { |
| 36 | private static final long serialVersionUID = 738687982126844179L; | 43 | private static final long serialVersionUID = 738687982126844179L; |
| 37 | 44 | ||
| 38 | private Map<String,String> m_superclasses; | 45 | private Map<String,String> m_superclasses; |
| 46 | private Multimap<String,String> m_methodImplementations; | ||
| 39 | 47 | ||
| 40 | public Ancestries( ) | 48 | public Ancestries( ) |
| 41 | { | 49 | { |
| 42 | m_superclasses = Maps.newHashMap(); | 50 | m_superclasses = Maps.newHashMap(); |
| 51 | m_methodImplementations = HashMultimap.create(); | ||
| 43 | } | 52 | } |
| 44 | 53 | ||
| 54 | @SuppressWarnings( "unchecked" ) | ||
| 45 | public void readFromJar( InputStream in ) | 55 | public void readFromJar( InputStream in ) |
| 46 | throws IOException | 56 | throws IOException |
| 47 | { | 57 | { |
| @@ -87,6 +97,7 @@ public class Ancestries implements Serializable | |||
| 87 | { | 97 | { |
| 88 | CtClass c = classPool.get( className ); | 98 | CtClass c = classPool.get( className ); |
| 89 | addSuperclass( c.getName(), c.getClassFile().getSuperclass() ); | 99 | addSuperclass( c.getName(), c.getClassFile().getSuperclass() ); |
| 100 | addMethodImplementations( c.getName(), (List<MethodInfo>)c.getClassFile().getMethods() ); | ||
| 90 | } | 101 | } |
| 91 | catch( NotFoundException ex ) | 102 | catch( NotFoundException ex ) |
| 92 | { | 103 | { |
| @@ -95,6 +106,14 @@ public class Ancestries implements Serializable | |||
| 95 | } | 106 | } |
| 96 | } | 107 | } |
| 97 | 108 | ||
| 109 | private void addMethodImplementations( String name, List<MethodInfo> methods ) | ||
| 110 | { | ||
| 111 | for( MethodInfo method : methods ) | ||
| 112 | { | ||
| 113 | m_methodImplementations.put( name, getMethodKey( method.getName(), method.getDescriptor() ) ); | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 98 | public void addSuperclass( String className, String superclassName ) | 117 | public void addSuperclass( String className, String superclassName ) |
| 99 | { | 118 | { |
| 100 | className = Descriptor.toJvmName( className ); | 119 | className = Descriptor.toJvmName( className ); |
| @@ -146,9 +165,71 @@ public class Ancestries implements Serializable | |||
| 146 | return subclasses; | 165 | return subclasses; |
| 147 | } | 166 | } |
| 148 | 167 | ||
| 168 | public boolean isMethodImplemented( MethodEntry methodEntry ) | ||
| 169 | { | ||
| 170 | return isMethodImplemented( methodEntry.getClassName(), methodEntry.getName(), methodEntry.getSignature() ); | ||
| 171 | } | ||
| 172 | |||
| 173 | public boolean isMethodImplemented( String className, String methodName, String methodSignature ) | ||
| 174 | { | ||
| 175 | Collection<String> implementations = m_methodImplementations.get( className ); | ||
| 176 | if( implementations == null ) | ||
| 177 | { | ||
| 178 | return false; | ||
| 179 | } | ||
| 180 | return implementations.contains( getMethodKey( methodName, methodSignature ) ); | ||
| 181 | } | ||
| 182 | |||
| 183 | public ClassInheritanceTreeNode getClassInheritance( Translator deobfuscatingTranslator, ClassEntry obfClassEntry ) | ||
| 184 | { | ||
| 185 | // get the root node | ||
| 186 | List<String> ancestry = getAncestry( obfClassEntry.getName() ); | ||
| 187 | ClassInheritanceTreeNode rootNode = new ClassInheritanceTreeNode( deobfuscatingTranslator, ancestry.get( ancestry.size() - 1 ) ); | ||
| 188 | |||
| 189 | // expand all children recursively | ||
| 190 | rootNode.load( this, true ); | ||
| 191 | |||
| 192 | return rootNode; | ||
| 193 | } | ||
| 194 | |||
| 195 | public MethodInheritanceTreeNode getMethodInheritance( Translator deobfuscatingTranslator, MethodEntry obfMethodEntry ) | ||
| 196 | { | ||
| 197 | // travel to the ancestor implementation | ||
| 198 | String baseImplementationClassName = obfMethodEntry.getClassName(); | ||
| 199 | for( String ancestorClassName : getAncestry( obfMethodEntry.getClassName() ) ) | ||
| 200 | { | ||
| 201 | if( isMethodImplemented( ancestorClassName, obfMethodEntry.getName(), obfMethodEntry.getSignature() ) ) | ||
| 202 | { | ||
| 203 | baseImplementationClassName = ancestorClassName; | ||
| 204 | } | ||
| 205 | } | ||
| 206 | |||
| 207 | // make a root node at the base | ||
| 208 | MethodEntry methodEntry = new MethodEntry( | ||
| 209 | new ClassEntry( baseImplementationClassName ), | ||
| 210 | obfMethodEntry.getName(), | ||
| 211 | obfMethodEntry.getSignature() | ||
| 212 | ); | ||
| 213 | MethodInheritanceTreeNode rootNode = new MethodInheritanceTreeNode( | ||
| 214 | deobfuscatingTranslator, | ||
| 215 | methodEntry, | ||
| 216 | isMethodImplemented( methodEntry ) | ||
| 217 | ); | ||
| 218 | |||
| 219 | // expand the full tree | ||
| 220 | rootNode.load( this, true ); | ||
| 221 | |||
| 222 | return rootNode; | ||
| 223 | } | ||
| 224 | |||
| 149 | private boolean isJre( String className ) | 225 | private boolean isJre( String className ) |
| 150 | { | 226 | { |
| 151 | return className.startsWith( "java/" ) | 227 | return className.startsWith( "java/" ) |
| 152 | || className.startsWith( "javax/" ); | 228 | || className.startsWith( "javax/" ); |
| 153 | } | 229 | } |
| 230 | |||
| 231 | private String getMethodKey( String name, String signature ) | ||
| 232 | { | ||
| 233 | return name + signature; | ||
| 234 | } | ||
| 154 | } | 235 | } |
diff --git a/src/cuchaz/enigma/gui/ClassInheritanceTreeNode.java b/src/cuchaz/enigma/analysis/ClassInheritanceTreeNode.java index 295bebe4..2ed141ff 100644 --- a/src/cuchaz/enigma/gui/ClassInheritanceTreeNode.java +++ b/src/cuchaz/enigma/analysis/ClassInheritanceTreeNode.java | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | * Contributors: | 8 | * Contributors: |
| 9 | * Jeff Martin - initial API and implementation | 9 | * Jeff Martin - initial API and implementation |
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma.gui; | 11 | package cuchaz.enigma.analysis; |
| 12 | 12 | ||
| 13 | import java.util.List; | 13 | import java.util.List; |
| 14 | 14 | ||
| @@ -16,7 +16,7 @@ import javax.swing.tree.DefaultMutableTreeNode; | |||
| 16 | 16 | ||
| 17 | import com.google.common.collect.Lists; | 17 | import com.google.common.collect.Lists; |
| 18 | 18 | ||
| 19 | import cuchaz.enigma.mapping.Ancestries; | 19 | import cuchaz.enigma.mapping.ClassEntry; |
| 20 | import cuchaz.enigma.mapping.Translator; | 20 | import cuchaz.enigma.mapping.Translator; |
| 21 | 21 | ||
| 22 | public class ClassInheritanceTreeNode extends DefaultMutableTreeNode | 22 | public class ClassInheritanceTreeNode extends DefaultMutableTreeNode |
| @@ -76,4 +76,24 @@ public class ClassInheritanceTreeNode extends DefaultMutableTreeNode | |||
| 76 | } | 76 | } |
| 77 | } | 77 | } |
| 78 | } | 78 | } |
| 79 | |||
| 80 | public static ClassInheritanceTreeNode findNode( ClassInheritanceTreeNode node, ClassEntry entry ) | ||
| 81 | { | ||
| 82 | // is this the node? | ||
| 83 | if( node.getObfClassName().equals( entry.getName() ) ) | ||
| 84 | { | ||
| 85 | return node; | ||
| 86 | } | ||
| 87 | |||
| 88 | // recurse | ||
| 89 | for( int i=0; i<node.getChildCount(); i++ ) | ||
| 90 | { | ||
| 91 | ClassInheritanceTreeNode foundNode = findNode( (ClassInheritanceTreeNode)node.getChildAt( i ), entry ); | ||
| 92 | if( foundNode != null ) | ||
| 93 | { | ||
| 94 | return foundNode; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | return null; | ||
| 98 | } | ||
| 79 | } | 99 | } |
diff --git a/src/cuchaz/enigma/mapping/DeobfuscatedAncestries.java b/src/cuchaz/enigma/analysis/DeobfuscatedAncestries.java index dcb0741a..b14eca72 100644 --- a/src/cuchaz/enigma/mapping/DeobfuscatedAncestries.java +++ b/src/cuchaz/enigma/analysis/DeobfuscatedAncestries.java | |||
| @@ -8,10 +8,12 @@ | |||
| 8 | * Contributors: | 8 | * Contributors: |
| 9 | * Jeff Martin - initial API and implementation | 9 | * Jeff Martin - initial API and implementation |
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma.mapping; | 11 | package cuchaz.enigma.analysis; |
| 12 | 12 | ||
| 13 | import java.util.Map; | 13 | import java.util.Map; |
| 14 | 14 | ||
| 15 | import cuchaz.enigma.mapping.ClassMapping; | ||
| 16 | |||
| 15 | public class DeobfuscatedAncestries extends Ancestries | 17 | public class DeobfuscatedAncestries extends Ancestries |
| 16 | { | 18 | { |
| 17 | private static final long serialVersionUID = 8316248774892618324L; | 19 | private static final long serialVersionUID = 8316248774892618324L; |
| @@ -20,7 +22,7 @@ public class DeobfuscatedAncestries extends Ancestries | |||
| 20 | private Map<String,ClassMapping> m_classesByObf; | 22 | private Map<String,ClassMapping> m_classesByObf; |
| 21 | private Map<String,ClassMapping> m_classesByDeobf; | 23 | private Map<String,ClassMapping> m_classesByDeobf; |
| 22 | 24 | ||
| 23 | protected DeobfuscatedAncestries( Ancestries ancestries, Map<String,ClassMapping> classesByObf, Map<String,ClassMapping> classesByDeobf ) | 25 | public DeobfuscatedAncestries( Ancestries ancestries, Map<String,ClassMapping> classesByObf, Map<String,ClassMapping> classesByDeobf ) |
| 24 | { | 26 | { |
| 25 | m_ancestries = ancestries; | 27 | m_ancestries = ancestries; |
| 26 | m_classesByObf = classesByObf; | 28 | m_classesByObf = classesByObf; |
diff --git a/src/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java b/src/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java new file mode 100644 index 00000000..1fecf489 --- /dev/null +++ b/src/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java | |||
| @@ -0,0 +1,134 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Public License v3.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/gpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.analysis; | ||
| 12 | |||
| 13 | import java.util.List; | ||
| 14 | |||
| 15 | import javax.swing.tree.DefaultMutableTreeNode; | ||
| 16 | |||
| 17 | import com.google.common.collect.Lists; | ||
| 18 | |||
| 19 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 20 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 21 | import cuchaz.enigma.mapping.Translator; | ||
| 22 | |||
| 23 | public class MethodInheritanceTreeNode extends DefaultMutableTreeNode | ||
| 24 | { | ||
| 25 | private static final long serialVersionUID = 1096677030991810007L; | ||
| 26 | |||
| 27 | private Translator m_deobfuscatingTranslator; | ||
| 28 | private MethodEntry m_entry; | ||
| 29 | private boolean m_isImplemented; | ||
| 30 | |||
| 31 | public MethodInheritanceTreeNode( Translator deobfuscatingTranslator, MethodEntry entry, boolean isImplemented ) | ||
| 32 | { | ||
| 33 | m_deobfuscatingTranslator = deobfuscatingTranslator; | ||
| 34 | m_entry = entry; | ||
| 35 | m_isImplemented = isImplemented; | ||
| 36 | } | ||
| 37 | |||
| 38 | public MethodEntry getMethodEntry( ) | ||
| 39 | { | ||
| 40 | return m_entry; | ||
| 41 | } | ||
| 42 | |||
| 43 | public String getDeobfClassName( ) | ||
| 44 | { | ||
| 45 | return m_deobfuscatingTranslator.translateClass( m_entry.getClassName() ); | ||
| 46 | } | ||
| 47 | |||
| 48 | public String getDeobfMethodName( ) | ||
| 49 | { | ||
| 50 | return m_deobfuscatingTranslator.translate( m_entry ); | ||
| 51 | } | ||
| 52 | |||
| 53 | public boolean isImplemented( ) | ||
| 54 | { | ||
| 55 | return m_isImplemented; | ||
| 56 | } | ||
| 57 | |||
| 58 | @Override | ||
| 59 | public String toString( ) | ||
| 60 | { | ||
| 61 | String className = getDeobfClassName(); | ||
| 62 | if( className == null ) | ||
| 63 | { | ||
| 64 | className = m_entry.getClassName(); | ||
| 65 | } | ||
| 66 | |||
| 67 | if( !m_isImplemented ) | ||
| 68 | { | ||
| 69 | return className; | ||
| 70 | } | ||
| 71 | else | ||
| 72 | { | ||
| 73 | String methodName = getDeobfMethodName(); | ||
| 74 | if( methodName == null ) | ||
| 75 | { | ||
| 76 | methodName = m_entry.getName(); | ||
| 77 | } | ||
| 78 | return className + "." + methodName + "()"; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | public void load( Ancestries ancestries, boolean recurse ) | ||
| 83 | { | ||
| 84 | // get all the child nodes | ||
| 85 | List<MethodInheritanceTreeNode> nodes = Lists.newArrayList(); | ||
| 86 | for( String subclassName : ancestries.getSubclasses( m_entry.getClassName() ) ) | ||
| 87 | { | ||
| 88 | MethodEntry methodEntry = new MethodEntry( | ||
| 89 | new ClassEntry( subclassName ), | ||
| 90 | m_entry.getName(), | ||
| 91 | m_entry.getSignature() | ||
| 92 | ); | ||
| 93 | nodes.add( new MethodInheritanceTreeNode( | ||
| 94 | m_deobfuscatingTranslator, | ||
| 95 | methodEntry, | ||
| 96 | ancestries.isMethodImplemented( subclassName, m_entry.getName(), m_entry.getSignature() ) | ||
| 97 | ) ); | ||
| 98 | } | ||
| 99 | |||
| 100 | // add them to this node | ||
| 101 | for( MethodInheritanceTreeNode node : nodes ) | ||
| 102 | { | ||
| 103 | this.add( node ); | ||
| 104 | } | ||
| 105 | |||
| 106 | if( recurse ) | ||
| 107 | { | ||
| 108 | for( MethodInheritanceTreeNode node : nodes ) | ||
| 109 | { | ||
| 110 | node.load( ancestries, true ); | ||
| 111 | } | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | public static MethodInheritanceTreeNode findNode( MethodInheritanceTreeNode node, MethodEntry entry ) | ||
| 116 | { | ||
| 117 | // is this the node? | ||
| 118 | if( node.getMethodEntry().equals( entry ) ) | ||
| 119 | { | ||
| 120 | return node; | ||
| 121 | } | ||
| 122 | |||
| 123 | // recurse | ||
| 124 | for( int i=0; i<node.getChildCount(); i++ ) | ||
| 125 | { | ||
| 126 | MethodInheritanceTreeNode foundNode = findNode( (MethodInheritanceTreeNode)node.getChildAt( i ), entry ); | ||
| 127 | if( foundNode != null ) | ||
| 128 | { | ||
| 129 | return foundNode; | ||
| 130 | } | ||
| 131 | } | ||
| 132 | return null; | ||
| 133 | } | ||
| 134 | } | ||
diff --git a/src/cuchaz/enigma/analysis/TreeDumpVisitor.java b/src/cuchaz/enigma/analysis/TreeDumpVisitor.java index 32607db9..05d0e6be 100644 --- a/src/cuchaz/enigma/analysis/TreeDumpVisitor.java +++ b/src/cuchaz/enigma/analysis/TreeDumpVisitor.java | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Public License v3.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/gpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 1 | package cuchaz.enigma.analysis; | 11 | package cuchaz.enigma.analysis; |
| 2 | 12 | ||
| 3 | import com.strobel.componentmodel.Key; | 13 | import com.strobel.componentmodel.Key; |
diff --git a/src/cuchaz/enigma/gui/Gui.java b/src/cuchaz/enigma/gui/Gui.java index 62f23918..db676777 100644 --- a/src/cuchaz/enigma/gui/Gui.java +++ b/src/cuchaz/enigma/gui/Gui.java | |||
| @@ -66,6 +66,8 @@ import jsyntaxpane.DefaultSyntaxKit; | |||
| 66 | import com.google.common.collect.Lists; | 66 | import com.google.common.collect.Lists; |
| 67 | 67 | ||
| 68 | import cuchaz.enigma.Constants; | 68 | import cuchaz.enigma.Constants; |
| 69 | import cuchaz.enigma.analysis.ClassInheritanceTreeNode; | ||
| 70 | import cuchaz.enigma.analysis.MethodInheritanceTreeNode; | ||
| 69 | import cuchaz.enigma.analysis.Token; | 71 | import cuchaz.enigma.analysis.Token; |
| 70 | import cuchaz.enigma.mapping.ArgumentEntry; | 72 | import cuchaz.enigma.mapping.ArgumentEntry; |
| 71 | import cuchaz.enigma.mapping.ClassEntry; | 73 | import cuchaz.enigma.mapping.ClassEntry; |
| @@ -343,10 +345,24 @@ public class Gui | |||
| 343 | { | 345 | { |
| 344 | if( event.getClickCount() == 2 ) | 346 | if( event.getClickCount() == 2 ) |
| 345 | { | 347 | { |
| 346 | ClassInheritanceTreeNode node = (ClassInheritanceTreeNode)m_inheritanceTree.getSelectionPath().getLastPathComponent(); | 348 | // get the selected node |
| 347 | if( node != null ) | 349 | Object node = m_inheritanceTree.getSelectionPath().getLastPathComponent(); |
| 350 | if( node == null ) | ||
| 348 | { | 351 | { |
| 349 | m_controller.openEntry( new ClassEntry( node.getObfClassName() ) ); | 352 | return; |
| 353 | } | ||
| 354 | |||
| 355 | if( node instanceof ClassInheritanceTreeNode ) | ||
| 356 | { | ||
| 357 | m_controller.openEntry( new ClassEntry( ((ClassInheritanceTreeNode)node).getObfClassName() ) ); | ||
| 358 | } | ||
| 359 | else if( node instanceof MethodInheritanceTreeNode ) | ||
| 360 | { | ||
| 361 | MethodInheritanceTreeNode methodNode = (MethodInheritanceTreeNode)node; | ||
| 362 | if( methodNode.isImplemented() ) | ||
| 363 | { | ||
| 364 | m_controller.openEntry( methodNode.getMethodEntry() ); | ||
| 365 | } | ||
| 350 | } | 366 | } |
| 351 | } | 367 | } |
| 352 | } | 368 | } |
| @@ -836,31 +852,46 @@ public class Gui | |||
| 836 | return; | 852 | return; |
| 837 | } | 853 | } |
| 838 | 854 | ||
| 839 | // get the current class | ||
| 840 | if( m_selectedEntryPair.obf instanceof ClassEntry ) | 855 | if( m_selectedEntryPair.obf instanceof ClassEntry ) |
| 841 | { | 856 | { |
| 857 | // get the class inheritance | ||
| 842 | ClassInheritanceTreeNode classNode = m_controller.getClassInheritance( (ClassEntry)m_selectedEntryPair.obf ); | 858 | ClassInheritanceTreeNode classNode = m_controller.getClassInheritance( (ClassEntry)m_selectedEntryPair.obf ); |
| 843 | 859 | ||
| 844 | // build the path from the root to the class node | 860 | // show the tree at the root |
| 845 | List<TreeNode> nodes = Lists.newArrayList(); | 861 | TreePath path = getPathToRoot( classNode ); |
| 846 | TreeNode node = classNode; | 862 | m_inheritanceTree.setModel( new DefaultTreeModel( (TreeNode)path.getPathComponent( 0 ) ) ); |
| 847 | do | 863 | m_inheritanceTree.expandPath( path ); |
| 848 | { | 864 | m_inheritanceTree.setSelectionRow( m_inheritanceTree.getRowForPath( path ) ); |
| 849 | nodes.add( node ); | 865 | } |
| 850 | node = node.getParent(); | 866 | else if( m_selectedEntryPair.obf instanceof MethodEntry ) |
| 851 | } | 867 | { |
| 852 | while( node != null ); | 868 | // get the method inheritance |
| 853 | Collections.reverse( nodes ); | 869 | MethodInheritanceTreeNode classNode = m_controller.getMethodInheritance( (MethodEntry)m_selectedEntryPair.obf ); |
| 854 | TreePath path = new TreePath( nodes.toArray() ); | ||
| 855 | 870 | ||
| 856 | // show the tree at the root | 871 | // show the tree at the root |
| 872 | TreePath path = getPathToRoot( classNode ); | ||
| 857 | m_inheritanceTree.setModel( new DefaultTreeModel( (TreeNode)path.getPathComponent( 0 ) ) ); | 873 | m_inheritanceTree.setModel( new DefaultTreeModel( (TreeNode)path.getPathComponent( 0 ) ) ); |
| 858 | m_inheritanceTree.expandPath( path ); | 874 | m_inheritanceTree.expandPath( path ); |
| 859 | m_inheritanceTree.setSelectionRow( m_inheritanceTree.getRowForPath( path ) ); | 875 | m_inheritanceTree.setSelectionRow( m_inheritanceTree.getRowForPath( path ) ); |
| 860 | } | 876 | } |
| 877 | |||
| 861 | redraw(); | 878 | redraw(); |
| 862 | } | 879 | } |
| 863 | 880 | ||
| 881 | private TreePath getPathToRoot( TreeNode node ) | ||
| 882 | { | ||
| 883 | List<TreeNode> nodes = Lists.newArrayList(); | ||
| 884 | TreeNode n = node; | ||
| 885 | do | ||
| 886 | { | ||
| 887 | nodes.add( n ); | ||
| 888 | n = n.getParent(); | ||
| 889 | } | ||
| 890 | while( n != null ); | ||
| 891 | Collections.reverse( nodes ); | ||
| 892 | return new TreePath( nodes.toArray() ); | ||
| 893 | } | ||
| 894 | |||
| 864 | private void openEntry( ) | 895 | private void openEntry( ) |
| 865 | { | 896 | { |
| 866 | if( m_selectedEntryPair == null ) | 897 | if( m_selectedEntryPair == null ) |
diff --git a/src/cuchaz/enigma/gui/GuiController.java b/src/cuchaz/enigma/gui/GuiController.java index a4228c72..1946b4a3 100644 --- a/src/cuchaz/enigma/gui/GuiController.java +++ b/src/cuchaz/enigma/gui/GuiController.java | |||
| @@ -20,6 +20,8 @@ import java.util.Stack; | |||
| 20 | import com.google.common.collect.Lists; | 20 | import com.google.common.collect.Lists; |
| 21 | 21 | ||
| 22 | import cuchaz.enigma.Deobfuscator; | 22 | import cuchaz.enigma.Deobfuscator; |
| 23 | import cuchaz.enigma.analysis.ClassInheritanceTreeNode; | ||
| 24 | import cuchaz.enigma.analysis.MethodInheritanceTreeNode; | ||
| 23 | import cuchaz.enigma.analysis.SourceIndex; | 25 | import cuchaz.enigma.analysis.SourceIndex; |
| 24 | import cuchaz.enigma.analysis.Token; | 26 | import cuchaz.enigma.analysis.Token; |
| 25 | import cuchaz.enigma.mapping.ClassEntry; | 27 | import cuchaz.enigma.mapping.ClassEntry; |
| @@ -27,8 +29,8 @@ import cuchaz.enigma.mapping.Entry; | |||
| 27 | import cuchaz.enigma.mapping.EntryPair; | 29 | import cuchaz.enigma.mapping.EntryPair; |
| 28 | import cuchaz.enigma.mapping.MappingsReader; | 30 | import cuchaz.enigma.mapping.MappingsReader; |
| 29 | import cuchaz.enigma.mapping.MappingsWriter; | 31 | import cuchaz.enigma.mapping.MappingsWriter; |
| 32 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 30 | import cuchaz.enigma.mapping.TranslationDirection; | 33 | import cuchaz.enigma.mapping.TranslationDirection; |
| 31 | import cuchaz.enigma.mapping.Translator; | ||
| 32 | 34 | ||
| 33 | public class GuiController | 35 | public class GuiController |
| 34 | { | 36 | { |
| @@ -128,27 +130,22 @@ public class GuiController | |||
| 128 | return m_deobfuscator.entryIsObfuscatedIdenfitier( m_deobfuscator.obfuscateEntry( deobfEntry ) ); | 130 | return m_deobfuscator.entryIsObfuscatedIdenfitier( m_deobfuscator.obfuscateEntry( deobfEntry ) ); |
| 129 | } | 131 | } |
| 130 | 132 | ||
| 131 | public ClassInheritanceTreeNode getClassInheritance( ClassEntry classEntry ) | 133 | public ClassInheritanceTreeNode getClassInheritance( ClassEntry obfClassEntry ) |
| 132 | { | 134 | { |
| 133 | Translator deobfuscatingTranslator = m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ); | 135 | ClassInheritanceTreeNode rootNode = m_deobfuscator.getAncestries().getClassInheritance( |
| 134 | 136 | m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), | |
| 135 | // create a node for this class | 137 | obfClassEntry |
| 136 | ClassInheritanceTreeNode thisNode = new ClassInheritanceTreeNode( deobfuscatingTranslator, classEntry.getName() ); | 138 | ); |
| 137 | 139 | return ClassInheritanceTreeNode.findNode( rootNode, obfClassEntry ); | |
| 138 | // expand all children recursively | 140 | } |
| 139 | thisNode.load( m_deobfuscator.getAncestries(), true ); | 141 | |
| 140 | 142 | public MethodInheritanceTreeNode getMethodInheritance( MethodEntry obfMethodEntry ) | |
| 141 | // get the ancestors too | 143 | { |
| 142 | ClassInheritanceTreeNode node = thisNode; | 144 | MethodInheritanceTreeNode rootNode = m_deobfuscator.getAncestries().getMethodInheritance( |
| 143 | for( String superclassName : m_deobfuscator.getAncestries().getAncestry( classEntry.getName() ) ) | 145 | m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), |
| 144 | { | 146 | obfMethodEntry |
| 145 | // add the parent node | 147 | ); |
| 146 | ClassInheritanceTreeNode parentNode = new ClassInheritanceTreeNode( deobfuscatingTranslator, superclassName ); | 148 | return MethodInheritanceTreeNode.findNode( rootNode, obfMethodEntry ); |
| 147 | parentNode.add( node ); | ||
| 148 | node = parentNode; | ||
| 149 | } | ||
| 150 | |||
| 151 | return thisNode; | ||
| 152 | } | 149 | } |
| 153 | 150 | ||
| 154 | public void rename( Entry obfEntry, String newName ) | 151 | public void rename( Entry obfEntry, String newName ) |
diff --git a/src/cuchaz/enigma/mapping/Mappings.java b/src/cuchaz/enigma/mapping/Mappings.java index 4dff6935..c7cb6a67 100644 --- a/src/cuchaz/enigma/mapping/Mappings.java +++ b/src/cuchaz/enigma/mapping/Mappings.java | |||
| @@ -20,6 +20,8 @@ import java.util.zip.GZIPInputStream; | |||
| 20 | import com.google.common.collect.Maps; | 20 | import com.google.common.collect.Maps; |
| 21 | 21 | ||
| 22 | import cuchaz.enigma.Util; | 22 | import cuchaz.enigma.Util; |
| 23 | import cuchaz.enigma.analysis.Ancestries; | ||
| 24 | import cuchaz.enigma.analysis.DeobfuscatedAncestries; | ||
| 23 | 25 | ||
| 24 | public class Mappings implements Serializable | 26 | public class Mappings implements Serializable |
| 25 | { | 27 | { |
diff --git a/src/cuchaz/enigma/mapping/Renamer.java b/src/cuchaz/enigma/mapping/Renamer.java index b7aa35ca..5a75c016 100644 --- a/src/cuchaz/enigma/mapping/Renamer.java +++ b/src/cuchaz/enigma/mapping/Renamer.java | |||
| @@ -15,6 +15,9 @@ import java.io.ObjectOutputStream; | |||
| 15 | import java.io.OutputStream; | 15 | import java.io.OutputStream; |
| 16 | import java.util.zip.GZIPOutputStream; | 16 | import java.util.zip.GZIPOutputStream; |
| 17 | 17 | ||
| 18 | import cuchaz.enigma.analysis.Ancestries; | ||
| 19 | import cuchaz.enigma.analysis.MethodInheritanceTreeNode; | ||
| 20 | |||
| 18 | public class Renamer | 21 | public class Renamer |
| 19 | { | 22 | { |
| 20 | private Ancestries m_ancestries; | 23 | private Ancestries m_ancestries; |
| @@ -54,6 +57,30 @@ public class Renamer | |||
| 54 | classMapping.setFieldName( obf.getName(), deobfName ); | 57 | classMapping.setFieldName( obf.getName(), deobfName ); |
| 55 | } | 58 | } |
| 56 | 59 | ||
| 60 | public void setMethodTreeName( MethodEntry obf, String deobfName ) | ||
| 61 | { | ||
| 62 | // get the method tree | ||
| 63 | setMethodTreeName( | ||
| 64 | m_ancestries.getMethodInheritance( m_mappings.getTranslator( m_ancestries, TranslationDirection.Deobfuscating ), obf ), | ||
| 65 | deobfName | ||
| 66 | ); | ||
| 67 | } | ||
| 68 | |||
| 69 | private void setMethodTreeName( MethodInheritanceTreeNode node, String deobfName ) | ||
| 70 | { | ||
| 71 | if( node.isImplemented() ) | ||
| 72 | { | ||
| 73 | // apply the name here | ||
| 74 | setMethodName( node.getMethodEntry(), deobfName ); | ||
| 75 | } | ||
| 76 | |||
| 77 | // recurse | ||
| 78 | for( int i=0; i<node.getChildCount(); i++ ) | ||
| 79 | { | ||
| 80 | setMethodTreeName( (MethodInheritanceTreeNode)node.getChildAt( i ), deobfName ); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 57 | public void setMethodName( MethodEntry obf, String deobfName ) | 84 | public void setMethodName( MethodEntry obf, String deobfName ) |
| 58 | { | 85 | { |
| 59 | deobfName = NameValidator.validateMethodName( deobfName ); | 86 | deobfName = NameValidator.validateMethodName( deobfName ); |
| @@ -67,6 +94,7 @@ public class Renamer | |||
| 67 | classMapping.setMethodNameAndSignature( obf.getName(), obf.getSignature(), deobfName, deobfSignature ); | 94 | classMapping.setMethodNameAndSignature( obf.getName(), obf.getSignature(), deobfName, deobfSignature ); |
| 68 | 95 | ||
| 69 | // TODO: update ancestor/descendant methods in other classes in the inheritance hierarchy too | 96 | // TODO: update ancestor/descendant methods in other classes in the inheritance hierarchy too |
| 97 | |||
| 70 | } | 98 | } |
| 71 | 99 | ||
| 72 | public void setArgumentName( ArgumentEntry obf, String deobfName ) | 100 | public void setArgumentName( ArgumentEntry obf, String deobfName ) |
diff --git a/src/cuchaz/enigma/mapping/Translator.java b/src/cuchaz/enigma/mapping/Translator.java index 4ab53bc5..02565c94 100644 --- a/src/cuchaz/enigma/mapping/Translator.java +++ b/src/cuchaz/enigma/mapping/Translator.java | |||
| @@ -14,6 +14,7 @@ import java.util.ArrayList; | |||
| 14 | import java.util.List; | 14 | import java.util.List; |
| 15 | import java.util.Map; | 15 | import java.util.Map; |
| 16 | 16 | ||
| 17 | import cuchaz.enigma.analysis.Ancestries; | ||
| 17 | import cuchaz.enigma.mapping.SignatureUpdater.ClassNameUpdater; | 18 | import cuchaz.enigma.mapping.SignatureUpdater.ClassNameUpdater; |
| 18 | 19 | ||
| 19 | public class Translator | 20 | public class Translator |