2020-08-28 04:03:12 -07:00
|
|
|
/**
|
|
|
|
|
* @file flush.cpp
|
2022-01-18 22:38:56 +03:30
|
|
|
* @author Sina Karvandi (sina@hyperdbg.org)
|
2020-08-28 04:03:12 -07:00
|
|
|
* @brief flush command
|
|
|
|
|
* @details
|
|
|
|
|
* @version 0.1
|
|
|
|
|
* @date 2020-08-19
|
|
|
|
|
*
|
|
|
|
|
* @copyright This project is released under the GNU Public License v3.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2022-05-04 16:38:21 -07:00
|
|
|
#include "pch.h"
|
2020-08-28 04:03:12 -07:00
|
|
|
|
2021-02-17 10:09:26 -08:00
|
|
|
//
|
|
|
|
|
// Global Variables
|
|
|
|
|
//
|
2026-06-08 23:45:43 +02:00
|
|
|
extern BOOLEAN g_IsKdModuleLoaded;
|
2021-02-17 10:09:26 -08:00
|
|
|
extern BOOLEAN g_IsSerialConnectedToRemoteDebuggee;
|
|
|
|
|
|
2020-08-28 04:03:12 -07:00
|
|
|
/**
|
2023-07-13 16:05:42 +09:00
|
|
|
* @brief help of the flush command
|
2020-08-28 04:03:12 -07:00
|
|
|
*
|
|
|
|
|
* @return VOID
|
|
|
|
|
*/
|
2021-03-22 18:19:39 +04:30
|
|
|
VOID
|
|
|
|
|
CommandFlushHelp()
|
|
|
|
|
{
|
2022-04-10 22:24:56 +04:30
|
|
|
ShowMessages("flush : removes all the buffer and messages from kernel-mode "
|
2021-03-22 18:19:39 +04:30
|
|
|
"buffers.\n\n");
|
2022-04-17 23:05:24 +04:30
|
|
|
|
2022-02-08 16:06:26 +03:30
|
|
|
ShowMessages("syntax : \tflush \n");
|
2020-08-28 04:03:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief flush command handler
|
|
|
|
|
*
|
|
|
|
|
* @return VOID
|
|
|
|
|
*/
|
2021-03-22 18:19:39 +04:30
|
|
|
VOID
|
|
|
|
|
CommandFlushRequestFlush()
|
|
|
|
|
{
|
|
|
|
|
BOOL Status;
|
|
|
|
|
ULONG ReturnedLength;
|
|
|
|
|
DEBUGGER_FLUSH_LOGGING_BUFFERS FlushRequest = {0};
|
|
|
|
|
|
|
|
|
|
if (g_IsSerialConnectedToRemoteDebuggee)
|
|
|
|
|
{
|
|
|
|
|
//
|
2026-06-08 23:45:43 +02:00
|
|
|
// It's on a debugger mode
|
2021-03-22 18:19:39 +04:30
|
|
|
//
|
|
|
|
|
KdSendFlushPacketToDebuggee();
|
2021-02-17 10:09:26 -08:00
|
|
|
}
|
2021-03-22 18:19:39 +04:30
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//
|
2026-06-08 23:45:43 +02:00
|
|
|
// It's on a local debugging mode
|
2021-03-22 18:19:39 +04:30
|
|
|
//
|
2026-06-08 23:45:43 +02:00
|
|
|
AssertShowMessageReturnStmt(g_IsKdModuleLoaded, g_DeviceHandle, ASSERT_MESSAGE_KD_NOT_LOADED, ASSERT_MESSAGE_DRIVER_NOT_LOADED, AssertReturn);
|
2021-03-22 18:19:39 +04:30
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// By the way, we don't need to send an input buffer
|
|
|
|
|
// to the kernel, but let's keep it like this, if we
|
2024-03-17 01:01:22 +09:00
|
|
|
// want to pass some other arguments to the kernel in
|
2021-03-22 18:19:39 +04:30
|
|
|
// the future
|
|
|
|
|
//
|
2026-07-20 12:27:14 +02:00
|
|
|
Status = PlatformDeviceIoControl(
|
2021-03-22 18:19:39 +04:30
|
|
|
g_DeviceHandle, // Handle to device
|
2023-10-25 15:05:29 +09:00
|
|
|
IOCTL_DEBUGGER_FLUSH_LOGGING_BUFFERS, // IO Control Code (IOCTL)
|
2021-03-22 18:19:39 +04:30
|
|
|
&FlushRequest, // Input Buffer to driver.
|
|
|
|
|
SIZEOF_DEBUGGER_FLUSH_LOGGING_BUFFERS, // Input buffer length
|
|
|
|
|
&FlushRequest, // Output Buffer from driver.
|
|
|
|
|
SIZEOF_DEBUGGER_FLUSH_LOGGING_BUFFERS, // Length of output buffer in
|
|
|
|
|
// bytes.
|
|
|
|
|
&ReturnedLength, // Bytes placed in buffer.
|
|
|
|
|
NULL // synchronous call
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!Status)
|
|
|
|
|
{
|
2026-07-20 12:27:14 +02:00
|
|
|
ShowMessages("ioctl failed with code 0x%x\n", PlatformGetLastError());
|
2021-03-22 18:19:39 +04:30
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-06 17:45:07 +09:00
|
|
|
if (FlushRequest.KernelStatus == DEBUGGER_OPERATION_WAS_SUCCESSFUL)
|
2021-03-22 18:19:39 +04:30
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// The amount of message that are deleted are the amount of
|
|
|
|
|
// vmx-root messages and vmx non-root messages
|
|
|
|
|
//
|
|
|
|
|
ShowMessages(
|
|
|
|
|
"flushing buffers was successful, total %d messages were cleared.\n",
|
|
|
|
|
FlushRequest.CountOfMessagesThatSetAsReadFromVmxNonRoot +
|
|
|
|
|
FlushRequest.CountOfMessagesThatSetAsReadFromVmxRoot);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ShowMessages("flushing buffers was not successful :(\n");
|
|
|
|
|
}
|
2021-02-17 10:09:26 -08:00
|
|
|
}
|
2020-08-28 04:03:12 -07:00
|
|
|
}
|
|
|
|
|
|
2021-02-10 15:19:01 -08:00
|
|
|
/**
|
|
|
|
|
* @brief flush command handler
|
|
|
|
|
*
|
2024-07-30 13:17:50 +09:00
|
|
|
* @param CommandTokens
|
2024-07-31 14:08:14 +09:00
|
|
|
* @param Command
|
2024-07-30 13:17:50 +09:00
|
|
|
*
|
2021-02-10 15:19:01 -08:00
|
|
|
* @return VOID
|
|
|
|
|
*/
|
2021-03-22 18:19:39 +04:30
|
|
|
VOID
|
2024-07-31 14:08:14 +09:00
|
|
|
CommandFlush(vector<CommandToken> CommandTokens, string Command)
|
2021-03-22 18:19:39 +04:30
|
|
|
{
|
2024-07-30 13:17:50 +09:00
|
|
|
if (CommandTokens.size() != 1)
|
2021-03-22 18:19:39 +04:30
|
|
|
{
|
2024-07-30 13:17:50 +09:00
|
|
|
ShowMessages("incorrect use of the '%s'\n\n",
|
|
|
|
|
GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
|
2021-03-22 18:19:39 +04:30
|
|
|
CommandFlushHelp();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-08-28 04:03:12 -07:00
|
|
|
|
2021-03-22 18:19:39 +04:30
|
|
|
//
|
|
|
|
|
// Flush the buffer
|
|
|
|
|
//
|
|
|
|
|
CommandFlushRequestFlush();
|
2020-08-28 04:03:12 -07:00
|
|
|
}
|