LLVM  4.0.0
FuzzerUtil.h
Go to the documentation of this file.
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 bool ExecuteCommandAndReadOutput(const std::string &Command, std::string *Out);
45 
46 // Platform specific functions.
47 void SetSignalHandler(const FuzzingOptions& Options);
48 
49 void SleepSeconds(int Seconds);
50 
51 unsigned long GetPid();
52 
53 size_t GetPeakRSSMb();
54 
55 int ExecuteCommand(const std::string &Command);
56 
57 FILE *OpenProcessPipe(const char *Command, const char *Mode);
58 
59 const void *SearchMemory(const void *haystack, size_t haystacklen,
60  const void *needle, size_t needlelen);
61 
62 std::string CloneArgsWithoutX(const std::vector<std::string> &Args,
63  const char *X1, const char *X2);
64 
65 inline std::string CloneArgsWithoutX(const std::vector<std::string> &Args,
66  const char *X) {
67  return CloneArgsWithoutX(Args, X, X);
68 }
69 
70 } // namespace fuzzer
71 
72 #endif // LLVM_FUZZER_UTIL_H
void PrintHexArray(const uint8_t *Data, size_t Size, const char *PrintAfter)
Definition: FuzzerUtil.cpp:27
SI Whole Quad Mode
bool ExecuteCommandAndReadOutput(const std::string &Command, std::string *Out)
Definition: FuzzerUtil.cpp:208
void SleepSeconds(int Seconds)
std::string DescribePC(const char *SymbolizedFMT, uintptr_t PC)
Definition: FuzzerUtil.cpp:182
static PassOptionList PrintAfter("print-after", llvm::cl::desc("Print IR after specified passes"), cl::Hidden)
std::string Base64(const Unit &U)
Definition: FuzzerUtil.cpp:154
FILE * OpenProcessPipe(const char *Command, const char *Mode)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
void SetSignalHandler(const FuzzingOptions &Options)
bool ToASCII(uint8_t *Data, size_t Size)
Definition: FuzzerUtil.cpp:59
void PrintPC(const char *SymbolizedFMT, const char *FallbackFMT, uintptr_t PC)
Definition: FuzzerUtil.cpp:191
const void * SearchMemory(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen)
bool IsASCII(const Unit &U)
Definition: FuzzerUtil.cpp:73
unsigned long GetPid()
size_t GetPeakRSSMb()
Definition: afl_driver.cpp:113
std::vector< uint8_t > Unit
Definition: FuzzerDefs.h:71
unsigned NumberOfCpuCores()
Definition: FuzzerUtil.cpp:198
int ExecuteCommand(const std::string &Command)
static void PrintASCII(const Word &W, const char *PrintAfter)
std::string CloneArgsWithoutX(const std::vector< std::string > &Args, const char *X1, const char *X2)
char * PC