-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pzucker/precondition #101
Merged
Merged
Pzucker/precondition #101
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
(library | ||
(name bap_wp) | ||
(public_name bap_wp) | ||
(libraries bap bap-x86-cpu z3 oUnit)) | ||
(name bap_wp) | ||
(public_name bap_wp) | ||
(libraries bap bap-x86-cpu z3 oUnit)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
(***************************************************************************) | ||
(* *) | ||
(* Copyright (C) 2018/2019 The Charles Stark Draper Laboratory, Inc. *) | ||
(* *) | ||
(* This file is provided under the license found in the LICENSE file in *) | ||
(* the top-level directory of this project. *) | ||
(* *) | ||
(* This work is funded in part by ONR/NAWC Contract N6833518C0107. Its *) | ||
(* content does not necessarily reflect the position or policy of the US *) | ||
(* Government and no official endorsement should be inferred. *) | ||
(* *) | ||
(***************************************************************************) | ||
|
||
open !Core_kernel | ||
open Bap.Std | ||
|
||
include Self() | ||
|
||
module Expr = Z3.Expr | ||
module Arith = Z3.Arithmetic | ||
module BV = Z3.BitVector | ||
module Bool = Z3.Boolean | ||
module Z3Array = Z3.Z3Array | ||
module FuncDecl = Z3.FuncDecl | ||
module Symbol = Z3.Symbol | ||
module Solver = Z3.Solver | ||
module Env = Environment | ||
module Constr = Constraint | ||
|
||
let get_decls_and_symbols (env : Env.t) : ((FuncDecl.func_decl * Symbol.symbol) list) = | ||
let var_map = Env.get_var_map env in | ||
let ctx = Env.get_context env in | ||
Env.EnvMap.fold var_map ~init:[] | ||
~f:(fun ~key:_ ~data:z3_var decls -> | ||
assert (Expr.is_const z3_var); | ||
let decl = FuncDecl.mk_const_decl_s ctx | ||
(Expr.to_string z3_var) | ||
(Expr.get_sort z3_var) in | ||
let sym = Symbol.mk_string ctx (Expr.to_string z3_var) in | ||
(decl,sym)::decls | ||
) | ||
|
||
let mk_smtlib2 (ctx : Z3.context) (smtlib_str : string) (decl_syms : (Z3.FuncDecl.func_decl * Z3.Symbol.symbol) list) : Constr.t = | ||
let fun_decls, fun_symbols = List.unzip decl_syms in | ||
let sort_symbols = [] in | ||
let sorts = [] in | ||
let asts = Z3.SMT.parse_smtlib2_string ctx smtlib_str | ||
sort_symbols | ||
sorts | ||
fun_symbols | ||
fun_decls | ||
in | ||
let goals = List.map (Z3.AST.ASTVector.to_expr_list asts) | ||
~f:(fun e -> | ||
e | ||
|> Constr.mk_goal (Expr.to_string e) | ||
|> Constr.mk_constr) | ||
in | ||
Constr.mk_clause [] goals | ||
|
||
let mk_smtlib2_single (env : Env.t) (smt_post : string) : Constr.t = | ||
let var_map = Env.get_var_map env in | ||
let smt_post = Env.EnvMap.fold var_map ~init:smt_post | ||
~f:(fun ~key:var ~data:z3_var smt_post -> | ||
String.substr_replace_all smt_post ~pattern:((Var.name var) ^ " ") ~with_:((Expr.to_string z3_var) ^ " ") | ||
) in | ||
info "New smt-lib string : %s\n" smt_post; | ||
let decl_syms = get_decls_and_symbols env in | ||
let ctx = Env.get_context env in | ||
mk_smtlib2 ctx smt_post decl_syms | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
(***************************************************************************) | ||
(* *) | ||
(* Copyright (C) 2018/2019 The Charles Stark Draper Laboratory, Inc. *) | ||
(* *) | ||
(* This file is provided under the license found in the LICENSE file in *) | ||
(* the top-level directory of this project. *) | ||
(* *) | ||
(* This work is funded in part by ONR/NAWC Contract N6833518C0107. Its *) | ||
(* content does not necessarily reflect the position or policy of the US *) | ||
(* Government and no official endorsement should be inferred. *) | ||
(* *) | ||
(***************************************************************************) | ||
|
||
(** | ||
|
||
This module exports types and utilities to process and report results found | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we update this comment to match the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Good catch. |
||
using the WP plugin. | ||
|
||
The report contains information about the result of the WP analysis, and in | ||
the case the result is [SAT], prints out the model that contains the input | ||
register and memory values that result in the program refuting a goal, the path | ||
taken to the refuted goal, and the register values at each jump in the path. | ||
|
||
*) | ||
|
||
module Env = Environment | ||
module Constr = Constraint | ||
|
||
|
||
(** [get_decls_and_symbols] builds from a the var_map in an environment | ||
a mapping of all Z3 func_decl to their symbol. This is a helper function for | ||
[mk_smtlib2] *) | ||
val get_decls_and_symbols : Env.t -> ((Z3.FuncDecl.func_decl * Z3.Symbol.symbol) list) | ||
|
||
(** [mk_smtlib2_single env smtlib_str] takes in a string representing a | ||
valid SMT-Lib-2 statement. | ||
The variables in the SMT-Lib statements need to appear in the | ||
environment. The intended purpose of this function is generating hypothesis | ||
and postconditions for single binary analysis *) | ||
val mk_smtlib2_single : Env.t -> string -> Constr.t | ||
|
||
(** [mk_smtlib2] parses a smtlib2 string in the context that has a mapping of func_decl | ||
to symbols and returns a constraint [Constr.t] corresponding to the smtlib2 string. | ||
The [func_decl * symbol] mapping can be constructed from an [Env.t] using the | ||
[get_decls_and_symbols] function. *) | ||
|
||
val mk_smtlib2 : Z3.context -> string -> ((Z3.FuncDecl.func_decl * Z3.Symbol.symbol) list) -> Constr.t |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a variable in the let-binding shares a name with a variable that already existed in the
env
, would removing it also remove the original variable? If so, it might be good to write a comment about that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, this could conceivable occur if some pervert wanted to name a let-bound variable
RAX
, or more pragmatically if an inner let shadows an outer let. This should cause a run-time error rather than a mysterious change in semantics. A comment might be appropriate though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. That's an interesting point. We didn't implement this correctly basically. We should store the variable we're covering up. In practice it probably isn't a problem because the let bindings seem to use names like "$1", but should probably still be fixed for sanity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really good catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I fixed this