PAGED_CODE()

#if DBG
#define PAGED_CODE() \
    if (VideoPortGetCurrentIrql() > 1 /*APC_LEVEL*/) { \
        VideoPortDebugPrint(0, "Video: Pageable code called at IRQL %d\n", VideoPortGetCurrentIrql() ); \
        ASSERT(FALSE); \
        }

#else
#define PAGED_CODE()
#endif

 

分析,注释每一行代码 NTSTATUS DbgkpPostFakeThreadMessages ( IN PEPROCESS Process, IN PDEBUG_OBJECT DebugObject, IN PETHREAD StartThread, OUT PETHREAD *pFirstThread, OUT PETHREAD *pLastThread ) /*++ Routine Description: This routine posts the faked initial process create, thread create messages Arguments: Process - Process to be debugged DebugObject - Debug object to queue messages to StartThread - Thread to start search from pFirstThread - First thread found in the list pLastThread - Last thread found in the list Return Value: None. --*/ { NTSTATUS Status; PETHREAD Thread, FirstThread, LastThread; DBGKM_APIMSG ApiMsg; BOOLEAN First = TRUE; BOOLEAN IsFirstThread; PIMAGE_NT_HEADERS NtHeaders; ULONG Flags; NTSTATUS Status1; PAGED_CODE (); LastThread = FirstThread = NULL; Status = STATUS_UNSUCCESSFUL; if (StartThread != NULL) { First = FALSE; FirstThread = StartThread; ObReferenceObject (FirstThread); } else { StartThread = PsGetNextProcessThread (Process, NULL); First = TRUE; } for (Thread = StartThread; Thread != NULL; Thread = PsGetNextProcessThread (Process, Thread)) { Flags = DEBUG_EVENT_NOWAIT; // // Keep a track ont he last thread we have seen. // We use this as a starting point for new threads after we // really attach so we can pick up any new threads. // if (LastThread != NULL) { ObDereferenceObject (LastThread); } LastThread = Thread; ObReferenceObject (LastThread); // // Acquire rundown protection of the thread. // This stops the thread exiting so we know it can't send // it's termination message // if (ExAcquireRundownProtection (&Thread->RundownProtect)) { Flags |= DEBUG_EVENT_RELEASE; // // Suspend the thread if we can for the debugger // We don't suspend terminating threads as we will not be giving details // of these to the debugger. // if (!IS_SYSTEM_THREAD (Thread)) { Status1 = PsSuspendThread (Thread, NULL); if (NT_SUCCESS (Status1)) { Flags |= DEBUG_EVENT_SUSPEND; } } } else { // // Rundown protection failed for this thread. // This means the thread is exiting. We will mark this thread // later so it doesn't sent a thread termination message. // We can't do this now because this attach might fail. // Flags |= DEBUG_EVENT_PROTECT_FAILED; } RtlZeroMemory (&ApiMsg, sizeof (ApiMsg)); if (First && (Flags&DEBUG_EVENT_PROTECT_FAILED) == 0 && !IS_SYSTEM_THREAD (Thread) && Thread->GrantedAccess != 0) { IsFirstThread = TRUE; } else { IsFirstThread = FALSE; } if (IsFirstThread) { ApiMsg.ApiNumber = DbgKmCreateProcessApi; if (Process->SectionObject != NULL) { // system process doesn't have one of these! ApiMsg.u.CreateProcessInfo.FileHandle = DbgkpSectionToFileHandle (Process->SectionObject); } else { ApiMsg.u.CreateProcessInfo.FileHandle = NULL; } ApiMsg.u.CreateProcessInfo.BaseOfImage = Process->SectionBaseAddress; try { NtHeaders = RtlImageNtHeader(Process->SectionBaseAddress); if (NtHeaders) { ApiMsg.u.CreateProcessInfo.InitialThread.StartAddress = NULL; // Filling this in breaks MSDEV! // (PVOID)(NtHeaders->OptionalHeader.ImageBase + NtHeaders->OptionalHeader.AddressOfEntryPoint); ApiMsg.u.CreateProcessInfo.DebugInfoFileOffset = NtHeaders->FileHeader.PointerToSymbolTable; ApiMsg.u.CreateProcessInfo.DebugInfoSize = NtHeaders->FileHeader.NumberOfSymbols; } } except (EXCEPTION_EXECUTE_HANDLER) { ApiMsg.u.CreateProcessInfo.InitialThread.StartAddress = NULL; ApiMsg.u.CreateProcessInfo.DebugInfoFileOffset = 0; ApiMsg.u.CreateProcessInfo.DebugInfoSize = 0; } } else { ApiMsg.ApiNumber = DbgKmCreateThreadApi; ApiMsg.u.CreateThread.StartAddress = Thread->StartAddress; } Status = DbgkpQueueMessage (Process, Thread, &ApiMsg, Flags, DebugObject); if (!NT_SUCCESS (Status)) { if (Flags&DEBUG_EVENT_SUSPEND) { PsResumeThread (Thread, NULL); } if (Flags&DEBUG_EVENT_RELEASE) { ExReleaseRundownProtection (&Thread->RundownProtect); } if (ApiMsg.ApiNumber == DbgKmCreateProcessApi && ApiMsg.u.CreateProcessInfo.FileHandle != NULL) { ObCloseHandle (ApiMsg.u.CreateProcessInfo.FileHandle, KernelMode); } PsQuitNextProcessThread (Thread); break; } else if (IsFirstThread) { First = FALSE; ObReferenceObject (Thread); FirstThread = Thread; } } if (!NT_SUCCESS (Status)) { if (FirstThread) { ObDereferenceObject (FirstThread); } if (LastThread != NULL) { ObDereferenceObject (LastThread); } } else { if (FirstThread) { *pFirstThread = FirstThread; *pLastThread = LastThread; } else { Status = STATUS_UNSUCCESSFUL; } } return Status; }
最新发布
08-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值