package javassist.bytecode; //import javassist.bytecode.*; import javassist.*; import java.util.*; import java.io.*; public class CodeAttributeTest{ //EOA1 /* public int test1(){ ConstPool cp = new ConstPool("assignment10.Point2"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); et.add(1,1,2,0,2); byte[] code = "dd".getBytes(); CodeAttribute ca = new CodeAttribute(cp, 5, 3, code, et); // Bytecode bc = new Bytecode(cp, 1, 0); // bc.addIconst(3); // bc.addReturn(CtClass.intType); // CodeAttribute ca = bc.toCodeAttribute(); // CodeIterator.Pointers cip = new CodeIterator.Pointers(0, 1, 2, et, ca); //Handler hdl = new Handler(et, 0, ca.iterator(), CtClass.intType, null); //System.out.println(et.catchType(1)); //hdl.replace0(0, bc, 2); //ExprEditor ee = new ExprEditor(); //hdl.runEditor(ee, ca.iterator()); et.remove(0); //System.out.println(cip.etable.size()); return ca.getExceptionTable().size(); } public int test2() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); et.add(1,1,2,0,2); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 1, 0); bc.addIconst(3); bc.addReturn(CtClass.intType); CodeAttribute ca = bc.toCodeAttribute(); Map map = new HashMap(); map.put("javassist.ClassPoolTailTest", "javassist.CtClassTypeTest"); AttributeInfo ca1 = (CodeAttribute)(ca.copy(cp, map)); return ((CodeAttribute)ca1).getMaxStack(); } public int test3() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); et.add(1,1,2,0,2); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 1, 0); bc.addIconst(3); bc.addReturn(CtClass.intType); CodeAttribute ca = bc.toCodeAttribute(); Map map = new HashMap(); map.put("javassist.ClassPoolTailTest", "javassist.CtClassTypeTest"); AttributeInfo ca1 = (CodeAttribute)(ca.copy(cp, map)); return ((CodeAttribute)ca1).getMaxLocals(); } public int test4() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); et.add(1,1,2,0,2); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 1, 0); bc.addIconst(3); bc.addReturn(CtClass.intType); CodeAttribute ca = bc.toCodeAttribute(); Map map = new HashMap(); map.put("javassist.ClassPoolTailTest", "javassist.CtClassTypeTest"); AttributeInfo ca1 = (CodeAttribute)(ca.copy(cp, map)); return ((CodeAttribute)ca1).info.length; } public int test5() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); et.add(1,1,2,0,2); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 1, 0); bc.addIconst(3); bc.addReturn(CtClass.intType); CodeAttribute ca = bc.toCodeAttribute(); ca.insertLocalVar(2, 1); return ca.getMaxLocals(); } //IOD2 public int test6() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); et.add(1,1,2,0,2); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 1, 0); bc.addIconst(3); bc.addReturn(CtClass.intType); CodeAttribute ca = bc.toCodeAttribute(); return ca.length(); } //IOD3 public int test7() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); et.add(1,1,2,0,2); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 1, 0); bc.addIconst(3); bc.addReturn(CtClass.intType); CodeAttribute ca = bc.toCodeAttribute(); DataOutputStream fout = new DataOutputStream(new FileOutputStream("fout.txt")); ca.write(fout); return fout.size(); } //IOD4 public int test8() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); et.add(1,1,2,0,2); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 1, 0); bc.addIconst(3); bc.addReturn(CtClass.intType); StackMapTable smt = new StackMapTable(cp, code); CodeAttribute ca = bc.toCodeAttribute(); return ca.get().length; } //IOD5 public int test9() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); et.add(1,1,2,0,2); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 1, 0); bc.addIconst(3); bc.addReturn(CtClass.intType); StackMapTable smt = new StackMapTable(cp, code); CodeAttribute ca = bc.toCodeAttribute(); ca.set(code); return ca.get().length; } //IOD 6 AND 7 are not applicable because reanameClass is not implemented completely in the source code //IOR_1, 2, 3, 4 are not implemented correctly in muJava //IPC_4 public String test10() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); et.add(1,1,2,0,2); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 1, 0); bc.addIconst(3); bc.addReturn(CtClass.intType); StackMapTable smt = new StackMapTable(cp, code); CodeAttribute ca = bc.toCodeAttribute(); CodeAttribute.RuntimeCopyException e = new CodeAttribute.RuntimeCopyException("test"); return e.toString(); } //ISD_1 public int test11() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); et.add(1,1,2,0,2); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 1, 0); bc.addIconst(3); bc.addReturn(CtClass.intType); StackMapTable smt = new StackMapTable(cp, code); CodeAttribute ca = bc.toCodeAttribute(); ca.setCode(code); return ca.get().length; } //JSI_1 public int test12() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); et.add(1,1,2,0,2); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 2, 2); bc.addIconst(3); bc.addReturn(CtClass.intType); Bytecode bc1 = new Bytecode(cp, 3, 2); bc1.addIconst(3); bc1.addReturn(CtClass.intType); CodeAttribute ca = bc.toCodeAttribute(); CodeAttribute ca1 = bc1.toCodeAttribute(); return ca.getMaxStack(); } //JSI_2 public int test13() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); et.add(1,1,2,0,2); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 2, 2); bc.addIconst(3); bc.addReturn(CtClass.intType); Bytecode bc1 = new Bytecode(cp, 3, 3); bc1.addIconst(3); bc1.addReturn(CtClass.intType); CodeAttribute ca = bc.toCodeAttribute(); CodeAttribute ca1 = bc1.toCodeAttribute(); return ca.getMaxLocals(); } //JSI_3 public int test14() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 2, 2); bc.addIconst(3); bc.addReturn(CtClass.intType); ExceptionTable et1 = new ExceptionTable(cp); et1.add(0,1,2,0,0); et1.add(1,1,2,0,2); CodeAttribute ca = new CodeAttribute(cp, 2, 2, code, et); CodeAttribute ca1 = new CodeAttribute(cp, 2, 2, code, et1); return ca.getExceptionTable().size(); } //JSI_4 public List test15() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); et.add(1,1,2,0,2); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 1, 0); bc.addIconst(3); bc.addReturn(CtClass.intType); StackMapTable smt = new StackMapTable(cp, code); CodeAttribute ca = bc.toCodeAttribute(); Map map = new HashMap(); map.put("javassist.ClassPoolTailTest", "javassist.CtClassTypeTest"); ca.setAttribute(smt); AttributeInfo ca1 = (CodeAttribute)(ca.copy(cp, map)); return ((CodeAttribute)ca).getAttributes(); } //JSI_5 public String test16() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 2, 2); bc.addIconst(3); bc.addReturn(CtClass.intType); CodeAttribute ca = new CodeAttribute(cp, 2, 2, code, et); CodeAttribute.LdcEntry cale = new CodeAttribute.LdcEntry(); CodeAttribute.LdcEntry cale1 = new CodeAttribute.LdcEntry(); CodeAttribute.LdcEntry cale2 = new CodeAttribute.LdcEntry(); cale1.next = cale2; return cale.next.toString(); } //JSI_6 public int test17() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 2, 2); bc.addIconst(3); bc.addReturn(CtClass.intType); CodeAttribute ca = new CodeAttribute(cp, 2, 2, code, et); CodeAttribute.LdcEntry cale = new CodeAttribute.LdcEntry(); CodeAttribute.LdcEntry cale1 = new CodeAttribute.LdcEntry(); cale.where = 0; cale1.where = 1; return cale.where; } //JSI_7 public int test18() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 2, 2); bc.addIconst(3); bc.addReturn(CtClass.intType); CodeAttribute ca = new CodeAttribute(cp, 2, 2, code, et); CodeAttribute.LdcEntry cale = new CodeAttribute.LdcEntry(); CodeAttribute.LdcEntry cale1 = new CodeAttribute.LdcEntry(); cale.index = 0; cale1.index = 1; return cale.index; }*/ //PCI_14 public int test19() throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); et.add(1,1,2,0,2); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 1, 0); bc.addIconst(3); bc.addReturn(CtClass.intType); CodeAttribute ca2 = new CodeAttribute(cp, 2, 2, code, et); StackMapTable smt = new StackMapTable(cp, code); CodeAttribute ca = bc.toCodeAttribute(); ca.getAttributes().add(ca2); Map map = new HashMap(); map.put("javassist.ClassPoolTailTest", "javassist.CtClassTypeTest"); //ca.setAttribute(smt); AttributeInfo ca1 = (CodeAttribute)(ca.copy(cp, map)); return ((CodeAttribute)ca).getAttributes().size(); } /* public static void main(String[] args) throws Exception{ ConstPool cp = new ConstPool("javassist.ClassPoolTailTest"); ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("c:\\mujava\\testset"); CtClass cc = pool.get("javassist.ClassPoolTailTest"); ExceptionTable et = new ExceptionTable(cp); et.add(0,1,2,0,0); et.add(1,1,2,0,2); byte[] code = "dd".getBytes(); Bytecode bc = new Bytecode(cp, 1, 0); bc.addIconst(3); bc.addReturn(CtClass.intType); CodeAttribute ca2 = new CodeAttribute(cp, 2, 2, code, et); StackMapTable smt = new StackMapTable(cp, code); CodeAttribute ca = bc.toCodeAttribute(); ca.getAttributes().add(ca2); Map map = new HashMap(); map.put("javassist.ClassPoolTailTest", "javassist.CtClassTypeTest"); //ca.setAttribute(smt); AttributeInfo ca1 = (CodeAttribute)(ca.copy(cp, map)); System.out.println(((CodeAttribute)ca).getAttributes()); }*/ }