Slow Scans <---

On lunes, 27 de diciembre de 2010 0 comentarios

by iPromise

I'm writing all my information into a buffer, and when the scan is finished I add the items into the listbox. Everything works but, when scanning a process that is very big, and not knowing where the address your looking for's region is, i'm going to have a big problem. I tried creating a thread for each region that I find which is readable but I can't pass on the T class, the structure or the value in CreateThread().


For instance:


Code:

template struct TMEMORY
{
   T Value;
   DWORD dwBaseAddr;
   DWORD dwEndAddr;
};

template void RunScan (TMEMORY *szMemInfo, T Value);

CreateThread (NULL, NULL, (LPTHREAD_START_ROUTINE) RunScan , ?, NULL, NULL);



Here is my current code:

Code:

template void Scan ( T Value )
   {
      SendMessageA (GetDlgItem (hWnd, IDC_LIST1), LB_RESETCONTENT, NULL, NULL);

      ofstream File ("C:\\File.txt");
      File.clear ();

      bool Fast = ( SendMessageA (GetDlgItem(hWnd, IDC_CHECKBOX1), BM_GETCHECK, 0, 0) == BST_CHECKED ) ? true : false;
      bool Slow = ( SendMessageA (GetDlgItem(hWnd, IDC_CHECKBOX2), BM_GETCHECK, 0, 0) == BST_CHECKED ) ? true : false;

      DWORD dwStartAddr = GetCurSel_2 (IDC_EDIT2);
      DWORD dwStopAddr  = GetCurSel_2 (IDC_EDIT3);

      for ( DWORD i = dwStartAddr;
                 i < dwStopAddr;
               i ++ )
      {
         MEMORY_BASIC_INFORMATION MBI = {0};
         VirtualQuery ((LPCVOID) i, &MBI, sizeof (MEMORY_BASIC_INFORMATION));

         if ( Fast )
         {
            if ( ( MBI.State == MEM_COMMIT ) &&
                ( MBI.Type  == MEM_PRIVATE ) &&
                ( MBI.RegionSize > 0 ) )
            {
               DWORD dwEndAddr = ( (DWORD) MBI.BaseAddress + (DWORD) MBI.RegionSize ) - 1 - sizeof (T);

               for ( DWORD addr = (DWORD) MBI.BaseAddress;
                        addr < (DWORD) dwEndAddr;
                        addr ++ )
               {
                  int read = read_for_except (addr, Value);

                  if ( read == 0 )
                  {
                     File << (LPVOID) addr << endl;
                  }
                  else if ( read == 2 )
                  {
                     addr = dwEndAddr;
                  }
               }

               i += (DWORD) MBI.RegionSize;
            }
            else
            {
               i += (DWORD) MBI.RegionSize;
            }
         }

         if ( Slow )
         {
            if ( ( MBI.Protect == PAGE_READWRITE ) &&
                ( MBI.RegionSize > 0 ) )
            {
               DWORD dwEndAddr = ( (DWORD) MBI.BaseAddress + (DWORD) MBI.RegionSize ) - 1 - sizeof (T);

               for ( DWORD addr = (DWORD) MBI.BaseAddress;
                        addr < (DWORD) dwEndAddr;
                        addr ++ )
               {
                  int read = read_for_except (addr, Value);

                  if ( read == 0 )
                  {
                     File << (LPVOID) addr << endl;
                  }
                  else if ( read == 2 )
                  {
                     addr = dwEndAddr;
                  }
               }

               i += (DWORD) MBI.RegionSize;
            }
            else
            {
               i += (DWORD) MBI.RegionSize;
            }
         }
      }

      File.close ();

      ifstream Read ("C:\\File.txt");

      while ( !Read.eof() )
      {
         LPVOID lpAddress;

         Read >> lpAddress;

         add_to_list ((DWORD) lpAddress, hWnd);
      }

      Read.close ();

      ObtainResults ();
   }
                

0 comentarios:

Publicar un comentario