diff options
| author | 2014-09-30 00:25:36 -0400 | |
|---|---|---|
| committer | 2014-09-30 00:25:36 -0400 | |
| commit | a83bbfd5c510367a194073b1db132022cacf65ed (patch) | |
| tree | abfd7520b79ef1e64b7430bd81e75a30353b7f14 /src/cuchaz/enigma/bytecode | |
| parent | fixed recognition of static initializer tokens (diff) | |
| download | enigma-fork-a83bbfd5c510367a194073b1db132022cacf65ed.tar.gz enigma-fork-a83bbfd5c510367a194073b1db132022cacf65ed.tar.xz enigma-fork-a83bbfd5c510367a194073b1db132022cacf65ed.zip | |
fixed nasty issue with renaming inner classes, but alas, more bugs remain
Diffstat (limited to 'src/cuchaz/enigma/bytecode')
| -rw-r--r-- | src/cuchaz/enigma/bytecode/ClassRenamer.java | 31 | ||||
| -rw-r--r-- | src/cuchaz/enigma/bytecode/ClassTranslator.java | 6 | ||||
| -rw-r--r-- | src/cuchaz/enigma/bytecode/InnerClassWriter.java | 20 |
3 files changed, 22 insertions, 35 deletions
diff --git a/src/cuchaz/enigma/bytecode/ClassRenamer.java b/src/cuchaz/enigma/bytecode/ClassRenamer.java index 9f0845d..849a323 100644 --- a/src/cuchaz/enigma/bytecode/ClassRenamer.java +++ b/src/cuchaz/enigma/bytecode/ClassRenamer.java | |||
| @@ -37,34 +37,25 @@ public class ClassRenamer | |||
| 37 | { | 37 | { |
| 38 | nameMap.put( entry.getKey().getName(), entry.getValue().getName() ); | 38 | nameMap.put( entry.getKey().getName(), entry.getValue().getName() ); |
| 39 | } | 39 | } |
| 40 | |||
| 40 | c.replaceClassName( nameMap ); | 41 | c.replaceClassName( nameMap ); |
| 41 | 42 | ||
| 42 | // translate the names in the InnerClasses attribute | 43 | // replace simple names in the InnerClasses attribute too |
| 43 | ConstPool constants = c.getClassFile().getConstPool(); | 44 | ConstPool constants = c.getClassFile().getConstPool(); |
| 44 | InnerClassesAttribute attr = (InnerClassesAttribute)c.getClassFile().getAttribute( InnerClassesAttribute.tag ); | 45 | InnerClassesAttribute attr = (InnerClassesAttribute)c.getClassFile().getAttribute( InnerClassesAttribute.tag ); |
| 45 | if( attr != null ) | 46 | if( attr != null ) |
| 46 | { | 47 | { |
| 47 | for( int i=0; i<attr.tableLength(); i++ ) | 48 | for( int i=0; i<attr.tableLength(); i++ ) |
| 48 | { | 49 | { |
| 49 | ClassEntry inClassEntry = new ClassEntry( Descriptor.toJvmName( attr.innerClass( i ) ) ); | 50 | ClassEntry classEntry = new ClassEntry( Descriptor.toJvmName( attr.innerClass( i ) ) ); |
| 50 | ClassEntry outClassEntry = map.get( inClassEntry ); | ||
| 51 | if( outClassEntry == null ) | ||
| 52 | { | ||
| 53 | continue; | ||
| 54 | } | ||
| 55 | attr.setInnerClassIndex( i, constants.addClassInfo( outClassEntry.getName() ) ); | ||
| 56 | if( attr.outerClassIndex( i ) != 0 ) | ||
| 57 | { | ||
| 58 | attr.setOuterClassIndex( i, constants.addClassInfo( outClassEntry.getOuterClassName() ) ); | ||
| 59 | } | ||
| 60 | if( attr.innerNameIndex( i ) != 0 ) | 51 | if( attr.innerNameIndex( i ) != 0 ) |
| 61 | { | 52 | { |
| 62 | attr.setInnerNameIndex( i, constants.addUtf8Info( outClassEntry.getInnerClassName() ) ); | 53 | attr.setInnerNameIndex( i, constants.addUtf8Info( classEntry.getInnerClassName() ) ); |
| 63 | } | 54 | } |
| 64 | 55 | ||
| 65 | /* DEBUG | 56 | /* DEBUG |
| 66 | System.out.println( String.format( "\tOBF: %s DEOBF: %s-> ATTR: %s,%s,%s", | 57 | System.out.println( String.format( "\tDEOBF: %s-> ATTR: %s,%s,%s", |
| 67 | obfClassEntry, deobfClassEntry, | 58 | classEntry, |
| 68 | attr.outerClass( i ), | 59 | attr.outerClass( i ), |
| 69 | attr.innerClass( i ), | 60 | attr.innerClass( i ), |
| 70 | attr.innerName( i ) | 61 | attr.innerName( i ) |
| @@ -109,16 +100,6 @@ public class ClassRenamer | |||
| 109 | }; | 100 | }; |
| 110 | c.replaceClassName( map ); | 101 | c.replaceClassName( map ); |
| 111 | 102 | ||
| 112 | // also check InnerClassesAttribute | ||
| 113 | InnerClassesAttribute attr = (InnerClassesAttribute)c.getClassFile().getAttribute( InnerClassesAttribute.tag ); | ||
| 114 | if( attr != null ) | ||
| 115 | { | ||
| 116 | for( int i=0; i<attr.tableLength(); i++ ) | ||
| 117 | { | ||
| 118 | entries.add( new ClassEntry( Descriptor.toJvmName( attr.innerClass( i ) ) ) ); | ||
| 119 | } | ||
| 120 | } | ||
| 121 | |||
| 122 | return entries; | 103 | return entries; |
| 123 | } | 104 | } |
| 124 | 105 | ||
diff --git a/src/cuchaz/enigma/bytecode/ClassTranslator.java b/src/cuchaz/enigma/bytecode/ClassTranslator.java index db28f21..181fadb 100644 --- a/src/cuchaz/enigma/bytecode/ClassTranslator.java +++ b/src/cuchaz/enigma/bytecode/ClassTranslator.java | |||
| @@ -132,7 +132,11 @@ public class ClassTranslator | |||
| 132 | Map<ClassEntry,ClassEntry> map = Maps.newHashMap(); | 132 | Map<ClassEntry,ClassEntry> map = Maps.newHashMap(); |
| 133 | for( ClassEntry obfClassEntry : ClassRenamer.getAllClassEntries( c ) ) | 133 | for( ClassEntry obfClassEntry : ClassRenamer.getAllClassEntries( c ) ) |
| 134 | { | 134 | { |
| 135 | map.put( obfClassEntry, m_translator.translateEntry( obfClassEntry ) ); | 135 | ClassEntry deobfClassEntry = m_translator.translateEntry( obfClassEntry ); |
| 136 | if( !obfClassEntry.equals( deobfClassEntry ) ) | ||
| 137 | { | ||
| 138 | map.put( obfClassEntry, deobfClassEntry ); | ||
| 139 | } | ||
| 136 | } | 140 | } |
| 137 | ClassRenamer.renameClasses( c, map ); | 141 | ClassRenamer.renameClasses( c, map ); |
| 138 | } | 142 | } |
diff --git a/src/cuchaz/enigma/bytecode/InnerClassWriter.java b/src/cuchaz/enigma/bytecode/InnerClassWriter.java index a061792..5e59307 100644 --- a/src/cuchaz/enigma/bytecode/InnerClassWriter.java +++ b/src/cuchaz/enigma/bytecode/InnerClassWriter.java | |||
| @@ -18,6 +18,7 @@ import javassist.bytecode.ConstPool; | |||
| 18 | import javassist.bytecode.Descriptor; | 18 | import javassist.bytecode.Descriptor; |
| 19 | import javassist.bytecode.EnclosingMethodAttribute; | 19 | import javassist.bytecode.EnclosingMethodAttribute; |
| 20 | import javassist.bytecode.InnerClassesAttribute; | 20 | import javassist.bytecode.InnerClassesAttribute; |
| 21 | import cuchaz.enigma.Constants; | ||
| 21 | import cuchaz.enigma.analysis.JarIndex; | 22 | import cuchaz.enigma.analysis.JarIndex; |
| 22 | import cuchaz.enigma.mapping.BehaviorEntry; | 23 | import cuchaz.enigma.mapping.BehaviorEntry; |
| 23 | import cuchaz.enigma.mapping.ClassEntry; | 24 | import cuchaz.enigma.mapping.ClassEntry; |
| @@ -33,21 +34,21 @@ public class InnerClassWriter | |||
| 33 | 34 | ||
| 34 | public void write( CtClass c ) | 35 | public void write( CtClass c ) |
| 35 | { | 36 | { |
| 36 | // get the outer class name | 37 | // is this an inner or outer class? |
| 37 | String obfClassName = Descriptor.toJvmName( c.getName() ); | 38 | String obfInnerClassName = new ClassEntry( Descriptor.toJvmName( c.getName() ) ).getSimpleName(); |
| 38 | String obfOuterClassName = m_jarIndex.getOuterClass( obfClassName ); | 39 | String obfOuterClassName = m_jarIndex.getOuterClass( obfInnerClassName ); |
| 39 | if( obfOuterClassName == null ) | 40 | if( obfOuterClassName == null ) |
| 40 | { | 41 | { |
| 41 | // this is an outer class | 42 | // this is an outer class |
| 42 | obfOuterClassName = obfClassName; | 43 | obfOuterClassName = Descriptor.toJvmName( c.getName() ); |
| 43 | } | 44 | } |
| 44 | else | 45 | else |
| 45 | { | 46 | { |
| 46 | // this is an inner class, rename it to outer$inner | 47 | // this is an inner class, rename it to outer$inner |
| 47 | ClassEntry obfClassEntry = new ClassEntry( obfOuterClassName + "$" + new ClassEntry( obfClassName ).getSimpleName() ); | 48 | ClassEntry obfClassEntry = new ClassEntry( obfOuterClassName + "$" + obfInnerClassName ); |
| 48 | c.setName( obfClassEntry.getName() ); | 49 | c.setName( obfClassEntry.getName() ); |
| 49 | 50 | ||
| 50 | BehaviorEntry caller = m_jarIndex.getAnonymousClassCaller( obfClassName ); | 51 | BehaviorEntry caller = m_jarIndex.getAnonymousClassCaller( obfInnerClassName ); |
| 51 | if( caller != null ) | 52 | if( caller != null ) |
| 52 | { | 53 | { |
| 53 | // write the enclosing method attribute | 54 | // write the enclosing method attribute |
| @@ -85,7 +86,7 @@ public class InnerClassWriter | |||
| 85 | for( String obfInnerClassName : obfInnerClassNames ) | 86 | for( String obfInnerClassName : obfInnerClassNames ) |
| 86 | { | 87 | { |
| 87 | // get the new inner class name | 88 | // get the new inner class name |
| 88 | ClassEntry obfClassEntry = new ClassEntry( obfOuterClassName + "$" + new ClassEntry( obfInnerClassName ).getSimpleName() ); | 89 | ClassEntry obfClassEntry = new ClassEntry( obfOuterClassName + "$" + obfInnerClassName ); |
| 89 | 90 | ||
| 90 | // here's what the JVM spec says about the InnerClasses attribute | 91 | // here's what the JVM spec says about the InnerClasses attribute |
| 91 | // append( inner, outer of inner if inner is member of outer 0 ow, name after $ if inner not anonymous 0 ow, flags ); | 92 | // append( inner, outer of inner if inner is member of outer 0 ow, name after $ if inner not anonymous 0 ow, flags ); |
| @@ -114,12 +115,13 @@ public class InnerClassWriter | |||
| 114 | attr.outerClass( attr.tableLength() - 1 ), | 115 | attr.outerClass( attr.tableLength() - 1 ), |
| 115 | attr.innerClass( attr.tableLength() - 1 ), | 116 | attr.innerClass( attr.tableLength() - 1 ), |
| 116 | attr.innerName( attr.tableLength() - 1 ), | 117 | attr.innerName( attr.tableLength() - 1 ), |
| 117 | obfInnerClassName, obfClassEntry.getName() | 118 | Constants.NonePackage + "/" + obfInnerClassName, |
| 119 | obfClassEntry.getName() | ||
| 118 | ) ); | 120 | ) ); |
| 119 | */ | 121 | */ |
| 120 | 122 | ||
| 121 | // make sure the outer class references only the new inner class names | 123 | // make sure the outer class references only the new inner class names |
| 122 | c.replaceClassName( obfInnerClassName, obfClassEntry.getName() ); | 124 | c.replaceClassName( Constants.NonePackage + "/" + obfInnerClassName, obfClassEntry.getName() ); |
| 123 | } | 125 | } |
| 124 | } | 126 | } |
| 125 | } | 127 | } |