HyperDbg Debugger
Loading...
Searching...
No Matches
eval.cpp File Reference

eval (?) command More...

#include "pch.h"

Functions

VOID CommandEvalHelp ()
 help of the ? command
BOOLEAN CommandEvalCheckTestcase ()
 Check test-cases for script-engine.
VOID CommandEval (vector< CommandToken > CommandTokens, string Command)
 handler of ? command

Variables

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
 Shows if the debugger was connected to remote debuggee over (A remote guest).
ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
 State of active debugging thread.

Detailed Description

eval (?) command

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2021-02-05

Function Documentation

◆ CommandEval()

VOID CommandEval ( vector< CommandToken > CommandTokens,
string Command )

handler of ? command

Parameters
CommandTokens
Command
Returns
VOID
197{
198 if (CommandTokens.size() == 1)
199 {
200 ShowMessages("incorrect use of the '%s'\n\n",
201 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
203 return;
204 }
205
206 //
207 // Trim the command
208 //
209 Trim(Command);
210
211 //
212 // Remove the first command from it
213 //
214 Command.erase(0, GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).size());
215
216 //
217 // Trim it again
218 //
219 Trim(Command);
220
221 //
222 // Check if it's a test-case check or not
223 //
224 if (!Command.compare("test"))
225 {
226 //
227 // It's a test-case checker
228 //
230 {
231 ShowMessages("err, testing script engine test-cases was not successful\n");
232 }
233 else
234 {
235 ShowMessages("testing script engine test-cases was successful\n");
236 }
237
238 return;
239 }
240
241 //
242 // Check if we're connected to a remote debuggee (kernel debugger) or the user debugger
243 //
245 {
246 //
247 // Send data to the target user debugger or kernel debugger
248 //
250 }
251 else
252 {
253 //
254 // It's a test (simulated) run of the script-engine
255 //
256 ShowMessages("this command should not be used while you're in VMI-Mode (not attached to the user debugger) "
257 "or not in the debugger mode, the results that you see is a simulated result for TESTING the script engine "
258 "and is not based on the status of your system. You can use this command, either in the debugger mode "
259 "(kernel debugger), or when you attached to a user debugger\n\n");
260
261 ShowMessages("test expression : %s \n", Command.c_str());
263 }
264}
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest).
Definition globals.h:253
ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
State of active debugging thread.
Definition globals.h:372
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
char CHAR
Definition BasicTypes.h:33
std::string GetCaseSensitiveStringFromCommandToken(CommandToken TargetToken)
Get case sensitive string from command token.
Definition common.cpp:467
VOID Trim(std::string &s)
trim from both ends and start of a string (in place)
Definition common.cpp:715
VOID CommandEvalHelp()
help of the ? command
Definition eval.cpp:26
BOOLEAN CommandEvalCheckTestcase()
Check test-cases for script-engine.
Definition eval.cpp:43
VOID ScriptEngineWrapperTestParser(const string &Expr)
test parser
Definition script-engine-wrapper.cpp:674
BOOLEAN ScriptEngineExecuteSingleExpression(CHAR *Expr, BOOLEAN ShowErrorMessageIfAny, BOOLEAN IsFormat)
Execute single expression for the kernel debugger and the user-mode debugger.
Definition script-engine.cpp:100

◆ CommandEvalCheckTestcase()

BOOLEAN CommandEvalCheckTestcase ( )

Check test-cases for script-engine.

Returns
BOOLEAN
44{
45 string Line;
46 BOOLEAN IsOpened = FALSE;
47 UINT64 ExpectedValue = 0;
48 BOOLEAN ExpectError = FALSE;
49 string Expr = "";
50 std::vector<std::string> TestFiles;
51
52 try
53 {
55 }
56 catch (const std::exception &)
57 {
58 ShowMessages("err, test-cases not found, make sure to run test-environment.py "
59 "before running test cases\n");
60 return FALSE;
61 }
62
63 for (auto item : TestFiles)
64 {
65 //
66 // Read the test-case file for script-engine
67 //
68 ifstream File(item.c_str());
69
70 if (File.is_open())
71 {
72 IsOpened = TRUE;
73
74 //
75 // File name
76 //
77 ShowMessages("Running from : %s\n\n", item.c_str());
78
79 while (std::getline(File, Line))
80 {
81 //
82 // Test case number
83 //
84 ShowMessages("Test-case number : %s\n", Line.c_str());
85
86 //
87 // Test-case statement
88 //
89 if (!std::getline(File, Line))
90 {
91 goto ErrorMessage;
92 }
93
94 Expr = Line;
95 ShowMessages("Statement : %s\n", Line.c_str());
96
97 //
98 // Test-case result
99 //
100 if (!std::getline(File, Line))
101 {
102 goto ErrorMessage;
103 }
104
105 if (!Line.compare("$error$"))
106 {
107 //
108 // It's an $error$ statement
109 //
110 ShowMessages("Expected result : %s\n", Line.c_str());
111
112 ExpectError = TRUE;
113 ExpectedValue = NULL;
114 }
115 else if (!ConvertStringToUInt64(Line, &ExpectedValue))
116 {
117 ShowMessages("err, the expected results are in incorrect format\n");
118 goto ErrorMessage;
119 }
120 else
121 {
122 //
123 // It's a value expected statement
124 //
125 ExpectError = FALSE;
126 ShowMessages("Expected result : %llx\n", ExpectedValue);
127 }
128
129 //
130 // Call wrapper for testing statements
131 //
132 Expr.append(" ");
133
134 //
135 // Test results
136 //
137 if (ScriptAutomaticStatementsTestWrapper(Expr, ExpectedValue, ExpectError))
138 {
139 ShowMessages("Test result : Passed\n");
140 }
141 else
142 {
143 ShowMessages("Test result : Failed\n");
144 }
145
146 //
147 // Test-case end
148 //
149 if (!std::getline(File, Line))
150 {
151 goto ErrorMessage;
152 }
153
154 //
155 // Check end case
156 //
157 if (Line.compare("$end$"))
158 {
159 //
160 // err, we'd expect a $end$ at this situation
161 //
162 goto ErrorMessage;
163 }
164
165 ShowMessages("\n------------------------------------------------------------\n\n");
166 }
167
168 File.close();
169 }
170 }
171
172 if (!IsOpened)
173 {
174 ShowMessages("err, could not find files for script engine test-cases\n");
175 return FALSE;
176 }
177
178 return TRUE;
179
180ErrorMessage:
181
182 ShowMessages("\nerr, testing failed! incorrect file format for the testing "
183 "script engine\nmake sure files have a correct ending format\n");
184 return FALSE;
185}
#define SCRIPT_ENGINE_TEST_CASES_DIRECTORY
Test cases file name.
Definition Definition.h:100
UCHAR BOOLEAN
Definition BasicTypes.h:35
std::vector< std::string > ListDirectory(const std::string &Directory, const std::string &Extension)
Create a list of special files in a directory.
Definition common.cpp:820
BOOLEAN ConvertStringToUInt64(string TextToConvert, PUINT64 Result)
NULL()
Definition test-case-generator.py:530
BOOLEAN ScriptAutomaticStatementsTestWrapper(const string &Expr, UINT64 ExpectationValue, BOOLEAN ExceptError)
massive tests for script engine statements
Definition script-engine-wrapper.cpp:497

◆ CommandEvalHelp()

VOID CommandEvalHelp ( )

help of the ? command

Returns
VOID
27{
28 ShowMessages("? : evaluates and execute expressions in debuggee.\n\n");
29
30 ShowMessages("syntax : \t? [Expression (string)]\n");
31
32 ShowMessages("\n");
33 ShowMessages("\t\te.g : ? print(dq(poi(@rcx)));\n");
34 ShowMessages("\t\te.g : ? json(dq(poi(@rcx)));\n");
35}

Variable Documentation

◆ g_ActiveProcessDebuggingState

ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
extern

State of active debugging thread.

372{0};

◆ g_IsSerialConnectedToRemoteDebuggee

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
extern

Shows if the debugger was connected to remote debuggee over (A remote guest).