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

Interpret general fields. More...

#include "pch.h"

Classes

struct  _ALLOCATED_MEMORY_FOR_SCRIPT_ENGINE_CASTING

Typedefs

typedef struct _ALLOCATED_MEMORY_FOR_SCRIPT_ENGINE_CASTING ALLOCATED_MEMORY_FOR_SCRIPT_ENGINE_CASTING
typedef struct _ALLOCATED_MEMORY_FOR_SCRIPT_ENGINE_CASTINGPALLOCATED_MEMORY_FOR_SCRIPT_ENGINE_CASTING

Functions

UINT64 ScriptEngineConvertNameToAddressWrapper (const CHAR *FunctionOrVariableName, PBOOLEAN WasFound)
 ScriptEngineConvertNameToAddress wrapper.
UINT32 ScriptEngineLoadFileSymbolWrapper (UINT64 BaseAddress, const CHAR *PdbFileName, const CHAR *CustomModuleName)
 ScriptEngineLoadFileSymbol wrapper.
VOID ScriptEngineSetTextMessageCallbackWrapper (PVOID Handler)
 ScriptEngineSetTextMessageCallback wrapper.
UINT32 ScriptEngineUnloadAllSymbolsWrapper ()
 ScriptEngineUnloadAllSymbols wrapper.
UINT32 ScriptEngineUnloadModuleSymbolWrapper (CHAR *ModuleName)
 ScriptEngineUnloadModuleSymbol wrapper.
UINT32 ScriptEngineSearchSymbolForMaskWrapper (const CHAR *SearchMask)
 ScriptEngineSearchSymbolForMask wrapper.
BOOLEAN ScriptEngineGetFieldOffsetWrapper (CHAR *TypeName, CHAR *FieldName, UINT32 *FieldOffset)
 ScriptEngineGetFieldOffset wrapper.
BOOLEAN ScriptEngineGetDataTypeSizeWrapper (CHAR *TypeName, UINT64 *TypeSize)
 ScriptEngineGetDataTypeSize wrapper.
BOOLEAN ScriptEngineCreateSymbolTableForDisassemblerWrapper (PVOID CallbackFunction)
 ScriptEngineCreateSymbolTableForDisassembler wrapper.
BOOLEAN ScriptEngineConvertFileToPdbPathWrapper (const CHAR *LocalFilePath, CHAR *ResultPath, SIZE_T ResultPathSize)
 ScriptEngineConvertFileToPdbPath wrapper.
BOOLEAN ScriptEngineSymbolInitLoadWrapper (PMODULE_SYMBOL_DETAIL BufferToStoreDetails, UINT32 StoredLength, BOOLEAN DownloadIfAvailable, const CHAR *SymbolPath, BOOLEAN IsSilentLoad)
 ScriptEngineSymbolInitLoad wrapper.
BOOLEAN ScriptEngineShowDataBasedOnSymbolTypesWrapper (const CHAR *TypeName, UINT64 Address, BOOLEAN IsStruct, PVOID BufferAddress, const CHAR *AdditionalParameters)
 ScriptEngineShowDataBasedOnSymbolTypes wrapper.
VOID ScriptEngineSymbolAbortLoadingWrapper ()
 SymbolAbortLoading wrapper.
BOOLEAN ScriptEngineConvertFileToPdbFileAndGuidAndAgeDetailsWrapper (const CHAR *LocalFilePath, CHAR *PdbFilePath, CHAR *GuidAndAgeDetails, BOOLEAN Is32BitModule)
 ScriptEngineConvertFileToPdbFileAndGuidAndAgeDetails wrapper.
BOOLEAN ScriptEngineConvertLoadedModuleToPdbFileAndGuidAndAgeDetailsWrapper (const BYTE *LoadedImageBytes, SIZE_T LoadedImageSize, const CHAR *LocalFilePath, CHAR *PdbFilePath, CHAR *GuidAndAgeDetails, BOOLEAN Is32BitModule)
 ScriptEngineConvertLoadedModuleToPdbFileAndGuidAndAgeDetails wrapper.
PVOID ScriptEngineParseWrapper (CHAR *Expr, BOOLEAN ShowErrorMessageIfAny)
 ScriptEngineParse wrapper.
VOID PrintSymbolBufferWrapper (PVOID SymbolBuffer)
 PrintSymbolBuffer wrapper.
VOID ScriptEngineEvalWrapper (PGUEST_REGS GuestRegs, string Expr)
 Script engine evaluation wrapper.
BOOLEAN ScriptAutomaticStatementsTestWrapper (const string &Expr, UINT64 ExpectationValue, BOOLEAN ExceptError)
 massive tests for script engine statements
PVOID AllocateStructForCasting (PALLOCATED_MEMORY_FOR_SCRIPT_ENGINE_CASTING AllocationsForCastings)
 allocate memory and build structure for casting
VOID ScriptEngineWrapperTestParser (const string &Expr)
 test parser
VOID ScriptEngineWrapperTestParserForHwdbg (const string &Expr)
 test parser for hwdbg
UINT64 ScriptEngineEvalUInt64StyleExpressionWrapper (const string &Expr, PBOOLEAN HasError)
 In the local debugging (VMI mode) environment, this function computes the expressions.
UINT64 ScriptEngineWrapperGetHead (PVOID SymbolBuffer)
 wrapper for getting head
UINT32 ScriptEngineWrapperGetSize (PVOID SymbolBuffer)
 wrapper for getting size
UINT32 ScriptEngineWrapperGetPointer (PVOID SymbolBuffer)
 wrapper for getting pointer
VOID ScriptEngineWrapperRemoveSymbolBuffer (PVOID SymbolBuffer)
 wrapper for removing symbol buffer

Variables

UINT64 * g_ScriptGlobalVariables
 Holder of script engines global variables.
UINT64 * g_ScriptStackBuffer
 Holder of stack buffer for script engine.
UINT64 g_CurrentExprEvalResult
 global variable to save the result of script-engine statement tests
BOOLEAN g_CurrentExprEvalResultHasError
 global variable to detect if there was an error in the result of script-engine statement tests
UINT64 * g_HwdbgPinsStatus
 Holder of pins (and ports) status of hwdbg.

Detailed Description

Interpret general fields.

Author
M.H. Gholamrezaei (mh@hy.nosp@m.perd.nosp@m.bg.or.nosp@m.g)
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2020-10-25

Typedef Documentation

◆ ALLOCATED_MEMORY_FOR_SCRIPT_ENGINE_CASTING

◆ PALLOCATED_MEMORY_FOR_SCRIPT_ENGINE_CASTING

Function Documentation

◆ AllocateStructForCasting()

PVOID AllocateStructForCasting ( PALLOCATED_MEMORY_FOR_SCRIPT_ENGINE_CASTING AllocationsForCastings)

allocate memory and build structure for casting

Parameters
AllocationsForCastingsMemory details for future deallocations
Returns
PVOID
532{
533 typedef struct _UNICODE_STRING
534 {
535 UINT16 Length; // +0x000
536 UINT16 MaximumLength; // +0x002
537 PWSTR Buffer; // +0x004
539
540 typedef struct _STUPID_STRUCT1
541 {
542 UINT32 Flag32; // +0x000
543 UINT64 Flag64; // +0x004
544 PVOID Context; // +0x00c
547
548 typedef struct _STUPID_STRUCT2
549 {
550 UINT32 Sina32; // +0x000
551 UINT64 Sina64; // +0x004
552 PVOID AghaaSina; // +0x00c
553 PUNICODE_STRING UnicodeStr; // +0x014
555
557
558 //
559 // Allocate UNICODE_STRING 1
560 //
561 WCHAR MyString1[40] = L"Hi come from stupid struct 1!";
562 UINT32 SizeOfMyString1 = (UINT32)wcslen(MyString1) * sizeof(WCHAR) + 2;
563 PUNICODE_STRING UnicodeStr1 = (PUNICODE_STRING)malloc(sizeof(UNICODE_STRING));
564
565 if (UnicodeStr1 == NULL)
566 {
567 return NULL;
568 }
569
570 AllocationsForCastings->Buff1 = (CHAR *)UnicodeStr1;
571 WCHAR * Buff1 = (WCHAR *)malloc(SizeOfMyString1);
572
573 if (Buff1 == NULL)
574 {
575 free(UnicodeStr1);
576 return NULL;
577 }
578
579 AllocationsForCastings->Buff2 = (CHAR *)Buff1;
580 RtlZeroMemory(Buff1, SizeOfMyString1);
581 UnicodeStr1->Buffer = Buff1;
582 UnicodeStr1->Length = UnicodeStr1->MaximumLength = SizeOfMyString1;
583 memcpy(UnicodeStr1->Buffer, MyString1, SizeOfMyString1);
584
585 //
586 // Allocate UNICODE_STRING 2
587 //
588 WCHAR MyString2[40] = L"Goodbye I'm at stupid struct 2!";
589 UINT32 SizeOfMyString2 = (UINT32)wcslen(MyString2) * sizeof(WCHAR) + 2;
590 PUNICODE_STRING UnicodeStr2 = (PUNICODE_STRING)malloc(sizeof(UNICODE_STRING));
591
592 if (UnicodeStr2 == NULL)
593 {
594 free(UnicodeStr1);
595 free(Buff1);
596
597 return NULL;
598 }
599
600 AllocationsForCastings->Buff3 = (CHAR *)UnicodeStr2;
601 WCHAR * Buff2 = (WCHAR *)malloc(SizeOfMyString2);
602
603 if (Buff2 == NULL)
604 {
605 free(UnicodeStr1);
606 free(Buff1);
607 free(UnicodeStr2);
608
609 return NULL;
610 }
611
612 AllocationsForCastings->Buff4 = (CHAR *)Buff2;
613 RtlZeroMemory(Buff2, SizeOfMyString2);
614 UnicodeStr2->Buffer = Buff2;
615 UnicodeStr2->Length = UnicodeStr2->MaximumLength = SizeOfMyString2;
616 memcpy(UnicodeStr2->Buffer, MyString2, SizeOfMyString2);
617
618 //
619 // Allocate STUPID_STRUCT1
620 //
621 PSTUPID_STRUCT1 StupidStruct1 = (PSTUPID_STRUCT1)malloc(sizeof(STUPID_STRUCT1));
622
623 if (StupidStruct1 == NULL)
624 {
625 free(UnicodeStr1);
626 free(Buff1);
627 free(UnicodeStr2);
628 free(Buff2);
629
630 return NULL;
631 }
632
633 AllocationsForCastings->Buff5 = (CHAR *)StupidStruct1;
634 StupidStruct1->Flag32 = 0x3232;
635 StupidStruct1->Flag64 = 0x6464;
636 StupidStruct1->Context = (PVOID)0x85;
637 StupidStruct1->StringValue = UnicodeStr1;
638
639 //
640 // Allocate STUPID_STRUCT2
641 //
642 PSTUPID_STRUCT2 StupidStruct2 = (PSTUPID_STRUCT2)malloc(sizeof(STUPID_STRUCT2));
643
644 if (StupidStruct2 == NULL)
645 {
646 free(UnicodeStr1);
647 free(Buff1);
648 free(UnicodeStr2);
649 free(Buff2);
650 free(StupidStruct1);
651
652 return NULL;
653 }
654
655 AllocationsForCastings->Buff6 = (CHAR *)StupidStruct2;
656
657 StupidStruct2->Sina32 = 0x32;
658 StupidStruct2->Sina64 = 0x64;
659 StupidStruct2->AghaaSina = (PVOID)0x55;
660 StupidStruct2->UnicodeStr = UnicodeStr2;
661 StupidStruct2->StupidStruct1 = StupidStruct1;
662
663 //_CrtDbgBreak();
664 return StupidStruct2;
665}
unsigned short UINT16
Definition BasicTypes.h:53
void * PVOID
Definition BasicTypes.h:56
unsigned int UINT32
Definition BasicTypes.h:54
char CHAR
Definition BasicTypes.h:33
struct _STUPID_STRUCT1 STUPID_STRUCT1
struct _STUPID_STRUCT2 * PSTUPID_STRUCT2
struct _STUPID_STRUCT1 * PSTUPID_STRUCT1
struct _UNICODE_STRING * PUNICODE_STRING
struct _UNICODE_STRING UNICODE_STRING
struct _STUPID_STRUCT2 STUPID_STRUCT2
NULL()
Definition test-case-generator.py:530
CHAR * Buff1
Definition script-engine-wrapper.cpp:32
CHAR * Buff5
Definition script-engine-wrapper.cpp:36
CHAR * Buff6
Definition script-engine-wrapper.cpp:37
CHAR * Buff4
Definition script-engine-wrapper.cpp:35
CHAR * Buff2
Definition script-engine-wrapper.cpp:33
CHAR * Buff3
Definition script-engine-wrapper.cpp:34
Definition casting.cpp:32
UINT32 Flag32
Definition casting.cpp:33
PVOID Context
Definition casting.cpp:35
UINT64 Flag64
Definition casting.cpp:34
PUNICODE_STRING StringValue
Definition casting.cpp:36
Definition casting.cpp:40
PSTUPID_STRUCT1 StupidStruct1
Definition casting.cpp:45
PUNICODE_STRING UnicodeStr
Definition casting.cpp:44
UINT64 Sina64
Definition casting.cpp:42
UINT32 Sina32
Definition casting.cpp:41
PVOID AghaaSina
Definition casting.cpp:43
Definition casting.cpp:25
USHORT Length
Definition casting.cpp:26
USHORT MaximumLength
Definition casting.cpp:27
PWSTR Buffer
Definition casting.cpp:28

◆ PrintSymbolBufferWrapper()

VOID PrintSymbolBufferWrapper ( PVOID SymbolBuffer)

PrintSymbolBuffer wrapper.

Print symbol buffer wrapper

Parameters
SymbolBuffer
Returns
PVOID
333{
334 PrintSymbolBuffer(SymbolBuffer);
335}
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE VOID PrintSymbolBuffer(const PVOID SymbolBuffer)
Prints a symbol buffer.
Definition script-engine.c:4083

◆ ScriptAutomaticStatementsTestWrapper()

BOOLEAN ScriptAutomaticStatementsTestWrapper ( const string & Expr,
UINT64 ExpectationValue,
BOOLEAN ExceptError )

massive tests for script engine statements

Parameters
ExprThe expression to test
ExpectationValueWhat value this statements expects (not used if ExceptError is TRUE)
ExceptErrorTrue if the statement expects an error
Returns
BOOLEAN whether the test was successful or not
498{
499 //
500 // Set the global variable indicator of test_statement to 0
501 //
503
504 //
505 // Call the test parser
506 //
508
509 //
510 // Check the global variable to see the results
511 //
512 if (g_CurrentExprEvalResultHasError && ExceptError)
513 {
514 return TRUE;
515 }
516 else if (ExpectationValue == g_CurrentExprEvalResult)
517 {
518 return TRUE;
519 }
520
521 return FALSE;
522}
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
VOID ScriptEngineWrapperTestParser(const string &Expr)
test parser
Definition script-engine-wrapper.cpp:674
BOOLEAN g_CurrentExprEvalResultHasError
global variable to detect if there was an error in the result of script-engine statement tests
Definition globals.h:681
UINT64 g_CurrentExprEvalResult
global variable to save the result of script-engine statement tests
Definition globals.h:674

◆ ScriptEngineConvertFileToPdbFileAndGuidAndAgeDetailsWrapper()

BOOLEAN ScriptEngineConvertFileToPdbFileAndGuidAndAgeDetailsWrapper ( const CHAR * LocalFilePath,
CHAR * PdbFilePath,
CHAR * GuidAndAgeDetails,
BOOLEAN Is32BitModule )

ScriptEngineConvertFileToPdbFileAndGuidAndAgeDetails wrapper.

Parameters
LocalFilePath
PdbFilePath
GuidAndAgeDetails
Is32BitModule
Returns
BOOLEAN
251{
252 return ScriptEngineConvertFileToPdbFileAndGuidAndAgeDetails(LocalFilePath, PdbFilePath, GuidAndAgeDetails, Is32BitModule);
253}
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE BOOLEAN ScriptEngineConvertFileToPdbFileAndGuidAndAgeDetails(const CHAR *LocalFilePath, CHAR *PdbFilePath, CHAR *GuidAndAgeDetails, BOOLEAN Is32BitModule)
Convert file to pdb attributes for symbols.
Definition script-engine.c:296

◆ ScriptEngineConvertFileToPdbPathWrapper()

BOOLEAN ScriptEngineConvertFileToPdbPathWrapper ( const CHAR * LocalFilePath,
CHAR * ResultPath,
SIZE_T ResultPathSize )

ScriptEngineConvertFileToPdbPath wrapper.

Parameters
LocalFilePath
ResultPath
Returns
BOOLEAN
176{
177 return ScriptEngineConvertFileToPdbPath(LocalFilePath, ResultPath, ResultPathSize);
178}
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE BOOLEAN ScriptEngineConvertFileToPdbPath(const CHAR *LocalFilePath, CHAR *ResultPath, SIZE_T ResultPathSize)
Convert local file to pdb path.
Definition script-engine.c:217

◆ ScriptEngineConvertLoadedModuleToPdbFileAndGuidAndAgeDetailsWrapper()

BOOLEAN ScriptEngineConvertLoadedModuleToPdbFileAndGuidAndAgeDetailsWrapper ( const BYTE * LoadedImageBytes,
SIZE_T LoadedImageSize,
const CHAR * LocalFilePath,
CHAR * PdbFilePath,
CHAR * GuidAndAgeDetails,
BOOLEAN Is32BitModule )

ScriptEngineConvertLoadedModuleToPdbFileAndGuidAndAgeDetails wrapper.

Parameters
LoadedImageBytes
LoadedImageSize
LocalFilePath
PdbFilePath
GuidAndAgeDetails
Is32BitModule
Returns
BOOLEAN
275{
277 LoadedImageBytes,
278 LoadedImageSize,
279 LocalFilePath,
280 PdbFilePath,
281 GuidAndAgeDetails,
282 Is32BitModule);
283}
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE BOOLEAN ScriptEngineConvertLoadedModuleToPdbFileAndGuidAndAgeDetails(const BYTE *LoadedImageBytes, SIZE_T LoadedImageSize, const CHAR *LocalFilePath, CHAR *PdbFilePath, CHAR *GuidAndAgeDetails, BOOLEAN Is32BitModule)
Convert loaded module bytes to pdb attributes for symbols.
Definition script-engine.c:317

◆ ScriptEngineConvertNameToAddressWrapper()

UINT64 ScriptEngineConvertNameToAddressWrapper ( const CHAR * FunctionOrVariableName,
PBOOLEAN WasFound )

ScriptEngineConvertNameToAddress wrapper.

Parameters
FunctionName
WasFound
Returns
UINT64
55{
56 return ScriptEngineConvertNameToAddress(FunctionOrVariableName, WasFound);
57}
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE UINT64 ScriptEngineConvertNameToAddress(const CHAR *FunctionOrVariableName, PBOOLEAN WasFound)
Converts name to address.
Definition script-engine.c:69

◆ ScriptEngineCreateSymbolTableForDisassemblerWrapper()

BOOLEAN ScriptEngineCreateSymbolTableForDisassemblerWrapper ( PVOID CallbackFunction)

ScriptEngineCreateSymbolTableForDisassembler wrapper.

Parameters
CallbackFunction
Returns
BOOLEAN
161{
162 return ScriptEngineCreateSymbolTableForDisassembler(CallbackFunction);
163}
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE BOOLEAN ScriptEngineCreateSymbolTableForDisassembler(PVOID CallbackFunction)
Create symbol table for disassembler.
Definition script-engine.c:201

◆ ScriptEngineEvalUInt64StyleExpressionWrapper()

UINT64 ScriptEngineEvalUInt64StyleExpressionWrapper ( const string & Expr,
PBOOLEAN HasError )

In the local debugging (VMI mode) environment, this function computes the expressions.

for example, if the user u ExAllocatePoolWithTag+0x10 this will evaluate the expr

Parameters
Expr
HasError
Returns
UINT64
781{
782 //
783 // In VMI-mode we'll form all registers as zero
784 //
785 GUEST_REGS GuestRegs = {0};
786
787 ScriptEngineEvalWrapper(&GuestRegs, Expr);
788
789 //
790 // Set the results and return the value
791 //
794}
VOID ScriptEngineEvalWrapper(PGUEST_REGS GuestRegs, string Expr)
Script engine evaluation wrapper.
Definition script-engine-wrapper.cpp:345
Definition BasicTypes.h:136

◆ ScriptEngineEvalWrapper()

VOID ScriptEngineEvalWrapper ( PGUEST_REGS GuestRegs,
string Expr )

Script engine evaluation wrapper.

Parameters
GuestRegs
Expr
Returns
VOID
347{
348 SCRIPT_ENGINE_GENERAL_REGISTERS ScriptGeneralRegisters = {0};
349
350 //
351 // Allocate global variables holder
352 //
354 {
355 g_ScriptGlobalVariables = (UINT64 *)malloc(MAX_VAR_COUNT * sizeof(UINT64));
356
357 if (g_ScriptGlobalVariables == NULL)
358 {
359 ShowMessages("err, could not allocate memory for user-mode global variables");
360
361 return;
362 }
363
364 RtlZeroMemory(g_ScriptGlobalVariables, MAX_VAR_COUNT * sizeof(UINT64));
365 }
366
367 //
368 // Allocate stack buffer holder, actually in reality each core should
369 // have its own set of stack buffer but as we never run multi-core scripts
370 // in user-mode, thus, it's okay to just have one buffer for stack buffer
371 //
373 {
374 g_ScriptStackBuffer = (UINT64 *)malloc(MAX_STACK_BUFFER_COUNT * sizeof(UINT64));
375
376 if (g_ScriptStackBuffer == NULL)
377 {
379
380 ShowMessages("err, could not allocate memory for user-mode stack buffer");
381
382 return;
383 }
384 }
385
386 //
387 // Run Parser
388 //
389 PSYMBOL_BUFFER CodeBuffer = (PSYMBOL_BUFFER)ScriptEngineParse((char *)Expr.c_str());
390
391#ifdef _SCRIPT_ENGINE_IR_PRINT_EN
392 //
393 // Print symbol buffer
394 //
395 PrintSymbolBuffer((PVOID)CodeBuffer);
396#endif
397
398 ACTION_BUFFER ActionBuffer = {0};
399 SYMBOL ErrorSymbol = {0};
400
401 UINT64 EXECUTENUMBER = 0;
402
403 ScriptGeneralRegisters.StackBuffer = g_ScriptStackBuffer;
404 ScriptGeneralRegisters.GlobalVariablesList = g_ScriptGlobalVariables;
405 RtlZeroMemory(g_ScriptStackBuffer, MAX_STACK_BUFFER_COUNT * sizeof(UINT64));
406
407 if (CodeBuffer->Message == NULL)
408 {
409#ifdef _SCRIPT_ENGINE_CODEEXEC_DBG_EN
410 printf("\nScriptEngineExecute:\n");
411#endif
412 UINT64 i = 0;
413 for (; i < CodeBuffer->Pointer;)
414 {
415 //
416 // Fill the action buffer but as we're in user-mode here
417 // then there is nothing to fill
418 //
419 ActionBuffer.Context = NULL;
420 ActionBuffer.CurrentAction = NULL;
421 ActionBuffer.ImmediatelySendTheResults = FALSE;
422 ActionBuffer.Tag = NULL;
423
424#ifdef _SCRIPT_ENGINE_CODEEXEC_DBG_EN
425 printf("Address = %lld, StackIndx = %lld, StackBaseIndx = %lld\n", i, ScriptGeneralRegisters.StackIndx, ScriptGeneralRegisters.StackBaseIndx);
426 PSYMBOL Operator = (PSYMBOL)((UINT64)CodeBuffer->Head +
427 (UINT64)(i * sizeof(SYMBOL)));
428 printf("Function = %s\n", FunctionNames[Operator->Value]);
429 printf("Stack Buffer:\n");
430 for (UINT64 j = 0; j < ScriptGeneralRegisters.StackIndx; j++)
431 {
432 printf("StackIndx = %lld, Value = %lld", j, ScriptGeneralRegisters.StackBuffer[j]);
433
434 if (j == ScriptGeneralRegisters.StackBaseIndx)
435 {
436 printf(" <===== StackBaseIndx");
437 }
438 printf("\n");
439 }
440 printf("\n");
441#endif
442
443 //
444 // If has error, show error message and abort
445 //
446 if (ScriptEngineExecute(GuestRegs,
447 &ActionBuffer,
448 &ScriptGeneralRegisters,
449 CodeBuffer,
450 &i,
451 &ErrorSymbol) == TRUE)
452 {
453 ShowMessages("err, ScriptEngineExecute, function = %s\n",
454 FunctionNames[ErrorSymbol.Value]);
457 break;
458 }
459 else if (ScriptGeneralRegisters.StackIndx >= MAX_STACK_BUFFER_COUNT)
460 {
461 ShowMessages("err, stack buffer overflow (more information: https://docs.hyperdbg.org/tips-and-tricks/misc/customize-build/change-script-engine-limitations)\n");
464 break;
465 }
466 else if (EXECUTENUMBER >= MAX_EXECUTION_COUNT)
467 {
468 ShowMessages("err, exceeding the max execution count (more information: https://docs.hyperdbg.org/tips-and-tricks/misc/customize-build/change-script-engine-limitations)\n");
471 break;
472 }
473
474 EXECUTENUMBER++;
475 }
476 }
477 else
478 {
479 ShowMessages("%s\n", CodeBuffer->Message);
480 }
481
482 RemoveSymbolBuffer(CodeBuffer);
483
484 return;
485}
BOOL ScriptEngineExecute(PGUEST_REGS GuestRegs, ACTION_BUFFER *ActionDetail, PSCRIPT_ENGINE_GENERAL_REGISTERS ScriptGeneralRegisters, SYMBOL_BUFFER *CodeBuffer, UINT64 *Indx, SYMBOL *ErrorOperator)
Execute the script buffer.
Definition ScriptEngineEval.c:297
struct _SCRIPT_ENGINE_GENERAL_REGISTERS SCRIPT_ENGINE_GENERAL_REGISTERS
List of different variables.
#define MAX_VAR_COUNT
Definition Constants.h:580
#define MAX_EXECUTION_COUNT
Maximum number of variables that can be used in the script engine.
Definition Constants.h:576
#define MAX_STACK_BUFFER_COUNT
Maximum number of stack buffer count in the script engine.
Definition Constants.h:571
struct SYMBOL * PSYMBOL
struct SYMBOL_BUFFER * PSYMBOL_BUFFER
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE VOID RemoveSymbolBuffer(PVOID SymbolBuffer)
Frees the memory allocated by SymbolBuffer.
Definition script-engine.c:3949
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE PVOID ScriptEngineParse(CHAR *Str)
The entry point of script engine.
Definition script-engine.c:343
printf("ho")
UINT64 * g_ScriptGlobalVariables
Holder of script engines global variables.
Definition Global.h:71
UINT64 * g_ScriptStackBuffer
Holder of stack buffer for script engine.
Definition globals.h:360
UINT64 * GlobalVariablesList
Definition BasicTypes.h:225
UINT64 StackIndx
Definition BasicTypes.h:226
UINT64 * StackBuffer
Definition BasicTypes.h:224
UINT64 StackBaseIndx
Definition BasicTypes.h:227
Definition ScriptEngineCommonDefinitions.h:35
long long unsigned Context
Definition ScriptEngineCommonDefinitions.h:39
long long unsigned Tag
Definition ScriptEngineCommonDefinitions.h:36
long long unsigned CurrentAction
Definition ScriptEngineCommonDefinitions.h:37
char ImmediatelySendTheResults
Definition ScriptEngineCommonDefinitions.h:38
unsigned int Pointer
Definition ScriptEngineCommonDefinitions.h:24
PSYMBOL Head
Definition ScriptEngineCommonDefinitions.h:23
char * Message
Definition ScriptEngineCommonDefinitions.h:26
Definition ScriptEngineCommonDefinitions.h:6
long long unsigned Value
Definition ScriptEngineCommonDefinitions.h:9

◆ ScriptEngineGetDataTypeSizeWrapper()

BOOLEAN ScriptEngineGetDataTypeSizeWrapper ( CHAR * TypeName,
UINT64 * TypeSize )

ScriptEngineGetDataTypeSize wrapper.

Parameters
TypeName
TypeSize
Returns
BOOLEAN
148{
149 return ScriptEngineGetDataTypeSize(TypeName, TypeSize);
150}
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE BOOLEAN ScriptEngineGetDataTypeSize(CHAR *TypeName, UINT64 *TypeSize)
Get size of a data type (structure).
Definition script-engine.c:186

◆ ScriptEngineGetFieldOffsetWrapper()

BOOLEAN ScriptEngineGetFieldOffsetWrapper ( CHAR * TypeName,
CHAR * FieldName,
UINT32 * FieldOffset )

ScriptEngineGetFieldOffset wrapper.

Parameters
TypeName
FieldName
FieldOffset
Returns
BOOLEAN
134{
135 return ScriptEngineGetFieldOffset(TypeName, FieldName, FieldOffset);
136}
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE BOOLEAN ScriptEngineGetFieldOffset(CHAR *TypeName, CHAR *FieldName, UINT32 *FieldOffset)
Get offset of a field from the structure.
Definition script-engine.c:170

◆ ScriptEngineLoadFileSymbolWrapper()

UINT32 ScriptEngineLoadFileSymbolWrapper ( UINT64 BaseAddress,
const CHAR * PdbFileName,
const CHAR * CustomModuleName )

ScriptEngineLoadFileSymbol wrapper.

Parameters
BaseAddress
FileName
Returns
UINT32
69{
70 return ScriptEngineLoadFileSymbol(BaseAddress, PdbFileName, CustomModuleName);
71}
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE UINT32 ScriptEngineLoadFileSymbol(UINT64 BaseAddress, const CHAR *PdbFileName, const CHAR *CustomModuleName)
Definition script-engine.c:89

◆ ScriptEngineParseWrapper()

PVOID ScriptEngineParseWrapper ( CHAR * Expr,
BOOLEAN ShowErrorMessageIfAny )

ScriptEngineParse wrapper.

Parameters
Expr
ShowErrorMessageIfAny
Returns
PVOID
299{
300 PSYMBOL_BUFFER SymbolBuffer;
301 SymbolBuffer = (PSYMBOL_BUFFER)ScriptEngineParse(Expr);
302
303 //
304 // Check if there is an error or not
305 //
306 if (SymbolBuffer->Message == NULL)
307 {
308 return SymbolBuffer;
309 }
310 else
311 {
312 //
313 // Show error message and free the buffer
314 //
315 if (ShowErrorMessageIfAny)
316 {
317 ShowMessages("%s\n", SymbolBuffer->Message);
318 }
320 return NULL;
321 }
322}
VOID ScriptEngineWrapperRemoveSymbolBuffer(PVOID SymbolBuffer)
wrapper for removing symbol buffer
Definition script-engine-wrapper.cpp:841

◆ ScriptEngineSearchSymbolForMaskWrapper()

UINT32 ScriptEngineSearchSymbolForMaskWrapper ( const CHAR * SearchMask)

ScriptEngineSearchSymbolForMask wrapper.

Parameters
SearchMask
Returns
UINT32
118{
119 return ScriptEngineSearchSymbolForMask(SearchMask);
120}
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE UINT32 ScriptEngineSearchSymbolForMask(const CHAR *SearchMask)
Search for a special mask.
Definition script-engine.c:153

◆ ScriptEngineSetTextMessageCallbackWrapper()

VOID ScriptEngineSetTextMessageCallbackWrapper ( PVOID Handler)

ScriptEngineSetTextMessageCallback wrapper.

Parameters
Handler
Returns
VOID
82{
84}
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE VOID ScriptEngineSetTextMessageCallback(PVOID Handler)
Set the message handler as an alternative to printf.
Definition script-engine.c:104

◆ ScriptEngineShowDataBasedOnSymbolTypesWrapper()

BOOLEAN ScriptEngineShowDataBasedOnSymbolTypesWrapper ( const CHAR * TypeName,
UINT64 Address,
BOOLEAN IsStruct,
PVOID BufferAddress,
const CHAR * AdditionalParameters )

ScriptEngineShowDataBasedOnSymbolTypes wrapper.

Parameters
TypeName
Address
IsStruct
BufferAddress
AdditionalParameters
Returns
BOOLEAN
219{
220 return ScriptEngineShowDataBasedOnSymbolTypes(TypeName, Address, IsStruct, BufferAddress, AdditionalParameters);
221}
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE BOOLEAN ScriptEngineShowDataBasedOnSymbolTypes(const CHAR *TypeName, UINT64 Address, BOOLEAN IsStruct, PVOID BufferAddress, const CHAR *AdditionalParameters)
Show data based on symbol types.
Definition script-engine.c:259

◆ ScriptEngineSymbolAbortLoadingWrapper()

VOID ScriptEngineSymbolAbortLoadingWrapper ( )

SymbolAbortLoading wrapper.

Returns
VOID
231{
233}
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE VOID ScriptEngineSymbolAbortLoading()
Cancel loading.
Definition script-engine.c:277

◆ ScriptEngineSymbolInitLoadWrapper()

BOOLEAN ScriptEngineSymbolInitLoadWrapper ( PMODULE_SYMBOL_DETAIL BufferToStoreDetails,
UINT32 StoredLength,
BOOLEAN DownloadIfAvailable,
const CHAR * SymbolPath,
BOOLEAN IsSilentLoad )

ScriptEngineSymbolInitLoad wrapper.

Parameters
ScriptEngineSymbolInitLoad
StoredLength
DownloadIfAvailable
SymbolPath
IsSilentLoad
Returns
BOOLEAN
197{
198 return ScriptEngineSymbolInitLoad(BufferToStoreDetails, StoredLength, DownloadIfAvailable, SymbolPath, IsSilentLoad);
199}
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE BOOLEAN ScriptEngineSymbolInitLoad(PVOID BufferToStoreDetails, UINT32 StoredLength, BOOLEAN DownloadIfAvailable, const CHAR *SymbolPath, BOOLEAN IsSilentLoad)
Initial load of the symbols.
Definition script-engine.c:236

◆ ScriptEngineUnloadAllSymbolsWrapper()

UINT32 ScriptEngineUnloadAllSymbolsWrapper ( )

ScriptEngineUnloadAllSymbols wrapper.

Returns
UINT32
93{
95}
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE UINT32 ScriptEngineUnloadAllSymbols()
Unload all the previously loaded symbols.
Definition script-engine.c:123

◆ ScriptEngineUnloadModuleSymbolWrapper()

UINT32 ScriptEngineUnloadModuleSymbolWrapper ( CHAR * ModuleName)

ScriptEngineUnloadModuleSymbol wrapper.

Parameters
ModuleName
Returns
UINT32
105{
106 return ScriptEngineUnloadModuleSymbol(ModuleName);
107}
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE UINT32 ScriptEngineUnloadModuleSymbol(CHAR *ModuleName)
Unload a special pdb.
Definition script-engine.c:138

◆ ScriptEngineWrapperGetHead()

UINT64 ScriptEngineWrapperGetHead ( PVOID SymbolBuffer)

wrapper for getting head

Parameters
SymbolBuffer
Returns
UINT64
804{
805 return (UINT64)((PSYMBOL_BUFFER)SymbolBuffer)->Head;
806}

◆ ScriptEngineWrapperGetPointer()

UINT32 ScriptEngineWrapperGetPointer ( PVOID SymbolBuffer)

wrapper for getting pointer

Parameters
SymbolBuffer
Returns
UINT32
830{
831 return (UINT32)((PSYMBOL_BUFFER)SymbolBuffer)->Pointer;
832}

◆ ScriptEngineWrapperGetSize()

UINT32 ScriptEngineWrapperGetSize ( PVOID SymbolBuffer)

wrapper for getting size

Parameters
SymbolBuffer
Returns
UINT32
816{
817 UINT32 Size =
818 (UINT32)((PSYMBOL_BUFFER)SymbolBuffer)->Pointer * sizeof(SYMBOL);
819 return Size;
820}

◆ ScriptEngineWrapperRemoveSymbolBuffer()

VOID ScriptEngineWrapperRemoveSymbolBuffer ( PVOID SymbolBuffer)

wrapper for removing symbol buffer

Parameters
SymbolBuffer
Returns
UINT32
842{
843 RemoveSymbolBuffer((PSYMBOL_BUFFER)SymbolBuffer);
844}

◆ ScriptEngineWrapperTestParser()

VOID ScriptEngineWrapperTestParser ( const string & Expr)

test parser

Parameters
Expr
Returns
VOID
675{
676 ALLOCATED_MEMORY_FOR_SCRIPT_ENGINE_CASTING AllocationsForCastings = {0};
677
678 typedef struct _TEST_STRUCT
679 {
680 UINT64 Var1;
681 UINT64 Var2;
682 UINT64 Var3;
683 UINT64 Var4;
684 } TEST_STRUCT, *PTEST_STRUCT;
685
686 PTEST_STRUCT TestStruct = (PTEST_STRUCT)malloc(sizeof(TEST_STRUCT));
687
688 if (TestStruct == NULL)
689 {
690 return;
691 }
692
693 RtlZeroMemory(TestStruct, sizeof(TEST_STRUCT));
694
695 TestStruct->Var1 = 0x41414141;
696 TestStruct->Var3 = 0x4242424242424242;
697
698 GUEST_REGS GuestRegs = {0};
699
700 CHAR test[] = "Hello world !";
701 WCHAR testw[] =
702 L"A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 "
703 L"9 a b c d e f g h i j k l m n o p q r s t u v w x y z";
704
705 CHAR * RspReg = (CHAR *)malloc(0x100);
706
707 if (RspReg == NULL)
708 {
709 ShowMessages("err, unable to allocate stack for script engine tests");
710 free(TestStruct);
711 return;
712 }
713
714 memcpy(RspReg, testw, sizeof(testw));
715
716 GuestRegs.rax = 0x1;
717 GuestRegs.rcx = (UINT64)AllocateStructForCasting(&AllocationsForCastings); // TestStruct
718 GuestRegs.rdx = 0x3;
719 GuestRegs.rbx = 0x4;
720 GuestRegs.rsp = (UINT64)RspReg + 0x50;
721 GuestRegs.rbp = 0x6;
722 GuestRegs.rsi = 0x7;
723 GuestRegs.rdi = 0x8;
724 GuestRegs.r8 = 0x9;
725 GuestRegs.r9 = 0xa;
726 GuestRegs.r10 = 0xb;
727 GuestRegs.r11 = 0xc;
728 GuestRegs.r12 = 0xd;
729 GuestRegs.r13 = 0xe;
730 GuestRegs.r14 = (UINT64)testw;
731 GuestRegs.r15 = (UINT64)test;
732
733 ScriptEngineEvalWrapper(&GuestRegs, Expr);
734
735 free(RspReg);
736 free(TestStruct);
737 free(AllocationsForCastings.Buff1);
738 free(AllocationsForCastings.Buff2);
739 free(AllocationsForCastings.Buff3);
740 free(AllocationsForCastings.Buff4);
741 free(AllocationsForCastings.Buff5);
742 free(AllocationsForCastings.Buff6);
743}
PVOID AllocateStructForCasting(PALLOCATED_MEMORY_FOR_SCRIPT_ENGINE_CASTING AllocationsForCastings)
allocate memory and build structure for casting
Definition script-engine-wrapper.cpp:531
struct _ALLOCATED_MEMORY_FOR_SCRIPT_ENGINE_CASTING ALLOCATED_MEMORY_FOR_SCRIPT_ENGINE_CASTING
UINT64 rsp
Definition BasicTypes.h:145
UINT64 r14
Definition BasicTypes.h:155
UINT64 r15
Definition BasicTypes.h:156
UINT64 rdi
Definition BasicTypes.h:148
UINT64 rax
Definition BasicTypes.h:141
UINT64 r12
Definition BasicTypes.h:153
UINT64 r13
Definition BasicTypes.h:154
UINT64 r9
Definition BasicTypes.h:150
UINT64 r8
Definition BasicTypes.h:149
UINT64 rbp
Definition BasicTypes.h:146
UINT64 rbx
Definition BasicTypes.h:144
UINT64 r10
Definition BasicTypes.h:151
UINT64 rcx
Definition BasicTypes.h:142
UINT64 rsi
Definition BasicTypes.h:147
UINT64 r11
Definition BasicTypes.h:152
UINT64 rdx
Definition BasicTypes.h:143

◆ ScriptEngineWrapperTestParserForHwdbg()

VOID ScriptEngineWrapperTestParserForHwdbg ( const string & Expr)

test parser for hwdbg

Parameters
Expr
Returns
VOID
753{
755 {
756 g_HwdbgPinsStatus = (UINT64 *)malloc(MAX_HWDBG_TESTING_PIN_COUNT * sizeof(UINT64));
757
758 if (g_HwdbgPinsStatus == NULL)
759 {
760 ShowMessages("err, could not allocate memory for hwdbg pins status");
761
762 return;
763 }
764
765 RtlZeroMemory(g_HwdbgPinsStatus, MAX_HWDBG_TESTING_PIN_COUNT * sizeof(UINT64));
766 }
767
769}
#define MAX_HWDBG_TESTING_PIN_COUNT
Maximum hwdbg testing pins count (for emulating the script behavior).
Definition Definition.h:65
struct GUEST_REGS * PGUEST_REGS
UINT64 * g_HwdbgPinsStatus
Holder of pins (and ports) status of hwdbg.
Definition globals.h:709

Variable Documentation

◆ g_CurrentExprEvalResult

UINT64 g_CurrentExprEvalResult
extern

global variable to save the result of script-engine statement tests

◆ g_CurrentExprEvalResultHasError

BOOLEAN g_CurrentExprEvalResultHasError
extern

global variable to detect if there was an error in the result of script-engine statement tests

◆ g_HwdbgPinsStatus

UINT64* g_HwdbgPinsStatus
extern

Holder of pins (and ports) status of hwdbg.

◆ g_ScriptGlobalVariables

UINT64* g_ScriptGlobalVariables
extern

Holder of script engines global variables.

◆ g_ScriptStackBuffer

UINT64* g_ScriptStackBuffer
extern

Holder of stack buffer for script engine.