make the cli interface ready

This commit is contained in:
Sina Karvandi 2020-04-12 03:09:26 -07:00
parent 9108b23496
commit 044d02a372
6 changed files with 129 additions and 57 deletions

View file

@ -14,35 +14,82 @@
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
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<string> Split(const string& s, const char& c)
{
string buff{ "" };
vector<string> 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<string> 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;
}

View file

@ -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";

View file

@ -15,6 +15,7 @@
#include <iostream>
#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

View file

@ -63,7 +63,7 @@
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)\Shared Headers;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<SupportJustMyCode>false</SupportJustMyCode>
</ClCompile>
<Link>
@ -102,6 +102,9 @@
<ItemGroup>
<ClCompile Include="hyperdbg-cli.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="details.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View file

@ -19,4 +19,9 @@
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="details.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View file

@ -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);
}