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 


Slow Scans <---

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Thu Dec 23, 2010 1:11 pm    Post subject: Slow Scans <--- Reply with quote

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().

p.s I got my pointer scanner done ^_^

For instance:

Code:

template <class T> struct TMEMORY
{
   T Value;
   DWORD dwBaseAddr;
   DWORD dwEndAddr;
};

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

CreateThread (NULL, NULL, (LPTHREAD_START_ROUTINE) RunScan <T>, ?, NULL, NULL);



Here is my current code:

Code:

template <class T> 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 <T> (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 <T> (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 ();
   }
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25806
Location: The netherlands

PostPosted: Thu Dec 23, 2010 1:32 pm    Post subject: Reply with quote

read_for_except
If I understand the name correctly that routine is enclosed in an exception handler. Setting up and cleaning up an exception handler is slow, try to set it up only once and only on important places (e.g if address 0x00400001 is unreadable, you can be sure that 00400002 is unreadable and 004000fff is unreadable as well)

also, File << (LPVOID) addr << endl; is slow as well
converting a pointer to a string and then append the endline characters to it

I'd say that not converting it to text and just save the 32-bits to the file is smaller AND faster

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Thu Dec 23, 2010 2:06 pm    Post subject: Reply with quote

@Dark Byte

Your right, this is read_for_except:

Code:

template <class T> int read_for_except (DWORD dwAddr, T Value)
{
   __try
   {
      if( read_addr <T> (dwAddr) == Value )
      {
         return 0;
      }
      else
      {
         return 1;
      }
   }
   __except ( true )
   {
      return 2;
   }
}


But you never know when an address becomes unreadable, so staying on the safe side, is okay, right? Should I use VirtualProtect on each region to see if its readable or not, doesn't VirtualQuery tell me which region is readable, and if thats the case I shouldn't encounter addresses like 0x00400001, unless, the region is readable but some addresses inside arn't. While i'm reading the region in my for () loop, should I use VirtualProtect instead of read_for_except to make sure i'm going to be reading a readable address?

About your writing theory, should I do:

Code:

// convert dword to text
string str;

stringstream ss;
ss << dwItem;
str += ss.str();
str += '\n';

// Save it to file
File << str;
Back to top
View user's profile Send private message MSN Messenger
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Thu Dec 23, 2010 4:00 pm    Post subject: Reply with quote

Just wrap the loop calling that function in the exception handling code and remove the code from within the function. ie. Hoist the exception handling code
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