diff --git a/hyperdbg/hyperlog/code/Logging.c b/hyperdbg/hyperlog/code/Logging.c index 27e80cc4..a699335d 100644 --- a/hyperdbg/hyperlog/code/Logging.c +++ b/hyperdbg/hyperlog/code/Logging.c @@ -105,36 +105,36 @@ LogInitialize(MESSAGE_TRACING_CALLBACKS * MsgTracingCallbacks) // Initialize buffers for trace message and data messages //(we have two buffers one for vmx root and one for vmx non-root) // - MessageBufferInformation = PlatformMemAllocateZeroedNonPagedPool(sizeof(LOG_BUFFER_INFORMATION) * 2); + g_MessageBufferInformation = PlatformMemAllocateZeroedNonPagedPool(sizeof(LOG_BUFFER_INFORMATION) * 2); - if (!MessageBufferInformation) + if (!g_MessageBufferInformation) { return FALSE; // STATUS_INSUFFICIENT_RESOURCES } // - // Allocate VmxTempMessage and VmxLogMessage + // Allocate g_VmxTempMessage and g_VmxLogMessage // - VmxTempMessage = NULL; - VmxTempMessage = PlatformMemAllocateZeroedNonPagedPool(PacketChunkSize * ProcessorsCount); + g_VmxTempMessage = NULL; + g_VmxTempMessage = PlatformMemAllocateZeroedNonPagedPool(PacketChunkSize * ProcessorsCount); - if (!VmxTempMessage) + if (!g_VmxTempMessage) { - PlatformMemFreePool(MessageBufferInformation); - MessageBufferInformation = NULL; + PlatformMemFreePool(g_MessageBufferInformation); + g_MessageBufferInformation = NULL; return FALSE; // STATUS_INSUFFICIENT_RESOURCES } - VmxLogMessage = NULL; - VmxLogMessage = PlatformMemAllocateZeroedNonPagedPool(PacketChunkSize * ProcessorsCount); + g_VmxLogMessage = NULL; + g_VmxLogMessage = PlatformMemAllocateZeroedNonPagedPool(PacketChunkSize * ProcessorsCount); - if (!VmxLogMessage) + if (!g_VmxLogMessage) { - PlatformMemFreePool(MessageBufferInformation); - MessageBufferInformation = NULL; + PlatformMemFreePool(g_MessageBufferInformation); + g_MessageBufferInformation = NULL; - PlatformMemFreePool(VmxTempMessage); - VmxTempMessage = NULL; + PlatformMemFreePool(g_VmxTempMessage); + g_VmxTempMessage = NULL; return FALSE; // STATUS_INSUFFICIENT_RESOURCES } @@ -142,12 +142,12 @@ LogInitialize(MESSAGE_TRACING_CALLBACKS * MsgTracingCallbacks) // // Initialize the lock for Vmx-root mode (HIGH_IRQL Spinlock) // - VmxRootLoggingLock = 0; + g_VmxRootLoggingLock = 0; // // Allocate buffer for messages and initialize the core buffer information // - for (int i = 0; i < 2; i++) + for (UINT32 i = 0; i < 2; i++) { // // initialize the lock @@ -155,17 +155,17 @@ LogInitialize(MESSAGE_TRACING_CALLBACKS * MsgTracingCallbacks) // for both but the second buffer spinlock is useless // as we use our custom spinlock // - PlatformSpinlockInitialize(&MessageBufferInformation[i].BufferLock); - PlatformSpinlockInitialize(&MessageBufferInformation[i].BufferLockForNonImmMessage); + PlatformSpinlockInitialize(&g_MessageBufferInformation[i].BufferLock); + PlatformSpinlockInitialize(&g_MessageBufferInformation[i].BufferLockForNonImmMessage); // // allocate the buffer for regular buffers // - MessageBufferInformation[i].BufferStartAddress = (UINT64)PlatformMemAllocateNonPagedPool(LogBufferSize); - MessageBufferInformation[i].BufferForMultipleNonImmediateMessage = (UINT64)PlatformMemAllocateNonPagedPool(PacketChunkSize); + g_MessageBufferInformation[i].BufferStartAddress = (UINT64)PlatformMemAllocateNonPagedPool(LogBufferSize); + g_MessageBufferInformation[i].BufferForMultipleNonImmediateMessage = (UINT64)PlatformMemAllocateNonPagedPool(PacketChunkSize); - if (!MessageBufferInformation[i].BufferStartAddress || - !MessageBufferInformation[i].BufferForMultipleNonImmediateMessage) + if (!g_MessageBufferInformation[i].BufferStartAddress || + !g_MessageBufferInformation[i].BufferForMultipleNonImmediateMessage) { return FALSE; // STATUS_INSUFFICIENT_RESOURCES } @@ -173,9 +173,9 @@ LogInitialize(MESSAGE_TRACING_CALLBACKS * MsgTracingCallbacks) // // allocate the buffer for priority buffers // - MessageBufferInformation[i].BufferStartAddressPriority = (UINT64)PlatformMemAllocateNonPagedPool(LogBufferSizePriority); + g_MessageBufferInformation[i].BufferStartAddressPriority = (UINT64)PlatformMemAllocateNonPagedPool(LogBufferSizePriority); - if (!MessageBufferInformation[i].BufferStartAddressPriority) + if (!g_MessageBufferInformation[i].BufferStartAddressPriority) { return FALSE; // STATUS_INSUFFICIENT_RESOURCES } @@ -183,15 +183,15 @@ LogInitialize(MESSAGE_TRACING_CALLBACKS * MsgTracingCallbacks) // // Zeroing the buffer // - PlatformZeroMemory((PVOID)MessageBufferInformation[i].BufferStartAddress, LogBufferSize); - PlatformZeroMemory((PVOID)MessageBufferInformation[i].BufferForMultipleNonImmediateMessage, PacketChunkSize); - PlatformZeroMemory((PVOID)MessageBufferInformation[i].BufferStartAddressPriority, LogBufferSizePriority); + PlatformZeroMemory((PVOID)g_MessageBufferInformation[i].BufferStartAddress, LogBufferSize); + PlatformZeroMemory((PVOID)g_MessageBufferInformation[i].BufferForMultipleNonImmediateMessage, PacketChunkSize); + PlatformZeroMemory((PVOID)g_MessageBufferInformation[i].BufferStartAddressPriority, LogBufferSizePriority); // // Set the end address // - MessageBufferInformation[i].BufferEndAddress = (UINT64)MessageBufferInformation[i].BufferStartAddress + LogBufferSize; - MessageBufferInformation[i].BufferEndAddressPriority = (UINT64)MessageBufferInformation[i].BufferStartAddressPriority + LogBufferSizePriority; + g_MessageBufferInformation[i].BufferEndAddress = (UINT64)g_MessageBufferInformation[i].BufferStartAddress + LogBufferSize; + g_MessageBufferInformation[i].BufferEndAddressPriority = (UINT64)g_MessageBufferInformation[i].BufferStartAddressPriority + LogBufferSizePriority; } // @@ -213,12 +213,12 @@ LogUnInitialize() // // de-allocate buffer for messages and initialize the core buffer information (for vmx-root core) // - for (int i = 0; i < 2; i++) + for (UINT32 i = 0; i < 2; i++) { // // Check if the buffer is allocated or not // - if (MessageBufferInformation == NULL64_ZERO) + if (g_MessageBufferInformation == NULL64_ZERO) { continue; // No need to free the buffers } @@ -226,29 +226,29 @@ LogUnInitialize() // // Free each buffers // - if (MessageBufferInformation[i].BufferStartAddress != NULL64_ZERO) + if (g_MessageBufferInformation[i].BufferStartAddress != NULL64_ZERO) { - PlatformMemFreePool((PVOID)MessageBufferInformation[i].BufferStartAddress); + PlatformMemFreePool((PVOID)g_MessageBufferInformation[i].BufferStartAddress); } - if (MessageBufferInformation[i].BufferStartAddressPriority != NULL64_ZERO) + if (g_MessageBufferInformation[i].BufferStartAddressPriority != NULL64_ZERO) { - PlatformMemFreePool((PVOID)MessageBufferInformation[i].BufferStartAddressPriority); + PlatformMemFreePool((PVOID)g_MessageBufferInformation[i].BufferStartAddressPriority); } - if (MessageBufferInformation[i].BufferForMultipleNonImmediateMessage != NULL64_ZERO) + if (g_MessageBufferInformation[i].BufferForMultipleNonImmediateMessage != NULL64_ZERO) { - PlatformMemFreePool((PVOID)MessageBufferInformation[i].BufferForMultipleNonImmediateMessage); + PlatformMemFreePool((PVOID)g_MessageBufferInformation[i].BufferForMultipleNonImmediateMessage); } } // // de-allocate buffers for trace message and data messages if they are allocated // - if (MessageBufferInformation != NULL64_ZERO) + if (g_MessageBufferInformation != NULL64_ZERO) { - PlatformMemFreePool((PVOID)MessageBufferInformation); - MessageBufferInformation = NULL; + PlatformMemFreePool((PVOID)g_MessageBufferInformation); + g_MessageBufferInformation = NULL; } } @@ -291,9 +291,9 @@ LogCallbackCheckIfBufferIsFull(BOOLEAN Priority) // if (Priority) { - CurrentIndexToWritePriority = MessageBufferInformation[Index].CurrentIndexToWritePriority; + CurrentIndexToWritePriority = g_MessageBufferInformation[Index].CurrentIndexToWritePriority; - if (MessageBufferInformation[Index].CurrentIndexToWritePriority > MaximumPacketsCapacityPriority - 1) + if (g_MessageBufferInformation[Index].CurrentIndexToWritePriority > MaximumPacketsCapacityPriority - 1) { // // start from the beginning @@ -303,9 +303,9 @@ LogCallbackCheckIfBufferIsFull(BOOLEAN Priority) } else { - CurrentIndexToWrite = MessageBufferInformation[Index].CurrentIndexToWrite; + CurrentIndexToWrite = g_MessageBufferInformation[Index].CurrentIndexToWrite; - if (MessageBufferInformation[Index].CurrentIndexToWrite > MaximumPacketsCapacity - 1) + if (g_MessageBufferInformation[Index].CurrentIndexToWrite > MaximumPacketsCapacity - 1) { // // start from the beginning @@ -321,11 +321,11 @@ LogCallbackCheckIfBufferIsFull(BOOLEAN Priority) if (Priority) { - Header = (BUFFER_HEADER *)((UINT64)MessageBufferInformation[Index].BufferStartAddressPriority + (CurrentIndexToWritePriority * (PacketChunkSize + sizeof(BUFFER_HEADER)))); + Header = (BUFFER_HEADER *)((UINT64)g_MessageBufferInformation[Index].BufferStartAddressPriority + (CurrentIndexToWritePriority * (PacketChunkSize + sizeof(BUFFER_HEADER)))); } else { - Header = (BUFFER_HEADER *)((UINT64)MessageBufferInformation[Index].BufferStartAddress + (CurrentIndexToWrite * (PacketChunkSize + sizeof(BUFFER_HEADER)))); + Header = (BUFFER_HEADER *)((UINT64)g_MessageBufferInformation[Index].BufferStartAddress + (CurrentIndexToWrite * (PacketChunkSize + sizeof(BUFFER_HEADER)))); } // @@ -419,7 +419,7 @@ LogCallbackSendBuffer(UINT32 OperationCode, PVOID Buffer, UINT32 BufferLength, B // Set the index // Index = 1; - SpinlockLock(&VmxRootLoggingLock); + SpinlockLock(&g_VmxRootLoggingLock); } else { @@ -431,7 +431,7 @@ LogCallbackSendBuffer(UINT32 OperationCode, PVOID Buffer, UINT32 BufferLength, B // // Acquire the lock // - PlatformSpinlockAcquire(&MessageBufferInformation[Index].BufferLock, &OldIRQL); + PlatformSpinlockAcquire(&g_MessageBufferInformation[Index].BufferLock, &OldIRQL); } // @@ -439,22 +439,22 @@ LogCallbackSendBuffer(UINT32 OperationCode, PVOID Buffer, UINT32 BufferLength, B // if (Priority) { - if (MessageBufferInformation[Index].CurrentIndexToWritePriority > MaximumPacketsCapacityPriority - 1) + if (g_MessageBufferInformation[Index].CurrentIndexToWritePriority > MaximumPacketsCapacityPriority - 1) { // // start from the beginning // - MessageBufferInformation[Index].CurrentIndexToWritePriority = 0; + g_MessageBufferInformation[Index].CurrentIndexToWritePriority = 0; } } else { - if (MessageBufferInformation[Index].CurrentIndexToWrite > MaximumPacketsCapacity - 1) + if (g_MessageBufferInformation[Index].CurrentIndexToWrite > MaximumPacketsCapacity - 1) { // // start from the beginning // - MessageBufferInformation[Index].CurrentIndexToWrite = 0; + g_MessageBufferInformation[Index].CurrentIndexToWrite = 0; } } @@ -465,11 +465,11 @@ LogCallbackSendBuffer(UINT32 OperationCode, PVOID Buffer, UINT32 BufferLength, B if (Priority) { - Header = (BUFFER_HEADER *)((UINT64)MessageBufferInformation[Index].BufferStartAddressPriority + (MessageBufferInformation[Index].CurrentIndexToWritePriority * (PacketChunkSize + sizeof(BUFFER_HEADER)))); + Header = (BUFFER_HEADER *)((UINT64)g_MessageBufferInformation[Index].BufferStartAddressPriority + (g_MessageBufferInformation[Index].CurrentIndexToWritePriority * (PacketChunkSize + sizeof(BUFFER_HEADER)))); } else { - Header = (BUFFER_HEADER *)((UINT64)MessageBufferInformation[Index].BufferStartAddress + (MessageBufferInformation[Index].CurrentIndexToWrite * (PacketChunkSize + sizeof(BUFFER_HEADER)))); + Header = (BUFFER_HEADER *)((UINT64)g_MessageBufferInformation[Index].BufferStartAddress + (g_MessageBufferInformation[Index].CurrentIndexToWrite * (PacketChunkSize + sizeof(BUFFER_HEADER)))); } // @@ -490,11 +490,11 @@ LogCallbackSendBuffer(UINT32 OperationCode, PVOID Buffer, UINT32 BufferLength, B if (Priority) { - SavingBuffer = (PVOID)((UINT64)MessageBufferInformation[Index].BufferStartAddressPriority + (MessageBufferInformation[Index].CurrentIndexToWritePriority * (PacketChunkSize + sizeof(BUFFER_HEADER))) + sizeof(BUFFER_HEADER)); + SavingBuffer = (PVOID)((UINT64)g_MessageBufferInformation[Index].BufferStartAddressPriority + (g_MessageBufferInformation[Index].CurrentIndexToWritePriority * (PacketChunkSize + sizeof(BUFFER_HEADER))) + sizeof(BUFFER_HEADER)); } else { - SavingBuffer = (PVOID)((UINT64)MessageBufferInformation[Index].BufferStartAddress + (MessageBufferInformation[Index].CurrentIndexToWrite * (PacketChunkSize + sizeof(BUFFER_HEADER))) + sizeof(BUFFER_HEADER)); + SavingBuffer = (PVOID)((UINT64)g_MessageBufferInformation[Index].BufferStartAddress + (g_MessageBufferInformation[Index].CurrentIndexToWrite * (PacketChunkSize + sizeof(BUFFER_HEADER))) + sizeof(BUFFER_HEADER)); } // @@ -507,11 +507,11 @@ LogCallbackSendBuffer(UINT32 OperationCode, PVOID Buffer, UINT32 BufferLength, B // if (Priority) { - MessageBufferInformation[Index].CurrentIndexToWritePriority = MessageBufferInformation[Index].CurrentIndexToWritePriority + 1; + g_MessageBufferInformation[Index].CurrentIndexToWritePriority = g_MessageBufferInformation[Index].CurrentIndexToWritePriority + 1; } else { - MessageBufferInformation[Index].CurrentIndexToWrite = MessageBufferInformation[Index].CurrentIndexToWrite + 1; + g_MessageBufferInformation[Index].CurrentIndexToWrite = g_MessageBufferInformation[Index].CurrentIndexToWrite + 1; } // @@ -545,14 +545,14 @@ LogCallbackSendBuffer(UINT32 OperationCode, PVOID Buffer, UINT32 BufferLength, B // if (IsVmxRoot) { - SpinlockUnlock(&VmxRootLoggingLock); + SpinlockUnlock(&g_VmxRootLoggingLock); } else { // // Release the lock // - PlatformSpinlockRelease(&MessageBufferInformation[Index].BufferLock, OldIRQL); + PlatformSpinlockRelease(&g_MessageBufferInformation[Index].BufferLock, OldIRQL); } return TRUE; @@ -586,7 +586,7 @@ LogMarkAllAsRead(BOOLEAN IsVmxRoot) // // Acquire the lock // - SpinlockLock(&VmxRootLoggingLock); + SpinlockLock(&g_VmxRootLoggingLock); } else { @@ -598,19 +598,19 @@ LogMarkAllAsRead(BOOLEAN IsVmxRoot) // // Acquire the lock // - PlatformSpinlockAcquire(&MessageBufferInformation[Index].BufferLock, &OldIRQL); + PlatformSpinlockAcquire(&g_MessageBufferInformation[Index].BufferLock, &OldIRQL); } // // We have iterate through the all indexes // - for (size_t i = 0; i < MaximumPacketsCapacity; i++) + for (SIZE_T i = 0; i < MaximumPacketsCapacity; i++) { // // Compute the current buffer to read // - BUFFER_HEADER * Header = (BUFFER_HEADER *)((UINT64)MessageBufferInformation[Index].BufferStartAddress + - (MessageBufferInformation[Index].CurrentIndexToSend * + BUFFER_HEADER * Header = (BUFFER_HEADER *)((UINT64)g_MessageBufferInformation[Index].BufferStartAddress + + (g_MessageBufferInformation[Index].CurrentIndexToSend * (PacketChunkSize + sizeof(BUFFER_HEADER)))); if (!Header->Valid) @@ -625,14 +625,14 @@ LogMarkAllAsRead(BOOLEAN IsVmxRoot) // if (IsVmxRoot) { - SpinlockUnlock(&VmxRootLoggingLock); + SpinlockUnlock(&g_VmxRootLoggingLock); } else { // // Release the lock // - PlatformSpinlockRelease(&MessageBufferInformation[Index].BufferLock, OldIRQL); + PlatformSpinlockRelease(&g_MessageBufferInformation[Index].BufferLock, OldIRQL); } return ResultsOfBuffersSetToRead; @@ -646,7 +646,7 @@ LogMarkAllAsRead(BOOLEAN IsVmxRoot) // // Second, save the buffer contents // - PVOID SendingBuffer = (PVOID)((UINT64)MessageBufferInformation[Index].BufferStartAddress + (MessageBufferInformation[Index].CurrentIndexToSend * (PacketChunkSize + sizeof(BUFFER_HEADER))) + sizeof(BUFFER_HEADER)); + PVOID SendingBuffer = (PVOID)((UINT64)g_MessageBufferInformation[Index].BufferStartAddress + (g_MessageBufferInformation[Index].CurrentIndexToSend * (PacketChunkSize + sizeof(BUFFER_HEADER))) + sizeof(BUFFER_HEADER)); // // Finally, set the current index to invalid as we sent it @@ -663,16 +663,16 @@ LogMarkAllAsRead(BOOLEAN IsVmxRoot) // // Check to see whether we passed the index or not // - if (MessageBufferInformation[Index].CurrentIndexToSend > MaximumPacketsCapacity - 2) + if (g_MessageBufferInformation[Index].CurrentIndexToSend > MaximumPacketsCapacity - 2) { - MessageBufferInformation[Index].CurrentIndexToSend = 0; + g_MessageBufferInformation[Index].CurrentIndexToSend = 0; } else { // // Increment the next index to read // - MessageBufferInformation[Index].CurrentIndexToSend = MessageBufferInformation[Index].CurrentIndexToSend + 1; + g_MessageBufferInformation[Index].CurrentIndexToSend = g_MessageBufferInformation[Index].CurrentIndexToSend + 1; } } @@ -682,14 +682,14 @@ LogMarkAllAsRead(BOOLEAN IsVmxRoot) // if (IsVmxRoot) { - SpinlockUnlock(&VmxRootLoggingLock); + SpinlockUnlock(&g_VmxRootLoggingLock); } else { // // Release the lock // - PlatformSpinlockRelease(&MessageBufferInformation[Index].BufferLock, OldIRQL); + PlatformSpinlockRelease(&g_MessageBufferInformation[Index].BufferLock, OldIRQL); } return ResultsOfBuffersSetToRead; @@ -725,7 +725,7 @@ LogReadBuffer(BOOLEAN IsVmxRoot, PVOID BufferToSaveMessage, UINT32 * ReturnedLen // // Acquire the lock // - SpinlockLock(&VmxRootLoggingLock); + SpinlockLock(&g_VmxRootLoggingLock); } else { @@ -737,7 +737,7 @@ LogReadBuffer(BOOLEAN IsVmxRoot, PVOID BufferToSaveMessage, UINT32 * ReturnedLen // // Acquire the lock // - PlatformSpinlockAcquire(&MessageBufferInformation[Index].BufferLock, &OldIRQL); + PlatformSpinlockAcquire(&g_MessageBufferInformation[Index].BufferLock, &OldIRQL); } // @@ -748,14 +748,14 @@ LogReadBuffer(BOOLEAN IsVmxRoot, PVOID BufferToSaveMessage, UINT32 * ReturnedLen // // Check for priority message // - Header = (BUFFER_HEADER *)((UINT64)MessageBufferInformation[Index].BufferStartAddressPriority + (MessageBufferInformation[Index].CurrentIndexToSendPriority * (PacketChunkSize + sizeof(BUFFER_HEADER)))); + Header = (BUFFER_HEADER *)((UINT64)g_MessageBufferInformation[Index].BufferStartAddressPriority + (g_MessageBufferInformation[Index].CurrentIndexToSendPriority * (PacketChunkSize + sizeof(BUFFER_HEADER)))); if (!Header->Valid) { // // Check for regular message // - Header = (BUFFER_HEADER *)((UINT64)MessageBufferInformation[Index].BufferStartAddress + (MessageBufferInformation[Index].CurrentIndexToSend * (PacketChunkSize + sizeof(BUFFER_HEADER)))); + Header = (BUFFER_HEADER *)((UINT64)g_MessageBufferInformation[Index].BufferStartAddress + (g_MessageBufferInformation[Index].CurrentIndexToSend * (PacketChunkSize + sizeof(BUFFER_HEADER)))); if (!Header->Valid) { @@ -769,14 +769,14 @@ LogReadBuffer(BOOLEAN IsVmxRoot, PVOID BufferToSaveMessage, UINT32 * ReturnedLen // if (IsVmxRoot) { - SpinlockUnlock(&VmxRootLoggingLock); + SpinlockUnlock(&g_VmxRootLoggingLock); } else { // // Release the lock // - PlatformSpinlockRelease(&MessageBufferInformation[Index].BufferLock, OldIRQL); + PlatformSpinlockRelease(&g_MessageBufferInformation[Index].BufferLock, OldIRQL); } return FALSE; @@ -803,11 +803,11 @@ LogReadBuffer(BOOLEAN IsVmxRoot, PVOID BufferToSaveMessage, UINT32 * ReturnedLen if (PriorityMessageIsAvailable) { - SendingBuffer = (PVOID)((UINT64)MessageBufferInformation[Index].BufferStartAddressPriority + (MessageBufferInformation[Index].CurrentIndexToSendPriority * (PacketChunkSize + sizeof(BUFFER_HEADER))) + sizeof(BUFFER_HEADER)); + SendingBuffer = (PVOID)((UINT64)g_MessageBufferInformation[Index].BufferStartAddressPriority + (g_MessageBufferInformation[Index].CurrentIndexToSendPriority * (PacketChunkSize + sizeof(BUFFER_HEADER))) + sizeof(BUFFER_HEADER)); } else { - SendingBuffer = (PVOID)((UINT64)MessageBufferInformation[Index].BufferStartAddress + (MessageBufferInformation[Index].CurrentIndexToSend * (PacketChunkSize + sizeof(BUFFER_HEADER))) + sizeof(BUFFER_HEADER)); + SendingBuffer = (PVOID)((UINT64)g_MessageBufferInformation[Index].BufferStartAddress + (g_MessageBufferInformation[Index].CurrentIndexToSend * (PacketChunkSize + sizeof(BUFFER_HEADER))) + sizeof(BUFFER_HEADER)); } // @@ -830,21 +830,21 @@ LogReadBuffer(BOOLEAN IsVmxRoot, PVOID BufferToSaveMessage, UINT32 * ReturnedLen // if (Header->BufferLength > DbgPrintLimitation) { - for (size_t i = 0; i <= Header->BufferLength / DbgPrintLimitation; i++) + for (SIZE_T i = 0; i <= Header->BufferLength / DbgPrintLimitation; i++) { if (i != 0) { - PlatformDbgPrint("%s", (char *)((UINT64)SendingBuffer + (DbgPrintLimitation * i) - 2)); + PlatformDbgPrint("%s", (CHAR *)((UINT64)SendingBuffer + (DbgPrintLimitation * i) - 2)); } else { - PlatformDbgPrint("%s", (char *)((UINT64)SendingBuffer + (DbgPrintLimitation * i))); + PlatformDbgPrint("%s", (CHAR *)((UINT64)SendingBuffer + (DbgPrintLimitation * i))); } } } else { - PlatformDbgPrint("%s", (char *)SendingBuffer); + PlatformDbgPrint("%s", (CHAR *)SendingBuffer); } } #endif @@ -871,16 +871,16 @@ LogReadBuffer(BOOLEAN IsVmxRoot, PVOID BufferToSaveMessage, UINT32 * ReturnedLen // // Check to see whether we passed the index or not // - if (MessageBufferInformation[Index].CurrentIndexToSendPriority > MaximumPacketsCapacityPriority - 2) + if (g_MessageBufferInformation[Index].CurrentIndexToSendPriority > MaximumPacketsCapacityPriority - 2) { - MessageBufferInformation[Index].CurrentIndexToSendPriority = 0; + g_MessageBufferInformation[Index].CurrentIndexToSendPriority = 0; } else { // // Increment the next index to read // - MessageBufferInformation[Index].CurrentIndexToSendPriority = MessageBufferInformation[Index].CurrentIndexToSendPriority + 1; + g_MessageBufferInformation[Index].CurrentIndexToSendPriority = g_MessageBufferInformation[Index].CurrentIndexToSendPriority + 1; } } else @@ -888,16 +888,16 @@ LogReadBuffer(BOOLEAN IsVmxRoot, PVOID BufferToSaveMessage, UINT32 * ReturnedLen // // Check to see whether we passed the index or not // - if (MessageBufferInformation[Index].CurrentIndexToSend > MaximumPacketsCapacity - 2) + if (g_MessageBufferInformation[Index].CurrentIndexToSend > MaximumPacketsCapacity - 2) { - MessageBufferInformation[Index].CurrentIndexToSend = 0; + g_MessageBufferInformation[Index].CurrentIndexToSend = 0; } else { // // Increment the next index to read // - MessageBufferInformation[Index].CurrentIndexToSend = MessageBufferInformation[Index].CurrentIndexToSend + 1; + g_MessageBufferInformation[Index].CurrentIndexToSend = g_MessageBufferInformation[Index].CurrentIndexToSend + 1; } } @@ -907,14 +907,14 @@ LogReadBuffer(BOOLEAN IsVmxRoot, PVOID BufferToSaveMessage, UINT32 * ReturnedLen // if (IsVmxRoot) { - SpinlockUnlock(&VmxRootLoggingLock); + SpinlockUnlock(&g_VmxRootLoggingLock); } else { // // Release the lock // - PlatformSpinlockRelease(&MessageBufferInformation[Index].BufferLock, OldIRQL); + PlatformSpinlockRelease(&g_MessageBufferInformation[Index].BufferLock, OldIRQL); } return TRUE; @@ -950,11 +950,11 @@ LogCheckForNewMessage(BOOLEAN IsVmxRoot, BOOLEAN Priority) if (Priority) { - Header = (BUFFER_HEADER *)((UINT64)MessageBufferInformation[Index].BufferStartAddressPriority + (MessageBufferInformation[Index].CurrentIndexToSendPriority * (PacketChunkSize + sizeof(BUFFER_HEADER)))); + Header = (BUFFER_HEADER *)((UINT64)g_MessageBufferInformation[Index].BufferStartAddressPriority + (g_MessageBufferInformation[Index].CurrentIndexToSendPriority * (PacketChunkSize + sizeof(BUFFER_HEADER)))); } else { - Header = (BUFFER_HEADER *)((UINT64)MessageBufferInformation[Index].BufferStartAddress + (MessageBufferInformation[Index].CurrentIndexToSend * (PacketChunkSize + sizeof(BUFFER_HEADER)))); + Header = (BUFFER_HEADER *)((UINT64)g_MessageBufferInformation[Index].BufferStartAddress + (g_MessageBufferInformation[Index].CurrentIndexToSend * (PacketChunkSize + sizeof(BUFFER_HEADER)))); } if (!Header->Valid) @@ -988,16 +988,16 @@ LogCallbackPrepareAndSendMessageToQueueWrapper(UINT32 OperationCode, BOOLEAN IsImmediateMessage, BOOLEAN ShowCurrentSystemTime, BOOLEAN Priority, - const char * Fmt, + const CHAR * Fmt, va_list ArgList) { - int SprintfResult; - size_t WrittenSize; + INT32 SprintfResult; + SIZE_T WrittenSize; BOOLEAN IsVmxRootMode; BOOLEAN Result = FALSE; // by default, we assume error happens - char * LogMessage = NULL; - char * TempMessage = NULL; - char TimeBuffer[20] = {0}; + CHAR * LogMessage = NULL; + CHAR * TempMessage = NULL; + CHAR TimeBuffer[20] = {0}; ULONG CurrentCore = PlatformCpuGetCurrentProcessorNumber(); // @@ -1011,8 +1011,8 @@ LogCallbackPrepareAndSendMessageToQueueWrapper(UINT32 OperationCode, // if (IsVmxRootMode) { - LogMessage = &VmxLogMessage[CurrentCore * PacketChunkSize]; - TempMessage = &VmxTempMessage[CurrentCore * PacketChunkSize]; + LogMessage = &g_VmxLogMessage[CurrentCore * PacketChunkSize]; + TempMessage = &g_VmxTempMessage[CurrentCore * PacketChunkSize]; } else { @@ -1179,7 +1179,7 @@ LogCallbackPrepareAndSendMessageToQueue(UINT32 OperationCode, BOOLEAN IsImmediateMessage, BOOLEAN ShowCurrentSystemTime, BOOLEAN Priority, - const char * Fmt, + const CHAR * Fmt, ...) { va_list ArgList; @@ -1275,7 +1275,7 @@ LogCallbackSendMessageToQueue(UINT32 OperationCode, BOOLEAN IsImmediateMessage, // Set the index // Index = 1; - SpinlockLock(&VmxRootLoggingLockForNonImmBuffers); + SpinlockLock(&g_VmxRootLoggingLockForNonImmBuffers); } else { @@ -1287,7 +1287,7 @@ LogCallbackSendMessageToQueue(UINT32 OperationCode, BOOLEAN IsImmediateMessage, // // Acquire the lock // - PlatformSpinlockAcquire(&MessageBufferInformation[Index].BufferLockForNonImmMessage, &OldIRQL); + PlatformSpinlockAcquire(&g_MessageBufferInformation[Index].BufferLockForNonImmMessage, &OldIRQL); } // // Set the result to True @@ -1297,50 +1297,50 @@ LogCallbackSendMessageToQueue(UINT32 OperationCode, BOOLEAN IsImmediateMessage, // // If log message WrittenSize is above the buffer then we have to send the previous buffer // - if ((MessageBufferInformation[Index].CurrentLengthOfNonImmBuffer + BufferLen) > PacketChunkSize - 1 && MessageBufferInformation[Index].CurrentLengthOfNonImmBuffer != 0) + if ((g_MessageBufferInformation[Index].CurrentLengthOfNonImmBuffer + BufferLen) > PacketChunkSize - 1 && g_MessageBufferInformation[Index].CurrentLengthOfNonImmBuffer != 0) { // // Send the previous buffer (non-immediate message), // accumulated messages don't have priority // Result = LogCallbackSendBuffer(OPERATION_LOG_NON_IMMEDIATE_MESSAGE, - (PVOID)MessageBufferInformation[Index].BufferForMultipleNonImmediateMessage, - MessageBufferInformation[Index].CurrentLengthOfNonImmBuffer, + (PVOID)g_MessageBufferInformation[Index].BufferForMultipleNonImmediateMessage, + g_MessageBufferInformation[Index].CurrentLengthOfNonImmBuffer, FALSE); // // Free the immediate buffer // - MessageBufferInformation[Index].CurrentLengthOfNonImmBuffer = 0; - PlatformZeroMemory((PVOID)MessageBufferInformation[Index].BufferForMultipleNonImmediateMessage, PacketChunkSize); + g_MessageBufferInformation[Index].CurrentLengthOfNonImmBuffer = 0; + PlatformZeroMemory((PVOID)g_MessageBufferInformation[Index].BufferForMultipleNonImmediateMessage, PacketChunkSize); } // // We have to save the message // - PlatformWriteMemory((PVOID)(MessageBufferInformation[Index].BufferForMultipleNonImmediateMessage + - MessageBufferInformation[Index].CurrentLengthOfNonImmBuffer), + PlatformWriteMemory((PVOID)(g_MessageBufferInformation[Index].BufferForMultipleNonImmediateMessage + + g_MessageBufferInformation[Index].CurrentLengthOfNonImmBuffer), LogMessage, BufferLen); // // add the length // - MessageBufferInformation[Index].CurrentLengthOfNonImmBuffer += BufferLen; + g_MessageBufferInformation[Index].CurrentLengthOfNonImmBuffer += BufferLen; // Check if we're in Vmx-root, if it is then we use our customized HIGH_IRQL Spinlock, // if not we use the windows spinlock // if (IsVmxRootMode) { - SpinlockUnlock(&VmxRootLoggingLockForNonImmBuffers); + SpinlockUnlock(&g_VmxRootLoggingLockForNonImmBuffers); } else { // // Release the lock // - PlatformSpinlockRelease(&MessageBufferInformation[Index].BufferLockForNonImmMessage, OldIRQL); + PlatformSpinlockRelease(&g_MessageBufferInformation[Index].BufferLockForNonImmMessage, OldIRQL); } return Result; diff --git a/hyperdbg/hyperlog/code/UnloadDll.c b/hyperdbg/hyperlog/code/UnloadDll.c index be8c9ba6..0f82e50e 100644 --- a/hyperdbg/hyperlog/code/UnloadDll.c +++ b/hyperdbg/hyperlog/code/UnloadDll.c @@ -28,7 +28,7 @@ DllInitialize( } NTSTATUS -DllUnload(void) +DllUnload(VOID) { return STATUS_SUCCESS; } diff --git a/hyperdbg/hyperlog/header/Logging.h b/hyperdbg/hyperlog/header/Logging.h index f94d96a8..c098d883 100644 --- a/hyperdbg/hyperlog/header/Logging.h +++ b/hyperdbg/hyperlog/header/Logging.h @@ -20,13 +20,13 @@ * @brief VMX buffer for logging messages * */ -char * VmxLogMessage; +CHAR * g_VmxLogMessage; /** * @brief VMX temporary buffer for logging messages * */ -char * VmxTempMessage; +CHAR * g_VmxTempMessage; ////////////////////////////////////////////////// // Structures // @@ -101,19 +101,19 @@ typedef struct _LOG_BUFFER_INFORMATION * @brief Global Variable for buffer on all cores * */ -LOG_BUFFER_INFORMATION * MessageBufferInformation; +LOG_BUFFER_INFORMATION * g_MessageBufferInformation; /** * @brief Vmx-root lock for logging * */ -volatile LONG VmxRootLoggingLock; +volatile LONG g_VmxRootLoggingLock; /** * @brief Vmx-root lock for logging * */ -volatile LONG VmxRootLoggingLockForNonImmBuffers; +volatile LONG g_VmxRootLoggingLockForNonImmBuffers; ////////////////////////////////////////////////// // Illustration // diff --git a/hyperdbg/hyperlog/header/UnloadDll.h b/hyperdbg/hyperlog/header/UnloadDll.h index c6388ac7..b4801b98 100644 --- a/hyperdbg/hyperlog/header/UnloadDll.h +++ b/hyperdbg/hyperlog/header/UnloadDll.h @@ -17,4 +17,4 @@ __declspec(dllexport) NTSTATUS DllInitialize(_In_ PUNICODE_STRING RegistryPath); -__declspec(dllexport) NTSTATUS DllUnload(void); +__declspec(dllexport) NTSTATUS DllUnload(VOID); diff --git a/hyperdbg/libhyperdbg/code/app/libhyperdbg.cpp b/hyperdbg/libhyperdbg/code/app/libhyperdbg.cpp index 414cb5d1..d144ef09 100644 --- a/hyperdbg/libhyperdbg/code/app/libhyperdbg.cpp +++ b/hyperdbg/libhyperdbg/code/app/libhyperdbg.cpp @@ -362,7 +362,7 @@ HyperDbgUnloadVmm() AssertShowMessageReturnStmt(g_DeviceHandle, ASSERT_MESSAGE_DRIVER_NOT_LOADED, AssertReturnOne); - ShowMessages("start terminating...\n"); + ShowMessages("start terminating vmm...\n"); // // Uninitialize the user debugger if it's initialized @@ -551,7 +551,7 @@ HyperDbgLoadVmmModule() // // Enable Debug privilege to the current token // - if ( !WindowsSetDebugPrivilege()) + if (!WindowsSetDebugPrivilege()) { ShowMessages("err, couldn't set debug privilege\n"); return 1; @@ -635,7 +635,7 @@ HyperDbgLoadHyperTraceModule() // // Enable Debug privilege to the current token // - if ( !WindowsSetDebugPrivilege()) + if (!WindowsSetDebugPrivilege()) { ShowMessages("err, couldn't set debug privilege\n"); return 1; diff --git a/hyperdbg/libhyperdbg/header/kd.h b/hyperdbg/libhyperdbg/header/kd.h index 97f6670f..ca3586c6 100644 --- a/hyperdbg/libhyperdbg/header/kd.h +++ b/hyperdbg/libhyperdbg/header/kd.h @@ -216,6 +216,12 @@ KdReloadSymbolsInDebuggee(BOOLEAN PauseDebuggee, UINT32 UserProcessId); BOOLEAN KdSendResponseOfThePingPacket(); +BOOLEAN +KdSendPcitreePacketToDebuggee(PDEBUGGEE_PCITREE_REQUEST_RESPONSE_PACKET PcitreePacket); + +BOOLEAN +KdSendPcidevinfoPacketToDebuggee(PDEBUGGEE_PCIDEVINFO_REQUEST_RESPONSE_PACKET PcidevinfoPacket); + VOID KdUninitializeConnection(); @@ -241,9 +247,3 @@ KdBreakControlCheckAndContinueDebugger(); VOID KdSetStatusAndWaitForPause(); - -BOOLEAN -KdSendPcitreePacketToDebuggee(PDEBUGGEE_PCITREE_REQUEST_RESPONSE_PACKET PcitreePacket); - -BOOLEAN -KdSendPcidevinfoPacketToDebuggee(PDEBUGGEE_PCIDEVINFO_REQUEST_RESPONSE_PACKET PcidevinfoPacket); diff --git a/hyperdbg/libhyperdbg/header/libhyperdbg.h b/hyperdbg/libhyperdbg/header/libhyperdbg.h index e6a881ed..2a112eed 100644 --- a/hyperdbg/libhyperdbg/header/libhyperdbg.h +++ b/hyperdbg/libhyperdbg/header/libhyperdbg.h @@ -15,9 +15,6 @@ // Functions // ////////////////////////////////////////////////// -INT -HyperDbgCreateHandleFromVmmModule(); - INT HyperDbgInitHyperTraceModule();