HyperDbg Debugger
Loading...
Searching...
No Matches
Smm.c File Reference

Routines for operations related to System Management Mode (SMM). More...

#include "pch.h"

Functions

UINT64 SmmReadSmiCount ()
BOOLEAN SmmTriggerPowerSmi ()
BOOLEAN SmmPerformSmiOperation (SMI_OPERATION_PACKETS *SmiOperationRequest, BOOLEAN ApplyFromVmxRootMode)
 Perform actions related to System Management Interrupts (SMIs).

Detailed Description

Routines for operations related to System Management Mode (SMM).

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.15
Date
2025-08-02

Function Documentation

◆ SmmPerformSmiOperation()

BOOLEAN SmmPerformSmiOperation ( SMI_OPERATION_PACKETS * SmiOperationRequest,
BOOLEAN ApplyFromVmxRootMode )

Perform actions related to System Management Interrupts (SMIs).

Parameters
SmiOperationRequest
ApplyFromVmxRootMode
Returns
BOOLEAN
84{
85 BOOLEAN Status = FALSE;
86
87 UNREFERENCED_PARAMETER(ApplyFromVmxRootMode);
88
89 //
90 // Check the SMI operation type and perform the corresponding action
91 //
92 switch (SmiOperationRequest->SmiOperationType)
93 {
95
96 //
97 // Read the SMI count from the MSR
98 //
99 SmiOperationRequest->SmiCount = SmmReadSmiCount();
100
101 Status = TRUE;
102 break;
103
105
106 if (SmmTriggerPowerSmi())
107 {
108 //
109 // If the SMI was triggered successfully
110 //
111 Status = TRUE;
112 }
113 else
114 {
115 //
116 // If the SMI was not triggered successfully, set error status
117 //
119 }
120
121 break;
122
123 default:
124
125 Status = FALSE;
127
128 break;
129 }
130
131 //
132 // Set the status of the SMI operation request
133 //
134 if (Status)
135 {
136 SmiOperationRequest->KernelStatus = DEBUGGER_OPERATION_WAS_SUCCESSFUL;
137 }
138
139 return Status;
140}
UINT64 SmmReadSmiCount()
Definition Smm.c:21
BOOLEAN SmmTriggerPowerSmi()
Definition Smm.c:39
UCHAR BOOLEAN
Definition BasicTypes.h:35
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
#define DEBUGGER_ERROR_UNABLE_TO_TRIGGER_SMI
error, unable to trigger SMI
Definition ErrorCodes.h:576
#define DEBUGGER_ERROR_INVALID_SMI_OPERATION_PARAMETERS
error, invalid parameters for SMI operation request
Definition ErrorCodes.h:570
#define DEBUGGER_OPERATION_WAS_SUCCESSFUL
General value to indicate that the operation or request was successful.
Definition ErrorCodes.h:23
@ SMI_OPERATION_REQUEST_TYPE_READ_COUNT
Definition RequestStructures.h:1254
@ SMI_OPERATION_REQUEST_TYPE_TRIGGER_POWER_SMI
Definition RequestStructures.h:1255
UINT32 KernelStatus
Definition RequestStructures.h:1267
UINT64 SmiCount
Definition RequestStructures.h:1266
SMI_OPERATION_REQUEST_TYPE SmiOperationType
Definition RequestStructures.h:1265

◆ SmmReadSmiCount()

UINT64 SmmReadSmiCount ( )
22{
23 UINT64 SmiCount = 0;
24
25 //
26 // Read the SMI count from MSR
27 //
28 SmiCount = (UINT64)CpuReadMsr(MSR_SMI_COUNT);
29
30 return SmiCount;
31}
#define MSR_SMI_COUNT
MSR for System Management Interrupt (SMI) count.
Definition Msr.h:24
UINT64 CpuReadMsr(ULONG MsrAddress)
Read an MSR.
Definition PlatformIntrinsics.c:213

◆ SmmTriggerPowerSmi()

BOOLEAN SmmTriggerPowerSmi ( )
40{
41 UINT8 SmmResponse = 0;
42
43 //
44 // check the initial value received from 0xB3 port
45 //
46 SmmResponse = CpuIoInByte(0xb2);
47
48 //
49 // write to 0xB2 port to cause SMI
50 //
52
53 //
54 // Check the response in port 0xB3
55 //
56 SmmResponse = CpuIoInByte(0xb2);
57
58 if (SmmResponse == SMI_TRIGGER_POWER_VALUE)
59 {
60 //
61 // If the response is SMI_TRIGGER_POWER_VALUE, it means the SMI was triggered successfully
62 //
63 return TRUE;
64 }
65 else
66 {
67 //
68 // If the response is not SMI_TRIGGER_POWER_VALUE, it means the SMI was not triggered successfully
69 //
70 return FALSE;
71 }
72}
UINT8 CpuIoInByte(UINT16 Port)
Read a byte from an I/O port.
Definition PlatformIntrinsics.c:573
VOID CpuIoOutByte(UINT16 Port, UINT8 Value)
Write a byte to an I/O port.
Definition PlatformIntrinsics.c:690
#define SMI_TRIGGER_POWER_VALUE
SMI trigger port value.
Definition Smm.h:23
unsigned char UINT8
Definition BasicTypes.h:52