Added image_descriptor::get_entry_point().

This commit is contained in:
Can Bölük 2020-08-29 06:08:45 +02:00
parent 29f9c1c872
commit d8c906ba1d
3 changed files with 17 additions and 0 deletions

View file

@ -177,6 +177,10 @@ namespace vtil
//
virtual uint64_t get_image_base() const = 0;
// Returns the entry point if relevant.
//
virtual std::optional<uint64_t> get_entry_point() const = 0;
// Returns the image size and the raw byte array.
//
virtual size_t get_image_size() const = 0;

View file

@ -626,6 +626,18 @@ namespace vtil
return dos_header->get_nt_headers<false>()->optional_header.image_base;
}
std::optional<uint64_t> pe_image::get_entry_point() const
{
// Get the entry point from optional header, return nullopt if zero.
//
auto dos_header = ( const dos_header_t* ) cdata();
uint64_t ep = is_pe64()
? dos_header->get_nt_headers<true>()->optional_header.entry_point
: dos_header->get_nt_headers<false>()->optional_header.entry_point;
if ( ep ) return ep;
return std::nullopt;
}
bool pe_image::is_valid() const
{
// Get image boundaries and the dos header.

View file

@ -56,6 +56,7 @@ namespace vtil
virtual void add_section( section_descriptor& in_out, const void* data, size_t size ) override;
virtual void enum_relocations( const function_view<bool( const relocation_descriptor& )>& fn ) const override;
virtual uint64_t get_image_base() const override;
virtual std::optional<uint64_t> get_entry_point() const override;
virtual size_t get_image_size() const override { return raw_bytes.size(); }
virtual void* data() override { return raw_bytes.data(); }
virtual const void* cdata() const override { return raw_bytes.data(); }