Skip to content
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

printable_bytes #1671

Merged
merged 1 commit into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions manticore/ethereum/manticore.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import binascii
import json
import logging
import string
from multiprocessing import Queue, Process
from queue import Empty as EmptyQueue
from typing import Dict, Optional, Union
Expand Down Expand Up @@ -37,7 +36,7 @@
from ..platforms import evm
from ..utils import config, log
from ..utils.deprecated import deprecated
from ..utils.helpers import PickleSerializer
from ..utils.helpers import PickleSerializer, printable_bytes

logger = logging.getLogger(__name__)
logging.getLogger("CryticCompile").setLevel(logging.ERROR)
Expand Down Expand Up @@ -1617,16 +1616,13 @@ def generate_testcase(self, state, message="", only_if=None, name="user"):
is_log_symbolic = issymbolic(log_item.memlog)
is_something_symbolic = is_log_symbolic or is_something_symbolic
solved_memlog = state.solve_one(log_item.memlog)
printable_bytes = "".join(
[c for c in map(chr, solved_memlog) if c in string.printable]
)

logs_summary.write("Address: %x\n" % log_item.address)
logs_summary.write(
"Memlog: %s (%s) %s\n"
% (
binascii.hexlify(solved_memlog).decode(),
printable_bytes,
printable_bytes(solved_memlog),
flagged(is_log_symbolic),
)
)
Expand Down
7 changes: 5 additions & 2 deletions manticore/platforms/evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
)
from ..core.state import Concretize, TerminateState
from ..utils.event import Eventful
from ..utils.helpers import printable_bytes
from ..utils import config
from ..core.smtlib.visitors import simplify
from ..exceptions import EthereumError
Expand Down Expand Up @@ -242,8 +243,10 @@ def dump(self, stream, state, mevm, conc_tx=None):
return_data = conc_tx.return_data

stream.write(
"Return_data: 0x{} {}\n".format(
binascii.hexlify(return_data).decode(), flagged(issymbolic(self.return_data))
"Return_data: 0x{} ({}) {}\n".format(
binascii.hexlify(return_data).decode(),
printable_bytes(return_data),
flagged(issymbolic(self.return_data))
)
)

Expand Down
7 changes: 7 additions & 0 deletions manticore/utils/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import pickle
import string
import sys
from collections import OrderedDict
from gzip import GzipFile
Expand Down Expand Up @@ -31,6 +32,12 @@ def interval_intersection(min1, max1, min2, max2):
return None


def printable_bytes(bytes: bytes):
return "".join(
[c for c in map(chr, bytes) if c in string.printable]
)


class CacheDict(OrderedDict):
def __init__(self, *args, max_size=30000, flush_perc=30, **kwargs):
self._max_size = max_size
Expand Down