Skip to content

Soot migration

Alexey Volkov edited this page Dec 12, 2022 · 10 revisions

Soot migration

Terminology:

Soot JacoDB
bytecode storage - JacoDB
scope of visible classes Scene JcClasspath
class SootClass JcClassOrInterface
class method SootMethod JcMethod
class field SootField JcField
type (with generics substitution) - JcJvmType
3-address bytecode representation JimpleBody JcRawInstList
Control flow graph ClassicCompleteUnitGraph JcGraph

Operations

create storage

Soot JacoDB
// points to specific runtime version
G.v().initJdk(new G.JreInfo(location, version)); 
Options options = Options.v();
options.set_soot_classpath(files);
Scene.v().loadNecessaryClasses();
PackManager.v().runPacks();
val db = jacodb {
    // points to specific runtime version
    useJavaRuntime(runtimeFolder)
    // jars to process
    loadByteCode(listOf(jar1, jar2))
    // persist all information to improve performance between restarts
    persistent(location = "/home/user/jcdb.db", clearOnStart = false)
}
val classpath = db.classpath(listOf(jar1))

find class

Soot JacoDB
SootClass clazz = Scene.v().getSootClass("java.lang.String");
val clazz = classpath.findClassOrNull("java.lang.String")

Get 3-address bytecode representation

Soot JacoDB
SootClass clazz = Scene.v().getSootClass("java.lang.String");
clazz.getMethod("length", Lists.emptyList()).retrieveActiveBody()
val clazz = classpath.findClassOrNull("java.lang.String") ?: throw  IllegalStateException()
classpath.findMethod("length").instructionList()

Get control flow graph

Soot JacoDB
ClassicCompleteUnitGraph graph = new ClassicCompleteUnitGraph(sootMmthod.getActiveBody());
val cfg = jcMethod.instructionList().graph()

Clone this wiki locally