HyperDbg/hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp

130 lines
2.4 KiB
C++
Raw Normal View History

2020-04-11 08:27:51 -07:00
/**
* @file hyperdbg-cli.cpp
* @author Sina Karvandi (sina@rayanfam.com)
2020-04-11 10:28:37 -07:00
* @brief Main HyperDbg Cli source coede
2020-04-11 08:27:51 -07:00
* @details
* @version 0.1
* @date 2020-04-11
2020-07-15 15:41:30 -07:00
*
2020-04-11 08:27:51 -07:00
* @copyright This project is released under the GNU Public License v3.
2020-07-15 15:41:30 -07:00
*
2020-04-11 08:27:51 -07:00
*/
2020-03-24 06:35:02 -07:00
#include <Windows.h>
2020-04-11 20:43:08 -07:00
#include <string>
2020-03-24 06:35:02 -07:00
#include <conio.h>
2020-04-11 10:28:37 -07:00
#include <iostream>
#include "Definition.h"
#include "Configuration.h"
2020-04-12 03:09:26 -07:00
#include "details.h"
2020-03-24 06:35:02 -07:00
2020-03-26 11:02:50 -07:00
#pragma comment(lib, "HPRDBGCTRL.lib")
2020-03-24 06:35:02 -07:00
2020-04-11 20:43:08 -07:00
using namespace std;
2020-04-11 10:28:37 -07:00
//
// Header file of HPRDBGCTRL
// Imports
//
extern "C"
{
2020-08-28 04:03:12 -07:00
__declspec (dllimport) int HyperdbgLoadVmm();
__declspec (dllimport) int HyperdbgUnload();
__declspec (dllimport) int HyperdbgInstallVmmDriver();
__declspec (dllimport) int HyperdbgUninstallDriver();
__declspec (dllimport) int HyperdbgInterpreter(const char* Command);
__declspec(dllexport) void HyperdbgShowSignature();
__declspec (dllimport) void HyperdbgSetTextMessageCallback(Callback handler);
2020-04-11 10:28:37 -07:00
2020-04-01 09:34:24 -07:00
}
2020-03-24 06:35:02 -07:00
2020-04-11 10:28:37 -07:00
/**
* @brief CLI main function
2020-08-28 04:03:12 -07:00
*
* @param argc
* @param argv
* @return int
2020-04-11 10:28:37 -07:00
*/
2020-07-15 15:41:30 -07:00
int main(int argc, char* argv[]) {
2020-08-28 04:03:12 -07:00
bool ExitFromDebugger = false;
2020-07-15 15:41:30 -07:00
if (argc != 1) {
//
// User-passed arguments to the debugger
//
if (!strcmp(argv[1], "--script")) {
char ScriptBuffer[MAX_PATH + 10] = { 0 };
2020-08-28 04:03:12 -07:00
2020-07-15 15:41:30 -07:00
//
// Executing the script
//
sprintf_s(ScriptBuffer, sizeof(ScriptBuffer), ".script %s", argv[2]);
HyperdbgInterpreter(ScriptBuffer);
printf("\n");
}
else
{
printf("invalid command line options passed to HyperDbg !\n");
return 1;
}
}
//
// Put to ease the test, it will be removed
//
2020-08-28 04:03:12 -07:00
/*
if (HyperdbgInstallVmmDriver()) {
2020-04-27 10:44:15 -07:00
return 1;
}
2020-08-28 04:03:12 -07:00
if (HyperdbgLoadVmm()) {
2020-04-27 10:44:15 -07:00
return 1;
2020-05-12 13:12:21 -07:00
}
_getch();
2020-05-14 08:28:28 -07:00
_getch();
2020-08-28 04:03:12 -07:00
return 0;
*/
2020-04-27 10:44:15 -07:00
2020-08-28 04:03:12 -07:00
//
// ---------------------------------------------------------
2020-08-28 04:03:12 -07:00
//
2020-04-12 03:09:26 -07:00
2020-07-15 15:41:30 -07:00
printf("HyperDbg Debugger [core version: v%s]\n", Version);
2020-04-12 03:09:26 -07:00
printf("Please visit https://docs.hyperdbg.com for more information...\n");
printf("HyperDbg is released under the GNU Public License v3 (GPLv3).\n\n");
2020-07-15 15:41:30 -07:00
while (!ExitFromDebugger)
2020-04-12 03:09:26 -07:00
{
2020-08-28 04:03:12 -07:00
HyperdbgShowSignature();
2020-04-12 03:09:26 -07:00
string command;
getline(cin, command);
2020-07-24 14:38:53 -07:00
if (cin.fail() || cin.eof()) {
cin.clear(); // reset cin state
}
2020-04-12 03:09:26 -07:00
int CommandExecutionResult = HyperdbgInterpreter(command.c_str());
//
2020-08-28 04:03:12 -07:00
// if the debugger encounters an exit state then the return will be 1
2020-04-12 03:09:26 -07:00
//
if (CommandExecutionResult == 1)
{
//
// Exit from the debugger
//
ExitFromDebugger = true;
}
2020-08-28 04:03:12 -07:00
if (CommandExecutionResult != 2)
{
printf("\n");
}
2020-04-12 03:09:26 -07:00
}
2020-08-28 04:03:12 -07:00
2020-04-11 10:28:37 -07:00
return 0;
2020-03-24 06:35:02 -07:00
}
2020-04-11 10:28:37 -07:00