Skip to content

Commit

Permalink
RTTI: Parse Type Descriptors (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dax89 committed Dec 21, 2020
1 parent 9b7bb91 commit 3a1ab8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions compiler/msvc/rtti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#define MSVC_CLASS_PREFIX_LENGTH 4

#define RTTICOMPLETEOBJECTLOCATOR_NAME "RTTICompleteObjectLocator"
#define RTTITYPEDESCRIPTOR_NAME "RTTITypeDescriptor"
#define DB_RTTICOMPLOBJLOCATOR_Q (std::string("/msvcrtti/") + RTTICOMPLETEOBJECTLOCATOR_NAME).c_str()
#define DB_RTTITYPEDESCR_Q (std::string("/msvcrtti/") + RTTITYPEDESCRIPTOR_NAME).c_str()

MSVCRTTI::MSVCRTTI(RDContext* ctx): m_context(ctx)
{
Expand All @@ -18,6 +20,17 @@ MSVCRTTI::MSVCRTTI(RDContext* ctx): m_context(ctx)
void MSVCRTTI::search()
{
this->findCompleteObjLocators();

for(const RTTICompleteObjectLocator* col : m_completeobjs)
{
auto loc = RD_AddressOf(m_loader, col);
if(!loc.valid) continue;

RDDocument_AddTypeName(m_document, loc.address, DB_RTTICOMPLOBJLOCATOR_Q);

if(RD_IsAddress(m_loader, col->pTypeDescriptor))
RDDocument_AddTypeName(m_document, col->pTypeDescriptor, DB_RTTITYPEDESCR_Q);
}
}

void MSVCRTTI::registerTypes()
Expand All @@ -30,8 +43,13 @@ void MSVCRTTI::registerTypes()
RDStructure_Append(cobjloc.get(), RDType_CreateInt(4, false), "cdOffset");
RDStructure_Append(cobjloc.get(), RDType_CreateInt(4, false), "pTypeDescriptor");
RDStructure_Append(cobjloc.get(), RDType_CreateInt(4, false), "pClassHierarchyDescriptor");

RDDatabase_WriteType(db, DB_RTTICOMPLOBJLOCATOR_Q, cobjloc.get());

rd_ptr<RDType> typedescr(RDType_CreateStructure(RTTITYPEDESCRIPTOR_NAME));
RDStructure_Append(typedescr.get(), RDType_CreateInt(4, false), "pVFTable");
RDStructure_Append(typedescr.get(), RDType_CreateInt(4, false), "spare");
//RDStructure_Append(cobjloc.get(), RDType_CreateString(), "name");
RDDatabase_WriteType(db, DB_RTTITYPEDESCR_Q, typedescr.get());
}

void MSVCRTTI::findCompleteObjLocators()
Expand Down Expand Up @@ -67,10 +85,6 @@ void MSVCRTTI::findCompleteObjLocators(const RDSegment* segment)
const char* pname = reinterpret_cast<const char*>(&ptypedesc->name);
if(!pname || std::strncmp(pname, MSVC_CLASS_PREFIX, MSVC_CLASS_PREFIX_LENGTH)) continue;
thethis->m_completeobjs.push_back(pobjloc);

auto loc = RD_AddressOf(thethis->m_loader, pobjloc);
rd_log(rd_tohex(loc.address));
RDDocument_AddTypeName(thethis->m_document, loc.address, DB_RTTICOMPLOBJLOCATOR_Q);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion compiler/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ void rdplugin_init(RDContext*, RDPluginModule* pm)
{
RD_PLUGIN_ENTRY(RDEntryAnalyzer, msvcanalyzer, "MSVC C++ ABI Analyzer");
msvcanalyzer.description = "Analyze C++ ABI and RTTI";
msvcanalyzer.flags = AnalyzerFlags_Experimental /*| AnalyzerFlags_Selected */ | AnalyzerFlags_RunOnce;
msvcanalyzer.flags = AnalyzerFlags_Experimental | AnalyzerFlags_Selected | AnalyzerFlags_RunOnce;
msvcanalyzer.order = 2000;
msvcanalyzer.isenabled = &MSVCCompiler::isEnabled;
msvcanalyzer.execute = &MSVCCompiler::execute;
Expand Down

0 comments on commit 3a1ab8c

Please sign in to comment.