summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jeff2014-08-25 00:05:18 -0400
committerGravatar jeff2014-08-25 00:05:18 -0400
commit5b35c2241ef6872bb76750b581f60d6060e40ee0 (patch)
treeb1656b8602c1328ca6602540ce6ac5c734a23ff0
parentfixed issue with bridge methods so source export has fewer compile errors. =) (diff)
downloadenigma-5b35c2241ef6872bb76750b581f60d6060e40ee0.tar.gz
enigma-5b35c2241ef6872bb76750b581f60d6060e40ee0.tar.xz
enigma-5b35c2241ef6872bb76750b581f60d6060e40ee0.zip
silly mercurial. You should commit this file...
-rw-r--r--src/cuchaz/enigma/analysis/BridgeFixer.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/analysis/BridgeFixer.java b/src/cuchaz/enigma/analysis/BridgeFixer.java
new file mode 100644
index 00000000..aeaf871a
--- /dev/null
+++ b/src/cuchaz/enigma/analysis/BridgeFixer.java
@@ -0,0 +1,77 @@
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 ******************************************************************************/
11package cuchaz.enigma.analysis;
12
13import javassist.CtClass;
14import javassist.CtMethod;
15import javassist.bytecode.ConstPool;
16import javassist.bytecode.Descriptor;
17import cuchaz.enigma.bytecode.ConstPoolEditor;
18import cuchaz.enigma.mapping.ClassEntry;
19import cuchaz.enigma.mapping.MethodEntry;
20
21public class BridgeFixer
22{
23 private JarIndex m_index;
24
25 public BridgeFixer( JarIndex index )
26 {
27 m_index = index;
28 }
29
30 public void fixBridges( CtClass c )
31 {
32 // rename declared methods
33 for( CtMethod method : c.getDeclaredMethods() )
34 {
35 // get the method entry
36 MethodEntry methodEntry = new MethodEntry(
37 new ClassEntry( Descriptor.toJvmName( c.getName() ) ),
38 method.getName(),
39 method.getSignature()
40 );
41 MethodEntry bridgeMethodEntry = m_index.getBridgeMethod( methodEntry );
42 if( bridgeMethodEntry != null )
43 {
44 // fix this bridged method
45 method.setName( bridgeMethodEntry.getName() );
46 }
47 }
48
49 // rename method references
50 // translate all the field and method references in the code by editing the constant pool
51 ConstPool constants = c.getClassFile().getConstPool();
52 ConstPoolEditor editor = new ConstPoolEditor( constants );
53 for( int i=1; i<constants.getSize(); i++ )
54 {
55 switch( constants.getTag( i ) )
56 {
57 case ConstPool.CONST_Methodref:
58 case ConstPool.CONST_InterfaceMethodref:
59 {
60 // translate the name and type
61 MethodEntry methodEntry = new MethodEntry(
62 new ClassEntry( Descriptor.toJvmName( editor.getMemberrefClassname( i ) ) ),
63 editor.getMemberrefName( i ),
64 editor.getMemberrefType( i )
65 );
66 MethodEntry bridgeMethodEntry = m_index.getBridgeMethod( methodEntry );
67 if( bridgeMethodEntry != null )
68 {
69 // FIXIT FIXIT FIXIT FIXIT FIXIT FIXIT FIXIT
70 editor.changeMemberrefNameAndType( i, bridgeMethodEntry.getName(), bridgeMethodEntry.getSignature() );
71 }
72 }
73 break;
74 }
75 }
76 }
77}