From 044d02a37232871c4df59a1294555b0fdd95455a Mon Sep 17 00:00:00 2001 From: Sina Karvandi Date: Sun, 12 Apr 2020 03:09:26 -0700 Subject: [PATCH] make the cli interface ready --- hyperdbg/hprdbgctrl/interpreter.cpp | 87 ++++++++++++++----- hyperdbg/hyperdbg-cli/details.h | 15 ++++ hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp | 56 ++++++------ hyperdbg/hyperdbg-cli/hyperdbg-cli.vcxproj | 5 +- .../hyperdbg-cli/hyperdbg-cli.vcxproj.filters | 5 ++ .../Components/CommandSection.Designer.cs | 18 ++-- 6 files changed, 129 insertions(+), 57 deletions(-) create mode 100644 hyperdbg/hyperdbg-cli/details.h diff --git a/hyperdbg/hprdbgctrl/interpreter.cpp b/hyperdbg/hprdbgctrl/interpreter.cpp index ea49f626..f4e6a50b 100644 --- a/hyperdbg/hprdbgctrl/interpreter.cpp +++ b/hyperdbg/hprdbgctrl/interpreter.cpp @@ -14,35 +14,82 @@ #include #include #include +#include using namespace std; + +#define clrscr() printf("\e[1;1H\e[2J") + // Exports extern "C" { - __declspec (dllexport) int __cdecl HyperdbgInterpreter(std::string Command); + __declspec (dllexport) int __cdecl HyperdbgInterpreter(const char* Command); } - /** - * @brief Interpret commands - * - * @param Command The text of command - * @return int returns return zero if it was successful or non-zero if there was error - */ -int HyperdbgInterpreter(std::string Command) { - /* - std::string delimiter = " "; +const vector Split(const string& s, const char& c) +{ + string buff{ "" }; + vector v; - size_t pos = 0; - std::string token; - while ((pos = Command.find(delimiter)) != std::string::npos) { - token = Command.substr(0, pos); - std::cout << token << std::endl; - Command.erase(0, pos + delimiter.length()); - } - std::cout << Command << std::endl; - */ + for (auto n : s) + { + if (n != c) buff += n; else + if (n == c && buff != "") { v.push_back(buff); buff = ""; } + } + if (buff != "") v.push_back(buff); - return 0; + return v; +} + +void CommandClearScreen() { + clrscr(); +} + + +/** + * @brief Interpret commands + * + * @param Command The text of command + * @return int returns return zero if it was successful or non-zero if there was error + */ +int _cdecl HyperdbgInterpreter(const char* Command) { + + string CommandString(Command); + + // + // Convert to lower case + // + transform(CommandString.begin(), CommandString.end(), CommandString.begin(), + [](unsigned char c) { return std::tolower(c); }); + + vector SplittedCommand{ Split(CommandString, ' ') }; + + // + // Check if user entered an empty imput + // + if (SplittedCommand.empty()) + { + printf("\n"); + return 0; + } + + string FirstCommand = SplittedCommand.front(); + + + if (!FirstCommand.compare("clear") || !FirstCommand.compare("cls") || !FirstCommand.compare(".cls")) + { + system("cls"); + } + else + { + printf("Couldn't resolve error at '%s'", FirstCommand.c_str()); + printf("\n\n"); + + } + + + + return 0; } \ No newline at end of file diff --git a/hyperdbg/hyperdbg-cli/details.h b/hyperdbg/hyperdbg-cli/details.h new file mode 100644 index 00000000..97ed9753 --- /dev/null +++ b/hyperdbg/hyperdbg-cli/details.h @@ -0,0 +1,15 @@ +/** + * @file details.h + * @author Sina Karvandi (sina@rayanfam.com) + * @brief All cli details + * @details + * @version 0.1 + * @date 2020-04-12 + * + * @copyright This project is released under the GNU Public License v3. + * + */ +#pragma once + + +char Version[] = "0.1.0.0"; \ No newline at end of file diff --git a/hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp b/hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp index 7b7392ba..3949fae7 100644 --- a/hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp +++ b/hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp @@ -15,6 +15,7 @@ #include #include "Definition.h" #include "Configuration.h" +#include "details.h" #pragma comment(lib, "HPRDBGCTRL.lib") @@ -30,30 +31,12 @@ extern "C" __declspec (dllimport) int __cdecl HyperdbgUnload(); __declspec (dllimport) int __cdecl HyperdbgInstallDriver(); __declspec (dllimport) int __cdecl HyperdbgUninstallDriver(); - __declspec (dllimport) int __cdecl HyperdbgInterpreter(std::string Command); + __declspec (dllimport) int __cdecl HyperdbgInterpreter(const char* Command); __declspec (dllimport) void __stdcall HyperdbgSetTextMessageCallback(Callback handler); } -/** - * @brief Print HyperDbg Header - * - */ -void PrintAppearance() { - - printf("\n" - - - " _ _ _ _____ ____ _ _ \n" - " | | | |_ _ _ __ ___ _ ____ _(_)___ ___ _ __ | ___| __ ___ _ __ ___ / ___| ___ _ __ __ _| |_ ___| |__ \n" - " | |_| | | | | '_ \\ / _ \\ '__\\ \\ / / / __|/ _ \\| '__| | |_ | '__/ _ \\| '_ ` _ \\ \\___ \\ / __| '__/ _` | __/ __| '_ \\ \n" - " | _ | |_| | |_) | __/ | \\ V /| \\__ \\ (_) | | | _|| | | (_) | | | | | | ___) | (__| | | (_| | || (__| | | |\n" - " |_| |_|\\__, | .__/ \\___|_| \\_/ |_|___/\\___/|_| |_| |_| \\___/|_| |_| |_| |____/ \\___|_| \\__,_|\\__\\___|_| |_|\n" - " |___/|_| \n" - "\n\n"); -} - /** * @brief CLI main function * @@ -61,17 +44,36 @@ void PrintAppearance() { */ int main() { - // - // Print Hypervisor From Scratch Message - // - PrintAppearance(); + bool ExitFromDebugger = false; + + printf("HyperDbg Debugger [core version: v%s]\n",Version); + printf("Please visit https://docs.hyperdbg.com for more information...\n"); + printf("HyperDbg is released under the GNU Public License v3 (GPLv3).\n\n"); + + while (!ExitFromDebugger) + { + printf("0: HyperDbg >"); + + string command; + getline(cin, command); + int CommandExecutionResult = HyperdbgInterpreter(command.c_str()); + + // + //if the debugger encounters an exit state then the return will be 1 + // + if (CommandExecutionResult == 1) + { + // + // Exit from the debugger + // + ExitFromDebugger = true; + } + + } - //std::string command = "salam"; - //HyperdbgInterpreter(command); - //_getch(); - //return 0; + return 0; // // Installing Driver diff --git a/hyperdbg/hyperdbg-cli/hyperdbg-cli.vcxproj b/hyperdbg/hyperdbg-cli/hyperdbg-cli.vcxproj index f749eb6f..ff94056b 100644 --- a/hyperdbg/hyperdbg-cli/hyperdbg-cli.vcxproj +++ b/hyperdbg/hyperdbg-cli/hyperdbg-cli.vcxproj @@ -63,7 +63,7 @@ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true $(SolutionDir)\Shared Headers;%(AdditionalIncludeDirectories) - MultiThreaded + MultiThreadedDebug false @@ -102,6 +102,9 @@ + + + diff --git a/hyperdbg/hyperdbg-cli/hyperdbg-cli.vcxproj.filters b/hyperdbg/hyperdbg-cli/hyperdbg-cli.vcxproj.filters index 10e7317c..bdaea224 100644 --- a/hyperdbg/hyperdbg-cli/hyperdbg-cli.vcxproj.filters +++ b/hyperdbg/hyperdbg-cli/hyperdbg-cli.vcxproj.filters @@ -19,4 +19,9 @@ Source Files + + + Header Files + + \ No newline at end of file diff --git a/hyperdbg/hyperdbg-gui/Components/CommandSection.Designer.cs b/hyperdbg/hyperdbg-gui/Components/CommandSection.Designer.cs index 0c9362b9..22712e17 100644 --- a/hyperdbg/hyperdbg-gui/Components/CommandSection.Designer.cs +++ b/hyperdbg/hyperdbg-gui/Components/CommandSection.Designer.cs @@ -36,33 +36,33 @@ // this.richTextBox2.Dock = System.Windows.Forms.DockStyle.Left; this.richTextBox2.Location = new System.Drawing.Point(0, 0); - this.richTextBox2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.richTextBox2.Margin = new System.Windows.Forms.Padding(4); this.richTextBox2.Name = "richTextBox2"; this.richTextBox2.ReadOnly = true; - this.richTextBox2.Size = new System.Drawing.Size(75, 20); + this.richTextBox2.Size = new System.Drawing.Size(212, 38); this.richTextBox2.TabIndex = 1; - this.richTextBox2.Text = " 0: hdbg >"; + this.richTextBox2.Text = " 0: HyperDbg >"; // // commandText // this.commandText.Dock = System.Windows.Forms.DockStyle.Fill; this.commandText.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.commandText.Location = new System.Drawing.Point(75, 0); - this.commandText.Margin = new System.Windows.Forms.Padding(2); + this.commandText.Location = new System.Drawing.Point(212, 0); + this.commandText.Margin = new System.Windows.Forms.Padding(4); this.commandText.Name = "commandText"; - this.commandText.Size = new System.Drawing.Size(639, 20); + this.commandText.Size = new System.Drawing.Size(1216, 38); this.commandText.TabIndex = 0; this.commandText.Text = ""; // // CommandSection // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Controls.Add(this.commandText); this.Controls.Add(this.richTextBox2); - this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.Margin = new System.Windows.Forms.Padding(4); this.Name = "CommandSection"; - this.Size = new System.Drawing.Size(714, 20); + this.Size = new System.Drawing.Size(1428, 38); this.ResumeLayout(false); }