本文整理了Java中org.objectweb.asm.tree.analysis.Analyzer
类的一些代码示例,展示了Analyzer
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Analyzer
类的具体详情如下:
包路径:org.objectweb.asm.tree.analysis.Analyzer
类名称:Analyzer
[英]A semantic bytecode analyzer. This class does not fully check that JSR and RET instructions are valid.
[中]语义字节码分析器。此类不会完全检查JSR和RET指令是否有效。
代码示例来源:origin: linkedin/parseq
@Override
public void visitEnd() {
try {
Analyzer analyzer = new Analyzer(new SourceInterpreter());
Frame[] frames = analyzer.analyze(_classToAnalyze, this);
for (int j = 0; j < f.getStackSize(); ++j) {
SourceValue stack = (SourceValue) f.getStack(j);
代码示例来源:origin: pxb1988/dex2jar
static void printAnalyzerResult(MethodNode method, Analyzer a, final PrintWriter pw)
throws IllegalArgumentException {
Frame[] frames = a.getFrames();
Textifier t = new Textifier();
TraceMethodVisitor mv = new TraceMethodVisitor(t);
String format = "%05d %-" + (method.maxStack + method.maxLocals + 6) + "s|%s";
for (int j = 0; j < method.instructions.size(); ++j) {
method.instructions.get(j).accept(mv);
s.append('?');
} else {
for (int k = 0; k < f.getLocals(); ++k) {
s.append(getShortName(f.getLocal(k).toString()));
for (int k = 0; k < f.getStackSize(); ++k) {
s.append(getShortName(f.getStack(k).toString()));
代码示例来源: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: apache/groovy
for (int i = 0; i < methods.size(); ++i) {
MethodNode method = (MethodNode) methods.get(i);
if (method.instructions.size() > 0) {
Analyzer a = new Analyzer(new SimpleVerifier());
try {
a.analyze(ca.name, method);
continue;
} catch (Exception e) {
for (int j = 0; j < method.instructions.size(); ++j) {
Object insn = method.instructions.get(j);
if (insn instanceof AbstractInsnNode) {
((AbstractInsnNode) insn).accept(mv);
代码示例来源:origin: net.tascalate.javaflow/net.tascalate.javaflow.providers.asm5
private void moveNew() throws AnalyzerException {
SourceInterpreter i = new SourceInterpreter();
Analyzer a = new Analyzer(i);
a.analyze(className, this);
Frame[] frames = a.getFrames();
for (int j = 0; j < methods.size(); j++) {
MethodInsnNode mnode = (MethodInsnNode) methods.get(j);
int n = instructions.indexOf(mnode);
Frame f = frames[n];
Type[] args = Type.getArgumentTypes(mnode.desc);
SourceValue v = (SourceValue) f.getStack(f.getStackSize() - args.length - 1);
@SuppressWarnings("unchecked")
Set<AbstractInsnNode> insns = v.insns;
} else {
int n1 = instructions.indexOf(ins);
if (ins.getOpcode() == DUP) { // <init> with params
AbstractInsnNode ins1 = instructions.get(n1 - 1);
if (ins1.getOpcode() == NEW) {
movable.put(ins1, mnode);
代码示例来源:origin: org.multiverse/multiverse-alpha-unborn
Analyzer a = new Analyzer(new SourceInterpreter());
Frame[] frames;
try {
frames = a.analyze(classNode.name, methodNode);
} catch (AnalyzerException e) {
throw new CompileException("failed to create frames for " + classMetadata.getName() + "." + methodNode.name);
int tranlocalVar = indexOfTranlocalVariable(methodNode.name, methodNode.desc);
InsnList newInstructions = new InsnList();
newInstructions.add(startLabelNode);
newInstructions.add(new LineNumberNode(debugInfo.beginLine, startLabelNode));
for (int k = 0; k < methodNode.instructions.size(); k++) {
Frame methodFrame = frames[methodNode.instructions.indexOf(originalFieldInsnNode)];
int size = 1 + (AsmUtils.isCategory2(originalFieldInsnNode.desc) ? 2 : 1);
int stackSlot = methodFrame.getStackSize() - size;
SourceValue stackValue = (SourceValue) methodFrame.getStack(stackSlot);
boolean aload0 = false;
} else {
Frame methodFrame = frames[methodNode.instructions.indexOf(originalFieldInsnNode)];
int stackSlot = methodFrame.getStackSize() - 1;
SourceValue stackValue = (SourceValue) methodFrame.getStack(stackSlot);
代码示例来源: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: EvoSuite/evosuite
try {
mn.maxStack++;
Analyzer a = new Analyzer(new StringBooleanInterpreter());
a.analyze(cn.name, mn);
Frame[] frames = a.getFrames();
AbstractInsnNode node = mn.instructions.getFirst();
boolean done = false;
while (!done) {
if (node == mn.instructions.getLast())
done = true;
AbstractInsnNode next = node.getNext();
int index = mn.instructions.indexOf(node);
if (index >= frames.length)
break;
if (current == null)
break;
int size = current.getStackSize();
if (node.getOpcode() == Opcodes.IFNE) {
JumpInsnNode branch = (JumpInsnNode) node;
if (current.getStack(size - 1) == StringBooleanInterpreter.STRING_BOOLEAN
|| isStringMethod(node.getPrevious())) {
logger.info("IFNE -> IFGT");
if (current.getStack(size - 1) == StringBooleanInterpreter.STRING_BOOLEAN
|| isStringMethod(node.getPrevious())) {
logger.info("IFEQ -> IFLE");
代码示例来源:origin: fge/grappa
= new BasicInterpreter();
final Analyzer<BasicValue> analyzer
= new Analyzer<>(basicInterpreter);
final AbstractInsnNode[] nodes = instructions.toArray();
final Frame<BasicValue>[] frames
= analyzer.analyze(className, this);
int areturn = -1;
for (int i = nodes.length -1; i >= 0; i--)
} else if (areturn != -1
&& nodes[i].getOpcode() != -1
&& frames[i].getStackSize() == 0) {
System.out.println("Found start of block at: " + i);
final InsnList list = new InsnList();
for (int j = i; j <= areturn; j++)
list.add(nodes[j]);
final Textifier textifier = new Textifier();
final PrintWriter pw = new PrintWriter(System.out);
代码示例来源:origin: org.ow2.asm/asm-debug-all
List<AbstractInsnNode> subroutineCalls = new ArrayList<AbstractInsnNode>();
Map<LabelNode, Subroutine> subroutineHeads = new HashMap<LabelNode, Subroutine>();
findSubroutine(0, main, subroutineCalls);
while (!subroutineCalls.isEmpty()) {
JumpInsnNode jsr = (JumpInsnNode) subroutineCalls.remove(0);
sub = new Subroutine(jsr.label, m.maxLocals, jsr);
subroutineHeads.put(jsr.label, sub);
findSubroutine(insns.indexOf(jsr.label), sub, subroutineCalls);
} else {
sub.callers.add(jsr);
Frame<V> current = newFrame(m.maxLocals, m.maxStack);
Frame<V> handler = newFrame(m.maxLocals, m.maxStack);
current.setReturn(interpreter.newValue(Type.getReturnType(m.desc)));
Type[] args = Type.getArgumentTypes(m.desc);
int local = 0;
if ((m.access & ACC_STATIC) == 0) {
Type ctype = Type.getObjectType(owner);
current.setLocal(local++, interpreter.newValue(ctype));
merge(0, current, null);
init(owner, m);
|| insnType == AbstractInsnNode.LINE
|| insnType == AbstractInsnNode.FRAME) {
merge(insn + 1, f, subroutine);
newControlFlowEdge(insn, insn + 1);
代码示例来源: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: dragome/dragome-sdk
public Frame[] analyze(final String owner, final MethodNode m) throws AnalyzerException
{
// System.out.println("Analyze: "+owner+"|"+m.name+"|"+m.signature+"|"+m.tryCatchBlocks);
final Frame[] frames= super.analyze(owner, m);
for (int i= 0; i < m.instructions.size(); i++)
{
int opcode= m.instructions.get(i).getOpcode();
if (opcode == MONITORENTER || opcode == MONITOREXIT)
{
// System.out.println(i);
}
}
return frames;
}
};
代码示例来源:origin: br.usp.each.saeg/asm-defuse
@Override
@SuppressWarnings("unchecked")
public Frame<V>[] analyze(final String owner, final MethodNode m) throws AnalyzerException {
n = m.instructions.size();
final Frame<V>[] frames = super.analyze(owner, m);
if (frames.length == 0) {
return frames;
代码示例来源: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
}
}
代码示例来源:origin: com.android.tools.lint/lint-checks
@Override
protected boolean newControlFlowExceptionEdge(int insn, int successor) {
AbstractInsnNode from = instructions.get(insn);
AbstractInsnNode to = instructions.get(successor);
graph.exception(from, to);
return super.newControlFlowExceptionEdge(insn, successor);
}
};
代码示例来源:origin: dragome/dragome-sdk
Frame frame= analyzer.getFrames()[canalyzer.getIndex(mnode)];
int lsize= frame.getLocals();
for (int j= lsize - 1; j >= 0; j--)
BasicValue value= (BasicValue) frame.getLocal(j);
if (isNull(value))
int ownerSize= mnode.getOpcode() == INVOKESTATIC ? 0 : 1; // TODO
int initSize= mnode.name.equals("<init>") ? 2 : 0;
int ssize= frame.getStackSize();
for (int j= 0; j < ssize - argSize - ownerSize - initSize; j++)
代码示例来源:origin: net.tascalate.javaflow/net.tascalate.javaflow.providers.asm5
Frame getFrameByNode(AbstractInsnNode node) {
int insIndex = instructions.indexOf(node);
Frame[] frames = analyzer.getFrames();
return null == frames || insIndex >= frames.length ? null : frames[insIndex];
}
代码示例来源:origin: org.ow2.asm/asm-debug-all
/**
* Creates a control flow graph edge corresponding to an exception handler.
* The default implementation of this method delegates to
* {@link #newControlFlowExceptionEdge(int, int)
* newControlFlowExceptionEdge(int, int)}. It can be overridden in order to
* construct the control flow graph of a method (this method is called by
* the {@link #analyze analyze} method during its visit of the method's
* code).
*
* @param insn
* an instruction index.
* @param tcb
* TryCatchBlockNode corresponding to this edge.
* @return true if this edge must be considered in the data flow analysis
* performed by this analyzer, or false otherwise. The default
* implementation of this method delegates to
* {@link #newControlFlowExceptionEdge(int, int)
* newControlFlowExceptionEdge(int, int)}.
*/
protected boolean newControlFlowExceptionEdge(final int insn,
final TryCatchBlockNode tcb) {
return newControlFlowExceptionEdge(insn, insns.indexOf(tcb.handler));
}
代码示例来源:origin: co.paralleluniverse/quasar
public InstrumentMethod(MethodDatabase db, String className, MethodNode mn) throws AnalyzerException {
this.db = db;
this.className = className;
this.mn = mn;
try {
Analyzer a = new TypeAnalyzer(db);
this.frames = a.analyze(className, mn);
this.lvarStack = mn.maxLocals;
this.firstLocal = ((mn.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC) ? 0 : 1;
} catch (UnsupportedOperationException ex) {
throw new AnalyzerException(null, ex.getMessage(), ex);
}
}
代码示例来源:origin: br.usp.each.saeg/asm-defuse
private DefUseAnalyzer(final DefUseInterpreter interpreter) {
this(new Analyzer<Value>(interpreter), interpreter);
}
内容来源于网络,如有侵权,请联系作者删除!