16. SB Objects – どのスコープに存在するか?
public void foo(){
SB x, y, z;
[x = new SB(“s3cr3t”);]1
[y = new SB(“p@55w0rd”);]2
[if(y.length() < x.length()){
[z = y;]4
} else{
[z = y.append(“007”);]5
}]3
class MyClass{
static SB x;
public static void foo(){
SB y, z;
[x = new SB(“s3cr3t”);]1
[y = new SB(“p@55w0rd”);]2
[if(y.length() < x.length()) {
[z = y;]4
} else{
bar();5
}]3
}}
public static void bar(){
System.out.println(MyClass.x);
}
ローカル変数 静的フィールド
Abbrev.
SB: StringBuilder
17. インスタンスフィールド
class MyClass
{
private SB x;
public SB getSBx(){
return x;
}
public SB setSBx(SB str){
x=str;
}
}
public static void foo(){
MyClass obj = new MyClass();
SB str= new SB();
obj.setSBx(str)
S.O.P(obj.getSBx());
}
18. public class MainActivity
{
protected void onCreate(Bundle b) {
User.static_secret= new SB("p@55w0rd");
CheckStatic cs= new CheckStatic();
cs.useStaticField();
}
}
デモ – 静的な SB
public class User {
public static SB static_secret;
}
public class CheckStatic {
public void useStaticField()
{
S.O.P(User.static_secret);
bar();
}
public void bar()
{
S.O.P(User.static_secret);
}
}
しかしライフサイクルはそんなに単純じゃない
- ループが発生することもある
デモ
30. インスタンスフィールド
class MyClass
{
private SB a;
public SB setA(SB str){
a=str;
}
public void resetSb_A(){
……..
}
}
public class MainActivity{
public static void onCreate(){
SB my_secret= new SB(“S3cr3t”);
MyClass mc = new MyClass();
Wrapper w = new Wrapper();
w.callW(mc, my_secret);
resetSb_A();
}
}
DEMO
public class Wrapper {
public void callW( MyClass mc, SB my_secret ){
mc.setA(my_secret);
}
}
Last use of “mc”
Instrumented Code
1. StringBuilderインスタンスフィールドのすべてのクラス をマーク
2. それらのオブジェクトインスタンスを探索
3. オブジェクトインスタンスの最終利用を追跡
4. MyClassにresetメソッドを追加
32. 参考文献
1. Implementing an intra procedural data flow analysis in Soot,
https://github.com/Sable/soot/wiki/Implementing-an-intra-procedural-data-flow-analysis-in-Soot
2. Instrumenting Android Apps with Soot, http://www.bodden.de/2013/01/08/soot-android-
instrumentation
3. Dexpler: Converting Android Dalvik Bytecode to Jimple for Static Analysis with Soot,
https://arxiv.org/pdf/1205.3576.pdf
4. Precise Interprocedural Dataflow Analysis via Graph Reachability,
https://courses.cs.washington.edu/courses/cse590md/01sp/w1l2.pdf
5. Slides by Matthew B. Dwyer and Robby, University of Nebraska-Lincoln, Kansas State University