upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/pe_loader.cpp
diff options
context:
space:
mode:
authorMoonEyes <ducoinbenjamin@yahoo.fr>2026-11-28 18:59:07 +0100
committerGitHub <noreply@github.com>2026-11-28 18:59:07 +0100
commit7daa4a4a51d304d9cb2b4576b65ca3ba05a5ff9b (patch)
treeb12fd87c9f14ede728280d2ec71f05cf0928254e /runtime/src/pe_loader.cpp
parent408aaeafec3efc1a1e0289fd6d66b193942f5400 (diff)
parentd8cfc01d51998698c9f8d1c2bc3c17a45c388b55 (diff)
Merge pull request #664 from sodove/perf/pe-block-reads
runtime: read PE files in blocks (RT-PE-BLOCK-READ)
Diffstat (limited to 'runtime/src/pe_loader.cpp')
-rw-r--r--runtime/src/pe_loader.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp
index d6ac0e1a4..d44160505 100644
--- a/runtime/src/pe_loader.cpp
+++ b/runtime/src/pe_loader.cpp
@@ -2,6 +2,7 @@
2 2
3#include <windows.h> 3#include <windows.h>
4#include <intrin.h> 4#include <intrin.h>
5#include <share.h>
5#include <tlhelp32.h> 6#include <tlhelp32.h>
6 7
7#include <algorithm> 8#include <algorithm>
@@ -10,7 +11,7 @@
10#include <cstdio> 11#include <cstdio>
11#include <cstdlib> 12#include <cstdlib>
12#include <cstring> 13#include <cstring>
13#include <fstream> 14#include <memory>
14#include <mutex> 15#include <mutex>
15#include <stdexcept> 16#include <stdexcept>
16#include <system_error> 17#include <system_error>
@@ -77,9 +78,16 @@ std::string path_utf8(const std::filesystem::path& path) {
77} 78}
78 79
79std::vector<uint8_t> read_file(const std::filesystem::path& p) { 80std::vector<uint8_t> read_file(const std::filesystem::path& p) {
80 std::ifstream f(p, std::ios::binary); 81 std::unique_ptr<std::FILE, decltype(&std::fclose)> file(
81 if (!f) throw std::runtime_error("cannot open " + path_utf8(p)); 82 _wfsopen(p.c_str(), L"rb", _SH_DENYNO), std::fclose);
82 return {std::istreambuf_iterator<char>(f), {}}; 83 if (!file) throw std::runtime_error("cannot open " + path_utf8(p));
84
85 std::vector<uint8_t> bytes;
86 std::array<uint8_t, 64 * 1024> block;
87 while (const auto count = std::fread(block.data(), 1, block.size(), file.get()))
88 bytes.insert(bytes.end(), block.data(), block.data() + count);
89 if (std::ferror(file.get())) throw std::runtime_error("cannot read " + path_utf8(p));
90 return bytes;
83} 91}
84 92
85template <class T> 93template <class T>