diff --git a/binaryninja-api b/binaryninja-api index 050e9a9..3007496 160000 --- a/binaryninja-api +++ b/binaryninja-api @@ -1 +1 @@ -Subproject commit 050e9a9888f12c42da6e64786ab9428ee98a5fe5 +Subproject commit 3007496dbbc0613373ac1160a1f3d85c88d6fe92 diff --git a/src/plugin.cpp b/src/plugin.cpp index ac68865..951de57 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -249,6 +249,46 @@ void GenerateConstructorGraphViz(BinaryView* view) view->ShowPlainTextReport("MSVC Constructor GraphViz DOT", out.str()); } +void MakeComponents(BinaryView* view) +{ + auto classesComp = view->CreateComponentWithName("MSVC Classes"); + for (auto coLocatorTag : view->GetAllTagReferencesOfType(GetCOLocatorTagType(view))) + { + auto coLocator = CompleteObjectLocator(view, coLocatorTag.addr); + + auto className = coLocator.GetClassName(); + if (coLocator.IsSubObject()) + { + className = className + " (" + coLocator.GetAssociatedClassName() + ")"; + } + + auto classComp = view->CreateComponentWithName(className, classesComp->GetGuid()); + + DataVariable coLocatorVar = {}; + if (view->GetDataVariableAtAddress(coLocator.m_address, coLocatorVar)) + { + classComp->AddDataVariable(coLocatorVar); + } + + if (auto vtable = coLocator.GetVirtualFunctionTable()) + { + DataVariable vtableVar = {}; + if (view->GetDataVariableAtAddress(coLocator.GetVirtualFunctionTable()->m_address, vtableVar)) + { + classComp->AddDataVariable(vtableVar); + } + + for (auto vFunc : vtable->GetVirtualFunctions()) + { + if (coLocator.GetClassHierarchyDescriptor().m_numBaseClassesValue <= 1 || vFunc.IsUnique()) + { + classComp->AddFunction(vFunc.m_func); + } + } + } + } +} + extern "C" { BN_DECLARE_CORE_ABI_VERSION @@ -260,6 +300,8 @@ extern "C" PluginCommand::Register("MSVC\\Find Class Fields", "Scans for all class fields in view.", &ScanClassFieldsView); PluginCommand::Register("MSVC\\Generate Constructors Graphviz", "Makes a graph from all the available MSVC constructors.", &GenerateConstructorGraphViz); + PluginCommand::Register("MSVC\\Make Class Components", + "Adds relevant data variables and functions to class components.", &MakeComponents); return true; }