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

134 lines
2.7 KiB
C++
Raw 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
//
// Global Variables
//
extern BOOLEAN g_IsSerialConnectedToRemoteDebuggee;
/**
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
{
PVOID CodeBuffer;
UINT64 BufferAddress;
UINT32 BufferLength;
UINT32 Pointer;
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(");");
2021-03-22 18:19:39 +04:30
if (g_IsSerialConnectedToRemoteDebuggee)
{
//
// Send over serial
//
//
// Run script engine handler
//
CodeBuffer = ScriptEngineParseWrapper((char *)Command.c_str(), TRUE);
2021-03-22 18:19:39 +04:30
if (CodeBuffer == NULL)
{
//
// return to show that this item contains an script
//
return;
}
//
// Print symbols (test)
//
// PrintSymbolBufferWrapper(CodeBuffer);
//
// Set the buffer and length
//
BufferAddress = ScriptEngineWrapperGetHead(CodeBuffer);
BufferLength = ScriptEngineWrapperGetSize(CodeBuffer);
Pointer = ScriptEngineWrapperGetPointer(CodeBuffer);
//
// Send it to the remote debuggee
//
KdSendScriptPacketToDebuggee(BufferAddress, BufferLength, Pointer, FALSE);
//
// Remove the buffer of script engine interpreted code
//
ScriptEngineWrapperRemoveSymbolBuffer(CodeBuffer);
2021-10-15 00:46:19 +03:30
ShowMessages("\n");
2021-03-22 18:19:39 +04:30
}
else
{
//
// error
//
ShowMessages("err, you're not connected to any debuggee\n");
}
}