diff options
Diffstat (limited to 'src/cuchaz/enigma/analysis/BridgeFixer.java')
| -rw-r--r-- | src/cuchaz/enigma/analysis/BridgeFixer.java | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/src/cuchaz/enigma/analysis/BridgeFixer.java b/src/cuchaz/enigma/analysis/BridgeFixer.java index 112b864..ad23b00 100644 --- a/src/cuchaz/enigma/analysis/BridgeFixer.java +++ b/src/cuchaz/enigma/analysis/BridgeFixer.java | |||
| @@ -20,61 +20,48 @@ import cuchaz.enigma.mapping.BehaviorEntryFactory; | |||
| 20 | import cuchaz.enigma.mapping.ClassEntry; | 20 | import cuchaz.enigma.mapping.ClassEntry; |
| 21 | import cuchaz.enigma.mapping.MethodEntry; | 21 | import cuchaz.enigma.mapping.MethodEntry; |
| 22 | 22 | ||
| 23 | public class BridgeFixer | 23 | public class BridgeFixer { |
| 24 | { | 24 | |
| 25 | private JarIndex m_index; | 25 | private JarIndex m_index; |
| 26 | 26 | ||
| 27 | public BridgeFixer( JarIndex index ) | 27 | public BridgeFixer(JarIndex index) { |
| 28 | { | ||
| 29 | m_index = index; | 28 | m_index = index; |
| 30 | } | 29 | } |
| 31 | 30 | ||
| 32 | public void fixBridges( CtClass c ) | 31 | public void fixBridges(CtClass c) { |
| 33 | { | ||
| 34 | // rename declared methods | 32 | // rename declared methods |
| 35 | for( CtMethod method : c.getDeclaredMethods() ) | 33 | for (CtMethod method : c.getDeclaredMethods()) { |
| 36 | { | ||
| 37 | // get the method entry | 34 | // get the method entry |
| 38 | MethodEntry methodEntry = new MethodEntry( | 35 | MethodEntry methodEntry = new MethodEntry( |
| 39 | new ClassEntry( Descriptor.toJvmName( c.getName() ) ), | 36 | new ClassEntry(Descriptor.toJvmName(c.getName())), |
| 40 | method.getName(), | 37 | method.getName(), |
| 41 | method.getSignature() | 38 | method.getSignature() |
| 42 | ); | 39 | ); |
| 43 | MethodEntry bridgeMethodEntry = m_index.getBridgeMethod( methodEntry ); | 40 | MethodEntry bridgeMethodEntry = m_index.getBridgeMethod(methodEntry); |
| 44 | if( bridgeMethodEntry != null ) | 41 | if (bridgeMethodEntry != null) { |
| 45 | { | ||
| 46 | // fix this bridged method | 42 | // fix this bridged method |
| 47 | method.setName( bridgeMethodEntry.getName() ); | 43 | method.setName(bridgeMethodEntry.getName()); |
| 48 | } | 44 | } |
| 49 | } | 45 | } |
| 50 | 46 | ||
| 51 | // rename method references | 47 | // rename method references |
| 52 | // translate all the field and method references in the code by editing the constant pool | 48 | // translate all the field and method references in the code by editing the constant pool |
| 53 | ConstPool constants = c.getClassFile().getConstPool(); | 49 | ConstPool constants = c.getClassFile().getConstPool(); |
| 54 | ConstPoolEditor editor = new ConstPoolEditor( constants ); | 50 | ConstPoolEditor editor = new ConstPoolEditor(constants); |
| 55 | for( int i=1; i<constants.getSize(); i++ ) | 51 | for (int i = 1; i < constants.getSize(); i++) { |
| 56 | { | 52 | switch (constants.getTag(i)) { |
| 57 | switch( constants.getTag( i ) ) | ||
| 58 | { | ||
| 59 | case ConstPool.CONST_Methodref: | 53 | case ConstPool.CONST_Methodref: |
| 60 | case ConstPool.CONST_InterfaceMethodref: | 54 | case ConstPool.CONST_InterfaceMethodref: { |
| 61 | { | 55 | BehaviorEntry behaviorEntry = BehaviorEntryFactory.create(Descriptor.toJvmName(editor.getMemberrefClassname(i)), editor.getMemberrefName(i), editor.getMemberrefType(i)); |
| 62 | BehaviorEntry behaviorEntry = BehaviorEntryFactory.create( | ||
| 63 | Descriptor.toJvmName( editor.getMemberrefClassname( i ) ), | ||
| 64 | editor.getMemberrefName( i ), | ||
| 65 | editor.getMemberrefType( i ) | ||
| 66 | ); | ||
| 67 | 56 | ||
| 68 | if( behaviorEntry instanceof MethodEntry ) | 57 | if (behaviorEntry instanceof MethodEntry) { |
| 69 | { | ||
| 70 | MethodEntry methodEntry = (MethodEntry)behaviorEntry; | 58 | MethodEntry methodEntry = (MethodEntry)behaviorEntry; |
| 71 | 59 | ||
| 72 | // translate the name and type | 60 | // translate the name and type |
| 73 | MethodEntry bridgeMethodEntry = m_index.getBridgeMethod( methodEntry ); | 61 | MethodEntry bridgeMethodEntry = m_index.getBridgeMethod(methodEntry); |
| 74 | if( bridgeMethodEntry != null ) | 62 | if (bridgeMethodEntry != null) { |
| 75 | { | ||
| 76 | // FIXIT FIXIT FIXIT FIXIT FIXIT FIXIT FIXIT | 63 | // FIXIT FIXIT FIXIT FIXIT FIXIT FIXIT FIXIT |
| 77 | editor.changeMemberrefNameAndType( i, bridgeMethodEntry.getName(), bridgeMethodEntry.getSignature() ); | 64 | editor.changeMemberrefNameAndType(i, bridgeMethodEntry.getName(), bridgeMethodEntry.getSignature()); |
| 78 | } | 65 | } |
| 79 | } | 66 | } |
| 80 | } | 67 | } |