HyperDbg Debugger
Loading...
Searching...
No Matches
tsc.cpp File Reference

!tsc commands More...

#include "pch.h"

Functions

VOID CommandTscHelp ()
 help of the !tsc command
VOID CommandTsc (vector< CommandToken > CommandTokens, string Command)
 handler of !tsc command

Detailed Description

!tsc commands

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2020-06-02

Function Documentation

◆ CommandTsc()

VOID CommandTsc ( vector< CommandToken > CommandTokens,
string Command )

handler of !tsc command

Parameters
CommandTokens
Command
Returns
VOID
47{
49 PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger = NULL;
50 PDEBUGGER_GENERAL_ACTION ActionCustomCode = NULL;
51 PDEBUGGER_GENERAL_ACTION ActionScript = NULL;
52 UINT32 EventLength;
53 UINT32 ActionBreakToDebuggerLength = 0;
54 UINT32 ActionCustomCodeLength = 0;
55 UINT32 ActionScriptLength = 0;
56 DEBUGGER_EVENT_PARSING_ERROR_CAUSE EventParsingErrorCause;
57
58 //
59 // Interpret and fill the general event and action fields
60 //
61 //
63 &CommandTokens,
65 &Event,
66 &EventLength,
67 &ActionBreakToDebugger,
68 &ActionBreakToDebuggerLength,
69 &ActionCustomCode,
70 &ActionCustomCodeLength,
71 &ActionScript,
72 &ActionScriptLength,
73 &EventParsingErrorCause))
74 {
75 return;
76 }
77
78 //
79 // Check for size
80 //
81 if (CommandTokens.size() > 1)
82 {
83 ShowMessages("incorrect use of the '%s'\n\n",
84 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
85
87
88 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
89 return;
90 }
91
92 //
93 // Send the ioctl to the kernel for event registration
94 //
95 if (!SendEventToKernel(Event, EventLength))
96 {
97 //
98 // There was an error, probably the handle was not initialized
99 // we have to free the Action before exit, it is because, we
100 // already freed the Event and string buffers
101 //
102
103 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
104 return;
105 }
106
107 //
108 // Add the event to the kernel
109 //
110 if (!RegisterActionToEvent(Event,
111 ActionBreakToDebugger,
112 ActionBreakToDebuggerLength,
113 ActionCustomCode,
114 ActionCustomCodeLength,
115 ActionScript,
116 ActionScriptLength))
117 {
118 //
119 // There was an error
120 //
121
122 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
123 return;
124 }
125}
unsigned int UINT32
Definition BasicTypes.h:54
@ TSC_INSTRUCTION_EXECUTION
Definition Events.h:151
struct _DEBUGGER_GENERAL_EVENT_DETAIL * PDEBUGGER_GENERAL_EVENT_DETAIL
struct _DEBUGGER_GENERAL_ACTION * PDEBUGGER_GENERAL_ACTION
std::string GetCaseSensitiveStringFromCommandToken(CommandToken TargetToken)
Get case sensitive string from command token.
Definition common.cpp:467
VOID FreeEventsAndActionsMemory(PDEBUGGER_GENERAL_EVENT_DETAIL Event, PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger, PDEBUGGER_GENERAL_ACTION ActionCustomCode, PDEBUGGER_GENERAL_ACTION ActionScript)
Deallocate buffers relating to events and actions.
Definition debugger.cpp:1688
BOOLEAN InterpretGeneralEventAndActionsFields(vector< CommandToken > *CommandTokens, VMM_EVENT_TYPE_ENUM EventType, PDEBUGGER_GENERAL_EVENT_DETAIL *EventDetailsToFill, PUINT32 EventBufferLength, PDEBUGGER_GENERAL_ACTION *ActionDetailsToFillBreakToDebugger, PUINT32 ActionBufferLengthBreakToDebugger, PDEBUGGER_GENERAL_ACTION *ActionDetailsToFillCustomCode, PUINT32 ActionBufferLengthCustomCode, PDEBUGGER_GENERAL_ACTION *ActionDetailsToFillScript, PUINT32 ActionBufferLengthScript, PDEBUGGER_EVENT_PARSING_ERROR_CAUSE ReasonForErrorInParsing)
Interpret general event fields.
Definition debugger.cpp:1736
BOOLEAN SendEventToKernel(PDEBUGGER_GENERAL_EVENT_DETAIL Event, UINT32 EventBufferLength)
Register the event to the kernel.
Definition debugger.cpp:1367
BOOLEAN RegisterActionToEvent(PDEBUGGER_GENERAL_EVENT_DETAIL Event, PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger, UINT32 ActionBreakToDebuggerLength, PDEBUGGER_GENERAL_ACTION ActionCustomCode, UINT32 ActionCustomCodeLength, PDEBUGGER_GENERAL_ACTION ActionScript, UINT32 ActionScriptLength)
Register the action to the event.
Definition debugger.cpp:1483
enum _DEBUGGER_EVENT_PARSING_ERROR_CAUSE DEBUGGER_EVENT_PARSING_ERROR_CAUSE
Reason for error in parsing commands.
NULL()
Definition test-case-generator.py:530
VOID CommandTscHelp()
help of the !tsc command
Definition tsc.cpp:20

◆ CommandTscHelp()

VOID CommandTscHelp ( )

help of the !tsc command

Returns
VOID
21{
22 ShowMessages("!tsc : monitors execution of rdtsc/rdtscp instructions.\n\n");
23
24 ShowMessages("syntax : \t!tsc [pid ProcessId (hex)] [core CoreId (hex)] [imm IsImmediate (yesno)] "
25 "[sc EnableShortCircuiting (onoff)] [stage CallingStage (prepostall)] [buffer PreAllocatedBuffer (hex)] "
26 "[script { Script (string) }] [asm condition { Condition (assembly/hex) }] [asm code { Code (assembly/hex) }] "
27 "[output {OutputName (string)}]\n");
28
29 ShowMessages("\n");
30 ShowMessages("\t\te.g : !tsc\n");
31 ShowMessages("\t\te.g : !tsc pid 400\n");
32 ShowMessages("\t\te.g : !tsc core 2 pid 400\n");
33 ShowMessages("\t\te.g : !tsc script { printf(\"RDTSC/P instruction called at: %%llx\\n\", @rip); }\n");
34 ShowMessages("\t\te.g : !tsc asm code { nop; nop; nop }\n");
35}