Repository navigation
Expand file tree
/
Copy pathChromium.cpp
More file actions
71 lines (59 loc) · 2.06 KB
/
Copy pathChromium.cpp
File metadata and controls
71 lines (59 loc) · 2.06 KB
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
71
#include <fstream>
#include <filesystem>
#include <benchmark/benchmark.h>
#include <libhat/scanner.hpp>
#include <format>
#include "scanner/scanner.hpp"
#define WIDE_STR_(x) L ## #x
#define WIDE_STR(x) WIDE_STR_(x)
static constexpr hat::cstring_view DLL_MAIN_PATTERN = "48 89 5C 24 08 48 89 74 24 10 57 48 83 EC ?? 49 8B F8 8B DA";
static std::span<const std::byte> GetFileData() {
static std::vector<std::byte> data = []{
const std::filesystem::path path{WIDE_STR(CHROME_DLL_PATH)};
std::ifstream file(path, std::ios::binary);
if (!file.is_open()) {
std::terminate();
}
file.seekg(0, std::ios::end);
const std::streampos fileSize = file.tellg();
file.seekg(0, std::ios::beg);
std::vector<std::byte> contents(static_cast<size_t>(fileSize));
file.read(reinterpret_cast<char*>(contents.data()), fileSize);
return contents;
}();
return data;
}
static void BenchmarkScanner(Scanner& scanner, benchmark::State& state) {
if (!scanner.Supported()) {
state.SkipWithMessage("Skipping (not natively supported by hardware or OS)");
return;
}
const auto buf = GetFileData();
const std::byte* result = nullptr;
scanner.Setup(DLL_MAIN_PATTERN);
for (auto _ : state) {
benchmark::DoNotOptimize(result = scanner.Find(buf));
}
if (!result) {
state.SkipWithError("Scanner failed to find match in buffer");
}
state.SetBytesProcessed(static_cast<int64_t>(state.iterations() * (result - buf.data())));
}
int main(int argc, char** argv) {
for (auto& scanner : Scanner::All()) {
auto* bm = ::benchmark::RegisterBenchmark(
std::string{scanner.Name()},
[&scanner](benchmark::State& state) {
BenchmarkScanner(scanner, state);
}
);
bm->Threads(1);
bm->MinWarmUpTime(2);
bm->MinTime(4);
bm->UseRealTime();
}
::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();
::benchmark::Shutdown();
return 0;
}