HyperDbg/hyperdbg/libhyperdbg/code/debugger/commands/debugging-commands/flush.cpp

126 lines
3.4 KiB
C++
Raw Normal View History

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.
*
*/
#include "pch.h"
2020-08-28 04:03:12 -07:00
//
// Global Variables
//
extern BOOLEAN g_IsKdModuleLoaded;
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");
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)
{
//
// It's on a debugger mode
2021-03-22 18:19:39 +04:30
//
KdSendFlushPacketToDebuggee();
}
2021-03-22 18:19:39 +04:30
else
{
//
// It's on a local debugging mode
2021-03-22 18:19:39 +04:30
//
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
//
Status = PlatformDeviceIoControl(
2021-03-22 18:19:39 +04:30
g_DeviceHandle, // Handle to device
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)
{
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");
}
}
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
* @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
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
}