diff --git a/jode/jode/flow/CreateClassField.java b/jode/jode/flow/CreateClassField.java new file mode 100644 index 0000000..dab7b27 --- /dev/null +++ b/jode/jode/flow/CreateClassField.java @@ -0,0 +1,91 @@ +/* + * CreateClassField (c) 1998 Jochen Hoenicke + * + * You may distribute under the terms of the GNU General Public License. + * + * IN NO EVENT SHALL JOCHEN HOENICKE BE LIABLE TO ANY PARTY FOR DIRECT, + * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF + * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JOCHEN HOENICKE + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * JOCHEN HOENICKE SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" + * BASIS, AND JOCHEN HOENICKE HAS NO OBLIGATION TO PROVIDE MAINTENANCE, + * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * $Id$ + */ + +package jode.flow; +import jode.expr.*; +import jode.Type; +import jode.decompiler.LocalInfo; + +public class CreateClassField { + + + public static boolean transform(IfThenElseBlock ifBlock, + StructuredBlock last) { + // convert + // if (class$classname == null) + // class$classname = class$("java.lang.Object"); + // to + // if (classname.class == null) { + // } + if (!(ifBlock.cond instanceof ComplexExpression) + || !(ifBlock.cond.getOperator() instanceof CompareUnaryOperator) + || !(ifBlock.cond.getOperator().getOperatorIndex() + == Operator.EQUALS_OP) + || !(ifBlock.thenBlock instanceof InstructionBlock) + || ifBlock.elseBlock != null) + return false; + + if (ifBlock.thenBlock.jump != null + && (ifBlock.jump == null + || (ifBlock.jump.destination + != ifBlock.thenBlock.jump.destination))) + return false; + + ComplexExpression cmp = (ComplexExpression) ifBlock.cond; + Expression instr = + ((InstructionBlock)ifBlock.thenBlock).getInstruction(); + if (!(cmp.getSubExpressions()[0] instanceof GetFieldOperator) + || !(instr instanceof ComplexExpression) + || !(instr.getOperator() instanceof PutFieldOperator)) + return false; + + ComplexExpression ass = (ComplexExpression) instr; + PutFieldOperator put = (PutFieldOperator) ass.getOperator(); + if (!put.isSynthetic() + || !put.matches((GetFieldOperator)cmp.getSubExpressions()[0]) + || !(ass.getSubExpressions()[0] instanceof ComplexExpression) + || !(ass.getSubExpressions()[0].getOperator() + instanceof InvokeOperator)) + return false; + + InvokeOperator invoke = (InvokeOperator) + ass.getSubExpressions()[0].getOperator(); + Expression param = + ((ComplexExpression)ass.getSubExpressions()[0]) + .getSubExpressions()[0]; + if (invoke.isGetClass() + && param instanceof ConstOperator + && param.getType().equals(Type.tString)) { + String clazz = ((ConstOperator)param).getValue(); + clazz = clazz.substring(1, clazz.length()-1); + if (put.getFieldName() + .equals("class$" + clazz.replace('.', '$')) + || put.getFieldName() + .equals("class$L" + clazz.replace('.', '$'))) { + cmp.setSubExpressions + (0, new ClassFieldOperator(Type.tClass(clazz))); + EmptyBlock empty = new EmptyBlock(); + empty.moveJump(ifBlock.thenBlock.jump); + ifBlock.setThenBlock(empty); + return true; + } + } + return false; + } +} diff --git a/jode/test/ArrayTest.java b/jode/test/ArrayTest.java new file mode 100644 index 0000000..0754611 --- /dev/null +++ b/jode/test/ArrayTest.java @@ -0,0 +1,74 @@ +package jode.test; +import java.io.*; +import java.lang.reflect.*; + +public class ArrayTest { + Serializable s; + Serializable[] u; + Cloneable c; + + public void test() { + int[] i = {4,3,2}; + i = new int[] {1, 2, 3}; + int[] j = new int[] {4,5,6}; + + int[][] k = {i,j}; + + u = k; + s = i; + c = i; + } + + public void typetest() { + int[] arr = null; + s = arr; + c = arr; + arr[0] = 3; + arr = arr != null ? arr : new int[4]; + } + + public static void main(String[] param) { + int[] arr = new int[4]; + Class cls = arr.getClass(); + System.err.println("int[].getClass() is: "+cls); + System.err.println("int[].getClass().getSuperclass() is: " + + cls.getSuperclass()); + Class[] ifaces = cls.getInterfaces(); + System.err.print("int[].getClass().getInterfaces() are: "); + for (int i = 0; i < ifaces.length; i++) { + if (i > 0) + System.err.print(", "); + System.err.print(ifaces[i]); + } + System.err.println(); + + Field[] fields = cls.getDeclaredFields(); + System.err.print("int[].getClass().getDeclaredFields() are: "); + for (int i = 0; i < fields.length; i++) { + if (i > 0) + System.err.print(", "); + System.err.print(fields[i]); + } + System.err.println(); + + Method[] methods = cls.getDeclaredMethods(); + System.err.print("int[].getClass().getDeclaredMethods() are: "); + for (int i = 0; i < methods.length; i++) { + if (i > 0) + System.err.print(", "); + System.err.print(methods[i]); + } + System.err.println(); + + Object o = arr; + System.err.println("arr instanceof Serializable: "+ + (o instanceof Serializable)); + System.err.println("arr instanceof Externalizable: "+ + (o instanceof Externalizable)); + System.err.println("arr instanceof Cloneable: "+ + (o instanceof Cloneable)); +// System.err.println("arr instanceof Comparable: "+ +// (o instanceof Comparable)); + } +} +