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 


[C#] Stuck writing a pointer scanner

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

Joined: 03 Feb 2010
Posts: 1

PostPosted: Tue Aug 06, 2013 9:23 pm    Post subject: [C#] Stuck writing a pointer scanner Reply with quote

I started writing a simple pointer scanner in C#. It is not exactly a C# question, more like a VirtualQueryEx / pointers in general question. I followed this: pinvoke.net/default.aspx/kernel32/VirtualQueryEx to try and find a list of all addresses in any program, like CE can do. So far my code is pretty much the same as in the link:

Code:
        private void newScan()
        {
            long MaxAddress = 0x7fffffff;
            long address = 0;
            List<memTest> memTests = new List<memTest>();

            do
            {
                MEMORY_BASIC_INFORMATION m;
                int result = VirtualQueryEx(StaticValues.SelectedProcess.Handle, (IntPtr)address, out m, (uint)Marshal.SizeOf(typeof(MEMORY_BASIC_INFORMATION)));

                memTests.Add(new memTest() { BaseAddress = m.BaseAddress, EndAddress = (uint)m.BaseAddress + (uint)m.RegionSize - 1, RegionSize = m.RegionSize, Result = result });

                if (address == (long)m.BaseAddress + (long)m.RegionSize)
                    break;
                address = (long)m.BaseAddress + (long)m.RegionSize;
            } while (address <= MaxAddress);
        }


The only exeption is, I use windows forms and add the result to a list instead of printing it to the console. Just to add everything, here is the object I use to create the list:

Code:
    public class memTest
    {
        public IntPtr BaseAddress;
        public uint EndAddress;
        public IntPtr RegionSize;
        public int Result;
    }


Now, this solution finds the first address just fine (I use CE to test this). To make an example, I am scanning my sound card, which has the base address of 0x570000 right now, this is the same in both my program and CE. Now, if I take the next region/base address my program finds it is 0x571000, which doesn't exist according to CE.

EDIT:
I am using a 64-bit windows 8 and the application I am testing is 64-bit. I tried earlier with a 32-bit application and that did not work at all, just ended up with an infinite loop.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Wed Aug 07, 2013 2:24 am    Post subject: Reply with quote

VirtualQueryEx also returns unallocated memory regions, so check if it is committed or not
Also, in visual c++ a long is only 32-bit

_________________
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
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