HyperDbg Debugger
Loading...
Searching...
No Matches
script-engine.cpp File Reference

Interpret script engine affairs. More...

#include "pch.h"

Functions

UINT64 ScriptEngineEvalSingleExpression (string Expr, PBOOLEAN HasError)
 Get the value from the evaluation of single expression from local debuggee and remote debuggee.
BOOLEAN ScriptEngineExecuteSingleExpression (CHAR *Expr, BOOLEAN ShowErrorMessageIfAny, BOOLEAN IsFormat)
 Execute single expression for the kernel debugger and the user-mode debugger.

Variables

UINT64 g_ResultOfEvaluatedExpression
 Result of the expression that is evaluated in the debuggee.
UINT32 g_ErrorStateOfResultOfEvaluatedExpression
 Shows the state of the evaluation of expression which whether contains error or not.
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

Interpret script engine affairs.

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

Function Documentation

◆ ScriptEngineEvalSingleExpression()

UINT64 ScriptEngineEvalSingleExpression ( string Expr,
PBOOLEAN HasError )

Get the value from the evaluation of single expression from local debuggee and remote debuggee.

Parameters
Expr
HasError
Returns
UINT64
32{
33 UINT64 Result = NULL;
34
35 //
36 // Prepend and append 'formats(' and ')'
37 //
38 Expr.insert(0, "formats(");
39 Expr.append(");");
40
42 {
43 //
44 // Send data to the target user debugger or kernel debugger
45 //
46 if (!ScriptEngineExecuteSingleExpression((CHAR *)Expr.c_str(), TRUE, TRUE))
47 {
48 *HasError = TRUE;
49 return NULL;
50 }
51
52 //
53 // Check whether there was an error in evaluation or not
54 //
56 {
57 //
58 // Everything was fine, return the result of the evaluated
59 // expression and null the global holders
60 //
64 *HasError = FALSE;
65 }
66 else
67 {
68 //
69 // There was an error evaluating the expression from the kernel (debuggee)
70 //
73
74 *HasError = TRUE;
75 Result = NULL;
76 }
77 }
78 else
79 {
80 //
81 // It's in vmi-mode,
82 // execute it locally with regs set to ZERO
83 //
84 Result = ScriptEngineEvalUInt64StyleExpressionWrapper(Expr, HasError);
85 }
86
87 return Result;
88}
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
#define DEBUGGER_OPERATION_WAS_SUCCESSFUL
General value to indicate that the operation or request was successful.
Definition ErrorCodes.h:23
UINT64 g_ResultOfEvaluatedExpression
Result of the expression that is evaluated in the debuggee.
Definition globals.h:640
UINT32 g_ErrorStateOfResultOfEvaluatedExpression
Shows the state of the evaluation of expression which whether contains error or not.
Definition globals.h:647
NULL()
Definition test-case-generator.py:530
UINT64 ScriptEngineEvalUInt64StyleExpressionWrapper(const string &Expr, PBOOLEAN HasError)
In the local debugging (VMI mode) environment, this function computes the expressions.
Definition script-engine-wrapper.cpp:780
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

◆ ScriptEngineExecuteSingleExpression()

BOOLEAN ScriptEngineExecuteSingleExpression ( CHAR * Expr,
BOOLEAN ShowErrorMessageIfAny,
BOOLEAN IsFormat )

Execute single expression for the kernel debugger and the user-mode debugger.

Parameters
Expr
ShowErrorMessageIfAny
IsFormatIf it's a format expression
Returns
BOOLEAN Returns TRUE if it was successful
101{
102 PVOID CodeBuffer;
103 UINT64 BufferAddress;
104 UINT32 BufferLength;
105 UINT32 Pointer;
106 BOOLEAN Result = FALSE;
107
108 //
109 // Check whether a kernel debugger is connected or a user-mode debugger is active
110 //
112 {
113 if (ShowErrorMessageIfAny)
114 {
115 ShowMessages("err, you're not connected to any debuggee (neither user debugger nor kernel debugger)\n");
116 }
117 return FALSE;
118 }
119
120 //
121 // Check if the user-mode debuggee is paused
122 //
124 {
125 if (ShowErrorMessageIfAny)
126 {
127 ShowMessages("err, the target process is NOT paused, you should run 'pause' to pause it\n");
128 }
129 return FALSE;
130 }
131
132 //
133 // Run script engine handler
134 //
135 CodeBuffer = ScriptEngineParseWrapper(Expr, ShowErrorMessageIfAny);
136
137 if (CodeBuffer == NULL)
138 {
139 //
140 // return to show that this item contains an error
141 //
142 return FALSE;
143 }
144
145 //
146 // Print symbols (test)
147 //
148 // PrintSymbolBufferWrapper(CodeBuffer);
149
150 //
151 // Set the buffer and length
152 //
153 BufferAddress = ScriptEngineWrapperGetHead(CodeBuffer);
154 BufferLength = ScriptEngineWrapperGetSize(CodeBuffer);
155 Pointer = ScriptEngineWrapperGetPointer(CodeBuffer);
156
158 {
159 //
160 // Send it to the remote debuggee (kernel debugger)
161 //
162 Result = KdSendScriptPacketToDebuggee(BufferAddress,
163 BufferLength,
164 Pointer,
165 IsFormat);
166 }
167 else if (g_ActiveProcessDebuggingState.IsActive)
168 {
169 //
170 // Send it to the user debugger
171 //
173 g_ActiveProcessDebuggingState.ProcessDebuggingToken,
175 BufferAddress,
176 BufferLength,
177 Pointer,
178 IsFormat);
179 }
180 else
181 {
182 //
183 // Not connected to any debuggee
184 //
185 ShowMessages("err, you're not connected to any debuggee (neither user debugger nor kernel debugger)\n");
186 Result = FALSE;
187 }
188
189 //
190 // Remove the buffer of script engine interpreted code
191 //
193
194 //
195 // Return result
196 //
197 return Result;
198}
UCHAR BOOLEAN
Definition BasicTypes.h:35
void * PVOID
Definition BasicTypes.h:56
unsigned int UINT32
Definition BasicTypes.h:54
BOOLEAN KdSendScriptPacketToDebuggee(UINT64 BufferAddress, UINT32 BufferLength, UINT32 Pointer, BOOLEAN IsFormat)
Sends a script packet to the debuggee.
Definition kd.cpp:1231
UINT32 ScriptEngineWrapperGetSize(PVOID SymbolBuffer)
wrapper for getting size
Definition script-engine-wrapper.cpp:815
UINT32 ScriptEngineWrapperGetPointer(PVOID SymbolBuffer)
wrapper for getting pointer
Definition script-engine-wrapper.cpp:829
PVOID ScriptEngineParseWrapper(CHAR *Expr, BOOLEAN ShowErrorMessageIfAny)
ScriptEngineParse wrapper.
Definition script-engine-wrapper.cpp:298
UINT64 ScriptEngineWrapperGetHead(PVOID SymbolBuffer)
wrapper for getting head
Definition script-engine-wrapper.cpp:803
VOID ScriptEngineWrapperRemoveSymbolBuffer(PVOID SymbolBuffer)
wrapper for removing symbol buffer
Definition script-engine-wrapper.cpp:841
BOOLEAN UdSendScriptBufferToProcess(UINT64 ProcessDetailToken, UINT32 TargetThreadId, UINT64 BufferAddress, UINT32 BufferLength, UINT32 Pointer, BOOLEAN IsFormat)
Send script buffer to the user debugger.
Definition ud.cpp:1176

Variable Documentation

◆ g_ActiveProcessDebuggingState

ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
extern

State of active debugging thread.

372{0};

◆ g_ErrorStateOfResultOfEvaluatedExpression

UINT32 g_ErrorStateOfResultOfEvaluatedExpression
extern

Shows the state of the evaluation of expression which whether contains error or not.

◆ g_IsSerialConnectedToRemoteDebuggee

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
extern

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

◆ g_ResultOfEvaluatedExpression

UINT64 g_ResultOfEvaluatedExpression
extern

Result of the expression that is evaluated in the debuggee.