DBG: Prototype RemotePtr class
This commit is contained in:
parent
391a90862a
commit
423e320f0f
|
@ -0,0 +1,95 @@
|
|||
#pragma once
|
||||
|
||||
#include "memory.h"
|
||||
|
||||
template<typename T, bool ReadOnly = false>
|
||||
class RemotePtr
|
||||
{
|
||||
public:
|
||||
explicit RemotePtr(uint Address)
|
||||
{
|
||||
Init(Address);
|
||||
|
||||
}
|
||||
|
||||
explicit RemotePtr(PVOID Address)
|
||||
{
|
||||
Init((uint)Address);
|
||||
}
|
||||
|
||||
~RemotePtr()
|
||||
{
|
||||
if(m_Modified)
|
||||
Sync();
|
||||
}
|
||||
|
||||
T get()
|
||||
{
|
||||
// Read the external program data; no user edits
|
||||
Update();
|
||||
return m_InternalData;
|
||||
}
|
||||
|
||||
size_t size()
|
||||
{
|
||||
return sizeof(T);
|
||||
}
|
||||
|
||||
T* operator->()
|
||||
{
|
||||
// The user could modify our internal structure after
|
||||
// return
|
||||
m_Modified = true;
|
||||
|
||||
// Read the external program data
|
||||
Update();
|
||||
return &m_InternalData;
|
||||
}
|
||||
|
||||
T operator=(const T & rhs)
|
||||
{
|
||||
// This operation is only allowed with ReadOnly==false
|
||||
if(!ReadOnly)
|
||||
{
|
||||
// Otherwise sync it with the external program and read it again.
|
||||
// The external program can be messing with data at the same time.
|
||||
m_InternalData = rhs;
|
||||
Sync();
|
||||
Update();
|
||||
return m_InternalData;
|
||||
}
|
||||
|
||||
__debugbreak();
|
||||
return rhs;
|
||||
}
|
||||
|
||||
T operator()()
|
||||
{
|
||||
return get();
|
||||
}
|
||||
|
||||
private:
|
||||
inline void Update()
|
||||
{
|
||||
MemRead(m_InternalAddr, &m_InternalData, sizeof(T));
|
||||
}
|
||||
|
||||
inline void Sync()
|
||||
{
|
||||
if(!ReadOnly)
|
||||
MemWrite(m_InternalAddr, &m_InternalData, sizeof(T));
|
||||
|
||||
m_Modified = false;
|
||||
}
|
||||
|
||||
inline void Init(uint Address)
|
||||
{
|
||||
m_Modified = false;
|
||||
m_InternalAddr = Address;
|
||||
memset(&m_InternalData, 0, sizeof(T));
|
||||
}
|
||||
|
||||
bool m_Modified;
|
||||
uint m_InternalAddr;
|
||||
T m_InternalData;
|
||||
};
|
|
@ -118,6 +118,7 @@
|
|||
<ClInclude Include="disasm_fast.h" />
|
||||
<ClInclude Include="disasm_helper.h" />
|
||||
<ClInclude Include="dynamicmem.h" />
|
||||
<ClInclude Include="dynamicptr.h" />
|
||||
<ClInclude Include="error.h" />
|
||||
<ClInclude Include="exception.h" />
|
||||
<ClInclude Include="exceptiondirectoryanalysis.h" />
|
||||
|
|
|
@ -638,5 +638,8 @@
|
|||
<ClInclude Include="linearanalysis.h">
|
||||
<Filter>Header Files\Analysis</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="dynamicptr.h">
|
||||
<Filter>Header Files\Utilities</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue