mirror of
https://github.com/HyperDbg/HyperDbg.git
synced 2026-07-09 17:19:26 +00:00
create different function separations for DPCs and Broadcasting routines
This commit is contained in:
parent
43cdab9821
commit
6e511c8368
10 changed files with 245 additions and 131 deletions
40
hyperdbg/hypertrace/code/Broadcast.c
Normal file
40
hyperdbg/hypertrace/code/Broadcast.c
Normal 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);
|
||||
}
|
||||
94
hyperdbg/hypertrace/code/DpcRoutines.c
Normal file
94
hyperdbg/hypertrace/code/DpcRoutines.c
Normal 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;
|
||||
}
|
||||
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
23
hyperdbg/hypertrace/header/Broadcast.h
Normal file
23
hyperdbg/hypertrace/header/Broadcast.h
Normal 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();
|
||||
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
23
hyperdbg/hypertrace/header/DpcRoutines.h
Normal file
23
hyperdbg/hypertrace/header/DpcRoutines.h
Normal 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);
|
||||
35
hyperdbg/hypertrace/header/GlobalVariables.h
Normal file
35
hyperdbg/hypertrace/header/GlobalVariables.h
Normal 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;
|
||||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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" />
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
Loading…
Add table
Add a link
Reference in a new issue