diff options
Diffstat (limited to 'src/cuchaz/enigma/convert/ClassMapper.java')
| -rw-r--r-- | src/cuchaz/enigma/convert/ClassMapper.java | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/convert/ClassMapper.java b/src/cuchaz/enigma/convert/ClassMapper.java new file mode 100644 index 0000000..a0d5a3f --- /dev/null +++ b/src/cuchaz/enigma/convert/ClassMapper.java | |||
| @@ -0,0 +1,73 @@ | |||
| 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 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.convert; | ||
| 12 | |||
| 13 | import java.io.File; | ||
| 14 | import java.io.IOException; | ||
| 15 | import java.util.jar.JarFile; | ||
| 16 | |||
| 17 | import javassist.CtClass; | ||
| 18 | |||
| 19 | import com.google.common.collect.HashMultiset; | ||
| 20 | import com.google.common.collect.Multiset; | ||
| 21 | |||
| 22 | import cuchaz.enigma.analysis.JarClassIterator; | ||
| 23 | |||
| 24 | public class ClassMapper | ||
| 25 | { | ||
| 26 | public static void main( String[] args ) | ||
| 27 | throws IOException | ||
| 28 | { | ||
| 29 | // TEMP | ||
| 30 | JarFile fromJar = new JarFile( new File( "input/1.8-pre1.jar" ) ); | ||
| 31 | JarFile toJar = new JarFile( new File( "input/1.8-pre2.jar" ) ); | ||
| 32 | |||
| 33 | new ClassMapper( fromJar, toJar ); | ||
| 34 | } | ||
| 35 | |||
| 36 | public ClassMapper( JarFile a, JarFile b ) | ||
| 37 | { | ||
| 38 | int numAClasses = JarClassIterator.getClassEntries( a ).size(); | ||
| 39 | int numBClasses = JarClassIterator.getClassEntries( b ).size(); | ||
| 40 | |||
| 41 | // TEMP | ||
| 42 | System.out.println( "A classes: " + numAClasses ); | ||
| 43 | System.out.println( "B classes: " + numBClasses ); | ||
| 44 | |||
| 45 | // compute the a classes | ||
| 46 | Multiset<ClassIdentity> aclasses = HashMultiset.create(); | ||
| 47 | for( CtClass c : JarClassIterator.classes( a ) ) | ||
| 48 | { | ||
| 49 | ClassIdentity aclass = new ClassIdentity( c ); | ||
| 50 | aclasses.add( aclass ); | ||
| 51 | } | ||
| 52 | |||
| 53 | int numMatches = 0; | ||
| 54 | |||
| 55 | // match the b classes to the a classes | ||
| 56 | for( CtClass c : JarClassIterator.classes( b ) ) | ||
| 57 | { | ||
| 58 | ClassIdentity bclass = new ClassIdentity( c ); | ||
| 59 | if( aclasses.contains( bclass ) ) | ||
| 60 | { | ||
| 61 | numMatches++; | ||
| 62 | } | ||
| 63 | |||
| 64 | // TEMP | ||
| 65 | //System.out.println( bclass ); | ||
| 66 | } | ||
| 67 | |||
| 68 | // TEMP | ||
| 69 | System.out.println( String.format( "Class matches: %d/%d (missing %d)", | ||
| 70 | numMatches, aclasses.size(), aclasses.size() - numMatches | ||
| 71 | ) ); | ||
| 72 | } | ||
| 73 | } | ||