软件分析课作业,使用SOOT完成指针分析,不能直接调用SOOT的指针分析模块。
看了大哥们的分享,我这个就是个垃圾,有空再改。
- 源代码阅读
- 添加案例
- 测试
- 优化
- 测试 sample/hello
- 考虑
JInstanceFieldRef
指令,即,这个问题比我想象的难很多。class.g
无法用直接转换为Local 类
待定,还没想好要不要加Steensgaard,以及完善Simple Anderson算法(我那个简直稀烂)。
指针分析算法设计: 本质上是,是实现Anderson指向分析算法
有问题。。。,FieldRef 和 Field 无法转换成Value。
Field,在soot中,可以理解为Java Class的变量,如 <objects.A: objects.B f>
FieldRef,是Field的在域(Field)上的一个具体指针。
我的理解是 Local.Field == FieldRef
,但Soot的Local好像没有Field迭代的接口
Anderson 换成 value, value
[*] Exception (leftValue Instanceof FieldRef):r0.<objects.A: int i> = 5
java.lang.ClassCastException: soot.AbstractSootFieldRef cannot be cast to soot.Value
没有优雅的办法,只能采用比较暴力的方案了。。。
定义四种关系,关系如下:
- Local -> Local
- Local -> FieldRef
- FieldRef -> Local
- FieldRef -> FieldRef
对于样本2,目前有两个困难:
- 如何梳理对多种关系(四种)进行约束求解
- 如何找到FieldRef和FieldRed对应的Local变量之前对关系,有助于提高精度。
针对问题2,已经找到解决方案:
if (rightValue instanceof FieldRef) {
System.out.println("[*] Right Value FieldRef: " + rightValue);
System.out.println("[*] GetField: " + ((FieldRef) rightValue).getField());
for (ValueBox valueBox : rightValue.getUseBoxes()) {
System.out.println(valueBox.getValue().toString());
}
}
我好像把from和to的关系又弄混了。
以 a = b 为例子,b为fromValue,a为toValue。
[+] (FieldRef, Local):r0.<objects.A: objects.B f> = $r1
Local HashCode: 546392117;FieldRef HashCode: 1452134218;FieldRef Field HashCode: 1267338499
Local HashCode: 1633439396
[+] start with "new" (Local, Local):$r2 = new objects.B
Local HashCode: 1098139353
Local HashCode: 1098139353
[+] (FieldRef, Local):r0.<objects.A: objects.B g> = $r2
Local HashCode: 546392117;FieldRef HashCode: 1206043908;FieldRef Field HashCode: 1425241044
Local HashCode: 1098139353
[+] (FieldRef, Local):r0.<objects.A: objects.B f> = r3
Local HashCode: 546392117;FieldRef HashCode: 1926620223;FieldRef Field HashCode: 1267338499
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConstraintValue that = (ConstraintValue) o;
return Objects.equals(localValue, that.localValue) && Objects.equals(fieldValue, that.fieldValue);
}
@Override
public int hashCode() {
if (fieldValue == null) {
return localValue.hashCode();
} else {
return fieldValue.hashCode();
}
}