diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/bytecode')
17 files changed, 302 insertions, 302 deletions
diff --git a/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java b/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java index 8058d0e..19c39d3 100644 --- a/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java +++ b/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java | |||
| @@ -31,29 +31,29 @@ public class CheckCastIterator implements Iterator<CheckCast> { | |||
| 31 | } | 31 | } |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | private ConstPool m_constants; | 34 | private ConstPool constants; |
| 35 | private CodeAttribute m_attribute; | 35 | private CodeAttribute attribute; |
| 36 | private CodeIterator m_iter; | 36 | private CodeIterator iter; |
| 37 | private CheckCast m_next; | 37 | private CheckCast next; |
| 38 | 38 | ||
| 39 | public CheckCastIterator(CodeAttribute codeAttribute) throws BadBytecode { | 39 | public CheckCastIterator(CodeAttribute codeAttribute) throws BadBytecode { |
| 40 | m_constants = codeAttribute.getConstPool(); | 40 | this.constants = codeAttribute.getConstPool(); |
| 41 | m_attribute = codeAttribute; | 41 | this.attribute = codeAttribute; |
| 42 | m_iter = m_attribute.iterator(); | 42 | this.iter = this.attribute.iterator(); |
| 43 | 43 | ||
| 44 | m_next = getNext(); | 44 | this.next = getNext(); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | @Override | 47 | @Override |
| 48 | public boolean hasNext() { | 48 | public boolean hasNext() { |
| 49 | return m_next != null; | 49 | return this.next != null; |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | @Override | 52 | @Override |
| 53 | public CheckCast next() { | 53 | public CheckCast next() { |
| 54 | CheckCast out = m_next; | 54 | CheckCast out = this.next; |
| 55 | try { | 55 | try { |
| 56 | m_next = getNext(); | 56 | this.next = getNext(); |
| 57 | } catch (BadBytecode ex) { | 57 | } catch (BadBytecode ex) { |
| 58 | throw new Error(ex); | 58 | throw new Error(ex); |
| 59 | } | 59 | } |
| @@ -67,16 +67,16 @@ public class CheckCastIterator implements Iterator<CheckCast> { | |||
| 67 | 67 | ||
| 68 | private CheckCast getNext() throws BadBytecode { | 68 | private CheckCast getNext() throws BadBytecode { |
| 69 | int prevPos = 0; | 69 | int prevPos = 0; |
| 70 | while (m_iter.hasNext()) { | 70 | while (this.iter.hasNext()) { |
| 71 | int pos = m_iter.next(); | 71 | int pos = this.iter.next(); |
| 72 | int opcode = m_iter.byteAt(pos); | 72 | int opcode = this.iter.byteAt(pos); |
| 73 | switch (opcode) { | 73 | switch (opcode) { |
| 74 | case Opcode.CHECKCAST: | 74 | case Opcode.CHECKCAST: |
| 75 | 75 | ||
| 76 | // get the type of this op code (next two bytes are a classinfo index) | 76 | // get the type of this op code (next two bytes are a classinfo index) |
| 77 | MethodEntry prevMethodEntry = getMethodEntry(prevPos); | 77 | MethodEntry prevMethodEntry = getMethodEntry(prevPos); |
| 78 | if (prevMethodEntry != null) { | 78 | if (prevMethodEntry != null) { |
| 79 | return new CheckCast(m_constants.getClassInfo(m_iter.s16bitAt(pos + 1)), prevMethodEntry); | 79 | return new CheckCast(this.constants.getClassInfo(this.iter.s16bitAt(pos + 1)), prevMethodEntry); |
| 80 | } | 80 | } |
| 81 | break; | 81 | break; |
| 82 | } | 82 | } |
| @@ -86,25 +86,25 @@ public class CheckCastIterator implements Iterator<CheckCast> { | |||
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | private MethodEntry getMethodEntry(int pos) { | 88 | private MethodEntry getMethodEntry(int pos) { |
| 89 | switch (m_iter.byteAt(pos)) { | 89 | switch (this.iter.byteAt(pos)) { |
| 90 | case Opcode.INVOKEVIRTUAL: | 90 | case Opcode.INVOKEVIRTUAL: |
| 91 | case Opcode.INVOKESTATIC: | 91 | case Opcode.INVOKESTATIC: |
| 92 | case Opcode.INVOKEDYNAMIC: | 92 | case Opcode.INVOKEDYNAMIC: |
| 93 | case Opcode.INVOKESPECIAL: { | 93 | case Opcode.INVOKESPECIAL: { |
| 94 | int index = m_iter.s16bitAt(pos + 1); | 94 | int index = this.iter.s16bitAt(pos + 1); |
| 95 | return new MethodEntry( | 95 | return new MethodEntry( |
| 96 | new ClassEntry(Descriptor.toJvmName(m_constants.getMethodrefClassName(index))), | 96 | new ClassEntry(Descriptor.toJvmName(this.constants.getMethodrefClassName(index))), |
| 97 | m_constants.getMethodrefName(index), | 97 | this.constants.getMethodrefName(index), |
| 98 | new Signature(m_constants.getMethodrefType(index)) | 98 | new Signature(this.constants.getMethodrefType(index)) |
| 99 | ); | 99 | ); |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | case Opcode.INVOKEINTERFACE: { | 102 | case Opcode.INVOKEINTERFACE: { |
| 103 | int index = m_iter.s16bitAt(pos + 1); | 103 | int index = this.iter.s16bitAt(pos + 1); |
| 104 | return new MethodEntry( | 104 | return new MethodEntry( |
| 105 | new ClassEntry(Descriptor.toJvmName(m_constants.getInterfaceMethodrefClassName(index))), | 105 | new ClassEntry(Descriptor.toJvmName(this.constants.getInterfaceMethodrefClassName(index))), |
| 106 | m_constants.getInterfaceMethodrefName(index), | 106 | this.constants.getInterfaceMethodrefName(index), |
| 107 | new Signature(m_constants.getInterfaceMethodrefType(index)) | 107 | new Signature(this.constants.getInterfaceMethodrefType(index)) |
| 108 | ); | 108 | ); |
| 109 | } | 109 | } |
| 110 | } | 110 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java b/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java index 548bea7..d8e7971 100644 --- a/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java +++ b/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java | |||
| @@ -51,8 +51,6 @@ public class ClassRenamer { | |||
| 51 | 51 | ||
| 52 | private static class ReplacerClassMap extends HashMap<String, String> { | 52 | private static class ReplacerClassMap extends HashMap<String, String> { |
| 53 | 53 | ||
| 54 | private static final long serialVersionUID = 317915213205066168L; | ||
| 55 | |||
| 56 | private ClassNameReplacer m_replacer; | 54 | private ClassNameReplacer m_replacer; |
| 57 | 55 | ||
| 58 | public ReplacerClassMap(ClassNameReplacer replacer) { | 56 | public ReplacerClassMap(ClassNameReplacer replacer) { |
| @@ -151,7 +149,7 @@ public class ClassRenamer { | |||
| 151 | } | 149 | } |
| 152 | 150 | ||
| 153 | /* DEBUG | 151 | /* DEBUG |
| 154 | System.out.println(String.format("\tDEOBF: %s-> ATTR: %s,%s,%s", classEntry, attr.outerClass(i), attr.innerClass(i), attr.innerName(i))); | 152 | System.out.println(String.format("\tDEOBF: %s-> ATTR: %s,%s,%s", classEntry, attr.outerClass(i), attr.innerClass(i), attr.innerName(i))); |
| 155 | */ | 153 | */ |
| 156 | } | 154 | } |
| 157 | } | 155 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/ClassTranslator.java b/src/main/java/cuchaz/enigma/bytecode/ClassTranslator.java index ef197cb..8fdd851 100644 --- a/src/main/java/cuchaz/enigma/bytecode/ClassTranslator.java +++ b/src/main/java/cuchaz/enigma/bytecode/ClassTranslator.java | |||
| @@ -22,10 +22,10 @@ import javassist.bytecode.SourceFileAttribute; | |||
| 22 | 22 | ||
| 23 | public class ClassTranslator { | 23 | public class ClassTranslator { |
| 24 | 24 | ||
| 25 | private Translator m_translator; | 25 | private Translator translator; |
| 26 | 26 | ||
| 27 | public ClassTranslator(Translator translator) { | 27 | public ClassTranslator(Translator translator) { |
| 28 | m_translator = translator; | 28 | this.translator = translator; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | public void translate(CtClass c) { | 31 | public void translate(CtClass c) { |
| @@ -46,7 +46,7 @@ public class ClassTranslator { | |||
| 46 | constants.getFieldrefName(i), | 46 | constants.getFieldrefName(i), |
| 47 | constants.getFieldrefType(i) | 47 | constants.getFieldrefType(i) |
| 48 | ); | 48 | ); |
| 49 | FieldEntry translatedEntry = m_translator.translateEntry(entry); | 49 | FieldEntry translatedEntry = this.translator.translateEntry(entry); |
| 50 | if (!entry.equals(translatedEntry)) { | 50 | if (!entry.equals(translatedEntry)) { |
| 51 | editor.changeMemberrefNameAndType(i, translatedEntry.getName(), translatedEntry.getType().toString()); | 51 | editor.changeMemberrefNameAndType(i, translatedEntry.getName(), translatedEntry.getType().toString()); |
| 52 | } | 52 | } |
| @@ -62,7 +62,7 @@ public class ClassTranslator { | |||
| 62 | editor.getMemberrefName(i), | 62 | editor.getMemberrefName(i), |
| 63 | editor.getMemberrefType(i) | 63 | editor.getMemberrefType(i) |
| 64 | ); | 64 | ); |
| 65 | BehaviorEntry translatedEntry = m_translator.translateEntry(entry); | 65 | BehaviorEntry translatedEntry = this.translator.translateEntry(entry); |
| 66 | if (!entry.equals(translatedEntry)) { | 66 | if (!entry.equals(translatedEntry)) { |
| 67 | editor.changeMemberrefNameAndType(i, translatedEntry.getName(), translatedEntry.getSignature().toString()); | 67 | editor.changeMemberrefNameAndType(i, translatedEntry.getName(), translatedEntry.getSignature().toString()); |
| 68 | } | 68 | } |
| @@ -78,13 +78,13 @@ public class ClassTranslator { | |||
| 78 | 78 | ||
| 79 | // translate the name | 79 | // translate the name |
| 80 | FieldEntry entry = EntryFactory.getFieldEntry(field); | 80 | FieldEntry entry = EntryFactory.getFieldEntry(field); |
| 81 | String translatedName = m_translator.translate(entry); | 81 | String translatedName = this.translator.translate(entry); |
| 82 | if (translatedName != null) { | 82 | if (translatedName != null) { |
| 83 | field.setName(translatedName); | 83 | field.setName(translatedName); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | // translate the type | 86 | // translate the type |
| 87 | Type translatedType = m_translator.translateType(entry.getType()); | 87 | Type translatedType = this.translator.translateType(entry.getType()); |
| 88 | field.getFieldInfo().setDescriptor(translatedType.toString()); | 88 | field.getFieldInfo().setDescriptor(translatedType.toString()); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| @@ -97,7 +97,7 @@ public class ClassTranslator { | |||
| 97 | CtMethod method = (CtMethod) behavior; | 97 | CtMethod method = (CtMethod) behavior; |
| 98 | 98 | ||
| 99 | // translate the name | 99 | // translate the name |
| 100 | String translatedName = m_translator.translate(entry); | 100 | String translatedName = this.translator.translate(entry); |
| 101 | if (translatedName != null) { | 101 | if (translatedName != null) { |
| 102 | method.setName(translatedName); | 102 | method.setName(translatedName); |
| 103 | } | 103 | } |
| @@ -105,7 +105,7 @@ public class ClassTranslator { | |||
| 105 | 105 | ||
| 106 | if (entry.getSignature() != null) { | 106 | if (entry.getSignature() != null) { |
| 107 | // translate the signature | 107 | // translate the signature |
| 108 | Signature translatedSignature = m_translator.translateSignature(entry.getSignature()); | 108 | Signature translatedSignature = this.translator.translateSignature(entry.getSignature()); |
| 109 | behavior.getMethodInfo().setDescriptor(translatedSignature.toString()); | 109 | behavior.getMethodInfo().setDescriptor(translatedSignature.toString()); |
| 110 | } | 110 | } |
| 111 | } | 111 | } |
| @@ -116,7 +116,7 @@ public class ClassTranslator { | |||
| 116 | 116 | ||
| 117 | if (enclosingMethodAttr.methodIndex() == 0) { | 117 | if (enclosingMethodAttr.methodIndex() == 0) { |
| 118 | BehaviorEntry obfBehaviorEntry = EntryFactory.getBehaviorEntry(Descriptor.toJvmName(enclosingMethodAttr.className())); | 118 | BehaviorEntry obfBehaviorEntry = EntryFactory.getBehaviorEntry(Descriptor.toJvmName(enclosingMethodAttr.className())); |
| 119 | BehaviorEntry deobfBehaviorEntry = m_translator.translateEntry(obfBehaviorEntry); | 119 | BehaviorEntry deobfBehaviorEntry = this.translator.translateEntry(obfBehaviorEntry); |
| 120 | c.getClassFile().addAttribute(new EnclosingMethodAttribute( | 120 | c.getClassFile().addAttribute(new EnclosingMethodAttribute( |
| 121 | constants, | 121 | constants, |
| 122 | deobfBehaviorEntry.getClassName() | 122 | deobfBehaviorEntry.getClassName() |
| @@ -127,7 +127,7 @@ public class ClassTranslator { | |||
| 127 | enclosingMethodAttr.methodName(), | 127 | enclosingMethodAttr.methodName(), |
| 128 | enclosingMethodAttr.methodDescriptor() | 128 | enclosingMethodAttr.methodDescriptor() |
| 129 | ); | 129 | ); |
| 130 | BehaviorEntry deobfBehaviorEntry = m_translator.translateEntry(obfBehaviorEntry); | 130 | BehaviorEntry deobfBehaviorEntry = this.translator.translateEntry(obfBehaviorEntry); |
| 131 | c.getClassFile().addAttribute(new EnclosingMethodAttribute( | 131 | c.getClassFile().addAttribute(new EnclosingMethodAttribute( |
| 132 | constants, | 132 | constants, |
| 133 | deobfBehaviorEntry.getClassName(), | 133 | deobfBehaviorEntry.getClassName(), |
| @@ -139,10 +139,10 @@ public class ClassTranslator { | |||
| 139 | 139 | ||
| 140 | // translate all the class names referenced in the code | 140 | // translate all the class names referenced in the code |
| 141 | // the above code only changed method/field/reference names and types, but not the rest of the class references | 141 | // the above code only changed method/field/reference names and types, but not the rest of the class references |
| 142 | ClassRenamer.renameClasses(c, m_translator); | 142 | ClassRenamer.renameClasses(c, this.translator); |
| 143 | 143 | ||
| 144 | // translate the source file attribute too | 144 | // translate the source file attribute too |
| 145 | ClassEntry deobfClassEntry = m_translator.translateEntry(classEntry); | 145 | ClassEntry deobfClassEntry = this.translator.translateEntry(classEntry); |
| 146 | if (deobfClassEntry != null) { | 146 | if (deobfClassEntry != null) { |
| 147 | String sourceFile = Descriptor.toJvmName(deobfClassEntry.getOutermostClassEntry().getSimpleName()) + ".java"; | 147 | String sourceFile = Descriptor.toJvmName(deobfClassEntry.getOutermostClassEntry().getSimpleName()) + ".java"; |
| 148 | c.getClassFile().addAttribute(new SourceFileAttribute(constants, sourceFile)); | 148 | c.getClassFile().addAttribute(new SourceFileAttribute(constants, sourceFile)); |
diff --git a/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java b/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java index 0082a72..256df61 100644 --- a/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java +++ b/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java | |||
| @@ -25,62 +25,62 @@ import javassist.bytecode.Descriptor; | |||
| 25 | 25 | ||
| 26 | public class ConstPoolEditor { | 26 | public class ConstPoolEditor { |
| 27 | 27 | ||
| 28 | private static Method m_getItem; | 28 | private static Method getItem; |
| 29 | private static Method m_addItem; | 29 | private static Method addItem; |
| 30 | private static Method m_addItem0; | 30 | private static Method addItem0; |
| 31 | private static Field m_items; | 31 | private static Field items; |
| 32 | private static Field m_cache; | 32 | private static Field cache; |
| 33 | private static Field m_numItems; | 33 | private static Field numItems; |
| 34 | private static Field m_objects; | 34 | private static Field objects; |
| 35 | private static Field m_elements; | 35 | private static Field elements; |
| 36 | private static Method m_methodWritePool; | 36 | private static Method methodWritePool; |
| 37 | private static Constructor<ConstPool> m_constructorPool; | 37 | private static Constructor<ConstPool> constructorPool; |
| 38 | 38 | ||
| 39 | static { | 39 | static { |
| 40 | try { | 40 | try { |
| 41 | m_getItem = ConstPool.class.getDeclaredMethod("getItem", int.class); | 41 | getItem = ConstPool.class.getDeclaredMethod("getItem", int.class); |
| 42 | m_getItem.setAccessible(true); | 42 | getItem.setAccessible(true); |
| 43 | 43 | ||
| 44 | m_addItem = ConstPool.class.getDeclaredMethod("addItem", Class.forName("javassist.bytecode.ConstInfo")); | 44 | addItem = ConstPool.class.getDeclaredMethod("addItem", Class.forName("javassist.bytecode.ConstInfo")); |
| 45 | m_addItem.setAccessible(true); | 45 | addItem.setAccessible(true); |
| 46 | 46 | ||
| 47 | m_addItem0 = ConstPool.class.getDeclaredMethod("addItem0", Class.forName("javassist.bytecode.ConstInfo")); | 47 | addItem0 = ConstPool.class.getDeclaredMethod("addItem0", Class.forName("javassist.bytecode.ConstInfo")); |
| 48 | m_addItem0.setAccessible(true); | 48 | addItem0.setAccessible(true); |
| 49 | 49 | ||
| 50 | m_items = ConstPool.class.getDeclaredField("items"); | 50 | items = ConstPool.class.getDeclaredField("items"); |
| 51 | m_items.setAccessible(true); | 51 | items.setAccessible(true); |
| 52 | 52 | ||
| 53 | m_cache = ConstPool.class.getDeclaredField("itemsCache"); | 53 | cache = ConstPool.class.getDeclaredField("itemsCache"); |
| 54 | m_cache.setAccessible(true); | 54 | cache.setAccessible(true); |
| 55 | 55 | ||
| 56 | m_numItems = ConstPool.class.getDeclaredField("numOfItems"); | 56 | numItems = ConstPool.class.getDeclaredField("numOfItems"); |
| 57 | m_numItems.setAccessible(true); | 57 | numItems.setAccessible(true); |
| 58 | 58 | ||
| 59 | m_objects = Class.forName("javassist.bytecode.LongVector").getDeclaredField("objects"); | 59 | objects = Class.forName("javassist.bytecode.LongVector").getDeclaredField("objects"); |
| 60 | m_objects.setAccessible(true); | 60 | objects.setAccessible(true); |
| 61 | 61 | ||
| 62 | m_elements = Class.forName("javassist.bytecode.LongVector").getDeclaredField("elements"); | 62 | elements = Class.forName("javassist.bytecode.LongVector").getDeclaredField("elements"); |
| 63 | m_elements.setAccessible(true); | 63 | elements.setAccessible(true); |
| 64 | 64 | ||
| 65 | m_methodWritePool = ConstPool.class.getDeclaredMethod("write", DataOutputStream.class); | 65 | methodWritePool = ConstPool.class.getDeclaredMethod("write", DataOutputStream.class); |
| 66 | m_methodWritePool.setAccessible(true); | 66 | methodWritePool.setAccessible(true); |
| 67 | 67 | ||
| 68 | m_constructorPool = ConstPool.class.getDeclaredConstructor(DataInputStream.class); | 68 | constructorPool = ConstPool.class.getDeclaredConstructor(DataInputStream.class); |
| 69 | m_constructorPool.setAccessible(true); | 69 | constructorPool.setAccessible(true); |
| 70 | } catch (Exception ex) { | 70 | } catch (Exception ex) { |
| 71 | throw new Error(ex); | 71 | throw new Error(ex); |
| 72 | } | 72 | } |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | private ConstPool m_pool; | 75 | private ConstPool pool; |
| 76 | 76 | ||
| 77 | public ConstPoolEditor(ConstPool pool) { | 77 | public ConstPoolEditor(ConstPool pool) { |
| 78 | m_pool = pool; | 78 | this.pool = pool; |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | public void writePool(DataOutputStream out) { | 81 | public void writePool(DataOutputStream out) { |
| 82 | try { | 82 | try { |
| 83 | m_methodWritePool.invoke(m_pool, out); | 83 | methodWritePool.invoke(this.pool, out); |
| 84 | } catch (Exception ex) { | 84 | } catch (Exception ex) { |
| 85 | throw new Error(ex); | 85 | throw new Error(ex); |
| 86 | } | 86 | } |
| @@ -88,27 +88,27 @@ public class ConstPoolEditor { | |||
| 88 | 88 | ||
| 89 | public static ConstPool readPool(DataInputStream in) { | 89 | public static ConstPool readPool(DataInputStream in) { |
| 90 | try { | 90 | try { |
| 91 | return m_constructorPool.newInstance(in); | 91 | return constructorPool.newInstance(in); |
| 92 | } catch (Exception ex) { | 92 | } catch (Exception ex) { |
| 93 | throw new Error(ex); | 93 | throw new Error(ex); |
| 94 | } | 94 | } |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | public String getMemberrefClassname(int memberrefIndex) { | 97 | public String getMemberrefClassname(int memberrefIndex) { |
| 98 | return Descriptor.toJvmName(m_pool.getClassInfo(m_pool.getMemberClass(memberrefIndex))); | 98 | return Descriptor.toJvmName(this.pool.getClassInfo(this.pool.getMemberClass(memberrefIndex))); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | public String getMemberrefName(int memberrefIndex) { | 101 | public String getMemberrefName(int memberrefIndex) { |
| 102 | return m_pool.getUtf8Info(m_pool.getNameAndTypeName(m_pool.getMemberNameAndType(memberrefIndex))); | 102 | return this.pool.getUtf8Info(this.pool.getNameAndTypeName(this.pool.getMemberNameAndType(memberrefIndex))); |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | public String getMemberrefType(int memberrefIndex) { | 105 | public String getMemberrefType(int memberrefIndex) { |
| 106 | return m_pool.getUtf8Info(m_pool.getNameAndTypeDescriptor(m_pool.getMemberNameAndType(memberrefIndex))); | 106 | return this.pool.getUtf8Info(this.pool.getNameAndTypeDescriptor(this.pool.getMemberNameAndType(memberrefIndex))); |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | public ConstInfoAccessor getItem(int index) { | 109 | public ConstInfoAccessor getItem(int index) { |
| 110 | try { | 110 | try { |
| 111 | Object entry = m_getItem.invoke(m_pool, index); | 111 | Object entry = getItem.invoke(this.pool, index); |
| 112 | if (entry == null) { | 112 | if (entry == null) { |
| 113 | return null; | 113 | return null; |
| 114 | } | 114 | } |
| @@ -120,7 +120,7 @@ public class ConstPoolEditor { | |||
| 120 | 120 | ||
| 121 | public int addItem(Object item) { | 121 | public int addItem(Object item) { |
| 122 | try { | 122 | try { |
| 123 | return (Integer) m_addItem.invoke(m_pool, item); | 123 | return (Integer) addItem.invoke(this.pool, item); |
| 124 | } catch (Exception ex) { | 124 | } catch (Exception ex) { |
| 125 | throw new Error(ex); | 125 | throw new Error(ex); |
| 126 | } | 126 | } |
| @@ -128,7 +128,7 @@ public class ConstPoolEditor { | |||
| 128 | 128 | ||
| 129 | public int addItemForceNew(Object item) { | 129 | public int addItemForceNew(Object item) { |
| 130 | try { | 130 | try { |
| 131 | return (Integer) m_addItem0.invoke(m_pool, item); | 131 | return (Integer) addItem0.invoke(this.pool, item); |
| 132 | } catch (Exception ex) { | 132 | } catch (Exception ex) { |
| 133 | throw new Error(ex); | 133 | throw new Error(ex); |
| 134 | } | 134 | } |
| @@ -140,22 +140,22 @@ public class ConstPoolEditor { | |||
| 140 | // remove the item from the cache | 140 | // remove the item from the cache |
| 141 | HashMap cache = getCache(); | 141 | HashMap cache = getCache(); |
| 142 | if (cache != null) { | 142 | if (cache != null) { |
| 143 | Object item = getItem(m_pool.getSize() - 1); | 143 | Object item = getItem(this.pool.getSize() - 1); |
| 144 | cache.remove(item); | 144 | cache.remove(item); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | // remove the actual item | 147 | // remove the actual item |
| 148 | // based off of LongVector.addElement() | 148 | // based off of LongVector.addElement() |
| 149 | Object items = m_items.get(m_pool); | 149 | Object item = items.get(this.pool); |
| 150 | Object[][] objects = (Object[][]) m_objects.get(items); | 150 | Object[][] object = (Object[][]) objects.get(items); |
| 151 | int numElements = (Integer) m_elements.get(items) - 1; | 151 | int numElements = (Integer) elements.get(items) - 1; |
| 152 | int nth = numElements >> 7; | 152 | int nth = numElements >> 7; |
| 153 | int offset = numElements & (128 - 1); | 153 | int offset = numElements & (128 - 1); |
| 154 | objects[nth][offset] = null; | 154 | object[nth][offset] = null; |
| 155 | 155 | ||
| 156 | // decrement the number of items | 156 | // decrement the number of items |
| 157 | m_elements.set(items, numElements); | 157 | elements.set(item, numElements); |
| 158 | m_numItems.set(m_pool, (Integer) m_numItems.get(m_pool) - 1); | 158 | numItems.set(this.pool, (Integer) numItems.get(this.pool) - 1); |
| 159 | } catch (Exception ex) { | 159 | } catch (Exception ex) { |
| 160 | throw new Error(ex); | 160 | throw new Error(ex); |
| 161 | } | 161 | } |
| @@ -164,7 +164,7 @@ public class ConstPoolEditor { | |||
| 164 | @SuppressWarnings("rawtypes") | 164 | @SuppressWarnings("rawtypes") |
| 165 | public HashMap getCache() { | 165 | public HashMap getCache() { |
| 166 | try { | 166 | try { |
| 167 | return (HashMap) m_cache.get(m_pool); | 167 | return (HashMap) cache.get(this.pool); |
| 168 | } catch (Exception ex) { | 168 | } catch (Exception ex) { |
| 169 | throw new Error(ex); | 169 | throw new Error(ex); |
| 170 | } | 170 | } |
| @@ -183,7 +183,7 @@ public class ConstPoolEditor { | |||
| 183 | cache.remove(item); | 183 | cache.remove(item); |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | new MemberRefInfoAccessor(item).setNameAndTypeIndex(m_pool.addNameAndTypeInfo(newName, newType)); | 186 | new MemberRefInfoAccessor(item).setNameAndTypeIndex(this.pool.addNameAndTypeInfo(newName, newType)); |
| 187 | 187 | ||
| 188 | // update the cache | 188 | // update the cache |
| 189 | if (cache != null) { | 189 | if (cache != null) { |
| @@ -212,7 +212,7 @@ public class ConstPoolEditor { | |||
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | // add the new name and repoint the name-and-type to it | 214 | // add the new name and repoint the name-and-type to it |
| 215 | new ClassInfoAccessor(item).setNameIndex(m_pool.addUtf8Info(newName)); | 215 | new ClassInfoAccessor(item).setNameIndex(this.pool.addUtf8Info(newName)); |
| 216 | 216 | ||
| 217 | // update the cache | 217 | // update the cache |
| 218 | if (cache != null) { | 218 | if (cache != null) { |
| @@ -252,7 +252,7 @@ public class ConstPoolEditor { | |||
| 252 | 252 | ||
| 253 | public String dump() { | 253 | public String dump() { |
| 254 | StringBuilder buf = new StringBuilder(); | 254 | StringBuilder buf = new StringBuilder(); |
| 255 | for (int i = 1; i < m_pool.getSize(); i++) { | 255 | for (int i = 1; i < this.pool.getSize(); i++) { |
| 256 | buf.append(String.format("%4d", i)); | 256 | buf.append(String.format("%4d", i)); |
| 257 | buf.append(" "); | 257 | buf.append(" "); |
| 258 | buf.append(getItem(i).toString()); | 258 | buf.append(getItem(i).toString()); |
diff --git a/src/main/java/cuchaz/enigma/bytecode/InfoType.java b/src/main/java/cuchaz/enigma/bytecode/InfoType.java index 89940d9..86e57ab 100644 --- a/src/main/java/cuchaz/enigma/bytecode/InfoType.java +++ b/src/main/java/cuchaz/enigma/bytecode/InfoType.java | |||
| @@ -213,29 +213,29 @@ public enum InfoType { | |||
| 213 | } | 213 | } |
| 214 | }; | 214 | }; |
| 215 | 215 | ||
| 216 | private static Map<Integer, InfoType> m_types; | 216 | private static Map<Integer, InfoType> types; |
| 217 | 217 | ||
| 218 | static { | 218 | static { |
| 219 | m_types = Maps.newTreeMap(); | 219 | types = Maps.newTreeMap(); |
| 220 | for (InfoType type : values()) { | 220 | for (InfoType type : values()) { |
| 221 | m_types.put(type.getTag(), type); | 221 | types.put(type.getTag(), type); |
| 222 | } | 222 | } |
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | private int m_tag; | 225 | private int tag; |
| 226 | private int m_level; | 226 | private int level; |
| 227 | 227 | ||
| 228 | InfoType(int tag, int level) { | 228 | InfoType(int tag, int level) { |
| 229 | m_tag = tag; | 229 | this.tag = tag; |
| 230 | m_level = level; | 230 | this.level = level; |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | public int getTag() { | 233 | public int getTag() { |
| 234 | return m_tag; | 234 | return this.tag; |
| 235 | } | 235 | } |
| 236 | 236 | ||
| 237 | public int getLevel() { | 237 | public int getLevel() { |
| 238 | return m_level; | 238 | return this.level; |
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | public void gatherIndexTree(Collection<Integer> indices, ConstPoolEditor editor, ConstInfoAccessor entry) { | 241 | public void gatherIndexTree(Collection<Integer> indices, ConstPoolEditor editor, ConstInfoAccessor entry) { |
| @@ -260,7 +260,7 @@ public enum InfoType { | |||
| 260 | } | 260 | } |
| 261 | 261 | ||
| 262 | public static InfoType getByTag(int tag) { | 262 | public static InfoType getByTag(int tag) { |
| 263 | return m_types.get(tag); | 263 | return types.get(tag); |
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | public static List<InfoType> getByLevel(int level) { | 266 | public static List<InfoType> getByLevel(int level) { |
diff --git a/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java b/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java index 25ac7d6..6d92610 100644 --- a/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java +++ b/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java | |||
| @@ -27,10 +27,10 @@ import javassist.bytecode.InnerClassesAttribute; | |||
| 27 | 27 | ||
| 28 | public class InnerClassWriter { | 28 | public class InnerClassWriter { |
| 29 | 29 | ||
| 30 | private JarIndex m_index; | 30 | private JarIndex index; |
| 31 | 31 | ||
| 32 | public InnerClassWriter(JarIndex index) { | 32 | public InnerClassWriter(JarIndex index) { |
| 33 | m_index = index; | 33 | this.index = index; |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | public void write(CtClass c) { | 36 | public void write(CtClass c) { |
| @@ -43,7 +43,7 @@ public class InnerClassWriter { | |||
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | ClassEntry obfClassEntry = EntryFactory.getClassEntry(c); | 45 | ClassEntry obfClassEntry = EntryFactory.getClassEntry(c); |
| 46 | List<ClassEntry> obfClassChain = m_index.getObfClassChain(obfClassEntry); | 46 | List<ClassEntry> obfClassChain = this.index.getObfClassChain(obfClassEntry); |
| 47 | 47 | ||
| 48 | boolean isInnerClass = obfClassChain.size() > 1; | 48 | boolean isInnerClass = obfClassChain.size() > 1; |
| 49 | if (isInnerClass) { | 49 | if (isInnerClass) { |
| @@ -51,7 +51,7 @@ public class InnerClassWriter { | |||
| 51 | // it's an inner class, rename it to the fully qualified name | 51 | // it's an inner class, rename it to the fully qualified name |
| 52 | c.setName(obfClassEntry.buildClassEntry(obfClassChain).getName()); | 52 | c.setName(obfClassEntry.buildClassEntry(obfClassChain).getName()); |
| 53 | 53 | ||
| 54 | BehaviorEntry caller = m_index.getAnonymousClassCaller(obfClassEntry); | 54 | BehaviorEntry caller = this.index.getAnonymousClassCaller(obfClassEntry); |
| 55 | if (caller != null) { | 55 | if (caller != null) { |
| 56 | 56 | ||
| 57 | // write the enclosing method attribute | 57 | // write the enclosing method attribute |
| @@ -64,7 +64,7 @@ public class InnerClassWriter { | |||
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | // does this class have any inner classes? | 66 | // does this class have any inner classes? |
| 67 | Collection<ClassEntry> obfInnerClassEntries = m_index.getInnerClasses(obfClassEntry); | 67 | Collection<ClassEntry> obfInnerClassEntries = this.index.getInnerClasses(obfClassEntry); |
| 68 | 68 | ||
| 69 | if (isInnerClass || !obfInnerClassEntries.isEmpty()) { | 69 | if (isInnerClass || !obfInnerClassEntries.isEmpty()) { |
| 70 | 70 | ||
| @@ -112,14 +112,14 @@ public class InnerClassWriter { | |||
| 112 | int innerClassNameIndex = 0; | 112 | int innerClassNameIndex = 0; |
| 113 | int accessFlags = AccessFlag.PUBLIC; | 113 | int accessFlags = AccessFlag.PUBLIC; |
| 114 | // TODO: need to figure out if we can put static or not | 114 | // TODO: need to figure out if we can put static or not |
| 115 | if (!m_index.isAnonymousClass(obfClassEntry)) { | 115 | if (!this.index.isAnonymousClass(obfClassEntry)) { |
| 116 | innerClassNameIndex = constPool.addUtf8Info(obfInnerClassEntry.getInnermostClassName()); | 116 | innerClassNameIndex = constPool.addUtf8Info(obfInnerClassEntry.getInnermostClassName()); |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | attr.append(innerClassIndex, parentClassIndex, innerClassNameIndex, accessFlags); | 119 | attr.append(innerClassIndex, parentClassIndex, innerClassNameIndex, accessFlags); |
| 120 | 120 | ||
| 121 | /* DEBUG | 121 | /* DEBUG |
| 122 | System.out.println(String.format("\tOBF: %s -> ATTR: %s,%s,%s (replace %s with %s)", | 122 | System.out.println(String.format("\tOBF: %s -> ATTR: %s,%s,%s (replace %s with %s)", |
| 123 | obfClassEntry, | 123 | obfClassEntry, |
| 124 | attr.innerClass(attr.tableLength() - 1), | 124 | attr.innerClass(attr.tableLength() - 1), |
| 125 | attr.outerClass(attr.tableLength() - 1), | 125 | attr.outerClass(attr.tableLength() - 1), |
diff --git a/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java b/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java index d0ce107..8edea16 100644 --- a/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java +++ b/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java | |||
| @@ -21,10 +21,10 @@ import javassist.bytecode.*; | |||
| 21 | 21 | ||
| 22 | public class LocalVariableRenamer { | 22 | public class LocalVariableRenamer { |
| 23 | 23 | ||
| 24 | private Translator m_translator; | 24 | private Translator translator; |
| 25 | 25 | ||
| 26 | public LocalVariableRenamer(Translator translator) { | 26 | public LocalVariableRenamer(Translator translator) { |
| 27 | m_translator = translator; | 27 | this.translator = translator; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | public void rename(CtClass c) { | 30 | public void rename(CtClass c) { |
| @@ -81,7 +81,7 @@ public class LocalVariableRenamer { | |||
| 81 | numArgs = behaviorEntry.getSignature().getArgumentTypes().size(); | 81 | numArgs = behaviorEntry.getSignature().getArgumentTypes().size(); |
| 82 | for (int i = starti; i < starti + numArgs && i < table.tableLength(); i++) { | 82 | for (int i = starti; i < starti + numArgs && i < table.tableLength(); i++) { |
| 83 | int argi = i - starti; | 83 | int argi = i - starti; |
| 84 | String argName = m_translator.translate(new ArgumentEntry(behaviorEntry, argi, "")); | 84 | String argName = this.translator.translate(new ArgumentEntry(behaviorEntry, argi, "")); |
| 85 | if (argName == null) { | 85 | if (argName == null) { |
| 86 | argName = "a" + (argi + 1); | 86 | argName = "a" + (argi + 1); |
| 87 | } | 87 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java b/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java index e53e8e7..17ecbbe 100644 --- a/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java +++ b/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java | |||
| @@ -21,10 +21,10 @@ import javassist.bytecode.LocalVariableAttribute; | |||
| 21 | 21 | ||
| 22 | public class MethodParameterWriter { | 22 | public class MethodParameterWriter { |
| 23 | 23 | ||
| 24 | private Translator m_translator; | 24 | private Translator translator; |
| 25 | 25 | ||
| 26 | public MethodParameterWriter(Translator translator) { | 26 | public MethodParameterWriter(Translator translator) { |
| 27 | m_translator = translator; | 27 | this.translator = translator; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | public void writeMethodArguments(CtClass c) { | 30 | public void writeMethodArguments(CtClass c) { |
| @@ -56,7 +56,7 @@ public class MethodParameterWriter { | |||
| 56 | // get the list of argument names | 56 | // get the list of argument names |
| 57 | List<String> names = new ArrayList<String>(numParams); | 57 | List<String> names = new ArrayList<String>(numParams); |
| 58 | for (int i = 0; i < numParams; i++) { | 58 | for (int i = 0; i < numParams; i++) { |
| 59 | names.add(m_translator.translate(new ArgumentEntry(behaviorEntry, i, ""))); | 59 | names.add(this.translator.translate(new ArgumentEntry(behaviorEntry, i, ""))); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | // save the mappings to the class | 62 | // save the mappings to the class |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java index fd987f5..66f2283 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java | |||
| @@ -14,32 +14,18 @@ import java.lang.reflect.Field; | |||
| 14 | 14 | ||
| 15 | public class ClassInfoAccessor { | 15 | public class ClassInfoAccessor { |
| 16 | 16 | ||
| 17 | private static Class<?> m_class; | 17 | private Object item; |
| 18 | private static Field m_nameIndex; | ||
| 19 | 18 | ||
| 20 | static { | 19 | private static Class<?> clazz; |
| 21 | try { | 20 | private static Field nameIndex; |
| 22 | m_class = Class.forName("javassist.bytecode.ClassInfo"); | ||
| 23 | m_nameIndex = m_class.getDeclaredField("name"); | ||
| 24 | m_nameIndex.setAccessible(true); | ||
| 25 | } catch (Exception ex) { | ||
| 26 | throw new Error(ex); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 31 | return m_class.isAssignableFrom(accessor.getItem().getClass()); | ||
| 32 | } | ||
| 33 | |||
| 34 | private Object m_item; | ||
| 35 | 21 | ||
| 36 | public ClassInfoAccessor(Object item) { | 22 | public ClassInfoAccessor(Object item) { |
| 37 | m_item = item; | 23 | this.item = item; |
| 38 | } | 24 | } |
| 39 | 25 | ||
| 40 | public int getNameIndex() { | 26 | public int getNameIndex() { |
| 41 | try { | 27 | try { |
| 42 | return (Integer) m_nameIndex.get(m_item); | 28 | return (Integer) nameIndex.get(this.item); |
| 43 | } catch (Exception ex) { | 29 | } catch (Exception ex) { |
| 44 | throw new Error(ex); | 30 | throw new Error(ex); |
| 45 | } | 31 | } |
| @@ -47,7 +33,21 @@ public class ClassInfoAccessor { | |||
| 47 | 33 | ||
| 48 | public void setNameIndex(int val) { | 34 | public void setNameIndex(int val) { |
| 49 | try { | 35 | try { |
| 50 | m_nameIndex.set(m_item, val); | 36 | nameIndex.set(this.item, val); |
| 37 | } catch (Exception ex) { | ||
| 38 | throw new Error(ex); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 43 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 44 | } | ||
| 45 | |||
| 46 | static { | ||
| 47 | try { | ||
| 48 | clazz = Class.forName("javassist.bytecode.ClassInfo"); | ||
| 49 | nameIndex = clazz.getDeclaredField("name"); | ||
| 50 | nameIndex.setAccessible(true); | ||
| 51 | } catch (Exception ex) { | 51 | } catch (Exception ex) { |
| 52 | throw new Error(ex); | 52 | throw new Error(ex); |
| 53 | } | 53 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java index 2692c06..ea775e9 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java | |||
| @@ -19,29 +19,17 @@ import cuchaz.enigma.bytecode.InfoType; | |||
| 19 | 19 | ||
| 20 | public class ConstInfoAccessor { | 20 | public class ConstInfoAccessor { |
| 21 | 21 | ||
| 22 | private static Class<?> m_class; | 22 | private static Class<?> clazz; |
| 23 | private static Field m_index; | 23 | private static Field index; |
| 24 | private static Method m_getTag; | 24 | private static Method getTag; |
| 25 | 25 | ||
| 26 | static { | 26 | private Object item; |
| 27 | try { | ||
| 28 | m_class = Class.forName("javassist.bytecode.ConstInfo"); | ||
| 29 | m_index = m_class.getDeclaredField("index"); | ||
| 30 | m_index.setAccessible(true); | ||
| 31 | m_getTag = m_class.getMethod("getTag"); | ||
| 32 | m_getTag.setAccessible(true); | ||
| 33 | } catch (Exception ex) { | ||
| 34 | throw new Error(ex); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | private Object m_item; | ||
| 39 | 27 | ||
| 40 | public ConstInfoAccessor(Object item) { | 28 | public ConstInfoAccessor(Object item) { |
| 41 | if (item == null) { | 29 | if (item == null) { |
| 42 | throw new IllegalArgumentException("item cannot be null!"); | 30 | throw new IllegalArgumentException("item cannot be null!"); |
| 43 | } | 31 | } |
| 44 | m_item = item; | 32 | this.item = item; |
| 45 | } | 33 | } |
| 46 | 34 | ||
| 47 | public ConstInfoAccessor(DataInputStream in) throws IOException { | 35 | public ConstInfoAccessor(DataInputStream in) throws IOException { |
| @@ -56,7 +44,7 @@ public class ConstInfoAccessor { | |||
| 56 | 44 | ||
| 57 | Constructor<?> constructor = Class.forName(className).getConstructor(DataInputStream.class, int.class); | 45 | Constructor<?> constructor = Class.forName(className).getConstructor(DataInputStream.class, int.class); |
| 58 | constructor.setAccessible(true); | 46 | constructor.setAccessible(true); |
| 59 | m_item = constructor.newInstance(in, oldIndex); | 47 | this.item = constructor.newInstance(in, oldIndex); |
| 60 | } catch (IOException ex) { | 48 | } catch (IOException ex) { |
| 61 | throw ex; | 49 | throw ex; |
| 62 | } catch (Exception ex) { | 50 | } catch (Exception ex) { |
| @@ -65,12 +53,12 @@ public class ConstInfoAccessor { | |||
| 65 | } | 53 | } |
| 66 | 54 | ||
| 67 | public Object getItem() { | 55 | public Object getItem() { |
| 68 | return m_item; | 56 | return this.item; |
| 69 | } | 57 | } |
| 70 | 58 | ||
| 71 | public int getIndex() { | 59 | public int getIndex() { |
| 72 | try { | 60 | try { |
| 73 | return (Integer) m_index.get(m_item); | 61 | return (Integer) index.get(this.item); |
| 74 | } catch (Exception ex) { | 62 | } catch (Exception ex) { |
| 75 | throw new Error(ex); | 63 | throw new Error(ex); |
| 76 | } | 64 | } |
| @@ -78,7 +66,7 @@ public class ConstInfoAccessor { | |||
| 78 | 66 | ||
| 79 | public void setIndex(int val) { | 67 | public void setIndex(int val) { |
| 80 | try { | 68 | try { |
| 81 | m_index.set(m_item, val); | 69 | index.set(this.item, val); |
| 82 | } catch (Exception ex) { | 70 | } catch (Exception ex) { |
| 83 | throw new Error(ex); | 71 | throw new Error(ex); |
| 84 | } | 72 | } |
| @@ -86,7 +74,7 @@ public class ConstInfoAccessor { | |||
| 86 | 74 | ||
| 87 | public int getTag() { | 75 | public int getTag() { |
| 88 | try { | 76 | try { |
| 89 | return (Integer) m_getTag.invoke(m_item); | 77 | return (Integer) getTag.invoke(this.item); |
| 90 | } catch (Exception ex) { | 78 | } catch (Exception ex) { |
| 91 | throw new Error(ex); | 79 | throw new Error(ex); |
| 92 | } | 80 | } |
| @@ -117,12 +105,12 @@ public class ConstInfoAccessor { | |||
| 117 | 105 | ||
| 118 | public void write(DataOutputStream out) throws IOException { | 106 | public void write(DataOutputStream out) throws IOException { |
| 119 | try { | 107 | try { |
| 120 | out.writeUTF(m_item.getClass().getName()); | 108 | out.writeUTF(this.item.getClass().getName()); |
| 121 | out.writeInt(getIndex()); | 109 | out.writeInt(getIndex()); |
| 122 | 110 | ||
| 123 | Method method = m_item.getClass().getMethod("write", DataOutputStream.class); | 111 | Method method = this.item.getClass().getMethod("write", DataOutputStream.class); |
| 124 | method.setAccessible(true); | 112 | method.setAccessible(true); |
| 125 | method.invoke(m_item, out); | 113 | method.invoke(this.item, out); |
| 126 | } catch (IOException ex) { | 114 | } catch (IOException ex) { |
| 127 | throw ex; | 115 | throw ex; |
| 128 | } catch (Exception ex) { | 116 | } catch (Exception ex) { |
| @@ -135,9 +123,9 @@ public class ConstInfoAccessor { | |||
| 135 | try { | 123 | try { |
| 136 | ByteArrayOutputStream buf = new ByteArrayOutputStream(); | 124 | ByteArrayOutputStream buf = new ByteArrayOutputStream(); |
| 137 | PrintWriter out = new PrintWriter(buf); | 125 | PrintWriter out = new PrintWriter(buf); |
| 138 | Method print = m_item.getClass().getMethod("print", PrintWriter.class); | 126 | Method print = this.item.getClass().getMethod("print", PrintWriter.class); |
| 139 | print.setAccessible(true); | 127 | print.setAccessible(true); |
| 140 | print.invoke(m_item, out); | 128 | print.invoke(this.item, out); |
| 141 | out.close(); | 129 | out.close(); |
| 142 | return buf.toString().replace("\n", ""); | 130 | return buf.toString().replace("\n", ""); |
| 143 | } catch (Exception ex) { | 131 | } catch (Exception ex) { |
| @@ -148,4 +136,16 @@ public class ConstInfoAccessor { | |||
| 148 | public InfoType getType() { | 136 | public InfoType getType() { |
| 149 | return InfoType.getByTag(getTag()); | 137 | return InfoType.getByTag(getTag()); |
| 150 | } | 138 | } |
| 139 | |||
| 140 | static { | ||
| 141 | try { | ||
| 142 | clazz = Class.forName("javassist.bytecode.ConstInfo"); | ||
| 143 | index = clazz.getDeclaredField("index"); | ||
| 144 | index.setAccessible(true); | ||
| 145 | getTag = clazz.getMethod("getTag"); | ||
| 146 | getTag.setAccessible(true); | ||
| 147 | } catch (Exception ex) { | ||
| 148 | throw new Error(ex); | ||
| 149 | } | ||
| 150 | } | ||
| 151 | } | 151 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java index 0ca82b7..69aee16 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java | |||
| @@ -14,35 +14,20 @@ import java.lang.reflect.Field; | |||
| 14 | 14 | ||
| 15 | public class InvokeDynamicInfoAccessor { | 15 | public class InvokeDynamicInfoAccessor { |
| 16 | 16 | ||
| 17 | private static Class<?> m_class; | 17 | private static Class<?> clazz; |
| 18 | private static Field m_bootstrapIndex; | 18 | private static Field bootstrapIndex; |
| 19 | private static Field m_nameAndTypeIndex; | 19 | private static Field nameAndTypeIndex; |
| 20 | 20 | ||
| 21 | static { | ||
| 22 | try { | ||
| 23 | m_class = Class.forName("javassist.bytecode.InvokeDynamicInfo"); | ||
| 24 | m_bootstrapIndex = m_class.getDeclaredField("bootstrap"); | ||
| 25 | m_bootstrapIndex.setAccessible(true); | ||
| 26 | m_nameAndTypeIndex = m_class.getDeclaredField("nameAndType"); | ||
| 27 | m_nameAndTypeIndex.setAccessible(true); | ||
| 28 | } catch (Exception ex) { | ||
| 29 | throw new Error(ex); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | 21 | ||
| 33 | public static boolean isType(ConstInfoAccessor accessor) { | 22 | private Object item; |
| 34 | return m_class.isAssignableFrom(accessor.getItem().getClass()); | ||
| 35 | } | ||
| 36 | |||
| 37 | private Object m_item; | ||
| 38 | 23 | ||
| 39 | public InvokeDynamicInfoAccessor(Object item) { | 24 | public InvokeDynamicInfoAccessor(Object item) { |
| 40 | m_item = item; | 25 | this.item = item; |
| 41 | } | 26 | } |
| 42 | 27 | ||
| 43 | public int getBootstrapIndex() { | 28 | public int getBootstrapIndex() { |
| 44 | try { | 29 | try { |
| 45 | return (Integer) m_bootstrapIndex.get(m_item); | 30 | return (Integer) bootstrapIndex.get(this.item); |
| 46 | } catch (Exception ex) { | 31 | } catch (Exception ex) { |
| 47 | throw new Error(ex); | 32 | throw new Error(ex); |
| 48 | } | 33 | } |
| @@ -50,7 +35,7 @@ public class InvokeDynamicInfoAccessor { | |||
| 50 | 35 | ||
| 51 | public void setBootstrapIndex(int val) { | 36 | public void setBootstrapIndex(int val) { |
| 52 | try { | 37 | try { |
| 53 | m_bootstrapIndex.set(m_item, val); | 38 | bootstrapIndex.set(this.item, val); |
| 54 | } catch (Exception ex) { | 39 | } catch (Exception ex) { |
| 55 | throw new Error(ex); | 40 | throw new Error(ex); |
| 56 | } | 41 | } |
| @@ -58,7 +43,7 @@ public class InvokeDynamicInfoAccessor { | |||
| 58 | 43 | ||
| 59 | public int getNameAndTypeIndex() { | 44 | public int getNameAndTypeIndex() { |
| 60 | try { | 45 | try { |
| 61 | return (Integer) m_nameAndTypeIndex.get(m_item); | 46 | return (Integer) nameAndTypeIndex.get(this.item); |
| 62 | } catch (Exception ex) { | 47 | } catch (Exception ex) { |
| 63 | throw new Error(ex); | 48 | throw new Error(ex); |
| 64 | } | 49 | } |
| @@ -66,7 +51,23 @@ public class InvokeDynamicInfoAccessor { | |||
| 66 | 51 | ||
| 67 | public void setNameAndTypeIndex(int val) { | 52 | public void setNameAndTypeIndex(int val) { |
| 68 | try { | 53 | try { |
| 69 | m_nameAndTypeIndex.set(m_item, val); | 54 | nameAndTypeIndex.set(this.item, val); |
| 55 | } catch (Exception ex) { | ||
| 56 | throw new Error(ex); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 61 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 62 | } | ||
| 63 | |||
| 64 | static { | ||
| 65 | try { | ||
| 66 | clazz = Class.forName("javassist.bytecode.InvokeDynamicInfo"); | ||
| 67 | bootstrapIndex = clazz.getDeclaredField("bootstrap"); | ||
| 68 | bootstrapIndex.setAccessible(true); | ||
| 69 | nameAndTypeIndex = clazz.getDeclaredField("nameAndType"); | ||
| 70 | nameAndTypeIndex.setAccessible(true); | ||
| 70 | } catch (Exception ex) { | 71 | } catch (Exception ex) { |
| 71 | throw new Error(ex); | 72 | throw new Error(ex); |
| 72 | } | 73 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java index bb9d16b..0e0297b 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java | |||
| @@ -14,35 +14,19 @@ import java.lang.reflect.Field; | |||
| 14 | 14 | ||
| 15 | public class MemberRefInfoAccessor { | 15 | public class MemberRefInfoAccessor { |
| 16 | 16 | ||
| 17 | private static Class<?> m_class; | 17 | private static Class<?> clazz; |
| 18 | private static Field m_classIndex; | 18 | private static Field classIndex; |
| 19 | private static Field m_nameAndTypeIndex; | 19 | private static Field nameAndTypeIndex; |
| 20 | 20 | ||
| 21 | static { | 21 | private Object item; |
| 22 | try { | ||
| 23 | m_class = Class.forName("javassist.bytecode.MemberrefInfo"); | ||
| 24 | m_classIndex = m_class.getDeclaredField("classIndex"); | ||
| 25 | m_classIndex.setAccessible(true); | ||
| 26 | m_nameAndTypeIndex = m_class.getDeclaredField("nameAndTypeIndex"); | ||
| 27 | m_nameAndTypeIndex.setAccessible(true); | ||
| 28 | } catch (Exception ex) { | ||
| 29 | throw new Error(ex); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 34 | return m_class.isAssignableFrom(accessor.getItem().getClass()); | ||
| 35 | } | ||
| 36 | |||
| 37 | private Object m_item; | ||
| 38 | 22 | ||
| 39 | public MemberRefInfoAccessor(Object item) { | 23 | public MemberRefInfoAccessor(Object item) { |
| 40 | m_item = item; | 24 | this.item = item; |
| 41 | } | 25 | } |
| 42 | 26 | ||
| 43 | public int getClassIndex() { | 27 | public int getClassIndex() { |
| 44 | try { | 28 | try { |
| 45 | return (Integer) m_classIndex.get(m_item); | 29 | return (Integer) classIndex.get(this.item); |
| 46 | } catch (Exception ex) { | 30 | } catch (Exception ex) { |
| 47 | throw new Error(ex); | 31 | throw new Error(ex); |
| 48 | } | 32 | } |
| @@ -50,7 +34,7 @@ public class MemberRefInfoAccessor { | |||
| 50 | 34 | ||
| 51 | public void setClassIndex(int val) { | 35 | public void setClassIndex(int val) { |
| 52 | try { | 36 | try { |
| 53 | m_classIndex.set(m_item, val); | 37 | classIndex.set(this.item, val); |
| 54 | } catch (Exception ex) { | 38 | } catch (Exception ex) { |
| 55 | throw new Error(ex); | 39 | throw new Error(ex); |
| 56 | } | 40 | } |
| @@ -58,7 +42,7 @@ public class MemberRefInfoAccessor { | |||
| 58 | 42 | ||
| 59 | public int getNameAndTypeIndex() { | 43 | public int getNameAndTypeIndex() { |
| 60 | try { | 44 | try { |
| 61 | return (Integer) m_nameAndTypeIndex.get(m_item); | 45 | return (Integer) nameAndTypeIndex.get(this.item); |
| 62 | } catch (Exception ex) { | 46 | } catch (Exception ex) { |
| 63 | throw new Error(ex); | 47 | throw new Error(ex); |
| 64 | } | 48 | } |
| @@ -66,7 +50,23 @@ public class MemberRefInfoAccessor { | |||
| 66 | 50 | ||
| 67 | public void setNameAndTypeIndex(int val) { | 51 | public void setNameAndTypeIndex(int val) { |
| 68 | try { | 52 | try { |
| 69 | m_nameAndTypeIndex.set(m_item, val); | 53 | nameAndTypeIndex.set(this.item, val); |
| 54 | } catch (Exception ex) { | ||
| 55 | throw new Error(ex); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 60 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 61 | } | ||
| 62 | |||
| 63 | static { | ||
| 64 | try { | ||
| 65 | clazz = Class.forName("javassist.bytecode.MemberrefInfo"); | ||
| 66 | classIndex = clazz.getDeclaredField("classIndex"); | ||
| 67 | classIndex.setAccessible(true); | ||
| 68 | nameAndTypeIndex = clazz.getDeclaredField("nameAndTypeIndex"); | ||
| 69 | nameAndTypeIndex.setAccessible(true); | ||
| 70 | } catch (Exception ex) { | 70 | } catch (Exception ex) { |
| 71 | throw new Error(ex); | 71 | throw new Error(ex); |
| 72 | } | 72 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java index 88e42f4..9a7dd69 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java | |||
| @@ -14,35 +14,19 @@ import java.lang.reflect.Field; | |||
| 14 | 14 | ||
| 15 | public class MethodHandleInfoAccessor { | 15 | public class MethodHandleInfoAccessor { |
| 16 | 16 | ||
| 17 | private static Class<?> m_class; | 17 | private static Class<?> clazz; |
| 18 | private static Field m_kindIndex; | 18 | private static Field kindIndex; |
| 19 | private static Field m_indexIndex; | 19 | private static Field indexIndex; |
| 20 | 20 | ||
| 21 | static { | 21 | private Object item; |
| 22 | try { | ||
| 23 | m_class = Class.forName("javassist.bytecode.MethodHandleInfo"); | ||
| 24 | m_kindIndex = m_class.getDeclaredField("refKind"); | ||
| 25 | m_kindIndex.setAccessible(true); | ||
| 26 | m_indexIndex = m_class.getDeclaredField("refIndex"); | ||
| 27 | m_indexIndex.setAccessible(true); | ||
| 28 | } catch (Exception ex) { | ||
| 29 | throw new Error(ex); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 34 | return m_class.isAssignableFrom(accessor.getItem().getClass()); | ||
| 35 | } | ||
| 36 | |||
| 37 | private Object m_item; | ||
| 38 | 22 | ||
| 39 | public MethodHandleInfoAccessor(Object item) { | 23 | public MethodHandleInfoAccessor(Object item) { |
| 40 | m_item = item; | 24 | this.item = item; |
| 41 | } | 25 | } |
| 42 | 26 | ||
| 43 | public int getTypeIndex() { | 27 | public int getTypeIndex() { |
| 44 | try { | 28 | try { |
| 45 | return (Integer) m_kindIndex.get(m_item); | 29 | return (Integer) kindIndex.get(this.item); |
| 46 | } catch (Exception ex) { | 30 | } catch (Exception ex) { |
| 47 | throw new Error(ex); | 31 | throw new Error(ex); |
| 48 | } | 32 | } |
| @@ -50,7 +34,7 @@ public class MethodHandleInfoAccessor { | |||
| 50 | 34 | ||
| 51 | public void setTypeIndex(int val) { | 35 | public void setTypeIndex(int val) { |
| 52 | try { | 36 | try { |
| 53 | m_kindIndex.set(m_item, val); | 37 | kindIndex.set(this.item, val); |
| 54 | } catch (Exception ex) { | 38 | } catch (Exception ex) { |
| 55 | throw new Error(ex); | 39 | throw new Error(ex); |
| 56 | } | 40 | } |
| @@ -58,7 +42,7 @@ public class MethodHandleInfoAccessor { | |||
| 58 | 42 | ||
| 59 | public int getMethodRefIndex() { | 43 | public int getMethodRefIndex() { |
| 60 | try { | 44 | try { |
| 61 | return (Integer) m_indexIndex.get(m_item); | 45 | return (Integer) indexIndex.get(this.item); |
| 62 | } catch (Exception ex) { | 46 | } catch (Exception ex) { |
| 63 | throw new Error(ex); | 47 | throw new Error(ex); |
| 64 | } | 48 | } |
| @@ -66,7 +50,23 @@ public class MethodHandleInfoAccessor { | |||
| 66 | 50 | ||
| 67 | public void setMethodRefIndex(int val) { | 51 | public void setMethodRefIndex(int val) { |
| 68 | try { | 52 | try { |
| 69 | m_indexIndex.set(m_item, val); | 53 | indexIndex.set(this.item, val); |
| 54 | } catch (Exception ex) { | ||
| 55 | throw new Error(ex); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 60 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 61 | } | ||
| 62 | |||
| 63 | static { | ||
| 64 | try { | ||
| 65 | clazz = Class.forName("javassist.bytecode.MethodHandleInfo"); | ||
| 66 | kindIndex = clazz.getDeclaredField("refKind"); | ||
| 67 | kindIndex.setAccessible(true); | ||
| 68 | indexIndex = clazz.getDeclaredField("refIndex"); | ||
| 69 | indexIndex.setAccessible(true); | ||
| 70 | } catch (Exception ex) { | 70 | } catch (Exception ex) { |
| 71 | throw new Error(ex); | 71 | throw new Error(ex); |
| 72 | } | 72 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java index 1d039f6..5ec9c3b 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java | |||
| @@ -14,32 +14,18 @@ import java.lang.reflect.Field; | |||
| 14 | 14 | ||
| 15 | public class MethodTypeInfoAccessor { | 15 | public class MethodTypeInfoAccessor { |
| 16 | 16 | ||
| 17 | private static Class<?> m_class; | 17 | private static Class<?> clazz; |
| 18 | private static Field m_descriptorIndex; | 18 | private static Field descriptorIndex; |
| 19 | 19 | ||
| 20 | static { | 20 | private Object item; |
| 21 | try { | ||
| 22 | m_class = Class.forName("javassist.bytecode.MethodTypeInfo"); | ||
| 23 | m_descriptorIndex = m_class.getDeclaredField("descriptor"); | ||
| 24 | m_descriptorIndex.setAccessible(true); | ||
| 25 | } catch (Exception ex) { | ||
| 26 | throw new Error(ex); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 31 | return m_class.isAssignableFrom(accessor.getItem().getClass()); | ||
| 32 | } | ||
| 33 | |||
| 34 | private Object m_item; | ||
| 35 | 21 | ||
| 36 | public MethodTypeInfoAccessor(Object item) { | 22 | public MethodTypeInfoAccessor(Object item) { |
| 37 | m_item = item; | 23 | this.item = item; |
| 38 | } | 24 | } |
| 39 | 25 | ||
| 40 | public int getTypeIndex() { | 26 | public int getTypeIndex() { |
| 41 | try { | 27 | try { |
| 42 | return (Integer) m_descriptorIndex.get(m_item); | 28 | return (Integer) descriptorIndex.get(this.item); |
| 43 | } catch (Exception ex) { | 29 | } catch (Exception ex) { |
| 44 | throw new Error(ex); | 30 | throw new Error(ex); |
| 45 | } | 31 | } |
| @@ -47,9 +33,24 @@ public class MethodTypeInfoAccessor { | |||
| 47 | 33 | ||
| 48 | public void setTypeIndex(int val) { | 34 | public void setTypeIndex(int val) { |
| 49 | try { | 35 | try { |
| 50 | m_descriptorIndex.set(m_item, val); | 36 | descriptorIndex.set(this.item, val); |
| 51 | } catch (Exception ex) { | 37 | } catch (Exception ex) { |
| 52 | throw new Error(ex); | 38 | throw new Error(ex); |
| 53 | } | 39 | } |
| 54 | } | 40 | } |
| 41 | |||
| 42 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 43 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 44 | } | ||
| 45 | |||
| 46 | static { | ||
| 47 | try { | ||
| 48 | clazz = Class.forName("javassist.bytecode.MethodTypeInfo"); | ||
| 49 | descriptorIndex = clazz.getDeclaredField("descriptor"); | ||
| 50 | descriptorIndex.setAccessible(true); | ||
| 51 | } catch (Exception ex) { | ||
| 52 | throw new Error(ex); | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 55 | } | 56 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java index acba779..95df37c 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java | |||
| @@ -14,35 +14,19 @@ import java.lang.reflect.Field; | |||
| 14 | 14 | ||
| 15 | public class NameAndTypeInfoAccessor { | 15 | public class NameAndTypeInfoAccessor { |
| 16 | 16 | ||
| 17 | private static Class<?> m_class; | 17 | private static Class<?> clazz; |
| 18 | private static Field m_nameIndex; | 18 | private static Field nameIndex; |
| 19 | private static Field m_typeIndex; | 19 | private static Field typeIndex; |
| 20 | 20 | ||
| 21 | static { | 21 | private Object item; |
| 22 | try { | ||
| 23 | m_class = Class.forName("javassist.bytecode.NameAndTypeInfo"); | ||
| 24 | m_nameIndex = m_class.getDeclaredField("memberName"); | ||
| 25 | m_nameIndex.setAccessible(true); | ||
| 26 | m_typeIndex = m_class.getDeclaredField("typeDescriptor"); | ||
| 27 | m_typeIndex.setAccessible(true); | ||
| 28 | } catch (Exception ex) { | ||
| 29 | throw new Error(ex); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 34 | return m_class.isAssignableFrom(accessor.getItem().getClass()); | ||
| 35 | } | ||
| 36 | |||
| 37 | private Object m_item; | ||
| 38 | 22 | ||
| 39 | public NameAndTypeInfoAccessor(Object item) { | 23 | public NameAndTypeInfoAccessor(Object item) { |
| 40 | m_item = item; | 24 | this.item = item; |
| 41 | } | 25 | } |
| 42 | 26 | ||
| 43 | public int getNameIndex() { | 27 | public int getNameIndex() { |
| 44 | try { | 28 | try { |
| 45 | return (Integer) m_nameIndex.get(m_item); | 29 | return (Integer) nameIndex.get(this.item); |
| 46 | } catch (Exception ex) { | 30 | } catch (Exception ex) { |
| 47 | throw new Error(ex); | 31 | throw new Error(ex); |
| 48 | } | 32 | } |
| @@ -50,7 +34,7 @@ public class NameAndTypeInfoAccessor { | |||
| 50 | 34 | ||
| 51 | public void setNameIndex(int val) { | 35 | public void setNameIndex(int val) { |
| 52 | try { | 36 | try { |
| 53 | m_nameIndex.set(m_item, val); | 37 | nameIndex.set(this.item, val); |
| 54 | } catch (Exception ex) { | 38 | } catch (Exception ex) { |
| 55 | throw new Error(ex); | 39 | throw new Error(ex); |
| 56 | } | 40 | } |
| @@ -58,7 +42,7 @@ public class NameAndTypeInfoAccessor { | |||
| 58 | 42 | ||
| 59 | public int getTypeIndex() { | 43 | public int getTypeIndex() { |
| 60 | try { | 44 | try { |
| 61 | return (Integer) m_typeIndex.get(m_item); | 45 | return (Integer) typeIndex.get(this.item); |
| 62 | } catch (Exception ex) { | 46 | } catch (Exception ex) { |
| 63 | throw new Error(ex); | 47 | throw new Error(ex); |
| 64 | } | 48 | } |
| @@ -66,7 +50,23 @@ public class NameAndTypeInfoAccessor { | |||
| 66 | 50 | ||
| 67 | public void setTypeIndex(int val) { | 51 | public void setTypeIndex(int val) { |
| 68 | try { | 52 | try { |
| 69 | m_typeIndex.set(m_item, val); | 53 | typeIndex.set(this.item, val); |
| 54 | } catch (Exception ex) { | ||
| 55 | throw new Error(ex); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 60 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 61 | } | ||
| 62 | |||
| 63 | static { | ||
| 64 | try { | ||
| 65 | clazz = Class.forName("javassist.bytecode.NameAndTypeInfo"); | ||
| 66 | nameIndex = clazz.getDeclaredField("memberName"); | ||
| 67 | nameIndex.setAccessible(true); | ||
| 68 | typeIndex = clazz.getDeclaredField("typeDescriptor"); | ||
| 69 | typeIndex.setAccessible(true); | ||
| 70 | } catch (Exception ex) { | 70 | } catch (Exception ex) { |
| 71 | throw new Error(ex); | 71 | throw new Error(ex); |
| 72 | } | 72 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java index b40e0eb..1c55a44 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java | |||
| @@ -14,32 +14,18 @@ import java.lang.reflect.Field; | |||
| 14 | 14 | ||
| 15 | public class StringInfoAccessor { | 15 | public class StringInfoAccessor { |
| 16 | 16 | ||
| 17 | private static Class<?> m_class; | 17 | private static Class<?> clazz; |
| 18 | private static Field m_stringIndex; | 18 | private static Field stringIndex; |
| 19 | 19 | ||
| 20 | static { | 20 | private Object item; |
| 21 | try { | ||
| 22 | m_class = Class.forName("javassist.bytecode.StringInfo"); | ||
| 23 | m_stringIndex = m_class.getDeclaredField("string"); | ||
| 24 | m_stringIndex.setAccessible(true); | ||
| 25 | } catch (Exception ex) { | ||
| 26 | throw new Error(ex); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 31 | return m_class.isAssignableFrom(accessor.getItem().getClass()); | ||
| 32 | } | ||
| 33 | |||
| 34 | private Object m_item; | ||
| 35 | 21 | ||
| 36 | public StringInfoAccessor(Object item) { | 22 | public StringInfoAccessor(Object item) { |
| 37 | m_item = item; | 23 | this.item = item; |
| 38 | } | 24 | } |
| 39 | 25 | ||
| 40 | public int getStringIndex() { | 26 | public int getStringIndex() { |
| 41 | try { | 27 | try { |
| 42 | return (Integer) m_stringIndex.get(m_item); | 28 | return (Integer) stringIndex.get(this.item); |
| 43 | } catch (Exception ex) { | 29 | } catch (Exception ex) { |
| 44 | throw new Error(ex); | 30 | throw new Error(ex); |
| 45 | } | 31 | } |
| @@ -47,7 +33,21 @@ public class StringInfoAccessor { | |||
| 47 | 33 | ||
| 48 | public void setStringIndex(int val) { | 34 | public void setStringIndex(int val) { |
| 49 | try { | 35 | try { |
| 50 | m_stringIndex.set(m_item, val); | 36 | stringIndex.set(this.item, val); |
| 37 | } catch (Exception ex) { | ||
| 38 | throw new Error(ex); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 43 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 44 | } | ||
| 45 | |||
| 46 | static { | ||
| 47 | try { | ||
| 48 | clazz = Class.forName("javassist.bytecode.StringInfo"); | ||
| 49 | stringIndex = clazz.getDeclaredField("string"); | ||
| 50 | stringIndex.setAccessible(true); | ||
| 51 | } catch (Exception ex) { | 51 | } catch (Exception ex) { |
| 52 | throw new Error(ex); | 52 | throw new Error(ex); |
| 53 | } | 53 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java index 9303b41..7a2cb66 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java | |||
| @@ -12,17 +12,17 @@ package cuchaz.enigma.bytecode.accessors; | |||
| 12 | 12 | ||
| 13 | public class Utf8InfoAccessor { | 13 | public class Utf8InfoAccessor { |
| 14 | 14 | ||
| 15 | private static Class<?> m_class; | 15 | private static Class<?> clazz; |
| 16 | 16 | ||
| 17 | static { | 17 | static { |
| 18 | try { | 18 | try { |
| 19 | m_class = Class.forName("javassist.bytecode.Utf8Info"); | 19 | clazz = Class.forName("javassist.bytecode.Utf8Info"); |
| 20 | } catch (Exception ex) { | 20 | } catch (Exception ex) { |
| 21 | throw new Error(ex); | 21 | throw new Error(ex); |
| 22 | } | 22 | } |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | public static boolean isType(ConstInfoAccessor accessor) { | 25 | public static boolean isType(ConstInfoAccessor accessor) { |
| 26 | return m_class.isAssignableFrom(accessor.getItem().getClass()); | 26 | return clazz.isAssignableFrom(accessor.getItem().getClass()); |
| 27 | } | 27 | } |
| 28 | } | 28 | } |