16#ifndef LIEF_PE_PARSER_H
17#define LIEF_PE_PARSER_H
91 static std::unique_ptr<Binary>
92 parse(
const std::string& filename,
96 static std::unique_ptr<Binary>
97 parse(std::vector<uint8_t> data,
100 static std::unique_ptr<Binary>
101 parse(
const uint8_t* buffer,
size_t size,
105 static std::unique_ptr<Binary>
110 static std::unique_ptr<Binary>
115 static std::unique_ptr<Binary>
128 static std::unique_ptr<Binary>
134 static std::unique_ptr<Binary>
140 static std::unique_ptr<Binary>
150 auto it = memoize_exception_info_.find(rva);
151 return it == memoize_exception_info_.end() ? nullptr : it->second;
174 unresolved_chains_.emplace_back(&info, target);
183 struct relocation_t {
187 Parser(
const std::string& file);
188 Parser(std::vector<uint8_t> data);
189 Parser(std::unique_ptr<BinaryStream> stream);
196 template<
typename PE_T>
202 ok_error_t read_section_content(
const details::pe_section& raw_sec,
203 uint32_t index,
Section& section);
205 template<
typename PE_T>
210 template<
typename PE_T>
213 template<
typename PE_T>
216 template<
typename PE_T>
219 template<
typename PE_T>
221 uint32_t iat_offset);
228 std::unique_ptr<Debug> parse_code_view(
const details::pe_debug& debug_info,
230 std::unique_ptr<Debug> parse_pogo(
const details::pe_debug& debug_info,
232 std::unique_ptr<Debug> parse_repro(
const details::pe_debug& debug_info,
235 template<
typename PE_T>
238 template<
typename PE_T>
241 template<
typename PE_T>
244 template<
typename PE_T>
257 template<
typename PE_T>
260 template<
typename PE_T>
263 template<
typename PE_T>
266 template<
typename PE_T>
270 std::unique_ptr<Binary> binary_;
271 std::unique_ptr<BinaryStream> stream_;
272 std::map<uint32_t, size_t> memoize_coff_str_;
273 std::map<uint32_t, ExceptionInfo*> memoize_exception_info_;
274 std::map<uint32_t, relocation_t> dyn_hdr_relocs_;
275 std::vector<std::pair<ExceptionInfo*, uint32_t>> unresolved_chains_;
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:35
This class represents a string located in the COFF string table.
Definition String.hpp:34
Class which represents a PE binary This is the main interface to manage and modify a PE executable.
Definition PE/Binary.hpp:57
This class represents a generic entry in the debug data directory. For known types,...
Definition debug/Debug.hpp:40
Class that represents a PE delayed import.
Definition DelayImport.hpp:37
This class is the base class for any exception or runtime function entry.
Definition ExceptionInfo.hpp:33
This class represents the load configuration data associated with the IMAGE_LOAD_CONFIG_DIRECTORY.
Definition LoadConfiguration.hpp:47
Main interface to parse PE binaries. In particular, the static Parser::parse functions should be used...
Definition PE/Parser.hpp:53
static std::unique_ptr< Binary > parse_from_dump(BinaryStream &stream, uint64_t addr, const ParserConfig &config=ParserConfig::default_conf())
Same as parse_from_dump(const std::string&, uint64_t, const ParserConfig&) but the dump is wrapped in...
static std::unique_ptr< Binary > parse_from_dump(const std::string &filepath, uint64_t addr, const ParserConfig &config=ParserConfig::default_conf())
Parse a PE binary from a memory dump located on disk.
static constexpr size_t MAX_IMPORT_ENTRIES
Definition PE/Parser.hpp:61
static constexpr size_t MAX_DLL_NAME_SIZE
Definition PE/Parser.hpp:68
static bool is_valid_import_name(const std::string &name)
Check if the given name is a valid import.
static constexpr size_t MAX_IMPORT_NAME_SIZE
Definition PE/Parser.hpp:65
static bool is_valid_dll_name(const std::string &name)
Check if the given name is a valid DLL name.
static std::unique_ptr< Binary > parse_from_memory(uintptr_t address, const ParserConfig &config=ParserConfig::default_conf())
Parse the PE binary at the given memory address.
void memoize(ExceptionInfo &info)
static std::unique_ptr< Binary > parse(std::unique_ptr< BinaryStream > stream, const ParserConfig &conf=ParserConfig::default_conf())
Parse a PE binary from the given BinaryStream.
Binary & bin()
Definition PE/Parser.hpp:158
const Binary & bin() const
Definition PE/Parser.hpp:154
static std::unique_ptr< Binary > parse(const uint8_t *buffer, size_t size, const ParserConfig &conf=ParserConfig::default_conf())
COFF::String * find_coff_string(uint32_t offset) const
ExceptionInfo * find_exception_info(uint32_t rva) const
Definition PE/Parser.hpp:149
static std::unique_ptr< Binary > parse(const std::string &filename, const ParserConfig &conf=ParserConfig::default_conf())
Parse a PE binary from the given filename.
std::unique_ptr< SpanStream > stream_from_rva(uint32_t rva, size_t size=0)
Parser(const Parser ©)=delete
void memoize(COFF::String str)
BinaryStream & stream()
Definition PE/Parser.hpp:162
void record_relocation(uint32_t rva, span< const uint8_t > data)
static constexpr size_t MAX_DATA_SIZE
Maximum size of the data read.
Definition PE/Parser.hpp:56
static std::unique_ptr< Binary > parse_from_dump(std::unique_ptr< BinaryStream > stream, uint64_t addr, const ParserConfig &config=ParserConfig::default_conf())
Same as parse_from_dump(const std::string&, uint64_t, const ParserConfig&) but the dump is wrapped in...
const ParserConfig & config() const
Definition PE/Parser.hpp:166
static std::unique_ptr< Binary > parse_from_memory(uintptr_t address, size_t size, const ParserConfig &config=ParserConfig::default_conf())
Parse the PE binary at the given memory address and with the given size.
void add_non_resolved(ExceptionInfo &info, uint32_t target)
Definition PE/Parser.hpp:173
static constexpr size_t MAX_PADDING_SIZE
Max size of the padding section.
Definition PE/Parser.hpp:71
Parser & operator=(const Parser ©)=delete
static std::unique_ptr< Binary > parse(std::vector< uint8_t > data, const ParserConfig &conf=ParserConfig::default_conf())
Parse a PE binary from a data buffer.
ok_error_t record_delta_relocation(uint32_t rva, int64_t delta, size_t size)
static constexpr size_t MAX_TLS_CALLBACKS
Definition PE/Parser.hpp:58
Class which represents an entry of the PE relocation table.
Definition RelocationEntry.hpp:37
Class which represents a Node in the resource tree.
Definition ResourceNode.hpp:46
Class which represents a PE section.
Definition PE/Section.hpp:47
Main interface to parse an executable regardless of its format.
Definition Abstract/Parser.hpp:31
Definition SpanStream.hpp:32
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:119
Definition DataDirectory.hpp:37
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
PE_TYPE
Definition PE/enums.hpp:22
@ PE32_PLUS
64 bits
Definition PE/enums.hpp:24
LIEF namespace.
Definition Abstract/Binary.hpp:41
tcb::span< ElementType, Extent > span
Definition span.hpp:22
This structure is used to configure the behavior of the PE Parser (PE::Parser).
Definition PE/ParserConfig.hpp:27
static const ParserConfig & default_conf()
Returns the default configuration for the PE Parser.
Definition PE/ParserConfig.hpp:29
#define LIEF_API
Definition visibility.h:45