HyperDbg/hyperdbg/libhyperdbg/code/debugger/commands/meta-commands/logclose.cpp

80 lines
1.6 KiB
C++
Raw Permalink Normal View History

/**
* @file logclose.cpp
2022-01-18 22:38:56 +03:30
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief .logclose command
* @details
* @version 0.1
* @date 2020-07-16
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#include "pch.h"
//
// Global Variables
//
2021-03-22 18:19:39 +04:30
extern BOOLEAN g_LogOpened;
extern ofstream g_LogOpenFile;
2020-08-28 04:03:12 -07:00
/**
* @brief help .logclose command
2021-02-10 15:19:01 -08:00
*
* @return VOID
2020-08-28 04:03:12 -07:00
*/
2021-03-22 18:19:39 +04:30
VOID
CommandLogcloseHelp()
{
2022-04-10 22:24:56 +04:30
ShowMessages(".logclose : closes the previously opened log.\n\n");
2021-12-28 01:14:56 +03:30
ShowMessages("syntax : \t.logclose\n");
}
2020-08-28 04:03:12 -07:00
/**
* @brief .logclose command handler
2021-02-10 15:19:01 -08:00
*
2024-07-30 15:07:17 +09:00
* @param CommandTokens
* @param Command
2024-07-30 15:07:17 +09:00
*
2021-02-10 15:19:01 -08:00
* @return VOID
2020-08-28 04:03:12 -07:00
*/
2021-03-22 18:19:39 +04:30
VOID
CommandLogclose(vector<CommandToken> CommandTokens, string Command)
2021-03-22 18:19:39 +04:30
{
2024-07-30 15:07:17 +09:00
if (CommandTokens.size() != 1)
2021-03-22 18:19:39 +04:30
{
2024-07-30 15:07:17 +09:00
ShowMessages("incorrect use of the '%s'\n\n",
GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
2021-03-22 18:19:39 +04:30
CommandLogcloseHelp();
return;
}
if (!g_LogOpened)
{
ShowMessages("there is no opened log, did you use '.logopen'? \n");
return;
}
2021-03-22 18:19:39 +04:30
//
// Show the time and message before close
//
time_t t = time(NULL);
struct tm tm = *localtime(&t);
ShowMessages("log file closed (%d-%02d-%02d "
"%02d:%02d:%02d)\n",
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec);
//
// close the file
//
g_LogOpenFile.close();
2021-03-22 18:19:39 +04:30
//
// Globally indicate that file is no longer available
//
g_LogOpened = FALSE;
}