summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/analysis/BridgeFixer.java
diff options
context:
space:
mode:
authorGravatar jeff2014-08-25 00:04:47 -0400
committerGravatar jeff2014-08-25 00:04:47 -0400
commit2e97f24a658aa897313cb7cf92ed2e4b4a986bfc (patch)
treef5b97f28a913ecddf5c4902b331540b106a8b128 /src/cuchaz/enigma/analysis/BridgeFixer.java
parentminor bug fixes (diff)
downloadenigma-fork-2e97f24a658aa897313cb7cf92ed2e4b4a986bfc.tar.gz
enigma-fork-2e97f24a658aa897313cb7cf92ed2e4b4a986bfc.tar.xz
enigma-fork-2e97f24a658aa897313cb7cf92ed2e4b4a986bfc.zip
fixed issue with bridge methods so source export has fewer compile errors. =)
Diffstat (limited to 'src/cuchaz/enigma/analysis/BridgeFixer.java')
-rw-r--r--src/cuchaz/enigma/analysis/BridgeFixer.java92
1 files changed, 0 insertions, 92 deletions
diff --git a/src/cuchaz/enigma/analysis/BridgeFixer.java b/src/cuchaz/enigma/analysis/BridgeFixer.java
deleted file mode 100644
index f13f68f..0000000
--- a/src/cuchaz/enigma/analysis/BridgeFixer.java
+++ /dev/null
@@ -1,92 +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 ******************************************************************************/
11package cuchaz.enigma.analysis;
12
13import java.util.List;
14
15import javassist.CannotCompileException;
16import javassist.CtClass;
17import javassist.CtMethod;
18import javassist.NotFoundException;
19import javassist.bytecode.AccessFlag;
20import javassist.expr.ExprEditor;
21import javassist.expr.MethodCall;
22
23import com.beust.jcommander.internal.Lists;
24
25public class BridgeFixer
26{
27 public void fixBridges( CtClass c )
28 {
29 // bridge methods are scrubbed and marked as synthetic methods by the obfuscator
30 // need to figure out which synthetics are bridge methods and restore them
31 for( CtMethod method : c.getDeclaredMethods() )
32 {
33 // skip non-synthetic methods
34 if( ( method.getModifiers() & AccessFlag.SYNTHETIC ) == 0 )
35 {
36 continue;
37 }
38
39 CtMethod bridgedMethod = getBridgedMethod( method );
40 if( bridgedMethod != null )
41 {
42 bridgedMethod.setName( method.getName() );
43 method.setModifiers( method.getModifiers() | AccessFlag.BRIDGE );
44
45 // TODO: rename all references to this method?
46 }
47 }
48 }
49
50 private CtMethod getBridgedMethod( CtMethod method )
51 {
52 // bridge methods just call another method, cast it to the return type, and return the result
53 // let's see if we can detect this scenario
54
55 // get all the called methods
56 final List<MethodCall> methodCalls = Lists.newArrayList();
57 try
58 {
59 method.instrument( new ExprEditor( )
60 {
61 @Override
62 public void edit( MethodCall call )
63 {
64 methodCalls.add( call );
65 }
66 } );
67 }
68 catch( CannotCompileException ex )
69 {
70 // this is stupid... we're not even compiling anything
71 throw new Error( ex );
72 }
73
74 // is there just one?
75 if( methodCalls.size() != 1 )
76 {
77 return null;
78 }
79 MethodCall call = methodCalls.get( 0 );
80
81 try
82 {
83 // we have a bridge method!
84 return call.getMethod();
85 }
86 catch( NotFoundException ex )
87 {
88 // can't find the type? not a bridge method
89 return null;
90 }
91 }
92}