summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cuchaz/enigma/Deobfuscator.java4
-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.java134
-rw-r--r--src/cuchaz/enigma/analysis/TreeDumpVisitor.java10
-rw-r--r--src/cuchaz/enigma/gui/Gui.java61
-rw-r--r--src/cuchaz/enigma/gui/GuiController.java39
-rw-r--r--src/cuchaz/enigma/mapping/Mappings.java2
-rw-r--r--src/cuchaz/enigma/mapping/Renamer.java28
-rw-r--r--src/cuchaz/enigma/mapping/Translator.java1
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;
31import com.strobel.decompiler.languages.java.ast.CompilationUnit; 31import com.strobel.decompiler.languages.java.ast.CompilationUnit;
32import com.strobel.decompiler.languages.java.ast.InsertParenthesesVisitor; 32import com.strobel.decompiler.languages.java.ast.InsertParenthesesVisitor;
33 33
34import cuchaz.enigma.analysis.Ancestries;
34import cuchaz.enigma.analysis.SourceIndex; 35import cuchaz.enigma.analysis.SourceIndex;
35import cuchaz.enigma.analysis.SourceIndexVisitor; 36import cuchaz.enigma.analysis.SourceIndexVisitor;
36import cuchaz.enigma.mapping.Ancestries;
37import cuchaz.enigma.mapping.ArgumentEntry; 37import cuchaz.enigma.mapping.ArgumentEntry;
38import cuchaz.enigma.mapping.ClassEntry; 38import cuchaz.enigma.mapping.ClassEntry;
39import cuchaz.enigma.mapping.ClassMapping; 39import 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 ******************************************************************************/
11package cuchaz.enigma.mapping; 11package cuchaz.enigma.analysis;
12 12
13import java.io.ByteArrayOutputStream; 13import java.io.ByteArrayOutputStream;
14import java.io.IOException; 14import java.io.IOException;
15import java.io.InputStream; 15import java.io.InputStream;
16import java.io.Serializable; 16import java.io.Serializable;
17import java.util.ArrayList; 17import java.util.ArrayList;
18import java.util.Collection;
18import java.util.List; 19import java.util.List;
19import java.util.Map; 20import java.util.Map;
20import java.util.zip.ZipEntry; 21import java.util.zip.ZipEntry;
@@ -25,23 +26,32 @@ import javassist.ClassPool;
25import javassist.CtClass; 26import javassist.CtClass;
26import javassist.NotFoundException; 27import javassist.NotFoundException;
27import javassist.bytecode.Descriptor; 28import javassist.bytecode.Descriptor;
29import javassist.bytecode.MethodInfo;
28 30
31import com.google.common.collect.HashMultimap;
29import com.google.common.collect.Lists; 32import com.google.common.collect.Lists;
30import com.google.common.collect.Maps; 33import com.google.common.collect.Maps;
34import com.google.common.collect.Multimap;
31 35
32import cuchaz.enigma.Constants; 36import cuchaz.enigma.Constants;
37import cuchaz.enigma.mapping.ClassEntry;
38import cuchaz.enigma.mapping.MethodEntry;
39import cuchaz.enigma.mapping.Translator;
33 40
34public class Ancestries implements Serializable 41public 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 ******************************************************************************/
11package cuchaz.enigma.gui; 11package cuchaz.enigma.analysis;
12 12
13import java.util.List; 13import java.util.List;
14 14
@@ -16,7 +16,7 @@ import javax.swing.tree.DefaultMutableTreeNode;
16 16
17import com.google.common.collect.Lists; 17import com.google.common.collect.Lists;
18 18
19import cuchaz.enigma.mapping.Ancestries; 19import cuchaz.enigma.mapping.ClassEntry;
20import cuchaz.enigma.mapping.Translator; 20import cuchaz.enigma.mapping.Translator;
21 21
22public class ClassInheritanceTreeNode extends DefaultMutableTreeNode 22public 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 ******************************************************************************/
11package cuchaz.enigma.mapping; 11package cuchaz.enigma.analysis;
12 12
13import java.util.Map; 13import java.util.Map;
14 14
15import cuchaz.enigma.mapping.ClassMapping;
16
15public class DeobfuscatedAncestries extends Ancestries 17public 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 ******************************************************************************/
11package cuchaz.enigma.analysis;
12
13import java.util.List;
14
15import javax.swing.tree.DefaultMutableTreeNode;
16
17import com.google.common.collect.Lists;
18
19import cuchaz.enigma.mapping.ClassEntry;
20import cuchaz.enigma.mapping.MethodEntry;
21import cuchaz.enigma.mapping.Translator;
22
23public 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 ******************************************************************************/
1package cuchaz.enigma.analysis; 11package cuchaz.enigma.analysis;
2 12
3import com.strobel.componentmodel.Key; 13import 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;
66import com.google.common.collect.Lists; 66import com.google.common.collect.Lists;
67 67
68import cuchaz.enigma.Constants; 68import cuchaz.enigma.Constants;
69import cuchaz.enigma.analysis.ClassInheritanceTreeNode;
70import cuchaz.enigma.analysis.MethodInheritanceTreeNode;
69import cuchaz.enigma.analysis.Token; 71import cuchaz.enigma.analysis.Token;
70import cuchaz.enigma.mapping.ArgumentEntry; 72import cuchaz.enigma.mapping.ArgumentEntry;
71import cuchaz.enigma.mapping.ClassEntry; 73import 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;
20import com.google.common.collect.Lists; 20import com.google.common.collect.Lists;
21 21
22import cuchaz.enigma.Deobfuscator; 22import cuchaz.enigma.Deobfuscator;
23import cuchaz.enigma.analysis.ClassInheritanceTreeNode;
24import cuchaz.enigma.analysis.MethodInheritanceTreeNode;
23import cuchaz.enigma.analysis.SourceIndex; 25import cuchaz.enigma.analysis.SourceIndex;
24import cuchaz.enigma.analysis.Token; 26import cuchaz.enigma.analysis.Token;
25import cuchaz.enigma.mapping.ClassEntry; 27import cuchaz.enigma.mapping.ClassEntry;
@@ -27,8 +29,8 @@ import cuchaz.enigma.mapping.Entry;
27import cuchaz.enigma.mapping.EntryPair; 29import cuchaz.enigma.mapping.EntryPair;
28import cuchaz.enigma.mapping.MappingsReader; 30import cuchaz.enigma.mapping.MappingsReader;
29import cuchaz.enigma.mapping.MappingsWriter; 31import cuchaz.enigma.mapping.MappingsWriter;
32import cuchaz.enigma.mapping.MethodEntry;
30import cuchaz.enigma.mapping.TranslationDirection; 33import cuchaz.enigma.mapping.TranslationDirection;
31import cuchaz.enigma.mapping.Translator;
32 34
33public class GuiController 35public 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;
20import com.google.common.collect.Maps; 20import com.google.common.collect.Maps;
21 21
22import cuchaz.enigma.Util; 22import cuchaz.enigma.Util;
23import cuchaz.enigma.analysis.Ancestries;
24import cuchaz.enigma.analysis.DeobfuscatedAncestries;
23 25
24public class Mappings implements Serializable 26public 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;
15import java.io.OutputStream; 15import java.io.OutputStream;
16import java.util.zip.GZIPOutputStream; 16import java.util.zip.GZIPOutputStream;
17 17
18import cuchaz.enigma.analysis.Ancestries;
19import cuchaz.enigma.analysis.MethodInheritanceTreeNode;
20
18public class Renamer 21public 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;
14import java.util.List; 14import java.util.List;
15import java.util.Map; 15import java.util.Map;
16 16
17import cuchaz.enigma.analysis.Ancestries;
17import cuchaz.enigma.mapping.SignatureUpdater.ClassNameUpdater; 18import cuchaz.enigma.mapping.SignatureUpdater.ClassNameUpdater;
18 19
19public class Translator 20public class Translator