| 65 | } |
| 66 | |
| 67 | std::vector<std::uint8_t> read_file_bytes(const std::string& path) { |
| 68 | std::ifstream in(path, std::ios::binary | std::ios::ate); |
| 69 | if (!in) throw Error("cannot open target PE: " + path); |
| 70 | const auto sz = static_cast<std::size_t>(in.tellg()); |
| 71 | in.seekg(0); |
| 72 | std::vector<std::uint8_t> v(sz); |
| 73 | if (!in.read(reinterpret_cast<char*>(v.data()), static_cast<std::streamsize>(sz))) throw Error("read target PE failed: " + path); |
| 74 | return v; |
| 75 | } |
| 76 | |
| 77 | // view into the PE. all offsets are file offsets. |
| 78 | struct PeView { |