summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/analysis/JarIndex.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/JarIndex.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/JarIndex.java')
-rw-r--r--src/cuchaz/enigma/analysis/JarIndex.java107
1 files changed, 87 insertions, 20 deletions
diff --git a/src/cuchaz/enigma/analysis/JarIndex.java b/src/cuchaz/enigma/analysis/JarIndex.java
index 06b0173..96bddc1 100644
--- a/src/cuchaz/enigma/analysis/JarIndex.java
+++ b/src/cuchaz/enigma/analysis/JarIndex.java
@@ -27,17 +27,26 @@ import javassist.CannotCompileException;
27import javassist.ClassPool; 27import javassist.ClassPool;
28import javassist.CtBehavior; 28import javassist.CtBehavior;
29import javassist.CtClass; 29import javassist.CtClass;
30import javassist.CtConstructor;
31import javassist.CtMethod;
30import javassist.NotFoundException; 32import javassist.NotFoundException;
31import javassist.bytecode.Descriptor; 33import javassist.bytecode.Descriptor;
34import javassist.expr.ConstructorCall;
32import javassist.expr.ExprEditor; 35import javassist.expr.ExprEditor;
36import javassist.expr.FieldAccess;
33import javassist.expr.MethodCall; 37import javassist.expr.MethodCall;
38import javassist.expr.NewExpr;
34 39
35import com.google.common.collect.HashMultimap; 40import com.google.common.collect.HashMultimap;
41import com.google.common.collect.Lists;
36import com.google.common.collect.Multimap; 42import com.google.common.collect.Multimap;
37import com.google.common.collect.Sets; 43import com.google.common.collect.Sets;
38 44
39import cuchaz.enigma.Constants; 45import cuchaz.enigma.Constants;
40import cuchaz.enigma.mapping.ClassEntry; 46import cuchaz.enigma.mapping.ClassEntry;
47import cuchaz.enigma.mapping.ConstructorEntry;
48import cuchaz.enigma.mapping.Entry;
49import cuchaz.enigma.mapping.FieldEntry;
41import cuchaz.enigma.mapping.MethodEntry; 50import cuchaz.enigma.mapping.MethodEntry;
42import cuchaz.enigma.mapping.Translator; 51import cuchaz.enigma.mapping.Translator;
43 52
@@ -46,7 +55,8 @@ public class JarIndex
46 private Set<String> m_obfClassNames; 55 private Set<String> m_obfClassNames;
47 private Ancestries m_ancestries; 56 private Ancestries m_ancestries;
48 private Multimap<String,MethodEntry> m_methodImplementations; 57 private Multimap<String,MethodEntry> m_methodImplementations;
49 private Multimap<MethodEntry,MethodEntry> m_methodCalls; 58 private Multimap<Entry,Entry> m_methodCalls;
59 private Multimap<FieldEntry,Entry> m_fieldCalls;
50 60
51 public JarIndex( JarFile jar ) 61 public JarIndex( JarFile jar )
52 { 62 {
@@ -54,6 +64,7 @@ public class JarIndex
54 m_ancestries = new Ancestries(); 64 m_ancestries = new Ancestries();
55 m_methodImplementations = HashMultimap.create(); 65 m_methodImplementations = HashMultimap.create();
56 m_methodCalls = HashMultimap.create(); 66 m_methodCalls = HashMultimap.create();
67 m_fieldCalls = HashMultimap.create();
57 68
58 // read the class names 69 // read the class names
59 Enumeration<JarEntry> enumeration = jar.entries(); 70 Enumeration<JarEntry> enumeration = jar.entries();
@@ -133,14 +144,30 @@ public class JarIndex
133 { 144 {
134 // get the method entry 145 // get the method entry
135 String className = Descriptor.toJvmName( behavior.getDeclaringClass().getName() ); 146 String className = Descriptor.toJvmName( behavior.getDeclaringClass().getName() );
136 final MethodEntry methodEntry = new MethodEntry( 147 final Entry thisEntry;
137 new ClassEntry( className ), 148 if( behavior instanceof CtMethod )
138 behavior.getName(), 149 {
139 behavior.getSignature() 150 MethodEntry methodEntry = new MethodEntry(
140 ); 151 new ClassEntry( className ),
141 152 behavior.getName(),
142 // index implementation 153 behavior.getSignature()
143 m_methodImplementations.put( className, methodEntry ); 154 );
155 thisEntry = methodEntry;
156
157 // index implementation
158 m_methodImplementations.put( className, methodEntry );
159 }
160 else if( behavior instanceof CtConstructor )
161 {
162 thisEntry = new ConstructorEntry(
163 new ClassEntry( className ),
164 behavior.getSignature()
165 );
166 }
167 else
168 {
169 throw new IllegalArgumentException( "behavior must be a method or a constructor!" );
170 }
144 171
145 // index method calls 172 // index method calls
146 try 173 try
@@ -150,20 +177,53 @@ public class JarIndex
150 @Override 177 @Override
151 public void edit( MethodCall call ) 178 public void edit( MethodCall call )
152 { 179 {
153 // is this a jar class?
154 String className = Descriptor.toJvmName( call.getClassName() ); 180 String className = Descriptor.toJvmName( call.getClassName() );
155 if( !m_obfClassNames.contains( className ) )
156 {
157 return;
158 }
159
160 // make entry for the called method
161 MethodEntry calledMethodEntry = new MethodEntry( 181 MethodEntry calledMethodEntry = new MethodEntry(
162 new ClassEntry( className ), 182 new ClassEntry( className ),
163 call.getMethodName(), 183 call.getMethodName(),
164 call.getSignature() 184 call.getSignature()
165 ); 185 );
166 m_methodCalls.put( calledMethodEntry, methodEntry ); 186 m_methodCalls.put( calledMethodEntry, thisEntry );
187 }
188
189 @Override
190 public void edit( FieldAccess call )
191 {
192 String className = Descriptor.toJvmName( call.getClassName() );
193 FieldEntry calledFieldEntry = new FieldEntry(
194 new ClassEntry( className ),
195 call.getFieldName()
196 );
197 m_fieldCalls.put( calledFieldEntry, thisEntry );
198 }
199
200 @Override
201 public void edit( ConstructorCall call )
202 {
203 String className = Descriptor.toJvmName( call.getClassName() );
204 ConstructorEntry calledConstructorEntry = new ConstructorEntry(
205 new ClassEntry( className ),
206 call.getSignature()
207 );
208 m_methodCalls.put( calledConstructorEntry, thisEntry );
209 }
210
211 @Override
212 public void edit( NewExpr call )
213 {
214 String className = Descriptor.toJvmName( call.getClassName() );
215 ConstructorEntry calledConstructorEntry = new ConstructorEntry(
216 new ClassEntry( className ),
217 call.getSignature()
218 );
219
220 // TEMP
221 if( className.equals( "bgw" ) )
222 {
223 System.out.println( calledConstructorEntry + " called by " + thisEntry );
224 }
225
226 m_methodCalls.put( calledConstructorEntry, thisEntry );
167 } 227 }
168 } ); 228 } );
169 } 229 }
@@ -202,7 +262,9 @@ public class JarIndex
202 public ClassInheritanceTreeNode getClassInheritance( Translator deobfuscatingTranslator, ClassEntry obfClassEntry ) 262 public ClassInheritanceTreeNode getClassInheritance( Translator deobfuscatingTranslator, ClassEntry obfClassEntry )
203 { 263 {
204 // get the root node 264 // get the root node
205 List<String> ancestry = m_ancestries.getAncestry( obfClassEntry.getName() ); 265 List<String> ancestry = Lists.newArrayList();
266 ancestry.add( obfClassEntry.getName() );
267 ancestry.addAll( m_ancestries.getAncestry( obfClassEntry.getName() ) );
206 ClassInheritanceTreeNode rootNode = new ClassInheritanceTreeNode( deobfuscatingTranslator, ancestry.get( ancestry.size() - 1 ) ); 268 ClassInheritanceTreeNode rootNode = new ClassInheritanceTreeNode( deobfuscatingTranslator, ancestry.get( ancestry.size() - 1 ) );
207 269
208 // expand all children recursively 270 // expand all children recursively
@@ -241,9 +303,14 @@ public class JarIndex
241 return rootNode; 303 return rootNode;
242 } 304 }
243 305
244 public Collection<MethodEntry> getMethodCallers( MethodEntry methodEntry ) 306 public Collection<Entry> getFieldCallers( FieldEntry fieldEntry )
307 {
308 return m_fieldCalls.get( fieldEntry );
309 }
310
311 public Collection<Entry> getMethodCallers( Entry entry )
245 { 312 {
246 return m_methodCalls.get( methodEntry ); 313 return m_methodCalls.get( entry );
247 } 314 }
248 315
249 private String getMethodKey( String name, String signature ) 316 private String getMethodKey( String name, String signature )