Projects STRLCPY LIEF Commits b9b0adf6
🤬
  • ■ ■ ■ ■ ■ ■
    api/python/lief/PE.pyi
    skipped 430 lines
    431 431   @property
    432 432   def authentihash_sha512(self) -> bytes: ...
    433 433   @property
     434 + def codeview_pdb(self) -> lief.PE.CodeViewPDB: ...
     435 + @property
    434 436   def data_directories(self) -> lief.PE.Binary.it_data_directories: ...
    435 437   @property
    436 438   def debug(self) -> lief.PE.Binary.it_debug: ...
    skipped 265 lines
    702 704   filename: str
    703 705   signature: list[int]
    704 706   def __init__(self) -> None: ...
     707 + @property
     708 + def guid(self) -> str: ...
    705 709   @property
    706 710   def parent(self) -> lief.PE.CodeView: ...
    707 711   
    skipped 2197 lines
  • ■ ■ ■ ■ ■ ■
    api/python/src/PE/objects/debug/pyCodeViewPDB.cpp
    skipped 43 lines
    44 44   "parent(self) -> lief.PE.CodeView"_p,
    45 45   nb::rv_policy::reference_internal)
    46 46   
     47 + .def_prop_ro("guid", &CodeViewPDB::guid)
     48 + 
    47 49   .def_prop_rw("signature",
    48 50   nb::overload_cast<>(&CodeViewPDB::signature, nb::const_),
    49 51   nb::overload_cast<const CodeViewPDB::signature_t&>(&CodeViewPDB::signature))
    skipped 15 lines
  • ■ ■ ■ ■ ■
    api/python/src/PE/objects/pyBinary.cpp
    skipped 262 lines
    263 263   "Return the " RST_CLASS_REF(lief.PE.Debug) ""_doc,
    264 264   nb::rv_policy::reference_internal)
    265 265   
     266 + .def_prop_ro("codeview_pdb",
     267 + nb::overload_cast<>(&Binary::codeview_pdb, nb::const_),
     268 + "Return the :class:`~.CodeViewPDB` if present"_doc,
     269 + nb::rv_policy::reference_internal)
     270 + 
    266 271   .def_prop_ro("load_configuration",
    267 272   nb::overload_cast<>(&Binary::load_configuration),
    268 273   "Return the " RST_CLASS_REF(lief.PE.LoadConfiguration) " object or None if not present"_doc,
    skipped 148 lines
  • ■ ■ ■ ■ ■ ■
    doc/sphinx/changelog.rst
    skipped 37 lines
    38 38   * Add support for Android packed relocation format (``DT_ANDROID_REL{A}``)
    39 39   * Add support for relative relocation format (``DT_RELR``)
    40 40   
     41 +:PE:
     42 + 
     43 + * Add :attr:`lief.PE.CodeViewPDB.guid` attribute (:issue:`480`)
     44 + 
    41 45  :CMake:
    42 46   
    43 47   * ``LIEFConfig.cmake`` is now installed in ``<prefix>/lib/cmake/LIEF/``
    skipped 1375 lines
  • ■ ■ ■ ■ ■
    include/LIEF/BinaryStream/SpanStream.hpp
    skipped 28 lines
    29 29   using BinaryStream::end;
    30 30   using BinaryStream::start;
    31 31   
    32  - static result<SpanStream> from_vector(const std::vector<uint8_t>& data);
     32 + static result<SpanStream> from_vector(const std::vector<uint8_t>& data) {
     33 + return SpanStream(data);
     34 + }
     35 + 
     36 + template<size_t N>
     37 + static result<SpanStream> from_array(const std::array<uint8_t, N>& data) {
     38 + return SpanStream(data.data(), N);
     39 + }
     40 + 
    33 41   SpanStream(span<const uint8_t> data);
    34 42   SpanStream(span<uint8_t> data);
    35 43   
    skipped 47 lines
  • ■ ■ ■ ■ ■ ■
    include/LIEF/PE/Binary.hpp
    skipped 35 lines
    36 36   
    37 37  //! Namespace related to the LIEF's PE module
    38 38  namespace PE {
     39 +class Builder;
     40 +class CodeViewPDB;
    39 41  class Debug;
     42 +class Export;
     43 +class LoadConfiguration;
    40 44  class Parser;
    41  -class Builder;
    42  -class ResourceNode;
     45 +class Relocation;
    43 46  class ResourceData;
    44 47  class ResourceDirectory;
    45  -class LoadConfiguration;
    46  -class Relocation;
    47  -class TLS;
    48  -class Export;
     48 +class ResourceNode;
    49 49  class RichHeader;
     50 +class TLS;
    50 51   
    51 52  //! Class which represents a PE binary
    52 53  //! This is the main interface to manage and modify a PE executable
    skipped 387 lines
    440 441   it_const_debug_entries debug() const {
    441 442   return debug_;
    442 443   }
     444 + 
     445 + //! Return the CodeViewPDB object if present
     446 + const CodeViewPDB* codeview_pdb() const;
    443 447   
    444 448   //! Retrun the LoadConfiguration object or a nullptr
    445 449   //! if the binary does not use the LoadConfiguration
    skipped 249 lines
  • ■ ■ ■ ■ ■ ■
    include/LIEF/PE/debug/CodeViewPDB.hpp
    skipped 42 lines
    43 43   CodeViewPDB(const CodeViewPDB& other);
    44 44   CodeViewPDB& operator=(const CodeViewPDB& other);
    45 45   
     46 + std::string guid() const;
     47 + 
    46 48   uint32_t age() const {
    47 49   return age_;
    48 50   }
    skipped 50 lines
  • ■ ■ ■ ■ ■ ■
    src/BinaryStream/SpanStream.cpp
    skipped 37 lines
    38 38   stype_ = STREAM_TYPE::SPAN;
    39 39  }
    40 40   
    41  -result<SpanStream> SpanStream::from_vector(const std::vector<uint8_t>& data) {
    42  - return SpanStream{data};
    43  -}
    44  - 
    45 41  result<const void*> SpanStream::read_at(uint64_t offset, uint64_t size) const {
    46 42   const uint64_t stream_size = this->size();
    47 43   if (offset > stream_size || (offset + size) > stream_size) {
    skipped 35 lines
  • ■ ■ ■ ■ ■ ■
    src/PE/Binary.cpp
    skipped 1358 lines
    1359 1359   return &*it_import;
    1360 1360  }
    1361 1361   
     1362 +const CodeViewPDB* Binary::codeview_pdb() const {
     1363 + if (debug_.empty()) {
     1364 + return nullptr;
     1365 + }
     1366 + 
     1367 + const auto it = std::find_if(debug_.begin(), debug_.end(),
     1368 + [] (const std::unique_ptr<Debug>& debug) {
     1369 + return CodeViewPDB::classof(debug.get());
     1370 + }
     1371 + );
     1372 + if (it == debug_.end()) {
     1373 + return nullptr;
     1374 + }
     1375 + 
     1376 + return static_cast<const CodeViewPDB*>(it->get());
     1377 +}
     1378 + 
    1362 1379  void Binary::accept(Visitor& visitor) const {
    1363 1380   visitor.visit(*this);
    1364 1381  }
    skipped 150 lines
  • ■ ■ ■ ■ ■ ■
    src/PE/debug/CodeViewPDB.cpp
    skipped 14 lines
    15 15   */
    16 16  #include "LIEF/PE/debug/CodeViewPDB.hpp"
    17 17  #include "LIEF/Visitor.hpp"
     18 +#include "LIEF/BinaryStream/SpanStream.hpp"
    18 19   
    19 20  #include "spdlog/fmt/fmt.h"
    20 21  #include "spdlog/fmt/ranges.h"
    skipped 22 lines
    43 44   visitor.visit(*this);
    44 45  }
    45 46   
     47 +std::string CodeViewPDB::guid() const {
     48 + auto stream = SpanStream::from_array(signature_);
     49 + if (!stream) {
     50 + return "";
     51 + }
     52 + stream->set_endian_swap(true);
     53 + return fmt::format("{:08x}-{:04x}-{:04x}-{:04x}-{:04x}{:08x}",
     54 + stream->read<uint32_t>().value_or(0),
     55 + stream->read<uint16_t>().value_or(0),
     56 + stream->read<uint16_t>().value_or(0),
     57 + stream->read_conv<uint16_t>().value_or(0),
     58 + stream->read_conv<uint16_t>().value_or(0),
     59 + stream->read_conv<uint32_t>().value_or(0)
     60 + );
     61 +}
     62 + 
    46 63  std::ostream& operator<<(std::ostream& os, const CodeViewPDB& entry) {
    47 64   os << static_cast<const CodeView&>(entry) << '\n'
    48 65   << fmt::format("[CV][PDB] age: {}\n", entry.age())
    49 66   << fmt::format("[CV][PDB] signature: {}\n", entry.signature())
     67 + << fmt::format("[CV][PDB] GUID: {}\n", entry.guid())
    50 68   << fmt::format("[CV][PDB] filename: {}\n", entry.filename())
    51 69   ;
    52 70   return os;
    skipped 5 lines
  • ■ ■ ■ ■ ■ ■
    tests/pe/test_debug.py
    skipped 44 lines
    45 45   assert entries[0].copy() == entries[0]
    46 46   assert entries[1].copy() != entries[-2]
    47 47   
     48 +def test_guid():
     49 + path = get_sample('PE/ntoskrnl.exe')
     50 + sample = lief.PE.parse(path)
     51 + cv: lief.PE.CodeViewPDB = sample.codeview_pdb
     52 + assert cv is not None
     53 + assert cv.guid == "fcb9afc6-a352-f97b-17cf-5f981382c782"
     54 + 
     55 + path = get_sample('PE/PE64_x86-64_binary_ConsoleApplication1.exe')
     56 + sample = lief.PE.parse(path)
     57 + cv: lief.PE.CodeViewPDB = sample.codeview_pdb
     58 + assert cv is not None
     59 + assert cv.guid == "b6e3d9f5-7147-4f01-a203-aa477c4aba54"
    48 60   
    49 61  def test_code_view_pdb():
    50 62   path = get_sample('PE/PE64_x86-64_binary_ConsoleApplication1.exe')
    skipped 79 lines
Please wait...
Page is in error, reload to recover