diff options
Diffstat (limited to 'src/cuchaz/enigma/bytecode/accessors')
9 files changed, 823 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java new file mode 100644 index 0000000..41e1d04 --- /dev/null +++ b/src/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java | |||
| @@ -0,0 +1,69 @@ | |||
| 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 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.bytecode.accessors; | ||
| 12 | |||
| 13 | import java.lang.reflect.Field; | ||
| 14 | |||
| 15 | public class ClassInfoAccessor | ||
| 16 | { | ||
| 17 | private static Class<?> m_class; | ||
| 18 | private static Field m_nameIndex; | ||
| 19 | |||
| 20 | static | ||
| 21 | { | ||
| 22 | try | ||
| 23 | { | ||
| 24 | m_class = Class.forName( "javassist.bytecode.ClassInfo" ); | ||
| 25 | m_nameIndex = m_class.getDeclaredField( "name" ); | ||
| 26 | m_nameIndex.setAccessible( true ); | ||
| 27 | } | ||
| 28 | catch( Exception ex ) | ||
| 29 | { | ||
| 30 | throw new Error( ex ); | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | public static boolean isType( ConstInfoAccessor accessor ) | ||
| 35 | { | ||
| 36 | return m_class.isAssignableFrom( accessor.getItem().getClass() ); | ||
| 37 | } | ||
| 38 | |||
| 39 | private Object m_item; | ||
| 40 | |||
| 41 | public ClassInfoAccessor( Object item ) | ||
| 42 | { | ||
| 43 | m_item = item; | ||
| 44 | } | ||
| 45 | |||
| 46 | public int getNameIndex( ) | ||
| 47 | { | ||
| 48 | try | ||
| 49 | { | ||
| 50 | return (Integer)m_nameIndex.get( m_item ); | ||
| 51 | } | ||
| 52 | catch( Exception ex ) | ||
| 53 | { | ||
| 54 | throw new Error( ex ); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | public void setNameIndex( int val ) | ||
| 59 | { | ||
| 60 | try | ||
| 61 | { | ||
| 62 | m_nameIndex.set( m_item, val ); | ||
| 63 | } | ||
| 64 | catch( Exception ex ) | ||
| 65 | { | ||
| 66 | throw new Error( ex ); | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
diff --git a/src/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java new file mode 100644 index 0000000..3c3d3fa --- /dev/null +++ b/src/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java | |||
| @@ -0,0 +1,199 @@ | |||
| 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 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.bytecode.accessors; | ||
| 12 | |||
| 13 | import java.io.ByteArrayInputStream; | ||
| 14 | import java.io.ByteArrayOutputStream; | ||
| 15 | import java.io.DataInputStream; | ||
| 16 | import java.io.DataOutputStream; | ||
| 17 | import java.io.IOException; | ||
| 18 | import java.io.PrintWriter; | ||
| 19 | import java.lang.reflect.Constructor; | ||
| 20 | import java.lang.reflect.Field; | ||
| 21 | import java.lang.reflect.Method; | ||
| 22 | |||
| 23 | import cuchaz.enigma.bytecode.InfoType; | ||
| 24 | |||
| 25 | public class ConstInfoAccessor | ||
| 26 | { | ||
| 27 | private static Class<?> m_class; | ||
| 28 | private static Field m_index; | ||
| 29 | private static Method m_getTag; | ||
| 30 | |||
| 31 | static | ||
| 32 | { | ||
| 33 | try | ||
| 34 | { | ||
| 35 | m_class = Class.forName( "javassist.bytecode.ConstInfo" ); | ||
| 36 | m_index = m_class.getDeclaredField( "index" ); | ||
| 37 | m_index.setAccessible( true ); | ||
| 38 | m_getTag = m_class.getMethod( "getTag" ); | ||
| 39 | m_getTag.setAccessible( true ); | ||
| 40 | } | ||
| 41 | catch( Exception ex ) | ||
| 42 | { | ||
| 43 | throw new Error( ex ); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | private Object m_item; | ||
| 48 | |||
| 49 | public ConstInfoAccessor( Object item ) | ||
| 50 | { | ||
| 51 | if( item == null ) | ||
| 52 | { | ||
| 53 | throw new IllegalArgumentException( "item cannot be null!" ); | ||
| 54 | } | ||
| 55 | m_item = item; | ||
| 56 | } | ||
| 57 | |||
| 58 | public ConstInfoAccessor( DataInputStream in ) | ||
| 59 | throws IOException | ||
| 60 | { | ||
| 61 | try | ||
| 62 | { | ||
| 63 | // read the entry | ||
| 64 | String className = in.readUTF(); | ||
| 65 | int oldIndex = in.readInt(); | ||
| 66 | |||
| 67 | // NOTE: ConstInfo instances write a type id (a "tag"), but they don't read it back | ||
| 68 | // so we have to read it here | ||
| 69 | in.readByte(); | ||
| 70 | |||
| 71 | Constructor<?> constructor = Class.forName( className ).getConstructor( DataInputStream.class, int.class ); | ||
| 72 | constructor.setAccessible( true ); | ||
| 73 | m_item = constructor.newInstance( in, oldIndex ); | ||
| 74 | } | ||
| 75 | catch( IOException ex ) | ||
| 76 | { | ||
| 77 | throw ex; | ||
| 78 | } | ||
| 79 | catch( Exception ex ) | ||
| 80 | { | ||
| 81 | throw new Error( ex ); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | public Object getItem( ) | ||
| 86 | { | ||
| 87 | return m_item; | ||
| 88 | } | ||
| 89 | |||
| 90 | public int getIndex( ) | ||
| 91 | { | ||
| 92 | try | ||
| 93 | { | ||
| 94 | return (Integer)m_index.get( m_item ); | ||
| 95 | } | ||
| 96 | catch( Exception ex ) | ||
| 97 | { | ||
| 98 | throw new Error( ex ); | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | public void setIndex( int val ) | ||
| 103 | { | ||
| 104 | try | ||
| 105 | { | ||
| 106 | m_index.set( m_item, val ); | ||
| 107 | } | ||
| 108 | catch( Exception ex ) | ||
| 109 | { | ||
| 110 | throw new Error( ex ); | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | public int getTag( ) | ||
| 115 | { | ||
| 116 | try | ||
| 117 | { | ||
| 118 | return (Integer)m_getTag.invoke( m_item ); | ||
| 119 | } | ||
| 120 | catch( Exception ex ) | ||
| 121 | { | ||
| 122 | throw new Error( ex ); | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | public ConstInfoAccessor copy( ) | ||
| 127 | { | ||
| 128 | return new ConstInfoAccessor( copyItem() ); | ||
| 129 | } | ||
| 130 | |||
| 131 | public Object copyItem( ) | ||
| 132 | { | ||
| 133 | // I don't know of a simpler way to copy one of these silly things... | ||
| 134 | try | ||
| 135 | { | ||
| 136 | // serialize the item | ||
| 137 | ByteArrayOutputStream buf = new ByteArrayOutputStream(); | ||
| 138 | DataOutputStream out = new DataOutputStream( buf ); | ||
| 139 | write( out ); | ||
| 140 | |||
| 141 | // deserialize the item | ||
| 142 | DataInputStream in = new DataInputStream( new ByteArrayInputStream( buf.toByteArray() ) ); | ||
| 143 | Object item = new ConstInfoAccessor( in ).getItem(); | ||
| 144 | in.close(); | ||
| 145 | |||
| 146 | return item; | ||
| 147 | } | ||
| 148 | catch( Exception ex ) | ||
| 149 | { | ||
| 150 | throw new Error( ex ); | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 154 | public void write( DataOutputStream out ) | ||
| 155 | throws IOException | ||
| 156 | { | ||
| 157 | try | ||
| 158 | { | ||
| 159 | out.writeUTF( m_item.getClass().getName() ); | ||
| 160 | out.writeInt( getIndex() ); | ||
| 161 | |||
| 162 | Method method = m_item.getClass().getMethod( "write", DataOutputStream.class ); | ||
| 163 | method.setAccessible( true ); | ||
| 164 | method.invoke( m_item, out ); | ||
| 165 | } | ||
| 166 | catch( IOException ex ) | ||
| 167 | { | ||
| 168 | throw ex; | ||
| 169 | } | ||
| 170 | catch( Exception ex ) | ||
| 171 | { | ||
| 172 | throw new Error( ex ); | ||
| 173 | } | ||
| 174 | } | ||
| 175 | |||
| 176 | @Override | ||
| 177 | public String toString( ) | ||
| 178 | { | ||
| 179 | try | ||
| 180 | { | ||
| 181 | ByteArrayOutputStream buf = new ByteArrayOutputStream(); | ||
| 182 | PrintWriter out = new PrintWriter( buf ); | ||
| 183 | Method print = m_item.getClass().getMethod( "print", PrintWriter.class ); | ||
| 184 | print.setAccessible( true ); | ||
| 185 | print.invoke( m_item, out ); | ||
| 186 | out.close(); | ||
| 187 | return buf.toString().replace( "\n", "" ); | ||
| 188 | } | ||
| 189 | catch( Exception ex ) | ||
| 190 | { | ||
| 191 | throw new Error( ex ); | ||
| 192 | } | ||
| 193 | } | ||
| 194 | |||
| 195 | public InfoType getType( ) | ||
| 196 | { | ||
| 197 | return InfoType.getByTag( getTag() ); | ||
| 198 | } | ||
| 199 | } | ||
diff --git a/src/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java new file mode 100644 index 0000000..169306a --- /dev/null +++ b/src/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java | |||
| @@ -0,0 +1,96 @@ | |||
| 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 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.bytecode.accessors; | ||
| 12 | |||
| 13 | import java.lang.reflect.Field; | ||
| 14 | |||
| 15 | public class InvokeDynamicInfoAccessor | ||
| 16 | { | ||
| 17 | private static Class<?> m_class; | ||
| 18 | private static Field m_bootstrapIndex; | ||
| 19 | private static Field m_nameAndTypeIndex; | ||
| 20 | |||
| 21 | static | ||
| 22 | { | ||
| 23 | try | ||
| 24 | { | ||
| 25 | m_class = Class.forName( "javassist.bytecode.InvokeDynamicInfo" ); | ||
| 26 | m_bootstrapIndex = m_class.getDeclaredField( "bootstrap" ); | ||
| 27 | m_bootstrapIndex.setAccessible( true ); | ||
| 28 | m_nameAndTypeIndex = m_class.getDeclaredField( "nameAndType" ); | ||
| 29 | m_nameAndTypeIndex.setAccessible( true ); | ||
| 30 | } | ||
| 31 | catch( Exception ex ) | ||
| 32 | { | ||
| 33 | throw new Error( ex ); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | public static boolean isType( ConstInfoAccessor accessor ) | ||
| 38 | { | ||
| 39 | return m_class.isAssignableFrom( accessor.getItem().getClass() ); | ||
| 40 | } | ||
| 41 | |||
| 42 | private Object m_item; | ||
| 43 | |||
| 44 | public InvokeDynamicInfoAccessor( Object item ) | ||
| 45 | { | ||
| 46 | m_item = item; | ||
| 47 | } | ||
| 48 | |||
| 49 | public int getBootstrapIndex( ) | ||
| 50 | { | ||
| 51 | try | ||
| 52 | { | ||
| 53 | return (Integer)m_bootstrapIndex.get( m_item ); | ||
| 54 | } | ||
| 55 | catch( Exception ex ) | ||
| 56 | { | ||
| 57 | throw new Error( ex ); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | public void setBootstrapIndex( int val ) | ||
| 62 | { | ||
| 63 | try | ||
| 64 | { | ||
| 65 | m_bootstrapIndex.set( m_item, val ); | ||
| 66 | } | ||
| 67 | catch( Exception ex ) | ||
| 68 | { | ||
| 69 | throw new Error( ex ); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | public int getNameAndTypeIndex( ) | ||
| 74 | { | ||
| 75 | try | ||
| 76 | { | ||
| 77 | return (Integer)m_nameAndTypeIndex.get( m_item ); | ||
| 78 | } | ||
| 79 | catch( Exception ex ) | ||
| 80 | { | ||
| 81 | throw new Error( ex ); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | public void setNameAndTypeIndex( int val ) | ||
| 86 | { | ||
| 87 | try | ||
| 88 | { | ||
| 89 | m_nameAndTypeIndex.set( m_item, val ); | ||
| 90 | } | ||
| 91 | catch( Exception ex ) | ||
| 92 | { | ||
| 93 | throw new Error( ex ); | ||
| 94 | } | ||
| 95 | } | ||
| 96 | } | ||
diff --git a/src/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java new file mode 100644 index 0000000..2ee3aff --- /dev/null +++ b/src/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java | |||
| @@ -0,0 +1,96 @@ | |||
| 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 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.bytecode.accessors; | ||
| 12 | |||
| 13 | import java.lang.reflect.Field; | ||
| 14 | |||
| 15 | public class MemberRefInfoAccessor | ||
| 16 | { | ||
| 17 | private static Class<?> m_class; | ||
| 18 | private static Field m_classIndex; | ||
| 19 | private static Field m_nameAndTypeIndex; | ||
| 20 | |||
| 21 | static | ||
| 22 | { | ||
| 23 | try | ||
| 24 | { | ||
| 25 | m_class = Class.forName( "javassist.bytecode.MemberrefInfo" ); | ||
| 26 | m_classIndex = m_class.getDeclaredField( "classIndex" ); | ||
| 27 | m_classIndex.setAccessible( true ); | ||
| 28 | m_nameAndTypeIndex = m_class.getDeclaredField( "nameAndTypeIndex" ); | ||
| 29 | m_nameAndTypeIndex.setAccessible( true ); | ||
| 30 | } | ||
| 31 | catch( Exception ex ) | ||
| 32 | { | ||
| 33 | throw new Error( ex ); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | public static boolean isType( ConstInfoAccessor accessor ) | ||
| 38 | { | ||
| 39 | return m_class.isAssignableFrom( accessor.getItem().getClass() ); | ||
| 40 | } | ||
| 41 | |||
| 42 | private Object m_item; | ||
| 43 | |||
| 44 | public MemberRefInfoAccessor( Object item ) | ||
| 45 | { | ||
| 46 | m_item = item; | ||
| 47 | } | ||
| 48 | |||
| 49 | public int getClassIndex( ) | ||
| 50 | { | ||
| 51 | try | ||
| 52 | { | ||
| 53 | return (Integer)m_classIndex.get( m_item ); | ||
| 54 | } | ||
| 55 | catch( Exception ex ) | ||
| 56 | { | ||
| 57 | throw new Error( ex ); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | public void setClassIndex( int val ) | ||
| 62 | { | ||
| 63 | try | ||
| 64 | { | ||
| 65 | m_classIndex.set( m_item, val ); | ||
| 66 | } | ||
| 67 | catch( Exception ex ) | ||
| 68 | { | ||
| 69 | throw new Error( ex ); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | public int getNameAndTypeIndex( ) | ||
| 74 | { | ||
| 75 | try | ||
| 76 | { | ||
| 77 | return (Integer)m_nameAndTypeIndex.get( m_item ); | ||
| 78 | } | ||
| 79 | catch( Exception ex ) | ||
| 80 | { | ||
| 81 | throw new Error( ex ); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | public void setNameAndTypeIndex( int val ) | ||
| 86 | { | ||
| 87 | try | ||
| 88 | { | ||
| 89 | m_nameAndTypeIndex.set( m_item, val ); | ||
| 90 | } | ||
| 91 | catch( Exception ex ) | ||
| 92 | { | ||
| 93 | throw new Error( ex ); | ||
| 94 | } | ||
| 95 | } | ||
| 96 | } | ||
diff --git a/src/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java new file mode 100644 index 0000000..27b7aee --- /dev/null +++ b/src/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java | |||
| @@ -0,0 +1,96 @@ | |||
| 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 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.bytecode.accessors; | ||
| 12 | |||
| 13 | import java.lang.reflect.Field; | ||
| 14 | |||
| 15 | public class MethodHandleInfoAccessor | ||
| 16 | { | ||
| 17 | private static Class<?> m_class; | ||
| 18 | private static Field m_kindIndex; | ||
| 19 | private static Field m_indexIndex; | ||
| 20 | |||
| 21 | static | ||
| 22 | { | ||
| 23 | try | ||
| 24 | { | ||
| 25 | m_class = Class.forName( "javassist.bytecode.MethodHandleInfo" ); | ||
| 26 | m_kindIndex = m_class.getDeclaredField( "refKind" ); | ||
| 27 | m_kindIndex.setAccessible( true ); | ||
| 28 | m_indexIndex = m_class.getDeclaredField( "refIndex" ); | ||
| 29 | m_indexIndex.setAccessible( true ); | ||
| 30 | } | ||
| 31 | catch( Exception ex ) | ||
| 32 | { | ||
| 33 | throw new Error( ex ); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | public static boolean isType( ConstInfoAccessor accessor ) | ||
| 38 | { | ||
| 39 | return m_class.isAssignableFrom( accessor.getItem().getClass() ); | ||
| 40 | } | ||
| 41 | |||
| 42 | private Object m_item; | ||
| 43 | |||
| 44 | public MethodHandleInfoAccessor( Object item ) | ||
| 45 | { | ||
| 46 | m_item = item; | ||
| 47 | } | ||
| 48 | |||
| 49 | public int getTypeIndex( ) | ||
| 50 | { | ||
| 51 | try | ||
| 52 | { | ||
| 53 | return (Integer)m_kindIndex.get( m_item ); | ||
| 54 | } | ||
| 55 | catch( Exception ex ) | ||
| 56 | { | ||
| 57 | throw new Error( ex ); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | public void setTypeIndex( int val ) | ||
| 62 | { | ||
| 63 | try | ||
| 64 | { | ||
| 65 | m_kindIndex.set( m_item, val ); | ||
| 66 | } | ||
| 67 | catch( Exception ex ) | ||
| 68 | { | ||
| 69 | throw new Error( ex ); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | public int getMethodRefIndex( ) | ||
| 74 | { | ||
| 75 | try | ||
| 76 | { | ||
| 77 | return (Integer)m_indexIndex.get( m_item ); | ||
| 78 | } | ||
| 79 | catch( Exception ex ) | ||
| 80 | { | ||
| 81 | throw new Error( ex ); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | public void setMethodRefIndex( int val ) | ||
| 86 | { | ||
| 87 | try | ||
| 88 | { | ||
| 89 | m_indexIndex.set( m_item, val ); | ||
| 90 | } | ||
| 91 | catch( Exception ex ) | ||
| 92 | { | ||
| 93 | throw new Error( ex ); | ||
| 94 | } | ||
| 95 | } | ||
| 96 | } | ||
diff --git a/src/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java new file mode 100644 index 0000000..4cba6a2 --- /dev/null +++ b/src/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java | |||
| @@ -0,0 +1,69 @@ | |||
| 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 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.bytecode.accessors; | ||
| 12 | |||
| 13 | import java.lang.reflect.Field; | ||
| 14 | |||
| 15 | public class MethodTypeInfoAccessor | ||
| 16 | { | ||
| 17 | private static Class<?> m_class; | ||
| 18 | private static Field m_descriptorIndex; | ||
| 19 | |||
| 20 | static | ||
| 21 | { | ||
| 22 | try | ||
| 23 | { | ||
| 24 | m_class = Class.forName( "javassist.bytecode.MethodTypeInfo" ); | ||
| 25 | m_descriptorIndex = m_class.getDeclaredField( "descriptor" ); | ||
| 26 | m_descriptorIndex.setAccessible( true ); | ||
| 27 | } | ||
| 28 | catch( Exception ex ) | ||
| 29 | { | ||
| 30 | throw new Error( ex ); | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | public static boolean isType( ConstInfoAccessor accessor ) | ||
| 35 | { | ||
| 36 | return m_class.isAssignableFrom( accessor.getItem().getClass() ); | ||
| 37 | } | ||
| 38 | |||
| 39 | private Object m_item; | ||
| 40 | |||
| 41 | public MethodTypeInfoAccessor( Object item ) | ||
| 42 | { | ||
| 43 | m_item = item; | ||
| 44 | } | ||
| 45 | |||
| 46 | public int getTypeIndex( ) | ||
| 47 | { | ||
| 48 | try | ||
| 49 | { | ||
| 50 | return (Integer)m_descriptorIndex.get( m_item ); | ||
| 51 | } | ||
| 52 | catch( Exception ex ) | ||
| 53 | { | ||
| 54 | throw new Error( ex ); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | public void setTypeIndex( int val ) | ||
| 59 | { | ||
| 60 | try | ||
| 61 | { | ||
| 62 | m_descriptorIndex.set( m_item, val ); | ||
| 63 | } | ||
| 64 | catch( Exception ex ) | ||
| 65 | { | ||
| 66 | throw new Error( ex ); | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
diff --git a/src/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java new file mode 100644 index 0000000..03b4de3 --- /dev/null +++ b/src/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java | |||
| @@ -0,0 +1,96 @@ | |||
| 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 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.bytecode.accessors; | ||
| 12 | |||
| 13 | import java.lang.reflect.Field; | ||
| 14 | |||
| 15 | public class NameAndTypeInfoAccessor | ||
| 16 | { | ||
| 17 | private static Class<?> m_class; | ||
| 18 | private static Field m_nameIndex; | ||
| 19 | private static Field m_typeIndex; | ||
| 20 | |||
| 21 | static | ||
| 22 | { | ||
| 23 | try | ||
| 24 | { | ||
| 25 | m_class = Class.forName( "javassist.bytecode.NameAndTypeInfo" ); | ||
| 26 | m_nameIndex = m_class.getDeclaredField( "memberName" ); | ||
| 27 | m_nameIndex.setAccessible( true ); | ||
| 28 | m_typeIndex = m_class.getDeclaredField( "typeDescriptor" ); | ||
| 29 | m_typeIndex.setAccessible( true ); | ||
| 30 | } | ||
| 31 | catch( Exception ex ) | ||
| 32 | { | ||
| 33 | throw new Error( ex ); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | public static boolean isType( ConstInfoAccessor accessor ) | ||
| 38 | { | ||
| 39 | return m_class.isAssignableFrom( accessor.getItem().getClass() ); | ||
| 40 | } | ||
| 41 | |||
| 42 | private Object m_item; | ||
| 43 | |||
| 44 | public NameAndTypeInfoAccessor( Object item ) | ||
| 45 | { | ||
| 46 | m_item = item; | ||
| 47 | } | ||
| 48 | |||
| 49 | public int getNameIndex( ) | ||
| 50 | { | ||
| 51 | try | ||
| 52 | { | ||
| 53 | return (Integer)m_nameIndex.get( m_item ); | ||
| 54 | } | ||
| 55 | catch( Exception ex ) | ||
| 56 | { | ||
| 57 | throw new Error( ex ); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | public void setNameIndex( int val ) | ||
| 62 | { | ||
| 63 | try | ||
| 64 | { | ||
| 65 | m_nameIndex.set( m_item, val ); | ||
| 66 | } | ||
| 67 | catch( Exception ex ) | ||
| 68 | { | ||
| 69 | throw new Error( ex ); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | public int getTypeIndex( ) | ||
| 74 | { | ||
| 75 | try | ||
| 76 | { | ||
| 77 | return (Integer)m_typeIndex.get( m_item ); | ||
| 78 | } | ||
| 79 | catch( Exception ex ) | ||
| 80 | { | ||
| 81 | throw new Error( ex ); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | public void setTypeIndex( int val ) | ||
| 86 | { | ||
| 87 | try | ||
| 88 | { | ||
| 89 | m_typeIndex.set( m_item, val ); | ||
| 90 | } | ||
| 91 | catch( Exception ex ) | ||
| 92 | { | ||
| 93 | throw new Error( ex ); | ||
| 94 | } | ||
| 95 | } | ||
| 96 | } | ||
diff --git a/src/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java new file mode 100644 index 0000000..5cdfce4 --- /dev/null +++ b/src/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java | |||
| @@ -0,0 +1,69 @@ | |||
| 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 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.bytecode.accessors; | ||
| 12 | |||
| 13 | import java.lang.reflect.Field; | ||
| 14 | |||
| 15 | public class StringInfoAccessor | ||
| 16 | { | ||
| 17 | private static Class<?> m_class; | ||
| 18 | private static Field m_stringIndex; | ||
| 19 | |||
| 20 | static | ||
| 21 | { | ||
| 22 | try | ||
| 23 | { | ||
| 24 | m_class = Class.forName( "javassist.bytecode.StringInfo" ); | ||
| 25 | m_stringIndex = m_class.getDeclaredField( "string" ); | ||
| 26 | m_stringIndex.setAccessible( true ); | ||
| 27 | } | ||
| 28 | catch( Exception ex ) | ||
| 29 | { | ||
| 30 | throw new Error( ex ); | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | public static boolean isType( ConstInfoAccessor accessor ) | ||
| 35 | { | ||
| 36 | return m_class.isAssignableFrom( accessor.getItem().getClass() ); | ||
| 37 | } | ||
| 38 | |||
| 39 | private Object m_item; | ||
| 40 | |||
| 41 | public StringInfoAccessor( Object item ) | ||
| 42 | { | ||
| 43 | m_item = item; | ||
| 44 | } | ||
| 45 | |||
| 46 | public int getStringIndex( ) | ||
| 47 | { | ||
| 48 | try | ||
| 49 | { | ||
| 50 | return (Integer)m_stringIndex.get( m_item ); | ||
| 51 | } | ||
| 52 | catch( Exception ex ) | ||
| 53 | { | ||
| 54 | throw new Error( ex ); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | public void setStringIndex( int val ) | ||
| 59 | { | ||
| 60 | try | ||
| 61 | { | ||
| 62 | m_stringIndex.set( m_item, val ); | ||
| 63 | } | ||
| 64 | catch( Exception ex ) | ||
| 65 | { | ||
| 66 | throw new Error( ex ); | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
diff --git a/src/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java new file mode 100644 index 0000000..1cadd83 --- /dev/null +++ b/src/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java | |||
| @@ -0,0 +1,33 @@ | |||
| 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 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.bytecode.accessors; | ||
| 12 | |||
| 13 | public class Utf8InfoAccessor | ||
| 14 | { | ||
| 15 | private static Class<?> m_class; | ||
| 16 | |||
| 17 | static | ||
| 18 | { | ||
| 19 | try | ||
| 20 | { | ||
| 21 | m_class = Class.forName( "javassist.bytecode.Utf8Info" ); | ||
| 22 | } | ||
| 23 | catch( Exception ex ) | ||
| 24 | { | ||
| 25 | throw new Error( ex ); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | public static boolean isType( ConstInfoAccessor accessor ) | ||
| 30 | { | ||
| 31 | return m_class.isAssignableFrom( accessor.getItem().getClass() ); | ||
| 32 | } | ||
| 33 | } | ||