void removeInsts(MethodNode m, MethodInsnNode mn, int pSize) { // remove args for (int i = 0; i < pSize; i++) { m.instructions.remove(mn.getPrevious()); } // remove INVOKESTATIC m.instructions.remove(mn); }
private void visitIOP(int op, int a){ // xstore // xload if(op>=21&&op<=58){ mn.visitVarInsn(op,a); } else { // xipush mn.visitIntInsn(op,a); } } private void visitJOP(int op, Label label){
private int findMethodCall(InsnList insns, LabelNode label) { boolean foundLabel = false; for (int i = 0; i < insns.size(); i++) { AbstractInsnNode n = insns.get(i); if (!foundLabel && n == label) { foundLabel = true; } else if (foundLabel && n.getOpcode() == Opcodes.INVOKEDYNAMIC) { return i; } } return -1; }
public LabelNode writeLabel(MethodNode mv, int lineNumber){ LabelNode node = new LabelNode(new Label()); mv.instructions.add(node); if (lineNumber != -1) mv.instructions.add(new LineNumberNode(lineNumber, node)); return node; }
private void reset0() { cn = new ClassNode(ASM4); fn = null; mn = null; }
/** * Replaces the void `<init>(boolean)` constructor for a call to the * `void <init>(int, int, int)` one. */ private void replaceGregorianCalendarBooleanConstructor(ListIterator<AbstractInsnNode> instructions, MethodInsnNode targetMethod) { // Remove the call to GregorianCalendar(boolean) instructions.remove(); // Discard the already-pushed parameter for GregorianCalendar(boolean) instructions.add(new InsnNode(Opcodes.POP)); // Add parameters values for calling GregorianCalendar(int, int, int) instructions.add(new InsnNode(Opcodes.ICONST_0)); instructions.add(new InsnNode(Opcodes.ICONST_0)); instructions.add(new InsnNode(Opcodes.ICONST_0)); // Call GregorianCalendar(int, int, int) instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, targetMethod.owner, targetMethod.name, "(III)V", targetMethod.itf)); }
private byte[] toByteArray(ClassNode cn) { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); cn.accept(cw); return cw.toByteArray(); }
public static void replaceMethodWriter(MethodVisitor mv, MethodNode mn) { MethodWriter mw = (MethodWriter) mv; ClassWriter cw = mw.cw; mn.accept(cw); removeMethodWriter(mw); } }
private void visitOP0(int op){ if(op>=26&&op<=45){ // xload_y int x=op-26; mn.visitVarInsn(ILOAD+x/4,x%4); }else if(op>=59&&op<=78){ // xstore_y int x=op-26; mn.visitVarInsn(ISTORE+x/4,x%4); }else{ mn.visitInsn(op); } } private void visitIOP(int op, int a){
private void visitJOP(int op, Label label){ mn.visitJumpInsn(op,label); } private void visitIIOP(int op, int a, int b){
private void line(int ln){ if(rebuildLine) { Label label=new Label(); mn.visitLabel(label); mn.visitLineNumber(ln, label); } } private static String unEscapeString(String str) {
public AnnotationNode visitAnnotation(final String desc, final boolean visible) { return (AnnotationNode) mn.visitAnnotation(desc, visible); }
public AnnotationNode visitAnnotation(final String desc, final boolean visible) { return (AnnotationNode) fn.visitAnnotation(desc, visible); } };
public AnnotationNode visitAnnotation(final String desc, final boolean visible) { return (AnnotationNode) cn.visitAnnotation(desc, visible); } };
private void visitIIOP(int op, int a, int b){ mn.visitIincInsn(a,b); } private Label getLabel(String name){
public AnnotationNode visitParameterAnnotation(final int parameter, final String desc, final boolean visible) { return (AnnotationNode) mn.visitParameterAnnotation(parameter, desc, visible); } };
private ClassNode readClassNode(byte[] data) { ClassReader cr = new ClassReader(data); ClassNode cn = new ClassNode(); cr.accept(cn, ClassReader.EXPAND_FRAMES | ClassReader.SKIP_FRAMES); return cn; }
public void accept(ClassVisitor cv) throws RecognitionException{ sFile(); cn.accept(cv); } public ClassNode parse() throws RecognitionException {