public SearchResult run(RSClient data, HashMap<String, ClassGen> classes) { for (ClassGen c : classes.values()) { ConstantPoolGen cpg = c.getConstantPool(); if (cpg.lookupFloat(16384.0000f) != -1) { for (Method m : c.getMethods()) { if (m.isStatic()) { MethodGen gen = new MethodGen(m, c.getClassName(), cpg); InstructionList il = gen.getInstructionList(); if (il == null) continue; InstructionFinder f = new InstructionFinder(il); Iterator e = f.search("GETSTATIC LDC FSUB PUTSTATIC"); if (e.hasNext()) { InstructionHandle[] handles = (InstructionHandle[]) e.next(); data.addField( "MapAngle", ((GETSTATIC) handles[0].getInstruction()).getClassName(cpg) + "." + ((GETSTATIC) handles[0].getInstruction()).getFieldName(cpg)); return SearchResult.Success; } } } } } return SearchResult.Failure; }
/** Replace all references to the old constant pool with references to the new constant pool */ public void replaceConstantPool(ConstantPoolGen old_cp, ConstantPoolGen new_cp) { for (InstructionHandle ih = start; ih != null; ih = ih.next) { Instruction i = ih.instruction; if (i instanceof CPInstruction) { CPInstruction ci = (CPInstruction) i; Constant c = old_cp.getConstant(ci.getIndex()); ci.setIndex(new_cp.addConstant(c, old_cp)); } } }
/** * Get LocalVariable object. * * <p>This relies on that the instruction list has already been dumped to byte code or or that the * `setPositions' methods has been called for the instruction list. * * <p>Note that for local variables whose scope end at the last instruction of the method's code, * the JVM specification is ambiguous: both a start_pc+length ending at the last instruction and * start_pc+length ending at first index beyond the end of the code are valid. * * @param il instruction list (byte code) which this variable belongs to * @param cp constant pool */ public LocalVariable getLocalVariable(ConstantPoolGen cp) { int start_pc = start.getPosition(); int length = end.getPosition() - start_pc; if (length > 0) length += end.getInstruction().getLength(); int name_index = cp.addUtf8(name); int signature_index = cp.addUtf8(type.getSignature()); return new LocalVariable( start_pc, length, name_index, signature_index, index, cp.getConstantPool()); }
/** Returns the attribute name for the specified attribute */ public String get_attribute_name(Attribute a) { int con_index = a.getNameIndex(); Constant c = pgen.getConstant(con_index); String att_name = ((ConstantUtf8) c).getBytes(); return (att_name); }
/** Symbolically executes the corresponding Java Virtual Machine instruction. */ public void visitLDC2_W(LDC2_W o) { Constant c = cpg.getConstant(o.getIndex()); if (c instanceof ConstantLong) { stack().push(Type.LONG); } if (c instanceof ConstantDouble) { stack().push(Type.DOUBLE); } }
/** Symbolically executes the corresponding Java Virtual Machine instruction. */ public void visitLDC_W(LDC_W o) { Constant c = cpg.getConstant(o.getIndex()); if (c instanceof ConstantInteger) { stack().push(Type.INT); } if (c instanceof ConstantFloat) { stack().push(Type.FLOAT); } if (c instanceof ConstantString) { stack().push(Type.STRING); } }
byte[] counterAdaptClass(final InputStream is, final String name) throws Exception { JavaClass jc = new ClassParser(is, name + ".class").parse(); ClassGen cg = new ClassGen(jc); String cName = cg.getClassName(); ConstantPoolGen cp = cg.getConstantPool(); if (!cg.isInterface()) { FieldGen fg = new FieldGen(ACC_PUBLIC, Type.getType("I"), "_counter", cp); cg.addField(fg.getField()); } Method[] ms = cg.getMethods(); for (int j = 0; j < ms.length; ++j) { MethodGen mg = new MethodGen(ms[j], cg.getClassName(), cp); if (!mg.getName().equals("<init>") && !mg.isStatic() && !mg.isAbstract() && !mg.isNative()) { if (mg.getInstructionList() != null) { InstructionList il = new InstructionList(); il.append(new ALOAD(0)); il.append(new ALOAD(0)); il.append(new GETFIELD(cp.addFieldref(name, "_counter", "I"))); il.append(new ICONST(1)); il.append(new IADD()); il.append(new PUTFIELD(cp.addFieldref(name, "_counter", "I"))); mg.getInstructionList().insert(il); mg.setMaxStack(Math.max(mg.getMaxStack(), 2)); boolean lv = ms[j].getLocalVariableTable() == null; boolean ln = ms[j].getLineNumberTable() == null; if (lv) { mg.removeLocalVariables(); } if (ln) { mg.removeLineNumbers(); } cg.replaceMethod(ms[j], mg.getMethod()); } } } return cg.getJavaClass().getBytes(); }
/** @return type associated with the instruction */ public Type getType(ConstantPoolGen cpg) { return getType(cpg.getConstantPool()); }
public Instruction createInstructionAnewarray(Element inst) { String classType = inst.getAttributeValue("elementType"); return new ANEWARRAY(_cp.addClass(classType)); }
public Instruction createInstructionCheckcast(Element inst) throws IllegalXMLVMException { String classType = inst.getAttributeValue("type"); return new CHECKCAST(_cp.addClass(classType)); }
public int consumeStack(ConstantPoolGen cpg) { return consumeStack(cpg.getConstantPool()); }