why does this memory scanner crash?

This is a discussion on why does this memory scanner crash? within the C++ Programming forums, part of the General Programming Boards category; not sure why but this is crashing, its just scanning the current process for the char[], Code: #include "stdafx.h" #include ...

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

    why does this memory scanner crash?

    not sure why but this is crashing, its just scanning the current process for the char[],

    Code:
    #include "stdafx.h"
    #include <windows.h>
    #include <stdio.h>
    
    
    
    //const char findme[8] = "PRIVMSG";
    
    int _tmain(int argc, _TCHAR* argv[])
    {
      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);
    
      }
    
    	return 0;
    }
    thanks if you can help

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    You're not checking the return value of OpenProcess, which may have failed. Also regionp is used without being initialized.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    315
    Quote Originally Posted by oogabooga View Post
    You're not checking the return value of OpenProcess, which may have failed. Also regionp is used without being initialized.
    i know the process is a valid handle, what should i intialize regionp to mate

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    FYI, wrong section. For Windows programming, you should post in the Windows section. Furthermore, this is C, so if it were not for the fact that it is Windows programming, this should have gone into the C section.
    Putting things in the right section helps attract more people specialized to the subject and avoids annoying people who don't deal with the subject.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stringstream and memory crash
    By fx69 in forum C++ Programming
    Replies: 7
    Last Post: 02-17-2010, 03:42 PM
  2. Crash when freeing memory.
    By Hulag in forum C++ Programming
    Replies: 4
    Last Post: 05-13-2005, 12:44 PM
  3. Choosing A Scanner
    By golfinguy4 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 03-08-2004, 01:31 AM
  4. Scanner
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 12-23-2001, 11:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21