This commit is contained in:
lhodges1 2023-08-21 22:40:40 +10:00
parent 5163bc14dd
commit bdb267e42b
6 changed files with 66 additions and 2 deletions

View file

@ -4,6 +4,9 @@
#include "ioctl.h"
#include "callbacks.h"
#include "hv.h"
PVOID callback_registration_handle;
LONG protected_process_id;

View file

@ -127,6 +127,7 @@
<ItemGroup>
<ClCompile Include="callbacks.c" />
<ClCompile Include="driver.c" />
<ClCompile Include="hv.c" />
<ClCompile Include="ioctl.c" />
<ClCompile Include="modules.c" />
<ClCompile Include="nmi.c" />
@ -136,6 +137,7 @@
<ClInclude Include="callbacks.h" />
<ClInclude Include="common.h" />
<ClInclude Include="driver.h" />
<ClInclude Include="hv.h" />
<ClInclude Include="ioctl.h" />
<ClInclude Include="modules.h" />
<ClInclude Include="nmi.h" />

View file

@ -42,6 +42,9 @@
<ClCompile Include="queue.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="hv.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="driver.h">
@ -65,5 +68,8 @@
<ClInclude Include="queue.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="hv.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

43
driver/hv.c Normal file
View file

@ -0,0 +1,43 @@
#include "hv.h"
#include <intrin.h>
#include "common.h"
#define TOTAL_ITERATION_COUNT 20
#define IA32_APERF_MSR 0x000000E8
/*
* 1. Bind thread to a single core
* 2. Raise the IRQL to HIGH_LEVEL
* 3. disable interrupts
*/
VOID APERFMsrTimingCheck()
{
ULONG64 old_irql;
INT cpuid_result[ 4 ];
old_irql = __readcr8();
__writecr8( HIGH_LEVEL );
_disable();
UINT64 aperf_before = __readmsr( IA32_APERF_MSR ) << 32;
__cpuid( cpuid_result, 1 );
UINT64 aperf_after = __readmsr( IA32_APERF_MSR ) << 32;
_enable();
__writecr8( old_irql );
UINT64 aperf_delta = aperf_after - aperf_before;
_enable();
DEBUG_LOG( "delta: %llx", aperf_delta );
}

8
driver/hv.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef HV_H
#define HV_H
#include <ntifs.h>
VOID APERFMsrTimingCheck();
#endif

View file

@ -7,6 +7,8 @@
#include "driver.h"
#include "callbacks.h"
#include "hv.h"
NTSTATUS DeviceControl(
_In_ PDRIVER_OBJECT DriverObject,
_In_ PIRP Irp
@ -40,8 +42,6 @@ NTSTATUS DeviceControl(
* it will issue a bug check under windows driver verifier.
*/
DEBUG_LOG( "irp addr: %p", ( void* )Irp );
status = PsCreateSystemThread(
&handle,
PROCESS_ALL_ACCESS,
@ -98,6 +98,8 @@ NTSTATUS DeviceControl(
case IOCTL_HANDLE_REPORTS_IN_CALLBACK_QUEUE:
APERFMsrTimingCheck();
status = HandlePeriodicCallbackReportQueue(Irp);
if ( !NT_SUCCESS( status ) )