# Soot Tutorial
[![Build Status](https://travis-ci.com/noidsirius/SootTutorial.svg?branch=master)](https://travis-ci.com/noidsirius/SootTutorial)
[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/noidsirius/SootTutorial)
[![Docker Pull](https://img.shields.io/docker/pulls/noidsirius/soot_tutorial)](https://hub.docker.com/r/noidsirius/soot_tutorial)
This repository contains (will contain) several simple examples of static program analysis in Java using [Soot](https://github.com/Sable/soot).
## Who this tutorial is for?
Anybody who knows Java programming and wants to do some static analysis in practice but does not know anything about Soot and static analysis in theory.
If you have some prior knowledge about static program analysis I suggest you learn Soot from [here](https://github.com/Sable/soot/wiki/Tutorials).
### [Why another tutorial for Soot?](docs/Other/Motivation.md)
## Setup
In short, use Java 8 and run `./gradlew build`. For more information and Docker setup, follow this [link](docs/Setup/).
## Chapters
### 1: Get your hands dirty
In this chapter, you will visit a very simple code example to be familiar with Soot essential data structures and **Jimple**, Soot's principle intermediate representation.
* `./gradlew run --args="HelloSoot"`: The Jimple representation of the [printFizzBuzz](demo/HelloSoot/FizzBuzz.java) method alongside the branch statement.
* `./gradlew run --args="HelloSoot draw"`: The visualization of the [printFizzBuzz](demo/HelloSoot/FizzBuzz.java) control-flow graph.
|Title |Tutorial | Soot Code | Example Input |
| :---: |:-------------: |:-------------:| :-----:|
|Hello Soot |[Doc](docs/1/) | [HelloSoot.java](src/main/java/dev/navids/soottutorial/hellosoot/HelloSoot.java) | [FizzBuzz.java](demo/HelloSoot/FizzBuzz.java) |
<img src="docs/1/images/cfg.png" alt="Control Flow Graph" width="400"/>
### 2: Know the basic APIs
In this chapter, you get familiar with some basic but useful methods in Soot to help read, analyze, and even update java code.
* `./gradlew run --args="BasicAPI"`: Analyze the class [Circle](demo/BasicAPI/Circle.java).
* `./gradlew run --args="BasicAPI draw"`: Analyze the class [Circle](demo/BasicAPI/Circle.java) and draws the call graph.
|Title |Tutorial | Soot Code | Example Input |
| :---: |:-------------: |:-------------:| :-----:|
|Basic API |[Doc](https://medium.com/@noidsirius/know-the-basic-tools-in-soot-18f394318a9c)| [BasicAPI.java](src/main/java/dev/navids/soottutorial/basicapi/BasicAPI.java) | [Circle](demo/BasicAPI/Circle.java) |
<img src="docs/2/images/callgraph.png" alt="Call Graph" width="400"/>
### 3: Android Instrumentation
In this chapter, you learn how to insert code into Android apps (without having their source code) using Soot. To run the code, you need Android SDK (check this [link](docs/Setup/)).
* `./gradlew run --args="AndroidLogger"`: Insert logging method calls at the beginning of APK methods of [Numix Calculator](demo/Android/calc.apk).
* `./gradlew run --args="AndroidClassInjector"`: Create a new class from scratch and inject it to the [Numix Calculator](demo/Android/calc.apk).
The instrumented APK is located in `demo/Android/Instrumented`. You need to sign it in order to install on an Android device:
```aidl
cd ./demo/Android
./sign.sh Instrumented/calc.apk key "android"
adb install -r -t Instrumented/calc.apk
```
To see the logs, run `adb logcat | grep -e "<SOOT_TUTORIAL>"`
|Title |Tutorial | Soot Code | Example APK|
| :---: |:-------------: |:-------------:| :-----:|
|Log method calls in an APK| [Doc](https://medium.com/@noidsirius/instrumenting-android-apps-with-soot-dd6f146ff4d2)| [AndroidLogger.java](src/main/java/dev/navids/soottutorial/android/AndroidLogger.java) | [Numix Calculator](demo/Android/calc.apk) (from [F-Droid](https://f-droid.org/en/packages/com.numix.calculator/))|
|Create and inject a class into an APK| [Doc](https://medium.com/@noidsirius/instrumenting-android-apps-with-soot-dd6f146ff4d2) | [AndroidClassInjector.java](src/main/java/dev/navids/soottutorial/android/AndroidClassInjector.java) | [Numix Calculator](demo/Android/calc.apk) (from [F-Droid](https://f-droid.org/en/packages/com.numix.calculator/))|
<img src="docs/3/images/packs.png" alt="Soot Packs + Dexpler" width="400"/>
### 4: Call graphs and PointsTo Analysis in Android
This chapter gives you a brief overview o call graphs and PointsTo analysis in Android and you learn how to create calls graphs using FlowDroid. The source code of the example code is [here](demo/Android/STDemoApp). To run the code, you need Android SDK (check this [link](docs/Setup/)).
* `./gradlew run --args="AndroidCallGraph <CG_Algorithm> (draw)"`: Create the call graph of [SootTutorial Demo App](demo/Android/st_demo.apk) using `<CG_Algorithm>` algorithm and print information such as reachable methods or the number of edges.
* `<CG_Algorithm>` can be `SPARK` or `CHA`
* `draw` argument is optional, if provided a visualization of call graph will shown.
* For example, `./gradlew run --args="AndroidCallGraph SPARK draw"` visualizes the call graph generated by SPARK algorithm.
* `./gradlew run --args="AndroidPTA"`: Perform PointsTo and Alias Analysis on [SootTutorial Demo App](demo/Android/st_demo.apk) using FlowDroid.
|Title |Tutorial | Soot Code | Example APK|
| :---: |:-------------: |:-------------:| :-----:|
|Call graphs in Android| [Doc](https://medium.com/geekculture/generating-call-graphs-in-android-using-flowdroid-pointsto-analysis-7b2e296e6697)| [AndroidCallgraph.java](src/main/java/dev/navids/soottutorial/android/AndroidCallgraph.java) | [SootTutorial Demo App](demo/Android/st_demo.apk) ([source code](demo/Android/STDemoApp))|
|PointsTo Analysis in Android| [Doc](https://medium.com/geekculture/generating-call-graphs-in-android-using-flowdroid-pointsto-analysis-7b2e296e6697)| [AndroidPointsToAnalysis.java](src/main/java/dev/navids/soottutorial/android/AndroidPointsToAnalysis.java) | [SootTutorial Demo App](demo/Android/st_demo.apk) ([source code](demo/Android/STDemoApp))|
<img src="docs/4/images/Spark_CG.png" alt="The call graph of SootTutorial Demo app" width="400"/>
### 5: Some *Real* Static Analysis (:construction: WIP)
* `./gradlew run --args="UsageFinder 'void println(java.lang.String)' 'java.io.PrintStream"`: Find usages of the method with the given subsignature in all methods of [UsageExample.java](demo/IntraAnalysis/UsageExample.java).
* `./gradlew run --args="UsageFinder 'void println(java.lang.String)' 'java.io.PrintStream"`: Find usages of the method with the given subsignature of the given class signature in all methods of [UsageExample.java](demo/IntraAnalysis/UsageExample.java).
|Title |Tutorial | Soot Code | Example Input |
| :---: |:-------------: |:-------------:| :-----:|
|Find usages of a method| | [UsageFinder.java](src/main/java/dev/navids/soottutorial/intraanalysis/usagefinder/UsageFinder.java) | [UsageExample.java](demo/IntraAnalysis/usagefinder/UsageExample.java) |
|Null Pointer Analysis ||[NullPointerAnalysis](src/main/java/dev/navids/soottutorial/intraanalysis/npanalysis/) | [NullPointerExample.java](demo/IntraAnalysis/NullPointerExample.java) |
### 6: Interprocedural analysis (:construction: WIP)
|Title |Tutorial | Soot Code | Example Input |
| :---: |:-------------: |:-------------:| :-----:|
| | | | |
没有合适的资源?快使用搜索试试~ 我知道了~
SootTutorial:Soot分步教程(Java静态分析框架)
共96个文件
java:31个
png:16个
xml:10个
5星 · 超过95%的资源 需积分: 50 23 下载量 3 浏览量
2021-05-16
08:12:50
上传
评论 3
收藏 4.52MB ZIP 举报
温馨提示
烟灰教程 该存储库包含(将包含)使用在Java中进行静态程序分析的几个简单示例。 本教程适用于谁? 任何了解Java编程并想在实践中进行静态分析但对理论上的Soot和静态分析一无所知的人。 如果您对静态程序分析有一定的了解,建议您从学习Soot。 设置 简而言之,使用Java 8并运行./gradlew build 。 有关更多信息和Docker设置,请单击此。 章节 1:弄脏你的手 在本章中,您将访问一个非常简单的代码示例,以熟悉Soot基本数据结构和Jimple (Soot的原理中间表示)。 ./gradlew run --args="HelloSoot" : 方法的Jimple表示形式以及分支语句。 ./gradlew run --args="HelloSoot draw" : 控制流图的可视化。 标题 教程 烟尘代码 输入示例 你好煤烟 HelloSoot.java
资源推荐
资源详情
资源评论
收起资源包目录
SootTutorial-master.zip (96个子文件)
SootTutorial-master
Dockerfile 707B
.gitignore 150B
gradle
wrapper
gradle-wrapper.jar 54KB
gradle-wrapper.properties 232B
README.md 7KB
build.gradle 2KB
.github
workflows
gradle-publish.yml 994B
gradlew.bat 3KB
docs
1
README.md 6KB
images
cfg-number.png 123KB
sootarch.png 155KB
cfg.png 165KB
Other
Motivation.md 2KB
4
images
Spark_CG.png 293KB
.DS_Store 6KB
2
images
callgraph.png 94KB
Setup
README.md 1KB
3
images
packs.png 194KB
gradlew 6KB
LICENSE 34KB
src
test
java
dev
navids
soottutorial
BasicAPITest.java 2KB
android
CGPTATest.java 6KB
AndroidInstrumentTest.java 3KB
HelloSootTest.java 1KB
main
java
dev
navids
soottutorial
intraanalysis
usagefinder
UsageFinder.java 3KB
npanalysis
NullPointerAnalysis.java 3KB
NullFlowSet.java 1KB
NPAMain.java 3KB
basicapi
BasicAPI.java 10KB
android
AndroidLogger.java 4KB
AndroidCallgraph.java 8KB
AndroidPointsToAnalysis.java 6KB
AndroidUtil.java 2KB
InstrumentUtil.java 5KB
AndroidClassInjector.java 5KB
Main.java 2KB
visual
CallGraphFilter.java 145B
Visualizer.java 12KB
AndroidCallGraphFilter.java 2KB
hellosoot
HelloSoot.java 3KB
.gitpod.yml 69B
.travis.yml 1KB
lib
soot-infoflow-summaries-classes.jar 318KB
soot-infoflow-cmd-classes.jar 18KB
soot-infoflow-classes.jar 579KB
soot-infoflow-android-classes.jar 488KB
.gitpod.Dockerfile 135B
settings.gradle 361B
buildDemo.sh 53B
demo
compile.sh 186B
BasicAPI
Circle.java 1KB
Android
key 1KB
STDemoApp
.gitignore 208B
gradle
wrapper
gradle-wrapper.jar 53KB
gradle-wrapper.properties 232B
build.gradle 558B
gradlew.bat 2KB
gradlew 5KB
app
.gitignore 7B
build.gradle 929B
proguard-rules.pro 751B
src
test
java
dev
navids
multicomp1
ExampleUnitTest.java 382B
main
AndroidManifest.xml 1KB
java
dev
navids
multicomp1
ClassChild.java 231B
ClassParent.java 183B
MyReceiver.java 674B
SecondActivity.java 995B
MainActivity.java 2KB
res
values
styles.xml 383B
colors.xml 208B
strings.xml 73B
mipmap-xxhdpi
ic_launcher_round.png 10KB
ic_launcher.png 6KB
layout
activity_main2.xml 845B
activity_main.xml 2KB
drawable-v24
ic_launcher_foreground.xml 2KB
mipmap-anydpi-v26
ic_launcher.xml 272B
ic_launcher_round.xml 272B
mipmap-xhdpi
ic_launcher_round.png 7KB
ic_launcher.png 4KB
mipmap-hdpi
ic_launcher_round.png 5KB
ic_launcher.png 3KB
drawable
ic_launcher_background.xml 5KB
mipmap-mdpi
ic_launcher_round.png 3KB
ic_launcher.png 2KB
mipmap-xxxhdpi
ic_launcher_round.png 15KB
ic_launcher.png 9KB
androidTest
java
dev
navids
multicomp1
ExampleInstrumentedTest.java 758B
gradle.properties 1KB
settings.gradle 45B
sign.sh 475B
calc.apk 994KB
st_demo.apk 1.57MB
IntraAnalysis
UsageExample.java 378B
NullPointerExample.java 1KB
HelloSoot
FizzBuzz.java 418B
共 96 条
- 1
cestZOE
- 粉丝: 27
- 资源: 4547
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页