org.objectweb.asm.tree.analysis.Analyzer.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(165)

本文整理了Java中org.objectweb.asm.tree.analysis.Analyzer.<init>()方法的一些代码示例,展示了Analyzer.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Analyzer.<init>()方法的具体详情如下:
包路径:org.objectweb.asm.tree.analysis.Analyzer
类名称:Analyzer
方法名:<init>

Analyzer.<init>介绍

[英]Constructs a new Analyzer.
[中]构造一个新的分析器。

代码示例

代码示例来源:origin: pxb1988/dex2jar

@Override
  public void visitFile(Path file, String relative) throws IOException {
    if (file.getFileName().toString().endsWith(".class")) {
      ClassReader cr = new ClassReader(Files.readAllBytes(file));
      ClassNode cn = new ClassNode();
      cr.accept(new CheckClassAdapter(cn, false),
          ClassReader.SKIP_DEBUG | ClassReader.EXPAND_FRAMES | ClassReader.SKIP_FRAMES);
      for (MethodNode method : cn.methods) {
        BasicVerifier verifier = new BasicVerifier();
        Analyzer<BasicValue> a = new Analyzer<>(verifier);
        try {
          a.analyze(cn.name, method);
        } catch (Exception ex) {
          System.err.println("Error verify method " + cr.getClassName() + "." + method.name + " "
              + method.desc);
          if (detail) {
            ex.printStackTrace(System.err);
            printAnalyzerResult(method, a, new PrintWriter(new OutputStreamWriter(System.err, StandardCharsets.UTF_8)));
          }
        }
      }
    }
  }
});

代码示例来源:origin: linkedin/parseq

@Override
public void visitEnd() {
 try {
  Analyzer analyzer = new Analyzer(new SourceInterpreter());
  Frame[] frames = analyzer.analyze(_classToAnalyze, this);

代码示例来源:origin: apache/groovy

MethodNode method = (MethodNode) methods.get(i);
if (method.instructions.size() > 0) {
  Analyzer a = new Analyzer(new SimpleVerifier());
  try {
    a.analyze(ca.name, method);

代码示例来源:origin: linkedin/parseq

@Override
public void visitEnd() {
 try {
  Analyzer analyzer = new Analyzer(new SourceInterpreter());
  Frame[] frames = analyzer.analyze(_classToAnalyze, this);
  int index = findMethodCall(this.instructions);
  if (index == -1) {
   return;
  }
  Frame f = frames[index];
  String fieldDesc = "";
  String methodDesc = "";
  for (int j = 0; j < f.getStackSize(); ++j) {
   SourceValue stack = (SourceValue) f.getStack(j);
   Object insn = stack.insns.iterator().next();
   if (insn instanceof FieldInsnNode) {
    FieldInsnNode fieldInstr = (FieldInsnNode) insn;
    fieldDesc = fieldInstr.name;
   } else if (insn instanceof TypeInsnNode) {
    fieldDesc = Util.getDescriptionForTypeInsnNode((TypeInsnNode) insn);
   } else if (insn instanceof MethodInsnNode) {
    methodDesc = Util.getDescriptionForMethodInsnNode((MethodInsnNode) insn);
   }
  }
  _inferredOperation = getInferredOperation(fieldDesc, methodDesc);
 } catch (AnalyzerException e) {
  System.out.println("Unable to analyze class, could not infer operation");
 }
}

代码示例来源:origin: pxb1988/dex2jar

@SuppressWarnings("rawtypes")
public static void verify(final ClassReader cr, PrintWriter out) throws AnalyzerException,
    IllegalArgumentException, IllegalAccessException {
  ClassNode cn = new ClassNode();
  cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);
  List methods = cn.methods;
  for (int i = 0; i < methods.size(); ++i) {
    MethodNode method = (MethodNode) methods.get(i);
    List tryCatchBlocks = method.tryCatchBlocks;
    for (int j = 0; j < tryCatchBlocks.size(); j++) {
      TryCatchBlockNode tcn = (TryCatchBlockNode) tryCatchBlocks.get(j);
      if (tcn.start.equals(tcn.end)) {
        throw new DexException("try/catch block %d in %s has same start(%s) and end(%s)", j, method.name,
            tcn.start.getLabel(), tcn.end.getLabel());
      }
    }
    BasicVerifier verifier = new BasicVerifier();
    Analyzer a = new Analyzer(verifier);
    try {
      a.analyze(cn.name, method);
    } catch (Exception e) {
      out.println(cr.getClassName() + "." + method.name + method.desc);
      printAnalyzerResult(method, a, out);
      e.printStackTrace(out);
      out.flush();
      throw new DexException("method " + method.name + " " + method.desc, e);
    }
  }
}

代码示例来源:origin: br.usp.each.saeg/asm-defuse

private DefUseAnalyzer(final DefUseInterpreter interpreter) {
  this(new Analyzer<Value>(interpreter), interpreter);
}

代码示例来源:origin: org.ow2.asm/asm-debug-all

@Override
  public void visitEnd() {
    Analyzer<BasicValue> a = new Analyzer<BasicValue>(
        new BasicVerifier());
    try {
      a.analyze("dummy", this);
    } catch (Exception e) {
      if (e instanceof IndexOutOfBoundsException
          && maxLocals == 0 && maxStack == 0) {
        throw new RuntimeException(
            "Data flow checking option requires valid, non zero maxLocals and maxStack values.");
      }
      e.printStackTrace();
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw, true);
      CheckClassAdapter.printAnalyzerResult(this, a, pw);
      pw.close();
      throw new RuntimeException(e.getMessage() + ' '
          + sw.toString());
    }
    accept(cmv);
  }
}, labels);

代码示例来源:origin: jhorstmann/i18n

public final void extractMessages(InputStream in) throws IOException, MessageExtractorException {
    ClassReader classReader = new ClassReader(in);
    ClassNode classNode = new ClassNode();
    classReader.accept(classNode, 0);

    interpreter.setCurrentClass(classNode);
    Analyzer analyzer = new Analyzer(interpreter);

    try {
      for (Iterator it=classNode.methods.iterator(); it.hasNext(); ) {
        MethodNode methodNode = (MethodNode) it.next();
        interpreter.setCurrentMethod(methodNode);
        analyzer.analyze(classNode.name, methodNode);
      }
    } catch (AnalyzerException ex) {
      throw new MessageExtractorException(ex);
    }
  }
}

代码示例来源:origin: net.jhorstmann/i18n-xgettext-asm

public final void extractMessages(InputStream in) throws IOException, MessageExtractorException {
    ClassReader classReader = new ClassReader(in);
    ClassNode classNode = new ClassNode();
    classReader.accept(classNode, 0);

    interpreter.setCurrentClass(classNode);
    Analyzer analyzer = new Analyzer(interpreter);

    try {
      for (Iterator it=classNode.methods.iterator(); it.hasNext(); ) {
        MethodNode methodNode = (MethodNode) it.next();
        interpreter.setCurrentMethod(methodNode);
        analyzer.analyze(classNode.name, methodNode);
      }
    } catch (AnalyzerException ex) {
      throw new MessageExtractorException(ex);
    }
  }
}

代码示例来源:origin: EvoSuite/evosuite

private Frame[] getArrayFrames(MethodNode mn) {
  try {
    Analyzer a = new Analyzer(new BooleanArrayInterpreter());
    a.analyze(cn.name, mn);
    return a.getFrames();
  } catch (Exception e) {
    logger.info("[Array] Error during analysis: " + e);
    return null;
  }
}

代码示例来源:origin: EvoSuite/evosuite

private void getFrames(MethodNode mn, String className) {
  try {
    Analyzer a = new Analyzer(new BooleanValueInterpreter(mn.desc,
        (mn.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC));
    a.analyze(className, mn);
    this.frames = a.getFrames();
  } catch (Exception e) {
    logger.info("1. Error during analysis: " + e);
    //e.printStackTrace();
    // TODO: Handle error
  }
}

代码示例来源:origin: org.lwjgl.lwjgl/lwjgl_util

private Frame<BasicValue>[] analyse() throws AnalyzerException {
  final Analyzer<BasicValue> a = new Analyzer<BasicValue>(new SimpleVerifier());
  a.analyze(className, this);
  return a.getFrames();
}

代码示例来源:origin: org.apache.aries.spifly/org.apache.aries.spifly.dynamic.framework.extension

@Override
public void visitEnd() {
 Analyzer<BasicValue> analyzer = new Analyzer<BasicValue>(new BasicVerifier());
 try {
  analyzer.analyze("dummy", this);
 } catch (IndexOutOfBoundsException e) {
  if (maxLocals == 0 && maxStack == 0) {
   throw new IllegalArgumentException(
     "Data flow checking option requires valid, non zero maxLocals and maxStack.",
     e);
  }
  throwError(analyzer, e);
 } catch (AnalyzerException e) {
  throwError(analyzer, e);
 }
 accept(methodVisitor);
}

代码示例来源:origin: org.apache.aries.spifly/org.apache.aries.spifly.dynamic.bundle

@Override
public void visitEnd() {
 Analyzer<BasicValue> analyzer = new Analyzer<BasicValue>(new BasicVerifier());
 try {
  analyzer.analyze("dummy", this);
 } catch (IndexOutOfBoundsException e) {
  if (maxLocals == 0 && maxStack == 0) {
   throw new IllegalArgumentException(
     "Data flow checking option requires valid, non zero maxLocals and maxStack.",
     e);
  }
  throwError(analyzer, e);
 } catch (AnalyzerException e) {
  throwError(analyzer, e);
 }
 accept(methodVisitor);
}

代码示例来源:origin: fge/grappa

public static void verifyMethodIntegrity(final String ownerInternalName, final MethodNode method) {
  try {
    new Analyzer(new SimpleVerifier()).analyze(ownerInternalName, method);
  } catch (AnalyzerException e) {
    throw new RuntimeException(
        "Integrity error in method '" + method.name + "' of type '" + ownerInternalName + "': ", e);
  }
}

代码示例来源:origin: vsilaev/tascalate-javaflow

public void visitEnd() {
  if (instructions.size() == 0 || labels.size() == 0) {
    accept(mv);
    return;
  }
  this.stackRecorderVar = maxLocals;
  try {
    moveNew();
    analyzer = new Analyzer(new FastClassVerifier(inheritanceLookup)) {
      @Override
      protected Frame newFrame(int nLocals, final int nStack) {
        return new MonitoringFrame(nLocals, nStack);
      }
      @Override
      protected Frame newFrame(Frame src) {
        return new MonitoringFrame(src);
      }
    };
    analyzer.analyze(className, this);
    accept(new ContinuableMethodVisitor(this));
  } catch (AnalyzerException ex) {
    throw new RuntimeException(ex);
  }
}

代码示例来源:origin: vsilaev/tascalate-javaflow

public void visitEnd() {
  checkCallSites();
  if (instructions.size() == 0 || labels.size() == 0) {
    accept(mv);
    return;
  }
  this.stackRecorderVar = maxLocals;
  try {
    moveNew();
    analyzer = new Analyzer(new FastClassVerifier(inheritanceLookup)) {
      @Override
      protected Frame newFrame(int nLocals, int nStack) {
        return new MonitoringFrame(nLocals, nStack);
      }
      @Override
      protected Frame newFrame(Frame src) {
        return new MonitoringFrame(src);
      }
    };
    analyzer.analyze(className, this);
    accept(new ContinuableMethodVisitor(this));
  } catch (AnalyzerException ex) {
    throw new RuntimeException(ex);
  }
}

代码示例来源:origin: net.tascalate.javaflow/net.tascalate.javaflow.providers.asm5

@Override
public void visitEnd() {
  checkCallSites();
  if (instructions.size() == 0 || labels.size() == 0) {
    accept(mv);
    return;
  }
  this.stackRecorderVar = maxLocals;
  try {
    moveNew();
    analyzer = new Analyzer(new FastClassVerifier(inheritanceLookup)) {
      @Override
      protected Frame newFrame(int nLocals, int nStack) {
        return new MonitoringFrame(nLocals, nStack);
      }
      @Override
      protected Frame newFrame(Frame src) {
        return new MonitoringFrame(src);
      }
    };
    analyzer.analyze(className, this);
    accept(new ContinuableMethodVisitor(this));
  } catch (AnalyzerException ex) {
    throw new RuntimeException(ex);
  }
}

代码示例来源:origin: vsilaev/tascalate-javaflow

public void visitEnd() {
  checkCallSites();
  if (instructions.size() == 0 || labels.size() == 0) {
    accept(mv);
    return;
  }
  this.stackRecorderVar = maxLocals;
  try {
    moveNew();
    analyzer = new Analyzer<BasicValue>(new FastClassVerifier(inheritanceLookup)) {
      @Override
      protected Frame<BasicValue> newFrame(int nLocals, int nStack) {
        return new MonitoringFrame<>(nLocals, nStack);
      }
      @Override
      protected Frame<BasicValue> newFrame(Frame<? extends BasicValue> src) {
        return new MonitoringFrame<BasicValue>(src);
      }
    };
    analyzer.analyze(className, this);
    accept(new ContinuableMethodVisitor(this));
  } catch (AnalyzerException ex) {
    throw new RuntimeException(ex);
  }
}

代码示例来源:origin: jpcsp/jpcsp

/**
 * Remove the dead code - or unreachable code - from a method.
 * 
 * @param method  the method to be updated
 */
private void removeDeadCode(MethodNode method) {
  try {
    // Analyze the method using the BasicInterpreter.
    // As a result, the computed frames are null for instructions
    // that cannot be reached.
    Analyzer analyzer = new Analyzer(new BasicInterpreter());
    analyzer.analyze(specializedClassName, method);
    Frame[] frames = analyzer.getFrames();
    AbstractInsnNode[] insns = method.instructions.toArray();
    for (int i = 0; i < frames.length; i++) {
      AbstractInsnNode insn = insns[i];
      if (frames[i] == null && insn.getType() != AbstractInsnNode.LABEL) {
        // This instruction was not reached by the analyzer
        method.instructions.remove(insn);
        insns[i] = null;
      }
    }
  } catch (AnalyzerException e) {
    // Ignore error
  }
}

相关文章