如何使用Soot SPARK来获取Web应用程序在Spring框架下的精确调用图?

huangapple go评论84阅读模式
英文:

How can I get a precise callgraph for a web Application using spring FrameWork by soot SPARK?

问题

我想要在分析使用Spring框架的Web应用程序时获得精确的调用图(使用Soot SPARK),但我有一个需要解决的重要问题:
Spring使用依赖注入(DI)来管理Bean,这意味着我们不需要创建对象。因此,对于某些接口,我无法获得精确的调用图(使用SPARK)。

示例:
当我使用Soot通过SPARK获取调用图(mainClass = AnimalMain.main(String[] args))时,它无法找到"Animal pig"和"Animal human"的实现类,因此结果不包含任何关于"pig.eat()"的边缘。因此,对于使用Spring框架的Web应用程序来说,这不实用。

如何获取精确的调用图?

public class AnimalMain {
    @Autowired
    Animal pig;

    @Autowired
    Animal human;

    Tree pineTree = new PineTree();

    public static void main(String[] args) {
        AnimalMain animalMain = new AnimalMain();
        animalMain.eat();
    }

    void eat() {
        pig.eat();
        pineTree.grow();
    }
}
public interface Animal {
    void eat();
}
@Component(value = "pig")
public class Pig implements Animal {
    @Override
    public void eat() {
        System.out.println(doEat());
    }

    private String doEat() {
        return "pig eat";
    }
}
@Component(value = "human")
public class Human implements Animal {
    @Override
    public void eat() {
        System.out.println("human eat ...");
    }
}
英文:

I want to get a precise callgraph (using soot SPARK) when analysising a web Application using spring FrameWork, but I have one big problem to solve:
Spring use DI (Dependency Injection) to manage beans , which means we don't need to create an Object. For this instance, I can't get precise callgraph (using SPARK) for some interface.

Example:
When I use soot to get the call graph by SPARK( mainClass = AnimalMain.main(String[] args)), it can't find the implement class of "Animal pig" and "Animal human", so the result don't contains any edge about "pig.eat()". So it is not practical for Web Applications using Spring FrameWork。

How can I get a precise callgraph ?

public class AnimalMain {
@Autowired
Animal pig;

@Autowired
Animal human;

Tree pineTree = new PineTree();

public static void main(String[] args) {
    AnimalMain animalMain = new AnimalMain();
    animalMain.eat();
}

void eat() {
    pig.eat();
    pineTree.grow();
}
}

public interface Animal {
void eat();
}
@component(value = "pig")
public class Pig implements Animal {

@Override
public void eat() {
    System.out.println(doEat());
}

private String doEat() {
    return "pig eat";
}
}

@component(value = "human")
public class Human implements Animal {
@override
public void eat() {
System.out.println("human eat ……");
}
}

答案1

得分: 1

我们(Soot团队)目前还没有一个良好的解决方案,但我们正在努力解决这个问题。

英文:

We (the Soot team) do not have a well working solution for this yet, but we are working on this at the moment.

huangapple
  • 本文由 发表于 2020年8月7日 17:16:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/63298805.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定