mirror of
https://github.com/es3n1n/defendnot.git
synced 2026-08-02 10:32:01 +00:00
initial
This commit is contained in:
177
defendnot-loader/core/autorun.cpp
Normal file
177
defendnot-loader/core/autorun.cpp
Normal file
@@ -0,0 +1,177 @@
|
||||
#include "core/core.hpp"
|
||||
|
||||
#include "shared/ctx.hpp"
|
||||
#include "shared/defer.hpp"
|
||||
#include "shared/names.hpp"
|
||||
|
||||
#include <print>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <comdef.h>
|
||||
#include <taskschd.h>
|
||||
|
||||
#pragma comment(lib, "taskschd.lib")
|
||||
#pragma comment(lib, "comsupp.lib")
|
||||
#pragma comment(lib, "ole32.lib")
|
||||
|
||||
namespace loader {
|
||||
namespace {
|
||||
constexpr std::string_view kTaskName = names::kProjectName;
|
||||
|
||||
template <typename Callable>
|
||||
[[nodiscard]] bool with_service(Callable&& callback) {
|
||||
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
defer->void {
|
||||
CoUninitialize();
|
||||
};
|
||||
|
||||
ITaskService* service = nullptr;
|
||||
hr = CoCreateInstance(CLSID_TaskScheduler, nullptr, CLSCTX_INPROC_SERVER, IID_ITaskService, reinterpret_cast<void**>(&service));
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
defer->void {
|
||||
service->Release();
|
||||
};
|
||||
|
||||
hr = service->Connect(VARIANT{}, VARIANT{}, VARIANT{}, VARIANT{});
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ITaskFolder* root_folder = nullptr;
|
||||
hr = service->GetFolder(BSTR(L"\\"), &root_folder);
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
defer->void {
|
||||
root_folder->Release();
|
||||
};
|
||||
|
||||
root_folder->DeleteTask(BSTR(kTaskName.data()), 0);
|
||||
return callback(service, root_folder);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
[[nodiscard]] bool add_to_autorun() {
|
||||
const auto bin_path = shared::get_this_module_path();
|
||||
|
||||
return with_service([bin_path](ITaskService* service, ITaskFolder* folder) -> bool {
|
||||
ITaskDefinition* task = nullptr;
|
||||
auto hr = service->NewTask(0, &task);
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
defer->void {
|
||||
task->Release();
|
||||
};
|
||||
|
||||
IRegistrationInfo* reg_info = nullptr;
|
||||
hr = task->get_RegistrationInfo(®_info);
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
defer->void {
|
||||
reg_info->Release();
|
||||
};
|
||||
reg_info->put_Author(_bstr_t(names::kRepoUrl.data()));
|
||||
|
||||
IPrincipal* pPrincipal = nullptr;
|
||||
hr = task->get_Principal(&pPrincipal);
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
defer->void {
|
||||
pPrincipal->Release();
|
||||
};
|
||||
|
||||
ITriggerCollection* trigger_collection = nullptr;
|
||||
hr = task->get_Triggers(&trigger_collection);
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
defer->void {
|
||||
trigger_collection->Release();
|
||||
};
|
||||
|
||||
ITrigger* trigger = nullptr;
|
||||
hr = trigger_collection->Create(TASK_TRIGGER_LOGON, &trigger);
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
defer->void {
|
||||
trigger->Release();
|
||||
};
|
||||
|
||||
IActionCollection* action_collection = nullptr;
|
||||
hr = task->get_Actions(&action_collection);
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
defer->void {
|
||||
action_collection->Release();
|
||||
};
|
||||
|
||||
IAction* action = nullptr;
|
||||
hr = action_collection->Create(TASK_ACTION_EXEC, &action);
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
defer->void {
|
||||
action->Release();
|
||||
};
|
||||
|
||||
IExecAction* exec_action = nullptr;
|
||||
hr = action->QueryInterface(IID_IExecAction, (void**)&exec_action);
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
defer->void {
|
||||
exec_action->Release();
|
||||
};
|
||||
|
||||
ITaskSettings* settings = nullptr;
|
||||
hr = task->get_Settings(&settings);
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
defer->void {
|
||||
settings->Release();
|
||||
};
|
||||
|
||||
pPrincipal->put_RunLevel(TASK_RUNLEVEL_HIGHEST);
|
||||
settings->put_DisallowStartIfOnBatteries(VARIANT_FALSE);
|
||||
settings->put_StopIfGoingOnBatteries(VARIANT_FALSE);
|
||||
exec_action->put_Path(_bstr_t(bin_path.string().c_str()));
|
||||
exec_action->put_Arguments(_bstr_t("--from-autorun"));
|
||||
|
||||
IRegisteredTask* registered_task = nullptr;
|
||||
hr = folder->RegisterTaskDefinition(_bstr_t(kTaskName.data()), task, TASK_CREATE_OR_UPDATE, VARIANT{}, VARIANT{}, TASK_LOGON_INTERACTIVE_TOKEN,
|
||||
_variant_t(L""), ®istered_task);
|
||||
|
||||
defer->void {
|
||||
registered_task->Release();
|
||||
};
|
||||
return SUCCEEDED(hr);
|
||||
});
|
||||
}
|
||||
|
||||
[[nodiscard]] bool remove_from_autorun() {
|
||||
return with_service([]<typename... TArgs>(TArgs...) -> bool { return true; });
|
||||
}
|
||||
} // namespace loader
|
||||
19
defendnot-loader/core/core.hpp
Normal file
19
defendnot-loader/core/core.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
namespace loader {
|
||||
struct Config {
|
||||
public:
|
||||
std::string name;
|
||||
bool disable;
|
||||
bool verbose;
|
||||
bool from_autorun;
|
||||
};
|
||||
|
||||
[[nodiscard]] HANDLE inject(std::string_view dll_path, std::string_view proc_name);
|
||||
[[nodiscard]] bool add_to_autorun();
|
||||
[[nodiscard]] bool remove_from_autorun();
|
||||
} // namespace loader
|
||||
58
defendnot-loader/core/inject.cpp
Normal file
58
defendnot-loader/core/inject.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "core/core.hpp"
|
||||
|
||||
#include "shared/defer.hpp"
|
||||
#include <print>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
namespace loader {
|
||||
[[nodiscard]] HANDLE inject(std::string_view dll_path, std::string_view proc_name) {
|
||||
STARTUPINFOA si = {
|
||||
.cb = sizeof(si),
|
||||
};
|
||||
PROCESS_INFORMATION pi = {
|
||||
0,
|
||||
};
|
||||
SECURITY_ATTRIBUTES sa = {
|
||||
.nLength = sizeof(sa),
|
||||
.bInheritHandle = TRUE,
|
||||
};
|
||||
|
||||
std::println("** booting {}", proc_name);
|
||||
if (!CreateProcessA(nullptr, const_cast<char*>(proc_name.data()), &sa, &sa, FALSE, CREATE_SUSPENDED, nullptr, nullptr, &si, &pi)) {
|
||||
throw std::runtime_error(std::format("unable to create process: {}", GetLastError()));
|
||||
}
|
||||
|
||||
defer->void {
|
||||
CloseHandle(pi.hThread);
|
||||
/// Not closing hProcess because we return it
|
||||
};
|
||||
|
||||
LPVOID mem = VirtualAllocEx(pi.hProcess, nullptr, dll_path.size() + 1, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
||||
if (mem == nullptr) {
|
||||
throw std::runtime_error(std::format("unable to allocate memory: {}", GetLastError()));
|
||||
}
|
||||
|
||||
defer->void {
|
||||
VirtualFreeEx(pi.hProcess, mem, 0, MEM_RELEASE);
|
||||
};
|
||||
|
||||
if (!WriteProcessMemory(pi.hProcess, mem, dll_path.data(), dll_path.size() + 1, nullptr)) {
|
||||
throw std::runtime_error(std::format("unable to write memory: {}", GetLastError()));
|
||||
}
|
||||
|
||||
HANDLE thread = CreateRemoteThread(pi.hProcess, nullptr, 0, reinterpret_cast<LPTHREAD_START_ROUTINE>(LoadLibraryA), mem, 0, nullptr);
|
||||
if (thread == NULL) {
|
||||
throw std::runtime_error(std::format("unable to create thread: {}", GetLastError()));
|
||||
}
|
||||
|
||||
defer->void {
|
||||
CloseHandle(thread);
|
||||
};
|
||||
|
||||
/// Wait for DllMain to complete
|
||||
WaitForSingleObject(thread, INFINITE);
|
||||
return pi.hProcess;
|
||||
}
|
||||
} // namespace loader
|
||||
262
defendnot-loader/defendnot-loader.vcxproj
Normal file
262
defendnot-loader/defendnot-loader.vcxproj
Normal file
@@ -0,0 +1,262 @@
|
||||
<?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>
|
||||
<ProjectConfiguration Include="Debug|ARM64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>ARM64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|ARM64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>ARM64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{91eb6f68-ce01-45ab-8b74-7fd618fdedb5}</ProjectGuid>
|
||||
<RootNamespace>defendnotloader</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>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" 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">
|
||||
<Import Project="..\cxx-shared\cxx-shared.vcxitems" 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>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
|
||||
<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|ARM64'">
|
||||
<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|ARM64'">
|
||||
<OutDir>$(SolutionDir)out\$(PlatformName)\</OutDir>
|
||||
<IntDir>$(OutDir)imm\$(ProjectName)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
|
||||
<OutDir>$(SolutionDir)out\$(PlatformName)\</OutDir>
|
||||
<IntDir>$(OutDir)imm\$(ProjectName)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)out\$(PlatformName)\</OutDir>
|
||||
<IntDir>$(OutDir)imm\$(ProjectName)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)out\$(PlatformName)\</OutDir>
|
||||
<IntDir>$(OutDir)imm\$(ProjectName)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)out\$(PlatformName)\</OutDir>
|
||||
<IntDir>$(OutDir)imm\$(ProjectName)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>$(SolutionDir)out\$(PlatformName)\</OutDir>
|
||||
<IntDir>$(OutDir)imm\$(ProjectName)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<LanguageStandard_C>stdclatest</LanguageStandard_C>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)vendor\argparse\include\;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
|
||||
<AdditionalOptions>/pdbaltpath:%_PDB% %(AdditionalOptions)</AdditionalOptions>
|
||||
</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>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<LanguageStandard_C>stdclatest</LanguageStandard_C>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)vendor\argparse\include\;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
|
||||
<AdditionalOptions>/pdbaltpath:%_PDB% %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<LanguageStandard_C>stdclatest</LanguageStandard_C>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)vendor\argparse\include\;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
|
||||
<AdditionalOptions>/pdbaltpath:%_PDB% %(AdditionalOptions)</AdditionalOptions>
|
||||
</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>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<LanguageStandard_C>stdclatest</LanguageStandard_C>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)vendor\argparse\include\;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
|
||||
<AdditionalOptions>/pdbaltpath:%_PDB% %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<LanguageStandard_C>stdclatest</LanguageStandard_C>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)vendor\argparse\include\;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
|
||||
<AdditionalOptions>/pdbaltpath:%_PDB% %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<LanguageStandard_C>stdclatest</LanguageStandard_C>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)vendor\argparse\include\;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
|
||||
<AdditionalOptions>/pdbaltpath:%_PDB% %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="core\autorun.cpp" />
|
||||
<ClCompile Include="core\inject.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="core\core.hpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
33
defendnot-loader/defendnot-loader.vcxproj.filters
Normal file
33
defendnot-loader/defendnot-loader.vcxproj.filters
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="core\inject.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="core\autorun.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="core\core.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
18
defendnot-loader/defendnot-loader.vcxproj.user
Normal file
18
defendnot-loader/defendnot-loader.vcxproj.user
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ShowAllFiles>true</ShowAllFiles>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
|
||||
<LocalDebuggerCommandArguments>--verbose</LocalDebuggerCommandArguments>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LocalDebuggerCommandArguments>--verbose</LocalDebuggerCommandArguments>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LocalDebuggerCommandArguments>--verbose</LocalDebuggerCommandArguments>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
127
defendnot-loader/main.cpp
Normal file
127
defendnot-loader/main.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
#include "core/core.hpp"
|
||||
#include "shared/ctx.hpp"
|
||||
#include "shared/defer.hpp"
|
||||
#include "shared/ipc.hpp"
|
||||
#include "shared/names.hpp"
|
||||
#include <argparse/argparse.hpp>
|
||||
|
||||
#include <format>
|
||||
#include <print>
|
||||
#include <thread>
|
||||
|
||||
namespace {
|
||||
void setup_window(const loader::Config& config) {
|
||||
if (!config.from_autorun || config.verbose) {
|
||||
shared::alloc_console();
|
||||
}
|
||||
}
|
||||
|
||||
void setup_context(const loader::Config& config) {
|
||||
std::println("** setting up context");
|
||||
|
||||
if (config.name.length() > shared::kMaxNameLength) {
|
||||
throw std::runtime_error(std::format("Max name length is {} characters", shared::kMaxNameLength));
|
||||
}
|
||||
|
||||
shared::ctx.state = config.disable ? shared::State::OFF : shared::State::ON;
|
||||
shared::ctx.verbose = config.verbose;
|
||||
std::ranges::copy(config.name, shared::ctx.name.data());
|
||||
|
||||
/// No need to overwrite ctx if we are called from autorun
|
||||
if (!config.from_autorun) {
|
||||
std::println("** overwriting ctx.bin");
|
||||
shared::ctx.serialize();
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] HANDLE load_defendnot() {
|
||||
std::println("** loading defendnot");
|
||||
|
||||
auto dll_path = shared::get_this_module_path().parent_path();
|
||||
dll_path /= names::kDllName;
|
||||
if (!std::filesystem::exists(dll_path)) {
|
||||
throw std::runtime_error(std::format("{} does not exist!", names::kDllName));
|
||||
}
|
||||
|
||||
return loader::inject(dll_path.string(), names::kVictimProcess);
|
||||
}
|
||||
|
||||
void wait_for_finish(shared::InterProcessCommunication& ipc) {
|
||||
std::println("** waiting for process to finish, this can take a while");
|
||||
std::cout << std::flush;
|
||||
while (!ipc->finished) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
}
|
||||
std::println("** success: {}", ipc->success);
|
||||
}
|
||||
|
||||
void process_autorun(const loader::Config& config) {
|
||||
if (shared::ctx.state == shared::State::ON) {
|
||||
std::println("** added to autorun: {}", loader::add_to_autorun());
|
||||
} else {
|
||||
std::println("** removed from autorun: {}", loader::remove_from_autorun());
|
||||
}
|
||||
}
|
||||
|
||||
void banner(const loader::Config& config) {
|
||||
std::println();
|
||||
std::println("thanks for using {}", names::kProjectName);
|
||||
std::println("please don't forget to leave a star at {}", names::kRepoUrl);
|
||||
|
||||
if (!config.from_autorun) {
|
||||
system("pause");
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char* argv[]) try {
|
||||
argparse::ArgumentParser program(std::format("{}-loader", names::kProjectName), "1.0.0");
|
||||
|
||||
program.add_argument("-n", "--name").help("av display name").default_value(std::string(names::kRepoUrl)).nargs(1);
|
||||
program.add_argument("-d", "--disable").help(std::format("disable {}", names::kProjectName)).default_value(false).implicit_value(true);
|
||||
program.add_argument("-v", "--verbose").help("verbose logging").default_value(false).implicit_value(true);
|
||||
program.add_argument("--from-autorun").hidden().default_value(false).implicit_value(true);
|
||||
|
||||
try {
|
||||
program.parse_args(argc, argv);
|
||||
} catch (...) {
|
||||
shared::alloc_console();
|
||||
std::cerr << program;
|
||||
system("pause");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
auto config = loader::Config{
|
||||
.name = program.get<std::string>("-n"),
|
||||
.disable = program.get<bool>("-d"),
|
||||
.verbose = program.get<bool>("-v"),
|
||||
.from_autorun = program.get<bool>("--from-autorun"),
|
||||
};
|
||||
|
||||
setup_window(config);
|
||||
setup_context(config);
|
||||
|
||||
/// \todo @es3n1n: move this to a separate function and add move ctor for ipc
|
||||
std::println("** setting up ipc");
|
||||
auto ipc = shared::InterProcessCommunication(shared::InterProcessCommunicationMode::READ_WRITE, true);
|
||||
ipc->finished = false;
|
||||
|
||||
const auto process = load_defendnot();
|
||||
defer->void {
|
||||
TerminateProcess(process, 0);
|
||||
};
|
||||
|
||||
wait_for_finish(ipc);
|
||||
process_autorun(config);
|
||||
banner(config);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
} catch (std::exception& err) {
|
||||
std::println(stderr, "** fatal error: {}", err.what());
|
||||
system("pause");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nCmdShow) {
|
||||
return main(__argc, __argv);
|
||||
}
|
||||
Reference in New Issue
Block a user