From 029f65d110279288f4cad7fb7cfaa33efd0f207d Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 28 Aug 2014 19:34:17 -0400 Subject: Show public/protected/private access on field/method/constructor references --- src/cuchaz/enigma/analysis/JarIndex.java | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'src/cuchaz/enigma/analysis/JarIndex.java') diff --git a/src/cuchaz/enigma/analysis/JarIndex.java b/src/cuchaz/enigma/analysis/JarIndex.java index 947453e..deacf16 100644 --- a/src/cuchaz/enigma/analysis/JarIndex.java +++ b/src/cuchaz/enigma/analysis/JarIndex.java @@ -23,6 +23,7 @@ import javassist.CannotCompileException; import javassist.CtBehavior; import javassist.CtClass; import javassist.CtConstructor; +import javassist.CtField; import javassist.CtMethod; import javassist.NotFoundException; import javassist.bytecode.AccessFlag; @@ -55,6 +56,7 @@ public class JarIndex { private Set m_obfClassEntries; private Ancestries m_ancestries; + private Map m_access; private Multimap m_methodImplementations; private Multimap> m_behaviorReferences; private Multimap> m_fieldReferences; @@ -67,6 +69,7 @@ public class JarIndex { m_obfClassEntries = Sets.newHashSet(); m_ancestries = new Ancestries(); + m_access = Maps.newHashMap(); m_methodImplementations = HashMultimap.create(); m_behaviorReferences = HashMultimap.create(); m_fieldReferences = HashMultimap.create(); @@ -89,7 +92,24 @@ public class JarIndex m_obfClassEntries.add( classEntry ); } - // step 2: index the types, methods + // step 2: index method/field access + for( CtClass c : JarClassIterator.classes( jar ) ) + { + fixClass( c ); + ClassEntry classEntry = new ClassEntry( Descriptor.toJvmName( c.getName() ) ); + for( CtField field : c.getDeclaredFields() ) + { + FieldEntry fieldEntry = new FieldEntry( classEntry, field.getName() ); + m_access.put( fieldEntry, Access.get( field ) ); + } + for( CtBehavior behavior : c.getDeclaredBehaviors() ) + { + MethodEntry methodEntry = new MethodEntry( classEntry, behavior.getName(), behavior.getSignature() ); + m_access.put( methodEntry, Access.get( behavior ) ); + } + } + + // step 3: index the types, methods for( CtClass c : JarClassIterator.classes( jar ) ) { fixClass( c ); @@ -105,7 +125,7 @@ public class JarIndex } } - // step 3: index inner classes and anonymous classes + // step 4: index inner classes and anonymous classes for( CtClass c : JarClassIterator.classes( jar ) ) { fixClass( c ); @@ -132,7 +152,7 @@ public class JarIndex } } - // step 4: update other indices with inner class info + // step 5: update other indices with inner class info Map renames = Maps.newHashMap(); for( Map.Entry entry : m_outerClasses.entrySet() ) { @@ -522,6 +542,11 @@ public class JarIndex return m_ancestries; } + public Access getAccess( Entry entry ) + { + return m_access.get( entry ); + } + public boolean isMethodImplemented( MethodEntry methodEntry ) { Collection implementations = m_methodImplementations.get( methodEntry.getClassName() ); -- cgit v1.2.3