Hook headers for Mode-based execution.  
More...
Go to the source code of this file.
Hook headers for Mode-based execution. 
- Author
- Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
- Version
- 0.2 
- Date
- 2023-03-17
- Copyright
- This project is released under the GNU Public License v3. 
◆ MAX_PHYSICAL_RAM_RANGE_COUNT
      
        
          | #define MAX_PHYSICAL_RAM_RANGE_COUNT   32 | 
      
 
 
◆ MODE_BASED_RAM_REGIONS
      
        
          | typedef struct MODE_BASED_RAM_REGIONS MODE_BASED_RAM_REGIONS | 
      
 
 
◆ PMODE_BASED_RAM_REGIONS
◆ ModeBasedExecHookDisableKernelModeExecution()
Adjust (unset) kernel-mode execution bit of target page-table but allow user-mode execution. 
should be called from vmx non-root mode 
- Parameters
- 
  
  
- Returns
- BOOLEAN 
   68{
   69    
   70    
   71    
   72    
   73    
   74    
   75    
   76 
   77    
   78    
   79    
   81    {
   82        EptTable->
PML4[i].UserModeExecute = 
TRUE;
 
   83 
   84        
   85        
   86        
   88    }
   89 
   90    
   91    
   92    
   94    {
   95        EptTable->
PML3[i].UserModeExecute = 
TRUE;
 
   96    }
   97 
   98    
   99    
  100    
  102    {
  104        {
  105            EptTable->
PML2[i][j].UserModeExecute = 
TRUE;
 
  106        }
  107    }
  108 
  110}
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
EPT_PML4_POINTER PML4[VMM_EPT_PML4E_COUNT]
28.2.2 Describes 512 contiguous 512GB memory regions each with 512 1GB regions.
Definition State.h:110
EPT_PML3_POINTER PML3[VMM_EPT_PML3E_COUNT]
Describes exactly 512 contiguous 1GB memory regions within a our singular 512GB PML4 region.
Definition State.h:116
EPT_PML2_ENTRY PML2[VMM_EPT_PML3E_COUNT][VMM_EPT_PML2E_COUNT]
For each 1GB PML3 entry, create 512 2MB entries to map identity. NOTE: We are using 2MB pages as the ...
Definition State.h:124
 
 
◆ ModeBasedExecHookDisableUserModeExecution()
Adjust (unset) user-mode execution bit of target page-table. 
should be called from vmx non-root mode 
- Parameters
- 
  
  
- Returns
- BOOLEAN 
   24{
   25    
   26    
   27    
   29    {
   30        
   31        
   32        
   33        EptTable->
PML4[i].UserModeExecute = 
FALSE;
 
   34    }
   35 
   36    
   37    
   38    
   40    {
   41        EptTable->
PML3[i].UserModeExecute = 
TRUE;
 
   42    }
   43 
   44    
   45    
   46    
   48    {
   50        {
   51            EptTable->
PML2[i][j].UserModeExecute = 
TRUE;
 
   52        }
   53    }
   54 
   56}
 
 
◆ ModeBasedExecHookEnableOrDisable()
Enable/disable MBEC. 
- Parameters
- 
  
    | VCpu | The virtual processor's state |  
 
- Returns
- VOID 
  162{
  163    if (State == 0x0)
  164    {
  166 
  167        
  168        
  169        
  171    }
  172    else
  173    {
  175    }
  176}
VOID HvSetModeBasedExecutionEnableFlag(BOOLEAN Set)
Set Mode-based Execution Control (MBEC) Enable bit.
Definition Hv.c:677
BOOLEAN MbecEnabled
Definition State.h:301
 
 
◆ ModeBasedExecHookInitialize()
      
        
          | BOOLEAN ModeBasedExecHookInitialize | ( |  | ) |  | 
      
 
Initialize the needed structure for hooking mode execution. 
should be called from vmx non-root mode
- Returns
- BOOLEAN 
  186{
  187    ULONG ProcessorsCount;
 
  188 
  189    
  190    
  191    
  192    ProcessorsCount = KeQueryActiveProcessorCount(0);
  193 
  194    
  195    
  196    
  198    {
  200    }
  201 
  202    
  203    
  204    
  206    {
  208    }
  209 
  210    
  211    
  212    
  214    {
  216    }
  217 
  218    
  219    
  220    
  221    for (size_t i = 0; i < ProcessorsCount; i++)
  222    {
  224    }
  225 
  226    
  227    
  228    
  229    
  231 
  232    
  233    
  234    
  236 
  238}
unsigned long ULONG
Definition BasicTypes.h:37
VOID BroadcastNotifyAllToInvalidateEptAllCores()
routines to notify to invalidate their ept on all cores
Definition Broadcast.c:119
VIRTUAL_MACHINE_STATE * g_GuestState
Save the state and variables related to virtualization on each to logical core.
Definition GlobalVariables.h:38
BOOLEAN g_ModeBasedExecutionControlState
Enable interception of Cr3 for Mode-based Execution detection.
Definition GlobalVariables.h:120
COMPATIBILITY_CHECKS_STATUS g_CompatibilityCheck
Different attributes and compatibility checks of the current processor.
Definition GlobalVariables.h:26
BOOLEAN ModeBasedExecHookEnableUsermodeExecution(PVMM_EPT_PAGE_TABLE EptTable)
Enables user-mode execution bit of target page-table.
Definition ModeBasedExecHook.c:119
BOOLEAN ModeBasedExecutionSupport
Definition CompatibilityChecks.h:28
BOOLEAN ExecuteOnlySupport
Definition CompatibilityChecks.h:29
 
 
◆ ModeBasedExecHookUninitialize()
      
        
          | VOID ModeBasedExecHookUninitialize | ( |  | ) |  | 
      
 
Uinitialize the needed structure for hooking mode execution. 
should be called from vmx non-root mode
- Returns
- VOID 
  248{
  249    
  250    
  251    
  253 
  254    
  255    
  256    
  258}
VOID BroadcasDisableMbecOnAllProcessors()
routines for disabling MBEC
Definition Broadcast.c:469
 
 
◆ PhysicalRamRegions