void Printf(const char *Fmt, ...);
void Print(const Unit &U, const char *PrintAfter = "");
+void PrintASCII(const uint8_t *Data, size_t Size, const char *PrintAfter = "");
void PrintASCII(const Unit &U, const char *PrintAfter = "");
std::string Hash(const Unit &U);
void SetTimer(int Seconds);
std::vector<DictionaryEntry> AutoDictionary;
std::vector<Mutator> Mutators;
std::vector<Mutator> CurrentMutatorSequence;
+ std::vector<DictionaryEntry> CurrentDictionaryEntrySequence;
const std::vector<Unit> *Corpus = nullptr;
FuzzerRandomBase &Rand;
size_t Idx = UsePositionHint ? PositionHint : Rand(Size + 1);
memmove(Data + Idx + Word.size(), Data + Idx, Size - Idx);
memcpy(Data + Idx, Word.data(), Word.size());
- return Size + Word.size();
+ Size += Word.size();
} else { // Overwrite some bytes with Word.
if (Word.size() > Size) return 0;
size_t Idx = UsePositionHint ? PositionHint : Rand(Size - Word.size());
memcpy(Data + Idx, Word.data(), Word.size());
- return Size;
}
+ CurrentDictionaryEntrySequence.push_back(DE);
+ return Size;
}
size_t MutationDispatcher::Mutate_ChangeASCIIInteger(uint8_t *Data, size_t Size,
void MutationDispatcher::StartMutationSequence() {
MDImpl->CurrentMutatorSequence.clear();
+ MDImpl->CurrentDictionaryEntrySequence.clear();
}
void MutationDispatcher::PrintMutationSequence() {
Printf("MS: %zd ", MDImpl->CurrentMutatorSequence.size());
for (auto M : MDImpl->CurrentMutatorSequence)
Printf("%s-", M.Name);
+ if (!MDImpl->CurrentDictionaryEntrySequence.empty()) {
+ Printf(" DE: ");
+ for (auto DE : MDImpl->CurrentDictionaryEntrySequence) {
+ Printf("\"");
+ PrintASCII(DE.Word, "\"-");
+ }
+ }
}
// Mutates Data in place, returns new size.
uint8_t Data[kMaxSize];
};
-static void PrintDataByte(uint8_t Byte) {
- if (Byte == '\\')
- Printf("\\\\");
- else if (Byte == '"')
- Printf("\\\"");
- else if (Byte >= 32 && Byte < 127)
- Printf("%c", Byte);
- else
- Printf("\\x%02x", Byte);
-}
-
-static void PrintData(const uint8_t *Data, size_t Size) {
- Printf("\"");
- for (size_t i = 0; i < Size; i++) {
- PrintDataByte(Data[i]);
- }
- Printf("\"");
-}
-
const size_t TraceBasedMutation::kMaxSize;
class TraceState {
Printf("AutoDict:\n");
for (auto &I : CountedUnits) {
Printf(" %zd ", I.first);
- PrintData(I.second.data(), I.second.size());
+ PrintASCII(I.second);
Printf("\n");
}
}
int Added1 = TryToAddDesiredData(Data2, Data1, CmpSize);
if ((Added1 || Added2) && Options.Verbosity >= 3) {
Printf("MemCmp Added %d%d: ", Added1, Added2);
- if (Added1) PrintData(Data1, CmpSize);
- if (Added2) PrintData(Data2, CmpSize);
+ if (Added1) PrintASCII(Data1, CmpSize);
+ if (Added2) PrintASCII(Data2, CmpSize);
Printf("\n");
}
}
Printf("%s", PrintAfter);
}
+void PrintASCIIByte(uint8_t Byte) {
+ if (Byte == '\\')
+ Printf("\\\\");
+ else if (Byte == '"')
+ Printf("\\\"");
+ else if (Byte >= 32 && Byte < 127)
+ Printf("%c", Byte);
+ else
+ Printf("\\x%02x", Byte);
+}
+
+void PrintASCII(const uint8_t *Data, size_t Size, const char *PrintAfter) {
+ for (size_t i = 0; i < Size; i++)
+ PrintASCIIByte(Data[i]);
+ Printf("%s", PrintAfter);
+}
+
void PrintASCII(const Unit &U, const char *PrintAfter) {
- for (auto X : U) {
- if (isprint(X))
- Printf("%c", X);
- else
- Printf("\\x%x", (unsigned)X);
- }
+ for (auto X : U)
+ PrintASCIIByte(X);
Printf("%s", PrintAfter);
}