00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
#include "stdarg.h"
00028
#include "stdio.h"
00029
#include "ntrtlp.h"
00030 #define NOEXTAPI
00031
#include "wdbgexts.h"
00032
#include <ntdbg.h>
00033
00034
00035 ULONG
00036 DbgPrint(
00037 PCHAR Format,
00038 ...
00039 )
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 {
00065 va_list arglist;
00066 UCHAR
Buffer[512];
00067
int cb;
00068 STRING Output;
00069
NTSTATUS Status = STATUS_SUCCESS;
00070
#if !defined(BLDR_KERNEL_RUNTIME) && !defined(NTOS_KERNEL_RUNTIME)
00071
00072
if (NtCurrentTeb()->InDbgPrint) {
00073
return STATUS_SUCCESS;
00074 }
00075 NtCurrentTeb()->InDbgPrint =
TRUE;
00076
#endif
00077
00078
00079
00080
00081
00082 va_start(arglist, Format);
00083
00084
#if !defined(BLDR_KERNEL_RUNTIME)
00085
__try {
00086 cb = _vsnprintf(
Buffer,
sizeof(
Buffer), Format, arglist);
00087 } __except (
EXCEPTION_EXECUTE_HANDLER) {
00088
Status = GetExceptionCode();
00089 }
00090
#else
00091
cb = _vsnprintf(
Buffer,
sizeof(
Buffer), Format, arglist);
00092
#endif
00093
00094 va_end(arglist);
00095
00096
if (!
NT_SUCCESS(
Status)) {
00097
#if !defined(BLDR_KERNEL_RUNTIME) && !defined(NTOS_KERNEL_RUNTIME)
00098
NtCurrentTeb()->InDbgPrint =
FALSE;
00099
#endif
00100
return Status;
00101 }
00102
00103
if (cb == -1) {
00104 cb =
sizeof(
Buffer);
00105
Buffer[
sizeof(
Buffer) - 1] =
'\n';
00106 }
00107 Output.Buffer =
Buffer;
00108 Output.Length = (
USHORT) cb;
00109
00110
00111
00112
00113
00114
00115
00116
#if !defined(BLDR_KERNEL_RUNTIME) && !defined(NTOS_KERNEL_RUNTIME)
00117
#if !i386
00118
00119
00120
00121
00122
00123
if (NtCurrentPeb()->FastPebLockRoutine !=
NULL)
00124
#endif
00125
if (NtCurrentPeb()->BeingDebugged) {
00126
EXCEPTION_RECORD ExceptionRecord;
00127
00128
00129
00130
00131
00132 ExceptionRecord.ExceptionCode = DBG_PRINTEXCEPTION_C;
00133 ExceptionRecord.ExceptionRecord = (PEXCEPTION_RECORD)
NULL;
00134 ExceptionRecord.NumberParameters = 2;
00135 ExceptionRecord.ExceptionFlags = 0;
00136 ExceptionRecord.ExceptionInformation[ 0 ] = Output.Length + 1;
00137 ExceptionRecord.ExceptionInformation[ 1 ] = (ULONG_PTR)(Output.Buffer);
00138
RtlRaiseException( &ExceptionRecord );
00139
#if !defined(BLDR_KERNEL_RUNTIME) && !defined(NTOS_KERNEL_RUNTIME)
00140
NtCurrentTeb()->InDbgPrint =
FALSE;
00141
#endif
00142
return STATUS_SUCCESS;
00143 }
00144
#endif
00145
Status =
DebugPrint( &Output );
00146
if (
Status == STATUS_BREAKPOINT) {
00147 DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C);
00148
Status = STATUS_SUCCESS;
00149 }
00150
#if !defined(BLDR_KERNEL_RUNTIME) && !defined(NTOS_KERNEL_RUNTIME)
00151
NtCurrentTeb()->InDbgPrint =
FALSE;
00152
#endif
00153
return Status;
00154 }
00155
00156 ULONG
00157 DbgPrintReturnControlC(
00158 PCHAR Format,
00159 ...
00160 )
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 {
00186 va_list arglist;
00187 UCHAR
Buffer[512];
00188
int cb;
00189 STRING Output;
00190
00191
00192
00193
00194
00195 va_start(arglist, Format);
00196
00197 cb = _vsnprintf(
Buffer,
sizeof(
Buffer), Format, arglist);
00198
if (cb == -1) {
00199 cb =
sizeof(
Buffer);
00200
Buffer[
sizeof(
Buffer) - 1] =
'\n';
00201 }
00202 Output.Buffer =
Buffer;
00203 Output.Length = (
USHORT) cb;
00204
00205
00206
00207
00208
00209
00210
00211
#if !defined(BLDR_KERNEL_RUNTIME) && !defined(NTOS_KERNEL_RUNTIME)
00212
#if !i386
00213
00214
00215
00216
00217
00218
if (NtCurrentPeb()->FastPebLockRoutine !=
NULL)
00219
#endif
00220
if (NtCurrentPeb()->BeingDebugged) {
00221
EXCEPTION_RECORD ExceptionRecord;
00222
00223
00224
00225
00226
00227 ExceptionRecord.ExceptionCode = DBG_PRINTEXCEPTION_C;
00228 ExceptionRecord.ExceptionRecord = (PEXCEPTION_RECORD)
NULL;
00229 ExceptionRecord.NumberParameters = 2;
00230 ExceptionRecord.ExceptionFlags = 0;
00231 ExceptionRecord.ExceptionInformation[ 0 ] = Output.Length + 1;
00232 ExceptionRecord.ExceptionInformation[ 1 ] = (ULONG_PTR)(Output.Buffer);
00233
RtlRaiseException( &ExceptionRecord );
00234
return STATUS_SUCCESS;
00235 }
00236
#endif
00237
return DebugPrint( &Output );
00238 }
00239
00240 ULONG
00241 DbgPrompt(
00242 IN PCHAR Prompt,
00243 OUT PCHAR Response,
00244 IN ULONG MaximumResponseLength
00245 )
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 {
00276
00277 STRING Input;
00278 STRING Output;
00279
00280
00281
00282
00283
00284 Input.MaximumLength = (
USHORT)MaximumResponseLength;
00285 Input.Buffer = Response;
00286 Output.Length = (
USHORT)
strlen( Prompt );
00287 Output.Buffer = Prompt;
00288
return DebugPrompt( &Output, &Input );
00289 }
00290
00291
#if defined(NTOS_KERNEL_RUNTIME) || defined(BLDR_KERNEL_RUNTIME)
00292
00293
00294
VOID
00295 DbgLoadImageSymbols(
00296 IN PSTRING FileName,
00297 IN PVOID ImageBase,
00298 IN ULONG_PTR ProcessId
00299 )
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 {
00314
00315 PIMAGE_NT_HEADERS NtHeaders;
00316
KD_SYMBOLS_INFO SymbolInfo;
00317
00318 SymbolInfo.
BaseOfDll = ImageBase;
00319 SymbolInfo.
ProcessId = ProcessId;
00320 NtHeaders =
RtlImageNtHeader( ImageBase );
00321
if (NtHeaders !=
NULL) {
00322 SymbolInfo.
CheckSum = (ULONG)NtHeaders->OptionalHeader.CheckSum;
00323 SymbolInfo.
SizeOfImage = (ULONG)NtHeaders->OptionalHeader.SizeOfImage;
00324
00325 }
else {
00326
00327
#if defined(BLDR_KERNEL_RUNTIME)
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337 SymbolInfo.
SizeOfImage = 0x100000;
00338
00339
#else
00340
00341 SymbolInfo.
SizeOfImage = 0;
00342
00343
#endif
00344
00345 SymbolInfo.
CheckSum = 0;
00346 }
00347
00348
DebugLoadImageSymbols( FileName, &SymbolInfo);
00349
00350
return;
00351 }
00352
00353
00354
VOID
00355 DbgUnLoadImageSymbols (
00356 IN PSTRING FileName,
00357 IN PVOID ImageBase,
00358 IN ULONG_PTR ProcessId
00359 )
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373 {
00374
KD_SYMBOLS_INFO SymbolInfo;
00375
00376 SymbolInfo.
BaseOfDll = ImageBase;
00377 SymbolInfo.
ProcessId = ProcessId;
00378 SymbolInfo.
CheckSum = 0;
00379 SymbolInfo.
SizeOfImage = 0;
00380
00381
DebugUnLoadImageSymbols( FileName, &SymbolInfo );
00382
00383
return;
00384 }
00385
00386
#endif // defined(NTOS_KERNEL_RUNTIME)