add local variables environment for script engine

This commit is contained in:
SinaKarvandi 2021-10-26 22:28:32 +03:30
parent e18ce8a2dd
commit 37b860362e
7 changed files with 272 additions and 182 deletions

View file

@ -22,6 +22,7 @@
// Global Variables
//
extern UINT64 * g_ScriptGlobalVariables;
extern UINT64 * g_ScriptLocalVariables;
//
// *********************** Pdb parse wrapper ***********************
@ -247,6 +248,8 @@ VOID
ScriptEngineEvalWrapper(PGUEST_REGS GuestRegs,
string Expr)
{
SCRIPT_ENGINE_VARIABLES_LIST VariablesList = {0};
//
// Allocate global variables holder
//
@ -256,6 +259,17 @@ ScriptEngineEvalWrapper(PGUEST_REGS GuestRegs,
RtlZeroMemory(g_ScriptGlobalVariables, MAX_VAR_COUNT * sizeof(UINT64));
}
//
// Allocate local variables holder, actually in reality each core should
// have its own set of local variables but as we never run multi-core scripts
// in user-mode, thus, it's okay to just have one buffer for local variables
//
if (!g_ScriptLocalVariables)
{
g_ScriptLocalVariables = (UINT64 *)malloc(MAX_VAR_COUNT * sizeof(UINT64));
RtlZeroMemory(g_ScriptLocalVariables, MAX_VAR_COUNT * sizeof(UINT64));
}
//
// Run Parser
//
@ -283,10 +297,17 @@ ScriptEngineEvalWrapper(PGUEST_REGS GuestRegs,
ActionBuffer.ImmediatelySendTheResults = FALSE;
ActionBuffer.Tag = NULL;
//
// Fill the variables list for this run
//
VariablesList.TempList = g_TempList;
VariablesList.GlobalVariablesList = g_ScriptGlobalVariables;
VariablesList.LocalVariablesList = g_ScriptLocalVariables;
//
// If has error, show error message and abort.
//
if (ScriptEngineExecute(GuestRegs, ActionBuffer, (UINT64 *)g_TempList, (UINT64 *)g_ScriptGlobalVariables, CodeBuffer, &i, &ErrorSymbol) == TRUE)
if (ScriptEngineExecute(GuestRegs, ActionBuffer, &VariablesList, CodeBuffer, &i, &ErrorSymbol) == TRUE)
{
CHAR NameOfOperator[MAX_FUNCTION_NAME_LENGTH] = {0};