diff options
| author | 2014-08-18 00:55:30 -0400 | |
|---|---|---|
| committer | 2014-08-18 00:55:30 -0400 | |
| commit | 34c1e8e64ec4575527a19fb4cb0640c57da784db (patch) | |
| tree | 44e3f1d50f8d8b8a9ab7c26dd94b58cba750cc67 /src/cuchaz/enigma/bytecode/ClassTranslator.java | |
| parent | added support for automatic reconstruction of inner and anonymous classes (diff) | |
| download | enigma-fork-34c1e8e64ec4575527a19fb4cb0640c57da784db.tar.gz enigma-fork-34c1e8e64ec4575527a19fb4cb0640c57da784db.tar.xz enigma-fork-34c1e8e64ec4575527a19fb4cb0640c57da784db.zip | |
crap-ton of bug fixes for inner classes
Diffstat (limited to 'src/cuchaz/enigma/bytecode/ClassTranslator.java')
| -rw-r--r-- | src/cuchaz/enigma/bytecode/ClassTranslator.java | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/src/cuchaz/enigma/bytecode/ClassTranslator.java b/src/cuchaz/enigma/bytecode/ClassTranslator.java index 3b5beeb..9ce06a5 100644 --- a/src/cuchaz/enigma/bytecode/ClassTranslator.java +++ b/src/cuchaz/enigma/bytecode/ClassTranslator.java | |||
| @@ -10,7 +10,6 @@ | |||
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma.bytecode; | 11 | package cuchaz.enigma.bytecode; |
| 12 | 12 | ||
| 13 | import java.util.HashSet; | ||
| 14 | import java.util.Set; | 13 | import java.util.Set; |
| 15 | 14 | ||
| 16 | import javassist.ClassMap; | 15 | import javassist.ClassMap; |
| @@ -20,6 +19,10 @@ import javassist.CtField; | |||
| 20 | import javassist.CtMethod; | 19 | import javassist.CtMethod; |
| 21 | import javassist.bytecode.ConstPool; | 20 | import javassist.bytecode.ConstPool; |
| 22 | import javassist.bytecode.Descriptor; | 21 | import javassist.bytecode.Descriptor; |
| 22 | import javassist.bytecode.InnerClassesAttribute; | ||
| 23 | |||
| 24 | import com.beust.jcommander.internal.Sets; | ||
| 25 | |||
| 23 | import cuchaz.enigma.mapping.ClassEntry; | 26 | import cuchaz.enigma.mapping.ClassEntry; |
| 24 | import cuchaz.enigma.mapping.FieldEntry; | 27 | import cuchaz.enigma.mapping.FieldEntry; |
| 25 | import cuchaz.enigma.mapping.MethodEntry; | 28 | import cuchaz.enigma.mapping.MethodEntry; |
| @@ -133,25 +136,47 @@ public class ClassTranslator | |||
| 133 | 136 | ||
| 134 | // translate all the class names referenced in the code | 137 | // translate all the class names referenced in the code |
| 135 | // the above code only changed method/field/reference names and types, but not the class names themselves | 138 | // the above code only changed method/field/reference names and types, but not the class names themselves |
| 136 | Set<String> classNames = getAllClassNames( c ); | 139 | Set<ClassEntry> classEntries = getAllClassEntries( c ); |
| 137 | ClassMap map = new ClassMap(); | 140 | ClassMap map = new ClassMap(); |
| 138 | for( String className : classNames ) | 141 | for( ClassEntry obfClassEntry : classEntries ) |
| 139 | { | 142 | { |
| 140 | String translatedName = m_translator.translateClass( className ); | 143 | map.put( obfClassEntry.getName(), m_translator.translateEntry( obfClassEntry ).getName() ); |
| 141 | if( translatedName != null ) | ||
| 142 | { | ||
| 143 | map.put( className, translatedName ); | ||
| 144 | } | ||
| 145 | } | 144 | } |
| 146 | if( !map.isEmpty() ) | 145 | c.replaceClassName( map ); |
| 146 | |||
| 147 | // translate the names in the InnerClasses attribute | ||
| 148 | InnerClassesAttribute attr = (InnerClassesAttribute)c.getClassFile().getAttribute( InnerClassesAttribute.tag ); | ||
| 149 | if( attr != null ) | ||
| 147 | { | 150 | { |
| 148 | c.replaceClassName( map ); | 151 | for( int i=0; i<attr.tableLength(); i++ ) |
| 152 | { | ||
| 153 | ClassEntry obfClassEntry = new ClassEntry( Descriptor.toJvmName( attr.innerClass( i ) ) ); | ||
| 154 | ClassEntry deobfClassEntry = m_translator.translateEntry( obfClassEntry ); | ||
| 155 | attr.setInnerClassIndex( i, constants.addClassInfo( deobfClassEntry.getName() ) ); | ||
| 156 | if( attr.outerClassIndex( i ) != 0 ) | ||
| 157 | { | ||
| 158 | attr.setOuterClassIndex( i, constants.addClassInfo( deobfClassEntry.getOuterClassName() ) ); | ||
| 159 | } | ||
| 160 | if( attr.innerNameIndex( i ) != 0 ) | ||
| 161 | { | ||
| 162 | attr.setInnerNameIndex( i, constants.addUtf8Info( deobfClassEntry.getInnerClassName() ) ); | ||
| 163 | } | ||
| 164 | |||
| 165 | /* DEBUG | ||
| 166 | System.out.println( String.format( "\tOBF: %s DEOBF: %s-> ATTR: %s,%s,%s", | ||
| 167 | obfClassEntry, deobfClassEntry, | ||
| 168 | attr.outerClass( i ), | ||
| 169 | attr.innerClass( i ), | ||
| 170 | attr.innerName( i ) | ||
| 171 | ) ); | ||
| 172 | */ | ||
| 173 | } | ||
| 149 | } | 174 | } |
| 150 | } | 175 | } |
| 151 | 176 | ||
| 152 | private Set<String> getAllClassNames( CtClass c ) | 177 | private Set<ClassEntry> getAllClassEntries( CtClass c ) |
| 153 | { | 178 | { |
| 154 | final Set<String> names = new HashSet<String>(); | 179 | final Set<ClassEntry> entries = Sets.newHashSet(); |
| 155 | ClassMap map = new ClassMap( ) | 180 | ClassMap map = new ClassMap( ) |
| 156 | { | 181 | { |
| 157 | @Override | 182 | @Override |
| @@ -159,13 +184,13 @@ public class ClassTranslator | |||
| 159 | { | 184 | { |
| 160 | if( obj instanceof String ) | 185 | if( obj instanceof String ) |
| 161 | { | 186 | { |
| 162 | names.add( (String)obj ); | 187 | entries.add( new ClassEntry( (String)obj ) ); |
| 163 | } | 188 | } |
| 164 | return null; | 189 | return null; |
| 165 | } | 190 | } |
| 166 | private static final long serialVersionUID = -202160293602070641L; | 191 | private static final long serialVersionUID = -202160293602070641L; |
| 167 | }; | 192 | }; |
| 168 | c.replaceClassName( map ); | 193 | c.replaceClassName( map ); |
| 169 | return names; | 194 | return entries; |
| 170 | } | 195 | } |
| 171 | } | 196 | } |