crucible-llvm-0.10: Support for translating and executing LLVM code in Crucible
Safe HaskellNone
LanguageHaskell2010

Lang.Crucible.LLVM.MemModel.Strings

Description

Manipulating C-style null-terminated strings

Synopsis

Documentation

storeString Source #

Arguments

:: forall sym bak (w :: Natural). (IsSymBackend sym bak, IsExpr (SymExpr sym), HasPtrWidth w, HasLLVMAnn sym, ?memOpts :: MemOptions) 
=> bak 
-> MemImpl sym 
-> LLVMPtr sym w

Pointer to write string to

-> Vector (SymBV sym 8)

The bytes of the string to write (null terminator not included)

-> IO (MemImpl sym) 

Store a string to memory, adding a null terminator at the end.

Loading strings

loadString Source #

Arguments

:: forall sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) 
=> bak 
-> MemImpl sym

memory to read from

-> LLVMPtr sym wptr

pointer to string value

-> Maybe Int

maximum characters to read

-> IO [Word8] 

Load a null-terminated string from the memory.

The pointer to read from must be concrete and nonnull. Moreover, we require all the characters in the string to be concrete. Otherwise it is very difficult to tell when the string has terminated. If a maximum number of characters is provided, no more than that number of charcters will be read. In either case, loadString will stop reading if it encounters a null-terminator.

loadMaybeString Source #

Arguments

:: forall sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) 
=> bak 
-> MemImpl sym

memory to read from

-> LLVMPtr sym wptr

pointer to string value

-> Maybe Int

maximum characters to read

-> IO (Maybe [Word8]) 

Like loadString, except the pointer to load may be null. If the pointer is null, we return Nothing. Otherwise we load the string as with loadString and return it.

loadConcretelyNullTerminatedString Source #

Arguments

:: forall sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) 
=> bak 
-> MemImpl sym 
-> LLVMPtr sym wptr 
-> Maybe Int

Maximum number of characters to read

-> IO [SymBV sym 8] 

Load a null-terminated string (with a concrete null terminator) from memory.

The string must contain a concrete null terminator. If a maximum number of characters is provided, no more than that number of characters will be read. In either case, loadConcretelyNullTerminatedString will stop reading if it encounters a (concretely) null terminator.

Note that the loaded string may actually be smaller than the returned list if any of the symbolic bytes are equal to 0.

loadProvablyNullTerminatedString Source #

Arguments

:: forall sym bak scope (st :: Type -> Type) fs solver (wptr :: Natural). (IsSymBackend sym bak, sym ~ ExprBuilder scope st fs, bak ~ OnlineBackend solver scope st fs, OnlineSolver solver, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) 
=> bak 
-> MemImpl sym 
-> LLVMPtr sym wptr 
-> Maybe Int

Maximum number of characters to read

-> IO [SymBV sym 8] 

Load a null-terminated string from memory.

Consults an SMT solver to check if any of the loaded bytes are known to be null (0). If a maximum number of characters is provided, no more than that number of charcters will be read. In either case, loadProvablyNullTerminatedString will stop reading if it encounters a null terminator.

Note that the loaded string may actually be smaller than the returned list if any of the symbolic bytes are equal to 0.

String length

strLen Source #

Arguments

:: forall sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions) 
=> bak 
-> MemImpl sym

memory to read from

-> LLVMPtr sym wptr

pointer to string value

-> IO (SymBV sym wptr) 

Compute the length of a null-terminated string.

The pointer to read from must be concrete and nonnull. The contents of the string may be symbolic; HOWEVER, this function will not terminate until it eventually reaches a concete null-terminator or a load error.

strnlen Source #

Arguments

:: forall sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) 
=> bak 
-> MemImpl sym 
-> LLVMPtr sym wptr

Pointer to null-terminated string

-> SymBV sym wptr

Size

If this is not concrete, this will generate an assertion failure.

-> IO (SymBV sym wptr) 

Implementation of libc strnlen.

strlenConcreteString Source #

Arguments

:: forall sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) 
=> bak 
-> MemImpl sym 
-> LLVMPtr sym wptr 
-> Maybe Int

Maximum number of characters to read

-> IO Int 

strlen of a concrete string.

If any symbolic bytes are encountered, an assertion failure will be generated. If a maximum number of characters is provided, no more than that number of characters will be read. In either case, strlenConcreteString will stop reading if it encounters a null terminator.

strlenConcretelyNullTerminatedString Source #

Arguments

:: forall sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) 
=> bak 
-> MemImpl sym 
-> LLVMPtr sym wptr 
-> Maybe Int

Maximum number of characters to read

-> IO (SymBV sym wptr) 

strlen of a null-terminated string (with a concrete null terminator).

The string must contain a concrete null terminator. If a maximum number of characters is provided, no more than that number of characters will be read. In either case, strlenConcretelyNullTerminatedString will stop reading if it encounters a (concretely) null terminator.

This has the same behavior as strLen, except that it supports a maximum length.

strlenProvablyNullTerminatedString Source #

Arguments

:: forall sym bak (wptr :: Natural) scope (st :: Type -> Type) fs solver. (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack, sym ~ ExprBuilder scope st fs, bak ~ OnlineBackend solver scope st fs, OnlineSolver solver) 
=> bak 
-> MemImpl sym 
-> LLVMPtr sym wptr 
-> Maybe Int

Maximum number of characters to read

-> IO (SymBV sym wptr) 

strlen of a provably null-terminated string.

Consults an SMT solver to check if any of the loaded bytes are known to be null (0). If a maximum number of characters is provided, no more than that number of charcters will be read. In either case, strlenProvablyNullTerminatedString will stop reading if it encounters a (provably) null terminator.

String copying

copyConcreteString Source #

Arguments

:: forall sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) 
=> bak 
-> MemImpl sym 
-> LLVMPtr sym wptr

Destination pointer

-> LLVMPtr sym wptr

Source pointer

-> IO (MemImpl sym) 

strcpy of a concrete string.

Uses loadString to load the string, see that function for details.

Asserts that the regions are disjoint.

copyConcretelyNullTerminatedString Source #

Arguments

:: forall sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) 
=> bak 
-> MemImpl sym 
-> LLVMPtr sym wptr

Destination pointer

-> LLVMPtr sym wptr

Source pointer

-> Maybe Int

Maximum number of characters to read

-> IO (MemImpl sym) 

strcpy of a concretely null-terminated string.

Uses loadConcretelyNullTerminatedString to load the string, see that function for details.

Asserts that the regions are disjoint.

copyProvablyNullTerminatedString Source #

Arguments

:: forall sym bak scope (st :: Type -> Type) fs solver (wptr :: Natural). (IsSymBackend sym bak, sym ~ ExprBuilder scope st fs, bak ~ OnlineBackend solver scope st fs, OnlineSolver solver, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) 
=> bak 
-> MemImpl sym 
-> LLVMPtr sym wptr

Destination pointer

-> LLVMPtr sym wptr

Source pointer

-> Maybe Int

Maximum number of characters to read

-> IO (MemImpl sym) 

strcpy of a concrete string.

Uses loadProvablyNullTerminatedString to load the string, see that function for details.

Asserts that the regions are disjoint.

String duplication

dupConcreteString Source #

Arguments

:: forall sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) 
=> bak 
-> MemImpl sym 
-> LLVMPtr sym wptr

Source pointer

-> String

Display string for allocation

-> Alignment

Alignment

-> IO (LLVMPtr sym wptr, MemImpl sym) 

strdup of a concrete string.

Uses loadString to load the string, see that function for details.

Allocates memory and copies the string to it, returning the new pointer.

dupConcretelyNullTerminatedString Source #

Arguments

:: forall sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) 
=> bak 
-> MemImpl sym 
-> LLVMPtr sym wptr

Source pointer

-> Maybe Int

Maximum number of characters to read

-> String

Display string for allocation

-> Alignment 
-> IO (LLVMPtr sym wptr, MemImpl sym) 

strdup of a concretely null-terminated string.

Uses loadConcretelyNullTerminatedString to load the string, see that function for details.

Allocates memory and copies the string to it, returning the new pointer.

dupProvablyNullTerminatedString Source #

Arguments

:: forall sym bak scope (st :: Type -> Type) fs solver (wptr :: Natural). (IsSymBackend sym bak, sym ~ ExprBuilder scope st fs, bak ~ OnlineBackend solver scope st fs, OnlineSolver solver, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) 
=> bak 
-> MemImpl sym 
-> LLVMPtr sym wptr

Source pointer

-> Maybe Int

Maximum number of characters to read

-> String

Display string for allocation

-> Alignment 
-> IO (LLVMPtr sym wptr, MemImpl sym) 

strdup of a provably null-terminated string.

Uses loadProvablyNullTerminatedString to load the string, see that function for details.

Allocates memory and copies the string to it, returning the new pointer.

Memory comparison

memcmp :: forall sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) => bak -> MemImpl sym -> LLVMPtr sym wptr -> LLVMPtr sym wptr -> SymBV sym wptr -> IO (SymBV sym 32) Source #

memcmp.

See memcmpConcreteLen for the return value.

Asserts that the length is concrete (non-symbolic).

memcmpConcreteLen :: forall sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) => bak -> MemImpl sym -> LLVMPtr sym wptr -> LLVMPtr sym wptr -> Integer -> IO (SymBV sym 32) Source #

Compare two memory regions byte-by-byte with a concrete length.

Returns: * 0 if the regions are equal * A negative value if the first differing byte in s1 is less than in s2 * A positive value if the first differing byte in s1 is greater than in s2

String comparison

strncmp :: forall sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) => bak -> MemImpl sym -> LLVMPtr sym wptr -> LLVMPtr sym wptr -> SymBV sym wptr -> IO (SymBV sym 32) Source #

strncmp - compare two null-terminated strings up to n characters.

See strncmpConcreteLen for the return value.

Asserts that the length is concrete (non-symbolic).

strncmpConcreteLen :: forall sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) => bak -> MemImpl sym -> LLVMPtr sym wptr -> LLVMPtr sym wptr -> Integer -> IO (SymBV sym 32) Source #

Compare two null-terminated strings up to n characters with a concrete length.

Returns: * 0 if the strings are equal (up to n characters or null terminator) * A negative value if the first differing byte in s1 is less than in s2 * A positive value if the first differing byte in s1 is greater than in s2

Requires that both strings have concrete null terminators.

cmpConcreteString :: forall sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) => bak -> MemImpl sym -> LLVMPtr sym wptr -> LLVMPtr sym wptr -> IO (SymBV sym 32) Source #

Compare two concrete strings.

Uses fullyConcreteNullTerminatedStrings checker. Both strings must be fully concrete (no symbolic bytes).

Returns: * 0 if the strings are equal * A negative value if the first differing byte in s1 is less than in s2 * A positive value if the first differing byte in s1 is greater than in s2

cmpConcretelyNullTerminatedString Source #

Arguments

:: forall sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack) 
=> bak 
-> MemImpl sym 
-> LLVMPtr sym wptr 
-> LLVMPtr sym wptr 
-> Maybe Int

Maximum number of characters to compare

-> IO (SymBV sym 32) 

Compare two strings with concrete null terminators.

Uses concretelyNullTerminatedStrings checker. The strings must have concrete null terminators, but may contain symbolic bytes before the terminator.

If a maximum length is provided, comparison stops at that length even if no null terminator is encountered.

Returns: * 0 if the strings are equal * A negative value if the first differing byte in s1 is less than in s2 * A positive value if the first differing byte in s1 is greater than in s2

cmpProvablyNullTerminatedString Source #

Arguments

:: forall sym bak (wptr :: Natural) scope (st :: Type -> Type) fs solver. (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack, sym ~ ExprBuilder scope st fs, bak ~ OnlineBackend solver scope st fs, OnlineSolver solver) 
=> bak 
-> MemImpl sym 
-> LLVMPtr sym wptr 
-> LLVMPtr sym wptr 
-> Maybe Int

Maximum number of characters to compare

-> IO (SymBV sym 32) 

Compare two strings with provably null terminators.

Uses provablyNullTerminatedStrings checker. Consults an SMT solver to check if bytes are provably null terminators.

If a maximum length is provided, comparison stops at that length even if no null terminator is encountered.

Returns: * 0 if the strings are equal * A negative value if the first differing byte in s1 is less than in s2 * A positive value if the first differing byte in s1 is greater than in s2

Low-level string loading primitives

ByteChecker

data ControlFlow a b Source #

Whether to stop or keep going

Like Rust's std::ops::ControlFlow.

Constructors

Continue a 
Break b 

Instances

Instances details
Bifunctor ControlFlow Source # 
Instance details

Defined in Lang.Crucible.LLVM.MemModel.Strings

Methods

bimap :: (a -> b) -> (c -> d) -> ControlFlow a c -> ControlFlow b d #

first :: (a -> b) -> ControlFlow a c -> ControlFlow b c #

second :: (b -> c) -> ControlFlow a b -> ControlFlow a c #

Functor (ControlFlow a) Source # 
Instance details

Defined in Lang.Crucible.LLVM.MemModel.Strings

Methods

fmap :: (a0 -> b) -> ControlFlow a a0 -> ControlFlow a b #

(<$) :: a0 -> ControlFlow a b -> ControlFlow a a0 #

newtype ByteChecker (m :: Type -> Type) sym bak a b Source #

Compute a result from a symbolic byte, and check if the load should continue to the next byte.

Used to:

Note that it is relatively common for a to be a function [b] -> [b]. This is used to build up a snoc-list.

Constructors

ByteChecker 

Fields

withMaxChars Source #

Arguments

:: (MonadIO m, HasCallStack, IsSymBackend sym bak, Functor m) 
=> Int

Maximum number of bytes to load

-> (a -> m b)

What to do when the maximum is reached

-> ByteChecker m sym bak a b 
-> ByteChecker m sym bak (a, Int) b 

ByteChecker for adding a maximum character length.

For loading strings

fullyConcreteNullTerminatedString :: forall (m :: Type -> Type) sym bak. (MonadIO m, HasCallStack, IsSymBackend sym bak) => ByteChecker m sym bak ([Word8] -> [Word8]) [Word8] Source #

ByteChecker for loading concrete strings.

Currently unused internally, but analogous with loadString. In fact, it would be good to define that function in terms of this one. However, this is blocked on TODO(#1406).

concretelyNullTerminatedString :: forall (m :: Type -> Type) sym bak. (MonadIO m, HasCallStack, IsSymBackend sym bak) => ByteChecker m sym bak ([SymBV sym 8] -> [SymBV sym 8]) [SymBV sym 8] Source #

ByteChecker for loading symbolic strings with a concrete null terminator.

Used in loadConcretelyNullTerminatedString.

provablyNullTerminatedString :: forall (m :: Type -> Type) sym bak scope (st :: Type -> Type) fs solver. (MonadIO m, HasCallStack, IsSymBackend sym bak, sym ~ ExprBuilder scope st fs, bak ~ OnlineBackend solver scope st fs, OnlineSolver solver) => ByteChecker m sym bak ([SymBV sym 8] -> [SymBV sym 8]) [SymBV sym 8] Source #

ByteChecker for loading symbolic strings with a provably-null terminator.

Used in loadSymbolicString.

For string length

fullyConcreteNullTerminatedStringLength :: forall (m :: Type -> Type) sym bak. (MonadIO m, HasCallStack, IsSymBackend sym bak) => ByteChecker m sym bak Int Int Source #

ByteChecker for strlen of concrete strings.

concretelyNullTerminatedStringLength :: forall (m :: Type -> Type) sym (wptr :: Natural) bak. (MonadIO m, MonadState (Pred sym) m, HasCallStack, HasPtrWidth wptr, IsSymBackend sym bak) => ByteChecker m sym bak (SymBV sym wptr) (SymBV sym wptr) Source #

ByteChecker for strlen of strings with a concrete null terminator.

provablyNullTerminatedStringLength :: forall (m :: Type -> Type) sym bak (wptr :: Natural) scope (st :: Type -> Type) fs solver. (MonadIO m, MonadState (Pred sym) m, HasCallStack, IsSymBackend sym bak, HasPtrWidth wptr, sym ~ ExprBuilder scope st fs, bak ~ OnlineBackend solver scope st fs, OnlineSolver solver) => ByteChecker m sym bak (SymBV sym wptr) (SymBV sym wptr) Source #

ByteChecker for strlen for strings with a provably-null terminator.

ByteLoader

newtype ByteLoader (m :: Type -> Type) sym bak (wptr :: Nat) Source #

Load a byte from memory.

The only ByteLoader defined here is llvmByteLoader, but Macaw users will most often want one based on doReadMemModel.

Constructors

ByteLoader 

Fields

llvmByteLoader :: forall sym bak (wptr :: Natural) (m :: Type -> Type). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack, MonadIO m) => MemImpl sym -> ByteLoader m sym bak wptr Source #

A ByteLoader for LLVM memory based on doLoad.

loadBytes

loadBytes Source #

Arguments

:: forall m a b sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack, MonadIO m) 
=> bak 
-> MemImpl sym 
-> a

Initial accumulator

-> LLVMPtr sym wptr

Pointer to load from

-> ByteLoader m sym bak wptr

How to load a byte from memory

-> ByteChecker m sym bak a b

How to check if we should continue loading the next byte

-> m b 

Load a sequence of bytes, one at a time.

Used to implement loadConcretelyNullTerminatedString and loadSymbolicString. Highly customizable via ByteLoader and ByteChecker.

Loading and checking two byte streams

BytesLoader

data BytesLoader (m :: Type -> Type) sym bak (wptr :: Nat) Source #

Load a byte from each of two memory locations.

The loader can optionally add assumptions after loading bytes when iteration continues. This is used for null-terminated string operations where we need to assume loaded bytes are non-null.

Like ByteLoader, but for two bytes (usually from different strings) at once.

Constructors

BytesLoader 

Fields

llvmBytesLoader :: forall sym bak (wptr :: Natural) (m :: Type -> Type). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack, MonadIO m) => MemImpl sym -> BytesLoader m sym bak wptr Source #

A BytesLoader for LLVM memory based on doLoad.

This version does not add any assumptions about loaded bytes. Use this for length-bounded operations like memcmp that need to handle null bytes in the middle of the data.

llvmStringsLoader :: forall sym bak (wptr :: Natural) (m :: Type -> Type). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack, MonadIO m) => MemImpl sym -> BytesLoader m sym bak wptr Source #

A BytesLoader for LLVM memory that adds non-null assumptions.

This version adds assumptions that loaded bytes are non-null when iteration continues. Use this for null-terminated string operations like strcmp.

BytesChecker

newtype BytesChecker (m :: Type -> Type) sym bak a b Source #

Compute a result from two symbolic bytes, and check if loading should continue to the next pair of bytes.

Used to compare two byte streams simultaneously, e.g., for strcmp.

Like ByteChecker, but for two bytes (usually from different strings) at once.

Constructors

BytesChecker 

Fields

withMaxBytes Source #

Arguments

:: (MonadIO m, HasCallStack, IsSymBackend sym bak, Functor m) 
=> Integer

Maximum number of bytes to compare

-> (bak -> a -> m b)

What to do when the maximum is reached

-> BytesChecker m sym bak a b 
-> BytesChecker m sym bak (a, Integer) b 

BytesChecker for adding a maximum byte length.

loadTwoBytes

loadTwoBytes Source #

Arguments

:: forall m a b sym bak (wptr :: Natural). (IsSymBackend sym bak, HasPtrWidth wptr, HasLLVMAnn sym, ?memOpts :: MemOptions, HasCallStack, MonadIO m) 
=> bak 
-> MemImpl sym 
-> a

Initial accumulator

-> LLVMPtr sym wptr

First pointer to load from

-> LLVMPtr sym wptr

Second pointer to load from

-> BytesLoader m sym bak wptr

How to load a byte from each memory location

-> BytesChecker m sym bak a b

How to check if we should continue loading the next bytes

-> m b 

Load sequences of bytes from two pointers simultaneously.

Used to implement strcmp. Similar to loadBytes but operates on two byte streams.

BytesCheckers for string comparison

fullyConcreteNullTerminatedStrings :: forall (m :: Type -> Type) sym bak. (MonadIO m, HasCallStack, IsSymBackend sym bak) => BytesChecker m sym bak (SymBV sym 32) (SymBV sym 32) Source #

BytesChecker for comparing concrete strings.

Stops when either string has a concrete null terminator.

concretelyNullTerminatedStrings :: forall (m :: Type -> Type) sym bak. (MonadIO m, HasCallStack, IsSymBackend sym bak) => BytesChecker m sym bak (SymBV sym 32) (SymBV sym 32) Source #

BytesChecker for comparing strings with concrete null terminators.

Stops when either string has a concrete null terminator.

provablyNullTerminatedStrings :: forall (m :: Type -> Type) sym bak scope (st :: Type -> Type) fs solver. (MonadIO m, HasCallStack, IsSymBackend sym bak, sym ~ ExprBuilder scope st fs, bak ~ OnlineBackend solver scope st fs, OnlineSolver solver) => BytesChecker m sym bak (SymBV sym 32) (SymBV sym 32) Source #

BytesChecker for comparing strings with provably null terminators.

Stops when either string is provably null-terminated.

lengthBoundedStringComparison :: forall (m :: Type -> Type) sym bak. (MonadIO m, HasCallStack, IsSymBackend sym bak) => Integer -> BytesChecker m sym bak (SymBV sym 32, Integer) (SymBV sym 32) Source #

BytesChecker for comparing strings with concrete null terminators up to a maximum length.

Combines null-terminator checking (like strcmp) with length bounding (like memcmp). Used for strncmp.

The accumulator is a pair of the comparison result so far and the current index.

lengthBoundedProvablyNullTerminatedStringComparison :: forall (m :: Type -> Type) sym bak scope (st :: Type -> Type) fs solver. (MonadIO m, HasCallStack, IsSymBackend sym bak, sym ~ ExprBuilder scope st fs, bak ~ OnlineBackend solver scope st fs, OnlineSolver solver) => Integer -> BytesChecker m sym bak (SymBV sym 32, Integer) (SymBV sym 32) Source #

BytesChecker for comparing strings with provably null terminators up to a maximum length.

Combines provably null-terminator checking with length bounding.

The accumulator is a pair of the comparison result so far and the current index.

BytesCheckers for length-bounded comparison

simpleByteComparison :: forall (m :: Type -> Type) sym bak. (MonadIO m, HasCallStack, IsSymBackend sym bak) => BytesChecker m sym bak () (SymBV sym 32) Source #

BytesChecker for comparing two bytes without length bounds.

Stops when bytes differ, otherwise continues indefinitely.

lengthBoundedByteComparison Source #

Arguments

:: forall (m :: Type -> Type) sym bak. (MonadIO m, HasCallStack, IsSymBackend sym bak) 
=> Integer

Maximum length

-> BytesChecker m sym bak ((), Integer) (SymBV sym 32) 

BytesChecker for comparing memory regions with a concrete length bound.

The accumulator is a pair of unit and the current index. Stops when the index reaches the maximum length, or when bytes differ.

Returns: * 0 if all bytes up to the length are equal * A negative value if the first differing byte in the first region is less * A positive value if the first differing byte in the first region is greater