-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
also, fixes c.data computation to include the trailing padding.
- Loading branch information
Showing
6 changed files
with
256 additions
and
71 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,73 @@ | ||
(** C Data model. | ||
This module defines abstractions for C values. | ||
A value is backed by a datum - a sequence of bits that represents | ||
the value. This module also defines models for integer | ||
representation. | ||
*) | ||
open Core_kernel[@@warning "-D"] | ||
open Bap.Std | ||
open Format | ||
|
||
(** models for 32 bit systems *) | ||
type model32 = [ | ||
| `LP32 | ||
| `ILP32 | ||
] | ||
|
||
(** models for 64 bit systems *) | ||
type model64 = [ | ||
| `ILP64 | ||
| `LLP64 | ||
| `LP64 | ||
] | ||
|
||
|
||
(** The following table summarize all models of integer | ||
representation. | ||
{v | ||
LP32 ILP32 ILP64 LLP64 LP64 | ||
char 8 8 8 8 8 | ||
short 16 16 16 16 16 | ||
int 16 32 64 32 32 | ||
long 32 32 64 32 64 | ||
addr 32 32 64 64 64 | ||
v} | ||
*) | ||
type model = [model32 | model64] | ||
|
||
(** Abstract value lattice. The lattice is complete, and | ||
[Set []] is the supremum, i.e., the bot.*) | ||
type value = | ||
| Top | ||
(** any possible value *) | ||
| Set of word list | ||
(** one of the specified *) | ||
[@@deriving bin_io, compare, sexp] | ||
|
||
type 'd obj = | ||
| Basic of Bap_c_type.basic | ||
| Field of (string * 'd) | ||
| Undef | ||
| Union of 'd list | ||
[@@deriving bin_io, compare, sexp] | ||
|
||
(** abstraction of a С datum. | ||
type ('d,'s) datum = | ||
| Imm of 's * 'd | ||
| Seq of ('d,'s) datum list | ||
| Ptr of ('d,'s) datum | ||
[@@deriving bin_io, compare, sexp] | ||
|
||
The datum is a sequence of bits that represenst a particular C | ||
value. We abstract datum as either an immediate value of the given | ||
size and value lattice, or a sequence of data, or a pointer to a | ||
datum.*) | ||
type t = | ||
| Imm of Size.t * value | ||
(** [Imm (size,value)] *) | ||
| Seq of t list | ||
(** [Seq (t1,..,tN)] *) | ||
| Ptr of t | ||
(** [Ptr (type,size)] *) | ||
type layout = {layout : (layout obj,int) datum} | ||
[@@deriving bin_io, compare, sexp] | ||
|
||
type t = (value,Size.t) datum | ||
[@@deriving bin_io, compare, sexp] | ||
|
||
let pp_value ppf = function | ||
| Top -> fprintf ppf "Top" | ||
| Set xs -> fprintf ppf "%a" (Seq.pp Word.pp) (Seq.of_list xs) | ||
let rec pp ppf = function | ||
| Imm (sz,v) -> fprintf ppf "%a:%a" pp_value v Size.pp sz | ||
| Seq ts -> fprintf ppf "%a" (Seq.pp pp) (Seq.of_list ts) | ||
| Ptr t -> fprintf ppf "%a ptr" pp t | ||
|
||
|
||
(** *) | ||
let rec pp_layout ppf : layout -> unit = fun {layout=datum} -> | ||
pp_datum ppf datum | ||
and pp_datum ppf : (layout obj, int) datum -> unit = function | ||
| Imm (sz,v) -> | ||
fprintf ppf "@[<2>[%a : %d]@]" pp_obj v sz | ||
| Seq objs -> | ||
fprintf ppf "@[@[<hv2>{@ "; | ||
pp_print_list ~pp_sep:(fun ppf () -> | ||
fprintf ppf ",@ ") | ||
pp_datum ppf objs; | ||
fprintf ppf "@]@;}@]" | ||
| Ptr t -> | ||
fprintf ppf "*%a" pp_datum t | ||
and pp_obj ppf : layout obj -> unit = function | ||
| Basic t -> Bap_c_type.(pp ppf (basic t)) | ||
| Field (name,layout) -> | ||
fprintf ppf "@[<2><%s : %a>@]" name pp_layout layout | ||
| Undef -> | ||
fprintf ppf "<undef>" | ||
| Union xs -> | ||
fprintf ppf "@[<hv>"; | ||
pp_print_list ~pp_sep:(fun ppf () -> fprintf ppf "@;| ") | ||
pp_layout ppf xs; | ||
fprintf ppf "@]" |
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,92 @@ | ||
(** C Data model. | ||
This module defines abstractions for C values. | ||
A value is backed by a datum - a sequence of bits that represents | ||
the value. This module also defines models for integer | ||
representation. | ||
*) | ||
open Core_kernel[@@warning "-D"] | ||
open Bap.Std | ||
|
||
(** models for 32 bit systems *) | ||
type model32 = [ | ||
| `LP32 | ||
| `ILP32 | ||
] | ||
|
||
(** models for 64 bit systems *) | ||
type model64 = [ | ||
| `ILP64 | ||
| `LLP64 | ||
| `LP64 | ||
] | ||
|
||
|
||
(** The following table summarize all models of integer | ||
representation. | ||
{v | ||
LP32 ILP32 ILP64 LLP64 LP64 | ||
char 8 8 8 8 8 | ||
short 16 16 16 16 16 | ||
int 16 32 64 32 32 | ||
long 32 32 64 32 64 | ||
addr 32 32 64 64 64 | ||
v} | ||
*) | ||
type model = [model32 | model64] | ||
|
||
(** A value lattice.*) | ||
type value = | ||
| Top (** any possible value *) | ||
| Set of word list (** one of the specified, [Set []] is bot *) | ||
[@@deriving bin_io, compare, sexp] | ||
|
||
|
||
(** A C Object representation. | ||
The type is parameterized with the object layout representation to | ||
enable the recursive definition of the generalized layout type. | ||
@since 2.5.0 *) | ||
type 'd obj = | ||
| Basic of Bap_c_type.basic (** A value of a basic type *) | ||
| Field of (string * 'd) (** A struct or union field *) | ||
| Undef (** Undefined data (padding or code) *) | ||
| Union of 'd list (** Union of values *) | ||
[@@deriving bin_io, compare, sexp] | ||
|
||
(** abstraction of a С datum. | ||
The datum is a sequence of bits that represents a C object. We | ||
abstract datum as either an immediate value of the given size, | ||
or a sequence of data, or a pointer to a datum. | ||
@since 2.5.0 | ||
*) | ||
type ('d,'s) datum = | ||
| Imm of 's * 'd (** [Imm (size, value)] *) | ||
| Seq of ('d,'s) datum list (** [Seq [t1; ... ;tN]] *) | ||
| Ptr of ('d,'s) datum (** [Ptr datum] *) | ||
[@@deriving bin_io, compare, sexp] | ||
|
||
|
||
(** Describes C object's layout. *) | ||
type layout = {layout : (layout obj,int) datum} | ||
[@@deriving bin_io, compare, sexp] | ||
|
||
|
||
(** The datum that uses value lattice for object representation. *) | ||
type t = (value,Size.t) datum | ||
[@@deriving bin_io, compare, sexp] | ||
|
||
|
||
(** [pp ppf datum] prints the datum in a human-readable form. | ||
@since 2.5.0 *) | ||
val pp : Format.formatter -> t -> unit | ||
|
||
|
||
(** [pp_layout ppf layout] outputs layout in a human-readable form. | ||
@since 2.5.0 *) | ||
val pp_layout : Format.formatter -> layout -> unit |
Oops, something went wrong.