|
| 1 | +import claripy |
| 2 | +import cozy.analysis as analysis |
| 3 | +import cozy.claripy_ext as claripy_ext |
| 4 | +from cozy.directive import Assume |
| 5 | +from cozy.project import Project |
| 6 | +from cozy.constants import * |
| 7 | +import cozy.primitives as primitives |
| 8 | +import cozy.execution_graph as execution_graph |
| 9 | + |
| 10 | +arg0 = [5, 4, 3] |
| 11 | +arg1 = claripy.BVS('idx_arg', INT_SIZE * 8) |
| 12 | + |
| 13 | +def construct_args(sess): |
| 14 | + # Constrain the first argument to satisfy -10 <= arg1 <= 10 |
| 15 | + sess.add_constraints(arg1.SGE(-10)) |
| 16 | + sess.add_constraints(arg1.SLE(10)) |
| 17 | + return [arg0, arg1] |
| 18 | + |
| 19 | +proj_pre = Project('test_programs/buff_overflow/buff_overflow') |
| 20 | +# The patched function is the same as the original, except it has an if statement |
| 21 | +# to check if the input argument is NULL |
| 22 | +proj_post = Project('test_programs/buff_overflow/buff_overflow_patched') |
| 23 | + |
| 24 | +proj_pre.add_prototype('patch_fun', 'int patch_fun(int a[], int i)') |
| 25 | +proj_post.add_prototype('patch_fun', 'int patch_fun(int a[], int i)') |
| 26 | + |
| 27 | +sess_pre = proj_pre.session('patch_fun') |
| 28 | +sess_post = proj_post.session('patch_fun') |
| 29 | + |
| 30 | +rslt_pre = sess_pre.run(construct_args(sess_pre)) |
| 31 | +rslt_post = sess_post.run(construct_args(sess_post)) |
| 32 | + |
| 33 | +def concrete_post_processor(args): |
| 34 | + return (args[0], primitives.from_twos_comp(args[1].concrete_value, 32)) |
| 35 | + |
| 36 | +args = (arg0, arg1) |
| 37 | + |
| 38 | +comparison = analysis.Comparison(rslt_pre, rslt_post) |
| 39 | + |
| 40 | +execution_graph.dump_comparison(proj_pre, proj_post, rslt_pre, rslt_post, comparison, output_file="cmp_buff_overflow.json", args=args, num_examples=2, include_actions=True) |
0 commit comments