Soot Library Field已存在

时间:2016-06-27 14:24:00

标签: java soot

我想在“向应用程序添加分析说明”教程中编写示例代码,因此我按照教程所述编写程序。但是当我运行它时我得到了这个错误:

  

[Thread-3] ERROR heros.solver.CountingThreadPoolExecutor - 工作线程执行失败:字段已存在:gotoCount类型

此错误与

对应
  

Scene.v()getMainClass()激活addField(gotoCounter);

我把我写的代码:

import soot.*;
import soot.jimple.*;
import soot.util.Chain;
import java.util.Iterator;
import java.util.Map;

public class GoToInstrumenter extends BodyTransformer {
private static GoToInstrumenter instance = new GoToInstrumenter();
private GoToInstrumenter() {}
public static GoToInstrumenter v() { return instance; }
protected void internalTransform(Body body, String phaseName, Map options) {
    if (!Scene.v().getMainClass().
            declaresMethod("void main(java.lang.String[])"))
        throw new RuntimeException("couldn't find main() in mainClass");
    SootField gotoCounter;
    SootClass javaIoPrintStream;
    boolean addedFieldToMainClassAndLoadedPrintStream=false;
    if (addedFieldToMainClassAndLoadedPrintStream)
        gotoCounter = Scene.v().getMainClass().getFieldByName("gotoCount");
    else
    {

        gotoCounter = new SootField("gotoCount", LongType.v(),
                Modifier.STATIC);
        Scene.v().getMainClass().addField(gotoCounter);

        Scene.v().loadClassAndSupport("java.io.PrintStream");
        javaIoPrintStream =Scene.v().getSootClass("java.io.PrintStream");

        addedFieldToMainClassAndLoadedPrintStream = true;
    }
    boolean isMainMethod = body.getMethod().getSubSignature()
            .equals("void main(java.lang.String[])");
    Local tmpLocal = Jimple.v().newLocal("tmp", LongType.v());
    body.getLocals().add(tmpLocal);
    Iterator stmtIt = body.getUnits().snapshotIterator();
    Chain units=body.getUnits();
    while (stmtIt.hasNext()) {
        Stmt s = (Stmt) stmtIt.next();
        if (s instanceof GotoStmt) {
            AssignStmt toAdd1 = Jimple.v().newAssignStmt(tmpLocal,
                    Jimple.v().newStaticFieldRef(gotoCounter.makeRef()));
            units.insertBefore(toAdd1, s);
       }

         }

      }
  }

请帮助我,我找不到导致这个问题的原因?

0 个答案:

没有答案