00217 :
00218
00219 This function
is called when a
new thread begins to execute. If
the
00220 thread has an associated
DebugPort, then a message
is sent thru
the
00221 port.
00222
00223 If
this thread
is the first thread in
the process, then
this event
00224
is translated into a CreateProcessInfo message.
00225
00226 If a message
is sent, then
while the thread
is awaiting a reply,
00227 all other threads in
the process are suspended.
00228
00229 Arguments:
00230
00231 StartAddress - Supplies
the start address
for the thread that
is
00232 starting.
00233
00234 Return Value:
00235
00236 None.
00237
00238 --*/
00239
00240 {
00241 PVOID Port;
00242 DBGKM_APIMSG m;
00243 PDBGKM_CREATE_THREAD CreateThreadArgs;
00244 PDBGKM_CREATE_PROCESS CreateProcessArgs;
00245
PETHREAD Thread;
00246
PEPROCESS Process;
00247 PDBGKM_LOAD_DLL LoadDllArgs;
00248
NTSTATUS Status;
00249 OBJECT_ATTRIBUTES Obja;
00250 IO_STATUS_BLOCK IoStatusBlock;
00251 PIMAGE_NT_HEADERS NtHeaders;
00252
00253
PAGED_CODE();
00254
00255 Process =
PsGetCurrentProcess();
00256
00257 Port =
PsGetCurrentThread()->HideFromDebugger ?
NULL : Process->
DebugPort;
00258
00259
if (
PsImageNotifyEnabled && !Process->
Pcb.
UserTime) {
00260
IMAGE_INFO ImageInfo;
00261 PIMAGE_NT_HEADERS NtHeaders;
00262 ANSI_STRING
FileName;
00263 UNICODE_STRING UnicodeFileName;
00264 PUNICODE_STRING pUnicodeFileName;
00265
00266
00267
00268
00269 ImageInfo.
Properties = 0;
00270 ImageInfo.
ImageAddressingMode =
IMAGE_ADDRESSING_MODE_32BIT;
00271 ImageInfo.
ImageBase = Process->
SectionBaseAddress;
00272 ImageInfo.
ImageSize = 0;
00273
00274
try {
00275 NtHeaders =
RtlImageNtHeader(Process->
SectionBaseAddress);
00276
00277
if ( NtHeaders ) {
00278 ImageInfo.
ImageSize = NtHeaders->OptionalHeader.SizeOfImage;
00279 }
00280 }
00281 except(EXCEPTION_EXECUTE_HANDLER) {
00282 ImageInfo.
ImageSize = 0;
00283 }
00284 ImageInfo.
ImageSelector = 0;
00285 ImageInfo.
ImageSectionNumber = 0;
00286
00287 pUnicodeFileName =
NULL;
00288
Status =
MmGetFileNameForSection(Process->
SectionHandle, (PSTRING)&FileName);
00289
if (
NT_SUCCESS(Status) ) {
00290
Status =
RtlAnsiStringToUnicodeString(&UnicodeFileName,&FileName,TRUE);
00291
ExFreePool(
FileName.Buffer);
00292
if (
NT_SUCCESS(Status) ) {
00293 pUnicodeFileName = &UnicodeFileName;
00294 }
00295 }
00296
PsCallImageNotifyRoutines(
00297 pUnicodeFileName,
00298 Process->
UniqueProcessId,
00299 &ImageInfo
00300 );
00301
if ( pUnicodeFileName ) {
00302
RtlFreeUnicodeString(pUnicodeFileName);
00303 }
00304
00305
00306
00307
00308 ImageInfo.
Properties = 0;
00309 ImageInfo.
ImageAddressingMode =
IMAGE_ADDRESSING_MODE_32BIT;
00310 ImageInfo.
ImageBase =
PsSystemDllBase;
00311 ImageInfo.
ImageSize = 0;
00312
00313
try {
00314 NtHeaders =
RtlImageNtHeader(PsSystemDllBase);
00315
if ( NtHeaders ) {
00316 ImageInfo.
ImageSize = NtHeaders->OptionalHeader.SizeOfImage;
00317 }
00318 }
00319 except(EXCEPTION_EXECUTE_HANDLER) {
00320 ImageInfo.
ImageSize = 0;
00321 }
00322
00323 ImageInfo.
ImageSelector = 0;
00324 ImageInfo.
ImageSectionNumber = 0;
00325
00326
RtlInitUnicodeString(&UnicodeFileName,L
"\\SystemRoot\\System32\\ntdll.dll");
00327
PsCallImageNotifyRoutines(
00328 &UnicodeFileName,
00329 Process->
UniqueProcessId,
00330 &ImageInfo
00331 );
00332 }
00333
00334
00335
if ( !Port ) {
00336
00337
return;
00338 }
00339
00340 Thread =
PsGetCurrentThread();
00341
00342
if ( Thread->
DeadThread ) {
00343
return;
00344 }
00345
00346
00347
00348
00349
00350
00351
00352
00353
PsLockProcess(Process,KernelMode,PsLockWaitForever);
00354
00355
00356
00357
00358
00359
00360
00361
if ( Process->
Pcb.
UserTime ) {
00362 Process->
CreateProcessReported =
TRUE;
00363 }
00364
00365
if ( Process->
CreateProcessReported ==
FALSE ) {
00366
00367
00368
00369
00370
00371 Process->
CreateProcessReported =
TRUE;
00372
00373 CreateThreadArgs = &m.u.CreateProcessInfo.InitialThread;
00374 CreateThreadArgs->SubSystemKey = 0;
00375
00376 CreateProcessArgs = &m.u.CreateProcessInfo;
00377 CreateProcessArgs->SubSystemKey = 0;
00378 CreateProcessArgs->FileHandle =
DbgkpSectionHandleToFileHandle(
00379 Process->
SectionHandle
00380 );
00381 CreateProcessArgs->BaseOfImage = Process->
SectionBaseAddress;
00382 CreateThreadArgs->StartAddress =
NULL;
00383 CreateProcessArgs->DebugInfoFileOffset = 0;
00384 CreateProcessArgs->DebugInfoSize = 0;
00385
00386
try {
00387 NtHeaders =
RtlImageNtHeader(Process->
SectionBaseAddress);
00388
if ( NtHeaders ) {
00389 CreateThreadArgs->StartAddress = (PVOID)(
00390 NtHeaders->OptionalHeader.ImageBase +
00391 NtHeaders->OptionalHeader.AddressOfEntryPoint);
00392
00393 CreateProcessArgs->DebugInfoFileOffset = NtHeaders->FileHeader.PointerToSymbolTable;
00394 CreateProcessArgs->DebugInfoSize = NtHeaders->FileHeader.NumberOfSymbols;
00395 }
00396 }
00397 except(EXCEPTION_EXECUTE_HANDLER) {
00398 CreateThreadArgs->StartAddress =
NULL;
00399 CreateProcessArgs->DebugInfoFileOffset = 0;
00400 CreateProcessArgs->DebugInfoSize = 0;
00401 }
00402
00403 DBGKM_FORMAT_API_MSG(m,DbgKmCreateProcessApi,
sizeof(*CreateProcessArgs));
00404
00405
PsUnlockProcess(Process);
00406
00407
DbgkpSendApiMessage(&m,Port,FALSE);
00408 ZwClose(CreateProcessArgs->FileHandle);
00409
00410 LoadDllArgs = &m.u.LoadDll;
00411 LoadDllArgs->BaseOfDll =
PsSystemDllBase;
00412 LoadDllArgs->DebugInfoFileOffset = 0;
00413 LoadDllArgs->DebugInfoSize = 0;
00414
00415
try {
00416 NtHeaders =
RtlImageNtHeader(PsSystemDllBase);
00417
if ( NtHeaders ) {
00418 LoadDllArgs->DebugInfoFileOffset = NtHeaders->FileHeader.PointerToSymbolTable;
00419 LoadDllArgs->DebugInfoSize = NtHeaders->FileHeader.NumberOfSymbols;
00420 }
00421 }
00422 except(EXCEPTION_EXECUTE_HANDLER) {
00423 LoadDllArgs->DebugInfoFileOffset = 0;
00424 LoadDllArgs->DebugInfoSize = 0;
00425 }
00426
00427
00428
00429
00430
00431 InitializeObjectAttributes(
00432 &Obja,
00433 &PsNtDllPathName,
00434 OBJ_CASE_INSENSITIVE,
00435 NULL,
00436 NULL
00437 );
00438
00439
Status =
ZwOpenFile(
00440 &LoadDllArgs->FileHandle,
00441 (ACCESS_MASK)(GENERIC_READ | SYNCHRONIZE),
00442 &Obja,
00443 &IoStatusBlock,
00444 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
00445 FILE_SYNCHRONOUS_IO_NONALERT
00446 );
00447
00448
if (
NT_SUCCESS(Status) ) {
00449 DBGKM_FORMAT_API_MSG(m,DbgKmLoadDllApi,
sizeof(*LoadDllArgs));
00450
DbgkpSendApiMessage(&m,Port,TRUE);
00451 }
00452 ZwClose(LoadDllArgs->FileHandle);
00453
00454 }
else {
00455
00456 CreateThreadArgs = &m.u.CreateThread;
00457 CreateThreadArgs->SubSystemKey = 0;
00458 CreateThreadArgs->StartAddress = StartAddress;
00459
00460 DBGKM_FORMAT_API_MSG(m,DbgKmCreateThreadApi,
sizeof(*CreateThreadArgs));
00461
00462
PsUnlockProcess(Process);
00463
00464
DbgkpSendApiMessage(&m,Port,TRUE);
00465 }
00466
00467
00468 }