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/SourcedAst.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/SourcedAst.java')
| -rw-r--r-- | src/cuchaz/enigma/analysis/SourcedAst.java | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/src/cuchaz/enigma/analysis/SourcedAst.java b/src/cuchaz/enigma/analysis/SourcedAst.java index 968c880..a88cc75 100644 --- a/src/cuchaz/enigma/analysis/SourcedAst.java +++ b/src/cuchaz/enigma/analysis/SourcedAst.java | |||
| @@ -16,7 +16,6 @@ import java.util.HashMap; | |||
| 16 | import javassist.bytecode.Descriptor; | 16 | import javassist.bytecode.Descriptor; |
| 17 | 17 | ||
| 18 | import com.google.common.collect.Maps; | 18 | import com.google.common.collect.Maps; |
| 19 | import com.sun.source.tree.ClassTree; | ||
| 20 | import com.sun.source.tree.CompilationUnitTree; | 19 | import com.sun.source.tree.CompilationUnitTree; |
| 21 | import com.sun.source.tree.ImportTree; | 20 | import com.sun.source.tree.ImportTree; |
| 22 | import com.sun.source.tree.Tree; | 21 | import com.sun.source.tree.Tree; |
| @@ -29,6 +28,7 @@ public class SourcedAst | |||
| 29 | private Trees m_trees; | 28 | private Trees m_trees; |
| 30 | private SourcePositions m_positions; | 29 | private SourcePositions m_positions; |
| 31 | private HashMap<String,String> m_classNameIndex; | 30 | private HashMap<String,String> m_classNameIndex; |
| 31 | private String m_packageName; | ||
| 32 | 32 | ||
| 33 | public SourcedAst( CompilationUnitTree tree, Trees trees ) | 33 | public SourcedAst( CompilationUnitTree tree, Trees trees ) |
| 34 | { | 34 | { |
| @@ -49,6 +49,13 @@ public class SourcedAst | |||
| 49 | // get the full and simple class names | 49 | // get the full and simple class names |
| 50 | String fullName = Descriptor.toJvmName( importTree.getQualifiedIdentifier().toString() ); | 50 | String fullName = Descriptor.toJvmName( importTree.getQualifiedIdentifier().toString() ); |
| 51 | String simpleName = fullName; | 51 | String simpleName = fullName; |
| 52 | |||
| 53 | if( fullName.startsWith( "__DEFAULT__/" ) ) | ||
| 54 | { | ||
| 55 | // remove the default package flag | ||
| 56 | fullName = fullName.substring( 12 ); | ||
| 57 | } | ||
| 58 | |||
| 52 | String[] parts = fullName.split( "/" ); | 59 | String[] parts = fullName.split( "/" ); |
| 53 | if( parts.length > 0 ) | 60 | if( parts.length > 0 ) |
| 54 | { | 61 | { |
| @@ -58,30 +65,26 @@ public class SourcedAst | |||
| 58 | m_classNameIndex.put( simpleName, fullName ); | 65 | m_classNameIndex.put( simpleName, fullName ); |
| 59 | } | 66 | } |
| 60 | 67 | ||
| 61 | // index the self class using the package name | 68 | // get the package name |
| 69 | m_packageName = null; | ||
| 62 | if( m_tree.getPackageName() != null ) | 70 | if( m_tree.getPackageName() != null ) |
| 63 | { | 71 | { |
| 64 | String packageName = Descriptor.toJvmName( m_tree.getPackageName().toString() ); | 72 | m_packageName = Descriptor.toJvmName( m_tree.getPackageName().toString() ); |
| 65 | for( Tree typeTree : m_tree.getTypeDecls() ) | ||
| 66 | { | ||
| 67 | if( typeTree instanceof ClassTree ) | ||
| 68 | { | ||
| 69 | ClassTree classTree = (ClassTree)typeTree; | ||
| 70 | String className = classTree.getSimpleName().toString(); | ||
| 71 | m_classNameIndex.put( className, packageName + "/" + className ); | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | 73 | } |
| 75 | } | 74 | } |
| 76 | 75 | ||
| 77 | public int getStart( Tree node ) | 76 | public int getStart( Tree node ) |
| 78 | { | 77 | { |
| 79 | return (int)m_positions.getStartPosition( m_tree, node ); | 78 | int pos = (int)m_positions.getStartPosition( m_tree, node ); |
| 79 | assert( pos >= 0 ); | ||
| 80 | return pos; | ||
| 80 | } | 81 | } |
| 81 | 82 | ||
| 82 | public int getEnd( Tree node ) | 83 | public int getEnd( Tree node ) |
| 83 | { | 84 | { |
| 84 | return (int)m_positions.getEndPosition( m_tree, node ); | 85 | int pos = (int)m_positions.getEndPosition( m_tree, node ); |
| 86 | assert( pos >= 0 ); | ||
| 87 | return pos; | ||
| 85 | } | 88 | } |
| 86 | 89 | ||
| 87 | public int getLine( Tree node ) | 90 | public int getLine( Tree node ) |
| @@ -121,8 +124,16 @@ public class SourcedAst | |||
| 121 | String fullClassName = m_classNameIndex.get( simpleClassName ); | 124 | String fullClassName = m_classNameIndex.get( simpleClassName ); |
| 122 | if( fullClassName == null ) | 125 | if( fullClassName == null ) |
| 123 | { | 126 | { |
| 124 | // no mapping was found, the name is probably already fully-qualified | 127 | if( m_packageName != null ) |
| 125 | fullClassName = simpleClassName; | 128 | { |
| 129 | // no mapping was found, assume it's in the package | ||
| 130 | fullClassName = m_packageName + "/" + simpleClassName; | ||
| 131 | } | ||
| 132 | else | ||
| 133 | { | ||
| 134 | // this must be in the default package | ||
| 135 | fullClassName = simpleClassName; | ||
| 136 | } | ||
| 126 | } | 137 | } |
| 127 | return fullClassName; | 138 | return fullClassName; |
| 128 | } | 139 | } |