Thread: search for a string the process help

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    319

    search for a string the process help

    This code seems to be crashing , can anyone help why

    Code:
    #include <windows.h>
    #include <stdio.h>
    
    
    
    //const char findme[8] = "PRIVMSG";
    
    int main()
    {
      HANDLE ThisProc = OpenProcess(PROCESS_ALL_ACCESS,true,GetCurrentProcessId());
      MEMORY_BASIC_INFORMATION mbi;
      SYSTEM_INFO si; 
      GetSystemInfo(&si);
      DWORD dwStart = 0;
      SIZE_T v;
      char *p;
      DWORD lpRead;
      const char* regionp;
      BYTE s = 't';
      char *memchrp;
      int memcmpr;
      const char findme[8] = "PRIVMSG";
      HANDLE Term;
    
     while(dwStart < (DWORD)si.lpMaximumApplicationAddress)
      {
    								
         v = VirtualQueryEx(ThisProc,
                     (void *)dwStart,
                                &mbi,
    sizeof(MEMORY_BASIC_INFORMATION));
    
    	 if(v == 0)
    	 {
    		printf("%s\n","breaking");
    		break;
    	 }
    	 
    
    	 if(mbi.State == MEM_COMMIT)
    	 {
    	     printf("%s\n","mem_commit");
    		 p = (char *)malloc(mbi.RegionSize);
    
    	
    
    		 printf("Memory at %02x, size %d\n",
                      mbi.BaseAddress,
                       mbi.RegionSize);
                
    		 if(ReadProcessMemory(ThisProc,(void *)dwStart,p,mbi.RegionSize,&lpRead))
             {
    			 
    			 	const char* offset = regionp;
    				while ((offset = (const char*)memchr(offset, findme[0], regionp+mbi.RegionSize-offset)) != 0)
    				{
    			
    					
    					if (memcmp(offset, findme, 7) == 0) 
    					{
    						   printf("%s\n","found");
    					       Sleep(5000);
    						   break;
    					}
    					
    					   
    					   ++offset;
    				}
    			
    
    		 }
    	 }
    
    	 if(dwStart + mbi.RegionSize < dwStart)
    	 {
    		printf("%s\n","breaking");
    		 break;
    	 }
    	    
    	 if(mbi.RegionSize != lpRead)
         {
             printf("Not enough bytes read %d != %d\n",mbi.RegionSize,lpRead);
        }
            
    	 dwStart += mbi.RegionSize;
    
    	
    
    	Sleep(5);
    
      }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Run it in the debugger, then it will at least show you which line is causing the problem.

    Oh, and you need to work on your indentation skills as well, if you want people to read your code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    while ((offset = (const char*)memchr(offset, findme[0], regionp+mbi.RegionSize-offset)) != 0)

    this is the line it crashs on

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Yeah, and to what does regionp (and offset) point?

  5. #5

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    Quote Originally Posted by rags_to_riches View Post
    Yeah, and to what does regionp (and offset) point?
    not sure

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you help me about tolower() in file
    By nctar in forum C Programming
    Replies: 7
    Last Post: 05-12-2010, 10:04 AM
  2. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  3. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  5. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM