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 


Why is my memory scanner not giving me "as many" r

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Ballesaft
How do I cheat?
Reputation: 0

Joined: 26 Apr 2014
Posts: 2

PostPosted: Sat Apr 26, 2014 4:15 pm    Post subject: Why is my memory scanner not giving me "as many" r Reply with quote

So i am trying to create a memory scanner like for example TSearch or Artmonkey for educational purposes and i find it a good task to improve my knowledge about memory, anyways i have written the code below and it succesfully retrieves the chunks from memory and it is able to find some of the values i am scanning for, say i tell it to look for an int with a value of 34, well it finds 3 results, i mean thats all good Smile but the problem is that TSearch, Artmonkey and cheat engine are all able to find so much more, i only get about 20-30% of the results that other memory scanners find, why is this ? i was hoping someone could help me with this Razz i have tried different solutions like changing the region protection filters, only looking at memory with MEM_COMMIT etc.. but i always get the same amount of data and variables :/

i also run it all in an elevated process with debug privileges aswell :S so i really don't know and any help would be appreciated.

Code:
Code:

    int id, val, current;
   DWORD current_loc = 0;
   std::vector<MATCH> vals;
   std::vector<BLOCK> blocks;
   std::string option;

   printf("Enter Identifier: ");
   std::cin >> id;

   HANDLE pHandle = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, id);

   if(pHandle != NULL) {
      printf("Enter value to look for: ");
      std::cin >> val;
   }

   SYSTEM_INFO si;
   MEMORY_BASIC_INFORMATION mem_info;
   ZeroMemory(&mem_info, 0x0);
   GetSystemInfo(&si);

   while(current_loc < (DWORD)si.lpMaximumApplicationAddress) {
      if(VirtualQueryEx(pHandle, (void*) current_loc, &mem_info, sizeof(MEMORY_BASIC_INFORMATION))) {
         if(mem_info.Protect != 0 && mem_info.Protect != 0x01) {
            BLOCK CurrentBlock = DATABLOCK(mem_info);
            blocks.push_back(CurrentBlock);
         }

         current_loc += mem_info.RegionSize;
      }
   }

   for(BLOCK block : blocks) {
      block.buffer = new BYTE[block.size];
      ReadProcessMemory(pHandle, (void*) block.loc, block.buffer, block.size,  NULL);

      for(int i = 0; i < block.size; i++) {
         if(memcmp(&block.buffer[i], &val, sizeof(int)) == 0) {
            MATCH current_match;

            current_match.loc = block.loc + i;
            current_match.val = (int) block.buffer[i];

            vals.push_back(current_match);
         }
      }
   }


ohh and here are some structures i created just to simplify it Smile might come in handy aswell ^^
Code:

    typedef struct MATCH {
        int val;
        DWORD loc;
    } MATCH;
   
    typedef struct BLOCK {
        DWORD loc;
        int size;
        BYTE* buffer;
    } BLOCK;
Back to top
View user's profile Send private message
DTeCH
Newbie cheater
Reputation: 0

Joined: 19 Jul 2013
Posts: 23
Location: Cayman Islands

PostPosted: Mon Apr 28, 2014 4:39 am    Post subject: Reply with quote

This may sound cheesy but, step through slowly near the end, & see where it stops looping through the process's "pages", & make sure you're going through all detected memory total to be scanned. Avoid all that will not be scanned/filtered out.

In my scanners (The fastest I've ever seen lol... honest!) , just before the loop to do the filtering + scanning (Assuming your coding is similar to mine), do a quick duplicate loop that just adds all the wanted memory page's sizes you want together, & skip over the ones you don't... no other code, just set a TotalKnownBytesToScan variable to use in the next main loop. When you get your total, make sure you add each byte scanned in the next main filtering + scanning loop in every cycle... including all error traps, skips, jumps + whatever. Make sure ALL routes to the loop next adds to this variable before continuing next loop cycle. Continue until your added total >= TotalKnownBytesToScan variable from the first short loop.

You might want to put a breakpoint on a temp line that checks to see if "CurrentBytesScanned >= TotalKnownBytesToScan" just to see if it ever gets hit. If not, then your code is falling short somewhere, & if that's the case, check to see if any variable has a minus "-" sign at the left of it. that minus sign means different things in the eyes of different calculation functions under the hood. In one case it's an overflow, in another case it's a signed int. IntPtr likes to assume different variable types based on whether it's running in 32, or 64 bit mode, & this alone can cause the infamous "-" to appear in the variables. Just to be safe, place a breakpoint on a temp line that will break somewhere inside your detected "possible matching address" checking function call (or loop), & visualize what's being checked, & compared... just to make sure the code is doing exactly what you expect. Sleep is killing me right now, so I'll return later if God's willing, & tidy this post up a bit. Razz

ps: Pretend my spelling is awesome! lol Very Happy

_________________
Hitler... When all else fails, you'll be in the right state of mind. Jesus Saves.
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
Ballesaft
How do I cheat?
Reputation: 0

Joined: 26 Apr 2014
Posts: 2

PostPosted: Tue Apr 29, 2014 9:43 am    Post subject: Thanks Reply with quote

Thank you for your reply, i did as u said and created a variable with the total size of all the pages in memory when added together, i found something weird tho Smile the total bytes of all pages all together is only 250kb of a process that task manager says is using 6080kb, so im clearly not fetching all pages or memory that i am supposed to Wink my loops are working fine and scans all the fetched memory, im just having a problem with fetching it all, maybe there is something wrong with my filtering ? Razz ima look into the filters a litlle, feel free to reply if u have any ideas, even the slightest detail or idea u guys have is worth sharing.

best regards.
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