Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions FindInterface/FindInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#define _CRT_SECURE_NO_WARNINGS
#include <Windows.h>
#include <stdio.h>

#pragma comment(lib, "Ole32.lib")

MULTI_QI mq[50000];
WCHAR keys[50000][256];
CLSID clsid;
DWORD index;

DWORD WINAPI FindInterface(LPVOID args) {
DWORD retval;
__try {
HANDLE hFile = CreateFile(L"now.local", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == NULL) return GetLastError();
char line[256];

SIZE_T convertedSize;
INT cnt = 0;
DWORD nBytes;

HRESULT hr = CoCreateInstanceEx(clsid, NULL, CLSCTX_LOCAL_SERVER, NULL, index, mq);
if (hr < 0) {
printf("CoCreateInstanceEx(LOCAL) Failed. hr: 0x%X\n", hr);
retval = hr;
}
else {
for (INT i = 0; i < index; i++) {

if (mq[i].hr == S_OK) {
memset(line, 0, 256);
wcstombs_s(&convertedSize, line, keys[i], 256);
strcat(line, "\n");
if (!WriteFile(hFile, line, strlen(line), &nBytes, NULL)) return GetLastError();
cnt++;
mq[i].pItf->Release();
}
}
}
if (cnt != 0) return 0;
else return 0x80004002;
}
__except (EXCEPTION_EXECUTE_HANDLER) {
printf("Exception!");
return GetExceptionCode();
}
return retval;
}

INT wmain(INT argc, WCHAR **argv) {
CoInitializeEx(NULL, COINIT_MULTITHREADED);

HRESULT hr;

hr = CLSIDFromString(argv[1], &clsid);
if (hr < 0) {
printf("CLSIDFromString() Failed. hr: 0x%X\n", hr);
return hr;
}

HKEY hKey;
LSTATUS status;
status = RegOpenKeyExW(HKEY_CLASSES_ROOT, L"Interface", 0, KEY_READ, &hKey);
if (status != ERROR_SUCCESS) {
printf("RegOpenKeyExW() Failed. LastError: %lu\n", GetLastError());
}
FILETIME lastWriteTime;
WCHAR keyName[256];
DWORD keyNameSize;
while (true) {
keyNameSize = sizeof(keyName) / sizeof(keyName[0]);
status = RegEnumKeyExW(hKey, index, keyName, &keyNameSize, NULL, NULL, NULL, &lastWriteTime);
lstrcpy(keys[index], keyName);
if (status == ERROR_NO_MORE_ITEMS) break;

IID* iid = (IID*)malloc(sizeof(IID));
IIDFromString(keyName, iid);

mq[index].pIID = iid;
index++;
}

DWORD tid;
HANDLE hThread = CreateThread(NULL, 0, FindInterface, NULL, 0, &tid);

DWORD waitResult = WaitForSingleObject(hThread, 10000);


DWORD retval;
if (waitResult == WAIT_OBJECT_0) {
GetExitCodeThread(hThread, &retval);
}
else if (waitResult == WAIT_TIMEOUT) {
retval = 0xFFFFFFFF;
}
else retval = 0xEEEEEEEE;

CoUninitialize();
return retval;
}
143 changes: 143 additions & 0 deletions FindInterface/FindInterface.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?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>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{5d31fa24-fe76-4f13-9cc8-41ff178beecb}</ProjectGuid>
<RootNamespace>FindInterface</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</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)'=='Release|x64'">
<OutDir>$(SolutionDir)bin\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)bin\$(Configuration)\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>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>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>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</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>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="FindInterface.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
22 changes: 22 additions & 0 deletions FindInterface/FindInterface.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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="FindInterface.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
94 changes: 94 additions & 0 deletions FindInterfaceInproc/FindInterfaceInproc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#define _CRT_SECURE_NO_WARNINGS
#include <Windows.h>
#include <stdio.h>

#pragma comment(lib, "Ole32.lib")

MULTI_QI mq[50000];
WCHAR keys[50000][256];
CLSID clsid;
DWORD index;

DWORD WINAPI FindInterface(LPVOID args) {
DWORD retval;
__try {
HANDLE hFile = CreateFile(L"now.inproc", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == NULL) return GetLastError();
char line[256];

SIZE_T convertedSize;
INT cnt = 0;
DWORD nBytes;

HRESULT hr;
IID iid;
LPVOID ppv;
for (INT i = 0; i < index; i++) {
IIDFromString(keys[i], &iid);
hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, &ppv);
if (hr < 0) continue;
memset(line, 0, 256);
wcstombs_s(&convertedSize, line, keys[i], 256);
if (!WriteFile(hFile, line, strlen(line), &nBytes, NULL)) return GetLastError();
}
if (cnt != 0) return 0;
else return 0x80004002;
}
__except (EXCEPTION_EXECUTE_HANDLER) {
printf("Exception!");
return GetExceptionCode();
}
return retval;
}

INT wmain(INT argc, WCHAR** argv) {
CoInitializeEx(NULL, COINIT_MULTITHREADED);

HRESULT hr;

hr = CLSIDFromString(argv[1], &clsid);
if (hr < 0) {
printf("CLSIDFromString() Failed. hr: 0x%X\n", hr);
return hr;
}

HKEY hKey;
LSTATUS status;
status = RegOpenKeyExW(HKEY_CLASSES_ROOT, L"Interface", 0, KEY_READ, &hKey);
if (status != ERROR_SUCCESS) {
printf("RegOpenKeyExW() Failed. LastError: %lu\n", GetLastError());
}
FILETIME lastWriteTime;
WCHAR keyName[256];
DWORD keyNameSize;
while (true) {
keyNameSize = sizeof(keyName) / sizeof(keyName[0]);
status = RegEnumKeyExW(hKey, index, keyName, &keyNameSize, NULL, NULL, NULL, &lastWriteTime);
lstrcpy(keys[index], keyName);
if (status == ERROR_NO_MORE_ITEMS) break;

IID* iid = (IID*)malloc(sizeof(IID));
IIDFromString(keyName, iid);

mq[index].pIID = iid;
index++;
}

DWORD tid;
HANDLE hThread = CreateThread(NULL, 0, FindInterface, NULL, 0, &tid);

DWORD waitResult = WaitForSingleObject(hThread, 20000);


DWORD retval;
if (waitResult == WAIT_OBJECT_0) {
GetExitCodeThread(hThread, &retval);
}
else if (waitResult == WAIT_TIMEOUT) {
retval = 0xFFFFFFFF;
}
else retval = 0xEEEEEEEE;

CoUninitialize();
return retval;
}
Loading