@@ -187,8 +187,8 @@ writeMemory' bs1 (C _ n) (C _ src) (C _ dst) bs0 =
187
187
readMemoryWord' :: Word -> [SWord 8 ] -> SymWord
188
188
readMemoryWord' (C _ i) m = sw256 $ fromBytes $ truncpad 32 (drop (num i) m)
189
189
190
- readMemoryWord32' :: Word -> [SWord 8 ] -> SWord 32
191
- readMemoryWord32' (C _ i) m = fromBytes $ truncpad 4 (drop (num i) m)
190
+ readMemoryWord32' :: Word -> [SWord 8 ] -> SymWord
191
+ readMemoryWord32' (C _ i) m = sw256 $ fromBytes $ truncpad 4 (drop (num i) m)
192
192
193
193
setMemoryWord' :: Word -> SymWord -> [SWord 8 ] -> [SWord 8 ]
194
194
setMemoryWord' (C _ i) (S _ x) =
@@ -208,8 +208,8 @@ readSWord' (C _ i) x =
208
208
else swordAt (num i) x
209
209
210
210
-- | Operations over dynamic symbolic memory (smt list of bytes)
211
- readByteOrZero'' :: SWord 32 -> SList (WordN 8 ) -> SWord 8
212
- readByteOrZero'' i bs =
211
+ readByteOrZero'' :: SymWord -> SList (WordN 8 ) -> SWord 8
212
+ readByteOrZero'' ( S _ i) bs =
213
213
ite (sFromIntegral (SL. length bs) .> i + 1 )
214
214
(bs .!! (sFromIntegral i))
215
215
(literal 0 )
@@ -265,24 +265,24 @@ read32At :: SInteger -> SList (WordN 8) -> SymWord
265
265
read32At i x = sw256 $ fromBytes $ [x .!! literal i | i <- [0 .. 31 ]]
266
266
267
267
-- | Although calldata can be modeled perfectly well directly as a Buffer,
268
- -- we allow for it to take on a special form; the pair ([SWord 8], SWord 32 )
268
+ -- we allow for it to take on a special form; the pair ([SWord 8], SymWord )
269
269
-- where the second argument is understood as the length of the list.
270
270
-- This allows us to 'fake' dynamically sized calldata arrays in a way
271
271
-- that has proven more efficient than `SList`.
272
272
data Calldata
273
273
= CalldataBuffer Buffer
274
- | CalldataDynamic ([SWord 8 ], SWord 32 )
274
+ | CalldataDynamic ([SWord 8 ], SymWord )
275
275
deriving Show
276
276
277
277
-- a whole foldable instance seems overkill, but length is always good to have!
278
- len :: Buffer -> SymWord -- SWord 32
278
+ len :: Buffer -> SymWord
279
279
len (DynamicSymBuffer a) = sw256 $ sFromIntegral $ SL. length a
280
280
len (StaticSymBuffer bs) = litWord . num $ length bs
281
281
len (ConcreteBuffer bs) = litWord . num $ BS. length bs
282
282
283
283
cdlen :: Calldata -> SymWord
284
284
cdlen (CalldataBuffer bf) = len bf
285
- cdlen (CalldataDynamic (_, a)) = sw256 $ sFromIntegral a
285
+ cdlen (CalldataDynamic (_, a)) = a
286
286
287
287
grab :: Int -> Buffer -> Buffer
288
288
grab n (StaticSymBuffer bs) = StaticSymBuffer $ take n bs
@@ -310,7 +310,7 @@ grabS n bs = case unliteral n of
310
310
readByteOrZero :: Int -> Buffer -> SWord 8
311
311
readByteOrZero i (StaticSymBuffer bs) = readByteOrZero' i bs
312
312
readByteOrZero i (ConcreteBuffer bs) = num $ Concrete. readByteOrZero i bs
313
- readByteOrZero i (DynamicSymBuffer bs) = readByteOrZero'' (literal $ num i) bs
313
+ readByteOrZero i (DynamicSymBuffer bs) = readByteOrZero'' (litWord $ num i) bs
314
314
315
315
-- pad up to 1000 bytes in the dynamic case
316
316
sliceWithZero :: SymWord -> SymWord -> Buffer -> Buffer
@@ -343,11 +343,13 @@ readMemoryWord i bf = case (maybeLitWord i, bf) of
343
343
344
344
readMemoryWord32 :: SymWord -> Buffer -> SWord 32
345
345
readMemoryWord32 i m = case (maybeLitWord i, m) of
346
- (Just i', StaticSymBuffer m') -> readMemoryWord32' i' m'
346
+ (Just i', StaticSymBuffer m') -> let S _ s = readMemoryWord32' i' m'
347
+ in sFromIntegral s
347
348
(Just i', ConcreteBuffer m') -> num $ Concrete. readMemoryWord32 i' m'
348
349
(_, DynamicSymBuffer m') -> case truncpad' 4 $ dropS i m' of
349
350
ConcreteBuffer s -> literal $ num $ Concrete. readMemoryWord32 0 s
350
- StaticSymBuffer s -> readMemoryWord32' 0 s
351
+ StaticSymBuffer s -> let S _ s' = readMemoryWord32' 0 s
352
+ in sFromIntegral s'
351
353
DynamicSymBuffer s -> fromBytes [s .!! literal k | k <- [0 .. 3 ]]
352
354
353
355
@@ -369,7 +371,7 @@ setMemoryByte i x m = case (maybeLitWord i, m) of
369
371
readSWord :: SymWord -> Buffer -> SymWord
370
372
readSWord i bf = case (maybeLitWord i, bf) of
371
373
(Just i', StaticSymBuffer x) -> readSWord' i' x
372
- (Just i', ConcreteBuffer x) -> num $ Concrete. readMemoryWord i' x
374
+ (Just i', ConcreteBuffer x) -> litWord $ Concrete. readBlobWord i' x
373
375
_ -> readSWord'' i (dynamize bf)
374
376
375
377
@@ -381,9 +383,9 @@ select' xs err ind = walk xs ind err
381
383
-- Generates a ridiculously large set of constraints (roughly 25k) when
382
384
-- the index is symbolic, but it still seems (kind of) manageable
383
385
-- for the solvers.
384
- readStaticWordWithBound :: SWord 32 -> ([SWord 8 ], SWord 32 ) -> SymWord
385
- readStaticWordWithBound ind (xs, bound) =
386
- case (num <$> fromSized <$> unliteral ind, num <$> fromSized <$> unliteral bound) of
386
+ readStaticWordWithBound :: SymWord -> ([SWord 8 ], SymWord ) -> SymWord
387
+ readStaticWordWithBound ( S _ ind) (xs, S _ bound) =
388
+ case (num <$> unliteral ind, num <$> unliteral bound) of
387
389
(Just i, Just b) ->
388
390
let bs = truncpad 32 $ drop i (take b xs)
389
391
in S (FromBytes (StaticSymBuffer bs)) (fromBytes bs)
0 commit comments