HyperDbg Debugger
Loading...
Searching...
No Matches
hyperdbg-cli.cpp File Reference

Main HyperDbg Cli source coede. More...

#include "platform/user/header/Environment.h"
#include <Windows.h>
#include <string>
#include <conio.h>
#include <iostream>
#include <vector>
#include "SDK/HyperDbgSdk.h"
#include "SDK/Imports/User/HyperDbgLibImports.h"

Functions

int main (int argc, char *argv[])
 CLI main function.
 

Detailed Description

Main HyperDbg Cli source coede.

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2020-04-11

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

CLI main function.

Parameters
argc
argv
Returns
int
38{
39 BOOLEAN exit_from_debugger = FALSE;
40 string previous_command;
41 BOOLEAN reset = FALSE;
42
43 //
44 // Set console output code page to UTF-8
45 //
46 SetConsoleOutputCP(CP_UTF8);
47
48 printf("HyperDbg Debugger [version: %s, build: %s]\n", CompleteVersion, BuildVersion);
49 printf("Please visit https://docs.hyperdbg.org for more information...\n");
50 printf("HyperDbg is released under the GNU Public License v3 (GPLv3).\n\n");
51
52 if (argc != 1)
53 {
54 //
55 // User-passed arguments to the debugger
56 //
57 if (!strcmp(argv[1], "--script"))
58 {
59 //
60 // Handle the script
61 //
63 }
64 else
65 {
66 printf("err, invalid command line options passed to the HyperDbg!\n");
67 return 1;
68 }
69 }
70
71 while (!exit_from_debugger)
72 {
74
75 string current_command = "";
76
77 //
78 // Clear multiline
79 //
80 reset = TRUE;
81
82 GetMultiLinecCommand:
83
84 string temp_command = "";
85
86 getline(cin, temp_command);
87
88 if (cin.fail() || cin.eof())
89 {
90 cin.clear(); // reset cin state
91
92 printf("\n\n");
93
94 //
95 // probably sth like CTRL+C pressed
96 //
97 continue;
98 }
99
100 //
101 // Check for multi-line commands
102 //
103 if (hyperdbg_u_check_multiline_command((CHAR *)temp_command.c_str(), reset) == TRUE)
104 {
105 //
106 // It's a multi-line command
107 //
108 reset = FALSE;
109
110 //
111 // Save the command with a space separator
112 //
113 current_command += temp_command + "\n";
114
115 //
116 // Show a small signature
117 //
118 printf("> ");
119
120 //
121 // Get next command
122 //
123 goto GetMultiLinecCommand;
124 }
125 else
126 {
127 //
128 // Reset for future commands
129 //
130 reset = TRUE;
131
132 //
133 // Either the multi-line is finished or it's a
134 // single line command
135 //
136 current_command += temp_command;
137 }
138
139 if (!current_command.compare("") && hyperdbg_u_continue_previous_command())
140 {
141 //
142 // Retry the previous command
143 //
144 current_command = previous_command;
145 }
146 else
147 {
148 //
149 // Save previous command
150 //
151 previous_command = current_command;
152 }
153
154 INT CommandExecutionResult = hyperdbg_u_interpreter((CHAR *)current_command.c_str());
155
156 //
157 // if the debugger encounters an exit state then the return will be 1
158 //
159 if (CommandExecutionResult == 1)
160 {
161 //
162 // Exit from the debugger
163 //
164 exit_from_debugger = true;
165 }
166 if (CommandExecutionResult != 2)
167 {
168 printf("\n");
169 }
170 }
171
172 return 0;
173}
UCHAR BOOLEAN
Definition BasicTypes.h:39
int INT
Definition BasicTypes.h:26
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
char CHAR
Definition BasicTypes.h:31
const unsigned char BuildVersion[]
Definition Constants.h:113
const unsigned char CompleteVersion[]
Definition Constants.h:111
IMPORT_EXPORT_LIBHYPERDBG INT hyperdbg_u_script_read_file_and_execute_commandline(INT argc, CHAR *argv[])
Parsing the command line options for scripts.
Definition export.cpp:169
IMPORT_EXPORT_LIBHYPERDBG BOOLEAN hyperdbg_u_continue_previous_command()
Some of commands like stepping commands (i, p, t) and etc. need to be repeated when the user press en...
Definition export.cpp:183
IMPORT_EXPORT_LIBHYPERDBG VOID hyperdbg_u_show_signature()
Show the signature of the debugger.
Definition export.cpp:116
IMPORT_EXPORT_LIBHYPERDBG BOOLEAN hyperdbg_u_check_multiline_command(CHAR *current_command, BOOLEAN reset)
Check if the command is a multiline command or not.
Definition export.cpp:196
IMPORT_EXPORT_LIBHYPERDBG INT hyperdbg_u_interpreter(CHAR *command)
Interprets the command.
Definition export.cpp:105
char ** argv
Definition symbol-parser.h:46