summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/bytecode
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/bytecode')
-rw-r--r--src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java119
-rw-r--r--src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java7
-rw-r--r--src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java1
3 files changed, 3 insertions, 124 deletions
diff --git a/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java b/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java
deleted file mode 100644
index d15dd87..0000000
--- a/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java
+++ /dev/null
@@ -1,119 +0,0 @@
1/*******************************************************************************
2 * Copyright (c) 2015 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser General Public
5 * License v3.0 which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html
7 * <p>
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11package cuchaz.enigma.bytecode;
12
13import java.util.Iterator;
14
15import cuchaz.enigma.bytecode.CheckCastIterator.CheckCast;
16import cuchaz.enigma.mapping.ClassEntry;
17import cuchaz.enigma.mapping.MethodEntry;
18import cuchaz.enigma.mapping.Signature;
19import javassist.bytecode.*;
20
21@Deprecated
22// TODO: Find if this class can have any usage.
23public class CheckCastIterator implements Iterator<CheckCast> {
24
25 public static class CheckCast {
26
27 public String className;
28 public MethodEntry prevMethodEntry;
29
30 public CheckCast(String className, MethodEntry prevMethodEntry) {
31 this.className = className;
32 this.prevMethodEntry = prevMethodEntry;
33 }
34 }
35
36 private ConstPool constants;
37 private CodeAttribute attribute;
38 private CodeIterator iter;
39 private CheckCast next;
40
41 public CheckCastIterator(CodeAttribute codeAttribute) throws BadBytecode {
42 this.constants = codeAttribute.getConstPool();
43 this.attribute = codeAttribute;
44 this.iter = this.attribute.iterator();
45
46 this.next = getNext();
47 }
48
49 @Override
50 public boolean hasNext() {
51 return this.next != null;
52 }
53
54 @Override
55 public CheckCast next() {
56 CheckCast out = this.next;
57 try {
58 this.next = getNext();
59 } catch (BadBytecode ex) {
60 throw new Error(ex);
61 }
62 return out;
63 }
64
65 @Override
66 public void remove() {
67 throw new UnsupportedOperationException();
68 }
69
70 private CheckCast getNext() throws BadBytecode {
71 int prevPos = 0;
72 while (this.iter.hasNext()) {
73 int pos = this.iter.next();
74 int opcode = this.iter.byteAt(pos);
75 switch (opcode) {
76 case Opcode.CHECKCAST:
77
78 // get the type of this op code (next two bytes are a classinfo index)
79 MethodEntry prevMethodEntry = getMethodEntry(prevPos);
80 if (prevMethodEntry != null) {
81 return new CheckCast(this.constants.getClassInfo(this.iter.s16bitAt(pos + 1)), prevMethodEntry);
82 }
83 break;
84 }
85 prevPos = pos;
86 }
87 return null;
88 }
89
90 private MethodEntry getMethodEntry(int pos) {
91 switch (this.iter.byteAt(pos)) {
92 case Opcode.INVOKEVIRTUAL:
93 case Opcode.INVOKESTATIC:
94 case Opcode.INVOKEDYNAMIC:
95 case Opcode.INVOKESPECIAL: {
96 int index = this.iter.s16bitAt(pos + 1);
97 return new MethodEntry(
98 new ClassEntry(Descriptor.toJvmName(this.constants.getMethodrefClassName(index))),
99 this.constants.getMethodrefName(index),
100 new Signature(this.constants.getMethodrefType(index))
101 );
102 }
103
104 case Opcode.INVOKEINTERFACE: {
105 int index = this.iter.s16bitAt(pos + 1);
106 return new MethodEntry(
107 new ClassEntry(Descriptor.toJvmName(this.constants.getInterfaceMethodrefClassName(index))),
108 this.constants.getInterfaceMethodrefName(index),
109 new Signature(this.constants.getInterfaceMethodrefType(index))
110 );
111 }
112 }
113 return null;
114 }
115
116 public Iterable<CheckCast> casts() {
117 return () -> CheckCastIterator.this;
118 }
119}
diff --git a/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java b/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java
index d49f13a..d874633 100644
--- a/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java
+++ b/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java
@@ -52,10 +52,10 @@ public class ClassRenamer {
52 52
53 private static class ReplacerClassMap extends HashMap<String, String> { 53 private static class ReplacerClassMap extends HashMap<String, String> {
54 54
55 private ClassNameReplacer m_replacer; 55 private ClassNameReplacer replacer;
56 56
57 public ReplacerClassMap(ClassNameReplacer replacer) { 57 public ReplacerClassMap(ClassNameReplacer replacer) {
58 m_replacer = replacer; 58 this.replacer = replacer;
59 } 59 }
60 60
61 @Override 61 @Override
@@ -67,7 +67,7 @@ public class ClassRenamer {
67 } 67 }
68 68
69 public String get(String className) { 69 public String get(String className) {
70 return m_replacer.replace(className); 70 return replacer.replace(className);
71 } 71 }
72 } 72 }
73 73
@@ -146,7 +146,6 @@ public class ClassRenamer {
146 146
147 // rename the constant pool (covers ClassInfo, MethodTypeInfo, and NameAndTypeInfo) 147 // rename the constant pool (covers ClassInfo, MethodTypeInfo, and NameAndTypeInfo)
148 ConstPool constPool = c.getClassFile().getConstPool(); 148 ConstPool constPool = c.getClassFile().getConstPool();
149 String className = constPool.getClassName();
150 constPool.renameClass(map); 149 constPool.renameClass(map);
151 150
152 // rename class attributes 151 // rename class attributes
diff --git a/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java b/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java
index 6e2a29d..eb70c23 100644
--- a/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java
+++ b/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java
@@ -15,7 +15,6 @@ import com.google.common.collect.Lists;
15import java.util.Collection; 15import java.util.Collection;
16import java.util.List; 16import java.util.List;
17 17
18import cuchaz.enigma.Deobfuscator;
19import cuchaz.enigma.analysis.JarIndex; 18import cuchaz.enigma.analysis.JarIndex;
20import cuchaz.enigma.mapping.*; 19import cuchaz.enigma.mapping.*;
21import javassist.ClassPool; 20import javassist.ClassPool;