[help] small problem with my memory scanner menu

Shout-Out

User Tag List

Results 1 to 12 of 12
  1. #1
    anon145236's Avatar Private
    Reputation
    1
    Join Date
    Oct 2011
    Posts
    9
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    EDIT: Removed

    EDIT: Removed
    Last edited by anon145236; 02-22-2012 at 09:51 AM. Reason: EDIT: Removed

    [help] small problem with my memory scanner
  2. #2
    namreeb's Avatar Legendary

    Reputation
    668
    Join Date
    Sep 2008
    Posts
    1,029
    Thanks G/R
    8/222
    Trade Feedback
    0 (0%)
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by anon145236 View Post
    hi folks,

    i wrote a memory scanner for wow which searches for a uint32 value (searchValue). i placed excactely 1589 searchValues in wows memory and then scanned for it. instead of 1589 pointers, my scanner delivers 1590 pointers. when i scan with cheatengine i receive the correct amout. so why does my scanner has has one result too much?

    i already tried to store my results as keyvalues in a dictionary and .. i got no exception, which means that all found pointers are unique keys ?!... so there shouldnt be any redundant pointers withing my result list ... but that would mean, that my scanner finds more searchValues in memory than cheatEngine does ... and guess what ... i believe the error lies in my source


    Code:
    public List<IntPtr> Int32Scanner(uint searchValue, Int32 startAddress, Int32 endAddress)
    {
    int bytesRead;
    int bufferSize = 20480;
    Int32 currentAddress = startAddress;
    List<IntPtr> results = new List<IntPtr>();
    int searchAreaSize = endAddress - startAddress;
    
    if (searchAreaSize >= bufferSize)
    {
        int numberOfLoops = searchAreaSize/bufferSize;
    
        for (int i = 0; i < numberOfLoops; i++)
        {
            var buffer = ReadMemoryAtAddress((IntPtr)currentAddress, (uint)bufferSize, out bytesRead);
    
            if (bytesRead > 0)
            {
                for (int j = 0; j < buffer.Length; j=j+8)
                {
                    if (BitConverter.ToUInt32(buffer, j).Equals(searchValue))
                    {
                        results.Add((IntPtr)(currentAddress + j));
                    }
                }
            }
            currentAddress += bufferSize;
        }
    
    }
    
    if (endAddress - currentAddress >= 0x4)
    {
        var buffer = ReadMemoryAtAddress((IntPtr)currentAddress, (uint)(endAddress - currentAddress), out bytesRead);
        if (bytesRead > 0)
        {
            for (int i = 0; i < buffer.Length; i=i+8)
            {
                if (BitConverter.ToUInt32(buffer, i).Equals(searchValue))
                    results.Add((IntPtr)(currentAddress + i));
            }
        }
    }
    
    MessageBox.Show(results.Count.ToString());  // returns:  1590
    
    return results;
    }
    hope you can help
    A couple of thoughts after a quick glance here. Firstly, I am surprised you are getting a result close to what you expect. You are stepping your search address by 8, instead of 4. Unless I'm crazy, this means you're skipping at least half of the possible locations. Secondly, I think that second if should be an else if. It looks as though you may be counting the same things twice. If it were me, I would redesign the first loop to work for all cases. It will run much faster if you locally buffer the data you're searching through.

  3. #3
    anon145236's Avatar Private
    Reputation
    1
    Join Date
    Oct 2011
    Posts
    9
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    EDIT: Removed
    Last edited by anon145236; 02-22-2012 at 09:49 AM. Reason: EDIT: Removed

  4. #4
    Bananenbrot's Avatar Contributor
    Reputation
    153
    Join Date
    Nov 2009
    Posts
    384
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok...

    1.) That's nonsense... even if you count in alignment, a struct with 3 pointers would be 16 bytes at max, and there would be pointers at j+4.

    2.) it's performance wise perfectly possible, you can either load all bytes at once (just give it a try, if you have enough ram to spare this is the best solution)
    or you do it like
    Code:
    while (currentAddress < endAddress)
    {
    int memoryRange = endAddress - currentAddress;
    int toRead = Math.Min(memoryRange, YourConstantBufferSize);
    byte[] buffer = ReadBytesAtAddress(currentAddress, toRead);
    // process buffer
    currentAddress += toRead;
    }
    Might be horrible mistakes in there, but you'll get it if you read it.
    For "stunning performance" you could even stackalloc that buffer, because your buffer size is already constant by definition.
    Last edited by Bananenbrot; 11-26-2011 at 05:39 AM.

  5. #5
    anon145236's Avatar Private
    Reputation
    1
    Join Date
    Oct 2011
    Posts
    9
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    EDIT: Removed
    Last edited by anon145236; 02-22-2012 at 09:49 AM. Reason: EDIT: Removed

  6. #6
    _Mike's Avatar Contributor
    Reputation
    310
    Join Date
    Apr 2008
    Posts
    531
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Bananenbrot View Post
    2.) it's performance wise perfectly possible, you can either load all bytes at once (just give it a try, if you have enough ram to spare this is the best solution)
    Copying memory is never good for performance. The best* way is to create a scanning thread within wow's address space. Or if you are willing/able to write a kernel driver**, map wow's address space in to your own.
    And before anyone claims the above to be overkill for a simple scanner.. Either you care about performance, and will do everything possible to maximize it. Or you don't care, and ReadProcessMemory()'ing 4 bytes at a time is acceptable. There is no middle ground imo

    *) best as in highest performance
    **) I don't think it's possible to do from user mode but I might be wrong

    Originally Posted by anon145236 View Post
    2.) i tried setting bufferSize to memoryRange( 0x7fffffff) and received an System.OutOfMemoryException despite i have 12gb of RAM
    Even if you could allocate that big of a buffer ReadProcessMemory() would fail. You can't read pages that doesn't exist.
    And no, you don't need all that redundant code. Bananenbrot's way is perfectly fine.

    even though i would love to simplify my code too, i think i have to stick on my "20480 bufferSize"-solution
    Again, you can't read pages that doesn't exist. Either blindly read just 1 at a time or make sure you can read them all first.
    Last edited by _Mike; 11-26-2011 at 07:52 PM.

  7. #7
    sitnspinlock's Avatar Elite User CoreCoins Purchaser
    Reputation
    398
    Join Date
    Sep 2010
    Posts
    439
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i take back what i said

    kestackattachprocess() too.

    though I don't know how else the second method you mention _mike would be possible, unless you were feeding the information back through an mj_read or an ioctl. nothing i know about at least
    Last edited by sitnspinlock; 11-26-2011 at 08:27 PM.

  8. #8
    _Mike's Avatar Contributor
    Reputation
    310
    Join Date
    Apr 2008
    Posts
    531
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by everdox View Post
    i take back what i said

    kestackattachprocess() too.

    though I don't know how else the second method you mention _mike would be possible, unless you were feeding the information back through an mj_read or an ioctl. nothing i know about at least
    I was thinking along the line of reversing how the memory manager works, and manually remap wow's pages in to both processes at once. I have no idea how to actually implement it, but now I feel like trying just for the fun of it

    At first I thought of using KeStackAttachProcess, but I can't think of a way to use it without doing unnecessary data copies.

  9. #9
    sitnspinlock's Avatar Elite User CoreCoins Purchaser
    Reputation
    398
    Join Date
    Sep 2010
    Posts
    439
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by _Mike View Post
    I was thinking along the line of reversing how the memory manager works, and manually remap wow's pages in to both processes at once. I have no idea how to actually implement it, but now I feel like trying just for the fun of it

    At first I thought of using KeStackAttachProcess, but I can't think of a way to use it without doing unnecessary data copies.
    you ever read windows internals 5th edition? the more i thought about this last night, i think it might be possible by walking the eprocess VAD tree in the same way it is to hide virtual pages.

    dunno but this might become a little christmas break project for me :O
    Last edited by sitnspinlock; 11-27-2011 at 03:22 PM.

  10. #10
    anon145236's Avatar Private
    Reputation
    1
    Join Date
    Oct 2011
    Posts
    9
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    EDIT: Removed
    Last edited by anon145236; 02-22-2012 at 09:49 AM. Reason: EDIT: Removed

  11. #11
    _Mike's Avatar Contributor
    Reputation
    310
    Join Date
    Apr 2008
    Posts
    531
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I only read through the code quickly so there might be things I've missed, but
    Code:
    currentAddress += (uint)mbi.BaseAddress + (uint)mbi.RegionSize;
    Is definitely wrong.
    Either assign (Base + Size), or increment by Size. Don't do both at the same time

  12. #12
    anon145236's Avatar Private
    Reputation
    1
    Join Date
    Oct 2011
    Posts
    9
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    EDIT: Removed
    Last edited by anon145236; 02-22-2012 at 09:49 AM. Reason: EDIT: Removed

Similar Threads

  1. [Help me]Problem with using function pointer in Debug builds
    By wanyancan in forum WoW Memory Editing
    Replies: 6
    Last Post: 01-06-2010, 05:06 AM
  2. (HELP) Login Problems with arcemu r429
    By Insignia in forum World of Warcraft Emulator Servers
    Replies: 5
    Last Post: 07-19-2008, 02:06 PM
  3. [c++] problem with reading memory
    By Lucani in forum WoW Memory Editing
    Replies: 3
    Last Post: 05-08-2008, 03:41 AM
  4. [Help Request]Problem with warglaives
    By m2]IceMan in forum WoW ME Questions and Requests
    Replies: 14
    Last Post: 02-21-2008, 03:21 PM
  5. Need help! got problem with Ascent.exe will +rep :P
    By Anthraxx in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 01-26-2008, 10:12 AM
All times are GMT -5. The time now is 09:06 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search