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< string > SplitCommand, string Command)
 handler of ? command
 

Variables

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

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< string > SplitCommand,
string Command )

handler of ? command

Parameters
SplitCommand
Command
Returns
VOID
197{
198 PVOID CodeBuffer;
200 UINT32 BufferLength;
201 UINT32 Pointer;
202
203 if (SplitCommand.size() == 1)
204 {
205 ShowMessages("incorrect use of the '?'\n\n");
207 return;
208 }
209
210 //
211 // Trim the command
212 //
213 Trim(Command);
214
215 //
216 // Remove the first command from it
217 //
218 Command.erase(0, SplitCommand.at(0).size());
219
220 //
221 // Trim it again
222 //
223 Trim(Command);
224
225 //
226 // Check if it's a test-case check or not
227 //
228 if (!Command.compare("test"))
229 {
230 //
231 // It's a test-case checker
232 //
234 {
235 ShowMessages("err, testing script engine test-cases was not successful\n");
236 }
237 else
238 {
239 ShowMessages("testing script engine test-cases was successful\n");
240 }
241
242 return;
243 }
244
246 {
247 //
248 // Send over serial
249 //
250
251 //
252 // Run script engine handler
253 //
254 CodeBuffer = ScriptEngineParseWrapper((char *)Command.c_str(), TRUE);
255
256 if (CodeBuffer == NULL)
257 {
258 //
259 // return to show that this item contains an script
260 //
261 return;
262 }
263
264 //
265 // Print symbols (test)
266 //
267 // PrintSymbolBufferWrapper(CodeBuffer);
268
269 //
270 // Set the buffer and length
271 //
273 BufferLength = ScriptEngineWrapperGetSize(CodeBuffer);
274 Pointer = ScriptEngineWrapperGetPointer(CodeBuffer);
275
276 //
277 // Send it to the remote debuggee
278 //
279 KdSendScriptPacketToDebuggee(BufferAddress, BufferLength, Pointer, FALSE);
280
281 //
282 // Remove the buffer of script engine interpreted code
283 //
285 }
286 else
287 {
288 //
289 // It's a test
290 //
291 ShowMessages("this command should not be used while you're in VMI-Mode or not in debugger-mode, "
292 "the results that you see is a simulated result for TESTING script-engine "
293 "and is not based on the status of your system. You can use this command, "
294 "ONLY in debugger-mode\n\n");
295
296 ShowMessages("test expression : %s \n", Command.c_str());
298 }
299}
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
unsigned __int64 UINT64
Definition BasicTypes.h:21
unsigned int UINT32
Definition BasicTypes.h:48
UINT64 BOOLEAN PVOID BufferAddress
Definition HyperDbgScriptImports.h:67
void Trim(std::string &s)
trim from both ends and start of a string (in place)
Definition common.cpp:594
VOID CommandEvalHelp()
help of the ? command
Definition eval.cpp:27
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest)
Definition globals.h:231
BOOLEAN CommandEvalCheckTestcase()
Check test-cases for script-engine.
Definition eval.cpp:44
BOOLEAN KdSendScriptPacketToDebuggee(UINT64 BufferAddress, UINT32 BufferLength, UINT32 Pointer, BOOLEAN IsFormat)
Sends a script packet to the debuggee.
Definition kd.cpp:1056
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
UINT32 ScriptEngineWrapperGetSize(PVOID SymbolBuffer)
wrapper for getting size
Definition script-engine-wrapper.cpp:834
VOID ScriptEngineWrapperTestParser(const string &Expr)
test parser
Definition script-engine-wrapper.cpp:719
UINT32 ScriptEngineWrapperGetPointer(PVOID SymbolBuffer)
wrapper for getting pointer
Definition script-engine-wrapper.cpp:848
PVOID ScriptEngineParseWrapper(char *Expr, BOOLEAN ShowErrorMessageIfAny)
ScriptEngineParse wrapper.
Definition script-engine-wrapper.cpp:267
UINT64 ScriptEngineWrapperGetHead(PVOID SymbolBuffer)
wrapper for getting head
Definition script-engine-wrapper.cpp:822
VOID ScriptEngineWrapperRemoveSymbolBuffer(PVOID SymbolBuffer)
wrapper for removing symbol buffer
Definition script-engine-wrapper.cpp:860

◆ CommandEvalCheckTestcase()

BOOLEAN CommandEvalCheckTestcase ( )

Check test-cases for script-engine.

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

◆ CommandEvalHelp()

VOID CommandEvalHelp ( )

help of the ? command

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

Variable Documentation

◆ g_IsSerialConnectedToRemoteDebuggee

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
extern

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