summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/mapping/MappingsReader.java
diff options
context:
space:
mode:
authorGravatar hg2014-08-17 10:56:17 -0400
committerGravatar hg2014-08-17 10:56:17 -0400
commit6c4440ac1133bfaa7871d1049d174528a289ef30 (patch)
treefe1142b285c5e43dbd3afe8dd3eb0189f027c6a6 /src/cuchaz/enigma/mapping/MappingsReader.java
parenttrying to get inner/anonymous classes working... I have a working heuristic i... (diff)
downloadenigma-fork-6c4440ac1133bfaa7871d1049d174528a289ef30.tar.gz
enigma-fork-6c4440ac1133bfaa7871d1049d174528a289ef30.tar.xz
enigma-fork-6c4440ac1133bfaa7871d1049d174528a289ef30.zip
added support for automatic reconstruction of inner and anonymous classes
also added class to restore bridge method flags taken out by the obfuscator
Diffstat (limited to 'src/cuchaz/enigma/mapping/MappingsReader.java')
-rw-r--r--src/cuchaz/enigma/mapping/MappingsReader.java76
1 files changed, 56 insertions, 20 deletions
diff --git a/src/cuchaz/enigma/mapping/MappingsReader.java b/src/cuchaz/enigma/mapping/MappingsReader.java
index b039409..4cebb3a 100644
--- a/src/cuchaz/enigma/mapping/MappingsReader.java
+++ b/src/cuchaz/enigma/mapping/MappingsReader.java
@@ -13,25 +13,27 @@ package cuchaz.enigma.mapping;
13import java.io.BufferedReader; 13import java.io.BufferedReader;
14import java.io.IOException; 14import java.io.IOException;
15import java.io.Reader; 15import java.io.Reader;
16import java.util.Deque;
16import java.util.NoSuchElementException; 17import java.util.NoSuchElementException;
17import java.util.Scanner; 18import java.util.Scanner;
18 19
20import com.google.common.collect.Queues;
21
19import cuchaz.enigma.Util; 22import cuchaz.enigma.Util;
20 23
21public class MappingsReader 24public class MappingsReader
22{ 25{
23 public Mappings read( Reader in ) 26 public Mappings read( Reader in )
24 throws IOException 27 throws IOException, MappingParseException
25 { 28 {
26 return read( new BufferedReader( in ) ); 29 return read( new BufferedReader( in ) );
27 } 30 }
28 31
29 public Mappings read( BufferedReader in ) 32 public Mappings read( BufferedReader in )
30 throws IOException 33 throws IOException, MappingParseException
31 { 34 {
32 Mappings mappings = new Mappings(); 35 Mappings mappings = new Mappings();
33 ClassMapping classMapping = null; 36 Deque<Object> mappingStack = Queues.newArrayDeque();
34 MethodMapping methodMapping = null;
35 37
36 int lineNumber = 0; 38 int lineNumber = 0;
37 String line = null; 39 String line = null;
@@ -47,12 +49,28 @@ public class MappingsReader
47 } 49 }
48 50
49 // skip blank lines 51 // skip blank lines
50 line = line.trim(); 52 if( line.trim().length() <= 0 )
51 if( line.length() <= 0 )
52 { 53 {
53 continue; 54 continue;
54 } 55 }
55 56
57 // get the indent of this line
58 int indent = 0;
59 for( int i=0; i<line.length(); i++ )
60 {
61 if( line.charAt( i ) != '\t' )
62 {
63 break;
64 }
65 indent++;
66 }
67
68 // handle stack pops
69 while( indent < mappingStack.size() )
70 {
71 mappingStack.pop();
72 }
73
56 Scanner scanner = new Scanner( line ); 74 Scanner scanner = new Scanner( line );
57 try 75 try
58 { 76 {
@@ -63,40 +81,58 @@ public class MappingsReader
63 81
64 if( token.equalsIgnoreCase( "CLASS" ) ) 82 if( token.equalsIgnoreCase( "CLASS" ) )
65 { 83 {
66 classMapping = readClass( scanner ); 84 ClassMapping classMapping = readClass( scanner );
67 mappings.addClassMapping( classMapping ); 85 if( indent == 0 )
68 methodMapping = null; 86 {
87 // outer class
88 mappings.addClassMapping( classMapping );
89 }
90 else if( indent == 1 )
91 {
92 // inner class
93 if( !( mappingStack.getFirst() instanceof ClassMapping ) )
94 {
95 throw new MappingParseException( lineNumber, "Unexpected CLASS entry here!" );
96 }
97 ((ClassMapping)mappingStack.getFirst()).addInnerClassMapping( classMapping );
98 }
99 else
100 {
101 throw new MappingParseException( lineNumber, "Unexpected CLASS entry here!" );
102 }
103 mappingStack.push( classMapping );
69 } 104 }
70 else if( token.equalsIgnoreCase( "FIELD" ) ) 105 else if( token.equalsIgnoreCase( "FIELD" ) )
71 { 106 {
72 if( classMapping == null ) 107 if( mappingStack.isEmpty() || !(mappingStack.getFirst() instanceof ClassMapping) )
73 { 108 {
74 throw new IllegalArgumentException( "Line " + lineNumber + ": Unexpected FIELD entry here!" ); 109 throw new MappingParseException( lineNumber, "Unexpected FIELD entry here!" );
75 } 110 }
76 classMapping.addFieldMapping( readField( scanner ) ); 111 ((ClassMapping)mappingStack.getFirst()).addFieldMapping( readField( scanner ) );
77 } 112 }
78 else if( token.equalsIgnoreCase( "METHOD" ) ) 113 else if( token.equalsIgnoreCase( "METHOD" ) )
79 { 114 {
80 if( classMapping == null ) 115 if( mappingStack.isEmpty() || !(mappingStack.getFirst() instanceof ClassMapping) )
81 { 116 {
82 throw new IllegalArgumentException( "Line " + lineNumber + ": Unexpected METHOD entry here!" ); 117 throw new MappingParseException( lineNumber, "Unexpected METHOD entry here!" );
83 } 118 }
84 methodMapping = readMethod( scanner ); 119 MethodMapping methodMapping = readMethod( scanner );
85 classMapping.addMethodMapping( methodMapping ); 120 ((ClassMapping)mappingStack.getFirst()).addMethodMapping( methodMapping );
121 mappingStack.push( methodMapping );
86 } 122 }
87 else if( token.equalsIgnoreCase( "ARG" ) ) 123 else if( token.equalsIgnoreCase( "ARG" ) )
88 { 124 {
89 if( classMapping == null || methodMapping == null ) 125 if( mappingStack.isEmpty() || !(mappingStack.getFirst() instanceof MethodMapping) )
90 { 126 {
91 throw new IllegalArgumentException( "Line " + lineNumber + ": Unexpected ARG entry here!" ); 127 throw new MappingParseException( lineNumber, "Unexpected ARG entry here!" );
92 } 128 }
93 methodMapping.addArgumentMapping( readArgument( scanner ) ); 129 ((MethodMapping)mappingStack.getFirst()).addArgumentMapping( readArgument( scanner ) );
94 } 130 }
95 } 131 }
96 } 132 }
97 catch( NoSuchElementException ex ) 133 catch( NoSuchElementException ex )
98 { 134 {
99 throw new IllegalArgumentException( "Line " + lineNumber + ": malformed line!" ); 135 throw new MappingParseException( lineNumber, "Malformed line!" );
100 } 136 }
101 finally 137 finally
102 { 138 {