I used NtQueryInformationThread without having to download ntdll (which, in my opinion, loads automatically). I needed to prepare a special header file with this content: http://pastebin.com/ieEqR0eL and include it in my project. After that, I was able to do something like this:
NTSTATUS status; THREAD_BASIC_INFORMATION basicInfo; typedef NTSTATUS ( WINAPI *NQIT )( HANDLE, LONG, PVOID, ULONG, PULONG ); HANDLE thread = OpenThread(THREAD_ALL_ACCESS, false, threadId); NQIT NtQueryInformationThread = ( NQIT )GetProcAddress( GetModuleHandle(TEXT("ntdll.dll")), "NtQueryInformationThread" ); status = NtQueryInformationThread(thread, 0, &basicInfo, sizeof(basicInfo), NULL); CloseHandle(thread); tebAddress = (DWORD)basicInfo.TebBaseAddress; DWORD pebAddress = *((DWORD*)(tebAddress+0x30)); stackBase = *((DWORD*)(tebAddress+4)); stackLimit = *((DWORD*)(tebAddress+8));
source share