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

Main HyperDbg Cli source code. More...

#include <string>
#include <iostream>
#include <vector>
#include <cstring>
#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 code.

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
argcthe number of arguments
argvthe arguments
Returns
int zero on success, 1 on failure
37{
38 BOOLEAN exit_from_debugger = FALSE;
39 string previous_command;
40 BOOLEAN reset = FALSE;
41
42 //
43 // Set console output code page to UTF-8
44 //
45#ifdef _WIN32
46 SetConsoleOutputCP(CP_UTF8);
47#endif
48
49 printf("HyperDbg Debugger [version: %s, build: %s]\n", CompleteVersion, BuildVersion);
50 printf("Please visit https://docs.hyperdbg.org for more information...\n");
51 printf("HyperDbg is released under the GNU Public License v3 (GPLv3).\n\n");
52
53#if BETA_VERSION == 1
54 printf("Notice: This is a beta release and may contain bugs or stability issues. ");
55 printf("If you encounter any problems, please report them and consider using the previous stable release.\n\n");
56#endif
57
58 if (argc != 1)
59 {
60 //
61 // User-passed arguments to the debugger
62 //
63 if (!strcmp(argv[1], "--script"))
64 {
65 //
66 // Handle the script
67 //
69 }
70 else
71 {
72 printf("err, invalid command line options passed to the HyperDbg!\n");
73 return 1;
74 }
75 }
76
77 while (!exit_from_debugger)
78 {
80
81 string current_command = "";
82
83 //
84 // Clear multiline
85 //
86 reset = TRUE;
87
88 GetMultiLineCommand:
89
90 string temp_command = "";
91
92 getline(cin, temp_command);
93
94 if (cin.fail() || cin.eof())
95 {
96 cin.clear(); // reset cin state
97
98 printf("\n\n");
99
100 //
101 // probably sth like CTRL+C pressed
102 //
103 continue;
104 }
105
106 //
107 // Check for multi-line commands
108 //
109 if (hyperdbg_u_check_multiline_command((CHAR *)temp_command.c_str(), reset) == TRUE)
110 {
111 //
112 // It's a multi-line command
113 //
114 reset = FALSE;
115
116 //
117 // Save the command with a space separator
118 //
119 current_command += temp_command + "\n";
120
121 //
122 // Show a small signature
123 //
124 printf("> ");
125
126 //
127 // Get next command
128 //
129 goto GetMultiLineCommand;
130 }
131 else
132 {
133 //
134 // Reset for future commands
135 //
136 reset = TRUE;
137
138 //
139 // Either the multi-line is finished or it's a
140 // single line command
141 //
142 current_command += temp_command;
143 }
144
145 if (!current_command.compare("") && hyperdbg_u_continue_previous_command())
146 {
147 //
148 // Retry the previous command
149 //
150 current_command = previous_command;
151 }
152 else
153 {
154 //
155 // Save previous command
156 //
157 previous_command = current_command;
158 }
159
160 INT CommandExecutionResult = hyperdbg_u_run_command((CHAR *)current_command.c_str());
161
162 //
163 // if the debugger encounters an exit state then the return will be 1
164 //
165 if (CommandExecutionResult == 1)
166 {
167 //
168 // Exit from the debugger
169 //
170 exit_from_debugger = true;
171 }
172 if (CommandExecutionResult != 2)
173 {
174 printf("\n");
175 }
176 }
177
178 return 0;
179}
UCHAR BOOLEAN
Definition BasicTypes.h:35
int INT
Definition BasicTypes.h:43
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
char CHAR
Definition BasicTypes.h:33
const UCHAR BuildVersion[]
Definition Constants.h:121
const UCHAR CompleteVersion[]
Definition Constants.h:119
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:301
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:315
IMPORT_EXPORT_LIBHYPERDBG VOID hyperdbg_u_show_signature()
Show the signature of the debugger.
Definition export.cpp:248
IMPORT_EXPORT_LIBHYPERDBG INT hyperdbg_u_run_command(CHAR *command)
Run a command.
Definition export.cpp:205
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:328
printf("ho")
char ** argv
Definition symbol-parser.h:47