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

!interrupt command More...

#include "pch.h"

Functions

VOID CommandInterruptHelp ()
 help of the !interrupt command
VOID CommandInterrupt (vector< CommandToken > CommandTokens, string Command)
 !interrupt command handler

Detailed Description

!interrupt command

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

Function Documentation

◆ CommandInterrupt()

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

!interrupt command handler

Parameters
CommandTokens
Command
Returns
VOID
50{
52 PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger = NULL;
53 PDEBUGGER_GENERAL_ACTION ActionCustomCode = NULL;
54 PDEBUGGER_GENERAL_ACTION ActionScript = NULL;
55 UINT32 EventLength;
56 UINT32 ActionBreakToDebuggerLength = 0;
57 UINT32 ActionCustomCodeLength = 0;
58 UINT32 ActionScriptLength = 0;
59 UINT64 SpecialTarget = 0;
60 BOOLEAN GetEntry = FALSE;
61 DEBUGGER_EVENT_PARSING_ERROR_CAUSE EventParsingErrorCause;
62
63 //
64 // Interpret and fill the general event and action fields
65 //
66 //
68 &CommandTokens,
70 &Event,
71 &EventLength,
72 &ActionBreakToDebugger,
73 &ActionBreakToDebuggerLength,
74 &ActionCustomCode,
75 &ActionCustomCodeLength,
76 &ActionScript,
77 &ActionScriptLength,
78 &EventParsingErrorCause))
79 {
80 return;
81 }
82
83 //
84 // Interpret command specific details (if any)
85 //
86 //
87 for (auto Section : CommandTokens)
88 {
89 if (CompareLowerCaseStrings(Section, "!interrupt"))
90 {
91 continue;
92 }
93 else if (!GetEntry)
94 {
95 //
96 // It's probably an index
97 //
98 if (!ConvertTokenToUInt64(Section, &SpecialTarget))
99 {
100 //
101 // Unknown parameter
102 //
103 ShowMessages("unknown parameter '%s'\n\n",
106
107 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
108 return;
109 }
110 else
111 {
112 //
113 // Check if entry is valid or not
114 //
115 if (!(SpecialTarget >= 32 && SpecialTarget <= 0xff))
116 {
117 //
118 // Entry is invalid (this command is designed for just entries
119 // between 32 to 255)
120 //
121 ShowMessages("the entry should be between 0x20 to 0xFF or the "
122 "entries between 32 to 255\n\n");
124
125 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
126 return;
127 }
128 GetEntry = TRUE;
129 }
130 }
131 else
132 {
133 //
134 // Unknown parameter
135 //
136 ShowMessages("unknown parameter '%s'\n\n",
139
140 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
141 return;
142 }
143 }
144
145 if (SpecialTarget == 0)
146 {
147 //
148 // The user didn't set the target interrupt, even though it's possible to
149 // get all interrupts but it makes the system not responsive so it's wrong
150 // to trigger event on all interrupts and we're not going to support it
151 //
152 ShowMessages("please specify an interrupt index to monitor, HyperDbg "
153 "doesn't support to trigger events on all interrupts because "
154 "it's not reasonable and make the system unresponsive\n");
156
157 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
158 return;
159 }
160
161 //
162 // Set the target interrupt
163 //
164 Event->Options.OptionalParam1 = SpecialTarget;
165
166 //
167 // Send the ioctl to the kernel for event registration
168 //
169 if (!SendEventToKernel(Event, EventLength))
170 {
171 //
172 // There was an error, probably the handle was not initialized
173 // we have to free the Action before exit, it is because, we
174 // already freed the Event and string buffers
175 //
176
177 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
178 return;
179 }
180
181 //
182 // Add the event to the kernel
183 //
184 if (!RegisterActionToEvent(Event,
185 ActionBreakToDebugger,
186 ActionBreakToDebuggerLength,
187 ActionCustomCode,
188 ActionCustomCodeLength,
189 ActionScript,
190 ActionScriptLength))
191 {
192 //
193 // There was an error
194 //
195
196 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
197 return;
198 }
199}
UCHAR BOOLEAN
Definition BasicTypes.h:35
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
unsigned int UINT32
Definition BasicTypes.h:54
@ EXTERNAL_INTERRUPT_OCCURRED
Definition Events.h:141
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
BOOLEAN CompareLowerCaseStrings(CommandToken TargetToken, const CHAR *StringToCompare)
Compare lower case strings.
Definition common.cpp:503
BOOLEAN ConvertTokenToUInt64(CommandToken TargetToken, PUINT64 Result)
add ` between 64 bit values and convert them to string
Definition common.cpp:447
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
VOID CommandInterruptHelp()
help of the !interrupt command
Definition interrupt.cpp:20
enum _DEBUGGER_EVENT_PARSING_ERROR_CAUSE DEBUGGER_EVENT_PARSING_ERROR_CAUSE
Reason for error in parsing commands.
NULL()
Definition test-case-generator.py:530
UINT64 OptionalParam1
Definition Events.h:277
DEBUGGER_EVENT_OPTIONS Options
Definition Events.h:396

◆ CommandInterruptHelp()

VOID CommandInterruptHelp ( )

help of the !interrupt command

Returns
VOID
21{
22 ShowMessages("!interrupt : monitors the external interrupt (IDT >= 32).\n\n");
23
24 ShowMessages("syntax : \t[IdtIndex (hex)] [pid ProcessId (hex)] "
25 "[core CoreId (hex)] [imm IsImmediate (yesno)] [sc EnableShortCircuiting (onoff)] "
26 "[stage CallingStage (prepostall)] [buffer PreAllocatedBuffer (hex)] [script { Script (string) }] "
27 "[asm condition { Condition (assembly/hex) }] [asm code { Code (assembly/hex) }] [output {OutputName (string)}]\n");
28
29 ShowMessages("\nnote : The index should be greater than 0x20 (32) and less "
30 "than 0xFF (255) - starting from zero.\n");
31
32 ShowMessages("\n");
33 ShowMessages("\t\te.g : !interrupt 0x2f\n");
34 ShowMessages("\t\te.g : !interrupt 0x2f pid 400\n");
35 ShowMessages("\t\te.g : !interrupt 0x2f core 2 pid 400\n");
36 ShowMessages("\t\te.g : !interrupt 0xd1 script { printf(\"clock interrupt received at the core: %%x\\n\", $core); }\n");
37 ShowMessages("\t\te.g : !interrupt 0x2f asm code { nop; nop; nop }\n");
38}