Soot学习笔记(1)-Adding profiling instructions to applications

本文介绍了如何使用Soot库在应用程序中添加分析指令,详细讲解了SootClass, SootMethod和Unit类的用法。通过加载类、创建方法和添加代码到JimpleBody,展示了构建和操作Java类的方法。" 106421673,8322198,使用DFS解决LeetCode 1219的C++实现,"['算法', 'LeetCode', 'C++编程', '深度优先搜索', '回溯']
摘要由CSDN通过智能技术生成

相关网页地址:https://github.com/Sable/soot/wiki/Adding-profiling-instructions-to-applications

这篇博文讲 SootClass, SootMethod and Unit classes 这几个类的具体使用方法。

1.首先,我们先要可以创造一个类来把方法放进去,下面是创造一个类的必要步骤:
(1)加载java.lang.Object,和库类。又由于这个类需要其他的类支持,又要加载Scene.v().loadClassAndSupport(“java.lang.System”);
The Scene is the container for all of the SootClasses in a program, and provides various utility methods. There is a singleton Scene object, accessible by calling Scene.v().

(2)加载SootClass,创建类
Create the HelloWorld’ SootClass, and set its super class as`java.lang.Object”.

sClass = new SootClass(“HelloWorld”, Modifier.PUBLIC);
This code creates a SootClass object for a public class named HelloWorld.

sClass.setSuperclass(Scene.v().getSootClass(“java.lang.Object”));
This sets the superclass of the newly-created class to the SootClass object for java.lang.Object. Note the use of the utility method getSootClass on the Scene.

Scene.v().addClass(sClass);
This adds the newly-created HelloWorld class to the Scene. All classes should belong to the Scene once they are created.

(3)在创建的Class中创建方法Main!
Adding methods to SootClasses

Create a main() method for HelloWorld with an empty body.

Now that we have a SootClass, we need to add methods to it.

**method = new SootMethod(“main”,
Arrays.asList(new Type[] {ArrayType.v(RefType.v(“java.lang.String”), 1)}),
VoidType.v(), Modifier.PUBLIC | Modifier.STATIC);**

We create a new public static method, main, declare that it takes an array of java.lang.String objects, and that it returns void.

The constructor for SootMethod takes a list, so we call the Java utility method Arrays.asList to create a list from the one-element array which we generate on the fly with new Type[] … . In the list, we put an array type, corresponding to a one-dimensional ArrayType of java.lang.String objects. The call to RefType fetches the type corresponding to the java.lang.String class.

Types Each SootClass represents a Java object. We can instantiate the class, giving an object with a given type. The two notions - type and class - are closely related, but distinct. To get the type for the java.lang.String class, by name, we call RefType.v(“java.lang.String”). Given a SootClass object sc, we could also call sc.getType() to get the corresponding type.

sClass.addMethod(method);

(4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值