diff options
Diffstat (limited to 'src/cuchaz/enigma/analysis/BridgeFixer.java')
| -rw-r--r-- | src/cuchaz/enigma/analysis/BridgeFixer.java | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/src/cuchaz/enigma/analysis/BridgeFixer.java b/src/cuchaz/enigma/analysis/BridgeFixer.java deleted file mode 100644 index ad23b00..0000000 --- a/src/cuchaz/enigma/analysis/BridgeFixer.java +++ /dev/null | |||
| @@ -1,72 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Public License v3.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/gpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.analysis; | ||
| 12 | |||
| 13 | import javassist.CtClass; | ||
| 14 | import javassist.CtMethod; | ||
| 15 | import javassist.bytecode.ConstPool; | ||
| 16 | import javassist.bytecode.Descriptor; | ||
| 17 | import cuchaz.enigma.bytecode.ConstPoolEditor; | ||
| 18 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 19 | import cuchaz.enigma.mapping.BehaviorEntryFactory; | ||
| 20 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 21 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 22 | |||
| 23 | public class BridgeFixer { | ||
| 24 | |||
| 25 | private JarIndex m_index; | ||
| 26 | |||
| 27 | public BridgeFixer(JarIndex index) { | ||
| 28 | m_index = index; | ||
| 29 | } | ||
| 30 | |||
| 31 | public void fixBridges(CtClass c) { | ||
| 32 | // rename declared methods | ||
| 33 | for (CtMethod method : c.getDeclaredMethods()) { | ||
| 34 | // get the method entry | ||
| 35 | MethodEntry methodEntry = new MethodEntry( | ||
| 36 | new ClassEntry(Descriptor.toJvmName(c.getName())), | ||
| 37 | method.getName(), | ||
| 38 | method.getSignature() | ||
| 39 | ); | ||
| 40 | MethodEntry bridgeMethodEntry = m_index.getBridgeMethod(methodEntry); | ||
| 41 | if (bridgeMethodEntry != null) { | ||
| 42 | // fix this bridged method | ||
| 43 | method.setName(bridgeMethodEntry.getName()); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | // rename method references | ||
| 48 | // translate all the field and method references in the code by editing the constant pool | ||
| 49 | ConstPool constants = c.getClassFile().getConstPool(); | ||
| 50 | ConstPoolEditor editor = new ConstPoolEditor(constants); | ||
| 51 | for (int i = 1; i < constants.getSize(); i++) { | ||
| 52 | switch (constants.getTag(i)) { | ||
| 53 | case ConstPool.CONST_Methodref: | ||
| 54 | case ConstPool.CONST_InterfaceMethodref: { | ||
| 55 | BehaviorEntry behaviorEntry = BehaviorEntryFactory.create(Descriptor.toJvmName(editor.getMemberrefClassname(i)), editor.getMemberrefName(i), editor.getMemberrefType(i)); | ||
| 56 | |||
| 57 | if (behaviorEntry instanceof MethodEntry) { | ||
| 58 | MethodEntry methodEntry = (MethodEntry)behaviorEntry; | ||
| 59 | |||
| 60 | // translate the name and type | ||
| 61 | MethodEntry bridgeMethodEntry = m_index.getBridgeMethod(methodEntry); | ||
| 62 | if (bridgeMethodEntry != null) { | ||
| 63 | // FIXIT FIXIT FIXIT FIXIT FIXIT FIXIT FIXIT | ||
| 64 | editor.changeMemberrefNameAndType(i, bridgeMethodEntry.getName(), bridgeMethodEntry.getSignature()); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | } | ||
| 68 | break; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | } | ||
| 72 | } | ||