package bap-std
Memory region
type t = mem
val sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t
val create :
?pos:int ->
?len:int ->
endian ->
addr ->
Core_kernel.Bigstring.t ->
t Core_kernel.Or_error.t
create ?pos ?len endian start data
creates a memory region.
Creates a memory view of the provided data
using the specified byte order endian
and mapping the first (pos
) byte to the start
address. The pos
and len
parameters can be used to narrow down the view, and default to 0
and the length of the provided string, correspondingly.
The data
may not be copied and the returned memory view may reference the same bigstring object.
rebase mem addr
returns the same memory but with the new starting address addr
.
val slot :
(Bap_core_theory.Theory.program, mem option) Bap_knowledge.Knowledge.slot
memory representation of a program
of_file endian start name
creates a memory region from file. Takes data stored in a file with the given name
and maps it to the memory region with the specified starting address start
and using the endian
for storing and reading words.
view word_size ~from ~words mem
returns a new memory that represents the specified region of memory mem
. copy
function performs deep copy.
view_exn mem
is the same as ok_exn @@view_exn mem
but is slightly more efficient.
range mem a0 a1
returns a view on mem
starting from address a0
and ending at a1
, bounds inclusive
merge m1 m2
takes two memory regions, that either intersects or share edges (i.e., difference between min_addr
of one of the blocks and max_addr
of another is less then or equal to one, and returns memory blocks that spans memory starting from the address
min (min_addr m1) (min_addr m2)
and ending with address
max (max_addr m1) (max_addr m2)
.
Will return an error, if either the above state precondition doesn't hold, or if this two memory blocks doesn't share the same underlying memory (i.e., bases), or if they have different endianness.
get ?disp ?index ?scale ?addr mem
reads a scale
sized word from mem
.
Parameters mimic the reference syntax in the gas assembler, e.g., dis(base,index,scale)
denotes address at base + index * scale + dis
.
The size of the returned word is equal to scale
, bytes are read in the endian mem
order.
val length : t -> int
length m
returns a number of bytes in m
compare_with mem addr
compares memory with addr
module Input : sig ... end
A set of low level input operations. Note: it is more effective to use above head iterators, instead of this low level interface, since iterators do not need to check every memory access.
Printing and outputting
val hexdump : t -> string
hexdump t out
outputs hexdump (as per hexdump -C
) of the memory to formatter out
a set of iterators, with identity monad.
include Memory_iterators with type t := t and type 'a m = 'a
fold ~word_size ~init ~f t
folds over elements of t
, so a result is f (... (f (f a elt_1) elt_2) ...) elt_n
iter ~word_size ~f t
applies f
to elements of t
foldi ~word_size ~init ~f t
is like fold
, but also passes an address to the f
iteri ~word_size ~f t
is like iter
, but also passes an address to the f
exists ~word_size ~f t
checks if at least one element of t
satisfies the predicate f
for_all ~word_size ~f t
checks if all elements of t
satisfies the predicate f
count ~word_size ~f t
is the number of elements in t
that satisfies the predicate f
.
find_if ~word_size ~f t
returns the first element of t
that satisfies the predicate p
or None if no elements satisfied
module With_error :
Memory_iterators with type t := t and type 'a m = 'a Core_kernel.Or_error.t
iterators lifter to the Or_error monad
module Make_iterators
(M : sig ... end) :
Memory_iterators with type t := t and type 'a m = 'a M.t
lifts iterators to monad M
Interfacing with C
The following interfaces is supposed to be used only for the purposes of exposing memory to c programs.
val to_buffer : t -> Core_kernel.Bigsubstring.t
to_buffers mem
creates a buffer representing the memory mem
. It is not specified whether the returned buffer has some sharing with underlying implementation. In other words the returned buffer shouldn't be modified.
Since it is not guaranteed that memory is contiguous, a sequence of buffers is returned, with each buffer representing a contiguous part of memory.
module Trie : sig ... end
Tries over memory