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#] Scanning memory

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

Joined: 22 Jan 2015
Posts: 3

PostPosted: Thu May 21, 2015 7:18 am    Post subject: [C#] Scanning memory Reply with quote

I'm a very bad programmer, and I turned to scan a code signature

Code:
        public int findsignature(int PID, byte[] signature)
        {
            try
            {
                unsafe
                {
                    long MaxAddr = 0x7fffffff;
                    long Addr = (long)Process.GetProcessById(PID).Modules[0].BaseAddress;
                    MEMORY_BASIC_INFORMATION m;
                    var handle = OpenProcess(0x001F0FFF, false, PID);
                    m.BaseAddress = IntPtr.Zero;
                    m.RegionSize = IntPtr.Zero;
                    byte[] buffer;
                    while (Addr <= MaxAddr)
                    {
                        VirtualQueryEx(handle, (IntPtr)Addr, out m, (uint)Marshal.SizeOf(typeof(MEMORY_BASIC_INFORMATION)));
                        buffer = new byte[(long)m.RegionSize];
                        int dammy = 0;
                        ReadProcessMemory(handle, m.BaseAddress, buffer, (int)m.RegionSize, out dammy);
                        if (Addr == (long)m.BaseAddress + (long)m.RegionSize)
                            break;
                        int count = 0;
                        Addr = (long)m.BaseAddress + (long)m.RegionSize;
                        if (buffer.Length > signature.Length)
                        {
                            for (int i = 0; i < buffer.Length; i++)
                            {
                                if (buffer[i] == signature[0])
                                {
                                    for (int q = 0; q < signature.Length; q++)
                                    {
                                        try
                                        {
                                            if (buffer[i + q] == signature[q] || signature[q] == -1)
                                            {
                                                count++;
                                                if (count == signature.Length)
                                                {
                                                    return i + (int)m.BaseAddress;
                                                }
                                            }
                                            else
                                            {
                                                count = 0;
                                            }
                                        }
                                        catch { }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                return 0;
            }
            return 0;
        }


This code looks for very long signatures. Who can tell me how to do better? So he looked for the signature is correct, and could look for them on the type of string?
I am very grateful to all who help me.
Code should support the signature search of unknown bytes "??" .

Sorry for my English.
I used Google translator
Back to top
View user's profile Send private message
Nummer
How do I cheat?
Reputation: 0

Joined: 22 Jan 2015
Posts: 3

PostPosted: Mon May 25, 2015 3:19 pm    Post subject: Reply with quote

up..
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