diff options
| author | 2014-08-07 00:55:43 -0400 | |
|---|---|---|
| committer | 2014-08-07 00:55:43 -0400 | |
| commit | 6aa7c6121a2ecbe78f14f8c3d7ddb55b8ddb10bd (patch) | |
| tree | 0b97553e42e2e3a52a1aab30914d885d143d5bf0 /src/cuchaz/enigma/analysis/Analyzer.java | |
| parent | added un-obfuscated classes to the deobfuscated classes list (diff) | |
| download | enigma-fork-6aa7c6121a2ecbe78f14f8c3d7ddb55b8ddb10bd.tar.gz enigma-fork-6aa7c6121a2ecbe78f14f8c3d7ddb55b8ddb10bd.tar.xz enigma-fork-6aa7c6121a2ecbe78f14f8c3d7ddb55b8ddb10bd.zip | |
started working on recognition of non-class member identifiers in the source
got class extends,implements working
and argument,field types
added filtering to make sure highlighted class names are actually classes in the jar
Diffstat (limited to 'src/cuchaz/enigma/analysis/Analyzer.java')
| -rw-r--r-- | src/cuchaz/enigma/analysis/Analyzer.java | 91 |
1 files changed, 52 insertions, 39 deletions
diff --git a/src/cuchaz/enigma/analysis/Analyzer.java b/src/cuchaz/enigma/analysis/Analyzer.java index dad8dc5..2b7e0b0 100644 --- a/src/cuchaz/enigma/analysis/Analyzer.java +++ b/src/cuchaz/enigma/analysis/Analyzer.java | |||
| @@ -35,6 +35,7 @@ import com.sun.source.util.Trees; | |||
| 35 | 35 | ||
| 36 | import cuchaz.enigma.mapping.ArgumentEntry; | 36 | import cuchaz.enigma.mapping.ArgumentEntry; |
| 37 | import cuchaz.enigma.mapping.ClassEntry; | 37 | import cuchaz.enigma.mapping.ClassEntry; |
| 38 | import cuchaz.enigma.mapping.Entry; | ||
| 38 | import cuchaz.enigma.mapping.FieldEntry; | 39 | import cuchaz.enigma.mapping.FieldEntry; |
| 39 | import cuchaz.enigma.mapping.MethodEntry; | 40 | import cuchaz.enigma.mapping.MethodEntry; |
| 40 | 41 | ||
| @@ -78,39 +79,31 @@ class TreeVisitor extends TreeScanner<CompilationUnitTree, SourcedAst> | |||
| 78 | 79 | ||
| 79 | private ClassEntry indexClass( ClassTree classTree, SourcedAst ast ) | 80 | private ClassEntry indexClass( ClassTree classTree, SourcedAst ast ) |
| 80 | { | 81 | { |
| 81 | // build the entry | 82 | // index the class name |
| 82 | ClassEntry entry = new ClassEntry( ast.getFullClassName( classTree.getSimpleName().toString() ) ); | 83 | ClassEntry classEntry = indexClassIdentifier( classTree, ast ); |
| 84 | assert( classEntry != null ); | ||
| 83 | 85 | ||
| 84 | // lex the source at this tree node | 86 | // index the extends clause |
| 85 | for( Token token : new Lexer( ast.getSource( classTree ).toString() ) ) | 87 | indexClassIdentifier( classTree.getExtendsClause(), ast ); |
| 88 | |||
| 89 | // index the implements clauses | ||
| 90 | for( Tree implementsTree : classTree.getImplementsClause() ) | ||
| 86 | { | 91 | { |
| 87 | // scan until we get the first identifier | 92 | indexClassIdentifier( implementsTree, ast ); |
| 88 | if( token.type == TokenType.IDENTIFIER ) | ||
| 89 | { | ||
| 90 | m_index.add( entry, offsetToken( token, ast.getStart( classTree ) ) ); | ||
| 91 | break; | ||
| 92 | } | ||
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | return entry; | 95 | return classEntry; |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | private FieldEntry indexField( VariableTree variableTree, SourcedAst ast, ClassEntry classEntry ) | 98 | private FieldEntry indexField( VariableTree variableTree, SourcedAst ast, ClassEntry classEntry ) |
| 99 | { | 99 | { |
| 100 | // build the entry | 100 | // index the field name |
| 101 | FieldEntry entry = new FieldEntry( classEntry, variableTree.getName().toString() ); | 101 | FieldEntry entry = new FieldEntry( classEntry, variableTree.getName().toString() ); |
| 102 | Token nameToken = new Lexer( ast.getSource( variableTree ) ).getFirstIdentifierMatching( variableTree.getName() ); | ||
| 103 | addToken( entry, nameToken, variableTree, ast ); | ||
| 102 | 104 | ||
| 103 | // lex the source at this tree node | 105 | // index the field type |
| 104 | Lexer lexer = new Lexer( ast.getSource( variableTree ).toString() ); | 106 | indexClassIdentifier( variableTree.getType(), ast ); |
| 105 | for( Token token : lexer ) | ||
| 106 | { | ||
| 107 | // scan until we find an identifier that matches the field name | ||
| 108 | if( token.type == TokenType.IDENTIFIER && lexer.getText( token ).equals( entry.getName() ) ) | ||
| 109 | { | ||
| 110 | m_index.add( entry, offsetToken( token, ast.getStart( variableTree ) ) ); | ||
| 111 | break; | ||
| 112 | } | ||
| 113 | } | ||
| 114 | 107 | ||
| 115 | return entry; | 108 | return entry; |
| 116 | } | 109 | } |
| @@ -136,13 +129,13 @@ class TreeVisitor extends TreeScanner<CompilationUnitTree, SourcedAst> | |||
| 136 | MethodEntry entry = new MethodEntry( classEntry, methodTree.getName().toString(), signature.toString() ); | 129 | MethodEntry entry = new MethodEntry( classEntry, methodTree.getName().toString(), signature.toString() ); |
| 137 | 130 | ||
| 138 | // lex the source at this tree node | 131 | // lex the source at this tree node |
| 139 | Lexer lexer = new Lexer( ast.getSource( methodTree ).toString() ); | 132 | Lexer lexer = new Lexer( ast.getSource( methodTree ) ); |
| 140 | for( Token token : lexer ) | 133 | for( Token token : lexer ) |
| 141 | { | 134 | { |
| 142 | // scan until we find an identifier that matches the method name | 135 | // scan until we find an identifier that matches the method name |
| 143 | if( token.type == TokenType.IDENTIFIER && lexer.getText( token ).equals( entry.getName() ) ) | 136 | if( token.type == TokenType.IDENTIFIER && lexer.getText( token ).equals( entry.getName() ) ) |
| 144 | { | 137 | { |
| 145 | m_index.add( entry, offsetToken( token, ast.getStart( methodTree ) ) ); | 138 | addToken( entry, token, methodTree, ast ); |
| 146 | break; | 139 | break; |
| 147 | } | 140 | } |
| 148 | } | 141 | } |
| @@ -152,27 +145,47 @@ class TreeVisitor extends TreeScanner<CompilationUnitTree, SourcedAst> | |||
| 152 | 145 | ||
| 153 | private void indexArgument( VariableTree variableTree, SourcedAst ast, MethodEntry methodEntry, int index ) | 146 | private void indexArgument( VariableTree variableTree, SourcedAst ast, MethodEntry methodEntry, int index ) |
| 154 | { | 147 | { |
| 155 | // build the entry | 148 | // index argument name |
| 156 | ArgumentEntry entry = new ArgumentEntry( methodEntry, index, variableTree.getName().toString() ); | 149 | ArgumentEntry entry = new ArgumentEntry( methodEntry, index, variableTree.getName().toString() ); |
| 150 | Token token = new Lexer( ast.getSource( variableTree ) ).getLastIdentifier(); | ||
| 151 | addToken( entry, token, variableTree, ast ); | ||
| 157 | 152 | ||
| 158 | // lex the source at this tree node | 153 | // index argument type |
| 159 | Lexer lexer = new Lexer( ast.getSource( variableTree ).toString() ); | 154 | indexClassIdentifier( variableTree.getType(), ast ); |
| 160 | for( Token token : lexer ) | 155 | } |
| 156 | |||
| 157 | private ClassEntry indexClassIdentifier( Tree tree, SourcedAst ast ) | ||
| 158 | { | ||
| 159 | if( tree == null ) | ||
| 161 | { | 160 | { |
| 162 | // scan until we find an identifier that matches the variable name | 161 | return null; |
| 163 | if( token.type == TokenType.IDENTIFIER && lexer.getText( token ).equals( entry.getName() ) ) | 162 | } |
| 164 | { | 163 | |
| 165 | m_index.add( entry, offsetToken( token, ast.getStart( variableTree ) ) ); | 164 | Lexer lexer = new Lexer( ast.getSource( tree ) ); |
| 166 | break; | 165 | Token token = lexer.getFirstIdentifier(); |
| 167 | } | 166 | if( token == null ) |
| 167 | { | ||
| 168 | return null; | ||
| 168 | } | 169 | } |
| 170 | |||
| 171 | ClassEntry classEntry = new ClassEntry( ast.getFullClassName( lexer.getText( token ) ) ); | ||
| 172 | addToken( classEntry, token, tree, ast ); | ||
| 173 | return classEntry; | ||
| 169 | } | 174 | } |
| 170 | 175 | ||
| 171 | private Token offsetToken( Token in, int offset ) | 176 | private void addToken( Entry entry, Token token, Tree tree, SourcedAst ast ) |
| 172 | { | 177 | { |
| 173 | return new Token( in.type, in.start + offset, in.length ); | 178 | if( token == null ) |
| 179 | { | ||
| 180 | throw new IllegalArgumentException( "token cannot be null!" ); | ||
| 181 | } | ||
| 182 | |||
| 183 | // offset the token by the tree | ||
| 184 | Token offsetToken = new Token( token.type, token.start + ast.getStart( tree ), token.length ); | ||
| 185 | |||
| 186 | m_index.add( entry, offsetToken ); | ||
| 174 | } | 187 | } |
| 175 | 188 | ||
| 176 | private String toJvmType( Tree tree, SourcedAst ast ) | 189 | private String toJvmType( Tree tree, SourcedAst ast ) |
| 177 | { | 190 | { |
| 178 | switch( tree.getKind() ) | 191 | switch( tree.getKind() ) |