diff options
| author | 2015-02-23 23:29:22 -0500 | |
|---|---|---|
| committer | 2015-02-23 23:29:22 -0500 | |
| commit | 2dc7428e37bdd7a119f53d02ce157675509b0d63 (patch) | |
| tree | 68f409ac726166e427eea3a199eb462130c53ccd /src/cuchaz/enigma/bytecode/InnerClassWriter.java | |
| parent | make types serializable (diff) | |
| download | enigma-fork-2dc7428e37bdd7a119f53d02ce157675509b0d63.tar.gz enigma-fork-2dc7428e37bdd7a119f53d02ce157675509b0d63.tar.xz enigma-fork-2dc7428e37bdd7a119f53d02ce157675509b0d63.zip | |
lots of work in better handling of inner classes
also working on recognizing unobfuscated and deobfuscated jars
(needed for M3L)
Diffstat (limited to 'src/cuchaz/enigma/bytecode/InnerClassWriter.java')
| -rw-r--r-- | src/cuchaz/enigma/bytecode/InnerClassWriter.java | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/src/cuchaz/enigma/bytecode/InnerClassWriter.java b/src/cuchaz/enigma/bytecode/InnerClassWriter.java index 5350b86..e82f56c 100644 --- a/src/cuchaz/enigma/bytecode/InnerClassWriter.java +++ b/src/cuchaz/enigma/bytecode/InnerClassWriter.java | |||
| @@ -14,13 +14,12 @@ import java.util.Collection; | |||
| 14 | 14 | ||
| 15 | import javassist.CtClass; | 15 | import javassist.CtClass; |
| 16 | import javassist.bytecode.ConstPool; | 16 | import javassist.bytecode.ConstPool; |
| 17 | import javassist.bytecode.Descriptor; | ||
| 18 | import javassist.bytecode.EnclosingMethodAttribute; | 17 | import javassist.bytecode.EnclosingMethodAttribute; |
| 19 | import javassist.bytecode.InnerClassesAttribute; | 18 | import javassist.bytecode.InnerClassesAttribute; |
| 20 | import cuchaz.enigma.Constants; | ||
| 21 | import cuchaz.enigma.analysis.JarIndex; | 19 | import cuchaz.enigma.analysis.JarIndex; |
| 22 | import cuchaz.enigma.mapping.BehaviorEntry; | 20 | import cuchaz.enigma.mapping.BehaviorEntry; |
| 23 | import cuchaz.enigma.mapping.ClassEntry; | 21 | import cuchaz.enigma.mapping.ClassEntry; |
| 22 | import cuchaz.enigma.mapping.EntryFactory; | ||
| 24 | 23 | ||
| 25 | public class InnerClassWriter { | 24 | public class InnerClassWriter { |
| 26 | 25 | ||
| @@ -32,18 +31,23 @@ public class InnerClassWriter { | |||
| 32 | 31 | ||
| 33 | public void write(CtClass c) { | 32 | public void write(CtClass c) { |
| 34 | 33 | ||
| 35 | // is this an inner or outer class? | 34 | // first, assume this is an inner class |
| 36 | String obfInnerClassName = new ClassEntry(Descriptor.toJvmName(c.getName())).getSimpleName(); | 35 | ClassEntry obfInnerClassEntry = EntryFactory.getClassEntry(c); |
| 37 | String obfOuterClassName = m_jarIndex.getOuterClass(obfInnerClassName); | 36 | ClassEntry obfOuterClassEntry = m_jarIndex.getOuterClass(obfInnerClassEntry); |
| 38 | if (obfOuterClassName == null) { | 37 | |
| 39 | // this is an outer class | 38 | // see if we're right |
| 40 | obfOuterClassName = Descriptor.toJvmName(c.getName()); | 39 | if (obfOuterClassEntry == null) { |
| 40 | |||
| 41 | // nope, it's an outer class | ||
| 42 | obfInnerClassEntry = null; | ||
| 43 | obfOuterClassEntry = EntryFactory.getClassEntry(c); | ||
| 41 | } else { | 44 | } else { |
| 42 | // this is an inner class, rename it to outer$inner | 45 | |
| 43 | ClassEntry obfClassEntry = new ClassEntry(obfOuterClassName + "$" + obfInnerClassName); | 46 | // yeah, it's an inner class, rename it to outer$inner |
| 47 | ClassEntry obfClassEntry = new ClassEntry(obfOuterClassEntry.getName() + "$" + obfInnerClassEntry.getSimpleName()); | ||
| 44 | c.setName(obfClassEntry.getName()); | 48 | c.setName(obfClassEntry.getName()); |
| 45 | 49 | ||
| 46 | BehaviorEntry caller = m_jarIndex.getAnonymousClassCaller(obfInnerClassName); | 50 | BehaviorEntry caller = m_jarIndex.getAnonymousClassCaller(obfInnerClassEntry); |
| 47 | if (caller != null) { | 51 | if (caller != null) { |
| 48 | // write the enclosing method attribute | 52 | // write the enclosing method attribute |
| 49 | if (caller.getName().equals("<clinit>")) { | 53 | if (caller.getName().equals("<clinit>")) { |
| @@ -55,18 +59,19 @@ public class InnerClassWriter { | |||
| 55 | } | 59 | } |
| 56 | 60 | ||
| 57 | // write the inner classes if needed | 61 | // write the inner classes if needed |
| 58 | Collection<String> obfInnerClassNames = m_jarIndex.getInnerClasses(obfOuterClassName); | 62 | Collection<ClassEntry> obfInnerClassEntries = m_jarIndex.getInnerClasses(obfOuterClassEntry); |
| 59 | if (obfInnerClassNames != null && !obfInnerClassNames.isEmpty()) { | 63 | if (obfInnerClassEntries != null && !obfInnerClassEntries.isEmpty()) { |
| 60 | writeInnerClasses(c, obfOuterClassName, obfInnerClassNames); | 64 | writeInnerClasses(c, obfOuterClassEntry, obfInnerClassEntries); |
| 61 | } | 65 | } |
| 62 | } | 66 | } |
| 63 | 67 | ||
| 64 | private void writeInnerClasses(CtClass c, String obfOuterClassName, Collection<String> obfInnerClassNames) { | 68 | private void writeInnerClasses(CtClass c, ClassEntry obfOuterClassEntry, Collection<ClassEntry> obfInnerClassEntries) { |
| 65 | InnerClassesAttribute attr = new InnerClassesAttribute(c.getClassFile().getConstPool()); | 69 | InnerClassesAttribute attr = new InnerClassesAttribute(c.getClassFile().getConstPool()); |
| 66 | c.getClassFile().addAttribute(attr); | 70 | c.getClassFile().addAttribute(attr); |
| 67 | for (String obfInnerClassName : obfInnerClassNames) { | 71 | for (ClassEntry obfInnerClassEntry : obfInnerClassEntries) { |
| 72 | |||
| 68 | // get the new inner class name | 73 | // get the new inner class name |
| 69 | ClassEntry obfClassEntry = new ClassEntry(obfOuterClassName + "$" + obfInnerClassName); | 74 | ClassEntry obfClassEntry = new ClassEntry(obfOuterClassEntry.getName() + "$" + obfInnerClassEntry.getSimpleName()); |
| 70 | 75 | ||
| 71 | // here's what the JVM spec says about the InnerClasses attribute | 76 | // here's what the JVM spec says about the InnerClasses attribute |
| 72 | // append( inner, outer of inner if inner is member of outer 0 ow, name after $ if inner not anonymous 0 ow, flags ); | 77 | // append( inner, outer of inner if inner is member of outer 0 ow, name after $ if inner not anonymous 0 ow, flags ); |
| @@ -77,7 +82,7 @@ public class InnerClassWriter { | |||
| 77 | int outerClassIndex = 0; | 82 | int outerClassIndex = 0; |
| 78 | int innerClassSimpleNameIndex = 0; | 83 | int innerClassSimpleNameIndex = 0; |
| 79 | int accessFlags = 0; | 84 | int accessFlags = 0; |
| 80 | if (!m_jarIndex.isAnonymousClass(obfInnerClassName)) { | 85 | if (!m_jarIndex.isAnonymousClass(obfInnerClassEntry)) { |
| 81 | outerClassIndex = constPool.addClassInfo(obfClassEntry.getOuterClassName()); | 86 | outerClassIndex = constPool.addClassInfo(obfClassEntry.getOuterClassName()); |
| 82 | innerClassSimpleNameIndex = constPool.addUtf8Info(obfClassEntry.getInnerClassName()); | 87 | innerClassSimpleNameIndex = constPool.addUtf8Info(obfClassEntry.getInnerClassName()); |
| 83 | } | 88 | } |
| @@ -96,7 +101,7 @@ public class InnerClassWriter { | |||
| 96 | */ | 101 | */ |
| 97 | 102 | ||
| 98 | // make sure the outer class references only the new inner class names | 103 | // make sure the outer class references only the new inner class names |
| 99 | c.replaceClassName(Constants.NonePackage + "/" + obfInnerClassName, obfClassEntry.getName()); | 104 | c.replaceClassName(obfInnerClassEntry.getName(), obfClassEntry.getName()); |
| 100 | } | 105 | } |
| 101 | } | 106 | } |
| 102 | } | 107 | } |