1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
/*++
Copyright (c) 1990 Microsoft Corporation
Module Name:
kdndis.c
Abstract:
Ndis Testprot Kernel Debugger extension
This module contains a set of useful kernel debugger extensions for the
NT MAC Tester
Author:
Sanjeev Katariya May-6-1993
Revision History:
Created
--*/
#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <windows.h>
#include <ntkdexts.h>
#include <stdlib.h>
#include <malloc.h>
#include "tpkd.h"
VOID
DumpNdisPacket(
PNTKD_OUTPUT_ROUTINE OutputRoutine,
PNTKD_READ_VIRTUAL_MEMORY ReadMemoryRoutine,
PNDIS_PACKET NdisPacket,
DWORD AddressNdisPacket
)
{
NDIS_BUFFER NdisBuffer;
DWORD BufferAddress;
BOOL ReadMemory = FALSE;
INT i;
(OutputRoutine)( "\nNDIS_PACKET at Memory location: 0x%lx\n", AddressNdisPacket );
(OutputRoutine)( "\tNDIS_PACKET_PRIVATE\n" );
(OutputRoutine)( "\t\tPhysical Count : %ld\n" , NdisPacket->Private.PhysicalCount );
(OutputRoutine)( "\t\tTotal Length : %ld\n" , NdisPacket->Private.TotalLength );
(OutputRoutine)( "\t\tNdis Buffer Head Ptr : 0x%lx\n", NdisPacket->Private.Head );
(OutputRoutine)( "\t\tNdis Buffer Tail Ptr : 0x%lx\n", NdisPacket->Private.Tail );
(OutputRoutine)( "\t\tNdis Packet Pool Ptr : 0x%lx\n", NdisPacket->Private.Pool );
(OutputRoutine)( "\t\tCount : %ld\n" , NdisPacket->Private.Count );
(OutputRoutine)( "\t\tFlags : 0x%lx\n", NdisPacket->Private.Flags );
(OutputRoutine)( "\t\tValid Counts : %d\n" , NdisPacket->Private.ValidCounts );
(OutputRoutine)( "\t\tMacReserved : " );
for( i = 0; i < 16; i++ ) {
(OutputRoutine)( "0x%2.2x", NdisPacket->MacReserved[i] );
}
(OutputRoutine)( "\n\t\tProtocolReserved : 0x%2.2x\n", NdisPacket->ProtocolReserved[0] );
//
// And now the NDIS_BUFFER chain
//
BufferAddress = NdisPacket->Private.Head;
try {
ReadMemory = (ReadMemoryRoutine)( (LPVOID)BufferAddress,
&NdisBuffer,
sizeof( NDIS_BUFFER ),
NULL
);
} except ( EXCEPTION_ACCESS_VIOLATION ) {
(OutputRoutine)( "The routine was unable to access NDIS_BUFFER number of bytes.\n" );
(OutputRoutine)( "Possible bad NDIS_BUFFER address 0x%lx\n", BufferAddress );
return;
}
while ( ReadMemory ) {
DumpNdisBuffer( OutputRoutine, ReadMemoryRoutine, &NdisBuffer, BufferAddress );
BufferAddress = NdisBuffer.Next;
(OutputRoutine)( "\n\tNext NDIS_BUFFER at address 0x%lx\n", BufferAddress );
try {
ReadMemory = (ReadMemoryRoutine)( (LPVOID)BufferAddress,
&NdisBuffer,
sizeof( NDIS_BUFFER ),
NULL
);
} except ( EXCEPTION_ACCESS_VIOLATION ) {
(OutputRoutine)( "The routine was unable to access NDIS_BUFFER number of bytes.\n" );
(OutputRoutine)( "Possible bad NDIS_BUFFER address 0x%lx\n", BufferAddress );
return;
}
}
}
VOID
DumpNdisBuffer(
PNTKD_OUTPUT_ROUTINE OutputRoutine,
PNTKD_READ_VIRTUAL_MEMORY ReadMemoryRoutine,
PNDIS_BUFFER NdisBuffer,
DWORD AddressNdisBuffer
)
{
ULONG i;
BOOL ReadMemory = FALSE;
PUCHAR Buffer = calloc( NdisBuffer->ByteCount, sizeof( UCHAR ) );
(OutputRoutine)( "\n\tNDIS_BUFFER at Memory location: 0x%lx\n", AddressNdisBuffer );
(OutputRoutine)( "\t\tNext Buffer : 0x%lx\n", NdisBuffer->Next );
(OutputRoutine)( "\t\tSize : %d\n" , NdisBuffer->Size );
(OutputRoutine)( "\t\tMDL Flags : 0x%x\n" , NdisBuffer->MdlFlags );
(OutputRoutine)( "\t\tEPROCESS Ptr : 0x%lx\n", NdisBuffer->Process );
(OutputRoutine)( "\t\tMapped System VA : 0x%lx\n", NdisBuffer->MappedSystemVa );
(OutputRoutine)( "\t\tStart VA : 0x%lx\n", NdisBuffer->StartVa );
(OutputRoutine)( "\t\tByte Count : 0x%lx\n", NdisBuffer->ByteCount);
(OutputRoutine)( "\t\tByte Offset : 0x%lx\n", NdisBuffer->ByteOffset );
(OutputRoutine)( "\t\tVA Contents\n" );
if ( Buffer != NULL ) {
try {
ReadMemory = (ReadMemoryRoutine)( (LPVOID)NdisBuffer->StartVa,
Buffer,
NdisBuffer->ByteCount,
NULL
);
} except ( EXCEPTION_ACCESS_VIOLATION ) {
(OutputRoutine)( "The routine was unable to access Byte Count number of bytes.\n" );
(OutputRoutine)( "Possible bad StartVa address 0x%lx\n", NdisBuffer->StartVa );
ReadMemory = FALSE;
}
if ( ReadMemory ) {
for( i = 0; i < NdisBuffer->ByteCount ; i++ ) {
if ( (i%16) == 0 ) {
(OutputRoutine)( "\n\t\t%2x", Buffer[i] );
} else {
(OutputRoutine)( "-%2x", Buffer[i] );
}
}
(OutputRoutine)( "\n" );
free( Buffer );
return;
}
free( Buffer );
}
(OutputRoutine)( "Unable to access contents of StartVa: 0x%lx\n", NdisBuffer->StartVa );
}
VOID
DumpOpenBuffer(
PNTKD_OUTPUT_ROUTINE OutputRoutine,
PNTKD_READ_VIRTUAL_MEMORY ReadMemoryRoutine,
POPEN_BLOCK OpenBuffer,
DWORD AddressOpenBuffer
)
{
ULONG i;
BOOL ReadMemory = FALSE;
(OutputRoutine)( "\n\tOPEN_BLOCK at Memory location: 0x%lx\n\n", AddressOpenBuffer );
(OutputRoutine)( "\t\tNdisBindingHandle : 0x%lx\n", OpenBuffer->NdisBindingHandle );
(OutputRoutine)( "\t\tNdisProtocolHandle : 0x%lx\n", OpenBuffer->NdisProtocolHandle );
(OutputRoutine)( "\t\tOpenInstance : %d\n" , OpenBuffer->OpenInstance );
(OutputRoutine)( "\t\tClosing Status : %d\n" , OpenBuffer->Closing );
(OutputRoutine)( "\t\tStation Address : " );
for( i = 0 ; i < ADDRESS_LENGTH; i++ ) {
(OutputRoutine)( "%2.2x", OpenBuffer->StationAddress[i] );
}
(OutputRoutine)( "\n" );
(OutputRoutine)( "\t\tPtr to Adapter Name : 0x%lx\n", OpenBuffer->AdapterName );
(OutputRoutine)( "\t\tSpin Lock Resource : 0x%lx\n", OpenBuffer->SpinLock );
(OutputRoutine)( "\t\tReference Count : %d\n" , OpenBuffer->ReferenceCount );
(OutputRoutine)( "\t\tMedium Index : %d\n" , OpenBuffer->MediumIndex );
(OutputRoutine)( "\t\tPtr to Media Info : 0x%lx\n", OpenBuffer->Media );
(OutputRoutine)( "\t\tPtr to Global Counters : 0x%lx\n", OpenBuffer->GlobalCounters );
(OutputRoutine)( "\t\tPtr to Environment : 0x%lx\n", OpenBuffer->Environment );
(OutputRoutine)( "\t\tPtr to Stress Block : 0x%lx\n", OpenBuffer->Stress );
(OutputRoutine)( "\t\tPtr to Send Block : 0x%lx\n", OpenBuffer->Send );
(OutputRoutine)( "\t\tPtr to Receive Block : 0x%lx\n", OpenBuffer->Receive );
(OutputRoutine)( "\t\tPtr to Event Queue : 0x%lx\n", OpenBuffer->EventQueue );
(OutputRoutine)( "\t\tPtr to Pause Block : 0x%lx\n", OpenBuffer->Pause );
(OutputRoutine)( "\t\tPtr to Open Request Handle : 0x%lx\n", OpenBuffer->OpenReqHndl );
(OutputRoutine)( "\t\tPtr to Close Request Handle : 0x%lx\n", OpenBuffer->CloseReqHndl );
(OutputRoutine)( "\t\tPtr to Reset Request Handle : 0x%lx\n", OpenBuffer->ResetReqHndl );
(OutputRoutine)( "\t\tPtr to Request Request Handle: 0x%lx\n", OpenBuffer->RequestReqHndl );
(OutputRoutine)( "\t\tPtr to Stress Request Handle : 0x%lx\n", OpenBuffer->StressReqHndl );
(OutputRoutine)( "\t\tStatus IRP cancelled : %d\n" , OpenBuffer->IrpCancelled );
(OutputRoutine)( "\t\tPtr to IRP : 0x%lx\n", OpenBuffer->Irp );
(OutputRoutine)( "\t\tSignature : 0x%lx\n", OpenBuffer->Signature );
}
/*
************************* Exported Routines **********************************
* *
* Method for invoking at debugger *
* *
* kd > !tpkd.ndispacket Address where Address is of type pointer *
* kd > !tpkd.ndisbuffer Address where Address is of type pointer *
* kd > !tpkd.openblock Address where Address is of type pointer *
* kd > !tpkd.help *
* *
*******************************************************************************
*/
VOID
ndispacket(
DWORD CurrentPc,
PNTKD_EXTENSION_APIS ExtensionApis,
LPSTR ArgumentString
)
{
PNTKD_OUTPUT_ROUTINE OutputRoutine ;
PNTKD_GET_EXPRESSION GetExpressionRoutine;
PNTKD_READ_VIRTUAL_MEMORY ReadMemoryRoutine ;
PNTKD_GET_SYMBOL GetSymbolRoutine ;
NDIS_PACKET Packet ;
DWORD AddressNdisPacket ;
BOOL ReadMemory = FALSE ;
OutputRoutine = ExtensionApis->lpOutputRoutine;
GetExpressionRoutine = ExtensionApis->lpGetExpressionRoutine;
GetSymbolRoutine = ExtensionApis->lpGetSymbolRoutine;
ReadMemoryRoutine = ExtensionApis->lpReadVirtualMemRoutine;
//
// Get the address of the NDIS_PACKET
AddressNdisPacket = (GetExpressionRoutine)(ArgumentString);
//
if ( !AddressNdisPacket ) {
return;
}
try {
//
// Now read the memory contents into our buffer area
//
ReadMemory = (ReadMemoryRoutine)( (LPVOID)AddressNdisPacket,
&Packet,
sizeof(NDIS_PACKET),
NULL
);
} except( EXCEPTION_ACCESS_VIOLATION ) {
(OutputRoutine)( "The routine was unable to access NDIS_PACKET size bytes.\n" );
(OutputRoutine)( "Possible bad NDIS_PACKET address 0x%lx\n", AddressNdisPacket );
ReadMemory = FALSE;
}
if ( !ReadMemory ) {
return;
}
DumpNdisPacket( OutputRoutine,
ReadMemoryRoutine,
&Packet,
AddressNdisPacket );
}
VOID
ndisbuffer(
DWORD CurrentPc,
PNTKD_EXTENSION_APIS ExtensionApis,
LPSTR ArgumentString
)
{
PNTKD_OUTPUT_ROUTINE OutputRoutine ;
PNTKD_GET_EXPRESSION GetExpressionRoutine;
PNTKD_READ_VIRTUAL_MEMORY ReadMemoryRoutine ;
PNTKD_GET_SYMBOL GetSymbolRoutine ;
NDIS_BUFFER NdisBuffer ;
DWORD AddressNdisBuffer ;
BOOL ReadMemory = FALSE ;
OutputRoutine = ExtensionApis->lpOutputRoutine;
GetExpressionRoutine = ExtensionApis->lpGetExpressionRoutine;
GetSymbolRoutine = ExtensionApis->lpGetSymbolRoutine;
ReadMemoryRoutine = ExtensionApis->lpReadVirtualMemRoutine;
//
// Get the address of the NDIS_PACKET
//
AddressNdisBuffer = (GetExpressionRoutine)(ArgumentString);
if ( !AddressNdisBuffer ) {
return;
}
try {
//
// Now read the memory contents into our buffer area
//
ReadMemory = (ReadMemoryRoutine)( (LPVOID)AddressNdisBuffer,
&NdisBuffer,
sizeof(NDIS_BUFFER),
NULL
);
} except( EXCEPTION_ACCESS_VIOLATION ) {
(OutputRoutine)( "The routine was unable to access NDIS_BUFFER size bytes.\n" );
(OutputRoutine)( "Possible bad NDIS_BUFFER address 0x%lx\n", AddressNdisBuffer );
ReadMemory = FALSE;
}
if ( !ReadMemory ) {
return;
}
DumpNdisBuffer( OutputRoutine,
ReadMemoryRoutine,
&NdisBuffer,
AddressNdisBuffer );
}
VOID
openblock(
DWORD CurrentPc,
PNTKD_EXTENSION_APIS ExtensionApis,
LPSTR ArgumentString
)
{
PNTKD_OUTPUT_ROUTINE OutputRoutine ;
PNTKD_GET_EXPRESSION GetExpressionRoutine;
PNTKD_READ_VIRTUAL_MEMORY ReadMemoryRoutine ;
PNTKD_GET_SYMBOL GetSymbolRoutine ;
OPEN_BLOCK OpenBuffer ;
DWORD AddressOpenBuffer ;
BOOL ReadMemory = FALSE ;
OutputRoutine = ExtensionApis->lpOutputRoutine;
GetExpressionRoutine = ExtensionApis->lpGetExpressionRoutine;
GetSymbolRoutine = ExtensionApis->lpGetSymbolRoutine;
ReadMemoryRoutine = ExtensionApis->lpReadVirtualMemRoutine;
//
// Get the address of the OPEN_BLOCK
//
AddressOpenBuffer = (GetExpressionRoutine)(ArgumentString);
if ( !AddressOpenBuffer ) {
return;
}
try {
//
// Now read the memory contents into our buffer area
//
ReadMemory = (ReadMemoryRoutine)( (LPVOID)AddressOpenBuffer,
&OpenBuffer,
sizeof(OPEN_BLOCK),
NULL
);
} except( EXCEPTION_ACCESS_VIOLATION ) {
(OutputRoutine)( "The routine was unable to access OPEN_BLOCK size bytes.\n" );
(OutputRoutine)( "Possible bad OPEN_BLOCK address 0x%lx\n", AddressOpenBuffer );
ReadMemory = FALSE;
}
if ( !ReadMemory ) {
return;
}
DumpOpenBuffer( OutputRoutine,
ReadMemoryRoutine,
&OpenBuffer,
AddressOpenBuffer );
}
VOID
help(
DWORD CurrentPc,
PNTKD_EXTENSION_APIS ExtensionApis,
LPSTR ArgumentString
)
{
PNTKD_OUTPUT_ROUTINE OutputRoutine;
OutputRoutine = ExtensionApis->lpOutputRoutine;
(OutputRoutine)( "The following commands are available\n" );
(OutputRoutine)( "\tndispacket <address>\n\tndisbuffer <address>\n\topenblock\n\thelp\n" );
}
|