Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tomrus88 committed Mar 15, 2024
1 parent 26b7abb commit f2c0a84
Show file tree
Hide file tree
Showing 17 changed files with 759 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vs/*
OpenLumina/x64/*
OpenLumina/*.user
x64/*
31 changes: 31 additions & 0 deletions OpenLumina.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.34707.107
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenLumina", "OpenLumina\OpenLumina.vcxproj", "{0C1F1447-DAE4-4FA1-BB44-CD3FEE29462F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
ida32 Debug|x64 = ida32 Debug|x64
ida32 Release|x64 = ida32 Release|x64
ida64 Debug|x64 = ida64 Debug|x64
ida64 Release|x64 = ida64 Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0C1F1447-DAE4-4FA1-BB44-CD3FEE29462F}.ida32 Debug|x64.ActiveCfg = ida32 Debug|x64
{0C1F1447-DAE4-4FA1-BB44-CD3FEE29462F}.ida32 Debug|x64.Build.0 = ida32 Debug|x64
{0C1F1447-DAE4-4FA1-BB44-CD3FEE29462F}.ida32 Release|x64.ActiveCfg = ida32 Release|x64
{0C1F1447-DAE4-4FA1-BB44-CD3FEE29462F}.ida32 Release|x64.Build.0 = ida32 Release|x64
{0C1F1447-DAE4-4FA1-BB44-CD3FEE29462F}.ida64 Debug|x64.ActiveCfg = ida64 Debug|x64
{0C1F1447-DAE4-4FA1-BB44-CD3FEE29462F}.ida64 Debug|x64.Build.0 = ida64 Debug|x64
{0C1F1447-DAE4-4FA1-BB44-CD3FEE29462F}.ida64 Release|x64.ActiveCfg = ida64 Release|x64
{0C1F1447-DAE4-4FA1-BB44-CD3FEE29462F}.ida64 Release|x64.Build.0 = ida64 Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {643F44C8-D40B-411D-996F-F5211E79422E}
EndGlobalSection
EndGlobal
150 changes: 150 additions & 0 deletions OpenLumina/OpenLumina.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#include "pch.h"

#define PLUGIN_NAME "OpenLumina"
#define PLUGIN_DESC "Allows IDA to connect to third party Lumina servers"
#define PLUGIN_PREFIX "OpenLumina: "

void load_and_decode_certificate(bytevec_t* buffer, const char* certFilePath)
{
auto certFile = fopenRT(certFilePath);

if (certFile != nullptr)
{
qstring cert;
qstring line;

if (qgetline(&line, certFile) >= 0)
{
do
{
if (strcmp(line.c_str(), "-----BEGIN CERTIFICATE-----"))
{
if (!strcmp(line.c_str(), "-----END CERTIFICATE-----"))
break;

if (line.length())
cert += line;
}
} while (qgetline(&line, certFile) >= 0);
}

qfclose(certFile);

if ((debug & IDA_DEBUG_LUMINA) != 0)
msg(PLUGIN_PREFIX "cert read: %s\n", cert.c_str());

if (!base64_decode(buffer, cert.c_str(), cert.length()))
buffer->resize(0);
}
}

static plugin_ctx_t* s_plugin_ctx = nullptr;

static BOOL(WINAPI* TrueCertAddEncodedCertificateToStore)(HCERTSTORE hCertStore, DWORD dwCertEncodingType, const BYTE* pbCertEncoded, DWORD cbCertEncoded, DWORD dwAddDisposition, PCCERT_CONTEXT* ppCertContext) = CertAddEncodedCertificateToStore;

static BOOL WINAPI HookedCertAddEncodedCertificateToStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, const BYTE* pbCertEncoded, DWORD cbCertEncoded, DWORD dwAddDisposition, PCCERT_CONTEXT* ppCertContext)
{
if ((debug & IDA_DEBUG_LUMINA) != 0)
msg(PLUGIN_PREFIX "HookedCertAddEncodedCertificateToStore called\n");

if (s_plugin_ctx != nullptr && s_plugin_ctx->decodedCert.size() != 0)
{
// inject our root certificate to certificate store
if (!TrueCertAddEncodedCertificateToStore(hCertStore, X509_ASN_ENCODING, &s_plugin_ctx->decodedCert[0], s_plugin_ctx->decodedCert.size(), CERT_STORE_ADD_USE_EXISTING, nullptr))
{
msg(PLUGIN_PREFIX "failed to add our root certificate to certificate store!\n");
}
else
{
if ((debug & IDA_DEBUG_LUMINA) != 0)
msg(PLUGIN_PREFIX "added our root certificate to certificate store\n");
}
}

return TrueCertAddEncodedCertificateToStore(hCertStore, dwCertEncodingType, pbCertEncoded, cbCertEncoded, dwAddDisposition, ppCertContext);
}

bool idaapi plugin_ctx_t::run(size_t arg)
{
msg(PLUGIN_PREFIX "plugin run called\n");
return true;
}

bool plugin_ctx_t::init_hook()
{
char fileNameBuffer[MAX_PATH];

auto certFileName = getsysfile(fileNameBuffer, sizeof(fileNameBuffer), "hexrays.crt", nullptr);

if (certFileName == nullptr)
{
msg(PLUGIN_PREFIX "can't find hexrays.crt file in your IDA folder!\n");
return false;
}

if ((debug & IDA_DEBUG_LUMINA) != 0)
msg(PLUGIN_PREFIX "using certificate file \"%s\"\n", certFileName);

load_and_decode_certificate(&decodedCert, certFileName);

if (decodedCert.size() == 0)
{
msg(PLUGIN_PREFIX "failed to decode certificate file!\n");
return false;
}

DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)TrueCertAddEncodedCertificateToStore, HookedCertAddEncodedCertificateToStore);
DetourTransactionCommit();

if ((debug & IDA_DEBUG_LUMINA) != 0)
msg(PLUGIN_PREFIX "certificate hook applied\n");

return true;
}

plugin_ctx_t::~plugin_ctx_t()
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)TrueCertAddEncodedCertificateToStore, HookedCertAddEncodedCertificateToStore);
DetourTransactionCommit();
}

static plugmod_t* idaapi init()
{
auto ctx = new plugin_ctx_t;

if (ctx == nullptr)
{
msg(PLUGIN_PREFIX "plugin ctx create failed!\n");
return nullptr;
}

if (!ctx->init_hook())
{
msg(PLUGIN_PREFIX "plugin init_hook failed!\n");
return nullptr;
}

s_plugin_ctx = ctx;

return ctx;
}

plugin_t PLUGIN =
{
IDP_INTERFACE_VERSION,
// PLUGIN_HIDE - Plugin should not appear in the Edit, Plugins menu.
// PLUGIN_FIX - Load plugin when IDA starts and keep it in the memory until IDA stops
// PLUGIN_MULTI - The plugin can work with multiple idbs in parallel
PLUGIN_HIDE | PLUGIN_FIX | PLUGIN_MULTI, // Plugin flags
init, // Initialize plugin
nullptr, // Terminate plugin
nullptr, // Invoke plugin
PLUGIN_DESC, // Long comment about the plugin
nullptr, // Multiline help about the plugin
PLUGIN_NAME, // Preferred short name of the plugin
nullptr, // Preferred hotkey to run the plugin
};
205 changes: 205 additions & 0 deletions OpenLumina/OpenLumina.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="ida32 Debug|x64">
<Configuration>ida32 Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="ida32 Release|x64">
<Configuration>ida32 Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="ida64 Debug|x64">
<Configuration>ida64 Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="ida64 Release|x64">
<Configuration>ida64 Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{0c1f1447-dae4-4fa1-bb44-cd3fee29462f}</ProjectGuid>
<RootNamespace>OpenLumina</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>openlumina</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ida32 Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ida64 Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ida32 Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ida64 Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="PropertySheet.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='ida32 Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ida64 Debug|x64'" Label="PropertySheets">
<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)'=='ida32 Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ida64 Release|x64'" Label="PropertySheets">
<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)'=='ida32 Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(IDADIR)\plugins\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ida64 Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(IDADIR)\plugins\</OutDir>
<TargetName>$(ProjectName)64</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ida32 Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(IDADIR)\plugins\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ida64 Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(IDADIR)\plugins\</OutDir>
<TargetName>$(ProjectName)64</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ida32 Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>_DEBUG;OPENLUMINA_EXPORTS;_WINDOWS;_USRDLL;__NT__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(IDASDK)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalOptions>/EXPORT:PLUGIN %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>ida.lib;version.lib;crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(IDASDK)\lib\x64_win_vc_32;$(IDASDK)\lib\x64_win_vc_32_pro</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ida64 Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>_DEBUG;OPENLUMINA_EXPORTS;_WINDOWS;_USRDLL;__NT__;__EA64__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(IDASDK)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalOptions>/EXPORT:PLUGIN %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>ida.lib;version.lib;crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(IDASDK)\lib\x64_win_vc_64;$(IDASDK)\lib\x64_win_vc_64_pro</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ida32 Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>NDEBUG;OPENLUMINA_EXPORTS;_WINDOWS;_USRDLL;__NT__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(IDASDK)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ExceptionHandling>false</ExceptionHandling>
<BufferSecurityCheck>false</BufferSecurityCheck>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalOptions>/EXPORT:PLUGIN %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>ida.lib;version.lib;crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(IDASDK)\lib\x64_win_vc_32;$(IDASDK)\lib\x64_win_vc_32_pro</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ida64 Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>NDEBUG;OPENLUMINA_EXPORTS;_WINDOWS;_USRDLL;__NT__;__EA64__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(IDASDK)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ExceptionHandling>false</ExceptionHandling>
<BufferSecurityCheck>false</BufferSecurityCheck>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalOptions>/EXPORT:PLUGIN %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>ida.lib;version.lib;crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(IDASDK)\lib\x64_win_vc_64;$(IDASDK)\lib\x64_win_vc_64_pro</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="framework.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="plugin_ctx.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="OpenLumina.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='ida32 Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='ida64 Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='ida32 Release|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='ida64 Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Loading

0 comments on commit f2c0a84

Please sign in to comment.