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 


picking up new processes
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Thu May 15, 2008 8:45 am    Post subject: Reply with quote

The refresh button is the concept you want. Create a thread or timer to constantly call the function you use to pull the process list. Send the clear message before updating and such. (Protip: Common sense works well when programming.. >.>)

And no, your example isn't 'correct' for EnumProcesses. EnumProcesses returns the process ids in an array, if you want to display them you need to print them out into a string buffer before sending them to the listbox.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu May 15, 2008 8:57 am    Post subject: Reply with quote

Wiccaan wrote:
The refresh button is the concept you want. Create a thread or timer to constantly call the function you use to pull the process list. Send the clear message before updating and such. (Protip: Common sense works well when programming.. >.>)

And no, your example isn't 'correct' for EnumProcesses. EnumProcesses returns the process ids in an array, if you want to display them you need to print them out into a string buffer before sending them to the listbox.


Code:

DWORD epProcesses[1024], epByteRet, epNumProcesses;
EnumProcesses(epProcesses, sizeof(epProcesses), epByteRet);
epNumProcesses = epByteRet / sizeof(DWORD);
for(int i = 0; i<epNumProcess; i++) {
   char *sepProcesses[epNumProcesses];
   sepProcesses[i] = (char*)epProcesses[i];
   SendMessage(hList, LB_ADDSTRING, NULL, (LPARAM)sepProcesses[i]);
}


Why do I have a feeling that is wrong... Rolling Eyes

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Thu May 15, 2008 9:52 am    Post subject: Reply with quote

Something like this:

Code:
char szProcId[255] = {0};
sprintf_s( szProcId, 255, "%d", epProcesses[i] );
SendMessage( hList, LB_ADDSTRING, NULL, (LPARAM)szProcId );

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu May 15, 2008 4:02 pm    Post subject: Reply with quote

Wiccaan wrote:
Something like this:

Code:
char szProcId[255] = {0};
sprintf_s( szProcId, 255, "%d", epProcesses[i] );
SendMessage( hList, LB_ADDSTRING, NULL, (LPARAM)szProcId );


Code:

DWORD epProcesses[1024], epByteRet, epNumProcesses;
EnumProcesses(epProcesses, sizeof(epProcesses), epByteRet);
epNumProcesses = epByteRet / sizeof(DWORD);
for(int i = 0; i<epNumProcess; i++) {
   char pid[255];
   sprintf_s(pid, 255, "%d", epProcesses[i]);
   SendMessage(hList, WM_SETTEXT, NULL, (LPARAM)pid);
}

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Thu May 15, 2008 4:35 pm    Post subject: Reply with quote

x0r wrote:
Wiccaan wrote:
Or instead of including psapi (if you don't want to) you can call ZwQuerySystemInformation yourself with SystemProcessesAndThreadsInformation ( 5 ) to get the same result.

CreateToolhelp32Snapshot also calls ZwQuerySystemInformation as does EnumProcess, so you get the same results basically either way. One function offers more results then the other.

Without trying to be rude, that's incredibly stupid. You should never use undocumented APIs.

Anyway, a call to CreateToolhelp32Snapshot would take much more time than EnumProcesses and when you throw the process loop into it you're looking at a much slower result. The main point of EmunProcesses is to be much faster than the alternative.


ZwQuerySystemInformation is documented.
http://msdn.microsoft.com/en-us/library/ms725506(VS.85).aspx

Most if not all the NT API are documented, whether it be through MSDN, or other sites, there are lots of references to learn about them. Calling them just because you think they are undocumented is far from 'stupid' as they can do a lot in the means of hacking.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Thu May 15, 2008 5:00 pm    Post subject: Reply with quote

Wiccaan wrote:
x0r wrote:
Wiccaan wrote:
Or instead of including psapi (if you don't want to) you can call ZwQuerySystemInformation yourself with SystemProcessesAndThreadsInformation ( 5 ) to get the same result.

CreateToolhelp32Snapshot also calls ZwQuerySystemInformation as does EnumProcess, so you get the same results basically either way. One function offers more results then the other.

Without trying to be rude, that's incredibly stupid. You should never use undocumented APIs.

Anyway, a call to CreateToolhelp32Snapshot would take much more time than EnumProcesses and when you throw the process loop into it you're looking at a much slower result. The main point of EmunProcesses is to be much faster than the alternative.


ZwQuerySystemInformation is documented.
http://msdn.microsoft.com/en-us/library/ms725506(VS.85).aspx

Most if not all the NT API are documented, whether it be through MSDN, or other sites, there are lots of references to learn about them. Calling them just because you think they are undocumented is far from 'stupid' as they can do a lot in the means of hacking.


I think he might be referring to SystemProcessesAndThreadsInformation, I did a quick Google search, and nothing turned up immediately; that might be the reason that I don't see it though--I'm not too interested in seeing it. =P

Anyways, EnumProcesses, in my opinion, just seems like the way to go in this situation.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Thu May 15, 2008 5:25 pm    Post subject: Reply with quote

Quote:
The ZwQuerySystemInformation function and the structures that it returns are internal to the operating system and subject to change from one release of Windows to another. To maintain the compatibility of your application, it is better to use the alternate functions previously mentioned instead.

If you do use ZwQuerySystemInformation, access the function through run-time dynamic linking. This gives your code an opportunity to respond gracefully if the function has been changed or removed from the operating system. Signature changes, however, may not be detectable.

This function has no associated import library. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Ntdll.dll.

Just sayin

_________________
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Fri May 16, 2008 7:52 am    Post subject: Reply with quote

Bickering aside. What about the code. I have everything fine with enumprocesses as long as rewriting goes, and I'm pretty sure I can do the time. But how do I compare the process selected and the one I have. Watch:

Code:

void ListProcess() {
   DWORD epProcesses[1024], epByteRet, epNumProcesses;
   EnumProcesses(epProcesses, sizeof(epProcesses), &epByteRet);
   epNumProcesses = epByteRet/sizeof(DWORD);
   for(int i = 0; i<epNumProcesses; i++) {
      char pid[255];
      sprintf_s(pid, 255, "%d", epProcesses[i]);
      SendMessage(hList, LB_SETTEXT, NULL, (LPARAM)pid);
   }
}

BOOK PK(char *szExe) {
   DWORD pkProcesses, pkByteRet, pkNumProcesses;
   EnumProcesses(pkProcesses, sizeof(pkProcesses), &pkByteRet);
   pkNumProcesses = pkByteRet/sizeof(DWORD);
   for(int i = 0; i<pkNumProcesses; i++) {
      char PKid[255];
      sprintf_s(PKid, 255, "%d", pkProcesses[i]);
      if(strcmp(pid, szExe) == 0) {
         HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, NULL, PKid);
         TerminateProcess(hProcess, 0);
         CloseHandle(hProcess);
         return TRUE;
      }
      return FALSE;
   }
}

void GetIndexName() {
   char szExe[260];
   int index = SendMessage(hList, LB_GETCURSEL, NULL, NULL);
   if(index != LB_ERR) {
      SendMessage(hList, LB_GETTEXT, (WPARAM)index, (LPARAM)szExe);
      PK(szExe);
      SendMessage(hList, LB_DELETESTRING, (WPARAM)index, NULL);
   }
   else {
      MessageBox(NULL, "Couldn't kill process!", "Error!", MB_OK | MB_ICONEXCLAMATION);
   }
}


If you look at the PK function, I just realized that I'm comparing the process id (integer) to the process name (string). How am I supposed to get the process name into a variable?

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Zand
Master Cheater
Reputation: 0

Joined: 21 Jul 2006
Posts: 424

PostPosted: Fri May 16, 2008 9:11 am    Post subject: Reply with quote

The heck?

You can't do strcmp if one of the parameters is clearly not a string. You can get a PID from a process name but it isn't foolproof as some processes have the same names, etc.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Fri May 16, 2008 2:13 pm    Post subject: Reply with quote

Zand wrote:
The heck?

You can't do strcmp if one of the parameters is clearly not a string. You can get a PID from a process name but it isn't foolproof as some processes have the same names, etc.


Technically its numbers stored inside a string.

its as if I did

Code:

char pid[] = "1025";


But that's not my problem. I need to get the process name, and yea seeing as most of the system processes (as you mentioned) are run more than once (svchost.exe for example) I would get the same pid. Hmmm...seems like CreateToolhelp32Snapshot may be bettere? Rolling Eyes Oh yeah and can I get the process name like this?

Code:

char pname[255];
sprintf_s(pname, 255, "%s", epProcesses[i]);

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Fri May 16, 2008 2:51 pm    Post subject: Reply with quote

http://msdn.microsoft.com/en-us/library/ms684919(VS.85).aspx

QueryFullProcessImageName Function

Retrieves the full name of the executable image for the specified process.

Edit: i'm not sure about the support of this function so:

GetProcessImageFileName Function

Retrieves the name of the executable file for the specified process.

http://msdn.microsoft.com/en-us/library/ms683217(VS.85).aspx

_________________
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
Goto page Previous  1, 2
Page 2 of 2

 
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