This commit is contained in:
alex 2017-12-12 12:24:44 -08:00
commit acd4e025b6
4 changed files with 47 additions and 39 deletions

View File

@ -270,10 +270,11 @@ class DeepState(object):
new_bytes = [] new_bytes = []
for b in byte_str: for b in byte_str:
if isinstance(b, str): if isinstance(b, str):
assert len(b) == 1 new_bytes.extend(ord(bn) for bn in b)
new_bytes.append(ord(b))
elif isinstance(b, (int, long)): elif isinstance(b, (int, long)):
new_bytes.append(b) new_bytes.append(b)
elif isinstance(b, (list, tuple)):
new_bytes.extend(self._concretize_bytes(b))
else: else:
new_bytes.append(self.concretize(b, constrain=True)) new_bytes.append(self.concretize(b, constrain=True))
return new_bytes return new_bytes
@ -303,9 +304,11 @@ class DeepState(object):
format_str = format_str.replace('z', '') format_str = format_str.replace('z', '')
format_str = format_str.replace('t', '') format_str = format_str.replace('t', '')
message.extend(format_str % val) message.append(format_str % val)
return "".join(message) res = "".join(message)
res.rstrip("\r\n")
return res
def _save_test(self, info, input_bytes): def _save_test(self, info, input_bytes):
"""Save the concretized bytes to a file.""" """Save the concretized bytes to a file."""
@ -495,7 +498,7 @@ class DeepState(object):
level = self.concretize(level, constrain=True) level = self.concretize(level, constrain=True)
ea = self.concretize(ea, constrain=True) ea = self.concretize(ea, constrain=True)
assert level in LOG_LEVEL_TO_LOGGER assert level in LOG_LEVEL_TO_LOGGER
self.log_message(level, self.read_c_string(ea, concretize=False)) self.log_message(level, self.read_c_string(ea, concretize=False)[0])
if level == LOG_LEVEL_FATAL: if level == LOG_LEVEL_FATAL:
self.api_fail() self.api_fail()
@ -513,8 +516,8 @@ class DeepState(object):
unpack_ea = self.concretize(unpack_ea, constrain=True) unpack_ea = self.concretize(unpack_ea, constrain=True)
uint64_ea = self.concretize(uint64_ea, constrain=True) uint64_ea = self.concretize(uint64_ea, constrain=True)
format_str, _ = self.read_c_string(format_ea) format_str = self.read_c_string(format_ea)[0]
unpack_str, _ = self.read_c_string(unpack_ea) unpack_str = self.read_c_string(unpack_ea)[0]
uint64_bytes = [] uint64_bytes = []
for i in xrange(8): for i in xrange(8):
b, _ = self.read_uint8_t(uint64_ea + i, concretize=False) b, _ = self.read_uint8_t(uint64_ea + i, concretize=False)
@ -545,8 +548,8 @@ class DeepState(object):
format_ea = self.concretize(format_ea, constrain=True) format_ea = self.concretize(format_ea, constrain=True)
str_ea = self.concretize(str_ea, constrain=True) str_ea = self.concretize(str_ea, constrain=True)
format_str, _ = self.read_c_string(format_ea) format_str = self.read_c_string(format_ea)[0]
print_str, _ = self.read_c_string(str_ea, concretize=False) print_str = self.read_c_string(str_ea, concretize=False)[0]
stream_id = 'stream_{}'.format(level) stream_id = 'stream_{}'.format(level)
stream = list(self.context[stream_id]) stream = list(self.context[stream_id])

View File

@ -30,35 +30,33 @@ TEST(OneOfExample, ProduceSixtyOrHigher) {
// Add this back in and uncomment out choices parts below, add // Add this back in and uncomment out choices parts below, add
// & choices, N to captures, and it becomes quite difficult. // & choices, N to captures, and it becomes quite difficult.
int N = 0; for (int N = 0;N < LENGTH; N++) {
while (N < LENGTH) {
N++;
OneOf( OneOf(
[&x] { [&x] {
x += 1; x += 1;
printf("-1\n"); printf("+=1\n");
//choices[N] = '+'; //choices[N] = '+';
}, },
[&x] { [&x] {
x -= 1; x -= 1;
printf("+1\n"); printf("-=1\n");
//choices[N] = '-'; //choices[N] = '-';
}, },
[&x] { [&x] {
x *= 2; x *= 2;
printf("*2\n"); printf("*2\n");
//choices[N] = '2'; //choices[N] = '2';
}, },
[&x] { [&x] {
x += 10; x += 10;
printf("+=10\n"); printf("+=10\n");
//choices[N] = 'x'; //choices[N] = 'x';
}, },
[&x] { [&x] {
x = 0; x = 0;
printf("=0\n"); printf("=0\n");
//choices[N] = '0'; //choices[N] = '0';
}); });
//choices[N+1] = 0; //choices[N+1] = 0;
ASSERT_LE(x, 60) ASSERT_LE(x, 60)

View File

@ -15,7 +15,7 @@
*/ */
#include <deepstate/DeepState.hpp> #include <deepstate/DeepState.hpp>
/*
TEST(Streaming, BasicLevels) { TEST(Streaming, BasicLevels) {
LOG(DEBUG) << "This is a debug message"; LOG(DEBUG) << "This is a debug message";
LOG(INFO) << "This is an info message"; LOG(INFO) << "This is an info message";
@ -32,11 +32,12 @@ TEST(Streaming, BasicTypes) {
LOG(INFO) << "string"; LOG(INFO) << "string";
LOG(INFO) << nullptr; LOG(INFO) << nullptr;
} }
*/
TEST(Formatting, OverridePrintf) { TEST(Formatting, OverridePrintf) {
printf("hello string=%s hex_lower=%x hex_upper=%X octal=%o char=%c dec=%d" printf("hello string=%s hex_lower=%x hex_upper=%X octal=%o char=%c dec=%d"
"double=%f sci=%e SCI=%E pointer=%p", "double=%f sci=%e SCI=%E pointer=%p",
"world", 999, 999, 999, 'a', 999, 999.0, 999.0, 999.0, "world"); "world", 999, 999, 999, 'a', 999, 999.0, 999.0, 999.0, "world");
printf("hello again!");
} }
int main(void) { int main(void) {

View File

@ -100,6 +100,12 @@ void DeepState_LogFormat(enum DeepState_LogLevel level,
} }
/* Override libc! */ /* Override libc! */
DEEPSTATE_NOINLINE
int puts(const char *str) {
DeepState_Log(DeepState_LogInfo, str);
return 0;
}
DEEPSTATE_NOINLINE DEEPSTATE_NOINLINE
int printf(const char *format, ...) { int printf(const char *format, ...) {
va_list args; va_list args;