Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Checking for a Killed TThread

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
h4c0r-BG
Master Cheater
Reputation: 0

Joined: 29 Nov 2006
Posts: 449
Location: The yogurt country

PostPosted: Sat Apr 04, 2009 9:17 am    Post subject: Checking for a Killed TThread Reply with quote

I have the handle and tid of the thread. I know how to check if the thread was suspended but how can i check if it was killed?

For some weird reason if i use OpenThread() it gives me valid handle (even if the thread is allready killed).

I am thinkink of using GetExitCodeThread() but i am not sure how, (tried already) and it kills my thread first and then my whole process. Who knows what i am doing wrong..

By the way i want to avoid using CreateToolhelp32Snapshot() for my goal, i believe there is an easier way.

_________________

Back to top
View user's profile Send private message
Skyone
Grandmaster Cheater
Reputation: 0

Joined: 10 Sep 2006
Posts: 508

PostPosted: Sat Apr 04, 2009 9:22 am    Post subject: Reply with quote

???

Last edited by Skyone on Wed Dec 23, 2009 9:08 am; edited 8 times in total
Back to top
View user's profile Send private message AIM Address MSN Messenger
h4c0r-BG
Master Cheater
Reputation: 0

Joined: 29 Nov 2006
Posts: 449
Location: The yogurt country

PostPosted: Sat Apr 04, 2009 9:43 am    Post subject: Reply with quote

Skyone, thank you for your idea. I am working in Delphi 7. I did the following:

function GetThreadId(
hThread: tHandle): dword;
stdcall; external kernel32 name 'GetThreadId';

But there was a problem. There is no GetThreadId exported function in kernel32.dll

_________________

Back to top
View user's profile Send private message
Skyone
Grandmaster Cheater
Reputation: 0

Joined: 10 Sep 2006
Posts: 508

PostPosted: Sat Apr 04, 2009 9:49 am    Post subject: Reply with quote

???

Last edited by Skyone on Wed Dec 23, 2009 9:08 am; edited 8 times in total
Back to top
View user's profile Send private message AIM Address MSN Messenger
h4c0r-BG
Master Cheater
Reputation: 0

Joined: 29 Nov 2006
Posts: 449
Location: The yogurt country

PostPosted: Sat Apr 04, 2009 9:56 am    Post subject: Reply with quote

return_value_of_func:=GetExitCodeThread(valid_handle_to_my_thread);

After being called once the "return_value_of_func" is 1, after that if i "recall" this line of code again:

return_value_of_func:=GetExitCodeThread(valid_handle_to_my_thread);

my application is terminated.

Edit:

BOOL WINAPI GetExitCodeThread(
__in HANDLE hThread,
__out LPDWORD lpExitCode
);


I have wrong syntaxis of my exported function. Fixing it right now.


Edit2:

if GetExitCodeThread(valid_handle_to_my_thread,asd) = true then messageboxa(0,pchar(inttohex(asd,1)),'getexitcode retvall',0);

I call the function once per second, and like after 5 seconds my application terminates without any errors or messageboxes.

_________________



Last edited by h4c0r-BG on Sat Apr 04, 2009 10:09 am; edited 1 time in total
Back to top
View user's profile Send private message
Skyone
Grandmaster Cheater
Reputation: 0

Joined: 10 Sep 2006
Posts: 508

PostPosted: Sat Apr 04, 2009 10:06 am    Post subject: Reply with quote

???

Last edited by Skyone on Wed Dec 23, 2009 9:08 am; edited 7 times in total
Back to top
View user's profile Send private message AIM Address MSN Messenger
h4c0r-BG
Master Cheater
Reputation: 0

Joined: 29 Nov 2006
Posts: 449
Location: The yogurt country

PostPosted: Sat Apr 04, 2009 10:12 am    Post subject: Reply with quote

Have tried:

GetExitCodeThread(cr_handle,259)
or
GetExitCodeThread(cr_handle,$259)

but my process still gets terminated like .. after ~5 seconds.

_________________

Back to top
View user's profile Send private message
Skyone
Grandmaster Cheater
Reputation: 0

Joined: 10 Sep 2006
Posts: 508

PostPosted: Sat Apr 04, 2009 10:26 am    Post subject: Reply with quote

???

Last edited by Skyone on Wed Dec 23, 2009 9:08 am; edited 7 times in total
Back to top
View user's profile Send private message AIM Address MSN Messenger
h4c0r-BG
Master Cheater
Reputation: 0

Joined: 29 Nov 2006
Posts: 449
Location: The yogurt country

PostPosted: Sat Apr 04, 2009 10:42 am    Post subject: Reply with quote

I don't get it... my application terminates without any errors. :S

I use my "thread check" code in a dll file. I inject that dll in a process ... the process terminates like ~ after 5-6 seconds without any errors.

Will be glad to hear some more ideas and will continue to investigate where is the problem.

_________________

Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Sat Apr 04, 2009 1:19 pm    Post subject: Reply with quote

should be relatively easy to convert to delphi...

Code:

__checkreturn BOOL ThreadStillExists(__in ULONG_PTR ProcessId,__in ULONG_PTR ThreadId)
{
   BOOL tB = false;
   HANDLE hSnapShot = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD,ProcessId);
   THREADENTRY32 TE;
   TE.dwSize = sizeof( THREADENTRY32 );
   tB = Thread32First( hSnapShot,&TE );
   if(!tB)
   {
      return FALSE;
   }
   else
   {
      if(TE.th32OwnerProcessID == ProcessId && TE.th32ThreadID == ThreadId)
      {
         return TRUE;
      }
      while( Thread32Next( hSnapShot,&TE ) != false)
      {
         if(TE.th32OwnerProcessID == ProcessId && TE.th32ThreadID == ThreadId)
         {
            return TRUE;
         }
      }
   }
   return FALSE;
}


oh and you should probably post the rest of your code so that we can look it over to help you with the error Wink

kind regards BanMe

_________________
don't +rep me..i do not wish to have "status" or "recognition" from you or anyone.. thank you.
Back to top
View user's profile Send private message MSN Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sat Apr 04, 2009 1:34 pm    Post subject: Reply with quote

You can use WaitForSingleObject() with a timeout of 0, and check the appropriate return value. Or if you want to wait until the thread exits before continuing, use a timeout of INFINITE.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites