diff --git a/hyperdbg/hprdbgctrl/code/debugger/commands/meta-commands/script.cpp b/hyperdbg/hprdbgctrl/code/debugger/commands/meta-commands/script.cpp index addc1601..e7ad73b2 100644 --- a/hyperdbg/hprdbgctrl/code/debugger/commands/meta-commands/script.cpp +++ b/hyperdbg/hprdbgctrl/code/debugger/commands/meta-commands/script.cpp @@ -103,63 +103,27 @@ CommandScriptRunCommand(std::string Input, vector PathAndArgs) } /** - * @brief .script command handler + * @brief Read file and run the script * - * @param SplittedCommand - * @param Command * @return VOID */ VOID -CommandScript(vector SplittedCommand, string Command) +HyperDbgScriptReadFileAndExecuteCommand(vector & PathAndArgs) { - std::string Line; - BOOLEAN IsOpened = FALSE; - bool Reset = false; - string CommandToExecute = ""; - vector PathAndArgs; - - if (SplittedCommand.size() == 1) - { - ShowMessages("please specify a file\n"); - CommandScriptHelp(); - return; - } - - // - // Trim the command - // - Trim(Command); - - // - // Remove .script from it - // - Command.erase(0, 7); - - // - // Trim it again - // - Trim(Command); - - // - // Split Path and args - // - SplitPathAndArgs(PathAndArgs, Command); - - /* - for (auto item : PathAndArgs) - { - // - // The first argument is the path - // - ShowMessages("Arg : %s\n", item.c_str()); - } - */ + std::string Line; + BOOLEAN IsOpened = FALSE; + bool Reset = false; + string CommandToExecute = ""; + string PathOfScriptFile = ""; // // Parse the script file, // the first argument is the path // - ifstream File(PathAndArgs.at(0)); + PathOfScriptFile = PathAndArgs.at(0); + ReplaceAll(PathOfScriptFile, "\"", ""); + + ifstream File(PathOfScriptFile); if (File.is_open()) { @@ -249,6 +213,63 @@ CommandScript(vector SplittedCommand, string Command) if (!IsOpened) { - ShowMessages("err, invalid file specified for .script command\n"); + ShowMessages("err, invalid file specified for the script\n"); } } + +/** + * @brief .script command handler + * + * @param SplittedCommand + * @param Command + * @return VOID + */ +VOID +CommandScript(vector SplittedCommand, string Command) +{ + vector PathAndArgs; + + if (SplittedCommand.size() == 1) + { + ShowMessages("please specify a file\n"); + CommandScriptHelp(); + return; + } + + // + // Trim the command + // + Trim(Command); + + // + // Remove .script from it + // + Command.erase(0, 7); + + // + // Trim it again + // + Trim(Command); + + // + // Split Path and args + // + SplitPathAndArgs(PathAndArgs, Command); + + /* + + for (auto item : PathAndArgs) + { + // + // The first argument is the path + // + ShowMessages("Arg : %s\n", item.c_str()); + } + + */ + + // + // Parse the file and the possible arguments + // + HyperDbgScriptReadFileAndExecuteCommand(PathAndArgs); +} diff --git a/hyperdbg/hprdbgctrl/header/exports.h b/hyperdbg/hprdbgctrl/header/exports.h index 8b8ed6d3..9a23da49 100644 --- a/hyperdbg/hprdbgctrl/header/exports.h +++ b/hyperdbg/hprdbgctrl/header/exports.h @@ -20,14 +20,16 @@ // extern "C" { extern bool inline AsmVmxSupportDetection(); + +__declspec(dllexport) int HyperdbgInterpreter(char * Command); __declspec(dllexport) int HyperdbgLoadVmm(); __declspec(dllexport) int HyperdbgUnload(); __declspec(dllexport) int HyperdbgInstallVmmDriver(); __declspec(dllexport) int HyperdbgUninstallDriver(); __declspec(dllexport) int HyperdbgStopDriver(); -__declspec(dllexport) void HyperdbgSetTextMessageCallback(Callback handler); -__declspec(dllexport) int HyperdbgInterpreter(char * Command); __declspec(dllexport) void HyperdbgShowSignature(); +__declspec(dllexport) void HyperdbgSetTextMessageCallback(Callback handler); +__declspec(dllexport) void HyperDbgScriptReadFileAndExecuteCommand(vector & PathAndArgs); __declspec(dllexport) bool HyperdbgContinuePreviousCommand(); __declspec(dllexport) bool HyperDbgCheckMultilineCommand(std::string & CurrentCommand, bool Reset); } diff --git a/hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp b/hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp index 5b5f862f..9092b3d0 100644 --- a/hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp +++ b/hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include "Definition.h" #include "Configuration.h" @@ -32,9 +33,10 @@ __declspec(dllimport) int HyperdbgUninstallDriver(); __declspec(dllimport) int HyperdbgStopDriver(); __declspec(dllimport) int HyperdbgInterpreter(char * Command); __declspec(dllimport) void HyperdbgShowSignature(); +__declspec(dllimport) void HyperdbgSetTextMessageCallback(Callback handler); +__declspec(dllimport) void HyperDbgScriptReadFileAndExecuteCommand(vector & PathAndArgs); __declspec(dllimport) bool HyperdbgContinuePreviousCommand(); __declspec(dllimport) bool HyperDbgCheckMultilineCommand(std::string & CurrentCommand, bool Reset); -__declspec(dllimport) void HyperdbgSetTextMessageCallback(Callback handler); } /** @@ -47,9 +49,10 @@ __declspec(dllimport) void HyperdbgSetTextMessageCallback(Callback handler); int main(int argc, char * argv[]) { - bool ExitFromDebugger = false; - string PreviousCommand; - bool Reset = false; + bool ExitFromDebugger = false; + string PreviousCommand; + bool Reset = false; + vector Args; printf("HyperDbg Debugger [version: %s, build: %s]\n", CompleteVersion, BuildVersion); printf("Please visit https://docs.hyperdbg.org for more information...\n"); @@ -62,18 +65,32 @@ main(int argc, char * argv[]) // if (!strcmp(argv[1], "--script")) { - char ScriptBuffer[MAX_PATH + 10] = {0}; + // + // + // + for (size_t i = 2; i < argc; i++) + { + std::string TempStr(argv[i]); + Args.push_back(TempStr); + } // - // Executing the script + // Check if the target path and args for script is not empty // - sprintf_s(ScriptBuffer, sizeof(ScriptBuffer), ".script %s", argv[2]); - HyperdbgInterpreter(ScriptBuffer); - printf("\n"); + if (!Args.empty()) + { + HyperDbgScriptReadFileAndExecuteCommand(Args); + printf("\n"); + } + else + { + printf("err, invalid command line options passed to the HyperDbg!\n"); + return 1; + } } else { - printf("invalid command line options passed to HyperDbg !\n"); + printf("err, invalid command line options passed to the HyperDbg!\n"); return 1; } }