Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://waleedassar.blogspot.com
- //http://www.twitter.com/waleedassar
- //You can use this system call to determine if the running thread is the only thread in the current
- // or remote process.
- //I found the parameter being called "ThreadAmILastThread", but i prefer to call it "ThreadAmIOnlyThread"
- //since the function call returns TRUE if the thread is the only thread in its process.
- #include "stdafx.h"
- #include "windows.h"
- #include "stdio.h"
- #define ThreadAmILastThread 0xC
- #define ThreadAmIOnlyThread 0xC
- extern "C"
- {
- int __stdcall ZwSetInformationThread(HANDLE,unsigned long,unsigned long*,unsigned long);
- int __stdcall ZwQueryInformationThread(HANDLE,unsigned long,unsigned long*,unsigned long,unsigned long*);
- }
- void Wait()
- {
- MessageBox(0,"Waliedassar","waliedassar",0);
- //Sleep(INFINITE);
- return;
- }
- int main()
- {
- //You can comment-out the following to see the difference.
- /*unsigned long tid=0;
- HANDLE hT=CreateThread(0,0x1000,(LPTHREAD_START_ROUTINE)(&Wait),0,0,&tid);
- if(hT==0) return 0;
- Sleep(1000);*/
- unsigned long OnlyThread=0;
- int ret=ZwQueryInformationThread(GetCurrentThread(),
- ThreadAmILastThread,(unsigned long*)(&OnlyThread),0x4,0);
- if(ret>=0) printf("Okay\r\n");
- else printf("Error %x\r\n",ret);
- printf("Only Thread: is %s\r\n",(OnlyThread?"TRUE":"FALSE"));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement