29 #ifndef COFFI_DIRECTORY_HPP
30 #define COFFI_DIRECTORY_HPP
40 #if defined(__has_include) && __has_include(<gsl/narrow>)
42 using gsl::narrow_cast;
45 #define narrow_cast static_cast
56 directory(uint32_t index) : data_{
nullptr}, index_{index} {}
65 COFFI_GET_SET_ACCESS(uint32_t, virtual_address);
66 COFFI_GET_SET_ACCESS(uint32_t, size);
71 uint32_t get_index()
const {
return index_; }
74 const char* get_data()
const {
return data_; }
77 void set_data(
const char* data, uint32_t size)
79 if ((index_ != DIRECTORY_CERTIFICATE_TABLE) &&
80 (index_ != DIRECTORY_BOUND_IMPORT)) {
90 char* temp_buffer =
new char[size];
95 std::copy(data, data + size, temp_buffer);
101 uint32_t get_data_filesize()
const
103 if ((index_ == DIRECTORY_CERTIFICATE_TABLE) ||
104 (index_ == DIRECTORY_BOUND_IMPORT)) {
111 bool load(std::istream& stream)
114 stream.read(
reinterpret_cast<char*
>(&header),
sizeof(header));
115 if (stream.gcount() !=
sizeof(header)) {
122 bool load_data(std::istream& stream)
124 if ((index_ != DIRECTORY_CERTIFICATE_TABLE) &&
125 (index_ != DIRECTORY_BOUND_IMPORT)) {
128 if ((get_size() > 0) && (get_virtual_address() != 0)) {
129 char* temp_buffer =
new char[get_size()];
130 stream.seekg(get_virtual_address());
131 stream.read(temp_buffer, get_size());
132 if (stream.gcount() !=
static_cast<int>(get_size())) {
141 void save(std::ostream& stream)
const
143 stream.write(
reinterpret_cast<const char*
>(&header),
sizeof(header));
146 void save_data(std::ostream& stream)
const
148 if ((index_ != DIRECTORY_CERTIFICATE_TABLE) &&
149 (index_ != DIRECTORY_BOUND_IMPORT)) {
152 if (data_ && get_size() > 0) {
153 stream.write(data_, get_size());
167 image_data_directory header{};
189 for (
auto d : *
this) {
196 bool load(std::istream& stream)
200 std::unique_ptr<directory> d = std::make_unique<directory>(i);
201 if (!d->load(stream)) {
204 push_back(d.release());
210 bool load_data(std::istream& stream)
212 for (
auto d : *
this) {
213 if (!d->load_data(stream)) {
221 void save(std::ostream& stream)
const
223 for (
auto d : *
this) {
229 uint32_t get_sizeof()
const
232 return narrow_cast<uint32_t>(size() * (*begin())->get_sizeof());
240 sections_provider* scn_;
List of image data directories.
directories(const directories &)=delete
Discards the copy constructor.
Class for accessing an image data directory.
directory(const directory &)=delete
Discards the copy constructor.
Interface that gives the headers and sections.
virtual const win_header * get_win_header() const =0
Returns the Windows NT header.
COFFI library classes for the COFF sections.