From 959cb5fd4f9586ec3bd265b452fe25fe1db82e3f Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 13 Jan 2015 23:25:04 -0500 Subject: source format change don't hate me too much if you were planning a big merge. =P --- .../enigma/bytecode/BytecodeIndexIterator.java | 121 +++---- src/cuchaz/enigma/bytecode/BytecodeTools.java | 269 +++++++--------- src/cuchaz/enigma/bytecode/CheckCastIterator.java | 98 +++--- src/cuchaz/enigma/bytecode/ClassRenamer.java | 103 +++--- src/cuchaz/enigma/bytecode/ClassTranslator.java | 104 +++--- src/cuchaz/enigma/bytecode/ConstPoolEditor.java | 295 +++++++----------- src/cuchaz/enigma/bytecode/InfoType.java | 347 +++++++++------------ src/cuchaz/enigma/bytecode/InnerClassWriter.java | 103 +++--- .../enigma/bytecode/MethodParameterWriter.java | 47 ++- .../enigma/bytecode/MethodParametersAttribute.java | 65 ++-- .../bytecode/accessors/ClassInfoAccessor.java | 58 ++-- .../bytecode/accessors/ConstInfoAccessor.java | 181 ++++------- .../accessors/InvokeDynamicInfoAccessor.java | 90 ++---- .../bytecode/accessors/MemberRefInfoAccessor.java | 90 ++---- .../accessors/MethodHandleInfoAccessor.java | 90 ++---- .../bytecode/accessors/MethodTypeInfoAccessor.java | 58 ++-- .../accessors/NameAndTypeInfoAccessor.java | 90 ++---- .../bytecode/accessors/StringInfoAccessor.java | 58 ++-- .../bytecode/accessors/Utf8InfoAccessor.java | 23 +- 19 files changed, 920 insertions(+), 1370 deletions(-) (limited to 'src/cuchaz/enigma/bytecode') diff --git a/src/cuchaz/enigma/bytecode/BytecodeIndexIterator.java b/src/cuchaz/enigma/bytecode/BytecodeIndexIterator.java index aadbeb2..fc2bac3 100644 --- a/src/cuchaz/enigma/bytecode/BytecodeIndexIterator.java +++ b/src/cuchaz/enigma/bytecode/BytecodeIndexIterator.java @@ -18,67 +18,53 @@ import javassist.bytecode.CodeAttribute; import javassist.bytecode.CodeIterator; import javassist.bytecode.Opcode; -public class BytecodeIndexIterator implements Iterator -{ - public static class Index - { +public class BytecodeIndexIterator implements Iterator { + + public static class Index { + private CodeIterator m_iter; private int m_pos; private boolean m_isWide; - protected Index( CodeIterator iter, int pos, boolean isWide ) - { + protected Index(CodeIterator iter, int pos, boolean isWide) { m_iter = iter; m_pos = pos; m_isWide = isWide; } - public int getIndex( ) - { - if( m_isWide ) - { - return m_iter.s16bitAt( m_pos ); - } - else - { - return m_iter.byteAt( m_pos ); + public int getIndex() { + if (m_isWide) { + return m_iter.s16bitAt(m_pos); + } else { + return m_iter.byteAt(m_pos); } } - public void setIndex( int val ) - throws BadBytecode - { - if( m_isWide ) - { - m_iter.write16bit( val, m_pos ); - } - else - { - if( val < 256 ) - { + public void setIndex(int val) throws BadBytecode { + if (m_isWide) { + m_iter.write16bit(val, m_pos); + } else { + if (val < 256) { // we can write the byte - m_iter.writeByte( val, m_pos ); - } - else - { + m_iter.writeByte(val, m_pos); + } else { // we need to upgrade this instruction to LDC_W - assert( m_iter.byteAt( m_pos - 1 ) == Opcode.LDC ); - m_iter.insertGap( m_pos - 1, 1 ); - m_iter.writeByte( Opcode.LDC_W, m_pos - 1 ); - m_iter.write16bit( val, m_pos ); + assert (m_iter.byteAt(m_pos - 1) == Opcode.LDC); + m_iter.insertGap(m_pos - 1, 1); + m_iter.writeByte(Opcode.LDC_W, m_pos - 1); + m_iter.write16bit(val, m_pos); m_isWide = true; // move the iterator to the next opcode - m_iter.move( m_pos + 2 ); + m_iter.move(m_pos + 2); } } // sanity check - assert( val == getIndex() ); + assert (val == getIndex()); } - public boolean isValid( Bytecode bytecode ) - { + public boolean isValid(Bytecode bytecode) { return getIndex() >= 0 && getIndex() < bytecode.getConstPool().getSize(); } } @@ -88,9 +74,7 @@ public class BytecodeIndexIterator implements Iterator indices( ) - { - return new Iterable( ) - { + public Iterable indices() { + return new Iterable() { @Override - public Iterator iterator( ) - { + public Iterator iterator() { return BytecodeIndexIterator.this; } }; } - public void saveChangesToBytecode( ) - { - BytecodeTools.setBytecode( m_bytecode, m_attribute.getCode() ); + public void saveChangesToBytecode() { + BytecodeTools.setBytecode(m_bytecode, m_attribute.getCode()); } } diff --git a/src/cuchaz/enigma/bytecode/BytecodeTools.java b/src/cuchaz/enigma/bytecode/BytecodeTools.java index 4407a90..2e456f4 100644 --- a/src/cuchaz/enigma/bytecode/BytecodeTools.java +++ b/src/cuchaz/enigma/bytecode/BytecodeTools.java @@ -34,256 +34,222 @@ import cuchaz.enigma.Util; import cuchaz.enigma.bytecode.BytecodeIndexIterator.Index; import cuchaz.enigma.bytecode.accessors.ConstInfoAccessor; -public class BytecodeTools -{ - public static byte[] writeBytecode( Bytecode bytecode ) - throws IOException - { +public class BytecodeTools { + + public static byte[] writeBytecode(Bytecode bytecode) throws IOException { + ByteArrayOutputStream buf = new ByteArrayOutputStream(); - DataOutputStream out = new DataOutputStream( buf ); - try - { + DataOutputStream out = new DataOutputStream(buf); + + try { // write the constant pool - new ConstPoolEditor( bytecode.getConstPool() ).writePool( out ); + new ConstPoolEditor(bytecode.getConstPool()).writePool(out); // write metadata - out.writeShort( bytecode.getMaxStack() ); - out.writeShort( bytecode.getMaxLocals() ); - out.writeShort( bytecode.getStackDepth() ); + out.writeShort(bytecode.getMaxStack()); + out.writeShort(bytecode.getMaxLocals()); + out.writeShort(bytecode.getStackDepth()); // write the code - out.writeShort( bytecode.getSize() ); - out.write( bytecode.get() ); + out.writeShort(bytecode.getSize()); + out.write(bytecode.get()); // write the exception table int numEntries = bytecode.getExceptionTable().size(); - out.writeShort( numEntries ); - for( int i=0; i attribute.getMaxLocals() ) - { - attribute.setMaxLocals( bytecode.getMaxLocals() ); + if (bytecode.getMaxLocals() > attribute.getMaxLocals()) { + attribute.setMaxLocals(bytecode.getMaxLocals()); } - if( bytecode.getMaxStack() > attribute.getMaxStack() ) - { - attribute.setMaxStack( bytecode.getMaxStack() ); + if (bytecode.getMaxStack() > attribute.getMaxStack()) { + attribute.setMaxStack(bytecode.getMaxStack()); } return bytecode; } - public static Bytecode copyBytecodeToConstPool( ConstPool dest, Bytecode bytecode ) - throws BadBytecode - { + public static Bytecode copyBytecodeToConstPool(ConstPool dest, Bytecode bytecode) throws BadBytecode { + // get the entries this bytecode needs from the const pool Set indices = Sets.newTreeSet(); - ConstPoolEditor editor = new ConstPoolEditor( bytecode.getConstPool() ); - BytecodeIndexIterator iterator = new BytecodeIndexIterator( bytecode ); - for( Index index : iterator.indices() ) - { - assert( index.isValid( bytecode ) ); - InfoType.gatherIndexTree( indices, editor, index.getIndex() ); + ConstPoolEditor editor = new ConstPoolEditor(bytecode.getConstPool()); + BytecodeIndexIterator iterator = new BytecodeIndexIterator(bytecode); + for (Index index : iterator.indices()) { + assert (index.isValid(bytecode)); + InfoType.gatherIndexTree(indices, editor, index.getIndex()); } Map indexMap = Maps.newTreeMap(); ConstPool src = bytecode.getConstPool(); - ConstPoolEditor editorSrc = new ConstPoolEditor( src ); - ConstPoolEditor editorDest = new ConstPoolEditor( dest ); + ConstPoolEditor editorSrc = new ConstPoolEditor(src); + ConstPoolEditor editorDest = new ConstPoolEditor(dest); // copy entries over in order of level so the index mapping is easier - for( InfoType type : InfoType.getSortedByLevel() ) - { - for( int index : indices ) - { - ConstInfoAccessor entry = editorSrc.getItem( index ); + for (InfoType type : InfoType.getSortedByLevel()) { + for (int index : indices) { + ConstInfoAccessor entry = editorSrc.getItem(index); // skip entries that aren't this type - if( entry.getType() != type ) - { + if (entry.getType() != type) { continue; } // make sure the source entry is valid before we copy it - assert( type.subIndicesAreValid( entry, editorSrc ) ); - assert( type.selfIndexIsValid( entry, editorSrc ) ); + assert (type.subIndicesAreValid(entry, editorSrc)); + assert (type.selfIndexIsValid(entry, editorSrc)); // make a copy of the entry so we can modify it safely - ConstInfoAccessor entryCopy = editorSrc.getItem( index ).copy(); - assert( type.subIndicesAreValid( entryCopy, editorSrc ) ); - assert( type.selfIndexIsValid( entryCopy, editorSrc ) ); + ConstInfoAccessor entryCopy = editorSrc.getItem(index).copy(); + assert (type.subIndicesAreValid(entryCopy, editorSrc)); + assert (type.selfIndexIsValid(entryCopy, editorSrc)); // remap the indices - type.remapIndices( indexMap, entryCopy ); - assert( type.subIndicesAreValid( entryCopy, editorDest ) ); + type.remapIndices(indexMap, entryCopy); + assert (type.subIndicesAreValid(entryCopy, editorDest)); // put the copy in the destination pool - int newIndex = editorDest.addItem( entryCopy.getItem() ); - entryCopy.setIndex( newIndex ); - assert( type.selfIndexIsValid( entryCopy, editorDest ) ) : type + ", self: " + entryCopy + " dest: " + editorDest.getItem( entryCopy.getIndex() ); + int newIndex = editorDest.addItem(entryCopy.getItem()); + entryCopy.setIndex(newIndex); + assert (type.selfIndexIsValid(entryCopy, editorDest)) : type + ", self: " + entryCopy + " dest: " + editorDest.getItem(entryCopy.getIndex()); // make sure the source entry is unchanged - assert( type.subIndicesAreValid( entry, editorSrc ) ); - assert( type.selfIndexIsValid( entry, editorSrc ) ); + assert (type.subIndicesAreValid(entry, editorSrc)); + assert (type.selfIndexIsValid(entry, editorSrc)); // add the index mapping so we can update the bytecode later - if( indexMap.containsKey( index ) ) - { - throw new Error( "Entry at index " + index + " already copied!" ); + if (indexMap.containsKey(index)) { + throw new Error("Entry at index " + index + " already copied!"); } - indexMap.put( index, newIndex ); + indexMap.put(index, newIndex); } } // make a new bytecode - Bytecode newBytecode = new Bytecode( dest, bytecode.getMaxStack(), bytecode.getMaxLocals() ); - bytecode.setStackDepth( bytecode.getStackDepth() ); - setBytecode( newBytecode, bytecode.get() ); - setExceptionTable( newBytecode, bytecode.getExceptionTable() ); + Bytecode newBytecode = new Bytecode(dest, bytecode.getMaxStack(), bytecode.getMaxLocals()); + bytecode.setStackDepth(bytecode.getStackDepth()); + setBytecode(newBytecode, bytecode.get()); + setExceptionTable(newBytecode, bytecode.getExceptionTable()); // apply the mappings to the bytecode - BytecodeIndexIterator iter = new BytecodeIndexIterator( newBytecode ); - for( Index index : iter.indices() ) - { + BytecodeIndexIterator iter = new BytecodeIndexIterator(newBytecode); + for (Index index : iter.indices()) { int oldIndex = index.getIndex(); - Integer newIndex = indexMap.get( oldIndex ); - if( newIndex != null ) - { + Integer newIndex = indexMap.get(oldIndex); + if (newIndex != null) { // make sure this mapping makes sense - InfoType typeSrc = editorSrc.getItem( oldIndex ).getType(); - InfoType typeDest = editorDest.getItem( newIndex ).getType(); - assert( typeSrc == typeDest ); + InfoType typeSrc = editorSrc.getItem(oldIndex).getType(); + InfoType typeDest = editorDest.getItem(newIndex).getType(); + assert (typeSrc == typeDest); // apply the mapping - index.setIndex( newIndex ); + index.setIndex(newIndex); } } iter.saveChangesToBytecode(); // make sure all the indices are valid - iter = new BytecodeIndexIterator( newBytecode ); - for( Index index : iter.indices() ) - { - assert( index.isValid( newBytecode ) ); + iter = new BytecodeIndexIterator(newBytecode); + for (Index index : iter.indices()) { + assert (index.isValid(newBytecode)); } return newBytecode; } - public static void setBytecode( Bytecode dest, byte[] src ) - { - if( src.length > dest.getSize() ) - { - dest.addGap( src.length - dest.getSize() ); + public static void setBytecode(Bytecode dest, byte[] src) { + if (src.length > dest.getSize()) { + dest.addGap(src.length - dest.getSize()); } - assert( dest.getSize() == src.length ); - for( int i=0; i=0; i-- ) - { - dest.getExceptionTable().remove( i ); + for (int i = size - 1; i >= 0; i--) { + dest.getExceptionTable().remove(i); } // copy the exception table - for( int i=0; i getParameterTypes( String signature ) - { + public static List getParameterTypes(String signature) { List types = Lists.newArrayList(); - for( int i=0; i 0 ) - { + while (arrayDim-- > 0) { type = "[" + type; } - types.add( type ); + types.add(type); } return types; } diff --git a/src/cuchaz/enigma/bytecode/CheckCastIterator.java b/src/cuchaz/enigma/bytecode/CheckCastIterator.java index 7ed5d7f..b6efbd4 100644 --- a/src/cuchaz/enigma/bytecode/CheckCastIterator.java +++ b/src/cuchaz/enigma/bytecode/CheckCastIterator.java @@ -22,15 +22,14 @@ import cuchaz.enigma.bytecode.CheckCastIterator.CheckCast; import cuchaz.enigma.mapping.ClassEntry; import cuchaz.enigma.mapping.MethodEntry; -public class CheckCastIterator implements Iterator -{ - public static class CheckCast - { +public class CheckCastIterator implements Iterator { + + public static class CheckCast { + public String className; public MethodEntry prevMethodEntry; - public CheckCast( String className, MethodEntry prevMethodEntry ) - { + public CheckCast(String className, MethodEntry prevMethodEntry) { this.className = className; this.prevMethodEntry = prevMethodEntry; } @@ -41,9 +40,7 @@ public class CheckCastIterator implements Iterator private CodeIterator m_iter; private CheckCast m_next; - public CheckCastIterator( CodeAttribute codeAttribute ) - throws BadBytecode - { + public CheckCastIterator(CodeAttribute codeAttribute) throws BadBytecode { m_constants = codeAttribute.getConstPool(); m_attribute = codeAttribute; m_iter = m_attribute.iterator(); @@ -52,52 +49,38 @@ public class CheckCastIterator implements Iterator } @Override - public boolean hasNext( ) - { + public boolean hasNext() { return m_next != null; } - + @Override - public CheckCast next( ) - { + public CheckCast next() { CheckCast out = m_next; - try - { + try { m_next = getNext(); - } - catch( BadBytecode ex ) - { - throw new Error( ex ); + } catch (BadBytecode ex) { + throw new Error(ex); } return out; } - + @Override - public void remove( ) - { + public void remove() { throw new UnsupportedOperationException(); } - private CheckCast getNext( ) - throws BadBytecode - { + private CheckCast getNext() throws BadBytecode { int prevPos = 0; - while( m_iter.hasNext() ) - { + while (m_iter.hasNext()) { int pos = m_iter.next(); - int opcode = m_iter.byteAt( pos ); - switch( opcode ) - { + int opcode = m_iter.byteAt(pos); + switch (opcode) { case Opcode.CHECKCAST: // get the type of this op code (next two bytes are a classinfo index) - MethodEntry prevMethodEntry = getMethodEntry( prevPos ); - if( prevMethodEntry != null ) - { - return new CheckCast( - m_constants.getClassInfo( m_iter.s16bitAt( pos + 1 ) ), - prevMethodEntry - ); + MethodEntry prevMethodEntry = getMethodEntry(prevPos); + if (prevMethodEntry != null) { + return new CheckCast(m_constants.getClassInfo(m_iter.s16bitAt(pos + 1)), prevMethodEntry); } break; } @@ -106,43 +89,36 @@ public class CheckCastIterator implements Iterator return null; } - private MethodEntry getMethodEntry( int pos ) - { - switch( m_iter.byteAt( pos ) ) - { + private MethodEntry getMethodEntry(int pos) { + switch (m_iter.byteAt(pos)) { case Opcode.INVOKEVIRTUAL: case Opcode.INVOKESTATIC: case Opcode.INVOKEDYNAMIC: - case Opcode.INVOKESPECIAL: - { - int index = m_iter.s16bitAt( pos + 1 ); + case Opcode.INVOKESPECIAL: { + int index = m_iter.s16bitAt(pos + 1); return new MethodEntry( - new ClassEntry( Descriptor.toJvmName( m_constants.getMethodrefClassName( index ) ) ), - m_constants.getMethodrefName( index ), - m_constants.getMethodrefType( index ) + new ClassEntry(Descriptor.toJvmName(m_constants.getMethodrefClassName(index))), + m_constants.getMethodrefName(index), + m_constants.getMethodrefType(index) ); } - case Opcode.INVOKEINTERFACE: - { - int index = m_iter.s16bitAt( pos + 1 ); + case Opcode.INVOKEINTERFACE: { + int index = m_iter.s16bitAt(pos + 1); return new MethodEntry( - new ClassEntry( Descriptor.toJvmName( m_constants.getInterfaceMethodrefClassName( index ) ) ), - m_constants.getInterfaceMethodrefName( index ), - m_constants.getInterfaceMethodrefType( index ) + new ClassEntry(Descriptor.toJvmName(m_constants.getInterfaceMethodrefClassName(index))), + m_constants.getInterfaceMethodrefName(index), + m_constants.getInterfaceMethodrefType(index) ); } } return null; } - - public Iterable casts( ) - { - return new Iterable( ) - { + + public Iterable casts() { + return new Iterable() { @Override - public Iterator iterator( ) - { + public Iterator iterator() { return CheckCastIterator.this; } }; diff --git a/src/cuchaz/enigma/bytecode/ClassRenamer.java b/src/cuchaz/enigma/bytecode/ClassRenamer.java index 849a323..f8e63d1 100644 --- a/src/cuchaz/enigma/bytecode/ClassRenamer.java +++ b/src/cuchaz/enigma/bytecode/ClassRenamer.java @@ -27,55 +27,43 @@ import cuchaz.enigma.mapping.ClassEntry; import cuchaz.enigma.mapping.SignatureUpdater; import cuchaz.enigma.mapping.SignatureUpdater.ClassNameUpdater; -public class ClassRenamer -{ - public static void renameClasses( CtClass c, Map map ) - { +public class ClassRenamer { + + public static void renameClasses(CtClass c, Map map) { + // build the map used by javassist ClassMap nameMap = new ClassMap(); - for( Map.Entry entry : map.entrySet() ) - { - nameMap.put( entry.getKey().getName(), entry.getValue().getName() ); + for (Map.Entry entry : map.entrySet()) { + nameMap.put(entry.getKey().getName(), entry.getValue().getName()); } - c.replaceClassName( nameMap ); + c.replaceClassName(nameMap); // replace simple names in the InnerClasses attribute too ConstPool constants = c.getClassFile().getConstPool(); - InnerClassesAttribute attr = (InnerClassesAttribute)c.getClassFile().getAttribute( InnerClassesAttribute.tag ); - if( attr != null ) - { - for( int i=0; i ATTR: %s,%s,%s", - classEntry, - attr.outerClass( i ), - attr.innerClass( i ), - attr.innerName( i ) - ) ); + System.out.println(String.format("\tDEOBF: %s-> ATTR: %s,%s,%s", classEntry, attr.outerClass(i), attr.innerClass(i), attr.innerName(i))); */ } } } - public static Set getAllClassEntries( final CtClass c ) - { + public static Set getAllClassEntries(final CtClass c) { + // get the classes that javassist knows about final Set entries = Sets.newHashSet(); - ClassMap map = new ClassMap( ) - { + ClassMap map = new ClassMap() { @Override - public Object get( Object obj ) - { - if( obj instanceof String ) - { + public Object get(Object obj) { + if (obj instanceof String) { String str = (String)obj; // javassist throws a lot of weird things at this map @@ -83,69 +71,60 @@ public class ClassRenamer // I'm opting to filter out the weirdness for now // skip anything with generic arguments - if( str.indexOf( '<' ) >= 0 || str.indexOf( '>' ) >= 0 || str.indexOf( ';' ) >= 0 ) - { + if (str.indexOf('<') >= 0 || str.indexOf('>') >= 0 || str.indexOf(';') >= 0) { return null; } // convert path/to/class.inner to path/to/class$inner - str = str.replace( '.', '$' ); + str = str.replace('.', '$'); // remember everything else - entries.add( new ClassEntry( str ) ); + entries.add(new ClassEntry(str)); } return null; } + private static final long serialVersionUID = -202160293602070641L; }; - c.replaceClassName( map ); + c.replaceClassName(map); return entries; } - public static void moveAllClassesOutOfDefaultPackage( CtClass c, String newPackageName ) - { + public static void moveAllClassesOutOfDefaultPackage(CtClass c, String newPackageName) { + // rename all classes Map map = Maps.newHashMap(); - for( ClassEntry classEntry : ClassRenamer.getAllClassEntries( c ) ) - { - if( classEntry.isInDefaultPackage() ) - { - map.put( classEntry, new ClassEntry( newPackageName + "/" + classEntry.getName() ) ); + for (ClassEntry classEntry : ClassRenamer.getAllClassEntries(c)) { + if (classEntry.isInDefaultPackage()) { + map.put(classEntry, new ClassEntry(newPackageName + "/" + classEntry.getName())); } } - ClassRenamer.renameClasses( c, map ); + ClassRenamer.renameClasses(c, map); // TEMP - for( ClassEntry classEntry : ClassRenamer.getAllClassEntries( c ) ) - { - if( classEntry.isInDefaultPackage() ) - { - throw new Error( "!!! " + classEntry ); + for (ClassEntry classEntry : ClassRenamer.getAllClassEntries(c)) { + if (classEntry.isInDefaultPackage()) { + throw new Error("!!! " + classEntry); } } // TEMP - for( CtBehavior behavior : c.getDeclaredBehaviors() ) - { - if( behavior.getSignature() == null ) - { + for (CtBehavior behavior : c.getDeclaredBehaviors()) { + if (behavior.getSignature() == null) { continue; } - SignatureUpdater.update( behavior.getSignature(), new ClassNameUpdater( ) - { + SignatureUpdater.update(behavior.getSignature(), new ClassNameUpdater() { @Override - public String update( String className ) - { - ClassEntry classEntry = new ClassEntry( className ); - if( classEntry.isInDefaultPackage() ) - { - throw new Error( "!!! " + className ); + public String update(String className) { + ClassEntry classEntry = new ClassEntry(className); + if (classEntry.isInDefaultPackage()) { + throw new Error("!!! " + className); } return className; } - } ); + }); } } } diff --git a/src/cuchaz/enigma/bytecode/ClassTranslator.java b/src/cuchaz/enigma/bytecode/ClassTranslator.java index 181fadb..bc12405 100644 --- a/src/cuchaz/enigma/bytecode/ClassTranslator.java +++ b/src/cuchaz/enigma/bytecode/ClassTranslator.java @@ -28,116 +28,102 @@ import cuchaz.enigma.mapping.FieldEntry; import cuchaz.enigma.mapping.MethodEntry; import cuchaz.enigma.mapping.Translator; -public class ClassTranslator -{ +public class ClassTranslator { + private Translator m_translator; - public ClassTranslator( Translator translator ) - { + public ClassTranslator(Translator translator) { m_translator = translator; } - public void translate( CtClass c ) - { + public void translate(CtClass c) { // NOTE: the order of these translations is very important // translate all the field and method references in the code by editing the constant pool ConstPool constants = c.getClassFile().getConstPool(); - ConstPoolEditor editor = new ConstPoolEditor( constants ); - for( int i=1; i map = Maps.newHashMap(); - for( ClassEntry obfClassEntry : ClassRenamer.getAllClassEntries( c ) ) - { - ClassEntry deobfClassEntry = m_translator.translateEntry( obfClassEntry ); - if( !obfClassEntry.equals( deobfClassEntry ) ) - { - map.put( obfClassEntry, deobfClassEntry ); + for (ClassEntry obfClassEntry : ClassRenamer.getAllClassEntries(c)) { + ClassEntry deobfClassEntry = m_translator.translateEntry(obfClassEntry); + if (!obfClassEntry.equals(deobfClassEntry)) { + map.put(obfClassEntry, deobfClassEntry); } } - ClassRenamer.renameClasses( c, map ); + ClassRenamer.renameClasses(c, map); } } diff --git a/src/cuchaz/enigma/bytecode/ConstPoolEditor.java b/src/cuchaz/enigma/bytecode/ConstPoolEditor.java index aa6149c..2dec3b7 100644 --- a/src/cuchaz/enigma/bytecode/ConstPoolEditor.java +++ b/src/cuchaz/enigma/bytecode/ConstPoolEditor.java @@ -23,8 +23,8 @@ import cuchaz.enigma.bytecode.accessors.ClassInfoAccessor; import cuchaz.enigma.bytecode.accessors.ConstInfoAccessor; import cuchaz.enigma.bytecode.accessors.MemberRefInfoAccessor; -public class ConstPoolEditor -{ +public class ConstPoolEditor { + private static Method m_getItem; private static Method m_addItem; private static Method m_addItem0; @@ -36,264 +36,213 @@ public class ConstPoolEditor private static Method m_methodWritePool; private static Constructor m_constructorPool; - static - { - try - { - m_getItem = ConstPool.class.getDeclaredMethod( "getItem", int.class ); - m_getItem.setAccessible( true ); + static { + try { + m_getItem = ConstPool.class.getDeclaredMethod("getItem", int.class); + m_getItem.setAccessible(true); - m_addItem = ConstPool.class.getDeclaredMethod( "addItem", Class.forName( "javassist.bytecode.ConstInfo" ) ); - m_addItem.setAccessible( true ); + m_addItem = ConstPool.class.getDeclaredMethod("addItem", Class.forName("javassist.bytecode.ConstInfo")); + m_addItem.setAccessible(true); - m_addItem0 = ConstPool.class.getDeclaredMethod( "addItem0", Class.forName( "javassist.bytecode.ConstInfo" ) ); - m_addItem0.setAccessible( true ); + m_addItem0 = ConstPool.class.getDeclaredMethod("addItem0", Class.forName("javassist.bytecode.ConstInfo")); + m_addItem0.setAccessible(true); - m_items = ConstPool.class.getDeclaredField( "items" ); - m_items.setAccessible( true ); + m_items = ConstPool.class.getDeclaredField("items"); + m_items.setAccessible(true); - m_cache = ConstPool.class.getDeclaredField( "itemsCache" ); - m_cache.setAccessible( true ); + m_cache = ConstPool.class.getDeclaredField("itemsCache"); + m_cache.setAccessible(true); - m_numItems = ConstPool.class.getDeclaredField( "numOfItems" ); - m_numItems.setAccessible( true ); + m_numItems = ConstPool.class.getDeclaredField("numOfItems"); + m_numItems.setAccessible(true); - m_objects = Class.forName( "javassist.bytecode.LongVector" ).getDeclaredField( "objects" ); - m_objects.setAccessible( true ); + m_objects = Class.forName("javassist.bytecode.LongVector").getDeclaredField("objects"); + m_objects.setAccessible(true); - m_elements = Class.forName( "javassist.bytecode.LongVector" ).getDeclaredField( "elements" ); - m_elements.setAccessible( true ); + m_elements = Class.forName("javassist.bytecode.LongVector").getDeclaredField("elements"); + m_elements.setAccessible(true); - m_methodWritePool = ConstPool.class.getDeclaredMethod( "write", DataOutputStream.class ); - m_methodWritePool.setAccessible( true ); + m_methodWritePool = ConstPool.class.getDeclaredMethod("write", DataOutputStream.class); + m_methodWritePool.setAccessible(true); - m_constructorPool = ConstPool.class.getDeclaredConstructor( DataInputStream.class ); - m_constructorPool.setAccessible( true ); - } - catch( Exception ex ) - { - throw new Error( ex ); + m_constructorPool = ConstPool.class.getDeclaredConstructor(DataInputStream.class); + m_constructorPool.setAccessible(true); + } catch (Exception ex) { + throw new Error(ex); } } private ConstPool m_pool; - public ConstPoolEditor( ConstPool pool ) - { + public ConstPoolEditor(ConstPool pool) { m_pool = pool; } - public void writePool( DataOutputStream out ) - { - try - { - m_methodWritePool.invoke( m_pool, out ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public void writePool(DataOutputStream out) { + try { + m_methodWritePool.invoke(m_pool, out); + } catch (Exception ex) { + throw new Error(ex); } } - public static ConstPool readPool( DataInputStream in ) - { - try - { - return m_constructorPool.newInstance( in ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public static ConstPool readPool(DataInputStream in) { + try { + return m_constructorPool.newInstance(in); + } catch (Exception ex) { + throw new Error(ex); } } - public String getMemberrefClassname( int memberrefIndex ) - { - return Descriptor.toJvmName( m_pool.getClassInfo( m_pool.getMemberClass( memberrefIndex ) ) ); + public String getMemberrefClassname(int memberrefIndex) { + return Descriptor.toJvmName(m_pool.getClassInfo(m_pool.getMemberClass(memberrefIndex))); } - public String getMemberrefName( int memberrefIndex ) - { - return m_pool.getUtf8Info( m_pool.getNameAndTypeName( m_pool.getMemberNameAndType( memberrefIndex ) ) ); + public String getMemberrefName(int memberrefIndex) { + return m_pool.getUtf8Info(m_pool.getNameAndTypeName(m_pool.getMemberNameAndType(memberrefIndex))); } - public String getMemberrefType( int memberrefIndex ) - { - return m_pool.getUtf8Info( m_pool.getNameAndTypeDescriptor( m_pool.getMemberNameAndType( memberrefIndex ) ) ); + public String getMemberrefType(int memberrefIndex) { + return m_pool.getUtf8Info(m_pool.getNameAndTypeDescriptor(m_pool.getMemberNameAndType(memberrefIndex))); } - public ConstInfoAccessor getItem( int index ) - { - try - { - Object entry = m_getItem.invoke( m_pool, index ); - if( entry == null ) - { + public ConstInfoAccessor getItem(int index) { + try { + Object entry = m_getItem.invoke(m_pool, index); + if (entry == null) { return null; } - return new ConstInfoAccessor( entry ); - } - catch( Exception ex ) - { - throw new Error( ex ); + return new ConstInfoAccessor(entry); + } catch (Exception ex) { + throw new Error(ex); } } - public int addItem( Object item ) - { - try - { - return (Integer)m_addItem.invoke( m_pool, item ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public int addItem(Object item) { + try { + return (Integer)m_addItem.invoke(m_pool, item); + } catch (Exception ex) { + throw new Error(ex); } } - public int addItemForceNew( Object item ) - { - try - { - return (Integer)m_addItem0.invoke( m_pool, item ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public int addItemForceNew(Object item) { + try { + return (Integer)m_addItem0.invoke(m_pool, item); + } catch (Exception ex) { + throw new Error(ex); } } - @SuppressWarnings( "rawtypes" ) - public void removeLastItem( ) - { - try - { + + @SuppressWarnings("rawtypes") + public void removeLastItem() { + try { // remove the item from the cache HashMap cache = getCache(); - if( cache != null ) - { - Object item = getItem( m_pool.getSize() - 1 ); - cache.remove( item ); + if (cache != null) { + Object item = getItem(m_pool.getSize() - 1); + cache.remove(item); } // remove the actual item // based off of LongVector.addElement() - Object items = m_items.get( m_pool ); - Object[][] objects = (Object[][])m_objects.get( items ); - int numElements = (Integer)m_elements.get( items ) - 1; + Object items = m_items.get(m_pool); + Object[][] objects = (Object[][])m_objects.get(items); + int numElements = (Integer)m_elements.get(items) - 1; int nth = numElements >> 7; - int offset = numElements & (128 - 1); - objects[nth][offset] = null; + int offset = numElements & (128 - 1); + objects[nth][offset] = null; // decrement the number of items - m_elements.set( items, numElements ); - m_numItems.set( m_pool, (Integer)m_numItems.get( m_pool ) - 1 ); - } - catch( Exception ex ) - { - throw new Error( ex ); + m_elements.set(items, numElements); + m_numItems.set(m_pool, (Integer)m_numItems.get(m_pool) - 1); + } catch (Exception ex) { + throw new Error(ex); } } - @SuppressWarnings( "rawtypes" ) - /* TEMP */public HashMap getCache( ) - { - try - { - return (HashMap)m_cache.get( m_pool ); - } - catch( Exception ex ) - { - throw new Error( ex ); + @SuppressWarnings("rawtypes") + public HashMap getCache() { + try { + return (HashMap)m_cache.get(m_pool); + } catch (Exception ex) { + throw new Error(ex); } } - @SuppressWarnings( { "rawtypes", "unchecked" } ) - public void changeMemberrefNameAndType( int memberrefIndex, String newName, String newType ) - { + @SuppressWarnings({ "rawtypes", "unchecked" }) + public void changeMemberrefNameAndType(int memberrefIndex, String newName, String newType) { // NOTE: when changing values, we always need to copy-on-write - try - { + try { // get the memberref item - Object item = getItem( memberrefIndex ).getItem(); + Object item = getItem(memberrefIndex).getItem(); // update the cache HashMap cache = getCache(); - if( cache != null ) - { - cache.remove( item ); + if (cache != null) { + cache.remove(item); } - new MemberRefInfoAccessor( item ).setNameAndTypeIndex( m_pool.addNameAndTypeInfo( newName, newType ) ); + new MemberRefInfoAccessor(item).setNameAndTypeIndex(m_pool.addNameAndTypeInfo(newName, newType)); // update the cache - if( cache != null ) - { - cache.put( item, item ); + if (cache != null) { + cache.put(item, item); } - } - catch( Exception ex ) - { - throw new Error( ex ); + } catch (Exception ex) { + throw new Error(ex); } // make sure the change worked - assert( newName.equals( getMemberrefName( memberrefIndex ) ) ); - assert( newType.equals( getMemberrefType( memberrefIndex ) ) ); + assert (newName.equals(getMemberrefName(memberrefIndex))); + assert (newType.equals(getMemberrefType(memberrefIndex))); } - @SuppressWarnings( { "rawtypes", "unchecked" } ) - public void changeClassName( int classNameIndex, String newName ) - { + @SuppressWarnings({ "rawtypes", "unchecked" }) + public void changeClassName(int classNameIndex, String newName) { // NOTE: when changing values, we always need to copy-on-write - try - { + try { // get the class item - Object item = getItem( classNameIndex ).getItem(); + Object item = getItem(classNameIndex).getItem(); // update the cache HashMap cache = getCache(); - if( cache != null ) - { - cache.remove( item ); + if (cache != null) { + cache.remove(item); } // add the new name and repoint the name-and-type to it - new ClassInfoAccessor( item ).setNameIndex( m_pool.addUtf8Info( newName ) ); + new ClassInfoAccessor(item).setNameIndex(m_pool.addUtf8Info(newName)); // update the cache - if( cache != null ) - { - cache.put( item, item ); + if (cache != null) { + cache.put(item, item); } - } - catch( Exception ex ) - { - throw new Error( ex ); + } catch (Exception ex) { + throw new Error(ex); } } - public static ConstPool newConstPool( ) - { + public static ConstPool newConstPool() { // const pool expects the name of a class to initialize itself // but we want an empty pool // so give it a bogus name, and then clear the entries afterwards - ConstPool pool = new ConstPool( "a" ); + ConstPool pool = new ConstPool("a"); - ConstPoolEditor editor = new ConstPoolEditor( pool ); + ConstPoolEditor editor = new ConstPoolEditor(pool); int size = pool.getSize(); - for( int i=0; i indices, ConstPoolEditor editor, ConstInfoAccessor entry ) - { - ClassInfoAccessor accessor = new ClassInfoAccessor( entry.getItem() ); - gatherIndexTree( indices, editor, accessor.getNameIndex() ); + public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) { + ClassInfoAccessor accessor = new ClassInfoAccessor(entry.getItem()); + gatherIndexTree(indices, editor, accessor.getNameIndex()); } @Override - public void remapIndices( Map map, ConstInfoAccessor entry ) - { - ClassInfoAccessor accessor = new ClassInfoAccessor( entry.getItem() ); - accessor.setNameIndex( remapIndex( map, accessor.getNameIndex() ) ); + public void remapIndices(Map map, ConstInfoAccessor entry) { + ClassInfoAccessor accessor = new ClassInfoAccessor(entry.getItem()); + accessor.setNameIndex(remapIndex(map, accessor.getNameIndex())); } @Override - public boolean subIndicesAreValid( ConstInfoAccessor entry, ConstPoolEditor pool ) - { - ClassInfoAccessor accessor = new ClassInfoAccessor( entry.getItem() ); - ConstInfoAccessor nameEntry = pool.getItem( accessor.getNameIndex() ); + public boolean subIndicesAreValid(ConstInfoAccessor entry, ConstPoolEditor pool) { + ClassInfoAccessor accessor = new ClassInfoAccessor(entry.getItem()); + ConstInfoAccessor nameEntry = pool.getItem(accessor.getNameIndex()); return nameEntry != null && nameEntry.getTag() == Utf8Info.getTag(); } }, - StringInfo( 8, 1 ) - { + StringInfo( 8, 1 ) { + @Override - public void gatherIndexTree( Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry ) - { - StringInfoAccessor accessor = new StringInfoAccessor( entry.getItem() ); - gatherIndexTree( indices, editor, accessor.getStringIndex() ); + public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) { + StringInfoAccessor accessor = new StringInfoAccessor(entry.getItem()); + gatherIndexTree(indices, editor, accessor.getStringIndex()); } @Override - public void remapIndices( Map map, ConstInfoAccessor entry ) - { - StringInfoAccessor accessor = new StringInfoAccessor( entry.getItem() ); - accessor.setStringIndex( remapIndex( map, accessor.getStringIndex() ) ); + public void remapIndices(Map map, ConstInfoAccessor entry) { + StringInfoAccessor accessor = new StringInfoAccessor(entry.getItem()); + accessor.setStringIndex(remapIndex(map, accessor.getStringIndex())); } @Override - public boolean subIndicesAreValid( ConstInfoAccessor entry, ConstPoolEditor pool ) - { - StringInfoAccessor accessor = new StringInfoAccessor( entry.getItem() ); - ConstInfoAccessor stringEntry = pool.getItem( accessor.getStringIndex() ); + public boolean subIndicesAreValid(ConstInfoAccessor entry, ConstPoolEditor pool) { + StringInfoAccessor accessor = new StringInfoAccessor(entry.getItem()); + ConstInfoAccessor stringEntry = pool.getItem(accessor.getStringIndex()); return stringEntry != null && stringEntry.getTag() == Utf8Info.getTag(); } }, - FieldRefInfo( 9, 2 ) - { + FieldRefInfo( 9, 2 ) { + @Override - public void gatherIndexTree( Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry ) - { - MemberRefInfoAccessor accessor = new MemberRefInfoAccessor( entry.getItem() ); - gatherIndexTree( indices, editor, accessor.getClassIndex() ); - gatherIndexTree( indices, editor, accessor.getNameAndTypeIndex() ); + public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) { + MemberRefInfoAccessor accessor = new MemberRefInfoAccessor(entry.getItem()); + gatherIndexTree(indices, editor, accessor.getClassIndex()); + gatherIndexTree(indices, editor, accessor.getNameAndTypeIndex()); } @Override - public void remapIndices( Map map, ConstInfoAccessor entry ) - { - MemberRefInfoAccessor accessor = new MemberRefInfoAccessor( entry.getItem() ); - accessor.setClassIndex( remapIndex( map, accessor.getClassIndex() ) ); - accessor.setNameAndTypeIndex( remapIndex( map, accessor.getNameAndTypeIndex() ) ); + public void remapIndices(Map map, ConstInfoAccessor entry) { + MemberRefInfoAccessor accessor = new MemberRefInfoAccessor(entry.getItem()); + accessor.setClassIndex(remapIndex(map, accessor.getClassIndex())); + accessor.setNameAndTypeIndex(remapIndex(map, accessor.getNameAndTypeIndex())); } - + @Override - public boolean subIndicesAreValid( ConstInfoAccessor entry, ConstPoolEditor pool ) - { - MemberRefInfoAccessor accessor = new MemberRefInfoAccessor( entry.getItem() ); - ConstInfoAccessor classEntry = pool.getItem( accessor.getClassIndex() ); - ConstInfoAccessor nameAndTypeEntry = pool.getItem( accessor.getNameAndTypeIndex() ); - return classEntry != null && classEntry.getTag() == ClassInfo.getTag() - && nameAndTypeEntry != null && nameAndTypeEntry.getTag() == NameAndTypeInfo.getTag(); + public boolean subIndicesAreValid(ConstInfoAccessor entry, ConstPoolEditor pool) { + MemberRefInfoAccessor accessor = new MemberRefInfoAccessor(entry.getItem()); + ConstInfoAccessor classEntry = pool.getItem(accessor.getClassIndex()); + ConstInfoAccessor nameAndTypeEntry = pool.getItem(accessor.getNameAndTypeIndex()); + return classEntry != null && classEntry.getTag() == ClassInfo.getTag() && nameAndTypeEntry != null && nameAndTypeEntry.getTag() == NameAndTypeInfo.getTag(); } }, - MethodRefInfo( 10, 2 ) // same as FieldRefInfo - { + // same as FieldRefInfo + MethodRefInfo( 10, 2 ) { + @Override - public void gatherIndexTree( Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry ) - { - FieldRefInfo.gatherIndexTree( indices, editor, entry ); + public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) { + FieldRefInfo.gatherIndexTree(indices, editor, entry); } @Override - public void remapIndices( Map map, ConstInfoAccessor entry ) - { - FieldRefInfo.remapIndices( map, entry ); + public void remapIndices(Map map, ConstInfoAccessor entry) { + FieldRefInfo.remapIndices(map, entry); } - + @Override - public boolean subIndicesAreValid( ConstInfoAccessor entry, ConstPoolEditor pool ) - { - return FieldRefInfo.subIndicesAreValid( entry, pool ); + public boolean subIndicesAreValid(ConstInfoAccessor entry, ConstPoolEditor pool) { + return FieldRefInfo.subIndicesAreValid(entry, pool); } }, - InterfaceMethodRefInfo( 11, 2 ) // same as FieldRefInfo - { + // same as FieldRefInfo + InterfaceMethodRefInfo( 11, 2 ) { + @Override - public void gatherIndexTree( Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry ) - { - FieldRefInfo.gatherIndexTree( indices, editor, entry ); + public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) { + FieldRefInfo.gatherIndexTree(indices, editor, entry); } @Override - public void remapIndices( Map map, ConstInfoAccessor entry ) - { - FieldRefInfo.remapIndices( map, entry ); + public void remapIndices(Map map, ConstInfoAccessor entry) { + FieldRefInfo.remapIndices(map, entry); } - + @Override - public boolean subIndicesAreValid( ConstInfoAccessor entry, ConstPoolEditor pool ) - { - return FieldRefInfo.subIndicesAreValid( entry, pool ); + public boolean subIndicesAreValid(ConstInfoAccessor entry, ConstPoolEditor pool) { + return FieldRefInfo.subIndicesAreValid(entry, pool); } }, - NameAndTypeInfo( 12, 1 ) - { + NameAndTypeInfo( 12, 1 ) { + @Override - public void gatherIndexTree( Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry ) - { - NameAndTypeInfoAccessor accessor = new NameAndTypeInfoAccessor( entry.getItem() ); - gatherIndexTree( indices, editor, accessor.getNameIndex() ); - gatherIndexTree( indices, editor, accessor.getTypeIndex() ); + public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) { + NameAndTypeInfoAccessor accessor = new NameAndTypeInfoAccessor(entry.getItem()); + gatherIndexTree(indices, editor, accessor.getNameIndex()); + gatherIndexTree(indices, editor, accessor.getTypeIndex()); } @Override - public void remapIndices( Map map, ConstInfoAccessor entry ) - { - NameAndTypeInfoAccessor accessor = new NameAndTypeInfoAccessor( entry.getItem() ); - accessor.setNameIndex( remapIndex( map, accessor.getNameIndex() ) ); - accessor.setTypeIndex( remapIndex( map, accessor.getTypeIndex() ) ); + public void remapIndices(Map map, ConstInfoAccessor entry) { + NameAndTypeInfoAccessor accessor = new NameAndTypeInfoAccessor(entry.getItem()); + accessor.setNameIndex(remapIndex(map, accessor.getNameIndex())); + accessor.setTypeIndex(remapIndex(map, accessor.getTypeIndex())); } @Override - public boolean subIndicesAreValid( ConstInfoAccessor entry, ConstPoolEditor pool ) - { - NameAndTypeInfoAccessor accessor = new NameAndTypeInfoAccessor( entry.getItem() ); - ConstInfoAccessor nameEntry = pool.getItem( accessor.getNameIndex() ); - ConstInfoAccessor typeEntry = pool.getItem( accessor.getTypeIndex() ); - return nameEntry != null && nameEntry.getTag() == Utf8Info.getTag() - && typeEntry != null && typeEntry.getTag() == Utf8Info.getTag(); + public boolean subIndicesAreValid(ConstInfoAccessor entry, ConstPoolEditor pool) { + NameAndTypeInfoAccessor accessor = new NameAndTypeInfoAccessor(entry.getItem()); + ConstInfoAccessor nameEntry = pool.getItem(accessor.getNameIndex()); + ConstInfoAccessor typeEntry = pool.getItem(accessor.getTypeIndex()); + return nameEntry != null && nameEntry.getTag() == Utf8Info.getTag() && typeEntry != null && typeEntry.getTag() == Utf8Info.getTag(); } }, - MethodHandleInfo( 15, 3 ) - { + MethodHandleInfo( 15, 3 ) { + @Override - public void gatherIndexTree( Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry ) - { - MethodHandleInfoAccessor accessor = new MethodHandleInfoAccessor( entry.getItem() ); - gatherIndexTree( indices, editor, accessor.getTypeIndex() ); - gatherIndexTree( indices, editor, accessor.getMethodRefIndex() ); + public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) { + MethodHandleInfoAccessor accessor = new MethodHandleInfoAccessor(entry.getItem()); + gatherIndexTree(indices, editor, accessor.getTypeIndex()); + gatherIndexTree(indices, editor, accessor.getMethodRefIndex()); } @Override - public void remapIndices( Map map, ConstInfoAccessor entry ) - { - MethodHandleInfoAccessor accessor = new MethodHandleInfoAccessor( entry.getItem() ); - accessor.setTypeIndex( remapIndex( map, accessor.getTypeIndex() ) ); - accessor.setMethodRefIndex( remapIndex( map, accessor.getMethodRefIndex() ) ); + public void remapIndices(Map map, ConstInfoAccessor entry) { + MethodHandleInfoAccessor accessor = new MethodHandleInfoAccessor(entry.getItem()); + accessor.setTypeIndex(remapIndex(map, accessor.getTypeIndex())); + accessor.setMethodRefIndex(remapIndex(map, accessor.getMethodRefIndex())); } - + @Override - public boolean subIndicesAreValid( ConstInfoAccessor entry, ConstPoolEditor pool ) - { - MethodHandleInfoAccessor accessor = new MethodHandleInfoAccessor( entry.getItem() ); - ConstInfoAccessor typeEntry = pool.getItem( accessor.getTypeIndex() ); - ConstInfoAccessor methodRefEntry = pool.getItem( accessor.getMethodRefIndex() ); - return typeEntry != null && typeEntry.getTag() == Utf8Info.getTag() - && methodRefEntry != null && methodRefEntry.getTag() == MethodRefInfo.getTag(); + public boolean subIndicesAreValid(ConstInfoAccessor entry, ConstPoolEditor pool) { + MethodHandleInfoAccessor accessor = new MethodHandleInfoAccessor(entry.getItem()); + ConstInfoAccessor typeEntry = pool.getItem(accessor.getTypeIndex()); + ConstInfoAccessor methodRefEntry = pool.getItem(accessor.getMethodRefIndex()); + return typeEntry != null && typeEntry.getTag() == Utf8Info.getTag() && methodRefEntry != null && methodRefEntry.getTag() == MethodRefInfo.getTag(); } }, - MethodTypeInfo( 16, 1 ) - { + MethodTypeInfo( 16, 1 ) { + @Override - public void gatherIndexTree( Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry ) - { - MethodTypeInfoAccessor accessor = new MethodTypeInfoAccessor( entry.getItem() ); - gatherIndexTree( indices, editor, accessor.getTypeIndex() ); + public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) { + MethodTypeInfoAccessor accessor = new MethodTypeInfoAccessor(entry.getItem()); + gatherIndexTree(indices, editor, accessor.getTypeIndex()); } @Override - public void remapIndices( Map map, ConstInfoAccessor entry ) - { - MethodTypeInfoAccessor accessor = new MethodTypeInfoAccessor( entry.getItem() ); - accessor.setTypeIndex( remapIndex( map, accessor.getTypeIndex() ) ); + public void remapIndices(Map map, ConstInfoAccessor entry) { + MethodTypeInfoAccessor accessor = new MethodTypeInfoAccessor(entry.getItem()); + accessor.setTypeIndex(remapIndex(map, accessor.getTypeIndex())); } - + @Override - public boolean subIndicesAreValid( ConstInfoAccessor entry, ConstPoolEditor pool ) - { - MethodTypeInfoAccessor accessor = new MethodTypeInfoAccessor( entry.getItem() ); - ConstInfoAccessor typeEntry = pool.getItem( accessor.getTypeIndex() ); + public boolean subIndicesAreValid(ConstInfoAccessor entry, ConstPoolEditor pool) { + MethodTypeInfoAccessor accessor = new MethodTypeInfoAccessor(entry.getItem()); + ConstInfoAccessor typeEntry = pool.getItem(accessor.getTypeIndex()); return typeEntry != null && typeEntry.getTag() == Utf8Info.getTag(); } }, - InvokeDynamicInfo( 18, 2 ) - { + InvokeDynamicInfo( 18, 2 ) { + @Override - public void gatherIndexTree( Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry ) - { - InvokeDynamicInfoAccessor accessor = new InvokeDynamicInfoAccessor( entry.getItem() ); - gatherIndexTree( indices, editor, accessor.getBootstrapIndex() ); - gatherIndexTree( indices, editor, accessor.getNameAndTypeIndex() ); + public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) { + InvokeDynamicInfoAccessor accessor = new InvokeDynamicInfoAccessor(entry.getItem()); + gatherIndexTree(indices, editor, accessor.getBootstrapIndex()); + gatherIndexTree(indices, editor, accessor.getNameAndTypeIndex()); } @Override - public void remapIndices( Map map, ConstInfoAccessor entry ) - { - InvokeDynamicInfoAccessor accessor = new InvokeDynamicInfoAccessor( entry.getItem() ); - accessor.setBootstrapIndex( remapIndex( map, accessor.getBootstrapIndex() ) ); - accessor.setNameAndTypeIndex( remapIndex( map, accessor.getNameAndTypeIndex() ) ); + public void remapIndices(Map map, ConstInfoAccessor entry) { + InvokeDynamicInfoAccessor accessor = new InvokeDynamicInfoAccessor(entry.getItem()); + accessor.setBootstrapIndex(remapIndex(map, accessor.getBootstrapIndex())); + accessor.setNameAndTypeIndex(remapIndex(map, accessor.getNameAndTypeIndex())); } - + @Override - public boolean subIndicesAreValid( ConstInfoAccessor entry, ConstPoolEditor pool ) - { - InvokeDynamicInfoAccessor accessor = new InvokeDynamicInfoAccessor( entry.getItem() ); - ConstInfoAccessor bootstrapEntry = pool.getItem( accessor.getBootstrapIndex() ); - ConstInfoAccessor nameAndTypeEntry = pool.getItem( accessor.getNameAndTypeIndex() ); - return bootstrapEntry != null && bootstrapEntry.getTag() == Utf8Info.getTag() - && nameAndTypeEntry != null && nameAndTypeEntry.getTag() == NameAndTypeInfo.getTag(); + public boolean subIndicesAreValid(ConstInfoAccessor entry, ConstPoolEditor pool) { + InvokeDynamicInfoAccessor accessor = new InvokeDynamicInfoAccessor(entry.getItem()); + ConstInfoAccessor bootstrapEntry = pool.getItem(accessor.getBootstrapIndex()); + ConstInfoAccessor nameAndTypeEntry = pool.getItem(accessor.getNameAndTypeIndex()); + return bootstrapEntry != null && bootstrapEntry.getTag() == Utf8Info.getTag() && nameAndTypeEntry != null && nameAndTypeEntry.getTag() == NameAndTypeInfo.getTag(); } }; private static Map m_types; - static - { + static { m_types = Maps.newTreeMap(); - for( InfoType type : values() ) - { - m_types.put( type.getTag(), type ); + for (InfoType type : values()) { + m_types.put(type.getTag(), type); } } private int m_tag; private int m_level; - private InfoType( int tag, int level ) - { + private InfoType(int tag, int level) { m_tag = tag; m_level = level; } - public int getTag( ) - { + public int getTag() { return m_tag; } - public int getLevel( ) - { + public int getLevel() { return m_level; } - public void gatherIndexTree( Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry ) - { + public void gatherIndexTree(Collection indices, ConstPoolEditor editor, ConstInfoAccessor entry) { // by default, do nothing } - public void remapIndices( Map map, ConstInfoAccessor entry ) - { + public void remapIndices(Map map, ConstInfoAccessor entry) { // by default, do nothing } - public boolean subIndicesAreValid( ConstInfoAccessor entry, ConstPoolEditor pool ) - { + public boolean subIndicesAreValid(ConstInfoAccessor entry, ConstPoolEditor pool) { // by default, everything is good return true; } - public boolean selfIndexIsValid( ConstInfoAccessor entry, ConstPoolEditor pool ) - { - ConstInfoAccessor entryCheck = pool.getItem( entry.getIndex() ); - if( entryCheck == null ) - { + public boolean selfIndexIsValid(ConstInfoAccessor entry, ConstPoolEditor pool) { + ConstInfoAccessor entryCheck = pool.getItem(entry.getIndex()); + if (entryCheck == null) { return false; } - return entryCheck.getItem().equals( entry.getItem() ); + return entryCheck.getItem().equals(entry.getItem()); } - public static InfoType getByTag( int tag ) - { - return m_types.get( tag ); + public static InfoType getByTag(int tag) { + return m_types.get(tag); } - public static List getByLevel( int level ) - { + public static List getByLevel(int level) { List types = Lists.newArrayList(); - for( InfoType type : values() ) - { - if( type.getLevel() == level ) - { - types.add( type ); + for (InfoType type : values()) { + if (type.getLevel() == level) { + types.add(type); } } return types; } - public static List getSortedByLevel( ) - { + public static List getSortedByLevel() { List types = Lists.newArrayList(); - types.addAll( getByLevel( 0 ) ); - types.addAll( getByLevel( 1 ) ); - types.addAll( getByLevel( 2 ) ); - types.addAll( getByLevel( 3 ) ); + types.addAll(getByLevel(0)); + types.addAll(getByLevel(1)); + types.addAll(getByLevel(2)); + types.addAll(getByLevel(3)); return types; } - public static void gatherIndexTree( Collection indices, ConstPoolEditor editor, int index ) - { + public static void gatherIndexTree(Collection indices, ConstPoolEditor editor, int index) { // add own index - indices.add( index ); + indices.add(index); // recurse - ConstInfoAccessor entry = editor.getItem( index ); - entry.getType().gatherIndexTree( indices, editor, entry ); + ConstInfoAccessor entry = editor.getItem(index); + entry.getType().gatherIndexTree(indices, editor, entry); } - private static int remapIndex( Map map, int index ) - { - Integer newIndex = map.get( index ); - if( newIndex == null ) - { + private static int remapIndex(Map map, int index) { + Integer newIndex = map.get(index); + if (newIndex == null) { newIndex = index; } return newIndex; diff --git a/src/cuchaz/enigma/bytecode/InnerClassWriter.java b/src/cuchaz/enigma/bytecode/InnerClassWriter.java index 5e59307..f52c31a 100644 --- a/src/cuchaz/enigma/bytecode/InnerClassWriter.java +++ b/src/cuchaz/enigma/bytecode/InnerClassWriter.java @@ -23,105 +23,80 @@ import cuchaz.enigma.analysis.JarIndex; import cuchaz.enigma.mapping.BehaviorEntry; import cuchaz.enigma.mapping.ClassEntry; -public class InnerClassWriter -{ +public class InnerClassWriter { + private JarIndex m_jarIndex; - public InnerClassWriter( JarIndex jarIndex ) - { + public InnerClassWriter(JarIndex jarIndex) { m_jarIndex = jarIndex; } - public void write( CtClass c ) - { + public void write(CtClass c) { + // is this an inner or outer class? - String obfInnerClassName = new ClassEntry( Descriptor.toJvmName( c.getName() ) ).getSimpleName(); - String obfOuterClassName = m_jarIndex.getOuterClass( obfInnerClassName ); - if( obfOuterClassName == null ) - { + String obfInnerClassName = new ClassEntry(Descriptor.toJvmName(c.getName())).getSimpleName(); + String obfOuterClassName = m_jarIndex.getOuterClass(obfInnerClassName); + if (obfOuterClassName == null) { // this is an outer class - obfOuterClassName = Descriptor.toJvmName( c.getName() ); - } - else - { + obfOuterClassName = Descriptor.toJvmName(c.getName()); + } else { // this is an inner class, rename it to outer$inner - ClassEntry obfClassEntry = new ClassEntry( obfOuterClassName + "$" + obfInnerClassName ); - c.setName( obfClassEntry.getName() ); + ClassEntry obfClassEntry = new ClassEntry(obfOuterClassName + "$" + obfInnerClassName); + c.setName(obfClassEntry.getName()); - BehaviorEntry caller = m_jarIndex.getAnonymousClassCaller( obfInnerClassName ); - if( caller != null ) - { + BehaviorEntry caller = m_jarIndex.getAnonymousClassCaller(obfInnerClassName); + if (caller != null) { // write the enclosing method attribute - if( caller.getName().equals( "" ) ) - { - c.getClassFile().addAttribute( new EnclosingMethodAttribute( - c.getClassFile().getConstPool(), - caller.getClassName() - ) ); - } - else - { - c.getClassFile().addAttribute( new EnclosingMethodAttribute( - c.getClassFile().getConstPool(), - caller.getClassName(), - caller.getName(), - caller.getSignature() - ) ); + if (caller.getName().equals("")) { + c.getClassFile().addAttribute(new EnclosingMethodAttribute(c.getClassFile().getConstPool(), caller.getClassName())); + } else { + c.getClassFile().addAttribute(new EnclosingMethodAttribute(c.getClassFile().getConstPool(), caller.getClassName(), caller.getName(), caller.getSignature())); } } } // write the inner classes if needed - Collection obfInnerClassNames = m_jarIndex.getInnerClasses( obfOuterClassName ); - if( obfInnerClassNames != null && !obfInnerClassNames.isEmpty() ) - { - writeInnerClasses( c, obfOuterClassName, obfInnerClassNames ); + Collection obfInnerClassNames = m_jarIndex.getInnerClasses(obfOuterClassName); + if (obfInnerClassNames != null && !obfInnerClassNames.isEmpty()) { + writeInnerClasses(c, obfOuterClassName, obfInnerClassNames); } } - private void writeInnerClasses( CtClass c, String obfOuterClassName, Collection obfInnerClassNames ) - { - InnerClassesAttribute attr = new InnerClassesAttribute( c.getClassFile().getConstPool() ); - c.getClassFile().addAttribute( attr ); - for( String obfInnerClassName : obfInnerClassNames ) - { + private void writeInnerClasses(CtClass c, String obfOuterClassName, Collection obfInnerClassNames) { + InnerClassesAttribute attr = new InnerClassesAttribute(c.getClassFile().getConstPool()); + c.getClassFile().addAttribute(attr); + for (String obfInnerClassName : obfInnerClassNames) { // get the new inner class name - ClassEntry obfClassEntry = new ClassEntry( obfOuterClassName + "$" + obfInnerClassName ); + ClassEntry obfClassEntry = new ClassEntry(obfOuterClassName + "$" + obfInnerClassName); // here's what the JVM spec says about the InnerClasses attribute - // append( inner, outer of inner if inner is member of outer 0 ow, name after $ if inner not anonymous 0 ow, flags ); + // append( inner, outer of inner if inner is member of outer 0 ow, name after $ if inner not anonymous 0 ow, flags ); // update the attribute with this inner class ConstPool constPool = c.getClassFile().getConstPool(); - int innerClassIndex = constPool.addClassInfo( obfClassEntry.getName() ); + int innerClassIndex = constPool.addClassInfo(obfClassEntry.getName()); int outerClassIndex = 0; int innerClassSimpleNameIndex = 0; - if( !m_jarIndex.isAnonymousClass( obfInnerClassName ) ) - { - outerClassIndex = constPool.addClassInfo( obfClassEntry.getOuterClassName() ); - innerClassSimpleNameIndex = constPool.addUtf8Info( obfClassEntry.getInnerClassName() ); + if (!m_jarIndex.isAnonymousClass(obfInnerClassName)) { + outerClassIndex = constPool.addClassInfo(obfClassEntry.getOuterClassName()); + innerClassSimpleNameIndex = constPool.addUtf8Info(obfClassEntry.getInnerClassName()); } - attr.append( - innerClassIndex, - outerClassIndex, - innerClassSimpleNameIndex, - c.getClassFile().getAccessFlags() & ~AccessFlag.SUPER - ); + attr.append(innerClassIndex, outerClassIndex, innerClassSimpleNameIndex, c.getClassFile().getAccessFlags() & ~AccessFlag.SUPER); - /* DEBUG - System.out.println( String.format( "\tOBF: %s -> ATTR: %s,%s,%s (replace %s with %s)", + /* DEBUG + System.out.println(String.format("\tOBF: %s -> ATTR: %s,%s,%s (replace %s with %s)", obfClassEntry, - attr.outerClass( attr.tableLength() - 1 ), - attr.innerClass( attr.tableLength() - 1 ), - attr.innerName( attr.tableLength() - 1 ), + attr.outerClass(attr.tableLength() - 1), + attr.innerClass(attr.tableLength() - 1), + attr.innerName(attr.tableLength() - 1), Constants.NonePackage + "/" + obfInnerClassName, obfClassEntry.getName() - ) ); + )); */ // make sure the outer class references only the new inner class names - c.replaceClassName( Constants.NonePackage + "/" + obfInnerClassName, obfClassEntry.getName() ); + c.replaceClassName(Constants.NonePackage + "/" + obfInnerClassName, obfClassEntry.getName()); } } } diff --git a/src/cuchaz/enigma/bytecode/MethodParameterWriter.java b/src/cuchaz/enigma/bytecode/MethodParameterWriter.java index adea7ea..5a11cd8 100644 --- a/src/cuchaz/enigma/bytecode/MethodParameterWriter.java +++ b/src/cuchaz/enigma/bytecode/MethodParameterWriter.java @@ -25,51 +25,42 @@ import cuchaz.enigma.mapping.ConstructorEntry; import cuchaz.enigma.mapping.MethodEntry; import cuchaz.enigma.mapping.Translator; -public class MethodParameterWriter -{ +public class MethodParameterWriter { + private Translator m_translator; - public MethodParameterWriter( Translator translator ) - { + public MethodParameterWriter(Translator translator) { m_translator = translator; } - public void writeMethodArguments( CtClass c ) - { + public void writeMethodArguments(CtClass c) { + // Procyon will read method arguments from the "MethodParameters" attribute, so write those - ClassEntry classEntry = new ClassEntry( Descriptor.toJvmName( c.getName() ) ); - for( CtBehavior behavior : c.getDeclaredBehaviors() ) - { - int numParams = Descriptor.numOfParameters( behavior.getMethodInfo().getDescriptor() ); - if( numParams <= 0 ) - { + ClassEntry classEntry = new ClassEntry(Descriptor.toJvmName(c.getName())); + for (CtBehavior behavior : c.getDeclaredBehaviors()) { + int numParams = Descriptor.numOfParameters(behavior.getMethodInfo().getDescriptor()); + if (numParams <= 0) { continue; } // get the behavior entry BehaviorEntry behaviorEntry; - if( behavior instanceof CtMethod ) - { - behaviorEntry = new MethodEntry( classEntry, behavior.getMethodInfo().getName(), behavior.getSignature() ); - } - else if( behavior instanceof CtConstructor ) - { - behaviorEntry = new ConstructorEntry( classEntry, behavior.getSignature() ); - } - else - { - throw new Error( "Unsupported behavior type: " + behavior.getClass().getName() ); + if (behavior instanceof CtMethod) { + behaviorEntry = new MethodEntry(classEntry, behavior.getMethodInfo().getName(), behavior.getSignature()); + } else if (behavior instanceof CtConstructor) { + behaviorEntry = new ConstructorEntry(classEntry, behavior.getSignature()); + } else { + throw new Error("Unsupported behavior type: " + behavior.getClass().getName()); } // get the list of parameter names - List names = new ArrayList( numParams ); - for( int i=0; i names = new ArrayList(numParams); + for (int i = 0; i < numParams; i++) { + names.add(m_translator.translate(new ArgumentEntry(behaviorEntry, i, ""))); } // save the mappings to the class - MethodParametersAttribute.updateClass( behavior.getMethodInfo(), names ); + MethodParametersAttribute.updateClass(behavior.getMethodInfo(), names); } } } diff --git a/src/cuchaz/enigma/bytecode/MethodParametersAttribute.java b/src/cuchaz/enigma/bytecode/MethodParametersAttribute.java index baf1ac1..bf95956 100644 --- a/src/cuchaz/enigma/bytecode/MethodParametersAttribute.java +++ b/src/cuchaz/enigma/bytecode/MethodParametersAttribute.java @@ -20,45 +20,38 @@ import javassist.bytecode.AttributeInfo; import javassist.bytecode.ConstPool; import javassist.bytecode.MethodInfo; -public class MethodParametersAttribute extends AttributeInfo -{ - private MethodParametersAttribute( ConstPool pool, List parameterNameIndices ) - { - super( pool, "MethodParameters", writeStruct( parameterNameIndices ) ); +public class MethodParametersAttribute extends AttributeInfo { + + private MethodParametersAttribute(ConstPool pool, List parameterNameIndices) { + super(pool, "MethodParameters", writeStruct(parameterNameIndices)); } - public static void updateClass( MethodInfo info, List names ) - { + public static void updateClass(MethodInfo info, List names) { // add the names to the class const pool ConstPool constPool = info.getConstPool(); List parameterNameIndices = new ArrayList(); - for( String name : names ) - { - if( name != null ) - { - parameterNameIndices.add( constPool.addUtf8Info( name ) ); - } - else - { - parameterNameIndices.add( 0 ); + for (String name : names) { + if (name != null) { + parameterNameIndices.add(constPool.addUtf8Info(name)); + } else { + parameterNameIndices.add(0); } } // add the attribute to the method - info.addAttribute( new MethodParametersAttribute( constPool, parameterNameIndices ) ); + info.addAttribute(new MethodParametersAttribute(constPool, parameterNameIndices)); } - private static byte[] writeStruct( List parameterNameIndices ) - { + private static byte[] writeStruct(List parameterNameIndices) { // JVM 8 Spec says the struct looks like this: // http://cr.openjdk.java.net/~mr/se/8/java-se-8-fr-spec-01/java-se-8-jvms-fr-diffs.pdf // uint8 num_params // for each param: - // uint16 name_index -> points to UTF8 entry in constant pool, or 0 for no entry - // uint16 access_flags -> don't care, just set to 0 + // uint16 name_index -> points to UTF8 entry in constant pool, or 0 for no entry + // uint16 access_flags -> don't care, just set to 0 ByteArrayOutputStream buf = new ByteArrayOutputStream(); - DataOutputStream out = new DataOutputStream( buf ); + DataOutputStream out = new DataOutputStream(buf); // NOTE: java hates unsigned integers, so we have to be careful here // the writeShort(), writeByte() methods will read 16,8 low-order bits from the int argument @@ -66,31 +59,27 @@ public class MethodParametersAttribute extends AttributeInfo // if the int is out of range, the byte stream won't look the way we want and weird things will happen final int SIZEOF_UINT8 = 1; final int SIZEOF_UINT16 = 2; - final int MAX_UINT8 = ( 1 << 8 ) - 1; - final int MAX_UINT16 = ( 1 << 16 ) - 1; + final int MAX_UINT8 = (1 << 8) - 1; + final int MAX_UINT16 = (1 << 16) - 1; - try - { - assert( parameterNameIndices.size() >= 0 && parameterNameIndices.size() <= MAX_UINT8 ); - out.writeByte( parameterNameIndices.size() ); + try { + assert (parameterNameIndices.size() >= 0 && parameterNameIndices.size() <= MAX_UINT8); + out.writeByte(parameterNameIndices.size()); - for( Integer index : parameterNameIndices ) - { - assert( index >= 0 && index <= MAX_UINT16 ); - out.writeShort( index ); + for (Integer index : parameterNameIndices) { + assert (index >= 0 && index <= MAX_UINT16); + out.writeShort(index); // just write 0 for the access flags - out.writeShort( 0 ); + out.writeShort(0); } out.close(); byte[] data = buf.toByteArray(); - assert( data.length == SIZEOF_UINT8 + parameterNameIndices.size()*( SIZEOF_UINT16 + SIZEOF_UINT16 ) ); + assert (data.length == SIZEOF_UINT8 + parameterNameIndices.size() * (SIZEOF_UINT16 + SIZEOF_UINT16)); return data; - } - catch( IOException ex ) - { - throw new Error( ex ); + } catch (IOException ex) { + throw new Error(ex); } } } diff --git a/src/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java index 41e1d04..d76f056 100644 --- a/src/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java +++ b/src/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java @@ -12,58 +12,44 @@ package cuchaz.enigma.bytecode.accessors; import java.lang.reflect.Field; -public class ClassInfoAccessor -{ +public class ClassInfoAccessor { + private static Class m_class; private static Field m_nameIndex; - static - { - try - { - m_class = Class.forName( "javassist.bytecode.ClassInfo" ); - m_nameIndex = m_class.getDeclaredField( "name" ); - m_nameIndex.setAccessible( true ); - } - catch( Exception ex ) - { - throw new Error( ex ); + static { + try { + m_class = Class.forName("javassist.bytecode.ClassInfo"); + m_nameIndex = m_class.getDeclaredField("name"); + m_nameIndex.setAccessible(true); + } catch (Exception ex) { + throw new Error(ex); } } - public static boolean isType( ConstInfoAccessor accessor ) - { - return m_class.isAssignableFrom( accessor.getItem().getClass() ); + public static boolean isType(ConstInfoAccessor accessor) { + return m_class.isAssignableFrom(accessor.getItem().getClass()); } private Object m_item; - public ClassInfoAccessor( Object item ) - { + public ClassInfoAccessor(Object item) { m_item = item; } - public int getNameIndex( ) - { - try - { - return (Integer)m_nameIndex.get( m_item ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public int getNameIndex() { + try { + return (Integer)m_nameIndex.get(m_item); + } catch (Exception ex) { + throw new Error(ex); } } - public void setNameIndex( int val ) - { - try - { - m_nameIndex.set( m_item, val ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public void setNameIndex(int val) { + try { + m_nameIndex.set(m_item, val); + } catch (Exception ex) { + throw new Error(ex); } } } diff --git a/src/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java index 3c3d3fa..d00c102 100644 --- a/src/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java +++ b/src/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java @@ -22,44 +22,35 @@ import java.lang.reflect.Method; import cuchaz.enigma.bytecode.InfoType; -public class ConstInfoAccessor -{ +public class ConstInfoAccessor { + private static Class m_class; private static Field m_index; private static Method m_getTag; - static - { - try - { - m_class = Class.forName( "javassist.bytecode.ConstInfo" ); - m_index = m_class.getDeclaredField( "index" ); - m_index.setAccessible( true ); - m_getTag = m_class.getMethod( "getTag" ); - m_getTag.setAccessible( true ); - } - catch( Exception ex ) - { - throw new Error( ex ); + static { + try { + m_class = Class.forName("javassist.bytecode.ConstInfo"); + m_index = m_class.getDeclaredField("index"); + m_index.setAccessible(true); + m_getTag = m_class.getMethod("getTag"); + m_getTag.setAccessible(true); + } catch (Exception ex) { + throw new Error(ex); } } private Object m_item; - public ConstInfoAccessor( Object item ) - { - if( item == null ) - { - throw new IllegalArgumentException( "item cannot be null!" ); + public ConstInfoAccessor(Object item) { + if (item == null) { + throw new IllegalArgumentException("item cannot be null!"); } m_item = item; } - public ConstInfoAccessor( DataInputStream in ) - throws IOException - { - try - { + public ConstInfoAccessor(DataInputStream in) throws IOException { + try { // read the entry String className = in.readUTF(); int oldIndex = in.readInt(); @@ -68,132 +59,98 @@ public class ConstInfoAccessor // so we have to read it here in.readByte(); - Constructor constructor = Class.forName( className ).getConstructor( DataInputStream.class, int.class ); - constructor.setAccessible( true ); - m_item = constructor.newInstance( in, oldIndex ); - } - catch( IOException ex ) - { + Constructor constructor = Class.forName(className).getConstructor(DataInputStream.class, int.class); + constructor.setAccessible(true); + m_item = constructor.newInstance(in, oldIndex); + } catch (IOException ex) { throw ex; - } - catch( Exception ex ) - { - throw new Error( ex ); + } catch (Exception ex) { + throw new Error(ex); } } - public Object getItem( ) - { + public Object getItem() { return m_item; } - public int getIndex( ) - { - try - { - return (Integer)m_index.get( m_item ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public int getIndex() { + try { + return (Integer)m_index.get(m_item); + } catch (Exception ex) { + throw new Error(ex); } } - public void setIndex( int val ) - { - try - { - m_index.set( m_item, val ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public void setIndex(int val) { + try { + m_index.set(m_item, val); + } catch (Exception ex) { + throw new Error(ex); } } - public int getTag( ) - { - try - { - return (Integer)m_getTag.invoke( m_item ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public int getTag() { + try { + return (Integer)m_getTag.invoke(m_item); + } catch (Exception ex) { + throw new Error(ex); } } - public ConstInfoAccessor copy( ) - { - return new ConstInfoAccessor( copyItem() ); + public ConstInfoAccessor copy() { + return new ConstInfoAccessor(copyItem()); } - public Object copyItem( ) - { + public Object copyItem() { // I don't know of a simpler way to copy one of these silly things... - try - { + try { // serialize the item ByteArrayOutputStream buf = new ByteArrayOutputStream(); - DataOutputStream out = new DataOutputStream( buf ); - write( out ); + DataOutputStream out = new DataOutputStream(buf); + write(out); // deserialize the item - DataInputStream in = new DataInputStream( new ByteArrayInputStream( buf.toByteArray() ) ); - Object item = new ConstInfoAccessor( in ).getItem(); + DataInputStream in = new DataInputStream(new ByteArrayInputStream(buf.toByteArray())); + Object item = new ConstInfoAccessor(in).getItem(); in.close(); return item; - } - catch( Exception ex ) - { - throw new Error( ex ); + } catch (Exception ex) { + throw new Error(ex); } } - public void write( DataOutputStream out ) - throws IOException - { - try - { - out.writeUTF( m_item.getClass().getName() ); - out.writeInt( getIndex() ); + public void write(DataOutputStream out) throws IOException { + try { + out.writeUTF(m_item.getClass().getName()); + out.writeInt(getIndex()); - Method method = m_item.getClass().getMethod( "write", DataOutputStream.class ); - method.setAccessible( true ); - method.invoke( m_item, out ); - } - catch( IOException ex ) - { + Method method = m_item.getClass().getMethod("write", DataOutputStream.class); + method.setAccessible(true); + method.invoke(m_item, out); + } catch (IOException ex) { throw ex; - } - catch( Exception ex ) - { - throw new Error( ex ); + } catch (Exception ex) { + throw new Error(ex); } } @Override - public String toString( ) - { - try - { + public String toString() { + try { ByteArrayOutputStream buf = new ByteArrayOutputStream(); - PrintWriter out = new PrintWriter( buf ); - Method print = m_item.getClass().getMethod( "print", PrintWriter.class ); - print.setAccessible( true ); - print.invoke( m_item, out ); + PrintWriter out = new PrintWriter(buf); + Method print = m_item.getClass().getMethod("print", PrintWriter.class); + print.setAccessible(true); + print.invoke(m_item, out); out.close(); - return buf.toString().replace( "\n", "" ); - } - catch( Exception ex ) - { - throw new Error( ex ); + return buf.toString().replace("\n", ""); + } catch (Exception ex) { + throw new Error(ex); } } - public InfoType getType( ) - { - return InfoType.getByTag( getTag() ); + public InfoType getType() { + return InfoType.getByTag(getTag()); } } diff --git a/src/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java index 169306a..0d780ea 100644 --- a/src/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java +++ b/src/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java @@ -12,85 +12,63 @@ package cuchaz.enigma.bytecode.accessors; import java.lang.reflect.Field; -public class InvokeDynamicInfoAccessor -{ +public class InvokeDynamicInfoAccessor { + private static Class m_class; private static Field m_bootstrapIndex; private static Field m_nameAndTypeIndex; - static - { - try - { - m_class = Class.forName( "javassist.bytecode.InvokeDynamicInfo" ); - m_bootstrapIndex = m_class.getDeclaredField( "bootstrap" ); - m_bootstrapIndex.setAccessible( true ); - m_nameAndTypeIndex = m_class.getDeclaredField( "nameAndType" ); - m_nameAndTypeIndex.setAccessible( true ); - } - catch( Exception ex ) - { - throw new Error( ex ); + static { + try { + m_class = Class.forName("javassist.bytecode.InvokeDynamicInfo"); + m_bootstrapIndex = m_class.getDeclaredField("bootstrap"); + m_bootstrapIndex.setAccessible(true); + m_nameAndTypeIndex = m_class.getDeclaredField("nameAndType"); + m_nameAndTypeIndex.setAccessible(true); + } catch (Exception ex) { + throw new Error(ex); } } - public static boolean isType( ConstInfoAccessor accessor ) - { - return m_class.isAssignableFrom( accessor.getItem().getClass() ); + public static boolean isType(ConstInfoAccessor accessor) { + return m_class.isAssignableFrom(accessor.getItem().getClass()); } private Object m_item; - public InvokeDynamicInfoAccessor( Object item ) - { + public InvokeDynamicInfoAccessor(Object item) { m_item = item; } - public int getBootstrapIndex( ) - { - try - { - return (Integer)m_bootstrapIndex.get( m_item ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public int getBootstrapIndex() { + try { + return (Integer)m_bootstrapIndex.get(m_item); + } catch (Exception ex) { + throw new Error(ex); } } - public void setBootstrapIndex( int val ) - { - try - { - m_bootstrapIndex.set( m_item, val ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public void setBootstrapIndex(int val) { + try { + m_bootstrapIndex.set(m_item, val); + } catch (Exception ex) { + throw new Error(ex); } } - public int getNameAndTypeIndex( ) - { - try - { - return (Integer)m_nameAndTypeIndex.get( m_item ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public int getNameAndTypeIndex() { + try { + return (Integer)m_nameAndTypeIndex.get(m_item); + } catch (Exception ex) { + throw new Error(ex); } } - public void setNameAndTypeIndex( int val ) - { - try - { - m_nameAndTypeIndex.set( m_item, val ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public void setNameAndTypeIndex(int val) { + try { + m_nameAndTypeIndex.set(m_item, val); + } catch (Exception ex) { + throw new Error(ex); } } } diff --git a/src/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java index 2ee3aff..9fe945f 100644 --- a/src/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java +++ b/src/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java @@ -12,85 +12,63 @@ package cuchaz.enigma.bytecode.accessors; import java.lang.reflect.Field; -public class MemberRefInfoAccessor -{ +public class MemberRefInfoAccessor { + private static Class m_class; private static Field m_classIndex; private static Field m_nameAndTypeIndex; - static - { - try - { - m_class = Class.forName( "javassist.bytecode.MemberrefInfo" ); - m_classIndex = m_class.getDeclaredField( "classIndex" ); - m_classIndex.setAccessible( true ); - m_nameAndTypeIndex = m_class.getDeclaredField( "nameAndTypeIndex" ); - m_nameAndTypeIndex.setAccessible( true ); - } - catch( Exception ex ) - { - throw new Error( ex ); + static { + try { + m_class = Class.forName("javassist.bytecode.MemberrefInfo"); + m_classIndex = m_class.getDeclaredField("classIndex"); + m_classIndex.setAccessible(true); + m_nameAndTypeIndex = m_class.getDeclaredField("nameAndTypeIndex"); + m_nameAndTypeIndex.setAccessible(true); + } catch (Exception ex) { + throw new Error(ex); } } - public static boolean isType( ConstInfoAccessor accessor ) - { - return m_class.isAssignableFrom( accessor.getItem().getClass() ); + public static boolean isType(ConstInfoAccessor accessor) { + return m_class.isAssignableFrom(accessor.getItem().getClass()); } private Object m_item; - public MemberRefInfoAccessor( Object item ) - { + public MemberRefInfoAccessor(Object item) { m_item = item; } - public int getClassIndex( ) - { - try - { - return (Integer)m_classIndex.get( m_item ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public int getClassIndex() { + try { + return (Integer)m_classIndex.get(m_item); + } catch (Exception ex) { + throw new Error(ex); } } - public void setClassIndex( int val ) - { - try - { - m_classIndex.set( m_item, val ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public void setClassIndex(int val) { + try { + m_classIndex.set(m_item, val); + } catch (Exception ex) { + throw new Error(ex); } } - public int getNameAndTypeIndex( ) - { - try - { - return (Integer)m_nameAndTypeIndex.get( m_item ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public int getNameAndTypeIndex() { + try { + return (Integer)m_nameAndTypeIndex.get(m_item); + } catch (Exception ex) { + throw new Error(ex); } } - public void setNameAndTypeIndex( int val ) - { - try - { - m_nameAndTypeIndex.set( m_item, val ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public void setNameAndTypeIndex(int val) { + try { + m_nameAndTypeIndex.set(m_item, val); + } catch (Exception ex) { + throw new Error(ex); } } } diff --git a/src/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java index 27b7aee..4c95b22 100644 --- a/src/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java +++ b/src/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java @@ -12,85 +12,63 @@ package cuchaz.enigma.bytecode.accessors; import java.lang.reflect.Field; -public class MethodHandleInfoAccessor -{ +public class MethodHandleInfoAccessor { + private static Class m_class; private static Field m_kindIndex; private static Field m_indexIndex; - static - { - try - { - m_class = Class.forName( "javassist.bytecode.MethodHandleInfo" ); - m_kindIndex = m_class.getDeclaredField( "refKind" ); - m_kindIndex.setAccessible( true ); - m_indexIndex = m_class.getDeclaredField( "refIndex" ); - m_indexIndex.setAccessible( true ); - } - catch( Exception ex ) - { - throw new Error( ex ); + static { + try { + m_class = Class.forName("javassist.bytecode.MethodHandleInfo"); + m_kindIndex = m_class.getDeclaredField("refKind"); + m_kindIndex.setAccessible(true); + m_indexIndex = m_class.getDeclaredField("refIndex"); + m_indexIndex.setAccessible(true); + } catch (Exception ex) { + throw new Error(ex); } } - public static boolean isType( ConstInfoAccessor accessor ) - { - return m_class.isAssignableFrom( accessor.getItem().getClass() ); + public static boolean isType(ConstInfoAccessor accessor) { + return m_class.isAssignableFrom(accessor.getItem().getClass()); } private Object m_item; - public MethodHandleInfoAccessor( Object item ) - { + public MethodHandleInfoAccessor(Object item) { m_item = item; } - public int getTypeIndex( ) - { - try - { - return (Integer)m_kindIndex.get( m_item ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public int getTypeIndex() { + try { + return (Integer)m_kindIndex.get(m_item); + } catch (Exception ex) { + throw new Error(ex); } } - public void setTypeIndex( int val ) - { - try - { - m_kindIndex.set( m_item, val ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public void setTypeIndex(int val) { + try { + m_kindIndex.set(m_item, val); + } catch (Exception ex) { + throw new Error(ex); } } - public int getMethodRefIndex( ) - { - try - { - return (Integer)m_indexIndex.get( m_item ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public int getMethodRefIndex() { + try { + return (Integer)m_indexIndex.get(m_item); + } catch (Exception ex) { + throw new Error(ex); } } - public void setMethodRefIndex( int val ) - { - try - { - m_indexIndex.set( m_item, val ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public void setMethodRefIndex(int val) { + try { + m_indexIndex.set(m_item, val); + } catch (Exception ex) { + throw new Error(ex); } } } diff --git a/src/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java index 4cba6a2..e151117 100644 --- a/src/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java +++ b/src/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java @@ -12,58 +12,44 @@ package cuchaz.enigma.bytecode.accessors; import java.lang.reflect.Field; -public class MethodTypeInfoAccessor -{ +public class MethodTypeInfoAccessor { + private static Class m_class; private static Field m_descriptorIndex; - static - { - try - { - m_class = Class.forName( "javassist.bytecode.MethodTypeInfo" ); - m_descriptorIndex = m_class.getDeclaredField( "descriptor" ); - m_descriptorIndex.setAccessible( true ); - } - catch( Exception ex ) - { - throw new Error( ex ); + static { + try { + m_class = Class.forName("javassist.bytecode.MethodTypeInfo"); + m_descriptorIndex = m_class.getDeclaredField("descriptor"); + m_descriptorIndex.setAccessible(true); + } catch (Exception ex) { + throw new Error(ex); } } - public static boolean isType( ConstInfoAccessor accessor ) - { - return m_class.isAssignableFrom( accessor.getItem().getClass() ); + public static boolean isType(ConstInfoAccessor accessor) { + return m_class.isAssignableFrom(accessor.getItem().getClass()); } private Object m_item; - public MethodTypeInfoAccessor( Object item ) - { + public MethodTypeInfoAccessor(Object item) { m_item = item; } - public int getTypeIndex( ) - { - try - { - return (Integer)m_descriptorIndex.get( m_item ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public int getTypeIndex() { + try { + return (Integer)m_descriptorIndex.get(m_item); + } catch (Exception ex) { + throw new Error(ex); } } - public void setTypeIndex( int val ) - { - try - { - m_descriptorIndex.set( m_item, val ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public void setTypeIndex(int val) { + try { + m_descriptorIndex.set(m_item, val); + } catch (Exception ex) { + throw new Error(ex); } } } diff --git a/src/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java index 03b4de3..6e82f3e 100644 --- a/src/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java +++ b/src/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java @@ -12,85 +12,63 @@ package cuchaz.enigma.bytecode.accessors; import java.lang.reflect.Field; -public class NameAndTypeInfoAccessor -{ +public class NameAndTypeInfoAccessor { + private static Class m_class; private static Field m_nameIndex; private static Field m_typeIndex; - static - { - try - { - m_class = Class.forName( "javassist.bytecode.NameAndTypeInfo" ); - m_nameIndex = m_class.getDeclaredField( "memberName" ); - m_nameIndex.setAccessible( true ); - m_typeIndex = m_class.getDeclaredField( "typeDescriptor" ); - m_typeIndex.setAccessible( true ); - } - catch( Exception ex ) - { - throw new Error( ex ); + static { + try { + m_class = Class.forName("javassist.bytecode.NameAndTypeInfo"); + m_nameIndex = m_class.getDeclaredField("memberName"); + m_nameIndex.setAccessible(true); + m_typeIndex = m_class.getDeclaredField("typeDescriptor"); + m_typeIndex.setAccessible(true); + } catch (Exception ex) { + throw new Error(ex); } } - public static boolean isType( ConstInfoAccessor accessor ) - { - return m_class.isAssignableFrom( accessor.getItem().getClass() ); + public static boolean isType(ConstInfoAccessor accessor) { + return m_class.isAssignableFrom(accessor.getItem().getClass()); } private Object m_item; - public NameAndTypeInfoAccessor( Object item ) - { + public NameAndTypeInfoAccessor(Object item) { m_item = item; } - public int getNameIndex( ) - { - try - { - return (Integer)m_nameIndex.get( m_item ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public int getNameIndex() { + try { + return (Integer)m_nameIndex.get(m_item); + } catch (Exception ex) { + throw new Error(ex); } } - public void setNameIndex( int val ) - { - try - { - m_nameIndex.set( m_item, val ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public void setNameIndex(int val) { + try { + m_nameIndex.set(m_item, val); + } catch (Exception ex) { + throw new Error(ex); } } - public int getTypeIndex( ) - { - try - { - return (Integer)m_typeIndex.get( m_item ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public int getTypeIndex() { + try { + return (Integer)m_typeIndex.get(m_item); + } catch (Exception ex) { + throw new Error(ex); } } - public void setTypeIndex( int val ) - { - try - { - m_typeIndex.set( m_item, val ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public void setTypeIndex(int val) { + try { + m_typeIndex.set(m_item, val); + } catch (Exception ex) { + throw new Error(ex); } } } diff --git a/src/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java index 5cdfce4..6665ffe 100644 --- a/src/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java +++ b/src/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java @@ -12,58 +12,44 @@ package cuchaz.enigma.bytecode.accessors; import java.lang.reflect.Field; -public class StringInfoAccessor -{ +public class StringInfoAccessor { + private static Class m_class; private static Field m_stringIndex; - static - { - try - { - m_class = Class.forName( "javassist.bytecode.StringInfo" ); - m_stringIndex = m_class.getDeclaredField( "string" ); - m_stringIndex.setAccessible( true ); - } - catch( Exception ex ) - { - throw new Error( ex ); + static { + try { + m_class = Class.forName("javassist.bytecode.StringInfo"); + m_stringIndex = m_class.getDeclaredField("string"); + m_stringIndex.setAccessible(true); + } catch (Exception ex) { + throw new Error(ex); } } - public static boolean isType( ConstInfoAccessor accessor ) - { - return m_class.isAssignableFrom( accessor.getItem().getClass() ); + public static boolean isType(ConstInfoAccessor accessor) { + return m_class.isAssignableFrom(accessor.getItem().getClass()); } private Object m_item; - public StringInfoAccessor( Object item ) - { + public StringInfoAccessor(Object item) { m_item = item; } - public int getStringIndex( ) - { - try - { - return (Integer)m_stringIndex.get( m_item ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public int getStringIndex() { + try { + return (Integer)m_stringIndex.get(m_item); + } catch (Exception ex) { + throw new Error(ex); } } - public void setStringIndex( int val ) - { - try - { - m_stringIndex.set( m_item, val ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public void setStringIndex(int val) { + try { + m_stringIndex.set(m_item, val); + } catch (Exception ex) { + throw new Error(ex); } } } diff --git a/src/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java b/src/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java index 1cadd83..2abf60b 100644 --- a/src/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java +++ b/src/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java @@ -10,24 +10,19 @@ ******************************************************************************/ package cuchaz.enigma.bytecode.accessors; -public class Utf8InfoAccessor -{ +public class Utf8InfoAccessor { + private static Class m_class; - static - { - try - { - m_class = Class.forName( "javassist.bytecode.Utf8Info" ); - } - catch( Exception ex ) - { - throw new Error( ex ); + static { + try { + m_class = Class.forName("javassist.bytecode.Utf8Info"); + } catch (Exception ex) { + throw new Error(ex); } } - public static boolean isType( ConstInfoAccessor accessor ) - { - return m_class.isAssignableFrom( accessor.getItem().getClass() ); + public static boolean isType(ConstInfoAccessor accessor) { + return m_class.isAssignableFrom(accessor.getItem().getClass()); } } -- cgit v1.2.3