add base code for the hypertrace project

This commit is contained in:
Hari Mishal 2025-12-02 19:08:27 +01:00
parent 338677a0fb
commit 19437cd694
11 changed files with 439 additions and 0 deletions

View file

@ -226,6 +226,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "config", "config", "{035508
include\config\Definition.h = include\config\Definition.h
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hypertrace", "hypertrace\hypertrace.vcxproj", "{9FA45E25-DAEB-4C2D-806C-7908A180195D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
debug|x64 = debug|x64
@ -279,6 +281,12 @@ Global
{B226530A-14B1-40AC-B82E-D9057400E7EE}.debug|x64.Build.0 = debug|x64
{B226530A-14B1-40AC-B82E-D9057400E7EE}.release|x64.ActiveCfg = release|x64
{B226530A-14B1-40AC-B82E-D9057400E7EE}.release|x64.Build.0 = release|x64
{9FA45E25-DAEB-4C2D-806C-7908A180195D}.debug|x64.ActiveCfg = debug|x64
{9FA45E25-DAEB-4C2D-806C-7908A180195D}.debug|x64.Build.0 = debug|x64
{9FA45E25-DAEB-4C2D-806C-7908A180195D}.debug|x64.Deploy.0 = debug|x64
{9FA45E25-DAEB-4C2D-806C-7908A180195D}.release|x64.ActiveCfg = release|x64
{9FA45E25-DAEB-4C2D-806C-7908A180195D}.release|x64.Build.0 = release|x64
{9FA45E25-DAEB-4C2D-806C-7908A180195D}.release|x64.Deploy.0 = release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -0,0 +1,22 @@
# Code generated by Visual Studio kit, DO NOT EDIT.
set(SourceFiles
"../include/components/spinlock/code/Spinlock.c"
"../include/platform/kernel/code/Mem.c"
"code/Logging.c"
"code/UnloadDll.c"
"../include/components/spinlock/header/Spinlock.h"
"../include/platform/kernel/header/Environment.h"
"../include/platform/kernel/header/Mem.h"
"header/Logging.h"
"header/pch.h"
"header/UnloadDll.h"
"hypertrace.def"
)
include_directories(
"../include"
"header"
)
wdk_add_library(hypertrace SHARED
KMDF 1.15
${SourceFiles}
)

View file

@ -0,0 +1,12 @@
/**
* @file Tracing.c
* @author Hari Mishal (harimishal6@gmail.com)
* @brief Message logging and tracing implementation
* @details
* @version 0.18
* @date 2025-12-02
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#include "pch.h"

View file

@ -0,0 +1,34 @@
/**
* @file UnloadDll.c
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief Unloading DLL in the target Windows
*
* @version 0.4
* @date 2023-07-06
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#include "pch.h"
//
// We'll add these functions, so whenever HyperDbg's driver is unloaded
// DllUnload will be called to unload this dll from the memory.
// this way we can remove the HyperDbg after unloading as there is no
// other module remains loaded in the memory.
//
NTSTATUS
DllInitialize(
_In_ PUNICODE_STRING RegistryPath)
{
UNREFERENCED_PARAMETER(RegistryPath);
return STATUS_SUCCESS;
}
NTSTATUS
DllUnload(void)
{
return STATUS_SUCCESS;
}

View file

@ -0,0 +1,25 @@
/**
* @file Tracing.h
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief Headers of Message logging and tracing
* @details
* @version 0.1
* @date 2020-04-11
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#pragma once
//////////////////////////////////////////////////
// Global Variables //
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// Structures //
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// Functions //
//////////////////////////////////////////////////

View file

@ -0,0 +1,20 @@
/**
* @file UnloadDll.h
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief Headers for unloading DLL in the target Windows
*
* @version 0.4
* @date 2023-07-06
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#pragma once
//////////////////////////////////////////////////
// Exported Functions //
//////////////////////////////////////////////////
__declspec(dllexport) NTSTATUS DllInitialize(_In_ PUNICODE_STRING RegistryPath);
__declspec(dllexport) NTSTATUS DllUnload(void);

View file

@ -0,0 +1,51 @@
/**
* @file pch.h
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief Headers of Message logging and tracing
* @details
* @version 0.2
* @date 2023-01-23
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#pragma once
#define _NO_CRT_STDIO_INLINE
#pragma warning(disable : 4201) // Suppress nameless struct/union warning
//
// Environment headers
//
#include "platform/kernel/header/Environment.h"
#ifdef ENV_WINDOWS
//
// Windows defined functions
//
# include <ntddk.h>
# include <ntstrsafe.h>
# include <Windef.h>
#endif // ENV_WINDOWS
//
// Scope definitions
//
#define HYPERDBG_KERNEL_MODE
#define HYPERDBG_HYPER_LOG
#include "UnloadDll.h"
#include "SDK/HyperDbgSdk.h"
#include "SDK/modules/HyperLog.h"
#include "SDK/imports/kernel/HyperDbgHyperLogImports.h"
#include "components/spinlock/header/Spinlock.h"
#include "Tracing.h"
//
// Platform independent headers
//
#include "platform/kernel/header/Mem.h"

View file

@ -0,0 +1,6 @@
LIBRARY hypertrace
EXPORTS
DllInitialize PRIVATE
DllUnload PRIVATE

View file

@ -0,0 +1,77 @@
;
; hypertrace.inf
;
[Version]
Signature="$WINDOWS NT$"
Class=System ; TODO: specify appropriate Class
ClassGuid={4d36e97d-e325-11ce-bfc1-08002be10318} ; TODO: specify appropriate ClassGuid
Provider=%ManufacturerName%
CatalogFile=hypertrace.cat
DriverVer= ; TODO: set DriverVer in stampinf property pages
PnpLockdown=1
[DestinationDirs]
DefaultDestDir = 12
hypertrace_Device_CoInstaller_CopyFiles = 11
[SourceDisksNames]
1 = %DiskName%,,,""
[SourceDisksFiles]
hypertrace.sys = 1,,
WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll=1 ; make sure the number matches with SourceDisksNames
;*****************************************
; Install Section
;*****************************************
[Manufacturer]
%ManufacturerName%=Standard,NT$ARCH$
[Standard.NT$ARCH$]
%hypertrace.DeviceDesc%=hypertrace_Device, Root\hypertrace ; TODO: edit hw-id
[hypertrace_Device.NT]
CopyFiles=Drivers_Dir
[Drivers_Dir]
hypertrace.sys
;-------------- Service installation
[hypertrace_Device.NT.Services]
AddService = hypertrace,%SPSVCINST_ASSOCSERVICE%, hypertrace_Service_Inst
; -------------- hypertrace driver install sections
[hypertrace_Service_Inst]
DisplayName = %hypertrace.SVCDESC%
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 3 ; SERVICE_DEMAND_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %12%\hypertrace.sys
;
;--- hypertrace_Device Coinstaller installation ------
;
[hypertrace_Device.NT.CoInstallers]
AddReg=hypertrace_Device_CoInstaller_AddReg
CopyFiles=hypertrace_Device_CoInstaller_CopyFiles
[hypertrace_Device_CoInstaller_AddReg]
HKR,,CoInstallers32,0x00010000, "WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll,WdfCoInstaller"
[hypertrace_Device_CoInstaller_CopyFiles]
WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll
[hypertrace_Device.NT.Wdf]
KmdfService = hypertrace, hypertrace_wdfsect
[hypertrace_wdfsect]
KmdfLibraryVersion = $KMDFVERSION$
[Strings]
SPSVCINST_ASSOCSERVICE= 0x00000002
ManufacturerName="<Your manufacturer name>" ;TODO: Replace with your manufacturer name
DiskName = "hypertrace Installation Disk"
hypertrace.DeviceDesc = "hypertrace Device"
hypertrace.SVCDESC = "hypertrace Service"

View file

@ -0,0 +1,122 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<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">
<ProjectGuid>{9FA45E25-DAEB-4C2D-806C-7908A180195D}</ProjectGuid>
<TemplateGuid>{1bc93793-694f-48fe-9372-81e2b05556fd}</TemplateGuid>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion>
<Configuration>Debug</Configuration>
<Platform Condition="'$(Platform)' == ''">x64</Platform>
<RootNamespace>hypertrace</RootNamespace>
<WindowsTargetPlatformVersion>$(LatestTargetPlatformVersion)</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='debug|x64'" Label="Configuration">
<TargetVersion>Windows10</TargetVersion>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<DriverType>KMDF</DriverType>
<DriverTargetPlatform>Universal</DriverTargetPlatform>
<Driver_SpectreMitigation>false</Driver_SpectreMitigation>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='release|x64'" Label="Configuration">
<TargetVersion>Windows10</TargetVersion>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<DriverType>KMDF</DriverType>
<DriverTargetPlatform>Universal</DriverTargetPlatform>
<Driver_SpectreMitigation>false</Driver_SpectreMitigation>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup 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 />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='debug|x64'">
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
<OutDir>$(SolutionDir)build\bin\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)build\obj\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>
<EnableInf2cat>false</EnableInf2cat>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='release|x64'">
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
<OutDir>$(SolutionDir)build\bin\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)build\obj\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>
<EnableInf2cat>false</EnableInf2cat>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='debug|x64'">
<DriverSign>
<FileDigestAlgorithm>sha256</FileDigestAlgorithm>
</DriverSign>
<ClCompile>
<AdditionalIncludeDirectories>$(SolutionDir)\include;$(ProjectDir)header;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
<PrecompiledHeader>Create</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
<EntryPointSymbol />
<NoEntryPoint>true</NoEntryPoint>
<ModuleDefinitionFile>hypertrace.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='release|x64'">
<DriverSign>
<FileDigestAlgorithm>sha256</FileDigestAlgorithm>
</DriverSign>
<ClCompile>
<AdditionalIncludeDirectories>$(SolutionDir)\include;$(ProjectDir)header;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
<PrecompiledHeader>Create</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp20</LanguageStandard>
<Optimization>Full</Optimization>
</ClCompile>
<Link>
<TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
<EntryPointSymbol />
<NoEntryPoint>true</NoEntryPoint>
<ModuleDefinitionFile>hypertrace.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<Inf Include="hypertrace.inf" />
</ItemGroup>
<ItemGroup>
<FilesToPackage Include="$(TargetPath)" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\include\components\spinlock\code\Spinlock.c" />
<ClCompile Include="..\include\platform\kernel\code\Mem.c" />
<ClCompile Include="code\Tracing.c" />
<ClCompile Include="code\UnloadDll.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\components\spinlock\header\Spinlock.h" />
<ClInclude Include="..\include\platform\kernel\header\Environment.h" />
<ClInclude Include="..\include\platform\kernel\header\Mem.h" />
<ClInclude Include="header\Tracing.h" />
<ClInclude Include="header\pch.h" />
<ClInclude Include="header\UnloadDll.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Driver Files">
<UniqueIdentifier>{8E41214B-6785-4CFE-B992-037D68949A14}</UniqueIdentifier>
<Extensions>inf;inv;inx;mof;mc;</Extensions>
</Filter>
<Filter Include="code">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="header">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="header\platform">
<UniqueIdentifier>{1ab177b4-9e6c-460e-834a-8fced04b42a3}</UniqueIdentifier>
</Filter>
<Filter Include="code\platform">
<UniqueIdentifier>{21f0281e-fc2a-4e13-97ac-e4b35a05a31e}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<Inf Include="hypertrace.inf">
<Filter>Driver Files</Filter>
</Inf>
</ItemGroup>
<ItemGroup>
<ClCompile Include="code\Tracing.c">
<Filter>code</Filter>
</ClCompile>
<ClCompile Include="..\include\components\spinlock\code\Spinlock.c">
<Filter>code</Filter>
</ClCompile>
<ClCompile Include="code\UnloadDll.c">
<Filter>code</Filter>
</ClCompile>
<ClCompile Include="..\include\platform\kernel\code\Mem.c">
<Filter>code\platform</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="header\Tracing.h">
<Filter>header</Filter>
</ClInclude>
<ClInclude Include="..\include\components\spinlock\header\Spinlock.h">
<Filter>header</Filter>
</ClInclude>
<ClInclude Include="header\pch.h">
<Filter>header</Filter>
</ClInclude>
<ClInclude Include="header\UnloadDll.h">
<Filter>header</Filter>
</ClInclude>
<ClInclude Include="..\include\platform\kernel\header\Environment.h">
<Filter>header\platform</Filter>
</ClInclude>
<ClInclude Include="..\include\platform\kernel\header\Mem.h">
<Filter>header\platform</Filter>
</ClInclude>
</ItemGroup>
</Project>