|
36 | 36 | import org.objectweb.asm.tree.MethodInsnNode;
|
37 | 37 | import org.objectweb.asm.tree.MethodNode;
|
38 | 38 | import org.objectweb.asm.tree.TypeInsnNode;
|
39 |
| -import org.objectweb.asm.tree.analysis.Analyzer; |
40 |
| -import org.objectweb.asm.tree.analysis.AnalyzerException; |
41 |
| -import org.objectweb.asm.tree.analysis.BasicInterpreter; |
42 |
| -import org.objectweb.asm.tree.analysis.BasicValue; |
43 |
| -import org.objectweb.asm.tree.analysis.Frame; |
44 | 39 | import org.objectweb.asm.util.Textifier;
|
45 | 40 | import org.objectweb.asm.util.TraceMethodVisitor;
|
46 | 41 |
|
@@ -550,91 +545,6 @@ public static ClassNode convertToClassNode(byte[] classBytes) {
|
550 | 545 | return result;
|
551 | 546 | }
|
552 | 547 |
|
553 |
| - //make an analyzer |
554 |
| - |
555 |
| - private static void printMethodAnalysis(String owner, MethodNode method) throws AnalyzerException { |
556 |
| - System.out.println("Analyzing method: " + method.name); |
557 |
| - BasicInterpreter interpreter = new BasicInterpreter(); |
558 |
| - Analyzer<BasicValue> a = new Analyzer<>(interpreter); |
559 |
| - Frame<BasicValue>[] frames = a.analyze(owner, method); |
560 |
| - Map<AbstractInsnNode, Integer> rtStacks = new HashMap<>(); |
561 |
| - for (int j = 0; j < method.instructions.size(); ++j) { |
562 |
| - AbstractInsnNode insn = method.instructions.get(j); |
563 |
| - Frame<BasicValue> frame = frames[j]; |
564 |
| - if (frame != null) { |
565 |
| - System.out.println("Locals: " + stringLocals(frame) + " stack: " + stringStack(frame) + " " + stringifyInstruction(insn)); |
566 |
| - } |
567 |
| - } |
568 |
| - } |
569 |
| - |
570 |
| - private static String stringLocals(Frame<BasicValue> frame) { |
571 |
| - StringBuilder sb = new StringBuilder(); |
572 |
| - for (int i = 0; i < frame.getLocals(); i++) { |
573 |
| - BasicValue value = frame.getLocal(i); |
574 |
| - sb.append(value); |
575 |
| - sb.append(" . "); |
576 |
| - } |
577 |
| - return sb.toString(); |
578 |
| - } |
579 |
| - |
580 |
| - private static String stringStack(Frame<BasicValue> frame) { |
581 |
| - StringBuilder sb = new StringBuilder(); |
582 |
| - for (int i = 0; i < frame.getStackSize(); i++) { |
583 |
| - BasicValue value = frame.getStack(i); |
584 |
| - sb.append(value); |
585 |
| - sb.append(" . "); |
586 |
| - } |
587 |
| - return sb.toString(); |
588 |
| - } |
589 |
| - |
590 |
| - //print class node |
591 |
| - public static void printClassFrames(byte [] classBytes) { |
592 |
| - ClassReader reader = new ClassReader(classBytes); |
593 |
| - ClassNode cn = new ClassNode(); |
594 |
| - reader.accept(cn, 0); |
595 |
| - for (MethodNode methodNode : cn.methods) { |
596 |
| - try { |
597 |
| - printMethodAnalysis(cn.name, methodNode); |
598 |
| - } catch (AnalyzerException e) { |
599 |
| - e.printStackTrace(); |
600 |
| - } |
601 |
| - } |
602 |
| - } |
603 |
| - |
604 |
| - //TEMPORARY |
605 |
| - |
606 |
| - public static void forceVisitationOfClassFile(byte[] classBytes, ClassInformationFinder classInfoFinder) { |
607 |
| - ClassReader reader = new ClassReader(classBytes); |
608 |
| - ClassWriter cw = new PatchedClassWriter(ClassWriter.COMPUTE_FRAMES, classInfoFinder); |
609 |
| - reader.accept(cw, ClassReader.EXPAND_FRAMES); |
610 |
| - } |
611 |
| - |
612 |
| - public static void getInstructionAtBCI(int bci, byte [] classBytes) { |
613 |
| - int bciMargin = 3; |
614 |
| - ClassReader reader = new ClassReader(classBytes); |
615 |
| - ClassNode cn = new ClassNode(); |
616 |
| - reader.accept(cn, 0); |
617 |
| - for (MethodNode methodNode : cn.methods) { |
618 |
| - int currentBytecodeIndex = 0; |
619 |
| - for (AbstractInsnNode instruction : methodNode.instructions) { |
620 |
| - if (instruction.getType() != AbstractInsnNode.LABEL && |
621 |
| - instruction.getType() != AbstractInsnNode.LINE && |
622 |
| - instruction.getType() != AbstractInsnNode.FRAME) { |
623 |
| - |
624 |
| - if (currentBytecodeIndex > bci - bciMargin || currentBytecodeIndex < bci + bciMargin) { |
625 |
| - if (currentBytecodeIndex == bci) { |
626 |
| - System.out.print("Target Instruction >>>>>"); |
627 |
| - } |
628 |
| - System.out.println("bci: " + currentBytecodeIndex + " " + stringifyInstruction(instruction)); |
629 |
| - } |
630 |
| - currentBytecodeIndex++; |
631 |
| - } |
632 |
| - |
633 |
| - } |
634 |
| - System.out.println("Finished instrumenting method: " + methodNode.name); |
635 |
| - } |
636 |
| - } |
637 |
| - |
638 | 548 | public static void createReadableClassFileFromClassNode(ClassNode cn, boolean isNew, String originalName, String targetName, String destDir) {
|
639 | 549 | if (targetName == null || originalName.contains(targetName)) {
|
640 | 550 | System.out.println("Weaved composite ClassLoader");
|
|
0 commit comments