Skip to content

Commit 20d51cb

Browse files
committed
Commit code
1 parent f07590e commit 20d51cb

File tree

11 files changed

+942
-0
lines changed

11 files changed

+942
-0
lines changed

Build/SchemaResolver.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30621.155
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SchemaResolver", "SchemaResolver.vcxproj", "{4E7617D1-E8E2-4EEE-8F64-CD3E1D6B9D83}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{4E7617D1-E8E2-4EEE-8F64-CD3E1D6B9D83}.Debug|x64.ActiveCfg = Debug|x64
17+
{4E7617D1-E8E2-4EEE-8F64-CD3E1D6B9D83}.Debug|x64.Build.0 = Debug|x64
18+
{4E7617D1-E8E2-4EEE-8F64-CD3E1D6B9D83}.Debug|x86.ActiveCfg = Debug|Win32
19+
{4E7617D1-E8E2-4EEE-8F64-CD3E1D6B9D83}.Debug|x86.Build.0 = Debug|Win32
20+
{4E7617D1-E8E2-4EEE-8F64-CD3E1D6B9D83}.Release|x64.ActiveCfg = Release|x64
21+
{4E7617D1-E8E2-4EEE-8F64-CD3E1D6B9D83}.Release|x64.Build.0 = Release|x64
22+
{4E7617D1-E8E2-4EEE-8F64-CD3E1D6B9D83}.Release|x86.ActiveCfg = Release|Win32
23+
{4E7617D1-E8E2-4EEE-8F64-CD3E1D6B9D83}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {90241CB0-EEE0-4D41-A756-7CADB224FEDF}
30+
EndGlobalSection
31+
EndGlobal

Build/SchemaResolver.vcxproj

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<ItemGroup>
22+
<ClCompile Include="..\Source\IResolver.cpp" />
23+
<ClCompile Include="..\Source\Main.cpp" />
24+
<ClCompile Include="..\Source\Utils.cpp" />
25+
</ItemGroup>
26+
<ItemGroup>
27+
<ClInclude Include="..\Source\Config.h" />
28+
<ClInclude Include="..\Source\IResolver.h" />
29+
<ClInclude Include="..\Source\Logger.h" />
30+
<ClInclude Include="..\Source\Native.h" />
31+
<ClInclude Include="..\Source\Utils.h" />
32+
</ItemGroup>
33+
<PropertyGroup Label="Globals">
34+
<VCProjectVersion>16.0</VCProjectVersion>
35+
<Keyword>Win32Proj</Keyword>
36+
<ProjectGuid>{4e7617d1-e8e2-4eee-8f64-cd3e1d6b9d83}</ProjectGuid>
37+
<RootNamespace>SchemaResolver</RootNamespace>
38+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
39+
</PropertyGroup>
40+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
41+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
42+
<ConfigurationType>Application</ConfigurationType>
43+
<UseDebugLibraries>true</UseDebugLibraries>
44+
<PlatformToolset>v142</PlatformToolset>
45+
<CharacterSet>Unicode</CharacterSet>
46+
</PropertyGroup>
47+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
48+
<ConfigurationType>Application</ConfigurationType>
49+
<UseDebugLibraries>false</UseDebugLibraries>
50+
<PlatformToolset>v142</PlatformToolset>
51+
<WholeProgramOptimization>true</WholeProgramOptimization>
52+
<CharacterSet>Unicode</CharacterSet>
53+
</PropertyGroup>
54+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
55+
<ConfigurationType>Application</ConfigurationType>
56+
<UseDebugLibraries>true</UseDebugLibraries>
57+
<PlatformToolset>v142</PlatformToolset>
58+
<CharacterSet>Unicode</CharacterSet>
59+
</PropertyGroup>
60+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
61+
<ConfigurationType>Application</ConfigurationType>
62+
<UseDebugLibraries>false</UseDebugLibraries>
63+
<PlatformToolset>v142</PlatformToolset>
64+
<WholeProgramOptimization>true</WholeProgramOptimization>
65+
<CharacterSet>Unicode</CharacterSet>
66+
</PropertyGroup>
67+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
68+
<ImportGroup Label="ExtensionSettings">
69+
</ImportGroup>
70+
<ImportGroup Label="Shared">
71+
</ImportGroup>
72+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
73+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
74+
</ImportGroup>
75+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
76+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
77+
</ImportGroup>
78+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
79+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
80+
</ImportGroup>
81+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
82+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
83+
</ImportGroup>
84+
<PropertyGroup Label="UserMacros" />
85+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
86+
<LinkIncremental>true</LinkIncremental>
87+
<IntDir>Binary\$(Platform)\$(Configuration)\</IntDir>
88+
<OutDir>$(SolutionDir)Binary\$(Platform)\$(Configuration)\</OutDir>
89+
<TargetName>$(ProjectName)32</TargetName>
90+
</PropertyGroup>
91+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
92+
<LinkIncremental>false</LinkIncremental>
93+
<IntDir>Binary\$(Platform)\$(Configuration)\</IntDir>
94+
<OutDir>$(SolutionDir)Binary\$(Platform)\$(Configuration)\</OutDir>
95+
<TargetName>$(ProjectName)32</TargetName>
96+
</PropertyGroup>
97+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
98+
<LinkIncremental>true</LinkIncremental>
99+
<OutDir>$(SolutionDir)Binary\$(Platform)\$(Configuration)\</OutDir>
100+
<IntDir>Binary\$(Platform)\$(Configuration)\</IntDir>
101+
<TargetName>$(ProjectName)64</TargetName>
102+
</PropertyGroup>
103+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
104+
<LinkIncremental>false</LinkIncremental>
105+
<OutDir>$(SolutionDir)Binary\$(Platform)\$(Configuration)\</OutDir>
106+
<IntDir>Binary\$(Platform)\$(Configuration)\</IntDir>
107+
<TargetName>$(ProjectName)64</TargetName>
108+
</PropertyGroup>
109+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
110+
<ClCompile>
111+
<WarningLevel>Level3</WarningLevel>
112+
<SDLCheck>true</SDLCheck>
113+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
114+
<ConformanceMode>true</ConformanceMode>
115+
<LanguageStandard>stdcpp17</LanguageStandard>
116+
<MultiProcessorCompilation>true</MultiProcessorCompilation>
117+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
118+
</ClCompile>
119+
<Link>
120+
<SubSystem>Console</SubSystem>
121+
<GenerateDebugInformation>true</GenerateDebugInformation>
122+
</Link>
123+
</ItemDefinitionGroup>
124+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
125+
<ClCompile>
126+
<WarningLevel>Level3</WarningLevel>
127+
<FunctionLevelLinking>true</FunctionLevelLinking>
128+
<IntrinsicFunctions>true</IntrinsicFunctions>
129+
<SDLCheck>true</SDLCheck>
130+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
131+
<ConformanceMode>true</ConformanceMode>
132+
<LanguageStandard>stdcpp17</LanguageStandard>
133+
<MultiProcessorCompilation>true</MultiProcessorCompilation>
134+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
135+
</ClCompile>
136+
<Link>
137+
<SubSystem>Console</SubSystem>
138+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
139+
<OptimizeReferences>true</OptimizeReferences>
140+
<GenerateDebugInformation>true</GenerateDebugInformation>
141+
</Link>
142+
</ItemDefinitionGroup>
143+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
144+
<ClCompile>
145+
<WarningLevel>Level3</WarningLevel>
146+
<SDLCheck>true</SDLCheck>
147+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
148+
<ConformanceMode>true</ConformanceMode>
149+
<LanguageStandard>stdcpp17</LanguageStandard>
150+
<MultiProcessorCompilation>true</MultiProcessorCompilation>
151+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
152+
</ClCompile>
153+
<Link>
154+
<SubSystem>Console</SubSystem>
155+
<GenerateDebugInformation>true</GenerateDebugInformation>
156+
</Link>
157+
</ItemDefinitionGroup>
158+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
159+
<ClCompile>
160+
<WarningLevel>Level3</WarningLevel>
161+
<FunctionLevelLinking>true</FunctionLevelLinking>
162+
<IntrinsicFunctions>true</IntrinsicFunctions>
163+
<SDLCheck>true</SDLCheck>
164+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
165+
<ConformanceMode>true</ConformanceMode>
166+
<LanguageStandard>stdcpp17</LanguageStandard>
167+
<MultiProcessorCompilation>true</MultiProcessorCompilation>
168+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
169+
</ClCompile>
170+
<Link>
171+
<SubSystem>Console</SubSystem>
172+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
173+
<OptimizeReferences>true</OptimizeReferences>
174+
<GenerateDebugInformation>true</GenerateDebugInformation>
175+
</Link>
176+
</ItemDefinitionGroup>
177+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
178+
<ImportGroup Label="ExtensionTargets">
179+
</ImportGroup>
180+
</Project>

Build/SchemaResolver.vcxproj.filters

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<ClCompile Include="..\Source\IResolver.cpp" />
5+
<ClCompile Include="..\Source\Utils.cpp" />
6+
<ClCompile Include="..\Source\Main.cpp" />
7+
</ItemGroup>
8+
<ItemGroup>
9+
<ClInclude Include="..\Source\IResolver.h" />
10+
<ClInclude Include="..\Source\Logger.h" />
11+
<ClInclude Include="..\Source\Native.h" />
12+
<ClInclude Include="..\Source\Utils.h" />
13+
<ClInclude Include="..\Source\Config.h" />
14+
</ItemGroup>
15+
</Project>

Source/Config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
#define SR_VERSION_STRING "0.1.0"

Source/IResolver.cpp

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include "IResolver.h"
2+
#include "Utils.h"
3+
4+
5+
IResolver& IResolver::GetInstance()
6+
{
7+
static IResolver i;
8+
return i;
9+
}
10+
11+
IResolver::IResolver()
12+
{
13+
InitializeApiSchema();
14+
}
15+
16+
IResolver::~IResolver()
17+
{
18+
}
19+
20+
bool IResolver::ResolveSchemaModule(const std::wstring &SchemaModuleName, std::vector<std::wstring> &RedirectedModuleName)
21+
{
22+
std::wstring SchemaName = Text::ToLower(SchemaModuleName);
23+
24+
auto Iterator = std::find_if(_ApiSchema.begin(), _ApiSchema.end(),
25+
[&SchemaModuleName](const auto &rhs) {
26+
return SchemaModuleName.find(rhs.first) != std::wstring::npos;
27+
}
28+
);
29+
30+
if (Iterator == _ApiSchema.end()) {
31+
return false;
32+
}
33+
34+
const std::vector<std::wstring> &vHosts = Iterator->second;
35+
if (vHosts.empty()) {
36+
return false;
37+
}
38+
39+
RedirectedModuleName = vHosts;
40+
return true;
41+
}
42+
43+
void IResolver::InitializeApiSchema()
44+
{
45+
if (System::Version::Is10OrGreater())
46+
{
47+
InitializeApiSchemaInternal<
48+
ApiSet::_10::NamespaceArrayT,
49+
ApiSet::_10::NamespaceEntryT,
50+
ApiSet::_10::ValueArrayT,
51+
ApiSet::_10::ValueEntryT
52+
>();
53+
}
54+
else if (System::Version::Is81OrGreater())
55+
{
56+
InitializeApiSchemaInternal<
57+
ApiSet::_81::NamespaceArrayT,
58+
ApiSet::_81::NamespaceEntryT,
59+
ApiSet::_81::ValueArrayT,
60+
ApiSet::_81::ValueEntryT
61+
>();
62+
}
63+
else if (System::Version::Is7OrGreater())
64+
{
65+
InitializeApiSchemaInternal<
66+
ApiSet::_7_8::NamespaceArrayT,
67+
ApiSet::_7_8::NamespaceEntryT,
68+
ApiSet::_7_8::ValueArrayT,
69+
ApiSet::_7_8::ValueEntryT
70+
>();
71+
}
72+
}
73+
74+
template <class ApiSetMapT, class ApiSetEntryT, class HostArrayT, class HostEntryT>
75+
void IResolver::InitializeApiSchemaInternal()
76+
{
77+
PebT *pPeb = Process::GetCurrentPeb();
78+
ApiSetMapT *pApiSetMap = (ApiSetMapT*)pPeb->ApiSetMap();
79+
80+
for (uint32_t i = 0; i < pApiSetMap->Count; ++i)
81+
{
82+
ApiSetEntryT *pDescriptor = pApiSetMap->Entry(i);
83+
HostArrayT *pHostArray = pApiSetMap->ValueArray(pDescriptor);
84+
85+
std::vector<std::wstring> vHosts;
86+
std::wstring ModuleName = Text::ToLower(pApiSetMap->ApiName(pDescriptor));
87+
88+
for (uint32_t j = 0; j < pHostArray->Count; ++j)
89+
{
90+
HostEntryT *pHost = pHostArray->Entry(pApiSetMap, j);
91+
92+
std::wstring HostName = pHost->HostName(pApiSetMap);
93+
if (!HostName.empty()) {
94+
vHosts.emplace_back(std::move(HostName));
95+
}
96+
}
97+
98+
_ApiSchema.emplace_back(std::make_pair(ModuleName, std::move(vHosts)));
99+
}
100+
}

Source/IResolver.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <vector>
5+
#include <list>
6+
7+
8+
class IResolver
9+
{
10+
public:
11+
static IResolver& GetInstance();
12+
13+
IResolver();
14+
~IResolver();
15+
16+
bool ResolveSchemaModule(const std::wstring &SchemaModuleName, std::vector<std::wstring> &RedirectedModuleName);
17+
18+
private:
19+
std::list<std::pair<std::wstring, std::vector<std::wstring>>> _ApiSchema;
20+
21+
void InitializeApiSchema();
22+
23+
template <class ApiSetMapT, class ApiSetEntry, class HostArrayT, class HostEntryT>
24+
void InitializeApiSchemaInternal();
25+
26+
};

Source/Logger.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
#include <string>
5+
6+
#include <Windows.h>
7+
8+
9+
enum class ConCol : uint16_t
10+
{
11+
Bright = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY,
12+
Yellow = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY,
13+
Purple = FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY,
14+
Red = FOREGROUND_RED | FOREGROUND_INTENSITY,
15+
Cyan = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY,
16+
Green = FOREGROUND_GREEN | FOREGROUND_INTENSITY,
17+
Blue = FOREGROUND_BLUE | FOREGROUND_INTENSITY,
18+
Default = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED,
19+
};
20+
21+
template <ConCol ConsoleColor = ConCol::Default, class ...ArgsT>
22+
void Log(const std::wstring &Format, ArgsT &&...Args)
23+
{
24+
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
25+
SetConsoleTextAttribute(hStdOut, (uint16_t)ConsoleColor);
26+
fwprintf(stdout, Format.c_str(), std::forward<ArgsT>(Args)...);
27+
SetConsoleTextAttribute(hStdOut, (uint16_t)ConCol::Default);
28+
}

0 commit comments

Comments
 (0)