protected String toStringMethod(byte[] classdata, String methodname, boolean quoted) { OutputStream os = new SimpleOutputStream(); // ClassReader reader = new ClassReader(classdata); MethodNode one = getMethod(classdata, methodname); one.instructions.accept(new MethodPrinter(new PrintStream(os))); String s = os.toString(); StringBuffer sb = new StringBuffer(s.replaceAll("\r", "")); if (!quoted) { return sb.toString(); } for (int i = 0; i < sb.length(); i++) { if (sb.charAt(i) == '\n') { sb.insert(i + 1, "\""); sb.insert(i, "\\n\"+"); i += 4; } } sb.insert(0, "Method is " + methodname + "\n\""); sb.delete(sb.length() - 3, sb.length()); return sb.toString(); }
@Override protected void generateMethod(InstructionGroup group, ClassWriter cw) { MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "create", "()Ljava/lang/Object;", null, null); convertXLoads(group); group.getInstructions().accept(mv); mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); // trigger automatic computing mv.visitEnd(); }
/** * Marks all labels of the method with control flow information. * * @param method * Method to mark labels */ public static void markLabels(final MethodNode method) { // We do not use the accept() method as ASM resets labels after every // call to accept() final MethodVisitor lfa = new LabelFlowAnalyzer(); for (int i = method.tryCatchBlocks.size(); --i >= 0;) { method.tryCatchBlocks.get(i).accept(lfa); } method.instructions.accept(lfa); }
@Override protected void generateMethod(InstructionGroup group, ClassWriter cw) { MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "run", '(' + Types.CONTEXT_DESC + ")Z", null, null); insertSetContextCalls(group, 1); convertXLoads(group); group.getInstructions().accept(mv); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); // trigger automatic computing mv.visitEnd(); }
@Override protected void generateMethod(final InstructionGroup group, final ClassWriter cw) { final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "get", CodegenUtils.sig(Object.class), null, null); convertXLoads(group); group.getInstructions().accept(mv); mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); // trigger automatic computing } }
@Override protected void generateMethod(final InstructionGroup group, final ClassWriter cw) { final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "run", CodegenUtils.sig(boolean.class, Context.class), null, null); insertSetContextCalls(group, 1); convertXLoads(group); group.getInstructions().accept(mv); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); // trigger automatic computing } }
mn.instructions.accept(mp);
private String hashAndGetName() { group.getInstructions().accept(this); for (final FieldNode node: group.getFields()) hasher.putObject(node, FieldNodeFunnel.INSTANCE); final byte[] hash = new byte[10]; hasher.hash().writeBytesTo(hash, 0, 10); final String prefix = group.getRoot().isActionRoot() ? "Action$" : "VarInit$"; return prefix + BASE_ENCODING.encode(hash); }
private void createStaticConstructor(ClassNode owner) throws UnsupportedEncodingException { MethodNode original = BytecodeHelper.getMethod(owner, "<clinit>", "()V"); MethodVisitor mv = owner.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null); // generate instructions InstructionAdapter builder = new InstructionAdapter(mv); builder.iconst(stringList.size()); builder.newarray(Type.getType(String.class)); for (int i = 0; i < stringList.size(); i++) { builder.dup(); builder.iconst(i); builder.aconst(Base64.getEncoder().encodeToString(stringList.get(i).getBytes("UTF-8"))); builder.astore(InstructionAdapter.OBJECT_TYPE); } builder.putstatic(unscrambleClass.name, FIELD_NAME, "[Ljava/lang/String;"); // merge with original if it exists if (original != null) { // original should already end with RETURN owner.methods.remove(original); original.instructions.accept(builder); } else { builder.areturn(Type.VOID_TYPE); } }
clInit.instructions.accept(atomicClInit); } else { atomicClInit.visitInsn(RETURN);
instructions.accept(mv);
private synchronized void name(InstructionGroup group, ParserClassNode classNode) { // generate an MD5 hash across the buffer, use only the first 96 bit MD5Digester digester = new MD5Digester(classNode.name); group.getInstructions().accept(digester); for (FieldNode field: group.getFields()) digester.visitField(field); byte[] hash = digester.getMD5Hash(); byte[] hash96 = new byte[12]; System.arraycopy(hash, 0, hash96, 0, 12); // generate a name for the group based on the hash String name = group.getRoot().isActionRoot() ? "Action$" : "VarInit$"; name += CUSTOM_BASE64.encodeToString(hash96, false); group.setName(name); }
instructions.accept(methodVisitor);
final Textifier textifier = new Textifier(); final PrintWriter pw = new PrintWriter(System.out); list.accept(new TraceMethodVisitor(textifier)); textifier.print(pw); pw.flush();