Interpret general event fields.
2355{
2362 UINT32 LengthOfCustomCodeActionBuffer = 0;
2363 UINT32 LengthOfScriptActionBuffer = 0;
2364 UINT32 LengthOfBreakActionBuffer = 0;
2365 UINT64 ConditionBufferAddress;
2366 UINT32 ConditionBufferLength = 0;
2367 vector<string> ListOfOutputSources;
2368 UINT64 CodeBufferAddress;
2369 UINT32 CodeBufferLength = 0;
2370 UINT64 ScriptBufferAddress;
2371 UINT64 ScriptCodeBuffer = 0;
2372 BOOLEAN HasScriptSyntaxError = 0;
2373 UINT32 ScriptBufferLength = 0;
2374 UINT32 ScriptBufferPointer = 0;
2375 UINT32 LengthOfEventBuffer = 0;
2376 string CommandString;
2391 UINT32 IndexOfValidSourceTags;
2392 UINT32 RequestBuffer = 0;
2393 PLIST_ENTRY TempList;
2395 vector<int> IndexesToRemove;
2396 vector<UINT64> ListOfValidSourceTags;
2397 int NewIndexToRemove = 0;
2398 int Index = 0;
2399
2400
2401
2402
2403 for (auto Section : *SplitCommandCaseSensitive)
2404 {
2405 CommandString.append(Section);
2406 CommandString.append(" ");
2407 }
2408
2409
2410
2411
2412 UINT64 BufferOfCommandStringLength = CommandString.size() + 1;
2413
2414
2415
2416
2417 PVOID BufferOfCommandString = malloc(BufferOfCommandStringLength);
2418
2419 RtlZeroMemory(BufferOfCommandString, BufferOfCommandStringLength);
2420
2421
2422
2423
2424 memcpy(BufferOfCommandString, CommandString.c_str(), CommandString.size());
2425
2426
2427
2428
2430 {
2431
2432
2433
2434 HasConditionBuffer =
FALSE;
2435
2436
2437
2438
2439 }
2440 else
2441 {
2442
2443
2444
2445 HasConditionBuffer =
TRUE;
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466 }
2467
2468
2469
2470
2472 {
2473
2474
2475
2476 HasCodeBuffer =
FALSE;
2477
2478
2479
2480 }
2481 else
2482 {
2483
2484
2485
2486 HasCodeBuffer =
TRUE;
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506 }
2507
2508
2509
2510
2512 SplitCommandCaseSensitive,
2513 &HasScriptSyntaxError,
2514 &ScriptBufferAddress,
2515 &ScriptBufferLength,
2516 &ScriptBufferPointer,
2517 &ScriptCodeBuffer))
2518 {
2519
2520
2521
2523
2524
2525
2526 }
2527 else
2528 {
2529
2530
2531
2532 if (HasScriptSyntaxError)
2533 {
2534 free(BufferOfCommandString);
2535
2538 }
2539
2540
2541
2542
2544 }
2545
2546
2547
2548
2549 if (!
InterpretOutput(SplitCommand, SplitCommandCaseSensitive, ListOfOutputSources))
2550 {
2551
2552
2553
2554 HasOutputPath =
FALSE;
2555
2556
2557
2558
2559 }
2560 else
2561 {
2562
2563
2564
2565 if (ListOfOutputSources.size() == 0)
2566 {
2567
2568
2569
2570 free(BufferOfCommandString);
2571
2575 }
2576
2577
2578
2579
2581 {
2582 free(BufferOfCommandString);
2583
2585 "err, based on this build of HyperDbg, the maximum input sources for "
2586 "a single event is 0x%x sources but you entered 0x%x sources\n",
2588 ListOfOutputSources.size());
2591 }
2592
2593
2594
2595
2597 {
2598 free(BufferOfCommandString);
2599
2600 ShowMessages(
"err, the name you entered, not found. Did you use "
2601 "'output' command to create it?\n");
2604 }
2605
2606
2607
2608
2609 for (auto item : ListOfOutputSources)
2610 {
2611 TempList = 0;
2612 OutputSourceFound =
FALSE;
2613
2614
2615
2616
2617
2619
2621 {
2622 TempList = TempList->Flink;
2623
2625
2626 if (strcmp(CurrentOutputSourceDetails->
Name,
2628 {
2629
2630
2631
2633 {
2634 free(BufferOfCommandString);
2635
2639 }
2640
2641
2642
2643
2645 {
2646
2647
2648
2649 ShowMessages(
"some of the output(s) are not opened, it's not an error, but please ensure "
2650 "to open the output using the 'output' command to forward the results to the "
2651 "target resource\n");
2652 }
2653
2654
2655
2656
2657 OutputSourceFound =
TRUE;
2658
2659
2660
2661
2662 ListOfValidSourceTags.push_back(
2664
2665
2666
2667
2668 break;
2669 }
2670 }
2671
2672 if (!OutputSourceFound)
2673 {
2674 free(BufferOfCommandString);
2675
2676 ShowMessages(
"err, the name you entered, not found. Did you use "
2677 "'output' command to create it?\n");
2680 }
2681 }
2682
2683
2684
2685 HasOutputPath =
TRUE;
2686 }
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2725
2727 RtlZeroMemory(TempEvent, LengthOfEventBuffer);
2728
2729
2730
2731
2732 if (TempEvent == NULL)
2733 {
2736 goto ReturnWithError;
2737 }
2738
2739
2740
2741
2743
2744
2745
2746
2748
2749
2750
2751
2752
2753
2755
2757 {
2758 ShowMessages(
"notice: as you're debugging a user-mode application, "
2759 "this event will only trigger on your current debugging process "
2760 "(pid:%x). If you want the event from the entire system, "
2761 "add 'pid all' to the event\n",
2763
2765 }
2766 else
2767 {
2769 }
2770
2771
2772
2773
2775
2776
2777
2778
2780
2781
2782
2783
2785
2786
2787
2788
2789 if (HasConditionBuffer)
2790 {
2792 (PVOID)ConditionBufferAddress,
2793 ConditionBufferLength);
2794
2795
2796
2797
2799 }
2800
2801
2802
2803
2804 if (HasCodeBuffer)
2805 {
2806
2807
2808
2809
2811
2813
2814 RtlZeroMemory(TempActionCustomCode, LengthOfCustomCodeActionBuffer);
2815
2816 memcpy(
2818 (PVOID)CodeBufferAddress,
2819 CodeBufferLength);
2820
2821
2822
2824
2825
2826
2827
2829
2830
2831
2832
2834
2835
2836
2837
2839 }
2840
2841
2842
2843
2844 if (HasScript)
2845 {
2846
2847
2848
2849
2852
2853 RtlZeroMemory(TempActionScript, LengthOfScriptActionBuffer);
2854
2856 (PVOID)ScriptBufferAddress,
2857 ScriptBufferLength);
2858
2859
2860
2862
2863
2864
2865
2867
2868
2869
2870
2873
2874
2875
2876
2878
2879
2880
2881
2883 }
2884
2885
2886
2887
2888
2889 if (!HasCodeBuffer && !HasScript)
2890 {
2891
2892
2893
2894
2896
2898
2899 RtlZeroMemory(TempActionBreak, LengthOfBreakActionBuffer);
2900
2901
2902
2903
2905
2906
2907
2908
2910
2911
2912
2913
2915 }
2916
2917
2918
2919
2920 for (auto Section : *SplitCommand)
2921 {
2922 Index++;
2923 if (IsNextCommandBufferSize)
2924 {
2926 {
2929 goto ReturnWithError;
2930 }
2931 else
2932 {
2933
2934
2935
2936 if (TempActionBreak != NULL)
2937 {
2939 }
2940 if (TempActionScript != NULL)
2941 {
2943 }
2944 if (TempActionCustomCode != NULL)
2945 {
2947 }
2948 }
2949 IsNextCommandBufferSize =
FALSE;
2950
2951
2952
2953
2954 IndexesToRemove.push_back(Index);
2955
2956 continue;
2957 }
2958
2959 if (IsNextCommandImmediateMessaging)
2960 {
2961 if (!Section.compare("yes"))
2962 {
2963 ImmediateMessagePassing =
TRUE;
2964 }
2965 else if (!Section.compare("no"))
2966 {
2967 ImmediateMessagePassing =
FALSE;
2968 }
2969 else
2970 {
2971
2972
2973
2974
2975 ShowMessages(
"err, immediate messaging token is invalid\n");
2977 goto ReturnWithError;
2978 }
2979
2980 IsNextCommandImmediateMessaging =
FALSE;
2981
2982
2983
2984
2985 IndexesToRemove.push_back(Index);
2986
2987 continue;
2988 }
2989
2990 if (IsNextCommandExecutionStage)
2991 {
2992 if (!Section.compare("pre"))
2993 {
2995 }
2996 else if (!Section.compare("post"))
2997 {
2999 }
3000 else if (!Section.compare("all"))
3001 {
3003 }
3004 else
3005 {
3006
3007
3008
3009
3010 ShowMessages(
"err, the specified execution mode is invalid; you can either choose 'pre' or 'post'\n");
3012 goto ReturnWithError;
3013 }
3014
3015 IsNextCommandExecutionStage =
FALSE;
3016
3017
3018
3019
3020 IndexesToRemove.push_back(Index);
3021
3022 continue;
3023 }
3024
3025 if (IsNextCommandSc)
3026 {
3027 if (!Section.compare("on"))
3028 {
3029 IsAShortCircuitingEventByDefault =
TRUE;
3030 }
3031 else if (!Section.compare("off"))
3032 {
3033 IsAShortCircuitingEventByDefault =
FALSE;
3034 }
3035 else
3036 {
3037
3038
3039
3040
3041 ShowMessages(
"err, the specified short-circuiting state is invalid; you can either choose 'on' or 'off'\n");
3043 goto ReturnWithError;
3044 }
3045
3046 IsNextCommandSc =
FALSE;
3047
3048
3049
3050
3051 IndexesToRemove.push_back(Index);
3052
3053 continue;
3054 }
3055
3056 if (IsNextCommandPid)
3057 {
3058 if (!Section.compare("all"))
3059 {
3061 }
3063 {
3066
3067 goto ReturnWithError;
3068 }
3069 else
3070 {
3071
3072
3073
3075 }
3076
3077 IsNextCommandPid =
FALSE;
3078
3079
3080
3081
3082 IndexesToRemove.push_back(Index);
3083
3084 continue;
3085 }
3086
3087 if (IsNextCommandCoreId)
3088 {
3090 {
3093 goto ReturnWithError;
3094 }
3095 else
3096 {
3097
3098
3099
3100 TempEvent->
CoreId = CoreId;
3101 }
3102 IsNextCommandCoreId =
FALSE;
3103
3104
3105
3106
3107 IndexesToRemove.push_back(Index);
3108
3109 continue;
3110 }
3111
3112 if (!Section.compare("pid"))
3113 {
3114 IsNextCommandPid =
TRUE;
3115
3116
3117
3118
3119 IndexesToRemove.push_back(Index);
3120
3121 continue;
3122 }
3123 if (!Section.compare("core"))
3124 {
3125 IsNextCommandCoreId =
TRUE;
3126
3127
3128
3129
3130 IndexesToRemove.push_back(Index);
3131
3132 continue;
3133 }
3134
3135 if (!Section.compare("imm"))
3136 {
3137
3138
3139
3140 IsNextCommandImmediateMessaging =
TRUE;
3141
3142
3143
3144
3145 IndexesToRemove.push_back(Index);
3146
3147 continue;
3148 }
3149
3150 if (!Section.compare("stage"))
3151 {
3152
3153
3154
3155 IsNextCommandExecutionStage =
TRUE;
3156
3157
3158
3159
3160 IndexesToRemove.push_back(Index);
3161
3162 continue;
3163 }
3164
3165 if (!Section.compare("sc"))
3166 {
3167
3168
3169
3170 IsNextCommandSc =
TRUE;
3171
3172
3173
3174
3175 IndexesToRemove.push_back(Index);
3176
3177 continue;
3178 }
3179
3180 if (!Section.compare("buffer"))
3181 {
3182 IsNextCommandBufferSize =
TRUE;
3183
3184
3185
3186
3187 IndexesToRemove.push_back(Index);
3188
3189 continue;
3190 }
3191 }
3192
3193
3194
3195
3196 if (IsNextCommandCoreId)
3197 {
3198 ShowMessages(
"err, please specify a value for 'core'\n");
3199
3201
3202 goto ReturnWithError;
3203 }
3204
3205 if (IsNextCommandPid)
3206 {
3207 ShowMessages(
"err, please specify a value for 'pid'\n");
3208
3210
3211 goto ReturnWithError;
3212 }
3213
3214 if (IsNextCommandBufferSize)
3215 {
3216 ShowMessages(
"err, please specify a value for 'buffer'\n");
3217
3219
3220 goto ReturnWithError;
3221 }
3222
3223 if (IsNextCommandImmediateMessaging)
3224 {
3225 ShowMessages(
"err, please specify a value for 'imm'\n");
3226
3228
3229 goto ReturnWithError;
3230 }
3231
3232 if (IsNextCommandExecutionStage)
3233 {
3234 ShowMessages(
"err, please specify a value for 'stage'\n");
3235
3237
3238 goto ReturnWithError;
3239 }
3240
3241 if (IsNextCommandSc)
3242 {
3243 ShowMessages(
"err, please specify a value for 'sc'\n");
3244
3246
3247 goto ReturnWithError;
3248 }
3249
3250
3251
3252
3255 IsAShortCircuitingEventByDefault)
3256 {
3258 "err, using the short-circuiting mechanism with 'post' or 'all' stage events "
3259 "doesn't make sense; it's not supported!\n");
3260
3262
3263 goto ReturnWithError;
3264 }
3265
3266
3267
3268
3270 {
3272 "err, the script or assembly code is either not found or invalid. "
3273 "As a result, the default action is to break. "
3274 "However, breaking to the debugger is not possible in the VMI Mode. "
3275 "To achieve full control of the system, you can switch to the Debugger Mode. "
3276 "In the VMI Mode, you can still use scripts and run custom code for local debugging."
3277 "For more information, please check: https://docs.hyperdbg.org/using-hyperdbg/prerequisites/operation-modes\n");
3278
3280
3281 goto ReturnWithError;
3282 }
3283
3284
3285
3286
3287
3288 if (!ImmediateMessagePassing && HasOutputPath)
3289 {
3290 ShowMessages(
"err, non-immediate message passing is not supported in "
3291 "'output-forwarding mode'\n");
3292
3294
3295 goto ReturnWithError;
3296 }
3297
3298
3299
3300
3301 if (TempActionBreak != NULL)
3302 {
3304 }
3305 if (TempActionScript != NULL)
3306 {
3308 }
3309 if (TempActionCustomCode != NULL)
3310 {
3312 }
3313
3314
3315
3316
3317 IndexOfValidSourceTags = 0;
3318 for (auto item : ListOfValidSourceTags)
3319 {
3321
3322
3323
3324
3325 IndexOfValidSourceTags++;
3326 }
3327
3328
3329
3330
3331 if (HasOutputPath)
3332 {
3334 }
3335
3336
3337
3338
3339 if (IsAShortCircuitingEventByDefault)
3340 {
3342 }
3343
3344
3345
3346
3348
3349
3350
3351
3352 *EventDetailsToFill = TempEvent;
3353 *EventBufferLength = LengthOfEventBuffer;
3354
3355
3356
3357
3358 if (TempActionBreak != NULL)
3359 {
3360 *ActionDetailsToFillBreakToDebugger = TempActionBreak;
3361 *ActionBufferLengthBreakToDebugger = LengthOfBreakActionBuffer;
3362 }
3363 if (TempActionScript != NULL)
3364 {
3365 *ActionDetailsToFillScript = TempActionScript;
3366 *ActionBufferLengthScript = LengthOfScriptActionBuffer;
3367 }
3368 if (TempActionCustomCode != NULL)
3369 {
3370 *ActionDetailsToFillCustomCode = TempActionCustomCode;
3371 *ActionBufferLengthCustomCode = LengthOfCustomCodeActionBuffer;
3372 }
3373
3374
3375
3376
3377 for (auto IndexToRemove : IndexesToRemove)
3378 {
3379 NewIndexToRemove++;
3380 SplitCommand->erase(SplitCommand->begin() + (IndexToRemove - NewIndexToRemove));
3381 SplitCommandCaseSensitive->erase(SplitCommandCaseSensitive->begin() + (IndexToRemove - NewIndexToRemove));
3382 }
3383
3384
3385
3386
3388 {
3391 }
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3406
3407ReturnWithError:
3408
3409 if (BufferOfCommandString)
3410 {
3411 free(BufferOfCommandString);
3412 }
3413
3414 if (TempEvent)
3415 {
3416 free(TempEvent);
3417 }
3418
3419 if (TempActionBreak != NULL)
3420 {
3421 free(TempActionBreak);
3422 }
3423 if (TempActionScript != NULL)
3424 {
3425 free(TempActionScript);
3426 }
3427 if (TempActionCustomCode != NULL)
3428 {
3429 free(TempActionCustomCode);
3430 }
3431
3433}
#define UseImmediateMessagingByDefaultOnEvents
Use immediate messaging (means that it sends each message when they received and do not accumulate th...
Definition Configuration.h:57
#define DEBUGGER_EVENT_APPLY_TO_ALL_CORES
Apply the event to all the cores.
Definition Constants.h:611
#define DebuggerOutputSourceMaximumRemoteSourceForSingleEvent
Determines how many sources a debugger can have for a single event.
Definition Constants.h:243
#define DEBUGGER_EVENT_APPLY_TO_ALL_PROCESSES
Apply the event to all the processes.
Definition Constants.h:617
enum _VMM_CALLBACK_EVENT_CALLING_STAGE_TYPE VMM_CALLBACK_EVENT_CALLING_STAGE_TYPE
Type of calling the event.
@ VMM_CALLBACK_CALLING_STAGE_ALL_EVENT_EMULATION
Definition DataTypes.h:95
@ VMM_CALLBACK_CALLING_STAGE_PRE_EVENT_EMULATION
Definition DataTypes.h:93
@ VMM_CALLBACK_CALLING_STAGE_POST_EVENT_EMULATION
Definition DataTypes.h:94
FORCEINLINE VOID InitializeListHead(_Out_ PLIST_ENTRY ListHead)
Definition Windows.h:41
BOOLEAN ConvertStringToUInt32(string TextToConvert, PUINT32 Result)
check and convert string to a 32 bit unsigned it and also check for special notations like 0x etc.
Definition common.cpp:347
std::string RemoveSpaces(std::string str)
Remove all the spaces in a string.
Definition common.cpp:606
BOOLEAN InterpretOutput(vector< string > *SplitCommand, vector< string > *SplitCommandCaseSensitive, vector< string > &InputSources)
Interpret output (if an event has special output)
Definition debugger.cpp:1703
BOOLEAN g_OutputSourcesInitialized
it shows whether the debugger started using output sources or not or in other words,...
Definition globals.h:408
LIST_ENTRY g_EventTrace
Holds a list of events in kernel and the state of events and the commands to show the state of each c...
Definition globals.h:400
BOOLEAN g_EventTraceInitialized
it shows whether the debugger started using events or not or in other words, is g_EventTrace initiali...
Definition globals.h:390
BOOLEAN InterpretConditionsAndCodes(vector< string > *SplitCommand, vector< string > *SplitCommandCaseSensitive, BOOLEAN IsConditionBuffer, PUINT64 BufferAddress, PUINT32 BufferLength)
Interpret conditions (if an event has condition) and custom code.
Definition debugger.cpp:1246
ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
State of active debugging thread.
Definition globals.h:362
BOOLEAN InterpretScript(vector< string > *SplitCommand, vector< string > *SplitCommandCaseSensitive, PBOOLEAN ScriptSyntaxErrors, PUINT64 BufferAddress, PUINT32 BufferLength, PUINT32 Pointer, PUINT64 ScriptCodeBuffer)
Interpret script (if an event has script)
Definition debugger.cpp:763
LIST_ENTRY g_OutputSources
Holds a list of output sources created by output command.
Definition globals.h:417
UINT64 GetNewDebuggerEventTag()
Get the New Debugger Event Tag object and increase the global variable for tag.
Definition debugger.cpp:2280
@ EVENT_FORWARDING_CLOSED
Definition forwarding.h:55
@ EVENT_FORWARDING_STATE_NOT_OPENED
Definition forwarding.h:53
VOID ScriptEngineWrapperRemoveSymbolBuffer(PVOID SymbolBuffer)
wrapper for removing symbol buffer
Definition script-engine-wrapper.cpp:860
structures hold the detail of event forwarding
Definition forwarding.h:80
DEBUGGER_EVENT_FORWARDING_STATE State
Definition forwarding.h:82
CHAR Name[MAXIMUM_CHARACTERS_FOR_EVENT_FORWARDING_NAME]
Definition forwarding.h:89
UINT64 OutputUniqueTag
Definition forwarding.h:86
Each event can have multiple actions.
Definition Events.h:406
UINT32 CustomCodeBufferSize
Definition Events.h:412
UINT32 ScriptBufferSize
Definition Events.h:413
DEBUGGER_EVENT_ACTION_TYPE_ENUM ActionType
Definition Events.h:408
UINT32 ScriptBufferPointer
Definition Events.h:414
UINT32 PreAllocatedBuffer
Definition Events.h:410
BOOLEAN ImmediateMessagePassing
Definition Events.h:409
UINT64 EventTag
Definition Events.h:407
BOOLEAN EnableShortCircuiting
Definition Events.h:366
BOOLEAN IsEnabled
Definition Events.h:364
VMM_EVENT_TYPE_ENUM EventType
Definition Events.h:389
UINT32 CountOfActions
Definition Events.h:386
UINT64 OutputSourceTags[DebuggerOutputSourceMaximumRemoteSourceForSingleEvent]
Definition Events.h:377
BOOLEAN HasCustomOutput
Definition Events.h:372
VMM_CALLBACK_EVENT_CALLING_STAGE_TYPE EventStage
Definition Events.h:369
UINT32 ConditionBufferSize
Definition Events.h:395
UINT32 ProcessId
Definition Events.h:360
UINT32 CoreId
Definition Events.h:357
time_t CreationTime
Definition Events.h:355