2016-11-30 20:06:14 +01:00
|
|
|
//===- FuzzerUtil.h - Internal header for the Fuzzer Utils ------*- C++ -* ===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Util functions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2016-12-13 18:46:11 +01:00
|
|
|
|
2016-11-30 20:06:14 +01:00
|
|
|
#ifndef LLVM_FUZZER_UTIL_H
|
|
|
|
#define LLVM_FUZZER_UTIL_H
|
|
|
|
|
|
|
|
#include "FuzzerDefs.h"
|
|
|
|
|
|
|
|
namespace fuzzer {
|
|
|
|
|
|
|
|
void PrintHexArray(const Unit &U, const char *PrintAfter = "");
|
|
|
|
|
|
|
|
void PrintHexArray(const uint8_t *Data, size_t Size,
|
|
|
|
const char *PrintAfter = "");
|
|
|
|
|
|
|
|
void PrintASCII(const uint8_t *Data, size_t Size, const char *PrintAfter = "");
|
|
|
|
|
|
|
|
void PrintASCII(const Unit &U, const char *PrintAfter = "");
|
|
|
|
|
|
|
|
// Changes U to contain only ASCII (isprint+isspace) characters.
|
|
|
|
// Returns true iff U has been changed.
|
|
|
|
bool ToASCII(uint8_t *Data, size_t Size);
|
|
|
|
|
|
|
|
bool IsASCII(const Unit &U);
|
|
|
|
|
|
|
|
bool IsASCII(const uint8_t *Data, size_t Size);
|
|
|
|
|
|
|
|
std::string Base64(const Unit &U);
|
|
|
|
|
|
|
|
void PrintPC(const char *SymbolizedFMT, const char *FallbackFMT, uintptr_t PC);
|
|
|
|
|
|
|
|
std::string DescribePC(const char *SymbolizedFMT, uintptr_t PC);
|
|
|
|
|
2016-12-13 18:45:53 +01:00
|
|
|
unsigned NumberOfCpuCores();
|
2016-11-30 20:06:14 +01:00
|
|
|
|
|
|
|
// Platform specific functions.
|
2016-12-13 18:45:20 +01:00
|
|
|
void SetSignalHandler(const FuzzingOptions& Options);
|
2016-11-30 20:06:14 +01:00
|
|
|
|
|
|
|
void SleepSeconds(int Seconds);
|
|
|
|
|
2016-12-13 18:45:44 +01:00
|
|
|
unsigned long GetPid();
|
2016-11-30 20:06:14 +01:00
|
|
|
|
|
|
|
size_t GetPeakRSSMb();
|
|
|
|
|
2016-12-02 21:54:56 +01:00
|
|
|
int ExecuteCommand(const std::string &Command);
|
2016-12-02 20:38:19 +01:00
|
|
|
|
2016-12-03 00:02:01 +01:00
|
|
|
FILE *OpenProcessPipe(const char *Command, const char *Mode);
|
|
|
|
|
|
|
|
const void *SearchMemory(const void *haystack, size_t haystacklen,
|
|
|
|
const void *needle, size_t needlelen);
|
|
|
|
|
2016-12-09 02:17:24 +01:00
|
|
|
std::string CloneArgsWithoutX(const std::vector<std::string> &Args,
|
|
|
|
const char *X1, const char *X2);
|
|
|
|
|
|
|
|
inline std::string CloneArgsWithoutX(const std::vector<std::string> &Args,
|
|
|
|
const char *X) {
|
|
|
|
return CloneArgsWithoutX(Args, X, X);
|
|
|
|
}
|
|
|
|
|
2017-07-15 01:33:04 +02:00
|
|
|
inline std::pair<std::string, std::string> SplitBefore(std::string X,
|
|
|
|
std::string S) {
|
|
|
|
auto Pos = S.find(X);
|
|
|
|
if (Pos == std::string::npos)
|
|
|
|
return std::make_pair(S, "");
|
|
|
|
return std::make_pair(S.substr(0, Pos), S.substr(Pos));
|
|
|
|
}
|
|
|
|
|
2017-01-22 02:58:26 +01:00
|
|
|
std::string DisassembleCmd(const std::string &FileName);
|
|
|
|
|
|
|
|
std::string SearchRegexCmd(const std::string &Regex);
|
|
|
|
|
2017-07-14 02:06:27 +02:00
|
|
|
size_t SimpleFastHash(const uint8_t *Data, size_t Size);
|
|
|
|
|
2016-11-30 20:06:14 +01:00
|
|
|
} // namespace fuzzer
|
2016-12-13 18:46:11 +01:00
|
|
|
|
2016-11-30 20:06:14 +01:00
|
|
|
#endif // LLVM_FUZZER_UTIL_H
|