create different function separations for DPCs and Broadcasting routines

This commit is contained in:
sina 2026-04-19 19:34:13 +02:00
parent 43cdab9821
commit 6e511c8368
10 changed files with 245 additions and 131 deletions

View file

@ -0,0 +1,40 @@
/**
* @file Broadcast.c
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief Broadcasting functions
*
* @version 0.19
* @date 2026-04-19
*
* @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(DpcRoutineEnableLbr, NULL);
}
/**
* @brief Routines to disable LBR on all cores
*
* @return VOID
*/
VOID
BroadcastDisableLbrOnAllCores()
{
//
// Broadcast to all cores
//
KeGenericCallDpc(DpcRoutineDisableLbr, NULL);
}

View file

@ -0,0 +1,94 @@
/**
* @file DpcRoutines.c
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief DPC routines
*
* @version 0.19
* @date 2026-04-19
*
* @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
DpcRoutineEnableLbr(KDPC * Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
{
LBR_IOCTL_REQUEST * CurrentRequest;
UNREFERENCED_PARAMETER(Dpc);
UNREFERENCED_PARAMETER(DeferredContext);
//
// Get the current request (for current core)
//
CurrentRequest = &g_LbrRequestState[KeGetCurrentProcessorNumberEx(NULL)];
//
// Enable LBR on all cores from VMX-root mode by VMCALL
//
// LbrStartLbr(CurrentRequest, TRUE, TRUE);
HyperTraceExamplePerformLbrTrace(TRUE, TRUE);
//
// Wait for all DPCs to synchronize at this point
//
KeSignalCallDpcSynchronize(SystemArgument2);
//
// Mark the DPC as being complete
//
KeSignalCallDpcDone(SystemArgument1);
return TRUE;
}
/**
* @brief Broadcast disabling LBR
*
* @param Dpc
* @param DeferredContext
* @param SystemArgument1
* @param SystemArgument2
* @return BOOLEAN
*/
BOOLEAN
DpcRoutineDisableLbr(KDPC * Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
{
LBR_IOCTL_REQUEST * CurrentRequest;
UNREFERENCED_PARAMETER(Dpc);
UNREFERENCED_PARAMETER(DeferredContext);
//
// Get the current request (for current core)
//
CurrentRequest = &g_LbrRequestState[KeGetCurrentProcessorNumberEx(NULL)];
//
// Disable LBR on all cores from VMX-root mode by VMCALL
//
LbrStopLbr(CurrentRequest, TRUE, TRUE);
//
// Wait for all DPCs to synchronize at this point
//
KeSignalCallDpcSynchronize(SystemArgument2);
//
// Mark the DPC as being complete
//
KeSignalCallDpcDone(SystemArgument1);
return TRUE;
}

View file

@ -10,24 +10,6 @@
*/
#include "pch.h"
/**
* @brief The flag indicating whether the hypertrace module callbacks is initialized or not
*
*/
BOOLEAN g_HyperTraceCallbacksInitialized = FALSE;
/**
* @brief The flag indicating whether the hypertrace LBR tracing is initialized or not
*
*/
BOOLEAN g_LastBranchRecordEnabled = FALSE;
/**
* @brief Core specific state
*
*/
LBR_IOCTL_REQUEST * g_LbrRequestState = NULL;
/**
* @brief Example of performing LBR trace
*
@ -195,116 +177,6 @@ HyperTraceInitCallback(HYPERTRACE_CALLBACKS * HypertraceCallbacks)
return TRUE;
}
/**
* @brief Broadcast enabling LBR
*
* @param Dpc
* @param DeferredContext
* @param SystemArgument1
* @param SystemArgument2
* @return BOOLEAN
*/
BOOLEAN
DpcRoutineEnableLbr(KDPC * Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
{
LBR_IOCTL_REQUEST * CurrentRequest;
UNREFERENCED_PARAMETER(Dpc);
UNREFERENCED_PARAMETER(DeferredContext);
//
// Get the current request (for current core)
//
CurrentRequest = &g_LbrRequestState[KeGetCurrentProcessorNumberEx(NULL)];
//
// Enable LBR on all cores from VMX-root mode by VMCALL
//
// LbrStartLbr(CurrentRequest, TRUE, TRUE);
HyperTraceExamplePerformLbrTrace(TRUE, TRUE);
//
// Wait for all DPCs to synchronize at this point
//
KeSignalCallDpcSynchronize(SystemArgument2);
//
// Mark the DPC as being complete
//
KeSignalCallDpcDone(SystemArgument1);
return TRUE;
}
/**
* @brief Routines to enable LBR on all cores
*
* @return VOID
*/
VOID
BroadcastEnableLbrOnAllCores()
{
//
// Broadcast to all cores
//
KeGenericCallDpc(DpcRoutineEnableLbr, NULL);
}
/**
* @brief Broadcast disabling LBR
*
* @param Dpc
* @param DeferredContext
* @param SystemArgument1
* @param SystemArgument2
* @return BOOLEAN
*/
BOOLEAN
DpcRoutineDisableLbr(KDPC * Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
{
LBR_IOCTL_REQUEST * CurrentRequest;
UNREFERENCED_PARAMETER(Dpc);
UNREFERENCED_PARAMETER(DeferredContext);
//
// Get the current request (for current core)
//
CurrentRequest = &g_LbrRequestState[KeGetCurrentProcessorNumberEx(NULL)];
//
// Disable LBR on all cores from VMX-root mode by VMCALL
//
LbrStopLbr(CurrentRequest, TRUE, TRUE);
//
// Wait for all DPCs to synchronize at this point
//
KeSignalCallDpcSynchronize(SystemArgument2);
//
// Mark the DPC as being complete
//
KeSignalCallDpcDone(SystemArgument1);
return TRUE;
}
/**
* @brief Routines to disable LBR on all cores
*
* @return VOID
*/
VOID
BroadcastDisableLbrOnAllCores()
{
//
// Broadcast to all cores
//
KeGenericCallDpc(DpcRoutineDisableLbr, NULL);
}
/**
* @brief Enable LBR tracing for HyperTrace
*

View file

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

View file

@ -4,8 +4,8 @@
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief Definition for Windows DPC functions
* @details
* @version 0.1
* @date 2020-04-10
* @version 0.19
* @date 2026-04-19
*
* @copyright This project is released under the GNU Public License v3.
*

View file

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

View file

@ -0,0 +1,35 @@
/**
* @file GlobalVariables.h
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief Definition for global variables
* @details
* @version 0.19
* @date 2026-04-19
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#pragma once
//////////////////////////////////////////////////
// Global Variables //
//////////////////////////////////////////////////
/**
* @brief The flag indicating whether the hypertrace module callbacks is initialized or not
*
*/
BOOLEAN g_HyperTraceCallbacksInitialized;
/**
* @brief The flag indicating whether the hypertrace LBR tracing is initialized or not
*
*/
BOOLEAN g_LastBranchRecordEnabled;
/**
* @brief Core specific state
*
*/
LBR_IOCTL_REQUEST * g_LbrRequestState;

View file

@ -43,9 +43,11 @@
#include "ia32-doc/out/ia32.h"
//
// DPC headers
// DPC and broadcasting function headers
//
#include "Dpc.h"
#include "DpcRoutines.h"
#include "Broadcast.h"
//
// Unload function (to be called when the driver is unloaded)
@ -93,3 +95,8 @@
// Export functions
//
#include "SDK/imports/kernel/HyperDbgHyperTrace.h"
//
// Global variables
//
#include "GlobalVariables.h"

View file

@ -103,6 +103,8 @@
<ClCompile Include="..\include\components\interface\HyperLogCallback.c" />
<ClCompile Include="..\include\components\spinlock\code\Spinlock.c" />
<ClCompile Include="..\include\platform\kernel\code\PlatformMem.c" />
<ClCompile Include="code\Broadcast.c" />
<ClCompile Include="code\DpcRoutines.c" />
<ClCompile Include="code\Lbr.c" />
<ClCompile Include="code\Tracing.c" />
<ClCompile Include="code\UnloadDll.c" />
@ -112,7 +114,10 @@
<ClInclude Include="..\include\components\spinlock\header\Spinlock.h" />
<ClInclude Include="..\include\platform\kernel\header\Environment.h" />
<ClInclude Include="..\include\platform\kernel\header\PlatformMem.h" />
<ClInclude Include="header\Broadcast.h" />
<ClInclude Include="header\Dpc.h" />
<ClInclude Include="header\DpcRoutines.h" />
<ClInclude Include="header\GlobalVariables.h" />
<ClInclude Include="header\Lbr.h" />
<ClInclude Include="header\Tracing.h" />
<ClInclude Include="header\pch.h" />

View file

@ -41,6 +41,12 @@
<ClCompile Include="code\Lbr.c">
<Filter>code</Filter>
</ClCompile>
<ClCompile Include="code\Broadcast.c">
<Filter>code</Filter>
</ClCompile>
<ClCompile Include="code\DpcRoutines.c">
<Filter>code</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="header\Tracing.h">
@ -70,5 +76,14 @@
<ClInclude Include="header\Dpc.h">
<Filter>header</Filter>
</ClInclude>
<ClInclude Include="header\Broadcast.h">
<Filter>header</Filter>
</ClInclude>
<ClInclude Include="header\DpcRoutines.h">
<Filter>header</Filter>
</ClInclude>
<ClInclude Include="header\GlobalVariables.h">
<Filter>header</Filter>
</ClInclude>
</ItemGroup>
</Project>