@@ -62,10 +62,30 @@ struct Pattern_t
6262 static constexpr std::size_t sm_nMaxSize = SIZE;
6363
6464 // Constructors.
65- constexpr Pattern_t (const Pattern_t<SIZE>& copyFrom) noexcept : m_nSize (copyFrom.m_nSize), m_aBytes(copyFrom.m_aBytes), m_aMask(copyFrom.m_aMask) { }
66- constexpr Pattern_t (Pattern_t<SIZE>&& moveFrom) noexcept : m_nSize (std::move(moveFrom.m_nSize)), m_aBytes(std::move(moveFrom.m_aBytes)), m_aMask(std::move(moveFrom.m_aMask)) { }
65+ constexpr Pattern_t (const Pattern_t<SIZE>& copyFrom) noexcept { CopyFrom (copyFrom); }
66+ constexpr Pattern_t (Pattern_t<SIZE>&& moveFrom) noexcept { MoveFrom (std::move (moveFrom)); }
6767 constexpr Pattern_t (std::size_t size = 0 , const std::array<uint8_t , SIZE>& bytes = {}, const std::array<char , SIZE>& mask = {}) noexcept : m_nSize(size), m_aBytes(bytes), m_aMask(mask) {} // Default one.
6868 constexpr Pattern_t (std::size_t &&size, std::array<uint8_t , SIZE>&& bytes, const std::array<char , SIZE>&& mask) noexcept : m_nSize(std::move(size)), m_aBytes(std::move(bytes)), m_aMask(std::move(mask)) {}
69+ Pattern_t& operator =(const Pattern_t<SIZE>& copyFrom) { return CopyFrom (); }
70+ Pattern_t& operator =(Pattern_t<SIZE>&& moveFrom) { return MoveFrom (std::move (moveFrom)); }
71+
72+ Pattern_t& CopyFrom (const Pattern_t<SIZE>& other)
73+ {
74+ m_nSize = other.m_nSize ;
75+ m_aBytes = other.m_aBytes ;
76+ m_aMask = other.m_aMask ;
77+
78+ return *this ;
79+ }
80+
81+ Pattern_t& MoveFrom (Pattern_t<SIZE>&& other)
82+ {
83+ m_nSize = other.m_nSize ;
84+ m_aBytes = std::move (other.m_aBytes );
85+ m_aMask = std::move (other.m_aMask );
86+
87+ return *this ;
88+ }
6989
7090 // Fields. Available to anyone (so structure).
7191 std::size_t m_nSize;
@@ -290,7 +310,7 @@ struct CCache
290310 CCache (
291311 const volatile std::uint8_t * pPatternMem,
292312 const size_t nSize,
293- const CMemory pStartAddress = nullptr ,
313+ const CMemory& pStartAddress = nullptr ,
294314 const Section_t* pModuleSection = nullptr
295315 )
296316 : m_svPattern(pPatternMem, pPatternMem + nSize)
@@ -321,13 +341,14 @@ struct CCache
321341
322342struct CHash
323343{
344+ static constexpr std::size_t m_nGoldenRatio = 0x9e3779b9u ;
345+
324346 std::size_t operator ()(const CCache& k) const noexcept
325347 {
326- static constexpr std::size_t golden_ratio = 0x9e3779b9u ;
327348 std::size_t h = std::hash<std::string>()(k.m_svPattern );
328- h ^= std::hash<uintptr_t >()(k.m_nStart ) + golden_ratio + (h << 6 ) + (h >> 2 );
329- h ^= std::hash<uintptr_t >()(k.m_pSectionAddr ) + golden_ratio + (h << 6 ) + (h >> 2 );
330- h ^= std::hash<size_t >()(k.m_nSectionSize ) + golden_ratio + (h << 6 ) + (h >> 2 );
349+ h ^= std::hash<uintptr_t >()(k.m_nStart ) + m_nGoldenRatio + (h << 6 ) + (h >> 2 );
350+ h ^= std::hash<uintptr_t >()(k.m_pSectionAddr ) + m_nGoldenRatio + (h << 6 ) + (h >> 2 );
351+ h ^= std::hash<size_t >()(k.m_nSectionSize ) + m_nGoldenRatio + (h << 6 ) + (h >> 2 );
331352 return h;
332353 }
333354};
@@ -359,24 +380,42 @@ class CAssemblyModule : public CMemory
359380
360381 public:
361382 constexpr CSignatureView () : m_pModule(nullptr ) {}
362- constexpr CSignatureView (CSignatureView&& moveFrom) : Base_t(std::move(moveFrom)), m_pModule(std::move(moveFrom.m_pModule)) {}
383+ constexpr CSignatureView (const CSignatureView& copyFrom) { CopyFrom (copyFrom); }
384+ constexpr CSignatureView (CSignatureView&& moveFrom) { MoveFrom (std::move (moveFrom)); }
363385 constexpr CSignatureView (const Base_t& pattern, CAssemblyModule* module ) : Base_t(pattern), m_pModule(module ) {}
364386 constexpr CSignatureView (Base_t&& pattern, CAssemblyModule* module ) : Base_t(std::move(pattern)), m_pModule(module ) {}
387+ CSignatureView& operator =(const CSignatureView& copyFrom) { return CopyFrom (copyFrom); }
388+ CSignatureView& operator =(CSignatureView&& moveFrom) { return MoveFrom (std::move (moveFrom)); }
389+
390+ CSignatureView& CopyFrom (const CSignatureView& other)
391+ {
392+ Base_t::CopyFrom (other);
393+ m_pModule = other.m_pModule ;
394+
395+ return *this ;
396+ }
397+ CSignatureView& MoveFrom (CSignatureView&& other)
398+ {
399+ Base_t::MoveFrom (std::move (other));
400+ m_pModule = std::exchange (other.m_pModule , nullptr );
401+
402+ return *this ;
403+ }
365404
366405 bool IsValid () const { return m_pModule && m_pModule->IsValid (); }
367406
368407 [[nodiscard]]
369- CMemory operator ()(const CMemory pStart = nullptr , const Section_t* pSection = nullptr ) const
408+ CMemory operator ()(const CMemory& pStart = nullptr , const Section_t* pSection = nullptr ) const
370409 {
371410 return Find (pStart, pSection);
372411 }
373412
374- [[nodiscard]] CMemory Find (const CMemory pStart, const Section_t* pSection = nullptr ) const
413+ [[nodiscard]] CMemory Find (const CMemory& pStart, const Section_t* pSection = nullptr ) const
375414 {
376415 return m_pModule->FindPattern <SIZE>(CMemory (Base_t::m_aBytes.data ()), std::string_view (Base_t::m_aMask.data (), Base_t::m_nSize), pStart, pSection);
377416 }
378417 [[nodiscard]] CMemory OffsetAndFind (const std::ptrdiff_t offset, CMemory pStart, const Section_t* pSection = nullptr ) const { return Find (pStart + offset, pSection); }
379- [[nodiscard]] CMemory OffsetFromSelfAndFind (const CMemory pStart, const Section_t* pSection = nullptr ) const { return OffsetAndFind (Base_t::m_nSize, pStart, pSection); }
418+ [[nodiscard]] CMemory OffsetFromSelfAndFind (const CMemory& pStart, const Section_t* pSection = nullptr ) const { return OffsetAndFind (Base_t::m_nSize, pStart, pSection); }
380419 [[nodiscard]] CMemory DerefAndFind (const std::uintptr_t deref, CMemory pStart, const Section_t* pSection = nullptr ) const { return Find (pStart.Deref (deref), pSection); }
381420 }; // class CSignatureView<SIZE>
382421
@@ -399,18 +438,30 @@ class CAssemblyModule : public CMemory
399438 ~CAssemblyModule ();
400439
401440 CAssemblyModule (const CAssemblyModule&) = delete ;
402- CAssemblyModule& operator =(const CAssemblyModule&) = delete ;
403- CAssemblyModule (CAssemblyModule&& other) noexcept : CMemory(std::exchange(static_cast <CMemory &>(other), DYNLIB_INVALID_MEMORY)), m_sPath(std::move(other.m_sPath)), m_vecSections(std::move(other.m_vecSections)), m_pExecutableSection(std::move(other.m_pExecutableSection)) {}
404- CAssemblyModule (const CMemory pModuleMemory);
441+ CAssemblyModule (CAssemblyModule&& moveFrom) noexcept { MoveFrom (std::move (moveFrom)); }
442+ CAssemblyModule (const CMemory& pModuleMemory);
405443 explicit CAssemblyModule (const std::string_view svModuleName);
406444 explicit CAssemblyModule (const char * pszModuleName) : CAssemblyModule(std::string_view(pszModuleName)) {}
407445 explicit CAssemblyModule (const std::string& sModuleName ) : CAssemblyModule(std::string_view(sModuleName )) {}
446+ CAssemblyModule &operator =(const CAssemblyModule&) = delete ;
447+ CAssemblyModule &operator =(CAssemblyModule&& moveFrom) { return MoveFrom (std::move (moveFrom)); }
448+
449+ CAssemblyModule &CopyFrom (const CAssemblyModule&) = delete;
450+ CAssemblyModule &MoveFrom (CAssemblyModule&& other)
451+ {
452+ *static_cast <CMemory *>(this ) = std::exchange (static_cast <CMemory &>(other), DYNLIB_INVALID_MEMORY);
453+ m_sPath = std::move (other.m_sPath );
454+ m_vecSections = std::move (other.m_vecSections );
455+ m_pExecutableSection = std::move (other.m_pExecutableSection );
456+
457+ return *this ;
458+ }
408459
409460 bool LoadFromPath (const std::string_view svModelePath, int flags);
410461 bool LoadFromPath (const std::string_view svModelePath);
411462
412463 bool InitFromName (const std::string_view svModuleName, bool bExtension = false );
413- bool InitFromMemory (const CMemory pModuleMemory, bool bForce = true );
464+ bool InitFromMemory (const CMemory& pModuleMemory, bool bForce = true );
414465
415466 template <std::size_t N>
416467 [[nodiscard]]
@@ -438,7 +489,7 @@ class CAssemblyModule : public CMemory
438489 // *pModuleSection
439490 // Output : CMemory
440491 // -----------------------------------------------------------------------------
441- CMemory FindPattern (const CMemoryView<std::uint8_t > pPatternMem, const std::string_view svMask, const CMemory pStartAddress, const Section_t* pModuleSection) const ;
492+ CMemory FindPattern (const CMemoryView<std::uint8_t >& pPatternMem, const std::string_view svMask, const CMemory& pStartAddress, const Section_t* pModuleSection) const ;
442493
443494 template <std::size_t SIZE>
444495 [[nodiscard]]
0 commit comments