diff --git a/hyperdbg/hprdbgctrl/code/debugger/commands/meta-commands/script.cpp b/hyperdbg/hprdbgctrl/code/debugger/commands/meta-commands/script.cpp index f36557b3..2991d87f 100644 --- a/hyperdbg/hprdbgctrl/code/debugger/commands/meta-commands/script.cpp +++ b/hyperdbg/hprdbgctrl/code/debugger/commands/meta-commands/script.cpp @@ -146,7 +146,7 @@ HyperDbgScriptReadFileAndExecuteCommand(std::vector & PathAndArgs) // // Check for multiline commands // - if (HyperDbgCheckMultilineCommand(Line, Reset)) + if (HyperDbgCheckMultilineCommand((char *)Line.c_str(), Reset)) { // // if the reset is true, we should make the saving buffer empty @@ -219,6 +219,42 @@ HyperDbgScriptReadFileAndExecuteCommand(std::vector & PathAndArgs) } } +/** + * @brief Parsing the command line options for scripts + * + * @return int + */ +int +HyperDbgScriptReadFileAndExecuteCommandline(int argc, char * argv[]) +{ + vector Args; + + // + // Convert it to the array + // + for (size_t i = 2; i < argc; i++) + { + std::string TempStr(argv[i]); + Args.push_back(TempStr); + } + + // + // Check if the target path and args for script is not empty + // + if (!Args.empty()) + { + HyperDbgScriptReadFileAndExecuteCommand(Args); + printf("\n"); + } + else + { + printf("err, invalid command line options passed to the HyperDbg!\n"); + return FALSE; + } + + return TRUE; +} + /** * @brief .script command handler * diff --git a/hyperdbg/hprdbgctrl/code/debugger/core/interpreter.cpp b/hyperdbg/hprdbgctrl/code/debugger/core/interpreter.cpp index f029ab2d..1c6ef290 100644 --- a/hyperdbg/hprdbgctrl/code/debugger/core/interpreter.cpp +++ b/hyperdbg/hprdbgctrl/code/debugger/core/interpreter.cpp @@ -369,9 +369,10 @@ HyperDbgShowSignature() * return false */ bool -HyperDbgCheckMultilineCommand(std::string & CurrentCommand, bool Reset) +HyperDbgCheckMultilineCommand(char * CurrentCommand, bool Reset) { - UINT32 CurrentCommandLen = 0; + UINT32 CurrentCommandLen = 0; + std::string CurrentCommandStr(CurrentCommand); if (Reset) { @@ -380,11 +381,11 @@ HyperDbgCheckMultilineCommand(std::string & CurrentCommand, bool Reset) g_InterpreterCountOfOpenCurlyBrackets = 0; } - CurrentCommandLen = CurrentCommand.length(); + CurrentCommandLen = CurrentCommandStr.length(); for (size_t i = 0; i < CurrentCommandLen; i++) { - switch (CurrentCommand.at(i)) + switch (CurrentCommandStr.at(i)) { case '"': diff --git a/hyperdbg/hprdbgctrl/header/exports.h b/hyperdbg/hprdbgctrl/header/exports.h index aa757afd..2ea097a9 100644 --- a/hyperdbg/hprdbgctrl/header/exports.h +++ b/hyperdbg/hprdbgctrl/header/exports.h @@ -37,7 +37,7 @@ __declspec(dllexport) int HyperDbgStopVmmDriver(); __declspec(dllexport) int HyperDbgInterpreter(char * Command); __declspec(dllexport) void HyperDbgShowSignature(); __declspec(dllexport) void HyperdbgSetTextMessageCallback(Callback handler); -__declspec(dllexport) void HyperDbgScriptReadFileAndExecuteCommand(std::vector & PathAndArgs); +__declspec(dllexport) int HyperDbgScriptReadFileAndExecuteCommandline(int argc, char * argv[]); __declspec(dllexport) bool HyperDbgContinuePreviousCommand(); -__declspec(dllexport) bool HyperDbgCheckMultilineCommand(std::string & CurrentCommand, bool Reset); +__declspec(dllexport) bool HyperDbgCheckMultilineCommand(char * CurrentCommand, bool Reset); } diff --git a/hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp b/hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp index b0ea2b1e..1e429db9 100644 --- a/hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp +++ b/hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp @@ -32,10 +32,9 @@ using namespace std; int main(int argc, char * argv[]) { - bool ExitFromDebugger = false; - string PreviousCommand; - bool Reset = false; - vector Args; + bool ExitFromDebugger = false; + string PreviousCommand; + bool Reset = false; printf("HyperDbg Debugger [version: %s, build: %s]\n", CompleteVersion, BuildVersion); printf("Please visit https://docs.hyperdbg.org for more information...\n"); @@ -49,27 +48,9 @@ main(int argc, char * argv[]) if (!strcmp(argv[1], "--script")) { // + // Handle the script // - // - for (size_t i = 2; i < argc; i++) - { - std::string TempStr(argv[i]); - Args.push_back(TempStr); - } - - // - // Check if the target path and args for script is not empty - // - if (!Args.empty()) - { - HyperDbgScriptReadFileAndExecuteCommand(Args); - printf("\n"); - } - else - { - printf("err, invalid command line options passed to the HyperDbg!\n"); - return 1; - } + HyperDbgScriptReadFileAndExecuteCommandline(argc, argv); } else { @@ -110,7 +91,7 @@ main(int argc, char * argv[]) // // Check for multi-line commands // - if (HyperDbgCheckMultilineCommand(TempCommand, Reset) == true) + if (HyperDbgCheckMultilineCommand((char *)TempCommand.c_str(), Reset) == true) { // // It's a multi-line command diff --git a/hyperdbg/include/SDK/Imports/HyperDbgCtrlImports.h b/hyperdbg/include/SDK/Imports/HyperDbgCtrlImports.h index 416cce63..19e6bb9d 100644 --- a/hyperdbg/include/SDK/Imports/HyperDbgCtrlImports.h +++ b/hyperdbg/include/SDK/Imports/HyperDbgCtrlImports.h @@ -23,9 +23,9 @@ __declspec(dllimport) int HyperDbgStopVmmDriver(); __declspec(dllimport) int HyperDbgInterpreter(char * Command); __declspec(dllimport) void HyperDbgShowSignature(); __declspec(dllimport) void HyperDbgSetTextMessageCallback(Callback handler); -__declspec(dllimport) void HyperDbgScriptReadFileAndExecuteCommand(std::vector & PathAndArgs); +__declspec(dllimport) int HyperDbgScriptReadFileAndExecuteCommandline(int argc, char * argv[]); __declspec(dllimport) bool HyperDbgContinuePreviousCommand(); -__declspec(dllimport) bool HyperDbgCheckMultilineCommand(std::string & CurrentCommand, bool Reset); +__declspec(dllimport) bool HyperDbgCheckMultilineCommand(char * CurrentCommand, bool Reset); #ifdef __cplusplus }