new interface
This commit is contained in:
parent
abba98ad2a
commit
efb3c07314
@ -165,13 +165,13 @@ extern void *DeepState_ConcretizeData(void *begin, void *end);
|
||||
|
||||
/* Assign a symbolic C string of length `len` with only chars in allowed,
|
||||
* if allowed is non-null */
|
||||
extern void DeepState_AssignCStr(char* str, size_t len, const char* allowed);
|
||||
extern void DeepState_AssignCStr_C(char* str, size_t len, const char* allowed);
|
||||
|
||||
/* Return a symbolic C string of length `len`. */
|
||||
extern char *DeepState_CStr(size_t len);
|
||||
extern char *DeepState_CStr_C(size_t len, const char* allowed);
|
||||
|
||||
/* Symbolize a C string */
|
||||
void DeepState_SymbolizeCStr(char *begin);
|
||||
void DeepState_SymbolizeCStr_C(char *begin, const char* allowed);
|
||||
|
||||
/* Concretize a C string. Returns a pointer to the beginning of the
|
||||
* concretized C string. */
|
||||
|
||||
@ -471,17 +471,32 @@ struct Comparer {
|
||||
}
|
||||
};
|
||||
|
||||
/* Like DeepState_AssignCStr_C, but fills in a null allowed. */
|
||||
inline static void DeepState_AssignCStr(char* str, size_t len,
|
||||
const char* allowed = 0) {
|
||||
DeepState_AssignCStr_C(str, len, allowed);
|
||||
}
|
||||
|
||||
/* Like DeepState_AssignCStr, but Pumps through possible string sizes. */
|
||||
inline static void DeepState_AssignCStrMax(char* str, size_t max_len,
|
||||
const char* allowed) {
|
||||
uint32_t size = DeepState_UIntInRange(0, max_len);
|
||||
DeepState_AssignCStr(str, Pump(size, max_len), allowed);
|
||||
inline static void DeepState_AssignCStrUpToLen(char* str, size_t max_len,
|
||||
const char* allowed = 0) {
|
||||
uint32_t len = DeepState_UIntInRange(0, max_len);
|
||||
DeepState_AssignCStr_C(str, Pump(len, max_len), allowed);
|
||||
}
|
||||
|
||||
/* Like DeepState_CStr_C, but fills in a null allowed. */
|
||||
inline static char* DeepState_CStr(size_t len, char* allowed = 0) {
|
||||
return DeepState_CStr_C(len, allowed);
|
||||
}
|
||||
|
||||
/* Like DeepState_CStr, but Pumps through possible string sizes. */
|
||||
inline static char* DeepState_CStrMax(size_t max_len) {
|
||||
uint32_t size = DeepState_UIntInRange(0, max_len);
|
||||
return DeepState_CStr(Pump(size, max_len));
|
||||
inline static char* DeepState_CStrUpToLen(size_t max_len, char* allowed = 0) {
|
||||
uint32_t len = DeepState_UIntInRange(0, max_len);
|
||||
return DeepState_CStr_C(Pump(len, max_len), allowed);
|
||||
}
|
||||
|
||||
inline static void DeepState_SymbolizeCStr_C(char *begin, char* allowed = 0) {
|
||||
DeepState_SymbolizeCStr_C(begin, allowed);
|
||||
}
|
||||
|
||||
} // namespace deepstate
|
||||
|
||||
@ -176,22 +176,28 @@ void *DeepState_ConcretizeData(void *begin, void *end) {
|
||||
}
|
||||
|
||||
/* Assign a symbolic C string of length `len`. */
|
||||
void DeepState_AssignCStr(char* str, size_t len, const char* allowed) {
|
||||
void DeepState_AssignCStr_C(char* str, size_t len, const char* allowed) {
|
||||
if (SIZE_MAX == len) {
|
||||
DeepState_Abandon("Can't create an SIZE_MAX-length string.");
|
||||
}
|
||||
if (NULL == str) {
|
||||
DeepState_Abandon("Attempted to populate null pointer.");
|
||||
}
|
||||
uint32_t allowed_size = strlen(allowed);
|
||||
for (int i = 0; i < len; i++) {
|
||||
str[i] = allowed[DeepState_UIntInRange(0, allowed_size)];
|
||||
if (len) {
|
||||
if (!allowed) {
|
||||
DeepState_SymbolizeData(str, &(str[len - 1]));
|
||||
} else {
|
||||
uint32_t allowed_size = strlen(allowed);
|
||||
for (int i = 0; i < len; i++) {
|
||||
str[i] = allowed[DeepState_UIntInRange(0, allowed_size)];
|
||||
}
|
||||
}
|
||||
}
|
||||
str[len] = '\0';
|
||||
}
|
||||
|
||||
/* Return a symbolic C string of length `len`. */
|
||||
char *DeepState_CStr(size_t len) {
|
||||
char *DeepState_CStr_C(size_t len, const char* allowed) {
|
||||
if (SIZE_MAX == len) {
|
||||
DeepState_Abandon("Can't create an SIZE_MAX-length string.");
|
||||
}
|
||||
@ -201,16 +207,33 @@ char *DeepState_CStr(size_t len) {
|
||||
}
|
||||
DeepState_GeneratedStrings[DeepState_GeneratedStringsIndex++] = str;
|
||||
if (len) {
|
||||
DeepState_SymbolizeData(str, &(str[len - 1]));
|
||||
if (!allowed) {
|
||||
DeepState_SymbolizeData(str, &(str[len - 1]));
|
||||
} else {
|
||||
uint32_t allowed_size = strlen(allowed);
|
||||
for (int i = 0; i < len; i++) {
|
||||
str[i] = allowed[DeepState_UIntInRange(0, allowed_size)];
|
||||
}
|
||||
}
|
||||
}
|
||||
str[len] = '\0';
|
||||
return str;
|
||||
}
|
||||
|
||||
/* Symbolize a C string */
|
||||
void DeepState_SymbolizeCStr(char *begin) {
|
||||
void DeepState_SymbolizeCStr_C(char *begin, const char* allowed) {
|
||||
if (begin && begin[0]) {
|
||||
DeepState_SymbolizeData(begin, begin + strlen(begin));
|
||||
if (!allowed) {
|
||||
DeepState_SymbolizeData(begin, begin + strlen(begin));
|
||||
} else {
|
||||
uint32_t allowed_size = strlen(allowed);
|
||||
uint8_t *bytes = (uint8_t *) begin;
|
||||
uintptr_t begin_addr = (uintptr_t) begin;
|
||||
uintptr_t end_addr = (uintptr_t) (begin + strlen(begin));
|
||||
for (uintptr_t i = 0, max_i = (end_addr - begin_addr); i < max_i; ++i) {
|
||||
bytes[i] = allowed[DeepState_UIntInRange(0, allowed_size)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user