2020-06-11 15:24:59 -07:00
|
|
|
/**
|
|
|
|
|
* @file interrupt.cpp
|
2022-01-18 22:38:56 +03:30
|
|
|
* @author Sina Karvandi (sina@hyperdbg.org)
|
2020-06-11 15:24:59 -07:00
|
|
|
* @brief !interrupt command
|
|
|
|
|
* @details
|
|
|
|
|
* @version 0.1
|
|
|
|
|
* @date 2020-06-11
|
|
|
|
|
*
|
|
|
|
|
* @copyright This project is released under the GNU Public License v3.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2022-05-04 16:38:21 -07:00
|
|
|
#include "pch.h"
|
2020-06-11 15:24:59 -07:00
|
|
|
|
2020-08-28 04:03:12 -07:00
|
|
|
/**
|
2023-07-13 16:05:42 +09:00
|
|
|
* @brief help of the !interrupt command
|
2020-10-22 06:27:28 -07:00
|
|
|
*
|
|
|
|
|
* @return VOID
|
2020-08-28 04:03:12 -07:00
|
|
|
*/
|
2021-03-22 18:19:39 +04:30
|
|
|
VOID
|
|
|
|
|
CommandInterruptHelp()
|
|
|
|
|
{
|
2022-04-10 22:24:56 +04:30
|
|
|
ShowMessages("!interrupt : monitors the external interrupt (IDT >= 32).\n\n");
|
2022-04-17 23:05:24 +04:30
|
|
|
|
2022-02-11 02:53:28 +03:30
|
|
|
ShowMessages("syntax : \t[IdtIndex (hex)] [pid ProcessId (hex)] "
|
2023-10-11 15:03:51 +09:00
|
|
|
"[core CoreId (hex)] [imm IsImmediate (yesno)] [sc EnableShortCircuiting (onoff)] "
|
|
|
|
|
"[stage CallingStage (prepostall)] [buffer PreAllocatedBuffer (hex)] [script { Script (string) }] "
|
2024-07-19 17:03:43 +09:00
|
|
|
"[asm condition { Condition (assembly/hex) }] [asm code { Code (assembly/hex) }] [output {OutputName (string)}]\n");
|
2022-04-17 23:05:24 +04:30
|
|
|
|
|
|
|
|
ShowMessages("\nnote : The index should be greater than 0x20 (32) and less "
|
2021-03-22 18:19:39 +04:30
|
|
|
"than 0xFF (255) - starting from zero.\n");
|
2022-04-17 23:05:24 +04:30
|
|
|
|
|
|
|
|
ShowMessages("\n");
|
2021-03-22 18:19:39 +04:30
|
|
|
ShowMessages("\t\te.g : !interrupt 0x2f\n");
|
|
|
|
|
ShowMessages("\t\te.g : !interrupt 0x2f pid 400\n");
|
|
|
|
|
ShowMessages("\t\te.g : !interrupt 0x2f core 2 pid 400\n");
|
2024-07-20 22:05:39 +09:00
|
|
|
ShowMessages("\t\te.g : !interrupt 0xd1 script { printf(\"clock interrupt received at the core: %%x\\n\", $core); }\n");
|
|
|
|
|
ShowMessages("\t\te.g : !interrupt 0x2f asm code { nop; nop; nop }\n");
|
2020-06-11 15:24:59 -07:00
|
|
|
}
|
|
|
|
|
|
2020-08-28 04:03:12 -07:00
|
|
|
/**
|
|
|
|
|
* @brief !interrupt command handler
|
2020-10-22 06:27:28 -07:00
|
|
|
*
|
2024-07-30 18:44:15 +09:00
|
|
|
* @param CommandTokens
|
2024-07-31 14:08:14 +09:00
|
|
|
* @param Command
|
2024-07-30 18:44:15 +09:00
|
|
|
*
|
2020-10-22 06:27:28 -07:00
|
|
|
* @return VOID
|
2020-08-28 04:03:12 -07:00
|
|
|
*/
|
2021-03-22 18:19:39 +04:30
|
|
|
VOID
|
2024-07-31 14:08:14 +09:00
|
|
|
CommandInterrupt(vector<CommandToken> CommandTokens, string Command)
|
2021-03-22 18:19:39 +04:30
|
|
|
{
|
2021-08-21 20:48:17 +04:30
|
|
|
PDEBUGGER_GENERAL_EVENT_DETAIL Event = NULL;
|
|
|
|
|
PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger = NULL;
|
|
|
|
|
PDEBUGGER_GENERAL_ACTION ActionCustomCode = NULL;
|
|
|
|
|
PDEBUGGER_GENERAL_ACTION ActionScript = NULL;
|
|
|
|
|
UINT32 EventLength;
|
|
|
|
|
UINT32 ActionBreakToDebuggerLength = 0;
|
|
|
|
|
UINT32 ActionCustomCodeLength = 0;
|
|
|
|
|
UINT32 ActionScriptLength = 0;
|
|
|
|
|
UINT64 SpecialTarget = 0;
|
|
|
|
|
BOOLEAN GetEntry = FALSE;
|
|
|
|
|
DEBUGGER_EVENT_PARSING_ERROR_CAUSE EventParsingErrorCause;
|
2020-06-11 15:24:59 -07:00
|
|
|
|
2021-03-22 18:19:39 +04:30
|
|
|
//
|
|
|
|
|
// Interpret and fill the general event and action fields
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
if (!InterpretGeneralEventAndActionsFields(
|
2024-07-30 18:44:15 +09:00
|
|
|
&CommandTokens,
|
2021-03-22 18:19:39 +04:30
|
|
|
EXTERNAL_INTERRUPT_OCCURRED,
|
|
|
|
|
&Event,
|
|
|
|
|
&EventLength,
|
|
|
|
|
&ActionBreakToDebugger,
|
|
|
|
|
&ActionBreakToDebuggerLength,
|
|
|
|
|
&ActionCustomCode,
|
|
|
|
|
&ActionCustomCodeLength,
|
|
|
|
|
&ActionScript,
|
2021-08-21 20:48:17 +04:30
|
|
|
&ActionScriptLength,
|
|
|
|
|
&EventParsingErrorCause))
|
2021-03-22 18:19:39 +04:30
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-06-11 15:24:59 -07:00
|
|
|
|
2021-03-22 18:19:39 +04:30
|
|
|
//
|
|
|
|
|
// Interpret command specific details (if any)
|
|
|
|
|
//
|
|
|
|
|
//
|
2024-07-30 18:44:15 +09:00
|
|
|
for (auto Section : CommandTokens)
|
2021-03-22 18:19:39 +04:30
|
|
|
{
|
2024-07-30 18:44:15 +09:00
|
|
|
if (CompareLowerCaseStrings(Section, "!interrupt"))
|
2021-03-22 18:19:39 +04:30
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else if (!GetEntry)
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// It's probably an index
|
|
|
|
|
//
|
2024-07-30 18:44:15 +09:00
|
|
|
if (!ConvertTokenToUInt64(Section, &SpecialTarget))
|
2021-03-22 18:19:39 +04:30
|
|
|
{
|
|
|
|
|
//
|
2024-03-17 19:00:14 +09:00
|
|
|
// Unknown parameter
|
2021-03-22 18:19:39 +04:30
|
|
|
//
|
2024-07-30 18:44:15 +09:00
|
|
|
ShowMessages("unknown parameter '%s'\n\n",
|
|
|
|
|
GetCaseSensitiveStringFromCommandToken(Section).c_str());
|
2021-03-22 18:19:39 +04:30
|
|
|
CommandInterruptHelp();
|
2022-05-09 01:34:07 +04:30
|
|
|
|
|
|
|
|
FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
|
2021-03-22 18:19:39 +04:30
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// Check if entry is valid or not
|
|
|
|
|
//
|
|
|
|
|
if (!(SpecialTarget >= 32 && SpecialTarget <= 0xff))
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// Entry is invalid (this command is designed for just entries
|
|
|
|
|
// between 32 to 255)
|
|
|
|
|
//
|
2021-04-11 22:21:22 +04:30
|
|
|
ShowMessages("the entry should be between 0x20 to 0xFF or the "
|
|
|
|
|
"entries between 32 to 255\n\n");
|
2021-03-22 18:19:39 +04:30
|
|
|
CommandInterruptHelp();
|
2022-05-09 01:34:07 +04:30
|
|
|
|
|
|
|
|
FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
|
2021-03-22 18:19:39 +04:30
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
GetEntry = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//
|
2024-03-17 19:00:14 +09:00
|
|
|
// Unknown parameter
|
2021-03-22 18:19:39 +04:30
|
|
|
//
|
2024-07-30 18:44:15 +09:00
|
|
|
ShowMessages("unknown parameter '%s'\n\n",
|
|
|
|
|
GetCaseSensitiveStringFromCommandToken(Section).c_str());
|
2021-03-22 18:19:39 +04:30
|
|
|
CommandInterruptHelp();
|
2022-05-09 01:34:07 +04:30
|
|
|
|
|
|
|
|
FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
|
2021-03-22 18:19:39 +04:30
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-11 15:24:59 -07:00
|
|
|
|
2021-03-22 18:19:39 +04:30
|
|
|
if (SpecialTarget == 0)
|
|
|
|
|
{
|
2020-06-11 15:24:59 -07:00
|
|
|
//
|
2021-03-22 18:19:39 +04:30
|
|
|
// The user didn't set the target interrupt, even though it's possible to
|
2024-03-17 01:01:22 +09:00
|
|
|
// get all interrupts but it makes the system not responsive so it's wrong
|
2021-03-22 18:19:39 +04:30
|
|
|
// to trigger event on all interrupts and we're not going to support it
|
2020-06-11 15:24:59 -07:00
|
|
|
//
|
2021-04-11 22:21:22 +04:30
|
|
|
ShowMessages("please specify an interrupt index to monitor, HyperDbg "
|
2021-03-22 18:19:39 +04:30
|
|
|
"doesn't support to trigger events on all interrupts because "
|
|
|
|
|
"it's not reasonable and make the system unresponsive\n");
|
2020-06-11 15:24:59 -07:00
|
|
|
CommandInterruptHelp();
|
2022-05-09 01:34:07 +04:30
|
|
|
|
|
|
|
|
FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
|
2020-06-11 15:24:59 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2020-10-22 06:27:28 -07:00
|
|
|
|
2020-06-11 15:24:59 -07:00
|
|
|
//
|
2021-03-22 18:19:39 +04:30
|
|
|
// Set the target interrupt
|
2020-06-11 15:24:59 -07:00
|
|
|
//
|
2023-10-14 21:28:08 +09:00
|
|
|
Event->Options.OptionalParam1 = SpecialTarget;
|
2020-08-28 04:03:12 -07:00
|
|
|
|
|
|
|
|
//
|
2022-05-06 19:21:56 +04:30
|
|
|
// Send the ioctl to the kernel for event registration
|
2020-08-28 04:03:12 -07:00
|
|
|
//
|
2021-03-22 18:19:39 +04:30
|
|
|
if (!SendEventToKernel(Event, EventLength))
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// There was an error, probably the handle was not initialized
|
|
|
|
|
// we have to free the Action before exit, it is because, we
|
|
|
|
|
// already freed the Event and string buffers
|
|
|
|
|
//
|
2022-05-08 22:13:44 +04:30
|
|
|
|
2022-05-09 01:34:07 +04:30
|
|
|
FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
|
2021-03-22 18:19:39 +04:30
|
|
|
return;
|
2020-10-22 06:27:28 -07:00
|
|
|
}
|
2020-06-11 15:24:59 -07:00
|
|
|
|
2020-08-28 04:03:12 -07:00
|
|
|
//
|
2021-03-22 18:19:39 +04:30
|
|
|
// Add the event to the kernel
|
2020-08-28 04:03:12 -07:00
|
|
|
//
|
2022-05-09 01:34:07 +04:30
|
|
|
if (!RegisterActionToEvent(Event,
|
|
|
|
|
ActionBreakToDebugger,
|
2022-03-13 01:33:21 +03:30
|
|
|
ActionBreakToDebuggerLength,
|
|
|
|
|
ActionCustomCode,
|
|
|
|
|
ActionCustomCodeLength,
|
|
|
|
|
ActionScript,
|
|
|
|
|
ActionScriptLength))
|
2021-03-22 18:19:39 +04:30
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// There was an error
|
|
|
|
|
//
|
2022-05-09 01:34:07 +04:30
|
|
|
|
|
|
|
|
FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
|
2021-03-22 18:19:39 +04:30
|
|
|
return;
|
|
|
|
|
}
|
2020-06-11 15:24:59 -07:00
|
|
|
}
|