1//===- FuzzerUtil.h - Internal header for the Fuzzer Utils ------*- C++ -* ===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// Util functions. 10//===----------------------------------------------------------------------===// 11 12#ifndef LLVM_FUZZER_UTIL_H 13#define LLVM_FUZZER_UTIL_H 14 15#include "FuzzerDefs.h" 16 17namespace fuzzer { 18 19void PrintHexArray(const Unit &U, const char *PrintAfter = ""); 20 21void PrintHexArray(const uint8_t *Data, size_t Size, 22 const char *PrintAfter = ""); 23 24void PrintASCII(const uint8_t *Data, size_t Size, const char *PrintAfter = ""); 25 26void PrintASCII(const Unit &U, const char *PrintAfter = ""); 27 28// Changes U to contain only ASCII (isprint+isspace) characters. 29// Returns true iff U has been changed. 30bool ToASCII(uint8_t *Data, size_t Size); 31 32bool IsASCII(const Unit &U); 33 34bool IsASCII(const uint8_t *Data, size_t Size); 35 36std::string Base64(const Unit &U); 37 38void PrintPC(const char *SymbolizedFMT, const char *FallbackFMT, uintptr_t PC); 39 40std::string DescribePC(const char *SymbolizedFMT, uintptr_t PC); 41 42unsigned NumberOfCpuCores(); 43 44// Platform specific functions. 45void SetSignalHandler(const FuzzingOptions& Options); 46 47void SleepSeconds(int Seconds); 48 49unsigned long GetPid(); 50 51size_t GetPeakRSSMb(); 52 53int ExecuteCommand(const std::string &Command); 54 55FILE *OpenProcessPipe(const char *Command, const char *Mode); 56 57const void *SearchMemory(const void *haystack, size_t haystacklen, 58 const void *needle, size_t needlelen); 59 60std::string CloneArgsWithoutX(const Vector<std::string> &Args, 61 const char *X1, const char *X2); 62 63inline std::string CloneArgsWithoutX(const Vector<std::string> &Args, 64 const char *X) { 65 return CloneArgsWithoutX(Args, X, X); 66} 67 68inline std::pair<std::string, std::string> SplitBefore(std::string X, 69 std::string S) { 70 auto Pos = S.find(X); 71 if (Pos == std::string::npos) 72 return std::make_pair(S, ""); 73 return std::make_pair(S.substr(0, Pos), S.substr(Pos)); 74} 75 76std::string DisassembleCmd(const std::string &FileName); 77 78std::string SearchRegexCmd(const std::string &Regex); 79 80size_t SimpleFastHash(const uint8_t *Data, size_t Size); 81 82} // namespace fuzzer 83 84#endif // LLVM_FUZZER_UTIL_H 85