mirror of
https://github.com/HyperDbg/HyperDbg.git
synced 2026-07-10 01:29:59 +00:00
support to script args from command line
This commit is contained in:
parent
ceca812c23
commit
ba6e40de6b
3 changed files with 100 additions and 60 deletions
|
|
@ -103,63 +103,27 @@ CommandScriptRunCommand(std::string Input, vector<string> PathAndArgs)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief .script command handler
|
||||
* @brief Read file and run the script
|
||||
*
|
||||
* @param SplittedCommand
|
||||
* @param Command
|
||||
* @return VOID
|
||||
*/
|
||||
VOID
|
||||
CommandScript(vector<string> SplittedCommand, string Command)
|
||||
HyperDbgScriptReadFileAndExecuteCommand(vector<string> & PathAndArgs)
|
||||
{
|
||||
std::string Line;
|
||||
BOOLEAN IsOpened = FALSE;
|
||||
bool Reset = false;
|
||||
string CommandToExecute = "";
|
||||
vector<string> 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<string> 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<string> SplittedCommand, string Command)
|
||||
{
|
||||
vector<string> 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<string> & PathAndArgs);
|
||||
__declspec(dllexport) bool HyperdbgContinuePreviousCommand();
|
||||
__declspec(dllexport) bool HyperDbgCheckMultilineCommand(std::string & CurrentCommand, bool Reset);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include <string>
|
||||
#include <conio.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#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<string> & 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<string> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue