george.karpenkov | 29efa6d | 2017-08-21 23:25:50 +0000 | [diff] [blame^] | 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 | |
| 17 | namespace fuzzer { |
| 18 | |
| 19 | void PrintHexArray(const Unit &U, const char *PrintAfter = ""); |
| 20 | |
| 21 | void PrintHexArray(const uint8_t *Data, size_t Size, |
| 22 | const char *PrintAfter = ""); |
| 23 | |
| 24 | void PrintASCII(const uint8_t *Data, size_t Size, const char *PrintAfter = ""); |
| 25 | |
| 26 | void 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. |
| 30 | bool ToASCII(uint8_t *Data, size_t Size); |
| 31 | |
| 32 | bool IsASCII(const Unit &U); |
| 33 | |
| 34 | bool IsASCII(const uint8_t *Data, size_t Size); |
| 35 | |
| 36 | std::string Base64(const Unit &U); |
| 37 | |
| 38 | void PrintPC(const char *SymbolizedFMT, const char *FallbackFMT, uintptr_t PC); |
| 39 | |
| 40 | std::string DescribePC(const char *SymbolizedFMT, uintptr_t PC); |
| 41 | |
| 42 | unsigned NumberOfCpuCores(); |
| 43 | |
| 44 | // Platform specific functions. |
| 45 | void SetSignalHandler(const FuzzingOptions& Options); |
| 46 | |
| 47 | void SleepSeconds(int Seconds); |
| 48 | |
| 49 | unsigned long GetPid(); |
| 50 | |
| 51 | size_t GetPeakRSSMb(); |
| 52 | |
| 53 | int ExecuteCommand(const std::string &Command); |
| 54 | |
| 55 | FILE *OpenProcessPipe(const char *Command, const char *Mode); |
| 56 | |
| 57 | const void *SearchMemory(const void *haystack, size_t haystacklen, |
| 58 | const void *needle, size_t needlelen); |
| 59 | |
| 60 | std::string CloneArgsWithoutX(const std::vector<std::string> &Args, |
| 61 | const char *X1, const char *X2); |
| 62 | |
| 63 | inline std::string CloneArgsWithoutX(const std::vector<std::string> &Args, |
| 64 | const char *X) { |
| 65 | return CloneArgsWithoutX(Args, X, X); |
| 66 | } |
| 67 | |
| 68 | inline 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 | |
| 76 | std::string DisassembleCmd(const std::string &FileName); |
| 77 | |
| 78 | std::string SearchRegexCmd(const std::string &Regex); |
| 79 | |
| 80 | size_t SimpleFastHash(const uint8_t *Data, size_t Size); |
| 81 | |
| 82 | } // namespace fuzzer |
| 83 | |
| 84 | #endif // LLVM_FUZZER_UTIL_H |