Lab Exercise 3 Python - SVF-tools/Software-Security-Analysis GitHub Wiki
launch.json
1.1 You can open Lab3.ipynb
as shown in the image below. For more details, see Configuration & Debugging.
2. Lab Exercise 3 task
- Implement methods from
test1()
totest8()
inAEMgr.ipynb
- Before running the test methods, execute the code cell above them to define the
AEState
andAbstractExecutionMgr
classes - Upload
Lab3.ipynb
to UNSWWebCMS
for your submission when you are finished with this lab. Your implementation will be evaluated against our internal tests. You will get the full marks if your code can pass them all. We have providedtest0()
as an example to help get started.
test code cell
only and there is NO need to modify other files under the Lab-Exercise-3 folder
*You will be working on SVF-Python AEMgr APIs to help with your implementation SVF-Python AEMgr API.
3. Debugging
If you want to see the value of AbstractValue
. You can also call toString()
to print the value (either Interval Value or Address Value).
a = IntervalValue(1,1)
print(a.toString())
4. Widening and Narrowing implementation for the below loop example in lecture slides
int a = 0;
while (a < 10){
a++;
}
def test():
mgr = AbstractExecutionMgr()
a = mgr.get_node_id("a")
entry_as = AEState()
cur_head_as = AEState()
body_as = AEState()
exit_as = AEState()
widen_delay = 3
increasing = True
# Compose 'entry_as' (a = 0)
entry_as[a] = IntervalValue(0, 0)
for cur_iter in range(100): # Upper bound to ensure fixpoint
if cur_iter >= widen_delay:
prev_head_as = cur_head_as.clone()
# Join entry_as and body_as into cur_head_as
cur_head_as = entry_as.clone()
cur_head_as.join_with(body_as)
if increasing:
ae_after_widening = prev_head_as.widening(cur_head_as)
cur_head_as = ae_after_widening.clone()
if cur_head_as.equals(prev_head_as):
increasing = False
continue
else:
ae_after_narrowing = prev_head_as.narrowing(cur_head_as)
cur_head_as = ae_after_narrowing.clone()
if cur_head_as.equals(prev_head_as):
break
else:
cur_head_as = entry_as.clone()
cur_head_as.join_with(body_as)
# Loop body: condition a < 10 and then a++
body_as = cur_head_as.clone()
body_as[a].meet_with(IntervalValue(BoundedInt.minus_infinity(), 9))
body_as[a] = body_as[a].getInterval() + IntervalValue(1, 1)
# Handle loop exit: a >= 10
exit_as = cur_head_as.clone()
exit_as[a].meet_with(IntervalValue(10, BoundedInt.plus_infinity()))
exit_as.print_abstract_state()
return exit_as