Knowing process' memory range menu

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    devouredelysium's Avatar Member
    Reputation
    1
    Join Date
    Jun 2009
    Posts
    8
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Knowing process' memory range

    Hello.

    Anyone knows if it is possible to get the memory range of an arbitrary process? This is, I know we can search from 0x400000 to 0x7FFF0000 by brute force, but many of this space will return bad results from ReadProcessMemory, so I'd like to know if it's possible to programatically get the defined range, so I can use it. I've been trying to use the ProcessModuleCollection collection off the Process class (in .net) but it does not seem to cover the whole range of memory of the programs. Any help?

    Knowing process' memory range
  2. #2
    Nesox's Avatar ★ Elder ★
    Reputation
    1280
    Join Date
    Mar 2007
    Posts
    1,238
    Thanks G/R
    0/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Entry of the first module - End of last module

  3. #3
    Bobbysing's Avatar Member
    Reputation
    192
    Join Date
    Jan 2009
    Posts
    36
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'd rather want to use VirtualQueryEx as it also tells you about pages outside of the modules.

  4. #4
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Call GetSystemInfo to get the minimum and maximum addresses, along with the page size. Then call VirtualQuery(Ex) beginning at the minimum and up to the maximum, adding region size at each loop iteration.

  5. #5
    devouredelysium's Avatar Member
    Reputation
    1
    Join Date
    Jun 2009
    Posts
    8
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello. Thanks for the answers. From what I see, GetSystemInfo will get me the minimum and maximum addresses. Now what I do not understand is what VirtualQueryEx will do here.

    a) Is it correct to assume that all the memory from the minimum to the maximum addresses returned by GetSystemInfo will be used by the process?
    b) If yes, then why would I use VirtualQueryEx?

    What do you mean by adding region size at each loop iteration?

    Thanks

  6. #6
    amadmonk's Avatar Active Member
    Reputation
    124
    Join Date
    Apr 2008
    Posts
    772
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by devouredelysium View Post
    Hello. Thanks for the answers. From what I see, GetSystemInfo will get me the minimum and maximum addresses. Now what I do not understand is what VirtualQueryEx will do here.

    a) Is it correct to assume that all the memory from the minimum to the maximum addresses returned by GetSystemInfo will be used by the process?
    Most emphatically, no.

    Originally Posted by devouredelysium View Post
    b) If yes, then why would I use VirtualQueryEx?

    What do you mean by adding region size at each loop iteration?

    Thanks
    VirtualQueryEx needs to be "walked upwards" through memory to give a complete block accounting of allocated memory. You'll have to read the MSDN docs for the API to understand it. Experiment a bit on your own process, and you'll see all kinds of little blocks allocated for various PE sections, heap, and so on.

    The only guaranteed-to-be-allocated contiguous block of memory in a process is a block returned by VQE. Processes do not have solid walls of memory; they have numerous little chunks of address space stitched together by the virtual memory manager. Cypher's method of determining valid memory is the only correct one. Actually you can skip the call to GetSystemInfo if you're lazy, since VQE will show you what's valid and what's not (but you may end up querying more than you need to, if you do).
    Don't believe everything you think.

  7. #7
    devouredelysium's Avatar Member
    Reputation
    1
    Join Date
    Jun 2009
    Posts
    8
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah. Thanks, that what I needed to know. I'll now try to work out the code.

    edit: Well, aren't the pages VirtualQueryEx returns the same as the ProcessModule object that the Process class returns?
    edit2: Well, now that I've searched it on MSDN, http://msdn.microsoft.com/en-us/libr...s.modules.aspx , they seem to be clearly different things.
    Last edited by devouredelysium; 06-08-2009 at 02:45 PM.

  8. #8
    amadmonk's Avatar Active Member
    Reputation
    124
    Join Date
    Apr 2008
    Posts
    772
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    They are related, but not the same.

    Loaded modules use memory blocks allocated by the virtual memory system (which VQE will show), but there are other blocks (notably heap, but there are others) that are not part of modules at all.
    Don't believe everything you think.

  9. #9
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by amadmonk View Post
    Most emphatically, no.



    VirtualQueryEx needs to be "walked upwards" through memory to give a complete block accounting of allocated memory. You'll have to read the MSDN docs for the API to understand it. Experiment a bit on your own process, and you'll see all kinds of little blocks allocated for various PE sections, heap, and so on.

    The only guaranteed-to-be-allocated contiguous block of memory in a process is a block returned by VQE. Processes do not have solid walls of memory; they have numerous little chunks of address space stitched together by the virtual memory manager. Cypher's method of determining valid memory is the only correct one. Actually you can skip the call to GetSystemInfo if you're lazy, since VQE will show you what's valid and what's not (but you may end up querying more than you need to, if you do).
    Afaik you still need GetSystemInformation if you want to get the correct page size for the machine. (I'm a portability nazi when it comes to Windows programming :P)

  10. #10
    devouredelysium's Avatar Member
    Reputation
    1
    Join Date
    Jun 2009
    Posts
    8
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks all, did the library in c# and to my surprise it does not look slower than MHS.

  11. #11
    amadmonk's Avatar Active Member
    Reputation
    124
    Join Date
    Apr 2008
    Posts
    772
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cypher View Post
    Afaik you still need GetSystemInformation if you want to get the correct page size for the machine. (I'm a portability nazi when it comes to Windows programming :P)
    Bah. Pages will always be 4k in my book.

    Are we using larger pages anywhere for reals now?

    (Edit: oh, I forgot about the large pages in the kernel. But still... that's the kernel...)
    Last edited by amadmonk; 06-09-2009 at 03:21 PM.
    Don't believe everything you think.

  12. #12
    amadmonk's Avatar Active Member
    Reputation
    124
    Join Date
    Apr 2008
    Posts
    772
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by devouredelysium View Post
    Thanks all, did the library in c# and to my surprise it does not look slower than MHS.
    I don't know where everyone got this built-in belief that C# is always slow. Sometimes it is (especially in situations where the GC is super-active), but usually it's comparable to C/C++ speeds (the JIT'ter/NGEN really does work, honest).

    In fact, IIRC, IronPython (the .Net-bound Python flavor) actually outperforms CPython (the native C Python flavor) on a number of benchmarks. I think that the garbage collection sometimes frees cycles during execution (allows for "lazy" cleanups rather than being "correct" in C/C++ with free/delete). Resource cleanup can be expensive, so this means that your slowdowns happen after all the excitement is over, not during the action -- which can, in some circumstances, dramatically speed up execution times.

    Of course, you could write C++/asm/whatever to do this too, but the point is: don't just assume something will be slow (or fast). Try it, benchmark it, and then see if it's fast enough for your purposes.
    Last edited by amadmonk; 06-09-2009 at 03:22 PM.
    Don't believe everything you think.

  13. #13
    devouredelysium's Avatar Member
    Reputation
    1
    Join Date
    Jun 2009
    Posts
    8
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I have experience in a lot of cases where i have similar c++/c# codes and c++ is way faster than c#, just that.

  14. #14
    amadmonk's Avatar Active Member
    Reputation
    124
    Join Date
    Apr 2008
    Posts
    772
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, there are definitely cases where C++ outperforms C#. In fact, given all else equal, and given tests that don't emphasize the benefits of garbage collection, C++ should usually outperform C#. But not usually by much (it depends), and not always. Plus the ease-of-development/prototyping in C# (for me) far outweighs the gain of a few milliseconds that I'll never see because it's eaten up in an input processing loop somewhere.

    But, to each his own. I know that to C++ purists like Cypher, even mentioning scripting/VM languages is nearly heresy...
    Don't believe everything you think.

  15. #15
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by amadmonk View Post
    Bah. Pages will always be 4k in my book.

    Are we using larger pages anywhere for reals now?

    (Edit: oh, I forgot about the large pages in the kernel. But still... that's the kernel...)
    AMD64? Itanium? I like to write architecture portable code if at all possible. It's certainly saved me a SHITTON of work recently now that I've been doing lots of native AMD64 programming.

    It's also great to do because you learn what to avoid, the correct way to do things, etc. and shield yourself from other potential problems.

    Plus, I can annoy people by pointing out hundreds of potential portability problems in their code bases.

Page 1 of 2 12 LastLast

Similar Threads

  1. In process memory reading/writing
    By unbekannt1 in forum WoW Memory Editing
    Replies: 7
    Last Post: 06-08-2010, 06:52 PM
  2. PyMem - Python process memory editing
    By nopz in forum WoW Memory Editing
    Replies: 5
    Last Post: 05-09-2010, 05:01 AM
  3. PyMem - Python process memory editing
    By nopz in forum Programming
    Replies: 5
    Last Post: 03-25-2010, 03:47 AM
  4. [Release][C#] In/Out of Process Memory Class
    By Apoc in forum WoW Memory Editing
    Replies: 9
    Last Post: 03-11-2010, 03:17 AM
  5. a little bit of c++ and reading process memory..
    By arynock in forum WoW Memory Editing
    Replies: 10
    Last Post: 05-22-2008, 04:12 AM
All times are GMT -5. The time now is 02:47 PM. 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