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

!exception command More...

#include "pch.h"

Functions

VOID CommandExceptionHelp ()
 help of the !exception command
VOID CommandException (vector< CommandToken > CommandTokens, string Command)
 !exception command handler

Detailed Description

!exception command

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

Function Documentation

◆ CommandException()

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

!exception command handler

Parameters
CommandTokens
Command
Returns
VOID
52{
54 PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger = NULL;
55 PDEBUGGER_GENERAL_ACTION ActionCustomCode = NULL;
56 PDEBUGGER_GENERAL_ACTION ActionScript = NULL;
57 UINT32 EventLength;
58 UINT32 ActionBreakToDebuggerLength = 0;
59 UINT32 ActionCustomCodeLength = 0;
60 UINT32 ActionScriptLength = 0;
62 BOOLEAN GetEntry = FALSE;
63 DEBUGGER_EVENT_PARSING_ERROR_CAUSE EventParsingErrorCause;
64
65 //
66 // Interpret and fill the general event and action fields
67 //
68 //
70 &CommandTokens,
72 &Event,
73 &EventLength,
74 &ActionBreakToDebugger,
75 &ActionBreakToDebuggerLength,
76 &ActionCustomCode,
77 &ActionCustomCodeLength,
78 &ActionScript,
79 &ActionScriptLength,
80 &EventParsingErrorCause))
81 {
82 return;
83 }
84
85 //
86 // Interpret command specific details (if any)
87 //
88 for (auto Section : CommandTokens)
89 {
90 if (CompareLowerCaseStrings(Section, "!exception"))
91 {
92 continue;
93 }
94 else if (!GetEntry)
95 {
96 //
97 // It's probably an index
98 //
99 if (!ConvertTokenToUInt64(Section, &SpecialTarget))
100 {
101 //
102 // Unknown parameter
103 //
104 ShowMessages("unknown parameter '%s'\n\n",
107
108 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
109 return;
110 }
111 else
112 {
113 //
114 // Check if entry is valid or not (start from zero)
115 //
116 if (SpecialTarget >= 31)
117 {
118 //
119 // Entry is invalid (this command is designed for just first 32
120 // entries)
121 //
122 ShowMessages("the entry should be between 0x0 to 0x1f or first 32 "
123 "entries'\n\n");
125
126 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
127 return;
128 }
129 GetEntry = TRUE;
130 }
131 }
132 else
133 {
134 //
135 // Unknown parameter
136 //
137 ShowMessages("unknown parameter '%s'\n\n",
140
141 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
142 return;
143 }
144 }
145
146 //
147 // Set the target exception (if not specific then it means all exceptions)
148 //
149 Event->Options.OptionalParam1 = SpecialTarget;
150
151 //
152 // Send the ioctl to the kernel for event registration
153 //
154 if (!SendEventToKernel(Event, EventLength))
155 {
156 //
157 // There was an error, probably the handle was not initialized
158 // we have to free the Action before exit, it is because, we
159 // already freed the Event and string buffers
160 //
161
162 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
163 return;
164 }
165
166 //
167 // Add the event to the kernel
168 //
169 if (!RegisterActionToEvent(Event,
170 ActionBreakToDebugger,
171 ActionBreakToDebuggerLength,
172 ActionCustomCode,
173 ActionCustomCodeLength,
174 ActionScript,
175 ActionScriptLength))
176 {
177 //
178 // There was an error
179 //
180
181 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
182 return;
183 }
184}
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
#define DEBUGGER_EVENT_EXCEPTIONS_ALL_FIRST_32_ENTRIES
Apply to all first 32 exceptions.
Definition Constants.h:757
@ EXCEPTION_OCCURRED
Definition Events.h:140
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 CommandExceptionHelp()
help of the !exception command
Definition exception.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

◆ CommandExceptionHelp()

VOID CommandExceptionHelp ( )

help of the !exception command

Returns
VOID
21{
22 ShowMessages("!exception : monitors the first 32 entry of IDT (starting from "
23 "zero).\n\n");
24
25 ShowMessages(
26 "syntax : \t!exception [IdtIndex (hex)] [pid ProcessId (hex)] "
27 "[core CoreId (hex)] [imm IsImmediate (yesno)] [sc EnableShortCircuiting (onoff)] "
28 "[stage CallingStage (prepostall)] [buffer PreAllocatedBuffer (hex)] [script { Script (string) }] "
29 "[asm condition { Condition (assembly/hex) }] [asm code { Code (assembly/hex) }] [output {OutputName (string)}]\n");
30
31 ShowMessages("\nnote: monitoring page-faults (entry 0xe) is implemented differently (for more information, check the documentation).\n");
32
33 ShowMessages("\n");
34 ShowMessages("\t\te.g : !exception\n");
35 ShowMessages("\t\te.g : !exception 0xe\n");
36 ShowMessages("\t\te.g : !exception pid 400\n");
37 ShowMessages("\t\te.g : !exception core 2 pid 400\n");
38 ShowMessages("\t\te.g : !exception 0xe stage post script { printf(\"page-fault occurred at: %%llx\\n\", @cr2); }\n");
39 ShowMessages("\t\te.g : !exception asm code { nop; nop; nop }\n");
40}