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

114 lines
2.5 KiB
C++
Raw Permalink Normal View History

/**
* @file logopen.cpp
2022-01-18 22:38:56 +03:30
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief .logopen command
* @details
* @version 0.1
* @date 2020-07-16
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#include "pch.h"
using namespace std;
2020-08-28 04:03:12 -07:00
//
// 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
/**
2023-07-13 16:05:42 +09:00
* @brief help of the .logopen 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
CommandLogopenHelp()
{
2022-04-10 22:24:56 +04:30
ShowMessages(".logopen : saves commands and results in a file.\n\n");
2022-02-10 02:42:47 +03:30
ShowMessages("syntax : \t.logopen [FilePath (string)]\n");
2024-07-30 15:07:17 +09:00
ShowMessages("\n");
ShowMessages("\t\te.g : .logopen c:\\users\\sina\\desktop\\log.txt\n");
ShowMessages("\t\te.g : .logopen \"c:\\users\\sina\\desktop\\log with space.txt\"\n");
}
2020-08-28 04:03:12 -07:00
/**
* @brief .logopen 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
CommandLogopen(vector<CommandToken> CommandTokens, string Command)
2021-03-22 18:19:39 +04:30
{
2024-07-30 15:07:17 +09:00
if (CommandTokens.size() != 2)
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
CommandLogopenHelp();
return;
}
if (g_LogOpened)
{
ShowMessages("log was opened previously, you have the close it first "
2021-04-18 23:22:28 +04:30
"(using .logclose)\n");
2021-03-22 18:19:39 +04:30
return;
}
2021-03-22 18:19:39 +04:30
//
// Try to open it as file
//
2024-07-30 15:07:17 +09:00
g_LogOpenFile.open(GetCaseSensitiveStringFromCommandToken(CommandTokens.at(1)).c_str());
2021-03-22 18:19:39 +04:30
//
// Check if it's okay
//
if (g_LogOpenFile.is_open())
{
//
// Start intercepting logs
//
g_LogOpened = TRUE;
//
// Enable save to the file (Message + time)
//
time_t t = time(NULL);
struct tm tm = *localtime(&t);
ShowMessages("save commands and results into file : %s (%d-%02d-%02d "
2021-03-22 18:19:39 +04:30
"%02d:%02d:%02d)\n",
2024-07-30 15:07:17 +09:00
GetCaseSensitiveStringFromCommandToken(CommandTokens.at(1)).c_str(),
2021-03-22 18:19:39 +04:30
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec);
}
else
{
2024-07-30 15:07:17 +09:00
ShowMessages("unable to open file : %s\n", GetCaseSensitiveStringFromCommandToken(CommandTokens.at(1)).c_str());
2021-03-22 18:19:39 +04:30
return;
}
}
2020-08-28 04:03:12 -07:00
/**
* @brief Append text to the file object
2021-02-10 15:19:01 -08:00
*
* @param Text
* @return VOID
2020-08-28 04:03:12 -07:00
*/
2021-03-22 18:19:39 +04:30
VOID
LogopenSaveToFile(const CHAR * Text)
2021-03-22 18:19:39 +04:30
{
g_LogOpenFile << Text;
}