-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathfuzz.cpp
70 lines (65 loc) · 2.29 KB
/
fuzz.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <StdAfx.h>
#include <core/smartview/SmartView.h>
#include <core/addin/mfcmapi.h>
#include <core/addin/addin.h>
#include <core/utility/registry.h>
#include <core/utility/strings.h>
#include <array>
#include <chrono>
#ifdef FUZZ
std::once_flag _initFlag;
void EnsureInit()
{
addin::MergeAddInArrays();
registry::doSmartView = true;
registry::useGetPropList = true;
registry::parseNamedProps = true;
registry::cacheNamedProps = true;
strings::setTestInstance(GetModuleHandleW(L"mfcmapi.exe"));
}
void test(const SBinary hex)
{
static auto testnum = 1LL;
const auto batchsize = 1000ll;
const bool doLog = testnum++ % batchsize == 0;
// we're gonna track run times for each parser type in an array
// We add the time of the current test to it's bucket, then every time doLog is true, we print the average time for that parser type
static std::array<std::chrono::duration<double, std::milli>, static_cast<size_t>(parserType::END)> runtimes = {};
for (const auto parser : SmartViewParserTypeArray)
{
if (parser.type == parserType::NOPARSING) continue;
//wprintf(L"Testing %ws\r\n", addin::AddInStructTypeToString(parser.type).c_str());
const auto start = std::chrono::high_resolution_clock::now();
(void) smartview::InterpretBinary(hex, parser.type, nullptr);
const auto end = std::chrono::high_resolution_clock::now();
runtimes[static_cast<size_t>(parser.type)] += end - start;
}
if (doLog)
{
wprintf(L"Test %lld\r\n", testnum);
wprintf(L"%-40s %-15s %-15s\n", L"Parser Type", L"Total Time (ms)", L"Time per Test (ms)");
for (const auto parser : SmartViewParserTypeArray)
{
if (parser.type == parserType::NOPARSING) continue;
wprintf(
L"%-40ws %-15f %-15f\n",
addin::AddInStructTypeToString(parser.type).c_str(),
runtimes[static_cast<size_t>(parser.type)].count(),
runtimes[static_cast<size_t>(parser.type)].count() / testnum);
}
}
}
#ifdef __cplusplus
#define FUZZ_EXPORT extern "C" __declspec(dllexport)
#else
#define FUZZ_EXPORT __declspec(dllexport)
#endif
FUZZ_EXPORT int __cdecl LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
std::call_once(_initFlag, EnsureInit);
const SBinary input = {static_cast<ULONG>(size), (LPBYTE) (data)};
//wprintf(L"Fuzzing: %ws\r\n", strings::BinToHexString(&input, true).c_str());
test(input);
return 0;
}
#endif // FUZZ