diff options
| author | 2014-08-30 14:14:54 -0400 | |
|---|---|---|
| committer | 2014-08-30 14:14:54 -0400 | |
| commit | 63172120a39a315e29bc38ea6634741797b3dcab (patch) | |
| tree | 9030b8678aaca06982ae4d1032298f52ab833e09 /src/cuchaz/enigma/convert/ClassIdentity.java | |
| parent | got a decent class matcher working (diff) | |
| download | enigma-fork-63172120a39a315e29bc38ea6634741797b3dcab.tar.gz enigma-fork-63172120a39a315e29bc38ea6634741797b3dcab.tar.xz enigma-fork-63172120a39a315e29bc38ea6634741797b3dcab.zip | |
finished class matching for now, need to work on class member matching
Diffstat (limited to 'src/cuchaz/enigma/convert/ClassIdentity.java')
| -rw-r--r-- | src/cuchaz/enigma/convert/ClassIdentity.java | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/cuchaz/enigma/convert/ClassIdentity.java b/src/cuchaz/enigma/convert/ClassIdentity.java index 0a3a449..980f31f 100644 --- a/src/cuchaz/enigma/convert/ClassIdentity.java +++ b/src/cuchaz/enigma/convert/ClassIdentity.java | |||
| @@ -60,6 +60,7 @@ import cuchaz.enigma.mapping.SignatureUpdater.ClassNameUpdater; | |||
| 60 | public class ClassIdentity | 60 | public class ClassIdentity |
| 61 | { | 61 | { |
| 62 | private ClassEntry m_classEntry; | 62 | private ClassEntry m_classEntry; |
| 63 | private String m_rawName; | ||
| 63 | private SidedClassNamer m_namer; | 64 | private SidedClassNamer m_namer; |
| 64 | private Set<String> m_fields; | 65 | private Set<String> m_fields; |
| 65 | private Set<String> m_methods; | 66 | private Set<String> m_methods; |
| @@ -70,13 +71,18 @@ public class ClassIdentity | |||
| 70 | private Set<String> m_implementations; | 71 | private Set<String> m_implementations; |
| 71 | private Set<String> m_references; | 72 | private Set<String> m_references; |
| 72 | 73 | ||
| 73 | public ClassIdentity( CtClass c, SidedClassNamer namer, JarIndex index, boolean useReferences ) | 74 | public ClassIdentity( CtClass c, SidedClassNamer namer, JarIndex index, boolean useReferences, boolean useRawNames ) |
| 74 | { | 75 | { |
| 75 | m_namer = namer; | 76 | m_namer = namer; |
| 76 | 77 | ||
| 77 | // stuff from the bytecode | 78 | // stuff from the bytecode |
| 78 | 79 | ||
| 79 | m_classEntry = new ClassEntry( Descriptor.toJvmName( c.getName() ) ); | 80 | m_classEntry = new ClassEntry( Descriptor.toJvmName( c.getName() ) ); |
| 81 | m_rawName = ""; | ||
| 82 | if( useRawNames ) | ||
| 83 | { | ||
| 84 | m_rawName = m_classEntry.getName(); | ||
| 85 | } | ||
| 80 | m_fields = Sets.newHashSet(); | 86 | m_fields = Sets.newHashSet(); |
| 81 | for( CtField field : c.getDeclaredFields() ) | 87 | for( CtField field : c.getDeclaredFields() ) |
| 82 | { | 88 | { |
| @@ -176,8 +182,16 @@ public class ClassIdentity | |||
| 176 | { | 182 | { |
| 177 | StringBuilder buf = new StringBuilder(); | 183 | StringBuilder buf = new StringBuilder(); |
| 178 | buf.append( "class: " ); | 184 | buf.append( "class: " ); |
| 185 | buf.append( m_classEntry.getName() ); | ||
| 186 | buf.append( " " ); | ||
| 179 | buf.append( hashCode() ); | 187 | buf.append( hashCode() ); |
| 180 | buf.append( "\n" ); | 188 | buf.append( "\n" ); |
| 189 | if( m_rawName.length() > 0 ) | ||
| 190 | { | ||
| 191 | buf.append( "\traw name: " ); | ||
| 192 | buf.append( m_rawName ); | ||
| 193 | buf.append( "\n" ); | ||
| 194 | } | ||
| 181 | for( String field : m_fields ) | 195 | for( String field : m_fields ) |
| 182 | { | 196 | { |
| 183 | buf.append( "\tfield " ); | 197 | buf.append( "\tfield " ); |
| @@ -425,7 +439,8 @@ public class ClassIdentity | |||
| 425 | 439 | ||
| 426 | public boolean equals( ClassIdentity other ) | 440 | public boolean equals( ClassIdentity other ) |
| 427 | { | 441 | { |
| 428 | return m_fields.equals( other.m_fields ) | 442 | return m_rawName.equals( other.m_rawName ) |
| 443 | && m_fields.equals( other.m_fields ) | ||
| 429 | && m_methods.equals( other.m_methods ) | 444 | && m_methods.equals( other.m_methods ) |
| 430 | && m_constructors.equals( other.m_constructors ) | 445 | && m_constructors.equals( other.m_constructors ) |
| 431 | && m_staticInitializer.equals( other.m_staticInitializer ) | 446 | && m_staticInitializer.equals( other.m_staticInitializer ) |
| @@ -439,6 +454,7 @@ public class ClassIdentity | |||
| 439 | public int hashCode( ) | 454 | public int hashCode( ) |
| 440 | { | 455 | { |
| 441 | List<Object> objs = Lists.newArrayList(); | 456 | List<Object> objs = Lists.newArrayList(); |
| 457 | objs.add( m_rawName ); | ||
| 442 | objs.addAll( m_fields ); | 458 | objs.addAll( m_fields ); |
| 443 | objs.addAll( m_methods ); | 459 | objs.addAll( m_methods ); |
| 444 | objs.addAll( m_constructors ); | 460 | objs.addAll( m_constructors ); |
| @@ -449,4 +465,24 @@ public class ClassIdentity | |||
| 449 | objs.addAll( m_references ); | 465 | objs.addAll( m_references ); |
| 450 | return Util.combineHashesOrdered( objs ); | 466 | return Util.combineHashesOrdered( objs ); |
| 451 | } | 467 | } |
| 468 | |||
| 469 | public int getMatchScore( ClassIdentity other ) | ||
| 470 | { | ||
| 471 | return getNumMatches( m_fields, other.m_fields ) | ||
| 472 | + getNumMatches( m_methods, other.m_methods ) | ||
| 473 | + getNumMatches( m_constructors, other.m_constructors ); | ||
| 474 | } | ||
| 475 | |||
| 476 | private int getNumMatches( Set<String> a, Set<String> b ) | ||
| 477 | { | ||
| 478 | int numMatches = 0; | ||
| 479 | for( String val : a ) | ||
| 480 | { | ||
| 481 | if( b.contains( val ) ) | ||
| 482 | { | ||
| 483 | numMatches++; | ||
| 484 | } | ||
| 485 | } | ||
| 486 | return numMatches; | ||
| 487 | } | ||
| 452 | } | 488 | } |