summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/convert/ClassMapper.java
blob: a0d5a3f13d4500017d493c4f77b6d508506327a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*******************************************************************************
 * Copyright (c) 2014 Jeff Martin.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     Jeff Martin - initial API and implementation
 ******************************************************************************/
package cuchaz.enigma.convert;

import java.io.File;
import java.io.IOException;
import java.util.jar.JarFile;

import javassist.CtClass;

import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;

import cuchaz.enigma.analysis.JarClassIterator;

public class ClassMapper
{
	public static void main( String[] args )
	throws IOException
	{
		// TEMP
		JarFile fromJar = new JarFile( new File( "input/1.8-pre1.jar" ) );
		JarFile toJar = new JarFile( new File( "input/1.8-pre2.jar" ) );
		
		new ClassMapper( fromJar, toJar );
	}
	
	public ClassMapper( JarFile a, JarFile b )
	{
		int numAClasses = JarClassIterator.getClassEntries( a ).size();
		int numBClasses = JarClassIterator.getClassEntries( b ).size();
		
		// TEMP
		System.out.println( "A classes: " + numAClasses );
		System.out.println( "B classes: " + numBClasses );
		
		// compute the a classes
		Multiset<ClassIdentity> aclasses = HashMultiset.create();
		for( CtClass c : JarClassIterator.classes( a ) )
		{
			ClassIdentity aclass = new ClassIdentity( c );
			aclasses.add( aclass );
		}
		
		int numMatches = 0;
		
		// match the b classes to the a classes
		for( CtClass c : JarClassIterator.classes( b ) )
		{
			ClassIdentity bclass = new ClassIdentity( c );
			if( aclasses.contains( bclass ) )
			{
				numMatches++;
			}
			
			// TEMP
			//System.out.println( bclass );
		}
		
		// TEMP
		System.out.println( String.format( "Class matches: %d/%d (missing %d)",
			numMatches, aclasses.size(), aclasses.size() - numMatches
		) );
	}
}