Skip to content

Commit

Permalink
added typeinfo hack
Browse files Browse the repository at this point in the history
now vs 2019 and 2013 and older is compatible by this component
  • Loading branch information
glensand committed Jul 29, 2021
1 parent 587d648 commit a842f85
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 0 deletions.
48 changes: 48 additions & 0 deletions TypeInfoHack/Hack.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

#include "Hack.h"

#pragma warning(push)
#pragma warning(disable: 4577) // 'noexcept' used with no exception handling mode specified

size_t type_info::hash_code() const noexcept
{
return __std_type_info_hash(&_Data);
}

bool type_info::operator==(const type_info& _Other) const noexcept
{
return __std_type_info_compare(&_Data, &_Other._Data) == 0;
}

bool type_info::operator!=(const type_info& _Other) const noexcept
{
return __std_type_info_compare(&_Data, &_Other._Data) != 0;
}

bool type_info::before(const type_info& _Other) const noexcept
{
return __std_type_info_compare(&_Data, &_Other._Data) < 0;
}

const char* type_info::name() const
{
#ifdef _M_CEE_PURE
return __std_type_info_name(&_Data, static_cast<__type_info_node*>(__type_info_root_node.ToPointer()));
#else
return __std_type_info_name(&_Data, &__type_info_root_node);
#endif
}

const char* type_info::name(__type_info_node*) const
{
#ifdef _M_CEE_PURE
return __std_type_info_name(&_Data, static_cast<__type_info_node*>(__type_info_root_node.ToPointer()));
#else
return __std_type_info_name(&_Data, &__type_info_root_node);
#endif
}

const char* type_info::raw_name() const
{
return _Data._DecoratedName;
}
90 changes: 90 additions & 0 deletions TypeInfoHack/Hack.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#pragma once

#include <vcruntime.h>

#ifdef MYDLL_EXPORTS
#define API __declspec(dllexport)
#else
#define API __declspec(dllimport)
#endif


#include <vcruntime.h>

#include <vcruntime_exception.h>

#pragma warning(push)
#pragma warning(disable: _VCRUNTIME_DISABLED_WARNINGS)

#if defined _M_CEE_MIXED && !defined _VCRT_BUILD
// Provide a fake definition of __type_info_node to suppress linker warning
// LNK4248: unresolved typeref token for '__type_info_node'; image may not run.
struct __type_info_node { };
#else
struct __type_info_node;
#endif

#ifdef _M_CEE_PURE
extern System::IntPtr __type_info_root_node;
#else
extern __type_info_node __type_info_root_node;
#endif


_CRT_BEGIN_C_HEADER

struct __std_type_info_data
{
const char* _UndecoratedName;
const char _DecoratedName[1];
__std_type_info_data() = delete;
__std_type_info_data(const __std_type_info_data&) = delete;
__std_type_info_data(__std_type_info_data&&) = delete;

__std_type_info_data& operator=(const __std_type_info_data&) = delete;
__std_type_info_data& operator=(__std_type_info_data&&) = delete;
};

_VCRTIMP int __cdecl __std_type_info_compare(
_In_ const __std_type_info_data* _Lhs,
_In_ const __std_type_info_data* _Rhs
);

_VCRTIMP size_t __cdecl __std_type_info_hash(
_In_ const __std_type_info_data* _Data
);

_VCRTIMP const char* __cdecl __std_type_info_name(
_Inout_ __std_type_info_data* _Data,
_Inout_ __type_info_node* _RootNode
);

_CRT_END_C_HEADER

class API type_info
{
public:

type_info(const type_info&) = delete;
type_info& operator=(const type_info&) = delete;

size_t hash_code() const noexcept;

bool operator==(const type_info& _Other) const noexcept;

bool operator!=(const type_info& _Other) const noexcept;

bool before(const type_info& _Other) const noexcept;

const char* name() const;

const char* name(__type_info_node*) const;

const char* raw_name() const;

virtual ~type_info() noexcept;

private:

mutable __std_type_info_data _Data;
};
150 changes: 150 additions & 0 deletions TypeInfoHack/TypeInfoHack.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{20bc294d-e18f-4fb2-84bf-6ede694f35b2}</ProjectGuid>
<RootNamespace>TypeInfoHack</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>MYDLL_EXPORTS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>MYDLL_EXPORTS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Hack.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Hack.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
27 changes: 27 additions & 0 deletions TypeInfoHack/TypeInfoHack.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Hack.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Hack.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions TypeInfoHack/TypeInfoHack.vcxproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
1 change: 1 addition & 0 deletions v110_static/class_110.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "class_110.h"
#include <typeinfo>

string::string(const char* _c): c(_c)
{
Expand Down
10 changes: 10 additions & 0 deletions vs2019.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "v142", "v142\vs2019.vcxproj
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "v110_static", "v110_static\v110_static.vcxproj", "{19185F72-6CBB-42DB-8B65-C6DCC58AEEB6}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TypeInfoHack", "TypeInfoHack\TypeInfoHack.vcxproj", "{20BC294D-E18F-4FB2-84BF-6EDE694F35B2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -54,6 +56,14 @@ Global
{19185F72-6CBB-42DB-8B65-C6DCC58AEEB6}.Release|x64.Build.0 = Release|x64
{19185F72-6CBB-42DB-8B65-C6DCC58AEEB6}.Release|x86.ActiveCfg = Release|Win32
{19185F72-6CBB-42DB-8B65-C6DCC58AEEB6}.Release|x86.Build.0 = Release|Win32
{20BC294D-E18F-4FB2-84BF-6EDE694F35B2}.Debug|x64.ActiveCfg = Debug|x64
{20BC294D-E18F-4FB2-84BF-6EDE694F35B2}.Debug|x64.Build.0 = Debug|x64
{20BC294D-E18F-4FB2-84BF-6EDE694F35B2}.Debug|x86.ActiveCfg = Debug|Win32
{20BC294D-E18F-4FB2-84BF-6EDE694F35B2}.Debug|x86.Build.0 = Debug|Win32
{20BC294D-E18F-4FB2-84BF-6EDE694F35B2}.Release|x64.ActiveCfg = Release|x64
{20BC294D-E18F-4FB2-84BF-6EDE694F35B2}.Release|x64.Build.0 = Release|x64
{20BC294D-E18F-4FB2-84BF-6EDE694F35B2}.Release|x86.ActiveCfg = Release|Win32
{20BC294D-E18F-4FB2-84BF-6EDE694F35B2}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit a842f85

Please sign in to comment.