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

!ioapic command More...

#include "pch.h"

Functions

VOID CommandIoapicHelp ()
 help of the !ioapic command
BOOLEAN HyperDbgGetIoApic (IO_APIC_ENTRY_PACKETS *IoApic)
 Request to get I/O APIC.
ULONG CommandIoapicShowRedir (PUCHAR Desc, BOOLEAN CommandReg, BOOLEAN DestSelf, ULONGLONG Lh, ULONGLONG Ll)
 Show redirections.
VOID CommandIoapicShowIoApicEntries (IO_APIC_ENTRY_PACKETS *IoApicPackets)
 Show I/O APIC.
VOID CommandIoapic (vector< CommandToken > CommandTokens, string Command)
 !ioapic command handler

Detailed Description

!ioapic command

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.11
Date
2024-11-18

Function Documentation

◆ CommandIoapic()

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

!ioapic command handler

Parameters
CommandTokens
Command
Returns
VOID
195{
196 IO_APIC_ENTRY_PACKETS * IoApicPackets = NULL;
197
198 if (CommandTokens.size() != 1)
199 {
200 ShowMessages("incorrect use of the '%s'\n\n",
201 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
202
204 return;
205 }
206
207 //
208 // Allocate buffer for I/O APIC
209 //
210 IoApicPackets = (IO_APIC_ENTRY_PACKETS *)malloc(sizeof(IO_APIC_ENTRY_PACKETS));
211
212 if (IoApicPackets == NULL)
213 {
214 ShowMessages("err, allocating buffer for receiving I/O APIC");
215 }
216
217 RtlZeroMemory(IoApicPackets, sizeof(IO_APIC_ENTRY_PACKETS));
218
219 //
220 // Get the I/O APIC buffer
221 //
222 if (HyperDbgGetIoApic(IoApicPackets) == TRUE)
223 {
224 //
225 // Show (dump) entries
226 //
227 CommandIoapicShowIoApicEntries(IoApicPackets);
228 }
229
230 //
231 // Deallocate the buffer
232 //
233 free(IoApicPackets);
234}
#define TRUE
Definition BasicTypes.h:114
struct _IO_APIC_ENTRY_PACKETS IO_APIC_ENTRY_PACKETS
The structure of I/O APIC result packet in HyperDbg.
std::string GetCaseSensitiveStringFromCommandToken(CommandToken TargetToken)
Get case sensitive string from command token.
Definition common.cpp:467
VOID CommandIoapicShowIoApicEntries(IO_APIC_ENTRY_PACKETS *IoApicPackets)
Show I/O APIC.
Definition ioapic.cpp:141
VOID CommandIoapicHelp()
help of the !ioapic command
Definition ioapic.cpp:20
BOOLEAN HyperDbgGetIoApic(IO_APIC_ENTRY_PACKETS *IoApic)
Request to get I/O APIC.
Definition ioapic.cpp:38
NULL()
Definition test-case-generator.py:530

◆ CommandIoapicHelp()

VOID CommandIoapicHelp ( )

help of the !ioapic command

Returns
VOID
21{
22 ShowMessages("!ioapic : shows the details of I/O APIC entries.\n\n");
23
24 ShowMessages("syntax : \t!ioapic\n");
25
26 ShowMessages("\n");
27 ShowMessages("\t\te.g : !ioapic\n");
28}

◆ CommandIoapicShowIoApicEntries()

VOID CommandIoapicShowIoApicEntries ( IO_APIC_ENTRY_PACKETS * IoApicPackets)

Show I/O APIC.

Parameters
IoApicPackets
Returns
VOID
142{
143 UINT32 Index = 0;
144 UINT32 Max;
145 UCHAR Desc[40];
146 UINT64 ll, lh;
147
148 UINT64 ApicBasePa = IoApicPackets->ApicBasePa;
149
150 ll = IoApicPackets->IoLl;
151
152 Max = (ll >> 16) & 0xff;
153
154 ShowMessages("IoApic @ %08x ID:%x (%x) Arb:%x\t I/O APIC VA: %s\n",
155 ApicBasePa,
156 IoApicPackets->IoIdReg >> 24,
157 ll & 0xFF,
158 IoApicPackets->IoArbIdReg,
159 SeparateTo64BitValue(IoApicPackets->ApicBaseVa).c_str());
160
161 //
162 // Dump inti table
163 //
164 Max *= 2;
165
166 for (Index = 0; Index <= Max; Index += 2)
167 {
169 {
170 //
171 // The buffer is now invalid
172 //
173 ShowMessages("err, there are additional entries in the I/O APIC that are not fully displayed in the results");
174 return;
175 }
176
177 ll = IoApicPackets->LlLhData[Index];
178 lh = IoApicPackets->LlLhData[Index + 1];
179
180 sprintf((CHAR *)Desc, "Inti%02X.", Index / 2);
181 CommandIoapicShowRedir(Desc, FALSE, FALSE, lh, ll);
182 }
183}
unsigned char UCHAR
Definition BasicTypes.h:34
#define FALSE
Definition BasicTypes.h:113
unsigned int UINT32
Definition BasicTypes.h:54
char CHAR
Definition BasicTypes.h:33
#define MAX_NUMBER_OF_IO_APIC_ENTRIES
Maximum number of I/O APIC entries.
Definition RequestStructures.h:1222
string SeparateTo64BitValue(UINT64 Value)
ULONG CommandIoapicShowRedir(PUCHAR Desc, BOOLEAN CommandReg, BOOLEAN DestSelf, ULONGLONG Lh, ULONGLONG Ll)
Show redirections.
Definition ioapic.cpp:60
UINT32 IoIdReg
Definition RequestStructures.h:1232
UINT64 ApicBaseVa
Definition RequestStructures.h:1231
UINT32 IoArbIdReg
Definition RequestStructures.h:1234
UINT64 LlLhData[MAX_NUMBER_OF_IO_APIC_ENTRIES]
Definition RequestStructures.h:1235
UINT32 IoLl
Definition RequestStructures.h:1233
UINT64 ApicBasePa
Definition RequestStructures.h:1230

◆ CommandIoapicShowRedir()

ULONG CommandIoapicShowRedir ( PUCHAR Desc,
BOOLEAN CommandReg,
BOOLEAN DestSelf,
ULONGLONG Lh,
ULONGLONG Ll )

Show redirections.

Parameters
Desc
CommandReg
DestSelf
Lh
Ll
Returns
ULONG
65{
66 static PUCHAR DelMode[] = {
67 (PUCHAR) "FixedDel",
68 (PUCHAR) "LowestDl",
69 (PUCHAR) "res010 ",
70 (PUCHAR) "remoterd",
71 (PUCHAR) "NMI ",
72 (PUCHAR) "RESET ",
73 (PUCHAR) "res110 ",
74 (PUCHAR) "ExtINTA "};
75
76 static PUCHAR DesShDesc[] = {(PUCHAR) "",
77 (PUCHAR) " Dest=Self",
78 (PUCHAR) " Dest=ALL",
79 (PUCHAR) " Dest=Othrs"};
80
81 ULONG Del, Dest, Delstat, Rirr, Trig, Masked, Destsh;
82
83 Del = (Ll >> 8) & 0x7;
84 Dest = (Ll >> 11) & 0x1;
85 Delstat = (Ll >> 12) & 0x1;
86 Rirr = (Ll >> 14) & 0x1;
87 Trig = (Ll >> 15) & 0x1;
88 Masked = (Ll >> 16) & 0x1;
89 Destsh = (Ll >> 18) & 0x3;
90
91 if (CommandReg)
92 {
93 //
94 // command reg's don't have a mask
95 //
96 Masked = 0;
97 }
98
99 ShowMessages("%s: %s Vec:%02X %s ",
100 Desc,
101 SeparateTo64BitValue(Ll).c_str(),
102 Ll & 0xff,
103 DelMode[Del]);
104
105 if (DestSelf)
106 {
107 ShowMessages("%s", DesShDesc[1]);
108 }
109 else if (CommandReg && Destsh)
110 {
111 ShowMessages("%s", DesShDesc[Destsh]);
112 }
113 else
114 {
115 if (Dest)
116 {
117 ShowMessages("Lg:%08x", Lh);
118 }
119 else
120 {
121 ShowMessages("PhysDest:%02X", (Lh >> 56) & 0xFF);
122 }
123 }
124
125 ShowMessages("%s %s %s %s\n",
126 Delstat ? "-Pend" : " ",
127 Trig ? "level" : "edge ",
128 Rirr ? "rirr" : " ",
129 Masked ? "masked" : " ");
130
131 return 0;
132}
unsigned long ULONG
Definition BasicTypes.h:31

◆ HyperDbgGetIoApic()

BOOLEAN HyperDbgGetIoApic ( IO_APIC_ENTRY_PACKETS * IoApic)

Request to get I/O APIC.

Parameters
IolApic
Returns
BOOLEAN
39{
40 BOOLEAN IsUsingX2APIC; // not used since I/O APIC is accessed through memory (not MSR)
41
43 IoApic,
45 &IsUsingX2APIC);
46}
BOOLEAN CommandApicSendRequest(DEBUGGER_APIC_REQUEST_TYPE ApicType, PVOID ApicBuffer, UINT32 ExpectedRequestSize, PBOOLEAN IsUsingX2APIC)
Send APIC requests.
Definition apic.cpp:47
UCHAR BOOLEAN
Definition BasicTypes.h:35
@ DEBUGGER_APIC_REQUEST_TYPE_READ_IO_APIC
Definition RequestStructures.h:1088