Skip to content

Commit

Permalink
Update Rich headers variables
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Dec 11, 2024
1 parent d4fa8d1 commit 738f60b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
4 changes: 3 additions & 1 deletion api/python/lief/dsc/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class DyldSharedCache:

DYLD_1042_1 = 8

UNRELEASED = 9
DYLD_1231_3 = 9

UNRELEASED = 10

class PLATFORM(enum.Enum):
UNKNOWN = 0
Expand Down
5 changes: 4 additions & 1 deletion include/LIEF/PE/RichHeader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ namespace PE {
/// or remove this information.
class LIEF_API RichHeader : public Object {
public:

using entries_t = std::vector<RichEntry>;
using it_entries = ref_iterator<entries_t&>;
using it_const_entries = const_ref_iterator<const entries_t&>;

static constexpr uint8_t RICH_MAGIC[] = {'R', 'i', 'c', 'h'};
static constexpr uint32_t RICH_MAGIC_INT = 0x68636952; // 'Rich'
static constexpr uint32_t DANS_MAGIC_NUMBER = 0x536E6144; // 'Rich'

RichHeader() = default;
RichHeader(const RichHeader&) = default;
RichHeader& operator=(const RichHeader&) = default;
Expand Down
1 change: 0 additions & 1 deletion include/LIEF/iostream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class vector_iostream {
return *this;
}


template<typename T>
vector_iostream& write(const std::vector<T>& elements) {
for (const T& e : elements) {
Expand Down
7 changes: 2 additions & 5 deletions src/PE/RichHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#define LIEF_PE_FORCE_UNDEF
#include "LIEF/PE/undef.h"

#include "PE/Structures.hpp"
#include "hash_stream.hpp"

namespace LIEF {
Expand All @@ -37,11 +36,10 @@ void RichHeader::accept(LIEF::Visitor& visitor) const {
}

std::vector<uint8_t> RichHeader::raw(uint32_t xor_key) const {
static constexpr uint32_t RICH_MAGIC = 0x68636952;
vector_iostream wstream;

wstream
.write(details::DanS_Magic_number ^ xor_key)
.write(DANS_MAGIC_NUMBER ^ xor_key)
/*
* The first chunk needs to be aligned on 64-bit and padded
* with 0-xor. We can't use vector_iostream::align as it would not
Expand All @@ -57,9 +55,8 @@ std::vector<uint8_t> RichHeader::raw(uint32_t xor_key) const {
wstream
.write(value ^ xor_key).write(entry.count() ^ xor_key);
}

wstream
.write(RICH_MAGIC).write(xor_key);
.write(RICH_MAGIC, std::size(RICH_MAGIC)).write(xor_key);

return wstream.raw();
}
Expand Down

0 comments on commit 738f60b

Please sign in to comment.