diff options
| author | 2015-03-30 23:56:21 -0400 | |
|---|---|---|
| committer | 2015-03-30 23:56:21 -0400 | |
| commit | 2fc8ae770442ec3ab91cf0c16cc30917e0d048d3 (patch) | |
| tree | a49e9ede649fb0f350fee1b8336f319df20f4973 /src/cuchaz/enigma/analysis/JarIndex.java | |
| parent | add publifier (diff) | |
| download | enigma-fork-2fc8ae770442ec3ab91cf0c16cc30917e0d048d3.tar.gz enigma-fork-2fc8ae770442ec3ab91cf0c16cc30917e0d048d3.tar.xz enigma-fork-2fc8ae770442ec3ab91cf0c16cc30917e0d048d3.zip | |
resolve methods using interfaces as well as superclasses
Diffstat (limited to 'src/cuchaz/enigma/analysis/JarIndex.java')
| -rw-r--r-- | src/cuchaz/enigma/analysis/JarIndex.java | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/src/cuchaz/enigma/analysis/JarIndex.java b/src/cuchaz/enigma/analysis/JarIndex.java index e255468..6b3cf67 100644 --- a/src/cuchaz/enigma/analysis/JarIndex.java +++ b/src/cuchaz/enigma/analysis/JarIndex.java | |||
| @@ -59,7 +59,6 @@ public class JarIndex { | |||
| 59 | 59 | ||
| 60 | private Set<ClassEntry> m_obfClassEntries; | 60 | private Set<ClassEntry> m_obfClassEntries; |
| 61 | private TranslationIndex m_translationIndex; | 61 | private TranslationIndex m_translationIndex; |
| 62 | private Multimap<String,String> m_interfaces; | ||
| 63 | private Map<Entry,Access> m_access; | 62 | private Map<Entry,Access> m_access; |
| 64 | private Multimap<ClassEntry,FieldEntry> m_fields; | 63 | private Multimap<ClassEntry,FieldEntry> m_fields; |
| 65 | private Multimap<ClassEntry,BehaviorEntry> m_behaviors; | 64 | private Multimap<ClassEntry,BehaviorEntry> m_behaviors; |
| @@ -74,7 +73,6 @@ public class JarIndex { | |||
| 74 | public JarIndex() { | 73 | public JarIndex() { |
| 75 | m_obfClassEntries = Sets.newHashSet(); | 74 | m_obfClassEntries = Sets.newHashSet(); |
| 76 | m_translationIndex = new TranslationIndex(); | 75 | m_translationIndex = new TranslationIndex(); |
| 77 | m_interfaces = HashMultimap.create(); | ||
| 78 | m_access = Maps.newHashMap(); | 76 | m_access = Maps.newHashMap(); |
| 79 | m_fields = HashMultimap.create(); | 77 | m_fields = HashMultimap.create(); |
| 80 | m_behaviors = HashMultimap.create(); | 78 | m_behaviors = HashMultimap.create(); |
| @@ -124,7 +122,6 @@ public class JarIndex { | |||
| 124 | if (className.equals(interfaceName)) { | 122 | if (className.equals(interfaceName)) { |
| 125 | throw new IllegalArgumentException("Class cannot be its own interface! " + className); | 123 | throw new IllegalArgumentException("Class cannot be its own interface! " + className); |
| 126 | } | 124 | } |
| 127 | m_interfaces.put(className, interfaceName); | ||
| 128 | } | 125 | } |
| 129 | for (CtBehavior behavior : c.getDeclaredBehaviors()) { | 126 | for (CtBehavior behavior : c.getDeclaredBehaviors()) { |
| 130 | indexBehavior(behavior); | 127 | indexBehavior(behavior); |
| @@ -176,7 +173,6 @@ public class JarIndex { | |||
| 176 | } | 173 | } |
| 177 | EntryRenamer.renameClassesInSet(renames, m_obfClassEntries); | 174 | EntryRenamer.renameClassesInSet(renames, m_obfClassEntries); |
| 178 | m_translationIndex.renameClasses(renames); | 175 | m_translationIndex.renameClasses(renames); |
| 179 | EntryRenamer.renameClassesInMultimap(renames, m_interfaces); | ||
| 180 | EntryRenamer.renameClassesInMultimap(renames, m_methodImplementations); | 176 | EntryRenamer.renameClassesInMultimap(renames, m_methodImplementations); |
| 181 | EntryRenamer.renameClassesInMultimap(renames, m_behaviorReferences); | 177 | EntryRenamer.renameClassesInMultimap(renames, m_behaviorReferences); |
| 182 | EntryRenamer.renameClassesInMultimap(renames, m_fieldReferences); | 178 | EntryRenamer.renameClassesInMultimap(renames, m_fieldReferences); |
| @@ -637,11 +633,11 @@ public class JarIndex { | |||
| 637 | interfaceMethodEntries.add(obfMethodEntry); | 633 | interfaceMethodEntries.add(obfMethodEntry); |
| 638 | } else { | 634 | } else { |
| 639 | // get the interface class | 635 | // get the interface class |
| 640 | for (String interfaceName : getInterfaces(obfMethodEntry.getClassName())) { | 636 | for (ClassEntry interfaceEntry : getInterfaces(obfMethodEntry.getClassName())) { |
| 641 | 637 | ||
| 642 | // is this method defined in this interface? | 638 | // is this method defined in this interface? |
| 643 | MethodEntry methodInterface = new MethodEntry( | 639 | MethodEntry methodInterface = new MethodEntry( |
| 644 | new ClassEntry(interfaceName), | 640 | interfaceEntry, |
| 645 | obfMethodEntry.getName(), | 641 | obfMethodEntry.getName(), |
| 646 | obfMethodEntry.getSignature() | 642 | obfMethodEntry.getSignature() |
| 647 | ); | 643 | ); |
| @@ -745,31 +741,33 @@ public class JarIndex { | |||
| 745 | return m_anonymousClasses.get(obfInnerClassName); | 741 | return m_anonymousClasses.get(obfInnerClassName); |
| 746 | } | 742 | } |
| 747 | 743 | ||
| 748 | public Set<String> getInterfaces(String className) { | 744 | public Set<ClassEntry> getInterfaces(String className) { |
| 749 | Set<String> interfaceNames = new HashSet<String>(); | 745 | ClassEntry classEntry = new ClassEntry(className); |
| 750 | interfaceNames.addAll(m_interfaces.get(className)); | 746 | Set<ClassEntry> interfaces = new HashSet<ClassEntry>(); |
| 751 | for (ClassEntry ancestor : m_translationIndex.getAncestry(new ClassEntry(className))) { | 747 | interfaces.addAll(m_translationIndex.getInterfaces(classEntry)); |
| 752 | interfaceNames.addAll(m_interfaces.get(ancestor.getName())); | 748 | for (ClassEntry ancestor : m_translationIndex.getAncestry(classEntry)) { |
| 749 | interfaces.addAll(m_translationIndex.getInterfaces(ancestor)); | ||
| 753 | } | 750 | } |
| 754 | return interfaceNames; | 751 | return interfaces; |
| 755 | } | 752 | } |
| 756 | 753 | ||
| 757 | public Set<String> getImplementingClasses(String targetInterfaceName) { | 754 | public Set<String> getImplementingClasses(String targetInterfaceName) { |
| 755 | |||
| 758 | // linear search is fast enough for now | 756 | // linear search is fast enough for now |
| 759 | Set<String> classNames = Sets.newHashSet(); | 757 | Set<String> classNames = Sets.newHashSet(); |
| 760 | for (Map.Entry<String,String> entry : m_interfaces.entries()) { | 758 | for (Map.Entry<ClassEntry,ClassEntry> entry : m_translationIndex.getClassInterfaces()) { |
| 761 | String className = entry.getKey(); | 759 | ClassEntry classEntry = entry.getKey(); |
| 762 | String interfaceName = entry.getValue(); | 760 | ClassEntry interfaceEntry = entry.getValue(); |
| 763 | if (interfaceName.equals(targetInterfaceName)) { | 761 | if (interfaceEntry.getName().equals(targetInterfaceName)) { |
| 764 | classNames.add(className); | 762 | classNames.add(classEntry.getClassName()); |
| 765 | m_translationIndex.getSubclassNamesRecursively(classNames, new ClassEntry(className)); | 763 | m_translationIndex.getSubclassNamesRecursively(classNames, classEntry); |
| 766 | } | 764 | } |
| 767 | } | 765 | } |
| 768 | return classNames; | 766 | return classNames; |
| 769 | } | 767 | } |
| 770 | 768 | ||
| 771 | public boolean isInterface(String className) { | 769 | public boolean isInterface(String className) { |
| 772 | return m_interfaces.containsValue(className); | 770 | return m_translationIndex.isInterface(new ClassEntry(className)); |
| 773 | } | 771 | } |
| 774 | 772 | ||
| 775 | public boolean containsObfClass(ClassEntry obfClassEntry) { | 773 | public boolean containsObfClass(ClassEntry obfClassEntry) { |