Skip to content

Commit d81ef7b

Browse files
committed
Correct Deref methods
1 parent a0b659e commit d81ef7b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

include/dynlibutils/memaddr.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,24 @@ class CMemory
148148
{
149149
std::uintptr_t base = m_addr;
150150

151-
while (base && deref--)
151+
while (deref)
152152
{
153153
base = *reinterpret_cast<std::uintptr_t*>(base + offset);
154+
deref--;
154155
}
155156

156157
return base;
157158
}
158-
CMemory& DerefSelf(int deref = 1, std::ptrdiff_t offset = 0) noexcept { while (m_addr && deref--) m_addr = *reinterpret_cast<std::uintptr_t*>(m_addr + offset); return *this; }
159+
CMemory& DerefSelf(int deref = 1, std::ptrdiff_t offset = 0) noexcept
160+
{
161+
while (deref)
162+
{
163+
m_addr = *reinterpret_cast<std::uintptr_t*>(m_addr + offset);
164+
deref--;
165+
}
166+
167+
return *this;
168+
}
159169

160170
CMemory FollowNearCall(const std::ptrdiff_t opcodeOffset = 0x1, const std::ptrdiff_t nextInstructionOffset = 0x5) const noexcept { return ResolveRelativeAddress(opcodeOffset, nextInstructionOffset); }
161171
CMemory& FollowNearCallSelf(const std::ptrdiff_t opcodeOffset = 0x1, const std::ptrdiff_t nextInstructionOffset = 0x5) noexcept { return ResolveRelativeAddressSelf(opcodeOffset, nextInstructionOffset); }

0 commit comments

Comments
 (0)