Commit 966e0767 authored by ussrhero's avatar ussrhero

Vtbl

parent 274e95ec
This diff is collapsed.
......@@ -542,17 +542,6 @@ protected:
virtual void getVirtualDisplacement( const std::wstring& fieldName, MEMOFFSET_32 &virtualBasePtr, size_t &virtualDispIndex, size_t &virtualDispSize );
virtual void getVirtualDisplacement( size_t fieldIndex, MEMOFFSET_32 &virtualBasePtr, size_t &virtualDispIndex, size_t &virtualDispSize );
void getFields(
const SymbolPtr &rootSym,
const SymbolPtr &baseVirtualSym,
MEMOFFSET_32 startOffset = 0,
MEMOFFSET_32 virtualBasePtr = 0,
size_t virtualDispIndex = 0,
size_t m_virtualDispSize = 0 );
void getVirtualFields();
};
///////////////////////////////////////////////////////////////////////////////
......
......@@ -88,6 +88,11 @@ public:
return m_inheritedMember;
}
bool isVtbl() const
{
return m_vtblMember;
}
void setMemberInherited()
{
m_inheritedMember = true;
......@@ -130,7 +135,8 @@ protected:
m_virtualMember( false ),
m_methodMember(false),
m_constMember(false),
m_inheritedMember(false)
m_inheritedMember(false),
m_vtblMember(false)
{}
std::wstring m_name;
......@@ -150,6 +156,7 @@ protected:
bool m_methodMember;
bool m_constMember;
bool m_inheritedMember;
bool m_vtblMember;
};
///////////////////////////////////////////////////////////////////////////////////
......@@ -161,10 +168,18 @@ public:
static TypeFieldPtr getField(
const SymbolPtr &sym,
const std::wstring& name,
MEMOFFSET_32 offset )
MEMOFFSET_32 offset,
MEMOFFSET_32 virtualBasePtr,
size_t virtualDispIndex,
size_t virtualDispSize)
{
SymbolUdtField *p = new SymbolUdtField( sym, name );
p->m_offset = offset;
p->m_virtualBasePtr = virtualBasePtr;
p->m_virtualDispIndex = virtualDispIndex;
p->m_virtualDispSize = virtualDispSize;
p->m_virtualMember = virtualBasePtr != 0;
return TypeFieldPtr(p);
}
......@@ -188,23 +203,6 @@ public:
return TypeFieldPtr(p);
}
static TypeFieldPtr getVirtualField(
const SymbolPtr &sym,
const std::wstring& name,
MEMOFFSET_32 offset,
MEMOFFSET_32 virtualBasePtr,
size_t virtualDispIndex,
size_t virtualDispSize )
{
SymbolUdtField *p = new SymbolUdtField( sym, name );
p->m_offset = offset;
p->m_virtualBasePtr = virtualBasePtr;
p->m_virtualDispIndex = virtualDispIndex;
p->m_virtualDispSize = virtualDispSize;
p->m_virtualMember = true;
return TypeFieldPtr(p);
}
static TypeFieldPtr getVirtualMethodField(
const SymbolPtr& sym,
const std::wstring& name
......@@ -216,6 +214,24 @@ public:
return TypeFieldPtr(p);
}
static TypeFieldPtr getVtblField(
const SymbolPtr& sym,
const std::wstring& name,
MEMOFFSET_32 offset,
MEMOFFSET_32 virtualBasePtr,
size_t virtualDispIndex,
size_t virtualDispSize
)
{
SymbolUdtField *p = new SymbolUdtField(sym, name);
p->m_vtblMember = true;
p->m_offset = offset;
p->m_virtualBasePtr = virtualBasePtr;
p->m_virtualDispIndex = virtualDispIndex;
p->m_virtualDispSize = virtualDispSize;
p->m_virtualMember = virtualBasePtr != 0;
return TypeFieldPtr(p);
}
public:
......
......@@ -12,8 +12,8 @@ namespace kdlib {
const TypeFieldPtr& FieldCollection::lookup(const std::wstring &name) const
{
FieldList::const_reverse_iterator it;
for ( it = m_fields.rbegin(); it != m_fields.rend(); ++it )
FieldList::const_iterator it;
for (it = m_fields.begin(); it != m_fields.end(); ++it)
{
if ( (*it)->getName() == name )
return *it;
......
......@@ -303,16 +303,67 @@ TEST_F( TypedVarTest, FunctionDebugRange )
ASSERT_LE(std::ptrdiff_t(funcptr->getDebugEnd()), static_cast<std::ptrdiff_t>(std::ptrdiff_t(funcptr->getAddress()) + funcptr->getSize()));
}
TEST_F(TypedVarTest, getVTBL)
{
// vtbl#1:
// classProBase1::virtMethod1 ( int virtMethod1(float a)
// classChild::virtMethod1 ( inherited from classBase1 int virtMethod1(int a) )
// classBase1::virtMethod2
TypedVarPtr var;
ASSERT_NO_THROW(var = loadTypedVar(L"g_classChild"));
ASSERT_TRUE(var->getElement(0)->getType()->deref()->isVtbl());
TypedVarPtr vtbl = var->getElement(0)->deref();
EXPECT_NE(std::wstring::npos, findSymbol((MEMOFFSET_64)*vtbl->getElement(0)).find(L"classProBase1"));
EXPECT_NE(std::wstring::npos, findSymbol((MEMOFFSET_64)*vtbl->getElement(1)).find(L"virtMethod1"));
EXPECT_NE(std::wstring::npos, findSymbol((MEMOFFSET_64)*vtbl->getElement(2)).find(L"virtMethod2"));
EXPECT_THROW(vtbl->getElement(3), kdlib::IndexException);
}
TEST_F(TypedVarTest, getVTBLByName)
{
TypedVarPtr var;
ASSERT_NO_THROW(var = loadTypedVar(L"g_classChild"));
ASSERT_TRUE(var->getElement(L"__VFN_table")->getType()->deref()->isVtbl());
ASSERT_EQ(3, var->getElement(L"__VFN_table")->getType()->deref()->getElementCount());
}
TEST_F(TypedVarTest, getSecondVTBL)
{
// vtbl #2
// classChild::virtMethod3
// classChild::virtMethod4
TypedVarPtr var;
ASSERT_NO_THROW(var = loadTypedVar(L"g_classChild"));
TEST_F(TypedVarTest, DISABLED_getVTBL)
ASSERT_TRUE(var->getElement(2)->getType()->deref()->isVtbl());
TypedVarPtr vtbl = var->getElement(2)->deref();
EXPECT_NE(std::wstring::npos, findSymbol((MEMOFFSET_64)*vtbl->getElement(0)).find(L"virtMethod3"));
EXPECT_NE(std::wstring::npos, findSymbol((MEMOFFSET_64)*vtbl->getElement(1)).find(L"virtMethod4"));
EXPECT_THROW(vtbl->getElement(2), kdlib::IndexException);
}
TEST_F(TypedVarTest, getVirtualVTBL)
{
TypedVarPtr var;
ASSERT_NO_THROW(var = loadTypedVar(L"g_virtChild"));
auto s = var->str();
TypedVarPtr vtbl;
ASSERT_NO_THROW(vtbl = loadTypedVar(L"g_virtChild")->getElement(2)->deref());
ASSERT_NO_THROW(vtbl = loadTypedVar(L"g_virtChild")->getElement(4)->deref());
EXPECT_NE(std::wstring::npos, findSymbol((MEMOFFSET_64)*vtbl->getElement(0)).find(L"virtChildMethod"));
EXPECT_THROW(vtbl->getElement(1), kdlib::IndexException);
ASSERT_NO_THROW(vtbl = loadTypedVar(L"g_virtChild")->getElement(4)->deref());
ASSERT_NO_THROW(vtbl = loadTypedVar(L"g_virtChild")->getElement(2)->deref());
EXPECT_NE(std::wstring::npos, findSymbol((MEMOFFSET_64)*vtbl->getElement(0)).find(L"virtMethod1"));
EXPECT_NE(std::wstring::npos, findSymbol((MEMOFFSET_64)*vtbl->getElement(1)).find(L"virtMethod2"));
EXPECT_NE(std::wstring::npos, findSymbol((MEMOFFSET_64)*vtbl->getElement(1)).find(L"virtMethod1"));
EXPECT_NE(std::wstring::npos, findSymbol((MEMOFFSET_64)*vtbl->getElement(2)).find(L"virtMethod2"));
EXPECT_THROW(vtbl->getElement(3), kdlib::IndexException);
}
TEST_F(TypedVarTest, FunctionCall)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment