diff --git a/hyperdbg/hprdbgctrl/sewrapper.cpp b/hyperdbg/hprdbgctrl/sewrapper.cpp index 401f963c..38a7971e 100644 --- a/hyperdbg/hprdbgctrl/sewrapper.cpp +++ b/hyperdbg/hprdbgctrl/sewrapper.cpp @@ -91,7 +91,6 @@ VOID ScriptEngineWrapperTestPerformAction(PGUEST_REGS_USER_MODE GuestRegs, NameOfOperator); break; - break; } } } else { diff --git a/hyperdbg/include/ScriptEngineCommon.h b/hyperdbg/include/ScriptEngineCommon.h index 40d09518..cf3791bf 100644 --- a/hyperdbg/include/ScriptEngineCommon.h +++ b/hyperdbg/include/ScriptEngineCommon.h @@ -568,6 +568,25 @@ VOID ScriptEngineFunctionJson(UINT64 Tag, BOOLEAN ImmediateMessagePassing, #endif // SCRIPT_ENGINE_KERNEL_MODE } +VOID ScriptEngineFunctionPrintf(UINT64 Tag, BOOLEAN ImmediateMessagePassing, + char* Format, UINT64 ArgCount, PSYMBOL FirstArg) { + +#ifdef SCRIPT_ENGINE_USER_MODE + ShowMessages("%s\n", Format); + PSYMBOL Symbol; + for (int i = 0; i < ArgCount; i++) + { + Symbol = FirstArg + i; + ShowMessages("%d\t",Symbol->Value); + } + +#endif // SCRIPT_ENGINE_USER_MODE + +#ifdef SCRIPT_ENGINE_KERNEL_MODE + LogSimpleWithTag(Tag, ImmediateMessagePassing, "%s : %d\n", Name, Value); +#endif // SCRIPT_ENGINE_KERNEL_MODE +} + UINT64 GetRegValue(PGUEST_REGS_USER_MODE GuestRegs, PSYMBOL Symbol) { switch (Symbol->Value) { case REGISTER_RAX: @@ -734,6 +753,7 @@ BOOL ScriptEngineExecute(PGUEST_REGS_USER_MODE GuestRegs, #ifdef SCRIPT_ENGINE_USER_MODE ShowMessages("Error:Expecting Operator Type.\n"); + return HasError; #endif // SCRIPT_ENGINE_USER_MODE } @@ -1152,5 +1172,37 @@ BOOL ScriptEngineExecute(PGUEST_REGS_USER_MODE GuestRegs, (char *)&Src1->Value, SrcVal0); return HasError; + + case FUNC_PRINTF: + + // + // Call the target function + // + + + *Indx = + *Indx + ((sizeof(unsigned long long) + strlen((char*)&Src0->Value)) / + sizeof(SYMBOL)); + + Src1 = (PSYMBOL)((unsigned long long)CodeBuffer->Head + + (unsigned long long)(*Indx * sizeof(SYMBOL))); + + *Indx = *Indx + 1; + + + PSYMBOL Src2 = NULL; + + if (Src1->Value > 0) + { + Src2 = (PSYMBOL)((unsigned long long)CodeBuffer->Head + + (unsigned long long)(*Indx * sizeof(SYMBOL))); + + *Indx = *Indx + Src1->Value; + } + ScriptEngineFunctionPrintf(ActionDetail.Tag, + ActionDetail.ImmediatelySendTheResults, (char*)&Src0->Value, Src1->Value, Src2); + + + return HasError; } } diff --git a/hyperdbg/include/ScriptEngineCommonDefinitions.h b/hyperdbg/include/ScriptEngineCommonDefinitions.h index 23c24dbd..fd83df25 100644 --- a/hyperdbg/include/ScriptEngineCommonDefinitions.h +++ b/hyperdbg/include/ScriptEngineCommonDefinitions.h @@ -34,6 +34,7 @@ typedef struct ACTION_BUFFER { #define SYMBOL_SEMANTIC_RULE_TYPE 4 #define SYMBOL_TEMP_TYPE 5 #define SYMBOL_STRING_TYPE 6 +#define SYMBOL_VARIABLE_COUNT_TYPE 7 #define INVALID -1 @@ -66,6 +67,7 @@ typedef struct ACTION_BUFFER { #define FUNC_LOW 24 #define FUNC_NOT 25 #define FUNC_MOV 26 +#define FUNC_VARGSTART 27 #define REGISTER_RAX 0 #define REGISTER_RCX 1 diff --git a/hyperdbg/script-engine/ScriptEngine.c b/hyperdbg/script-engine/ScriptEngine.c index c5da4435..952cb7a5 100644 --- a/hyperdbg/script-engine/ScriptEngine.c +++ b/hyperdbg/script-engine/ScriptEngine.c @@ -247,19 +247,24 @@ void CodeGen(TOKEN_LIST MatchedStack, PSYMBOL_BUFFER CodeBuffer, TOKEN Operator) PSYMBOL TempSymbol; OperatorSymbol = ToSymbol(Operator); - PushSymbol(CodeBuffer, OperatorSymbol); + - Op0 = Pop(MatchedStack); - Op0Symbol = ToSymbol(Op0); - PushSymbol(CodeBuffer, Op0Symbol); + if (!strcmp(Operator->Value, "@MOV")) { + PushSymbol(CodeBuffer, OperatorSymbol); + Op0 = Pop(MatchedStack); + Op0Symbol = ToSymbol(Op0); + PushSymbol(CodeBuffer, Op0Symbol); + RemoveSymbol(Op0Symbol); + Op1 = Pop(MatchedStack); Op1Symbol = ToSymbol(Op1); PushSymbol(CodeBuffer, Op1Symbol); + RemoveSymbol(Op1Symbol); /* printf("%s\t%s,\t%s\n", Operator->Value, Op1->Value, Op0->Value); @@ -270,19 +275,34 @@ void CodeGen(TOKEN_LIST MatchedStack, PSYMBOL_BUFFER CodeBuffer, TOKEN Operator) // FreeTemp(Op0); FreeTemp(Op1); + } else if (IsType2Func(Operator)) { + PushSymbol(CodeBuffer, OperatorSymbol); + Op0 = Pop(MatchedStack); + Op0Symbol = ToSymbol(Op0); + PushSymbol(CodeBuffer, Op0Symbol); + RemoveSymbol(Op0Symbol); /* printf("%s\t%s\n", Operator->Value, Op0->Value); printf("_____________\n");*/ + + } else if (IsType1Func(Operator)) { + PushSymbol(CodeBuffer, OperatorSymbol); + Op0 = Pop(MatchedStack); + Op0Symbol = ToSymbol(Op0); + PushSymbol(CodeBuffer, Op0Symbol); + RemoveSymbol(Op0Symbol); + Temp = NewTemp(); Push(MatchedStack, Temp); TempSymbol = ToSymbol(Temp); PushSymbol(CodeBuffer, TempSymbol); + RemoveSymbol(TempSymbol); /* printf("%s\t%s,\t%s\n", Operator->Value, Temp->Value, Op0->Value); printf("_____________\n");*/ @@ -290,24 +310,91 @@ void CodeGen(TOKEN_LIST MatchedStack, PSYMBOL_BUFFER CodeBuffer, TOKEN Operator) // Free the operand if it is a temp value // FreeTemp(Op0); + } else if (IsType3Func(Operator)) { + PushSymbol(CodeBuffer, OperatorSymbol); + Op0 = Pop(MatchedStack); + Op0Symbol = ToSymbol(Op0); + PushSymbol(CodeBuffer, Op0Symbol); + RemoveSymbol(Op0Symbol); + Op1 = Pop(MatchedStack); Op1Symbol = ToSymbol(Op1); PushSymbol(CodeBuffer, Op1Symbol); + RemoveSymbol(Op1Symbol); + // // Free the operand if it is a temp value // FreeTemp(Op0); FreeTemp(Op1); + + } + else if (IsType4Func(Operator)) + { + PushSymbol(CodeBuffer, OperatorSymbol); + PSYMBOL_BUFFER TempStack = NewSymbolBuffer(); + UINT32 OperandCount = 0; + + do + { + Op1 = Pop(MatchedStack); + if (Op1->Type != SEMANTIC_RULE) + { + Op1Symbol = ToSymbol(Op1); + PushSymbol(TempStack, Op1Symbol); + RemoveSymbol(Op1Symbol); + FreeTemp(Op1); + OperandCount++; + } + + } while (!(Op1->Type == SEMANTIC_RULE && !strcmp(Op1->Value, "@VARGSTART"))); + + printf("Operand Count = %d \n", OperandCount); + + Op0 = Pop(MatchedStack); + Op0Symbol = ToSymbol(Op0); + PushSymbol(CodeBuffer, Op0Symbol); + RemoveSymbol(Op0Symbol); + + // TODO: Push OperandCount + PSYMBOL OperandCountSymbol = NewSymbol(); + OperandCountSymbol->Type = SYMBOL_VARIABLE_COUNT_TYPE; + OperandCountSymbol->Value = OperandCount; + PushSymbol(CodeBuffer, OperandCountSymbol); + RemoveSymbol(OperandCountSymbol); + + + PSYMBOL Symbol; + for (int i = TempStack->Pointer - 1; i >= 0 ;i--) + { + Symbol = TempStack->Head + i; + PushSymbol(CodeBuffer, Symbol); + } + RemoveSymbolBuffer(TempStack); + + + + + + FreeTemp(Op0); + } else if (IsNaiveOperator(Operator)) { + PushSymbol(CodeBuffer, OperatorSymbol); + Op0 = Pop(MatchedStack); + Op0Symbol = ToSymbol(Op0); + PushSymbol(CodeBuffer, Op0Symbol); + RemoveSymbol(Op0Symbol); + Op1 = Pop(MatchedStack); Op1Symbol = ToSymbol(Op1); PushSymbol(CodeBuffer, Op1Symbol); + RemoveSymbol(Op1Symbol); @@ -315,6 +402,9 @@ void CodeGen(TOKEN_LIST MatchedStack, PSYMBOL_BUFFER CodeBuffer, TOKEN Operator) Push(MatchedStack, Temp); TempSymbol = ToSymbol(Temp); PushSymbol(CodeBuffer, TempSymbol); + RemoveSymbol(TempSymbol); + + /* printf("%s\t%s,\t%s,\t%s\n", Operator->Value, Temp->Value, Op0->Value, Op1->Value); @@ -325,11 +415,23 @@ void CodeGen(TOKEN_LIST MatchedStack, PSYMBOL_BUFFER CodeBuffer, TOKEN Operator) // FreeTemp(Op0); FreeTemp(Op1); + } + else if (!strcmp (Operator->Value, "@VARGSTART")) + { + TOKEN OperatorCopy = NewToken(); + OperatorCopy->Value = malloc(strlen(Operator->Value) + 1); + strcpy(OperatorCopy->Value, Operator->Value); + OperatorCopy->Type = Operator->Type; + Push(MatchedStack, OperatorCopy); + + } + else { - printf("Internal Error: Unhandled sematic ruls.\n"); + printf("Internal Error: Unhandled semantic ruls.\n"); } + RemoveSymbol(OperatorSymbol); return; } @@ -535,7 +637,7 @@ PSYMBOL_BUFFER PushSymbol(PSYMBOL_BUFFER SymbolBuffer, const PSYMBOL Symbol) } strcpy((char*)&WriteAddr->Value, (char*)&Symbol->Value); - RemoveSymbol(Symbol); + } else { @@ -543,7 +645,7 @@ PSYMBOL_BUFFER PushSymbol(PSYMBOL_BUFFER SymbolBuffer, const PSYMBOL Symbol) // Write input to the appropriate address in SymbolBuffer // *WriteAddr = *Symbol; - RemoveSymbol(Symbol); + // // Update Pointer @@ -593,7 +695,7 @@ PSYMBOL_BUFFER PushSymbol(PSYMBOL_BUFFER SymbolBuffer, const PSYMBOL Symbol) void PrintSymbolBuffer(const PSYMBOL_BUFFER SymbolBuffer) { PSYMBOL Symbol; - for (int i = 0; i < SymbolBuffer->Pointer; i++) + for (int i = 0; i < SymbolBuffer->Pointer;) { Symbol = SymbolBuffer->Head + i; diff --git a/hyperdbg/script-engine/common.c b/hyperdbg/script-engine/common.c index 795074e5..3f850faa 100644 --- a/hyperdbg/script-engine/common.c +++ b/hyperdbg/script-engine/common.c @@ -116,6 +116,12 @@ void PrintToken(TOKEN Token) case END_OF_STACK: printf(" END_OF_STACK>\n"); break; + case STRING: + printf(" STRING>\n"); + break; + case TEMP: + printf(" TEMP>\n"); + break; case UNKNOWN: printf(" UNKNOWN>\n"); break; @@ -418,7 +424,7 @@ TOKEN NewTemp(void) if (i == MAX_TEMP_COUNT) { // TODO: Handle Error - printf("Error: Not enough tempporary variables to allocate. \n"); + printf("Error: Not enough temporary variables to allocate. \n"); } TOKEN Temp = NewToken(); char TempValue[8]; @@ -491,6 +497,19 @@ char IsType3Func(TOKEN Operator) return 0; } +char IsType4Func(TOKEN Operator) +{ + unsigned int n = TWOOPFUNC1_LENGTH; + for (int i = 0; i < n; i++) + { + if (!strcmp(Operator->Value, VarArgFunc1[i])) + { + return 1; + } + } + return 0; +} + /** * * diff --git a/hyperdbg/script-engine/parse_table.c b/hyperdbg/script-engine/parse_table.c index 91f1213d..34e48d05 100644 --- a/hyperdbg/script-engine/parse_table.c +++ b/hyperdbg/script-engine/parse_table.c @@ -75,7 +75,7 @@ const struct _TOKEN Rhs[RULES_COUNT][MAX_RHS_LEN]= {{KEYWORD, "print"},{SPECIAL_TOKEN, "("},{NON_TERMINAL, "E0"},{SEMANTIC_RULE, "@PRINT"},{SPECIAL_TOKEN, ")"}}, {{KEYWORD, "formats"},{SPECIAL_TOKEN, "("},{NON_TERMINAL, "E0"},{SEMANTIC_RULE, "@FORMATS"},{SPECIAL_TOKEN, ")"}}, {{KEYWORD, "json"},{SPECIAL_TOKEN, "("},{NON_TERMINAL, "E11"},{SPECIAL_TOKEN, ","},{NON_TERMINAL, "E0"},{SEMANTIC_RULE, "@JSON"},{SPECIAL_TOKEN, ")"}}, - {{SEMANTIC_RULE, "@PRINTF"},{SPECIAL_TOKEN, "("},{NON_TERMINAL, "E11"},{SEMANTIC_RULE, "@VARGSTART"},{NON_TERMINAL, "VA"},{SEMANTIC_RULE, "@VarArgFunc1"},{SPECIAL_TOKEN, ")"}}, + {{KEYWORD, "printf"},{SPECIAL_TOKEN, "("},{NON_TERMINAL, "E11"},{SEMANTIC_RULE, "@VARGSTART"},{NON_TERMINAL, "VA"},{SEMANTIC_RULE, "@PRINTF"},{SPECIAL_TOKEN, ")"}}, {{SPECIAL_TOKEN, ","},{NON_TERMINAL, "E0"},{NON_TERMINAL, "VA"}}, {{EPSILON, "eps"}}, {{EPSILON, "eps"}}, @@ -198,106 +198,107 @@ const unsigned int RhsSize[RULES_COUNT]= }; const char* NoneTerminalMap[NONETERMINAL_COUNT]= { -"E6'", -"E6", +"E3", "E5", -"S'", -"E0'", -"E2'", -"E3'", -"C'", -"E1", -"E7", -"C", -"E4", -"E7'", -"E0", -"E4'", -"E10", -"E1'", -"E9", -"E11", -"E8", -"E5'", -"E9'", "E8'", -"E2", -"VA", +"E0'", +"E6", +"S'", "S", -"E3" +"E3'", +"E2'", +"E2", +"E8", +"E7'", +"E6'", +"E4", +"E9'", +"E10", +"E7", +"E9", +"C'", +"E0", +"C", +"E1", +"E4'", +"VA", +"E5'", +"E11", +"E1'" }; const char* TerminalMap[TERMINAL_COUNT]= { -"json", -"sizeof", -"_id", -"&", -"(", -"_hex", -"print", -"^", -"_pseudo_register", -"<<", -"_string", -"formats", -"str", -"*", -"_register", -"$", -"-", "|", -"wstr", -";", -"dw", -"_binary", -"=", -"dq", -",", -"dd", -"hi", -"_decimal", +"print", +"_id", +"<<", +"json", +"*", "/", -"%", -"low", -")", -"neg", -"poi", -"+", +"-", +"_register", +";", +"hi", "_octal", +")", +"dw", "func", +"_string", +"+", +"neg", +"str", +"(", +"&", +"_decimal", +"=", +">>", +"_hex", +"$", +"sizeof", +"wstr", +"printf", +"formats", +"_binary", +"%", +"dd", +"dq", "db", +"_pseudo_register", +",", "not", -">>" +"poi", +"^", +"low" }; const int ParseTable[NONETERMINAL_COUNT][TERMINAL_COUNT]= { - {-1 ,-1 ,-1 ,31 ,-1 ,-1 ,-1 ,31 ,-1 ,31 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,30 ,31 ,-1 ,31 ,-1 ,-1 ,-1 ,-1 ,31 ,-1 ,-1 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,16 ,-1 ,-1 ,15 ,-1 } }; const char* KeywordList[]= { "print", @@ -380,7 +381,8 @@ const SYMBOL_MAP SemanticRulesMapList[]= { {"@HI", FUNC_HI}, {"@LOW", FUNC_LOW}, {"@NOT", FUNC_NOT}, -{"@MOV", FUNC_MOV} +{"@MOV", FUNC_MOV}, +{"@VARGSTART", FUNC_VARGSTART} }; const SYMBOL_MAP RegisterMapList[]= { {"rax", REGISTER_RAX}, diff --git a/hyperdbg/script-engine/parse_table.h b/hyperdbg/script-engine/parse_table.h index 5b3bccf1..37be02fb 100644 --- a/hyperdbg/script-engine/parse_table.h +++ b/hyperdbg/script-engine/parse_table.h @@ -3,7 +3,7 @@ #include "common.h" #include "ScriptEngineCommonDefinitions.h" #define RULES_COUNT 62 -#define TERMINAL_COUNT 40 +#define TERMINAL_COUNT 41 #define NONETERMINAL_COUNT 27 #define START_VARIABLE "S" #define MAX_RHS_LEN 7 @@ -11,7 +11,7 @@ #define OPERATORS_LIST_LENGTH 10 #define REGISTER_MAP_LIST_LENGTH 16 #define PSEUDO_REGISTER_MAP_LIST_LENGTH 9 -#define SEMANTIC_RULES_MAP_LIST_LENGTH 27 +#define SEMANTIC_RULES_MAP_LIST_LENGTH 28 #define ONEOPFUNC1_LENGTH 12 #define ONEOPFUNC2_LENGTH 2 #define TWOOPFUNC1_LENGTH 1 diff --git a/hyperdbg/script-engine/python/Grammar.txt b/hyperdbg/script-engine/python/Grammar.txt index 669328c5..021b93ad 100644 --- a/hyperdbg/script-engine/python/Grammar.txt +++ b/hyperdbg/script-engine/python/Grammar.txt @@ -20,7 +20,7 @@ S'->eps C->@PUSH _id = E0 @MOV C' C->.OneOpFunc2 ( E0 @.OneOpFunc2 ) C->.TwoOpFunc1 ( E11 , E0 @.OneOpFunc1 ) -C->.VarArgFunc1 ( E11 @VARGSTART VA @VarArgFunc1 ) +C->.VarArgFunc1 ( E11 @VARGSTART VA @.VarArgFunc1 ) VA->, E0 VA VA->eps diff --git a/hyperdbg/script-engine/python/parse_table_generator.py b/hyperdbg/script-engine/python/parse_table_generator.py index bec29bdc..e25d0dfd 100644 --- a/hyperdbg/script-engine/python/parse_table_generator.py +++ b/hyperdbg/script-engine/python/parse_table_generator.py @@ -115,7 +115,7 @@ class Parser: self.HeaderFile.write("#define OPERATORS_LIST_LENGTH " + str(len(self.OperatorsList)) + "\n") self.HeaderFile.write("#define REGISTER_MAP_LIST_LENGTH " + str(len(self.RegistersList))+ "\n") self.HeaderFile.write("#define PSEUDO_REGISTER_MAP_LIST_LENGTH " + str(len(self.PseudoRegistersList))+ "\n") - self.HeaderFile.write("#define SEMANTIC_RULES_MAP_LIST_LENGTH " + str(len(self.keywordList) + len(self.OperatorsList) + 1)+ "\n") + self.HeaderFile.write("#define SEMANTIC_RULES_MAP_LIST_LENGTH " + str(len(self.keywordList) + len(self.OperatorsList) + 2)+ "\n") for Key in self.FunctionsDict: self.HeaderFile.write("#define "+ Key[1:].upper() + "_LENGTH "+ str(len(self.FunctionsDict[Key]))+"\n") @@ -188,6 +188,7 @@ typedef struct ACTION_BUFFER { #define SYMBOL_SEMANTIC_RULE_TYPE 4 #define SYMBOL_TEMP_TYPE 5 #define SYMBOL_STRING_TYPE 6 +#define SYMBOL_VARIABLE_COUNT_TYPE 7 #define INVALID -1 @@ -237,9 +238,6 @@ typedef struct ACTION_BUFFER { # Read top of stack Top = GetTop(Stack) - print(CurrentIn) - print(Stack) - if self.IsNoneTerminal(Top): Id = self.ParseTable[self.GetNoneTerminalId(Top)][self.GetTerminalId(CurrentIn)] @@ -384,7 +382,10 @@ typedef struct ACTION_BUFFER { for X in self.keywordList: self.CommonHeaderFile.write("#define " + "FUNC_" + X.upper() + " " + str(Counter) + "\n") Counter += 1 - self.CommonHeaderFile.write("#define "+ "FUNC_MOV " + str(Counter) + "\n\n") + self.CommonHeaderFile.write("#define "+ "FUNC_MOV " + str(Counter) + "\n") + + Counter += 1 + self.CommonHeaderFile.write("#define "+ "FUNC_VARGSTART " + str(Counter) + "\n\n") self.SourceFile.write("const SYMBOL_MAP SemanticRulesMapList[]= {\n") @@ -396,7 +397,8 @@ typedef struct ACTION_BUFFER { for X in self.keywordList: self.SourceFile.write("{\"@" + X.upper() + "\", "+ "FUNC_" + X.upper() + "},\n") - self.SourceFile.write("{\"@" + "MOV" + "\", "+ "FUNC_MOV" + "}\n") + self.SourceFile.write("{\"@" + "MOV" + "\", "+ "FUNC_MOV" + "},\n") + self.SourceFile.write("{\"@" + "VARGSTART" + "\", "+ "FUNC_VARGSTART" + "}\n") self.SourceFile.write("};\n") @@ -469,8 +471,6 @@ typedef struct ACTION_BUFFER { def WriteMaps(self): for Key in self.FunctionsDict: - print(Key) - self.HeaderFile.write("extern const char* "+ Key[1:]+ "[];\n") self.SourceFile.write("const char* "+ Key[1:]+ "[] = {\n") diff --git a/hyperdbg/script-engine/scanner.c b/hyperdbg/script-engine/scanner.c index 1500d448..cab9b379 100644 --- a/hyperdbg/script-engine/scanner.c +++ b/hyperdbg/script-engine/scanner.c @@ -388,7 +388,7 @@ TOKEN GetToken(char* c, char* str) if (*c != '`') Append(Token, *c); *c = sgetc(str); - } while (IsLetter(*c) || *c == '`'); + } while (IsLetter(*c) || IsHex(*c) || *c == '`'); if (IsKeyword(Token->Value)) { Token->Type = KEYWORD;