add HyperPerf project structures

This commit is contained in:
sina 2026-06-22 16:19:49 +02:00
parent 7dfe5be985
commit c17ebc09c4
22 changed files with 1038 additions and 19 deletions

View file

@ -8,8 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
New release of the HyperDbg Debugger.
### Added
- Added structure for the hyperperf (Hardware Performance Counter) project
### Changed
- Separated SDK libraries for user mode and kernel mode modules
- Added hypertrace, hyperevade, and hyperperf DLL files to SDK
## [0.20.0.0-beta] - 2026-06-21
New release of the HyperDbg Debugger.

View file

@ -84,14 +84,19 @@
xcopy /E /I /Y "$(SolutionDir)include\SDK" "$(OutDir)SDK"
xcopy /E /I /Y "$(SolutionDir)..\examples" "$(OutDir)SDK\examples"
mkdir "$(OutDir)SDK\libraries"
copy "$(OutDir)pdbex.lib" "$(OutDir)SDK\libraries\pdbex.lib"
copy "$(OutDir)kdserial.lib" "$(OutDir)SDK\libraries\kdserial.lib"
copy "$(OutDir)libhyperdbg.dll" "$(OutDir)SDK\libraries\libhyperdbg.dll"
copy "$(OutDir)script-engine.dll" "$(OutDir)SDK\libraries\script-engine.dll"
copy "$(OutDir)symbol-parser.dll" "$(OutDir)SDK\libraries\symbol-parser.dll"
copy "$(OutDir)hyperlog.dll" "$(OutDir)SDK\libraries\hyperlog.dll"
copy "$(OutDir)hyperhv.dll" "$(OutDir)SDK\libraries\hyperhv.dll"
copy "$(OutDir)libipt.dll" "$(OutDir)SDK\libraries\libipt.dll"
mkdir "$(OutDir)SDK\libraries\kernel"
mkdir "$(OutDir)SDK\libraries\user"
copy "$(OutDir)pdbex.dll" "$(OutDir)SDK\libraries\user\pdbex.dll"
copy "$(OutDir)libipt.dll" "$(OutDir)SDK\libraries\user\libipt.dll"
copy "$(OutDir)script-engine.dll" "$(OutDir)SDK\libraries\user\script-engine.dll"
copy "$(OutDir)symbol-parser.dll" "$(OutDir)SDK\libraries\user\symbol-parser.dll"
copy "$(OutDir)libhyperdbg.dll" "$(OutDir)SDK\libraries\user\libhyperdbg.dll"
copy "$(OutDir)hyperlog.dll" "$(OutDir)SDK\libraries\kernel\hyperlog.dll"
copy "$(OutDir)hyperhv.dll" "$(OutDir)SDK\libraries\kernel\hyperhv.dll"
copy "$(OutDir)hypertrace.dll" "$(OutDir)SDK\libraries\kernel\hyperevade.dll"
copy "$(OutDir)hypertrace.dll" "$(OutDir)SDK\libraries\kernel\hypertrace.dll"
copy "$(OutDir)hyperperf.dll" "$(OutDir)SDK\libraries\kernel\hyperperf.dll"
copy "$(OutDir)kdserial.dll" "$(OutDir)SDK\libraries\kernel\kdserial.dll"
if exist "$(OutDir)constants\" rd /q /s "$(OutDir)constants\"
mkdir "$(OutDir)constants"
copy "$(SolutionDir)miscellaneous\constants\pciid\pci.ids" "$(OutDir)constants\pci.ids"</Command>
@ -129,14 +134,19 @@ copy "$(SolutionDir)miscellaneous\constants\pciid\pci.ids" "$(OutDir)constants\p
xcopy /E /I /Y "$(SolutionDir)include\SDK" "$(OutDir)SDK"
xcopy /E /I /Y "$(SolutionDir)..\examples" "$(OutDir)SDK\examples"
mkdir "$(OutDir)SDK\libraries"
copy "$(OutDir)pdbex.lib" "$(OutDir)SDK\libraries\pdbex.lib"
copy "$(OutDir)kdserial.lib" "$(OutDir)SDK\libraries\kdserial.lib"
copy "$(OutDir)libhyperdbg.dll" "$(OutDir)SDK\libraries\libhyperdbg.dll"
copy "$(OutDir)script-engine.dll" "$(OutDir)SDK\libraries\script-engine.dll"
copy "$(OutDir)symbol-parser.dll" "$(OutDir)SDK\libraries\symbol-parser.dll"
copy "$(OutDir)hyperlog.dll" "$(OutDir)SDK\libraries\hyperlog.dll"
copy "$(OutDir)hyperhv.dll" "$(OutDir)SDK\libraries\hyperhv.dll"
copy "$(OutDir)libipt.dll" "$(OutDir)SDK\libraries\libipt.dll"
mkdir "$(OutDir)SDK\libraries\kernel"
mkdir "$(OutDir)SDK\libraries\user"
copy "$(OutDir)pdbex.dll" "$(OutDir)SDK\libraries\user\pdbex.dll"
copy "$(OutDir)libipt.dll" "$(OutDir)SDK\libraries\user\libipt.dll"
copy "$(OutDir)script-engine.dll" "$(OutDir)SDK\libraries\user\script-engine.dll"
copy "$(OutDir)symbol-parser.dll" "$(OutDir)SDK\libraries\user\symbol-parser.dll"
copy "$(OutDir)libhyperdbg.dll" "$(OutDir)SDK\libraries\user\libhyperdbg.dll"
copy "$(OutDir)hyperlog.dll" "$(OutDir)SDK\libraries\kernel\hyperlog.dll"
copy "$(OutDir)hyperhv.dll" "$(OutDir)SDK\libraries\kernel\hyperhv.dll"
copy "$(OutDir)hypertrace.dll" "$(OutDir)SDK\libraries\kernel\hyperevade.dll"
copy "$(OutDir)hypertrace.dll" "$(OutDir)SDK\libraries\kernel\hypertrace.dll"
copy "$(OutDir)hyperperf.dll" "$(OutDir)SDK\libraries\kernel\hyperperf.dll"
copy "$(OutDir)kdserial.dll" "$(OutDir)SDK\libraries\kernel\kdserial.dll"
if exist "$(OutDir)constants\" rd /q /s "$(OutDir)constants\"
mkdir "$(OutDir)constants"
copy "$(SolutionDir)miscellaneous\constants\pciid\pci.ids" "$(OutDir)constants\pci.ids"</Command>

View file

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32602.215
# Visual Studio Version 18
VisualStudioVersion = 18.7.11911.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hyperdbg-cli", "hyperdbg-cli\hyperdbg-cli.vcxproj", "{FBCBBBAD-4EAE-469E-827F-F59FE9E7375B}"
ProjectSection(ProjectDependencies) = postProject
@ -90,6 +90,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "imports", "imports", "{B3D9
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hyperkd", "hyperkd\hyperkd.vcxproj", "{AFDD7028-1ED9-442E-8A3D-01CFA3AA1CAA}"
ProjectSection(ProjectDependencies) = postProject
{360E54B1-0B92-4BCA-8111-4BF384292621} = {360E54B1-0B92-4BCA-8111-4BF384292621}
{9FA45E25-DAEB-4C2D-806C-7908A180195D} = {9FA45E25-DAEB-4C2D-806C-7908A180195D}
{AFDE69E9-EE3D-470E-8407-C1F0D98F9E3D} = {AFDE69E9-EE3D-470E-8407-C1F0D98F9E3D}
{BB17323A-2460-4AE1-8AFE-B367400B934F} = {BB17323A-2460-4AE1-8AFE-B367400B934F}
@ -101,6 +102,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "modules", "modules", "{13E4
ProjectSection(SolutionItems) = preProject
include\SDK\modules\HyperEvade.h = include\SDK\modules\HyperEvade.h
include\SDK\Modules\HyperLog.h = include\SDK\Modules\HyperLog.h
include\SDK\modules\HyperPerf.h = include\SDK\modules\HyperPerf.h
include\SDK\modules\HyperTrace.h = include\SDK\modules\HyperTrace.h
include\SDK\Modules\VMM.h = include\SDK\Modules\VMM.h
EndProjectSection
@ -207,6 +209,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "kernel", "kernel", "{947577
include\SDK\imports\kernel\HyperDbgHyperEvade.h = include\SDK\imports\kernel\HyperDbgHyperEvade.h
include\SDK\Imports\Kernel\HyperDbgHyperLogImports.h = include\SDK\Imports\Kernel\HyperDbgHyperLogImports.h
include\SDK\Imports\Kernel\HyperDbgHyperLogIntrinsics.h = include\SDK\Imports\Kernel\HyperDbgHyperLogIntrinsics.h
include\SDK\imports\kernel\HyperDbgHyperPerf.h = include\SDK\imports\kernel\HyperDbgHyperPerf.h
include\SDK\imports\kernel\HyperDbgHyperTrace.h = include\SDK\imports\kernel\HyperDbgHyperTrace.h
include\SDK\Imports\Kernel\HyperDbgVmmImports.h = include\SDK\Imports\Kernel\HyperDbgVmmImports.h
EndProjectSection
@ -327,6 +330,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "header", "header", "{CA2D9C
include\components\pe\header\pe-image-reader.h = include\components\pe\header\pe-image-reader.h
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hyperperf", "hyperperf\hyperperf.vcxproj", "{360E54B1-0B92-4BCA-8111-4BF384292621}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
debug|x64 = debug|x64
@ -384,6 +389,12 @@ Global
{9FA45E25-DAEB-4C2D-806C-7908A180195D}.debug|x64.Build.0 = debug|x64
{9FA45E25-DAEB-4C2D-806C-7908A180195D}.release|x64.ActiveCfg = release|x64
{9FA45E25-DAEB-4C2D-806C-7908A180195D}.release|x64.Build.0 = release|x64
{360E54B1-0B92-4BCA-8111-4BF384292621}.debug|x64.ActiveCfg = debug|x64
{360E54B1-0B92-4BCA-8111-4BF384292621}.debug|x64.Build.0 = debug|x64
{360E54B1-0B92-4BCA-8111-4BF384292621}.debug|x64.Deploy.0 = debug|x64
{360E54B1-0B92-4BCA-8111-4BF384292621}.release|x64.ActiveCfg = release|x64
{360E54B1-0B92-4BCA-8111-4BF384292621}.release|x64.Build.0 = release|x64
{360E54B1-0B92-4BCA-8111-4BF384292621}.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/PlatformMem.c"
"code/Logging.c"
"code/UnloadDll.c"
"../include/components/spinlock/header/Spinlock.h"
"../include/platform/kernel/header/Environment.h"
"../include/platform/kernel/header/PlatformMem.h"
"header/Logging.h"
"header/pch.h"
"header/UnloadDll.h"
"hyperperf.def"
)
include_directories(
"../include"
"header"
)
wdk_add_library(hyperperf SHARED
KMDF 1.15
${SourceFiles}
)

View file

@ -0,0 +1,84 @@
/**
* @file PerfApi.c
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief PMU routines for HyperPerf module
* @details
* @version 0.21
* @date 2026-06-22
*
* @copyright This project is released under the GNU Public License v3.
*/
#include "pch.h"
/**
* @brief Initialize the hyperperf module callbacks
* @details This only for callback initialization, not for PMU, etc. initialization
*
* @param HyperPerfCallbacks Pointer to the HyperPerf callbacks structure to be registered
* @param RunningOnHypervisorEnvironment Whether the initialization is being done for hypervisor environment or not,
* it can be used to skip some of the initialization steps if it is not for hypervisor environment and behave differently based on that
*
* @return BOOLEAN
*/
BOOLEAN
HyperPerfInitCallback(HYPERPERF_CALLBACKS * HyperPerfCallbacks,
BOOLEAN RunningOnHypervisorEnvironment)
{
//
// Check if any of the required callbacks are NULL
//
for (UINT32 i = 0; i < sizeof(HYPERPERF_CALLBACKS) / sizeof(UINT64); i++)
{
if (((PVOID *)HyperPerfCallbacks)[i] == NULL)
{
//
// The callback has null entry, so we cannot proceed
//
return FALSE;
}
}
//
// Save the callbacks
//
PlatformWriteMemory(&g_Callbacks, HyperPerfCallbacks, sizeof(HYPERPERF_CALLBACKS));
//
// Set the flag to indicate whether the initialization is being done for hypervisor environment or not
//
g_RunningOnHypervisorEnvironment = RunningOnHypervisorEnvironment;
//
// Enable callbacks and set the initialized flag
//
g_HyperPerfCallbacksInitialized = TRUE;
return TRUE;
}
/**
* @brief Uninitialize the hypertrace module
*
* @return VOID
*/
VOID
HyperPerfUninit()
{
//
// Check if the callbacks are initialized, if not, we don't need to handle anymore
//
if (!g_HyperPerfCallbacksInitialized)
{
return;
}
//
// Reset the environment flag to default value
//
g_RunningOnHypervisorEnvironment = FALSE;
//
// Set callbacks to not initialized
//
g_HyperPerfCallbacksInitialized = FALSE;
}

View file

@ -0,0 +1,26 @@
/**
* @file Broadcast.c
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief Broadcasting functions
* @details
* @version 0.21
* @date 2026-06-22
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#include "pch.h"
/**
* @brief Routines to enable LBR on all cores
*
* @return VOID
*/
VOID
BroadcastEnableLbrOnAllCores()
{
//
// Broadcast to all cores
//
KeGenericCallDpc(DpcRoutineTestPmu, NULL);
}

View file

@ -0,0 +1,35 @@
/**
* @file DpcRoutines.c
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief DPC routines
* @details
* @version 0.21
* @date 2026-06-22
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#include "pch.h"
/**
* @brief Broadcast enabling LBR
*
* @param Dpc
* @param DeferredContext
* @param SystemArgument1
* @param SystemArgument2
* @return BOOLEAN
*/
BOOLEAN
DpcRoutineTestPmu(KDPC * Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
{
UNREFERENCED_PARAMETER(Dpc);
UNREFERENCED_PARAMETER(DeferredContext);
// ------------------------------------------------------------------------------
// Synchronize the end of this routine with the caller
//
PlatformBroadcastSynchronizeEndOfRoutine(SystemArgument1, SystemArgument2);
return TRUE;
}

View file

@ -0,0 +1,45 @@
/**
* @file UnloadDll.c
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief Unloading DLL in the target Windows
* @details
* @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.
//
/**
* @brief Routine called on DLL initialization
*
* @param RegistryPath The registry path of the driver
* @return NTSTATUS
*/
NTSTATUS
DllInitialize(
_In_ PUNICODE_STRING RegistryPath)
{
UNREFERENCED_PARAMETER(RegistryPath);
return STATUS_SUCCESS;
}
/**
* @brief Routine called on DLL unload
*
* @return NTSTATUS
*/
NTSTATUS
DllUnload(VOID)
{
return STATUS_SUCCESS;
}

View file

@ -0,0 +1,19 @@
/**
* @file PerfApi.h
* @author
* @brief Header for general PMU routines for HyperPerf module
* @details
* @version 0.21
* @date 2026-06-22
*
* @copyright This project is released under the GNU Public License v3.
*/
#pragma once
//////////////////////////////////////////////////
// Functions //
//////////////////////////////////////////////////
//
// Most of the functions are defined and exported
//

View file

@ -0,0 +1,20 @@
/**
* @file Broadcast.h
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief Headers for broadcasting functions
* @details
* @version 0.21
* @date 2026-06-22
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#pragma once
//////////////////////////////////////////////////
// Functions //
//////////////////////////////////////////////////
VOID
BroadcastTestPmuOnAllCores();

View file

@ -0,0 +1,20 @@
/**
* @file DpcRoutines.h
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief Definition for DPC functions
* @details
* @version 0.21
* @date 2026-06-22
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#pragma once
//////////////////////////////////////////////////
// Functions //
//////////////////////////////////////////////////
BOOLEAN
DpcRoutineTestPmu(KDPC * Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2);

View file

@ -0,0 +1,22 @@
/**
* @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,35 @@
/**
* @file GlobalVariables.h
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief Definition for global variables
* @details
* @version 0.21
* @date 2026-06-22
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#pragma once
//////////////////////////////////////////////////
// Global Variables //
//////////////////////////////////////////////////
/**
* @brief List of callbacks
*
*/
HYPERPERF_CALLBACKS g_Callbacks;
/**
* @brief The flag indicating whether the hyperperf module callbacks is initialized or not
*
*/
BOOLEAN g_HyperPerfCallbacksInitialized;
/**
* @brief The flag indicating whether the initialization is being done for hypervisor environment or not
*
*/
BOOLEAN g_RunningOnHypervisorEnvironment;

View file

@ -0,0 +1,111 @@
/**
* @file pch.h
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief Headers of Message logging and tracing
* @details
* @version 0.21
* @date 2026-06-22
*
* @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/general/header/Environment.h"
#ifdef HYPERDBG_ENV_WINDOWS
//
// Windows defined functions
//
# include <ntddk.h>
# include <ntstrsafe.h>
# include <Windef.h>
#endif // HYPERDBG_ENV_WINDOWS
//
// Scope definitions
//
#define HYPERDBG_KERNEL_MODE
#define HYPERDBG_HYPERPERF
//
// Add ia32-doc
//
#include "ia32-doc/out/ia32.h"
//
// SDK headers
//
#include "SDK/HyperDbgSdk.h"
//
// Configuration
//
#include "config/Configuration.h"
//
// Platform independent headers
//
#include "platform/kernel/header/PlatformMem.h"
#include "platform/kernel/header/PlatformIntrinsics.h"
#include "platform/kernel/header/PlatformBroadcast.h"
#include "platform/kernel/header/PlatformCpu.h"
#include "platform/kernel/header/PlatformSpinlock.h"
#include "platform/kernel/header/PlatformIrql.h"
#include "platform/kernel/header/PlatformDpc.h"
#include "platform/kernel/header/PlatformTime.h"
#include "platform/kernel/header/PlatformDbg.h"
#include "platform/kernel/header/PlatformIo.h"
#include "platform/kernel/header/PlatformEvent.h"
//
// Unload function (to be called when the driver is unloaded)
//
#include "common/UnloadDll.h"
//
// Hyperlog headers
//
#include "components/callback/header/HyperLogCallback.h"
#include "SDK/imports/kernel/HyperDbgHyperLogIntrinsics.h"
//
// Spinlock headers
//
#include "components/spinlock/header/Spinlock.h"
//
// HyperPerf Callbacks
//
#include "SDK/modules/HyperPerf.h"
//
// Definition of general tracing types
//
#include "api/PerfApi.h"
//
// DPC and broadcasting function headers
//
#include "broadcast/DpcRoutines.h"
#include "broadcast/Broadcast.h"
//
// Export functions
//
#include "SDK/imports/kernel/HyperDbgHyperPerf.h"
//
// Global variables
//
#include "globals/GlobalVariables.h"

View file

@ -0,0 +1,167 @@
/**
* @file Pt.h
* @author Masoud Rahimi Jafari (Masoodrahimy1379@gmail.com)
* @brief Header for Processor Trace (PT) tracing routines for HyperTrace module
* @details Engine that programs Intel PT MSRs from VMX root or kernel context.
* Buffer / ToPA management is kept here; user-visible PT structures
* live in the SDK header [PtDefinitions.h].
* @version 0.19
* @date 2026-04-29
*
* @copyright This project is released under the GNU Public License v3.
*/
#pragma once
//////////////////////////////////////////////////
// Constants //
//////////////////////////////////////////////////
//
// Pool tag for PT contiguous allocations (ASCII "PtHd")
//
#define POOL_TAG_PT 'dHtP'
//////////////////////////////////////////////////
// Structures //
//////////////////////////////////////////////////
/**
* @brief Narrow input descriptor for PtFilter.
*
* These are the only fields a caller is allowed to set per-CPU
* when reconfiguring an active PT trace. Engine-internal options
* (BranchEn, TscEn, MtcEn, CycEn, RetCompression, *Freq, etc.)
* stay under the engine's control and are NOT exposed here.
*
* BufferSize == 0 means "keep whatever the per-CPU slot already
* has" — pure filter changes don't touch the ToPA / output /
* overflow buffers and can run from a DPC.
*/
typedef struct _PT_FILTER_OPTIONS
{
BOOLEAN TraceUser;
BOOLEAN TraceKernel;
UINT64 TargetCr3;
UINT64 BufferSize;
UINT32 NumAddrRanges;
PT_ADDR_RANGE AddrRanges[PT_MAX_ADDR_RANGES];
} PT_FILTER_OPTIONS, *PPT_FILTER_OPTIONS;
/**
* @brief Per-CPU bookkeeping for the user-mode mmap surface.
*
* One MDL + user VA per CPU describes the main output buffer
* immediately followed by the 4 KB overflow page as a single
* virtually contiguous region in the mapping process. Lives in
* g_PtUserMappings; lifetime tied to the PT enable cycle.
*/
typedef struct _PT_USER_MAPPING
{
PMDL Mdl;
PVOID UserVa;
} PT_USER_MAPPING, *PPT_USER_MAPPING;
//////////////////////////////////////////////////
// Functions //
//////////////////////////////////////////////////
//
// HyperDbg-style wrappers (mirroring Lbr*)
//
BOOLEAN
PtCheck();
BOOLEAN
PtStart();
VOID
PtStop();
VOID
PtPause();
VOID
PtResume();
UINT64
PtSize();
VOID
PtDump();
VOID
PtFlush();
//
// LBR-style filter wrapper, one CPU at a time. Mirrors LbrFilter in shape:
// caller passes a PT_FILTER_OPTIONS describing only the user-tunable bits
// (TraceUser, TraceKernel, TargetCr3, BufferSize, NumAddrRanges, AddrRanges),
// and PtFilter handles the stop / config-update / start sequence on the
// CURRENT CPU. Engine-internal config (BranchEn, TscEn, etc.) is left
// untouched in the per-CPU PT_TRACE_CONFIG.
//
VOID
PtFilter(const PT_FILTER_OPTIONS * FilterOptions);
//
// PASSIVE_LEVEL helpers — call before / after the per-core DPC broadcasts.
// Required because MmAllocateContiguousMemorySpecifyCache and
// MmFreeContiguousMemory must run at IRQL == PASSIVE_LEVEL.
//
BOOLEAN
PtAllocateAllCpuBuffers();
VOID
PtFreeAllCpuBuffers();
//
// User-mode mmap surface: map every per-CPU main output + overflow
// buffer into the calling user process. Idempotent within an enable
// cycle; torn down by PtFreeAllCpuBuffers (i.e. PT disable / flush).
//
INT32
PtMmapAllCpuBuffersToUser(PT_USER_BUFFER_DESC * OutDescs, UINT32 MaxDescs, UINT32 * OutNumCpus);
VOID
PtUnmapAllCpuBuffersFromUser();
//
// Engine routines (operate on a specific PT_PER_CPU instance)
//
INT32
PtEngineQueryCapabilities(PT_CAPABILITIES * OutCaps);
VOID
PtEngineInitDefaultConfig(PT_TRACE_CONFIG * Config);
INT32
PtEngineAllocateBuffers(PT_PER_CPU * Cpu, const PT_TRACE_CONFIG * Config);
VOID
PtEngineFreeBuffers(PT_PER_CPU * Cpu);
INT32
PtEngineStart(PT_PER_CPU * Cpu);
UINT64
PtEngineStop(PT_PER_CPU * Cpu, PT_OUTPUT_BUFFER * Out);
INT32
PtEnginePause(PT_PER_CPU * Cpu);
INT32
PtEngineResume(PT_PER_CPU * Cpu);
UINT64
PtEngineHandlePmi(PT_PER_CPU * Cpu, PT_OUTPUT_BUFFER * Out);
BOOLEAN
PtEngineIsPtPmi();
INT32
PtEngineSizeToTopaEncoding(UINT64 SizeInBytes);

View file

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

View file

@ -0,0 +1,145 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Windows.SDK.CPP.x64.10.0.28000.1839\build\native\Microsoft.Windows.SDK.cpp.x64.props" Condition="Exists('..\packages\Microsoft.Windows.SDK.CPP.x64.10.0.28000.1839\build\native\Microsoft.Windows.SDK.cpp.x64.props')" />
<Import Project="..\packages\Microsoft.Windows.SDK.CPP.10.0.28000.1839\build\native\Microsoft.Windows.SDK.cpp.props" Condition="Exists('..\packages\Microsoft.Windows.SDK.CPP.10.0.28000.1839\build\native\Microsoft.Windows.SDK.cpp.props')" />
<Import Project="..\packages\Microsoft.Windows.WDK.x64.10.0.28000.1839\build\native\Microsoft.Windows.WDK.x64.props" Condition="Exists('..\packages\Microsoft.Windows.WDK.x64.10.0.28000.1839\build\native\Microsoft.Windows.WDK.x64.props')" />
<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>{360E54B1-0B92-4BCA-8111-4BF384292621}</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>hyperperf</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>Desktop</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>Desktop</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;$(SolutionDir)dependencies;%(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>hyperperf.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='release|x64'">
<DriverSign>
<FileDigestAlgorithm>sha256</FileDigestAlgorithm>
</DriverSign>
<ClCompile>
<AdditionalIncludeDirectories>$(SolutionDir)\include;$(ProjectDir)header;$(SolutionDir)dependencies;%(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>hyperperf.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<FilesToPackage Include="$(TargetPath)" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\include\components\callback\code\HyperLogCallback.c" />
<ClCompile Include="..\include\platform\kernel\code\PlatformBroadcast.c" />
<ClCompile Include="..\include\platform\kernel\code\PlatformCpu.c" />
<ClCompile Include="..\include\platform\kernel\code\PlatformIntrinsics.c" />
<ClCompile Include="..\include\platform\kernel\code\PlatformMem.c" />
<ClCompile Include="code\api\PerfApi.c" />
<ClCompile Include="code\broadcast\Broadcast.c" />
<ClCompile Include="code\broadcast\DpcRoutines.c" />
<ClCompile Include="code\common\UnloadDll.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\components\callback\header\HyperLogCallback.h" />
<ClInclude Include="..\include\platform\kernel\header\PlatformBroadcast.h" />
<ClInclude Include="..\include\platform\kernel\header\PlatformCpu.h" />
<ClInclude Include="..\include\platform\kernel\header\PlatformIntrinsics.h" />
<ClInclude Include="..\include\platform\kernel\header\PlatformMem.h" />
<ClInclude Include="header\api\PerfApi.h" />
<ClInclude Include="header\broadcast\Broadcast.h" />
<ClInclude Include="header\broadcast\DpcRoutines.h" />
<ClInclude Include="header\common\UnloadDll.h" />
<ClInclude Include="header\globals\GlobalVariables.h" />
<ClInclude Include="header\pch.h" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\Microsoft.Windows.SDK.CPP.10.0.28000.1839\build\native\Microsoft.Windows.SDK.cpp.targets" Condition="Exists('..\packages\Microsoft.Windows.SDK.CPP.10.0.28000.1839\build\native\Microsoft.Windows.SDK.cpp.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Windows.WDK.x64.10.0.28000.1839\build\native\Microsoft.Windows.WDK.x64.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.WDK.x64.10.0.28000.1839\build\native\Microsoft.Windows.WDK.x64.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.SDK.CPP.10.0.28000.1839\build\native\Microsoft.Windows.SDK.cpp.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.SDK.CPP.10.0.28000.1839\build\native\Microsoft.Windows.SDK.cpp.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.SDK.CPP.10.0.28000.1839\build\native\Microsoft.Windows.SDK.cpp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.SDK.CPP.10.0.28000.1839\build\native\Microsoft.Windows.SDK.cpp.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.SDK.CPP.x64.10.0.28000.1839\build\native\Microsoft.Windows.SDK.cpp.x64.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.SDK.CPP.x64.10.0.28000.1839\build\native\Microsoft.Windows.SDK.cpp.x64.props'))" />
</Target>
</Project>

View file

@ -0,0 +1,119 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<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>
<Filter Include="code\api">
<UniqueIdentifier>{09d5457a-bade-4a3f-a171-641110492d57}</UniqueIdentifier>
</Filter>
<Filter Include="code\broadcast">
<UniqueIdentifier>{b8b32a09-61fb-433a-ad79-eb7cfc5f3437}</UniqueIdentifier>
</Filter>
<Filter Include="code\common">
<UniqueIdentifier>{32ea8333-847b-443d-8992-4140d54dc1d3}</UniqueIdentifier>
</Filter>
<Filter Include="header\api">
<UniqueIdentifier>{df6eb164-34b2-4f2a-9530-b88443662fb7}</UniqueIdentifier>
</Filter>
<Filter Include="header\broadcast">
<UniqueIdentifier>{cb4e742a-6e43-4798-af4a-72bcb11089c9}</UniqueIdentifier>
</Filter>
<Filter Include="header\common">
<UniqueIdentifier>{ab21116d-5f5b-4ef8-82bb-6585ac3dec95}</UniqueIdentifier>
</Filter>
<Filter Include="header\globals">
<UniqueIdentifier>{57d56081-eede-41a3-b9f0-e7019d32c986}</UniqueIdentifier>
</Filter>
<Filter Include="code\components">
<UniqueIdentifier>{4f62540b-d186-479e-83a0-1b550134f487}</UniqueIdentifier>
</Filter>
<Filter Include="code\components\callback">
<UniqueIdentifier>{9fe877a7-e261-4579-9752-a3156b6e69d9}</UniqueIdentifier>
</Filter>
<Filter Include="header\components">
<UniqueIdentifier>{8bc2336a-b1c5-4e93-9793-23a5cfdc741d}</UniqueIdentifier>
</Filter>
<Filter Include="header\components\callback">
<UniqueIdentifier>{fc73555b-2be3-4898-bcdb-df83fa3e1388}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\include\platform\kernel\code\PlatformMem.c">
<Filter>code\platform</Filter>
</ClCompile>
<ClCompile Include="code\broadcast\Broadcast.c">
<Filter>code\broadcast</Filter>
</ClCompile>
<ClCompile Include="code\broadcast\DpcRoutines.c">
<Filter>code\broadcast</Filter>
</ClCompile>
<ClCompile Include="code\common\UnloadDll.c">
<Filter>code\common</Filter>
</ClCompile>
<ClCompile Include="code\api\PerfApi.c">
<Filter>code\api</Filter>
</ClCompile>
<ClCompile Include="..\include\platform\kernel\code\PlatformIntrinsics.c">
<Filter>code\platform</Filter>
</ClCompile>
<ClCompile Include="..\include\platform\kernel\code\PlatformBroadcast.c">
<Filter>code\broadcast</Filter>
</ClCompile>
<ClCompile Include="..\include\platform\kernel\code\PlatformCpu.c">
<Filter>code\platform</Filter>
</ClCompile>
<ClCompile Include="..\include\components\callback\code\HyperLogCallback.c">
<Filter>code\components\callback</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\platform\kernel\header\PlatformMem.h">
<Filter>header\platform</Filter>
</ClInclude>
<ClInclude Include="header\broadcast\Broadcast.h">
<Filter>header\broadcast</Filter>
</ClInclude>
<ClInclude Include="header\broadcast\DpcRoutines.h">
<Filter>header\broadcast</Filter>
</ClInclude>
<ClInclude Include="header\common\UnloadDll.h">
<Filter>header\common</Filter>
</ClInclude>
<ClInclude Include="header\globals\GlobalVariables.h">
<Filter>header\globals</Filter>
</ClInclude>
<ClInclude Include="header\api\PerfApi.h">
<Filter>header\api</Filter>
</ClInclude>
<ClInclude Include="..\include\platform\kernel\header\PlatformIntrinsics.h">
<Filter>header\platform</Filter>
</ClInclude>
<ClInclude Include="..\include\platform\kernel\header\PlatformBroadcast.h">
<Filter>header\platform</Filter>
</ClInclude>
<ClInclude Include="..\include\platform\kernel\header\PlatformCpu.h">
<Filter>header\platform</Filter>
</ClInclude>
<ClInclude Include="..\include\components\callback\header\HyperLogCallback.h">
<Filter>header\components\callback</Filter>
</ClInclude>
<ClInclude Include="header\pch.h">
<Filter>header</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Windows.SDK.CPP" version="10.0.28000.1839" targetFramework="native" />
<package id="Microsoft.Windows.SDK.CPP.x64" version="10.0.28000.1839" targetFramework="native" />
<package id="Microsoft.Windows.WDK.x64" version="10.0.28000.1839" targetFramework="native" />
</packages>

View file

@ -11,7 +11,7 @@
#include "pch.h"
/**
* @brief Initialize the hyper trace module callbacks
* @brief Initialize the hypertrace module callbacks
* @details This only for callback initialization, not for LBR, PT, etc. initialization
*
* @param HyperTraceCallbacks Pointer to the HyperTrace callbacks structure to be registered

View file

@ -0,0 +1,33 @@
/**
* @file HyperDbgHyperPerf.h
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief Headers relating exported functions from hyperperf (pmu) module
* @version 0.21
* @date 2026-06-22
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#pragma once
#ifdef HYPERDBG_HYPERPERF
# define IMPORT_EXPORT_HYPERPERF __declspec(dllexport)
#else
# define IMPORT_EXPORT_HYPERPERF __declspec(dllimport)
#endif
//////////////////////////////////////////////////
// HyperPerf Functions //
//////////////////////////////////////////////////
//
// Initialize the hyperperf module with the provided callbacks
//
IMPORT_EXPORT_HYPERPERF BOOLEAN
HyperPerfInitCallback(HYPERPERF_CALLBACKS * HyperPerfCallbacks, BOOLEAN RunningOnHypervisorEnvironment);
//
// Uninitialize the HyperPerf module
//
IMPORT_EXPORT_HYPERPERF VOID
HyperPerfUninit();

View file

@ -0,0 +1,80 @@
/**
* @file HyperPerf.h
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief HyperDbg's SDK for hyperperf project
* @details This file contains definitions of HyperPerf routines
* @version 0.21
* @date 2026-06-22
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#pragma once
//////////////////////////////////////////////////
// Callback Types //
//////////////////////////////////////////////////
/**
* @brief A function from the message tracer that send the inputs to the
* queue of the messages
*
*/
typedef BOOLEAN (*LOG_CALLBACK_PREPARE_AND_SEND_MESSAGE_TO_QUEUE)(UINT32 OperationCode,
BOOLEAN IsImmediateMessage,
BOOLEAN ShowCurrentSystemTime,
BOOLEAN Priority,
const CHAR * Fmt,
va_list ArgList);
/**
* @brief A function that sends the messages to message tracer buffers
*
*/
typedef BOOLEAN (*LOG_CALLBACK_SEND_MESSAGE_TO_QUEUE)(UINT32 OperationCode, BOOLEAN IsImmediateMessage, CHAR * LogMessage, UINT32 BufferLen, BOOLEAN Priority);
/**
* @brief A function that sends the messages to message tracer buffers
*
*/
typedef BOOLEAN (*LOG_CALLBACK_SEND_BUFFER)(_In_ UINT32 OperationCode,
_In_reads_bytes_(BufferLength) PVOID Buffer,
_In_ UINT32 BufferLength,
_In_ BOOLEAN Priority);
/**
* @brief A function that checks whether the priority or regular buffer is full or not
*
*/
typedef BOOLEAN (*LOG_CALLBACK_CHECK_IF_BUFFER_IS_FULL)(BOOLEAN Priority);
/**
* @brief A function that checks whether the current execution mode is VMX-root mode or not
*
*/
typedef BOOLEAN (*VM_FUNC_VMX_GET_CURRENT_EXECUTION_MODE)();
//////////////////////////////////////////////////
// Callback Structure //
//////////////////////////////////////////////////
/**
* @brief Prototype of each function needed by hyperperf module
*
*/
typedef struct _HYPERPERF_CALLBACKS
{
//
// *** Log (Hyperlog) callbacks ***
//
LOG_CALLBACK_PREPARE_AND_SEND_MESSAGE_TO_QUEUE LogCallbackPrepareAndSendMessageToQueueWrapper;
LOG_CALLBACK_SEND_MESSAGE_TO_QUEUE LogCallbackSendMessageToQueue;
LOG_CALLBACK_SEND_BUFFER LogCallbackSendBuffer;
LOG_CALLBACK_CHECK_IF_BUFFER_IS_FULL LogCallbackCheckIfBufferIsFull;
//
// *** Hypervisor (Hyperhv) callbacks ***
//
VM_FUNC_VMX_GET_CURRENT_EXECUTION_MODE VmFuncVmxGetCurrentExecutionMode;
} HYPERPERF_CALLBACKS, *PHYPERPERF_CALLBACKS;