summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/analysis
diff options
context:
space:
mode:
authorGravatar jeff2014-08-23 23:43:31 -0400
committerGravatar jeff2014-08-23 23:43:31 -0400
commit8fa1741b621644ef84a9395a4c395d4ff3a89207 (patch)
tree9cc054e2636dd13a32950ad68dba212275d33026 /src/cuchaz/enigma/analysis
parentadded export command with progress bar (diff)
downloadenigma-fork-8fa1741b621644ef84a9395a4c395d4ff3a89207.tar.gz
enigma-fork-8fa1741b621644ef84a9395a4c395d4ff3a89207.tar.xz
enigma-fork-8fa1741b621644ef84a9395a4c395d4ff3a89207.zip
moved all classes from the default package into a package called "default" so they can be properly imported by other classes
Diffstat (limited to 'src/cuchaz/enigma/analysis')
-rw-r--r--src/cuchaz/enigma/analysis/JarClassIterator.java45
-rw-r--r--src/cuchaz/enigma/analysis/JarIndex.java40
2 files changed, 55 insertions, 30 deletions
diff --git a/src/cuchaz/enigma/analysis/JarClassIterator.java b/src/cuchaz/enigma/analysis/JarClassIterator.java
index cf6df80..6c9f124 100644
--- a/src/cuchaz/enigma/analysis/JarClassIterator.java
+++ b/src/cuchaz/enigma/analysis/JarClassIterator.java
@@ -28,6 +28,7 @@ import javassist.bytecode.Descriptor;
28import com.beust.jcommander.internal.Lists; 28import com.beust.jcommander.internal.Lists;
29 29
30import cuchaz.enigma.Constants; 30import cuchaz.enigma.Constants;
31import cuchaz.enigma.mapping.ClassEntry;
31 32
32public class JarClassIterator implements Iterator<CtClass> 33public class JarClassIterator implements Iterator<CtClass>
33{ 34{
@@ -36,13 +37,22 @@ public class JarClassIterator implements Iterator<CtClass>
36 37
37 public JarClassIterator( JarFile jar ) 38 public JarClassIterator( JarFile jar )
38 { 39 {
39 this( jar, getClassEntries( jar ) );
40 }
41
42 public JarClassIterator( JarFile jar, List<JarEntry> entries )
43 {
44 m_jar = jar; 40 m_jar = jar;
45 m_iter = entries.iterator(); 41
42 // get the jar entries that correspond to classes
43 List<JarEntry> classEntries = Lists.newArrayList();
44 Enumeration<JarEntry> entries = m_jar.entries();
45 while( entries.hasMoreElements() )
46 {
47 JarEntry entry = entries.nextElement();
48
49 // is this a class file?
50 if( entry.getName().endsWith( ".class" ) )
51 {
52 classEntries.add( entry );
53 }
54 }
55 m_iter = classEntries.iterator();
46 } 56 }
47 57
48 @Override 58 @Override
@@ -79,19 +89,13 @@ public class JarClassIterator implements Iterator<CtClass>
79 } 89 }
80 } 90 }
81 91
82 // determine the class name (ie chop off the ".class")
83 String className = Descriptor.toJavaName( entry.getName().substring( 0, entry.getName().length() - ".class".length() ) );
84
85 // get a javassist handle for the class 92 // get a javassist handle for the class
93 String className = Descriptor.toJavaName( getClassEntry( entry ).getName() );
86 ClassPool classPool = new ClassPool(); 94 ClassPool classPool = new ClassPool();
87 classPool.insertClassPath( new ByteArrayClassPath( className, bos.toByteArray() ) ); 95 classPool.insertClassPath( new ByteArrayClassPath( className, bos.toByteArray() ) );
88 return classPool.get( className ); 96 return classPool.get( className );
89 } 97 }
90 catch( IOException ex ) 98 catch( IOException | NotFoundException ex )
91 {
92 throw new Error( "Unable to read class: " + entry.getName() );
93 }
94 catch( NotFoundException ex )
95 { 99 {
96 throw new Error( "Unable to load class: " + entry.getName() ); 100 throw new Error( "Unable to load class: " + entry.getName() );
97 } 101 }
@@ -103,9 +107,9 @@ public class JarClassIterator implements Iterator<CtClass>
103 throw new UnsupportedOperationException(); 107 throw new UnsupportedOperationException();
104 } 108 }
105 109
106 public static List<JarEntry> getClassEntries( JarFile jar ) 110 public static List<ClassEntry> getClassEntries( JarFile jar )
107 { 111 {
108 List<JarEntry> classes = Lists.newArrayList(); 112 List<ClassEntry> classEntries = Lists.newArrayList();
109 Enumeration<JarEntry> entries = jar.entries(); 113 Enumeration<JarEntry> entries = jar.entries();
110 while( entries.hasMoreElements() ) 114 while( entries.hasMoreElements() )
111 { 115 {
@@ -114,10 +118,10 @@ public class JarClassIterator implements Iterator<CtClass>
114 // is this a class file? 118 // is this a class file?
115 if( !entry.isDirectory() && entry.getName().endsWith( ".class" ) ) 119 if( !entry.isDirectory() && entry.getName().endsWith( ".class" ) )
116 { 120 {
117 classes.add( entry ); 121 classEntries.add( getClassEntry( entry ) );
118 } 122 }
119 } 123 }
120 return classes; 124 return classEntries;
121 } 125 }
122 126
123 public static Iterable<CtClass> classes( final JarFile jar ) 127 public static Iterable<CtClass> classes( final JarFile jar )
@@ -131,4 +135,9 @@ public class JarClassIterator implements Iterator<CtClass>
131 } 135 }
132 }; 136 };
133 } 137 }
138
139 private static ClassEntry getClassEntry( JarEntry entry )
140 {
141 return new ClassEntry( entry.getName().substring( 0, entry.getName().length() - ".class".length() ) );
142 }
134} 143}
diff --git a/src/cuchaz/enigma/analysis/JarIndex.java b/src/cuchaz/enigma/analysis/JarIndex.java
index 315a286..cdaca37 100644
--- a/src/cuchaz/enigma/analysis/JarIndex.java
+++ b/src/cuchaz/enigma/analysis/JarIndex.java
@@ -17,7 +17,6 @@ import java.util.Iterator;
17import java.util.List; 17import java.util.List;
18import java.util.Map; 18import java.util.Map;
19import java.util.Set; 19import java.util.Set;
20import java.util.jar.JarEntry;
21import java.util.jar.JarFile; 20import java.util.jar.JarFile;
22 21
23import javassist.CannotCompileException; 22import javassist.CannotCompileException;
@@ -35,13 +34,12 @@ import javassist.expr.MethodCall;
35import javassist.expr.NewExpr; 34import javassist.expr.NewExpr;
36 35
37import com.google.common.collect.HashMultimap; 36import com.google.common.collect.HashMultimap;
38import com.google.common.collect.HashMultiset;
39import com.google.common.collect.Lists; 37import com.google.common.collect.Lists;
40import com.google.common.collect.Maps; 38import com.google.common.collect.Maps;
41import com.google.common.collect.Multimap; 39import com.google.common.collect.Multimap;
42import com.google.common.collect.Multiset;
43import com.google.common.collect.Sets; 40import com.google.common.collect.Sets;
44 41
42import cuchaz.enigma.bytecode.ClassRenamer;
45import cuchaz.enigma.mapping.ArgumentEntry; 43import cuchaz.enigma.mapping.ArgumentEntry;
46import cuchaz.enigma.mapping.BehaviorEntry; 44import cuchaz.enigma.mapping.BehaviorEntry;
47import cuchaz.enigma.mapping.ClassEntry; 45import cuchaz.enigma.mapping.ClassEntry;
@@ -53,7 +51,7 @@ import cuchaz.enigma.mapping.Translator;
53 51
54public class JarIndex 52public class JarIndex
55{ 53{
56 private Set<String> m_obfClassNames; 54 private Set<ClassEntry> m_obfClassEntries;
57 private Ancestries m_ancestries; 55 private Ancestries m_ancestries;
58 private Multimap<String,MethodEntry> m_methodImplementations; 56 private Multimap<String,MethodEntry> m_methodImplementations;
59 private Multimap<BehaviorEntry,EntryReference<BehaviorEntry,BehaviorEntry>> m_behaviorReferences; 57 private Multimap<BehaviorEntry,EntryReference<BehaviorEntry,BehaviorEntry>> m_behaviorReferences;
@@ -64,7 +62,7 @@ public class JarIndex
64 62
65 public JarIndex( ) 63 public JarIndex( )
66 { 64 {
67 m_obfClassNames = Sets.newHashSet(); 65 m_obfClassEntries = Sets.newHashSet();
68 m_ancestries = new Ancestries(); 66 m_ancestries = new Ancestries();
69 m_methodImplementations = HashMultimap.create(); 67 m_methodImplementations = HashMultimap.create();
70 m_behaviorReferences = HashMultimap.create(); 68 m_behaviorReferences = HashMultimap.create();
@@ -77,15 +75,20 @@ public class JarIndex
77 public void indexJar( JarFile jar ) 75 public void indexJar( JarFile jar )
78 { 76 {
79 // pass 1: read the class names 77 // pass 1: read the class names
80 for( JarEntry entry : JarClassIterator.getClassEntries( jar ) ) 78 for( ClassEntry classEntry : JarClassIterator.getClassEntries( jar ) )
81 { 79 {
82 String className = entry.getName().substring( 0, entry.getName().length() - 6 ); 80 if( classEntry.isInDefaultPackage() )
83 m_obfClassNames.add( Descriptor.toJvmName( className ) ); 81 {
82 // move out of default package
83 classEntry = new ClassEntry( "default/" + classEntry.getName() );
84 }
85 m_obfClassEntries.add( classEntry );
84 } 86 }
85 87
86 // pass 2: index the types, methods 88 // pass 2: index the types, methods
87 for( CtClass c : JarClassIterator.classes( jar ) ) 89 for( CtClass c : JarClassIterator.classes( jar ) )
88 { 90 {
91 fixClass( c );
89 m_ancestries.addSuperclass( c.getName(), c.getClassFile().getSuperclass() ); 92 m_ancestries.addSuperclass( c.getName(), c.getClassFile().getSuperclass() );
90 for( CtBehavior behavior : c.getDeclaredBehaviors() ) 93 for( CtBehavior behavior : c.getDeclaredBehaviors() )
91 { 94 {
@@ -96,8 +99,10 @@ public class JarIndex
96 // pass 2: index inner classes and anonymous classes 99 // pass 2: index inner classes and anonymous classes
97 for( CtClass c : JarClassIterator.classes( jar ) ) 100 for( CtClass c : JarClassIterator.classes( jar ) )
98 { 101 {
102 fixClass( c );
103
99 String outerClassName = findOuterClass( c ); 104 String outerClassName = findOuterClass( c );
100 if( outerClassName != null )// /* TEMP */ && false ) 105 if( outerClassName != null )
101 { 106 {
102 String innerClassName = Descriptor.toJvmName( c.getName() ); 107 String innerClassName = Descriptor.toJvmName( c.getName() );
103 m_innerClasses.put( outerClassName, innerClassName ); 108 m_innerClasses.put( outerClassName, innerClassName );
@@ -127,6 +132,17 @@ public class JarIndex
127 renameClasses( renames ); 132 renameClasses( renames );
128 } 133 }
129 134
135 private void fixClass( CtClass c )
136 {
137 ClassEntry classEntry = new ClassEntry( Descriptor.toJvmName( c.getName() ) );
138 if( classEntry.isInDefaultPackage() )
139 {
140 // move class out of default package
141 classEntry = new ClassEntry( "default/" + classEntry.getName() );
142 ClassRenamer.moveAllClassesOutOfDefaultPackage( c, "default" );
143 }
144 }
145
130 private void indexBehavior( CtBehavior behavior ) 146 private void indexBehavior( CtBehavior behavior )
131 { 147 {
132 // get the method entry 148 // get the method entry
@@ -270,7 +286,7 @@ public class JarIndex
270 else if( callerClasses.size() > 1 ) 286 else if( callerClasses.size() > 1 )
271 { 287 {
272 // TEMP 288 // TEMP
273 System.out.println( "WARNING: Illegal class called by more than one class!" + callerClasses ); 289 System.out.println( "WARNING: Illegal constructor called by more than one class!" + callerClasses );
274 } 290 }
275 } 291 }
276 292
@@ -423,9 +439,9 @@ public class JarIndex
423 return true; 439 return true;
424 } 440 }
425 441
426 public Set<String> getObfClassNames( ) 442 public Set<ClassEntry> getObfClassEntries( )
427 { 443 {
428 return m_obfClassNames; 444 return m_obfClassEntries;
429 } 445 }
430 446
431 public Ancestries getAncestries( ) 447 public Ancestries getAncestries( )