1 5 import jas.*; 6 7 import java.io.*; 8 import sun.tools.java.RuntimeConstants; 9 10 public class all implements RuntimeConstants 11 { 12 public static void main(String argv[]) 13 throws Exception  14 { 15 ClassEnv c = new ClassEnv(); 16 17 19 c.addCPItem(new AsciiCP("fubar")); 20 c.addCPItem(new ClassCP("java/lang/Number")); 21 c.addCPItem(new DoubleCP(2.0)); 22 c.addCPItem(new FieldCP("java/lang/System", 23 "out", 24 "Ljava/io/PrintStream;")); 25 c.addCPItem(new FloatCP((float)(2.0))); 26 c.addCPItem(new IntegerCP(2)); 27 c.addCPItem(new InterfaceCP("java/lang/Runnable", 28 "run", 29 "()V")); 30 c.addCPItem(new LongCP(2)); 31 c.addCPItem(new MethodCP("java/lang/Thread", 32 "run", 33 "()V")); 34 35 c.addCPItem(new NameTypeCP("sdfsdf", "Ljava/lang/Object;")); 36 c.addCPItem(new StringCP("sdf")); 37 38 39 c.addField(new Var((short) ACC_PUBLIC, 41 new AsciiCP("someIntvar"), 42 new AsciiCP("I"), 43 null)); 44 c.addField(new Var((short)(ACC_PUBLIC|ACC_STATIC|ACC_FINAL), 45 new AsciiCP("finalInt"), 46 new AsciiCP("I"), 47 new ConstAttr(new IntegerCP(10)))); 48 49 c.addInterface(new ClassCP("java/lang/Runnable")); 51 52 c.setClass(new ClassCP("regress")); 53 c.setSuperClass(new ClassCP("java/lang/Object")); 54 c.setClassAccess((short) ACC_PUBLIC); 55 56 58 CodeAttr code = new CodeAttr(); 59 62 code.addInsn(new Insn(opc_return)); 64 code.addInsn(new Insn(opc_astore, 5)); 66 code.addInsn(new Insn(opc_dstore, 256)); 68 code.addInsn(new Insn(opc_istore, 2576)); 69 70 code.addInsn(new Label("First label")); 72 code.addInsn(new Insn(opc_jsr, 74 new Label("First label"))); 75 code.addInsn(new Label("second_label")); 77 code.addInsn(new Insn(opc_ldc_w, new StringCP("sdfsdf"))); 79 80 code.addInsn(new IincInsn(2, -2)); 82 code.addInsn(new IincInsn(1234, 2)); 84 code.addInsn(new IincInsn(3, -200)); 85 code.addInsn(new InvokeinterfaceInsn(new ClassCP("java/lang/Number"), 1)); 86 code.addInsn(new MultiarrayInsn(new ClassCP("java/lang/Double"), 3)); 87 Label woo[] = new Label[3]; 88 woo[0] = new Label("First label"); 89 woo[1] = new Label("second_label"); 90 woo[2] = new Label("second_label"); 91 code.addInsn(new TableswitchInsn(0, 2, woo[0], woo)); 92 93 int m[] = new int[3]; 94 m[0] = 11; 95 m[1] = 15; 96 m[2] = -1; 97 code.addInsn(new LookupswitchInsn(woo[0], m, woo)); 98 99 100 Catchtable ctb = new Catchtable(); 102 ctb.addEntry(new Label("First label"), 104 new Label("second_label"), 105 new Label("second_label"), 106 new ClassCP("java/lang/Exception")); 107 ctb.addEntry(new Label("First label"), 108 new Label("second_label"), 109 new Label("second_label"), 110 new ClassCP("java/lang/Error")); 111 code.setCatchtable(ctb); 112 code.setStackSize((short)100); 113 code.setVarSize((short)500); 114 LineTableAttr ln = new LineTableAttr(); 116 ln.addEntry(woo[0], 234); 117 ln.addEntry(woo[1], 245); 118 ln.addEntry(woo[2], 22); 119 code.setLineTable(ln); 120 String foo = "sldkfj sdlfkj"; 122 byte dat[] = new byte[foo.length()]; 123 foo.getBytes(0, dat.length, dat, 0); 124 code.addGenericAttr(new GenericAttr("strangeAttr", dat)); 125 126 LocalVarTableAttr lv = new LocalVarTableAttr(); 128 lv.addEntry(new LocalVarEntry(woo[0], woo[2], "fakevar", "I", 22)); 129 lv.addEntry(new LocalVarEntry(woo[1], woo[1], "morefa", "()V", 10)); 130 code.setLocalVarTable(lv); 131 132 ExceptAttr ex = new ExceptAttr(); 136 ex.addException(new ClassCP("java/io/IOException")); 137 ex.addException(new ClassCP("java/lang/Error")); 138 c.addMethod((short) ACC_PUBLIC, 139 "fubarmethod", 140 "()V", 141 code, 142 ex); 143 144 145 146 147 c.setSource(new SourceAttr("all.java")); 149 c.addGenericAttr(new GenericAttr("blahAttr", dat)); 151 c.write(new DataOutputStream(new FileOutputStream("regress.class"))); 152 } 153 } 154 155 156
| Popular Tags
|