summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/analysis/MethodCallsTreeNode.java
diff options
context:
space:
mode:
authorGravatar jeff2014-08-13 00:22:12 -0400
committerGravatar jeff2014-08-13 00:22:12 -0400
commitcc74d0e62cfdcf14c5918234f69d587d264807ed (patch)
tree7a11bd6af9b7cd2f28c3dbd43a281b4036464f77 /src/cuchaz/enigma/analysis/MethodCallsTreeNode.java
parentgot simple method call graph working! (diff)
downloadenigma-fork-cc74d0e62cfdcf14c5918234f69d587d264807ed.tar.gz
enigma-fork-cc74d0e62cfdcf14c5918234f69d587d264807ed.tar.xz
enigma-fork-cc74d0e62cfdcf14c5918234f69d587d264807ed.zip
added support for field access searches
added proper detection/handling for constructors
Diffstat (limited to 'src/cuchaz/enigma/analysis/MethodCallsTreeNode.java')
-rw-r--r--src/cuchaz/enigma/analysis/MethodCallsTreeNode.java114
1 files changed, 81 insertions, 33 deletions
diff --git a/src/cuchaz/enigma/analysis/MethodCallsTreeNode.java b/src/cuchaz/enigma/analysis/MethodCallsTreeNode.java
index dedfb2e..b5cf4c3 100644
--- a/src/cuchaz/enigma/analysis/MethodCallsTreeNode.java
+++ b/src/cuchaz/enigma/analysis/MethodCallsTreeNode.java
@@ -10,12 +10,15 @@
10 ******************************************************************************/ 10 ******************************************************************************/
11package cuchaz.enigma.analysis; 11package cuchaz.enigma.analysis;
12 12
13import java.util.List; 13import java.util.Set;
14 14
15import javax.swing.tree.DefaultMutableTreeNode; 15import javax.swing.tree.DefaultMutableTreeNode;
16import javax.swing.tree.TreeNode;
16 17
17import com.google.common.collect.Lists; 18import com.google.common.collect.Sets;
18 19
20import cuchaz.enigma.mapping.ConstructorEntry;
21import cuchaz.enigma.mapping.Entry;
19import cuchaz.enigma.mapping.MethodEntry; 22import cuchaz.enigma.mapping.MethodEntry;
20import cuchaz.enigma.mapping.Translator; 23import cuchaz.enigma.mapping.Translator;
21 24
@@ -24,72 +27,117 @@ public class MethodCallsTreeNode extends DefaultMutableTreeNode
24 private static final long serialVersionUID = -3658163700783307520L; 27 private static final long serialVersionUID = -3658163700783307520L;
25 28
26 private Translator m_deobfuscatingTranslator; 29 private Translator m_deobfuscatingTranslator;
27 private MethodEntry m_entry; 30 private MethodEntry m_methodEntry;
31 private ConstructorEntry m_constructorEntry;
28 32
29 public MethodCallsTreeNode( Translator deobfuscatingTranslator, MethodEntry entry ) 33 public MethodCallsTreeNode( Translator deobfuscatingTranslator, MethodEntry entry )
30 { 34 {
31 m_deobfuscatingTranslator = deobfuscatingTranslator; 35 m_deobfuscatingTranslator = deobfuscatingTranslator;
32 m_entry = entry; 36 m_methodEntry = entry;
37 m_constructorEntry = null;
38 }
39
40 public MethodCallsTreeNode( Translator deobfuscatingTranslator, ConstructorEntry entry )
41 {
42 m_deobfuscatingTranslator = deobfuscatingTranslator;
43 m_methodEntry = null;
44 m_constructorEntry = entry;
33 } 45 }
34 46
35 public MethodEntry getMethodEntry( ) 47 public MethodEntry getMethodEntry( )
36 { 48 {
37 return m_entry; 49 return m_methodEntry;
38 } 50 }
39 51
40 public String getDeobfClassName( ) 52 public ConstructorEntry getConstructorEntry( )
41 { 53 {
42 return m_deobfuscatingTranslator.translateClass( m_entry.getClassName() ); 54 return m_constructorEntry;
43 } 55 }
44 56
45 public String getDeobfMethodName( ) 57 public Entry getEntry( )
46 { 58 {
47 return m_deobfuscatingTranslator.translate( m_entry ); 59 if( m_methodEntry != null )
60 {
61 return m_methodEntry;
62 }
63 else if( m_constructorEntry != null )
64 {
65 return m_constructorEntry;
66 }
67 throw new Error( "Illegal state!" );
48 } 68 }
49 69
50 @Override 70 @Override
51 public String toString( ) 71 public String toString( )
52 { 72 {
53 String className = getDeobfClassName(); 73 if( m_methodEntry != null )
54 if( className == null )
55 { 74 {
56 className = m_entry.getClassName(); 75 String className = m_deobfuscatingTranslator.translateClass( m_methodEntry.getClassName() );
76 if( className == null )
77 {
78 className = m_methodEntry.getClassName();
79 }
80
81 String methodName = m_deobfuscatingTranslator.translate( m_methodEntry );
82 if( methodName == null )
83 {
84 methodName = m_methodEntry.getName();
85 }
86 return className + "." + methodName + "()";
57 } 87 }
58 88 else if( m_constructorEntry != null )
59 String methodName = getDeobfMethodName();
60 if( methodName == null )
61 { 89 {
62 methodName = m_entry.getName(); 90 String className = m_deobfuscatingTranslator.translateClass( m_constructorEntry.getClassName() );
91 if( className == null )
92 {
93 className = m_constructorEntry.getClassName();
94 }
95 return className + "()";
63 } 96 }
64 return className + "." + methodName + "()"; 97 throw new Error( "Illegal state!" );
65 } 98 }
66 99
67 public void load( JarIndex index, boolean recurse ) 100 public void load( JarIndex index, boolean recurse )
68 { 101 {
69 // get all the child nodes 102 // get all the child nodes
70 List<MethodCallsTreeNode> nodes = Lists.newArrayList(); 103 for( Entry entry : index.getMethodCallers( getEntry() ) )
71 for( MethodEntry entry : index.getMethodCallers( m_entry ) )
72 { 104 {
73 nodes.add( new MethodCallsTreeNode( m_deobfuscatingTranslator, entry ) ); 105 if( entry instanceof MethodEntry )
74 } 106 {
75 107 add( new MethodCallsTreeNode( m_deobfuscatingTranslator, (MethodEntry)entry ) );
76 // add them to this node 108 }
77 for( MethodCallsTreeNode node : nodes ) 109 else if( entry instanceof ConstructorEntry )
78 { 110 {
79 this.add( node ); 111 add( new MethodCallsTreeNode( m_deobfuscatingTranslator, (ConstructorEntry)entry ) );
112 }
80 } 113 }
81 114
82 if( recurse ) 115 if( recurse && children != null )
83 { 116 {
84 for( MethodCallsTreeNode node : nodes ) 117 for( Object child : children )
85 { 118 {
86 // don't recurse into self 119 if( child instanceof MethodCallsTreeNode )
87 if( node.getMethodEntry().equals( m_entry ) )
88 { 120 {
89 continue; 121 MethodCallsTreeNode node = (MethodCallsTreeNode)child;
122
123 // don't recurse into ancestor
124 Set<Entry> ancestors = Sets.newHashSet();
125 TreeNode n = (TreeNode)node;
126 while( n.getParent() != null )
127 {
128 n = n.getParent();
129 if( n instanceof MethodCallsTreeNode )
130 {
131 ancestors.add( ((MethodCallsTreeNode)n).getEntry() );
132 }
133 }
134 if( ancestors.contains( node.getEntry() ) )
135 {
136 continue;
137 }
138
139 node.load( index, true );
90 } 140 }
91
92 node.load( index, true );
93 } 141 }
94 } 142 }
95 } 143 }