14 #define CFG_CHECK_MTRR_ON_MAPS 84 memzero(&gIface,
sizeof(gIface));
85 memzero(&gUpIface,
sizeof(gUpIface));
132 if ((gIface.
Size) || (gUpIface.
Size))
143 if ((NULL == GlueInterface->QueryGuestInfo) ||
144 (NULL == GlueInterface->PhysMemMapToHost) ||
145 (NULL == GlueInterface->PhysMemUnmap) ||
146 (NULL == GlueInterface->RegisterMSRHandler) ||
147 (NULL == GlueInterface->UnregisterMSRHandler) ||
148 (NULL == GlueInterface->RegisterEPTHandler) ||
149 (NULL == GlueInterface->UnregisterEPTHandler) ||
150 (NULL == GlueInterface->GetEPTPageProtection) ||
151 (NULL == GlueInterface->SetEPTPageProtection) ||
152 (NULL == GlueInterface->PhysMemGetTypeFromMtrrs) ||
153 (NULL == GlueInterface->EnableMSRExit) ||
154 (NULL == GlueInterface->DisableMSRExit) ||
155 (NULL == GlueInterface->PauseVcpus) ||
156 (NULL == GlueInterface->ResumeVcpus) ||
157 (NULL == GlueInterface->GpaToHpa) ||
158 (NULL == GlueInterface->RegisterIntroTimerHandler) ||
159 (NULL == GlueInterface->UnregisterIntroTimerHandler) ||
160 (NULL == GlueInterface->RegisterIntroCallHandler) ||
161 (NULL == GlueInterface->UnregisterIntroCallHandler) ||
162 (NULL == GlueInterface->RegisterDtrHandler) ||
163 (NULL == GlueInterface->UnregisterDtrHandler) ||
164 (NULL == GlueInterface->InjectTrap) ||
165 (NULL == GlueInterface->SetIntroEmulatorContext) ||
166 (NULL == GlueInterface->RegisterXcrWriteHandler) ||
167 (NULL == GlueInterface->UnregisterXcrWriteHandler) ||
168 (NULL == GlueInterface->RegisterCrWriteHandler) ||
169 (NULL == GlueInterface->UnregisterCrWriteHandler) ||
170 (NULL == GlueInterface->EnableCrWriteExit) ||
171 (NULL == GlueInterface->DisableCrWriteExit) ||
172 (NULL == GlueInterface->NotifyIntrospectionAlert) ||
173 (NULL == GlueInterface->RegisterBreakpointHandler) ||
174 (NULL == GlueInterface->UnregisterBreakpointHandler) ||
175 (NULL == GlueInterface->ReleaseBuffer))
186 if ((NULL == UpperInterface->TracePrint) ||
187 (NULL == UpperInterface->MemAllocWithTagAndInfo) ||
188 (NULL == UpperInterface->MemFreeWithTagAndInfo) ||
189 (NULL == UpperInterface->SpinLockInit) ||
190 (NULL == UpperInterface->SpinLockUnInit) ||
191 (NULL == UpperInterface->SpinLockAcquire) ||
192 (NULL == UpperInterface->SpinLockRelease) ||
193 (NULL == UpperInterface->RwSpinLockInit) ||
194 (NULL == UpperInterface->RwSpinLockUnInit) ||
195 (NULL == UpperInterface->RwSpinLockAcquireExclusive) ||
196 (NULL == UpperInterface->RwSpinLockAcquireShared) ||
197 (NULL == UpperInterface->RwSpinLockReleaseExclusive) ||
198 (NULL == UpperInterface->RwSpinLockReleaseShared) ||
199 (NULL == UpperInterface->BugCheck) ||
200 (NULL == UpperInterface->EnterDebugger))
205 memcpy(&gIface, GlueInterface,
sizeof(gIface));
206 memcpy(&gUpIface, UpperInterface,
sizeof(gUpIface));
301 #ifdef CFG_CHECK_MTRR_ON_MAPS 315 #endif // CFG_CHECK_MTRR_ON_MAPS 323 freeSlot = (firstFreeIndex * 64ull) + pos;
325 pPageTable[freeSlot] = ((hpa &
PHYS_PAGE_MASK) | (pPageTable[freeSlot] & 0xFFCULL) | 0x003);
390 Flags &= ~PHYS_MAP_FLG_NO_FASTMAP;
419 QWORD currentSlot, *pPageTable;
427 gPageBitmap[currentSlot / 64] &= ~(1ULL << (currentSlot % 64));
429 pPageTable[currentSlot] = (pPageTable[currentSlot] & 0xFFCULL);
441 ERROR(
"[ERROR] gIface.PhysMemUnmap failed for (%p %p): 0x%08x\n", HostPtr, *HostPtr, status);
824 _Inout_ _At_(*SpinLock, _Post_null_)
void **SpinLock
840 CRITICAL(
"[ERROR] SpinLockAcquire failed: 0x%08x\n", status);
855 CRITICAL(
"[ERROR] SpinLockRelease failed: 0x%08x\n", status);
873 _Inout_ _At_(*SpinLock, _Post_null_)
void **SpinLock
1045 _In_ size_t EventSize
1113 _Out_ size_t *TotalHeapSize,
1114 _Out_ size_t *FreeHeapSize
1119 *TotalHeapSize = 0xFFFFFFFF;
1120 *FreeHeapSize = 0xFFFFFFFF;
1131 _In_ char const *Message
1301 #ifdef INT_COMPILER_MSVC 1303 __attribute__((malloc))
1304 __attribute__ ((alloc_size (1)))
1310 _In_ const char *FileName,
1337 "[ERROR] MemAllocWithTagAndInfo failed in file '%s:%d' for size 0x%llx: 0x%08x\n",
1338 FileName, FileLine, Length, status);
1351 void **addr = &Address;
INTSTATUS IntDisableCrWriteExit(DWORD Cr)
INTSTATUS IntUnregisterEPTHandler(void)
INTSTATUS IntSpinLockInit(void **SpinLock, char *Name)
INTSTATUS IntUnregisterCrWriteHandler(void)
PFUNC_IntUnregisterBreakpointHandler UnregisterBreakpointHandler
PFUNC_IntQueryHeapSize QueryHeapSize
PFUNC_IntUnregisterIntroCallHandler UnregisterIntroCallHandler
INTSTATUS IntNotifyIntroEvent(INTRO_EVENT_TYPE EventClass, void *Param, size_t EventSize)
Notifies the integrator about an introspection alert.
PFUNC_IntNotifyIntrospectionDetectedOs NotifyIntrospectionDetectedOs
static INTSTATUS IntPhysMemFastMap(QWORD PhysAddress, void **HostPtr)
Maps a guest physical address using the fast map mechanism.
PFUNC_IntRegisterXcrWriteHandler RegisterXcrWriteHandler
BOOLEAN GlueIsVeApiAvailable(void)
Checks if the virtualization exception API is implemented.
PFUNC_IntGetEPTPageProtection GetEPTPageProtection
PFUNC_IntUnregisterDescriptorTableHandler UnregisterDtrHandler
#define GLUE_IFACE_VERSION_LATEST
static uint8_t _BitScanForward64(uint32_t *Index, uint64_t Mask)
INTSTATUS IntUnregisterXcrWriteHandler(void)
INTSTATUS IntSendMessage(char const *Message)
Sends an Introcore message.
#define INT_STATUS_SUCCESS
INTSTATUS IntUnregisterIntroCallHandler(void)
PFUNC_IntGetAgentContent GetAgentContent
static GLUE_IFACE gIface
The instance of the GLUE_IFACE that is being used.
#define INT_STATUS_OUT_OF_RESOURCES
PFUNC_HpFreeWithTagAndInfo MemFreeWithTagAndInfo
#define _Out_writes_bytes_(expr)
INTSTATUS PRINTF_ATTRIBUTE(* PFUNC_IntTracePrint)(const CHAR *File, DWORD Line, const CHAR *Format,...)
Provides print-like trace functionality for introcore.
PFUNC_IntRegisterVmxTimerHandler RegisterIntroTimerHandler
PFUNC_IntPhysMemUnmap PhysMemUnmap
PFUNC_IntUnregisterVmxTimerHandler UnregisterIntroTimerHandler
PFUNC_IntRequestVcpusResume ResumeVcpus
INTSTATUS IntPhysMemMap(QWORD PhysAddress, DWORD Length, DWORD Flags, void **HostPtr)
Maps a guest physical address inside Introcore VA space.
PFUNC_IntInjectTrap InjectTrap
INTSTATUS IntNotifyEngines(void *Parameters)
BOOLEAN GlueIsSppApiAvailable(void)
Checks if the SPP APIs in GLUE_IFACE are implemented.
Interface that exposes basic services to the introspection engines.
#define INT_SUCCESS(Status)
INTSTATUS IntUnregisterBreakpointHandler(void)
DWORD gFastPaPagesCount
The number of pages reserved for the fast map zone.
INTSTATUS IntResumeVcpus(void)
Resumes the VCPUs previously paused with IntPauseVcpus.
PFUNC_HpAllocWithTagAndInfo MemAllocWithTagAndInfo
PFUNC_IntCreateEPT CreateEPT
INTSTATUS IntUnregisterEnginesResultCalback(void)
Thin wrapper over the optional GLUE_IFACE.UnregisterEnginesResultCalback API.
PFUNC_IntGetEPTPageConvertible GetEPTPageConvertible
INTSTATUS IntNotifyIntroInactive(void)
INTSTATUS IntRwSpinLockUnInit(void **SpinLock)
QWORD gEventId
The ID of the current event.
PFUNC_IntRwSpinLockAcquireShared RwSpinLockAcquireShared
PFUNC_IntDestroyEPT DestroyEPT
INTSTATUS IntUnregisterEventInjectionHandler(void)
INTSTATUS(* PFUNC_IntEPTViolationCallback)(void *GuestHandle, QWORD PhysicalAddress, DWORD Length, QWORD VirtualAddress, DWORD CpuNumber, INTRO_ACTION *Action, IG_EPT_ACCESS Type)
PFUNC_IntRwSpinLockReleaseShared RwSpinLockReleaseShared
INTSTATUS IntRegisterEnginesResultCallback(PFUNC_IntEventEnginesResultCallback Callback)
Thin wrapper over the optional GLUE_IFACE.RegisterEnginesResultCallback API.
#define INT_STATUS_NOT_NEEDED_HINT
Plain text message sent from Introcore to the integrator. See EVENT_INTROSPECTION_MESSAGE.
void * gFastPaPageBase
The base of the fast map memory region.
PFUNC_IntPhysMemMapToHost PhysMemMapToHost
#define PHYS_MAP_FLG_NO_FASTMAP
Indicates that IntPhysMemMap should not use the fast memory mapping mechanism.
int INTSTATUS
The status data type.
#define UPPER_IFACE_VERSION_LATEST
INTSTATUS IntRegisterIntroCallHandler(PFUNC_IntIntroCallCallback Callback)
INTSTATUS IntSetVEInfoPage(DWORD CpuNumber, QWORD VeInfoGpa)
INTSTATUS IntNotifyIntroErrorState(INTRO_ERROR_STATE State, INTRO_ERROR_CONTEXT *Context)
PFUNC_IntRwSpinLockAcquireExclusive RwSpinLockAcquireExclusive
INTSTATUS IntRegisterDtrHandler(PFUNC_IntIntroDescriptorTableCallback Callback)
PFUNC_IntRegisterMSRHandler RegisterMSRHandler
#define PAGE_COUNT(addr, bytes)
PFUNC_IntRwSpinLockUnInit RwSpinLockUnInit
INTSTATUS(* PFUNC_IntMSRViolationCallback)(void *GuestHandle, DWORD Msr, IG_MSR_HOOK_TYPE Flags, INTRO_ACTION *Action, QWORD OriginalValue, QWORD *NewValue, DWORD CpuNumber)
INTSTATUS IntPauseVcpus(void)
Pauses all the guest VCPUs.
INTSTATUS IntGetAgentContent(DWORD AgentTag, BOOLEAN Is64, DWORD *Size, BYTE **Content)
INTSTATUS IntAlertCreateExceptionInEvent(void *Event, INTRO_EVENT_TYPE Type)
This function creates an alert-exception for each alert sent to the integrator.
INTSTATUS IntRegisterEventInjectionHandler(PFUNC_IntEventInjectionCallback Callback)
#define INT_STATUS_OPERATION_NOT_IMPLEMENTED
Interface used for communicating between the introspection engine and the integrator.
PFUNC_IntUnregisterEPTHandler UnregisterEPTHandler
INTSTATUS IntGpaToHpa(QWORD Gpa, QWORD *Hpa)
INTSTATUS IntEnableCrWriteExit(DWORD Cr)
PFUNC_IntBugCheck BugCheck
INTSTATUS IntPhysMemUnmap(void **HostPtr)
Unmaps an address previously mapped with IntPhysMemMap.
PFUNC_IntDisableCrWriteExit DisableCrWriteExit
INTSTATUS(* PFUNC_IntIntroDescriptorTableCallback)(void *GuestHandle, DWORD Flags, DWORD CpuNumber, INTRO_ACTION *Action)
INTSTATUS IntNotifyIntroDetectedOs(INTRO_GUEST_TYPE OsType, DWORD OsVersion, BOOLEAN Is64)
Wrapper over GLUE_IFACE.NotifyIntrospectionDetectedOs.
INTSTATUS IntSetEPTPageConvertible(DWORD EptIndex, QWORD Address, BOOLEAN Convertible)
PFUNC_IntRegisterBreakpointHandler RegisterBreakpointHandler
PFUNC_IntSpinLockAcquire SpinLockAcquire
PFUNC_IntSetEPTPageConvertible SetEPTPageConvertible
INTSTATUS(* PFUNC_IntBreakpointCallback)(void *GuestHandle, QWORD PhysicalAddress, DWORD CpuNumber)
void IntSpinLockAcquire(void *SpinLock)
Shows warning logs and logs with a higher level.
PFUNC_IntSetIntroEmulatorContext SetIntroEmulatorContext
DWORD Size
The size of the interface.Must match UPPER_IFACE_VERSION_1_SIZE.
PFUNC_IntNotifyIntroAlert NotifyIntrospectionAlert
static void __invlpg(void *Address)
INTSTATUS IntReleaseBuffer(void *Buffer, DWORD Size)
INTSTATUS IntRegisterMSRHandler(PFUNC_IntMSRViolationCallback Callback)
#define _Acquires_lock_(expr)
PFUNC_IntNotifyIntrospectionErrorState NotifyIntrospectionErrorState
PFUNC_IntSetVeInfoPage SetVeInfoPage
INTSTATUS IntCreateEPT(DWORD *EptIndex)
PFUNC_IntEnableMsrExit EnableMSRExit
IG_LOG_LEVEL gLogLevel
The currently used log level.
PFUNC_IntRegisterDescriptorTableHandler RegisterDtrHandler
INTSTATUS(* PFUNC_IntEventInjectionCallback)(void *GuestHandle, DWORD Vector, QWORD ErrorCode, QWORD Cr2, DWORD CpuNumber)
The context of an error state.
PFUNC_IntRegisterIntroCallHandler RegisterIntroCallHandler
INTSTATUS IntSwitchEPT(DWORD NewEptIndex)
PFUNC_IntSpinLockRelease SpinLockRelease
PFUNC_IntRegisterEnginesResultCallback RegisterEnginesResultCallback
PFUNC_IntSetEPTPageProtection SetEPTPageProtection
INTSTATUS IntRegisterEPTHandler(PFUNC_IntEPTViolationCallback Callback)
INTSTATUS IntReserveVaSpaceWithPt(void **FirstPageBase, DWORD *PagesCount, void **PtBase)
Reserves a contiguous region of virtual memory which will then be used to map physical pages...
PFUNC_IntGpaToHpa GpaToHpa
PFUNC_IntToggleRepOptimization ToggleRepOptimization
INTSTATUS IntUnregisterVmxTimerHandler(void)
INTSTATUS IntQueryGuestInfo(DWORD InfoClass, void *InfoParam, void *Buffer, DWORD BufferLength)
void IntGlueReset(void)
Resets the global glue state (gIface. gUpIface, gIntHandle, gEventId, etc)
INTSTATUS GlueResumeVcpus(void)
void * gFastPaPtBase
The base of the page table that maps the fast map zone.
PFUNC_IntRegisterEventInjectionHandler RegisterEventInjectionHandler
DWORD Size
The size of the interface.Must match GLUE_IFACE_VERSION_1_SIZE.
INTSTATUS IntToggleRepOptimization(BOOLEAN Enable)
PFUNC_IntSwitchEPT SwitchEPT
PFUNC_IntFlushEPTPermissions FlushEPTPermissions
#define _Releases_lock_(expr)
INTSTATUS IntGlueInit(GLUE_IFACE const *GlueInterface, UPPER_IFACE const *UpperInterface)
Initializes the instances of GLUE_IFACE and UPPER_IFACE that will be used.
INTSTATUS IntSetSPPPageProtection(QWORD Gpa, QWORD Spp)
PFUNC_IntRwSpinLockInit RwSpinLockInit
INTSTATUS IntInjectTrap(DWORD CpuNumber, BYTE TrapNumber, DWORD ErrorCode, QWORD Cr2)
BOOLEAN GlueIsScanEnginesApiAvailable(void)
Checks if the third party memory scanning engines are present.
INTSTATUS IntPhysMemGetTypeFromMtrrs(QWORD Gpa, IG_MEMTYPE *MemType)
PFUNC_IntSetSPPPageProtection SetSPPPageProtection
#define GLUE_IFACE_VERSION_LATEST_SIZE
INTSTATUS IntSpinLockUnInit(void **SpinLock)
void(* PFUNC_IntEnterDebugger)(void)
Breaks into the debugger.
INTSTATUS(* PFUNC_IntEventEnginesResultCallback)(void *GuestHandle, PENG_NOTIFICATION_HEADER EngineNotification)
size_t strlcpy(char *dst, const char *src, size_t dest_size)
QWORD StartupTime
Startup time.
INTSTATUS IntRwSpinLockReleaseShared(void *SpinLock)
INTSTATUS IntRwSpinLockReleaseExclusive(void *SpinLock)
#define INT_STATUS_ALREADY_INITIALIZED_HINT
#define _Outptr_result_bytebuffer_(expr)
PFUNC_IntDisableMsrExit DisableMSRExit
PFUNC_IntNotifyEngines NotifyScanEngines
PFUNC_IntReserveVaSpaceWithPt ReserveVaSpaceWithPt
INTSTATUS IntGetEPTPageConvertible(DWORD EptIndex, QWORD Address, BOOLEAN *Convertible)
INTRO_GUEST_TYPE
The type of the introspected operating system.
PFUNC_IntUnregisterCrWriteHandler UnregisterCrWriteHandler
PFUNC_IntUnregisterEventInjectionHandler UnregisterEventInjectionHandler
INTSTATUS(* PFUNC_IntIntroCallCallback)(void *GuestHandle, QWORD Rip, DWORD Cpu)
PFUNC_IntEnterDebugger EnterDebugger
INTSTATUS IntRegisterXcrWriteHandler(PFUNC_IntXcrWriteCallback Callback)
INTSTATUS IntRwSpinLockAcquireExclusive(void *SpinLock)
#define _In_reads_bytes_(expr)
PFUNC_IntSpinLockInit SpinLockInit
PFUNC_IntGetSPPPageProtection GetSPPPageProtection
INTSTATUS IntFlushEPTPermissions(void)
INTSTATUS(* PFUNC_IntCrWriteCallback)(void *GuestHandle, DWORD Cr, DWORD CpuNumber, QWORD OldValue, QWORD NewValue, INTRO_ACTION *Action)
PFUNC_IntEnterDebugger GlueEnterDebugger
The API used to break into the debugger.
PFUNC_IntQueryGuestInfo QueryGuestInfo
void IntSpinLockRelease(void *SpinLock)
INTSTATUS(* PFUNC_IntIntroTimerCallback)(void *GuestHandle)
INTSTATUS IntDisableMsrExit(DWORD Msr, BOOLEAN *OldValue)
#define INT_STATUS_INVALID_DATA_TYPE
INTRO_ERROR_STATE
Error states.
#define _When_(expr, arg)
INTSTATUS IntSetIntroEmulatorContext(DWORD CpuNumber, QWORD VirtualAddress, DWORD BufferSize, BYTE *Buffer)
INTSTATUS IntEnableMsrExit(DWORD Msr, BOOLEAN *OldValue)
enum _IG_LOG_LEVEL IG_LOG_LEVEL
Controls the verbosity of the logs.
PFUNC_IntUnregisterMSRHandler UnregisterMSRHandler
INTSTATUS IntSetEPTPageProtection(DWORD EptIndex, QWORD Gpa, BYTE Read, BYTE Write, BYTE Execute)
QWORD gPageBitmap[8]
Indicates which pages inside the fast map region are free.
PFUNC_IntUnregisterEnginesResultCalback UnregisterEnginesResultCalback
INTSTATUS IntRegisterVmxTimerHandler(PFUNC_IntIntroTimerCallback Callback)
PFUNC_IntNotifyIntrospectionDeactivated NotifyIntrospectionDeactivated
PFUNC_IntUnregisterXcrWriteHandler UnregisterXcrWriteHandler
PFUNC_IntEnableCrWriteExit EnableCrWriteExit
CHAR Message[ALERT_MAX_MESSAGE_SIZE]
Raw data.
PFUNC_IntRegisterCrWriteHandler RegisterCrWriteHandler
#define UPPER_IFACE_VERSION_LATEST_SIZE
IG_MEMTYPE
Memory type values.
#define INT_STATUS_INVALID_PARAMETER_1
#define INT_STATUS_NOT_SUPPORTED
INTSTATUS GluePauseVcpus(void)
static UPPER_IFACE gUpIface
The instance of UPPER_IFACE that is being used.
PFUNC_IntNotifyIntrospectionActivated NotifyIntrospectionActivated
enum _INTRO_EVENT_TYPE INTRO_EVENT_TYPE
Event classes.
#define CRITICAL(fmt,...)
__noreturn void IntBugCheck(void)
void * gIntHandle
The guest handle provided by the integrator at initialization.
PFUNC_IntTracePrint GlueTracePrint
The trace API used.
PFUNC_IntRwSpinLockReleaseExclusive RwSpinLockReleaseExclusive
INTSTATUS IntUnregisterDtrHandler(void)
INTSTATUS IntQueryHeapSize(size_t *TotalHeapSize, size_t *FreeHeapSize)
PFUNC_IntTracePrint TracePrint
PFUNC_IntGetPhysicalPageTypeFromMtrrs PhysMemGetTypeFromMtrrs
INTSTATUS IntGetSPPPageProtection(QWORD Gpa, QWORD *Spp)
INTSTATUS IntNotifyIntroActive(void)
INTSTATUS IntRegisterCrWriteHandler(PFUNC_IntCrWriteCallback Callback)
INTSTATUS IntUnregisterMSRHandler(void)
INTSTATUS IntGetEPTPageProtection(DWORD EptIndex, QWORD Gpa, BYTE *Read, BYTE *Write, BYTE *Execute)
PFUNC_IntRegisterEPTHandler RegisterEPTHandler
INTSTATUS IntDestroyEPT(DWORD EptIndex)
INTSTATUS IntRwSpinLockAcquireShared(void *SpinLock)
#define INT_STATUS_INVALID_PARAMETER_2
PFUNC_IntRequestVcpusPause PauseVcpus
DWORD gCurLogBuffer
Used for utf16_for_log to support calling that function 8 times in a single macro.
INTSTATUS(* PFUNC_IntXcrWriteCallback)(void *GuestHandle, DWORD CpuNumber, INTRO_ACTION *Action)
PFUNC_IntReleaseBuffer ReleaseBuffer
INTSTATUS IntRegisterBreakpointHandler(PFUNC_IntBreakpointCallback Callback)
BOOLEAN Guest64
True if the OS is in 64-bit mode, False if it is not.
INTRO_GUEST_TYPE Type
Type.
Event structure for plain data/message passing.
PFUNC_IntSpinLockUnInit SpinLockUnInit
INTSTATUS IntRwSpinLockInit(void **SpinLock, char *Name)