Skip to content

Commit f551c3d

Browse files
author
Andrey Bazhan
committed
Merge branch 'dev'
2 parents 207ca90 + 6ab27cb commit f551c3d

9 files changed

Lines changed: 325 additions & 140 deletions

File tree

SwishDbgExt/EngExpCppEx.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ IsValid(
4141
ULONG64 Pointer
4242
);
4343

44-
LPSTR
44+
PSTR
4545
GetNameByOffset(
46-
ULONG64 Offset,
47-
LPSTR Name,
48-
ULONG NameSize
49-
);
46+
_In_ ULONG64 Offset,
47+
_Out_writes_(Length) PSTR Buffer,
48+
_In_ ULONG Length
49+
);
5050

5151
BOOLEAN
5252
IsPointerHooked(

SwishDbgExt/EngExtCppEx.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,12 @@ Return Value:
425425
// return SIGN_EXTEND(Pointer);
426426
}
427427

428-
LPSTR
428+
PSTR
429429
GetNameByOffset(
430430
_In_ ULONG64 Offset,
431-
_Out_writes_(NameSize) LPSTR Name,
432-
_In_ ULONG NameSize
433-
)
431+
_Out_writes_(Length) PSTR Buffer,
432+
_In_ ULONG Length
433+
)
434434
/*++
435435
436436
Routine Description:
@@ -449,20 +449,26 @@ Return Value:
449449
450450
--*/
451451
{
452-
HRESULT hResult;
453-
RtlZeroMemory(Name, NameSize);
452+
CHAR DisplacementString[MAX_PATH];
453+
ULONG64 Displacement;
454+
ULONG BytesRead;
454455

455-
if (Offset)
456-
{
457-
// TODO: GetOffsetSymbol()
458-
hResult = g_Ext->m_Symbols->GetNameByOffset(Offset, (PSTR)Name, NameSize, NULL, NULL);
459-
if (hResult != S_OK)
460-
{
461-
strcpy_s((LPSTR)Name, NameSize, "*UNKNOWN*");
456+
Buffer[0] = '\0';
457+
458+
if (Offset) {
459+
460+
if (g_Ext->m_Symbols->GetNameByOffset(Offset, (PSTR)Buffer, Length, &BytesRead, &Displacement) == S_OK) {
461+
462+
if (Displacement != 0) {
463+
464+
StringCchPrintf(DisplacementString, _countof(DisplacementString), "+0x%x", Displacement);
465+
466+
StringCchCat(Buffer, Length - _tcslen(Buffer), DisplacementString);
467+
}
462468
}
463469
}
464470

465-
return Name;
471+
return Buffer;
466472
}
467473

468474
BOOLEAN

SwishDbgExt/Objects.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Return Value:
7878

7979
if (!ObTypeInit)
8080
{
81-
ObjTypeTable = ExtRemoteTyped("(nt!_OBJECT_TYPE **)@$extin", GetExpression("nt!ObTypeIndexTable"));
81+
ObjTypeTable = ExtRemoteTyped("(nt!_OBJECT_TYPE **)@$extin", ObTypeIndexTableAddress);
8282
ObTypeInit = TRUE;
8383
}
8484

@@ -95,7 +95,7 @@ Return Value:
9595

9696
HandleObj->ObjectTypeIndex = ObjHeader.Field("TypeIndex").GetUchar();
9797

98-
if (g_Ext->m_Data->ReadVirtual(GetExpression("nt!ObHeaderCookie"), &HeaderCookie, sizeof(HeaderCookie), NULL) == S_OK) {
98+
if (g_Ext->m_Data->ReadVirtual(ObHeaderCookieAddress, &HeaderCookie, sizeof(HeaderCookie), NULL) == S_OK) {
9999

100100
HandleObj->ObjectTypeIndex = (((ObjHeaderAddr >> 8) & 0xff) ^ HandleObj->ObjectTypeIndex) ^ HeaderCookie;
101101
}
@@ -230,7 +230,7 @@ Return Value:
230230

231231
if (!ObjectDir)
232232
{
233-
ReadPointer(GetExpression("nt!ObpRootDirectoryObject"), &ObjectDir);
233+
ReadPointer(ObpRootDirectoryObjectAddress, &ObjectDir);
234234
}
235235

236236
Directory = ExtRemoteTyped("(nt!_OBJECT_DIRECTORY *)@$extin", ObjectDir);

SwishDbgExt/Process.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,26 @@ Return Value:
177177
178178
--*/
179179
{
180-
RtlZeroMemory(&mm_CcDllObject, sizeof(mm_CcDllObject));
180+
try {
181+
182+
RtlZeroMemory(&mm_CcDllObject, sizeof(mm_CcDllObject));
181183

182-
if (m_TypedObject.GetPtr()) {
184+
if (m_TypedObject.GetPtr()) {
183185

184-
m_ImageBase = m_TypedObject.Field("DllBase").GetPtr();
185-
m_ImageSize = m_TypedObject.Field("SizeOfImage").GetUlong();
186+
m_ImageBase = m_TypedObject.Field("DllBase").GetPtr();
187+
m_ImageSize = m_TypedObject.Field("SizeOfImage").GetUlong();
186188

187-
if (m_TypedObject.HasField("LoadTime")) {
189+
ExtRemoteTypedEx::GetUnicodeString(m_TypedObject.Field("FullDllName"), (PWSTR)&mm_CcDllObject.FullDllName, sizeof(mm_CcDllObject.FullDllName));
190+
ExtRemoteTypedEx::GetUnicodeString(m_TypedObject.Field("BaseDllName"), (PWSTR)&mm_CcDllObject.DllName, sizeof(mm_CcDllObject.DllName));
188191

189-
mm_CcDllObject.LoadTime.QuadPart = m_TypedObject.Field("LoadTime.QuadPart").GetUlong64();
192+
if (m_TypedObject.HasField("LoadTime")) {
193+
194+
mm_CcDllObject.LoadTime.QuadPart = m_TypedObject.Field("LoadTime.QuadPart").GetUlong64();
195+
}
190196
}
197+
}
198+
catch (...) {
191199

192-
ExtRemoteTypedEx::GetUnicodeString(m_TypedObject.Field("FullDllName"), (PWSTR)&mm_CcDllObject.FullDllName, sizeof(mm_CcDllObject.FullDllName));
193-
ExtRemoteTypedEx::GetUnicodeString(m_TypedObject.Field("BaseDllName"), (PWSTR)&mm_CcDllObject.DllName, sizeof(mm_CcDllObject.DllName));
194200
}
195201
}
196202

@@ -498,6 +504,9 @@ Return Value:
498504
for (Dlls.First(); !Dlls.IsDone(); Dlls.Next()) {
499505

500506
MsDllObject Object = Dlls.Current();
507+
508+
Object.mm_CcDllObject.LoadTime.QuadPart = 0;
509+
501510
m_DllList.push_back(Object);
502511
}
503512
}

SwishDbgExt/Registry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ GetKeyNode(
224224

225225
try {
226226

227-
ReadPointer(GetExpression("nt!CmpMasterHive"), &CmpMasterHive);
228-
ReadPointer(GetExpression("nt!CmpRegistryRootObject"), &CmpRegistryRootObject);
227+
ReadPointer(CmpMasterHiveAddress, &CmpMasterHive);
228+
ReadPointer(CmpRegistryRootObjectAddress, &CmpRegistryRootObject);
229229

230230
ExtRemoteTyped KeyHive("(nt!_HHIVE *)@$extin", CmpMasterHive);
231231
ExtRemoteTyped KeyBody("(nt!_CM_KEY_BODY *)@$extin", CmpRegistryRootObject);

SwishDbgExt/SwishDbgExt.cpp

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ BOOLEAN g_Verbose = FALSE;
4949
#endif
5050

5151

52+
ULONG64 KeNumberProcessorsAddress;
53+
ULONG64 KiProcessorBlockAddress;
54+
ULONG64 ObpRootDirectoryObjectAddress;
55+
ULONG64 ObTypeIndexTableAddress;
56+
ULONG64 ObHeaderCookieAddress;
57+
ULONG64 CmpRegistryRootObjectAddress;
58+
ULONG64 CmpMasterHiveAddress;
59+
60+
5261
class EXT_CLASS : public ExtExtension
5362
{
5463
public:
@@ -137,6 +146,16 @@ class EXT_CLASS : public ExtExtension
137146
" under certain conditions; type `show c' for details.\n",
138147
EXT_VERSION, __DATE__);
139148

149+
KeNumberProcessorsAddress = GetExpression("nt!KeNumberProcessors");
150+
KiProcessorBlockAddress = GetExpression("nt!KiProcessorBlock");
151+
152+
ObpRootDirectoryObjectAddress = GetExpression("nt!ObpRootDirectoryObject");
153+
ObTypeIndexTableAddress = GetExpression("nt!ObTypeIndexTable");
154+
ObHeaderCookieAddress = GetExpression("nt!ObHeaderCookie");
155+
156+
CmpRegistryRootObjectAddress = GetExpression("nt!CmpRegistryRootObject");
157+
CmpMasterHiveAddress = GetExpression("nt!CmpMasterHive");
158+
140159
DebugControl->Release();
141160
DebugClient->Release();
142161

@@ -1648,27 +1667,27 @@ EXT_COMMAND(ms_idt,
16481667
"{base;ed,o;base;Display information for a given idt}")
16491668
{
16501669
ULONG64 IdtBase = GetArgU64("base", FALSE);
1651-
vector<IDT_OBJECT> Idts = GetInterrupts(IdtBase);
1670+
vector<IDT_ENTRY> IdtEntries = GetInterrupts(IdtBase);
16521671

16531672
Dml(" |-----|-----|--------------------|--------------------------------------------------------|---------|--------|\n"
16541673
" | <col fg=\"emphfg\">%-3s</col> | <col fg=\"emphfg\">%-3s</col> | <col fg=\"emphfg\">%-18s</col> | <col fg=\"emphfg\">%-54s</col> | <col fg=\"emphfg\">%-7s</col> | <col fg=\"emphfg\">%-6s</col> |\n"
16551674
" |-----|-----|--------------------|--------------------------------------------------------|---------|--------|\n",
16561675
"Cre", "Idx", "Address", "Name", "Patched", "Hooked");
16571676

1658-
for each (IDT_OBJECT Idt in Idts)
1659-
{
1660-
UCHAR Name[512] = { 0 };
1677+
for each (IDT_ENTRY IdtEntry in IdtEntries) {
1678+
1679+
CHAR Name[MAX_PATH] = {0};
1680+
1681+
if (IdtEntry.Address) {
16611682

1662-
if (Idt.Entry)
1663-
{
16641683
Dml(" | %3d | %3d | <link cmd = \"u 0x%016I64X L5\">0x%016I64X</link> | %-54s | <col fg=\"changed\">%-7s</col> | <col fg=\"changed\">%-6s</col> |\n",
1665-
Idt.CoreIndex,
1666-
Idt.Index,
1667-
Idt.Entry,
1668-
Idt.Entry,
1669-
GetNameByOffset(Idt.Entry, (PSTR)Name, _countof(Name)),
1670-
Idt.Entry ? "" : "",
1671-
IsPointerHooked(Idt.Entry) ? "Yes" : "No");
1684+
IdtEntry.CoreIndex,
1685+
IdtEntry.Index,
1686+
IdtEntry.Address,
1687+
IdtEntry.Address,
1688+
GetNameByOffset(IdtEntry.Address, (PSTR)Name, _countof(Name)),
1689+
IdtEntry.Address ? "" : "",
1690+
IsPointerHooked(IdtEntry.Address) ? "Yes" : "");
16721691
}
16731692
}
16741693
}

SwishDbgExt/SwishDbgExt.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ extern "C" {
110110
//
111111

112112
extern BOOLEAN g_Verbose;
113+
extern ULONG64 KeNumberProcessorsAddress;
114+
extern ULONG64 KiProcessorBlockAddress;
115+
extern ULONG64 ObpRootDirectoryObjectAddress;
116+
extern ULONG64 ObTypeIndexTableAddress;
117+
extern ULONG64 ObHeaderCookieAddress;
118+
extern ULONG64 CmpRegistryRootObjectAddress;
119+
extern ULONG64 CmpMasterHiveAddress;
113120

114121
VOID
115122
ReleaseObjectTypeTable(

0 commit comments

Comments
 (0)