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

!ioin command More...

#include "pch.h"

Functions

VOID CommandIoinHelp ()
 help of the !ioin command
 
VOID CommandIoin (vector< string > SplitCommand, string Command)
 !ioin command handler
 

Detailed Description

!ioin command

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

Function Documentation

◆ CommandIoin()

VOID CommandIoin ( vector< string > SplitCommand,
string Command )

!ioin command handler

Parameters
SplitCommand
Command
Returns
VOID
48{
50 PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger = NULL;
51 PDEBUGGER_GENERAL_ACTION ActionCustomCode = NULL;
52 PDEBUGGER_GENERAL_ACTION ActionScript = NULL;
53 UINT32 EventLength;
54 UINT32 ActionBreakToDebuggerLength = 0;
55 UINT32 ActionCustomCodeLength = 0;
56 UINT32 ActionScriptLength = 0;
57 UINT64 SpecialTarget = DEBUGGER_EVENT_ALL_IO_PORTS;
58 BOOLEAN GetPort = FALSE;
59 vector<string> SplitCommandCaseSensitive {Split(Command, ' ')};
60 DEBUGGER_EVENT_PARSING_ERROR_CAUSE EventParsingErrorCause;
61
62 //
63 // Interpret and fill the general event and action fields
64 //
66 &SplitCommand,
67 &SplitCommandCaseSensitive,
69 &Event,
70 &EventLength,
71 &ActionBreakToDebugger,
72 &ActionBreakToDebuggerLength,
73 &ActionCustomCode,
74 &ActionCustomCodeLength,
75 &ActionScript,
76 &ActionScriptLength,
77 &EventParsingErrorCause))
78 {
79 return;
80 }
81
82 //
83 // Interpret command specific details (if any)
84 //
85 for (auto Section : SplitCommand)
86 {
87 if (!Section.compare("!ioin"))
88 {
89 continue;
90 }
91 else if (!GetPort)
92 {
93 //
94 // It's probably an I/O port
95 //
96 if (!ConvertStringToUInt64(Section, &SpecialTarget))
97 {
98 //
99 // Unknown parameter
100 //
101 ShowMessages("unknown parameter '%s'\n\n", Section.c_str());
103
104 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
105 return;
106 }
107 else
108 {
109 GetPort = TRUE;
110 }
111 }
112 else
113 {
114 //
115 // Unknown parameter
116 //
117 ShowMessages("unknown parameter '%s'\n\n", Section.c_str());
119
120 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
121 return;
122 }
123 }
124
125 //
126 // Set the target I/O port
127 //
128 Event->Options.OptionalParam1 = SpecialTarget;
129
130 //
131 // Send the ioctl to the kernel for event registration
132 //
133 if (!SendEventToKernel(Event, EventLength))
134 {
135 //
136 // There was an error, probably the handle was not initialized
137 // we have to free the Action before exit, it is because, we
138 // already freed the Event and string buffers
139 //
140
141 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
142 return;
143 }
144
145 //
146 // Add the event to the kernel
147 //
148 if (!RegisterActionToEvent(Event,
149 ActionBreakToDebugger,
150 ActionBreakToDebuggerLength,
151 ActionCustomCode,
152 ActionCustomCodeLength,
153 ActionScript,
154 ActionScriptLength))
155 {
156 //
157 // There was an error
158 //
159
160 FreeEventsAndActionsMemory(Event, ActionBreakToDebugger, ActionCustomCode, ActionScript);
161 return;
162 }
163}
UCHAR BOOLEAN
Definition BasicTypes.h:39
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
unsigned __int64 UINT64
Definition BasicTypes.h:21
unsigned int UINT32
Definition BasicTypes.h:48
#define DEBUGGER_EVENT_ALL_IO_PORTS
Apply to all I/O ports.
Definition Constants.h:641
const vector< string > Split(const string &s, const char &c)
general split command
Definition common.cpp:117
BOOLEAN ConvertStringToUInt64(string TextToConvert, PUINT64 Result)
check and convert string to a 64 bit unsigned integer and also check for special notations like 0x,...
Definition common.cpp:240
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:2292
BOOLEAN InterpretGeneralEventAndActionsFields(vector< string > *SplitCommand, vector< string > *SplitCommandCaseSensitive, 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:2342
BOOLEAN SendEventToKernel(PDEBUGGER_GENERAL_EVENT_DETAIL Event, UINT32 EventBufferLength)
Register the event to the kernel.
Definition debugger.cpp:1969
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:2086
@ IN_INSTRUCTION_EXECUTION
Definition Events.h:134
VOID CommandIoinHelp()
help of the !ioin command
Definition ioin.cpp:20
enum _DEBUGGER_EVENT_PARSING_ERROR_CAUSE DEBUGGER_EVENT_PARSING_ERROR_CAUSE
Reason for error in parsing commands.
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
NULL()
Definition test-case-generator.py:530
UINT64 OptionalParam1
Definition Events.h:272
Each event can have multiple actions.
Definition Events.h:406
Each command is like the following struct, it also used for tracing works in user mode and sending it...
Definition Events.h:350
DEBUGGER_EVENT_OPTIONS Options
Definition Events.h:391

◆ CommandIoinHelp()

VOID CommandIoinHelp ( )

help of the !ioin command

Returns
VOID
21{
22 ShowMessages("!ioin : detects the execution of IN (I/O instructions) "
23 "instructions.\n\n");
24
25 ShowMessages("syntax : \t!ioin [Port (hex)] [pid ProcessId (hex)] [core CoreId (hex)] "
26 "[imm IsImmediate (yesno)] [sc EnableShortCircuiting (onoff)] [stage CallingStage (prepostall)] "
27 "[buffer PreAllocatedBuffer (hex)] [script { Script (string) }] [asm condition { Condition (assembly/hex) }] "
28 "[asm code { Code (assembly/hex) }] [output {OutputName (string)}]\n");
29
30 ShowMessages("\n");
31 ShowMessages("\t\te.g : !ioin\n");
32 ShowMessages("\t\te.g : !ioin 0x64\n");
33 ShowMessages("\t\te.g : !ioin pid 400\n");
34 ShowMessages("\t\te.g : !ioin core 2 pid 400\n");
35 ShowMessages("\t\te.g : !ioin script { printf(\"IN instruction is executed at port: %%llx\\n\", $context); }\n");
36 ShowMessages("\t\te.g : !ioin asm code { nop; nop; nop }\n");
37}