summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/convert/ClassIdentity.java
diff options
context:
space:
mode:
authorGravatar jeff2014-08-30 16:31:31 -0400
committerGravatar jeff2014-08-30 16:31:31 -0400
commit59c592673635e989fd0785d41d51d7c3dd17cc0b (patch)
treeccbf73bd2b45bdfa6901db03100e5ff7f4116220 /src/cuchaz/enigma/convert/ClassIdentity.java
parentfinished class matching for now, need to work on class member matching (diff)
downloadenigma-fork-59c592673635e989fd0785d41d51d7c3dd17cc0b.tar.gz
enigma-fork-59c592673635e989fd0785d41d51d7c3dd17cc0b.tar.xz
enigma-fork-59c592673635e989fd0785d41d51d7c3dd17cc0b.zip
debugging class matcher... almost got it!
Diffstat (limited to 'src/cuchaz/enigma/convert/ClassIdentity.java')
-rw-r--r--src/cuchaz/enigma/convert/ClassIdentity.java40
1 files changed, 24 insertions, 16 deletions
diff --git a/src/cuchaz/enigma/convert/ClassIdentity.java b/src/cuchaz/enigma/convert/ClassIdentity.java
index 980f31f..8de7128 100644
--- a/src/cuchaz/enigma/convert/ClassIdentity.java
+++ b/src/cuchaz/enigma/convert/ClassIdentity.java
@@ -16,7 +16,6 @@ import java.security.NoSuchAlgorithmException;
16import java.util.Enumeration; 16import java.util.Enumeration;
17import java.util.List; 17import java.util.List;
18import java.util.Map; 18import java.util.Map;
19import java.util.Set;
20 19
21import javassist.CannotCompileException; 20import javassist.CannotCompileException;
22import javassist.CtBehavior; 21import javassist.CtBehavior;
@@ -36,8 +35,9 @@ import javassist.expr.MethodCall;
36import javassist.expr.NewExpr; 35import javassist.expr.NewExpr;
37 36
38import com.beust.jcommander.internal.Maps; 37import com.beust.jcommander.internal.Maps;
39import com.beust.jcommander.internal.Sets; 38import com.google.common.collect.HashMultiset;
40import com.google.common.collect.Lists; 39import com.google.common.collect.Lists;
40import com.google.common.collect.Multiset;
41 41
42import cuchaz.enigma.Constants; 42import cuchaz.enigma.Constants;
43import cuchaz.enigma.Util; 43import cuchaz.enigma.Util;
@@ -62,14 +62,14 @@ public class ClassIdentity
62 private ClassEntry m_classEntry; 62 private ClassEntry m_classEntry;
63 private String m_rawName; 63 private String m_rawName;
64 private SidedClassNamer m_namer; 64 private SidedClassNamer m_namer;
65 private Set<String> m_fields; 65 private Multiset<String> m_fields;
66 private Set<String> m_methods; 66 private Multiset<String> m_methods;
67 private Set<String> m_constructors; 67 private Multiset<String> m_constructors;
68 private String m_staticInitializer; 68 private String m_staticInitializer;
69 private String m_extends; 69 private String m_extends;
70 private Set<String> m_implements; 70 private Multiset<String> m_implements;
71 private Set<String> m_implementations; 71 private Multiset<String> m_implementations;
72 private Set<String> m_references; 72 private Multiset<String> m_references;
73 73
74 public ClassIdentity( CtClass c, SidedClassNamer namer, JarIndex index, boolean useReferences, boolean useRawNames ) 74 public ClassIdentity( CtClass c, SidedClassNamer namer, JarIndex index, boolean useReferences, boolean useRawNames )
75 { 75 {
@@ -83,17 +83,17 @@ public class ClassIdentity
83 { 83 {
84 m_rawName = m_classEntry.getName(); 84 m_rawName = m_classEntry.getName();
85 } 85 }
86 m_fields = Sets.newHashSet(); 86 m_fields = HashMultiset.create();
87 for( CtField field : c.getDeclaredFields() ) 87 for( CtField field : c.getDeclaredFields() )
88 { 88 {
89 m_fields.add( scrubSignature( field.getSignature() ) ); 89 m_fields.add( scrubSignature( field.getSignature() ) );
90 } 90 }
91 m_methods = Sets.newHashSet(); 91 m_methods = HashMultiset.create();
92 for( CtMethod method : c.getDeclaredMethods() ) 92 for( CtMethod method : c.getDeclaredMethods() )
93 { 93 {
94 m_methods.add( scrubSignature( method.getSignature() ) + "0x" + getBehaviorSignature( method ) ); 94 m_methods.add( scrubSignature( method.getSignature() ) + "0x" + getBehaviorSignature( method ) );
95 } 95 }
96 m_constructors = Sets.newHashSet(); 96 m_constructors = HashMultiset.create();
97 for( CtConstructor constructor : c.getDeclaredConstructors() ) 97 for( CtConstructor constructor : c.getDeclaredConstructors() )
98 { 98 {
99 m_constructors.add( scrubSignature( constructor.getSignature() ) + "0x" + getBehaviorSignature( constructor ) ); 99 m_constructors.add( scrubSignature( constructor.getSignature() ) + "0x" + getBehaviorSignature( constructor ) );
@@ -108,7 +108,7 @@ public class ClassIdentity
108 { 108 {
109 m_extends = scrubClassName( c.getClassFile().getSuperclass() ); 109 m_extends = scrubClassName( c.getClassFile().getSuperclass() );
110 } 110 }
111 m_implements = Sets.newHashSet(); 111 m_implements = HashMultiset.create();
112 for( String interfaceName : c.getClassFile().getInterfaces() ) 112 for( String interfaceName : c.getClassFile().getInterfaces() )
113 { 113 {
114 m_implements.add( scrubClassName( interfaceName ) ); 114 m_implements.add( scrubClassName( interfaceName ) );
@@ -116,7 +116,7 @@ public class ClassIdentity
116 116
117 // stuff from the jar index 117 // stuff from the jar index
118 118
119 m_implementations = Sets.newHashSet(); 119 m_implementations = HashMultiset.create();
120 @SuppressWarnings( "unchecked" ) 120 @SuppressWarnings( "unchecked" )
121 Enumeration<ClassImplementationsTreeNode> implementations = index.getClassImplementations( null, m_classEntry ).children(); 121 Enumeration<ClassImplementationsTreeNode> implementations = index.getClassImplementations( null, m_classEntry ).children();
122 while( implementations.hasMoreElements() ) 122 while( implementations.hasMoreElements() )
@@ -125,7 +125,7 @@ public class ClassIdentity
125 m_implementations.add( scrubClassName( node.getClassEntry().getName() ) ); 125 m_implementations.add( scrubClassName( node.getClassEntry().getName() ) );
126 } 126 }
127 127
128 m_references = Sets.newHashSet(); 128 m_references = HashMultiset.create();
129 if( useReferences ) 129 if( useReferences )
130 { 130 {
131 for( CtField field : c.getDeclaredFields() ) 131 for( CtField field : c.getDeclaredFields() )
@@ -154,7 +154,7 @@ public class ClassIdentity
154 } 154 }
155 } 155 }
156 } 156 }
157 157
158 private void addReference( EntryReference<? extends Entry,BehaviorEntry> reference ) 158 private void addReference( EntryReference<? extends Entry,BehaviorEntry> reference )
159 { 159 {
160 if( reference.context.getSignature() != null ) 160 if( reference.context.getSignature() != null )
@@ -473,7 +473,15 @@ public class ClassIdentity
473 + getNumMatches( m_constructors, other.m_constructors ); 473 + getNumMatches( m_constructors, other.m_constructors );
474 } 474 }
475 475
476 private int getNumMatches( Set<String> a, Set<String> b ) 476 public boolean matches( CtClass c )
477 {
478 // just compare declaration counts
479 return m_fields.size() == c.getDeclaredFields().length
480 && m_methods.size() == c.getDeclaredMethods().length
481 && m_constructors.size() == c.getDeclaredConstructors().length;
482 }
483
484 private int getNumMatches( Multiset<String> a, Multiset<String> b )
477 { 485 {
478 int numMatches = 0; 486 int numMatches = 0;
479 for( String val : a ) 487 for( String val : a )