From 5b35c2241ef6872bb76750b581f60d6060e40ee0 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 25 Aug 2014 00:05:18 -0400 Subject: silly mercurial. You should commit this file... --- src/cuchaz/enigma/analysis/BridgeFixer.java | 77 +++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/cuchaz/enigma/analysis/BridgeFixer.java (limited to 'src/cuchaz/enigma/analysis/BridgeFixer.java') diff --git a/src/cuchaz/enigma/analysis/BridgeFixer.java b/src/cuchaz/enigma/analysis/BridgeFixer.java new file mode 100644 index 0000000..aeaf871 --- /dev/null +++ b/src/cuchaz/enigma/analysis/BridgeFixer.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2014 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ +package cuchaz.enigma.analysis; + +import javassist.CtClass; +import javassist.CtMethod; +import javassist.bytecode.ConstPool; +import javassist.bytecode.Descriptor; +import cuchaz.enigma.bytecode.ConstPoolEditor; +import cuchaz.enigma.mapping.ClassEntry; +import cuchaz.enigma.mapping.MethodEntry; + +public class BridgeFixer +{ + private JarIndex m_index; + + public BridgeFixer( JarIndex index ) + { + m_index = index; + } + + public void fixBridges( CtClass c ) + { + // rename declared methods + for( CtMethod method : c.getDeclaredMethods() ) + { + // get the method entry + MethodEntry methodEntry = new MethodEntry( + new ClassEntry( Descriptor.toJvmName( c.getName() ) ), + method.getName(), + method.getSignature() + ); + MethodEntry bridgeMethodEntry = m_index.getBridgeMethod( methodEntry ); + if( bridgeMethodEntry != null ) + { + // fix this bridged method + method.setName( bridgeMethodEntry.getName() ); + } + } + + // rename method references + // translate all the field and method references in the code by editing the constant pool + ConstPool constants = c.getClassFile().getConstPool(); + ConstPoolEditor editor = new ConstPoolEditor( constants ); + for( int i=1; i