http://bbs.pediy.com/showthread.php?t=174534 得到如下结构@cvcvxk
typedef NTSTATUS (NTAPI *_ZwCreateThreadEx)(
OUT PHANDLE ThreadHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
IN HANDLE ProcessHandle,
IN PTHREAD_START_ROUTINE StartRoutine,
IN PVOID StartContext,
IN ULONG CreateThreadFlags,
IN SIZE_T ZeroBits OPTIONAL,
IN SIZE_T StackSize OPTIONAL,
IN SIZE_T MaximumStackSize OPTIONAL,
IN PPROC_THREAD_ATTRIBUTE_LIST AttributeList
);
太菜了,还得请教下。。。
xp下的hook函数
NTSTATUS
HookedNtCreateThread(
OUT PHANDLE ThreadHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
IN HANDLE ProcessHandle,
OUT PCLIENT_ID ClientId,
IN PCONTEXT ThreadContext,
IN PWORD InitialTeb,
IN BOOLEAN CreateSuspended
)
{
}
由于现在hook了NtCreateThreadEx函数,参数有了变化
NTSTATUS
MyNtCreateThreadEx(
OUT PHANDLE ThreadHandle,
IN ACCESS_MASK DesiredAccess,
IN PVOID ObjectAttributes OPTIONAL,
IN HANDLE ProcessHandle,
IN PVOID lpStartAddress,
IN PVOID StartContext,//StartContext
IN BOOL CreateSuspended,
IN ULONG StackZeroBits,
IN SIZE_T SizeOfStackCommit,
IN SIZE_T SizeOfStackReserve,
OUT PVOID lpBytesBuffer)
{
第一:我需要在这个函数中得到线程ID和类似于ThreadContext->Eax的起始地址。
在NtCreateThread中通过ClientId->UniqueThread和ThreadContext->Eax得到。
但在NtCreateThreadEx中,无此参数,于是线程ID无法得到(我现在用的是PsGetCurrentThread()->Cid.UniqueThread,但是我又不是很确定,因为我要获得的是被创建的线程ID,而不是创建者的)
第二:关于@kman说的 ThreadContext->Eax和lpStartAddress“相同”的说法,经过验证,也没法作用。我也不是要拦截线程起始地址,只是和PEB的范围做判断。详见这个判断
if (ThreadContext->Eax >= (DWORD)BaseAddress &&
ThreadContext->Eax < (DWORD)BaseAddress+(DWORD)SizeOfImage)
{
//一些操作
break;
}
}
for (i = 0 ; i < AttributeList->Length / sizeof(NT_PROC_THREAD_ATTRIBUTE_ENTRY) ; i++)
{
if (AttributeList->Entry[i].Attribute == 0x10003)
tid = *Attribute->Entry[i].Value
}
当然,这里面还需要你自己做一些容错的处理代码。