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

78 lines
1.5 KiB
C++
Raw Permalink Normal View History

/**
* @file print.cpp
2022-01-18 22:38:56 +03:30
* @author Sina Karvandi (sina@hyperdbg.org)
* @author M.H. Gholamrezaei (mh@hyperdbg.org)
* @brief print command
* @details
* @version 0.1
* @date 2020-10-08
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#include "pch.h"
2020-10-22 09:02:28 -07:00
using namespace std;
2020-10-08 08:16:23 -07:00
/**
2023-07-13 16:05:42 +09:00
* @brief help of the print command
*
* @return VOID
*/
2021-03-22 18:19:39 +04:30
VOID
CommandPrintHelp()
{
2022-04-10 22:24:56 +04:30
ShowMessages("print : evaluates expressions.\n\n");
ShowMessages("syntax : \tprint [Expression (string)]\n");
ShowMessages("\n");
2021-03-22 18:19:39 +04:30
ShowMessages("\t\te.g : print dq(poi(@rcx))\n");
}
/**
* @brief handler of print command
*
* @param CommandTokens
2021-02-10 15:19:01 -08:00
* @param Command
*
* @return VOID
*/
2021-03-22 18:19:39 +04:30
VOID
CommandPrint(vector<CommandToken> CommandTokens, string Command)
2021-03-22 18:19:39 +04:30
{
if (CommandTokens.size() == 1)
2021-03-22 18:19:39 +04:30
{
ShowMessages("incorrect use of the '%s'\n\n",
GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
2021-03-22 18:19:39 +04:30
CommandPrintHelp();
return;
}
//
2021-03-22 18:19:39 +04:30
// Trim the command
//
2021-03-22 18:19:39 +04:30
Trim(Command);
//
2021-03-22 18:19:39 +04:30
// Remove print from it
//
Command.erase(0, GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).size());
//
2021-03-22 18:19:39 +04:30
// Trim it again
//
2021-03-22 18:19:39 +04:30
Trim(Command);
//
2021-03-22 18:19:39 +04:30
// Prepend and append 'print(' and ')'
//
2021-03-22 18:19:39 +04:30
Command.insert(0, "print(");
Command.append(");");
//
// Execute the expression
//
ScriptEngineExecuteSingleExpression((CHAR *)Command.c_str(), TRUE, FALSE);
}