Page 1 of 3 123 LastLast
Results 1 to 15 of 31
  1. #1
    Silent's Avatar
    Join Date
    Jan 2015
    Gender
    male
    Location
    Melbourne, Australia
    Posts
    5,070
    Reputation
    2172
    Thanks
    8,474
    My Mood
    Bitchy

    C# Memory class x86

    Hello MPGH, Today I'm going to be uploading a basic memory class for C# that I created in my spare time.

    Features:
    WriteBytes
    WriteByte
    WriteInt
    WriteString
    WriteFloat
    ReadBytes
    ReadByte
    ReadInt
    ReadString
    ReadString Advanced
    ReadFloat
    PatternScan


    Source:
    Code:
    using System;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    using System.Text;
     
    class Memory
    {
        private IntPtr pHandel = IntPtr.Zero;
        private Process attachedProcess = null;
        private byte[] buffer;
     
        public bool Open_pHandel(string processName)
        {
            Process[] proc = Process.GetProcessesByName(processName);
     
            if (proc.Length == 0)
                return false;
            else if (proc.Length > 1)
                throw new Exception("More then one process found.");
            else
            {
                attachedProcess = proc[0];
                pHandel = proc[0].Handle;
                return true;
            }
        }
     
        #region x86
        #region Write
        public bool WriteBytes(int address, byte[] value, bool virtualProtect = false)
        {
            int countOfUsed = 0;
            bool result = false;
            uint oldProtection = 0;
     
     
            if (virtualProtect)
                Win32.x86.VirtualProtectEx(pHandel, address, (uint)value.Length, 0x40, out oldProtection);
     
            result = Win32.x86.WriteProcessMemory(pHandel, address, value, (uint)value.Length, out countOfUsed);
     
            if (virtualProtect)
                Win32.x86.VirtualProtectEx(pHandel, address, (uint)value.Length, oldProtection, out oldProtection);
     
            return result;
        }
     
        public bool WriteInt(int address, int value, bool virtualProtect = false)
        {
            buffer = BitConverter.GetBytes(value);
            return WriteBytes(address, buffer, virtualProtect);
        }
     
        public bool WriteByte(int address, byte value, bool virtualProtect = false)
        {
            buffer = new byte[] { value };
            return WriteBytes(address, buffer, virtualProtect);
        }
     
        public bool WriteString(int address, string value, bool virtualProtect = false)
        {
            buffer = Encoding.ASCII.GetBytes(value);//No unicode support atm
            return WriteBytes(address, buffer, virtualProtect);
        }
     
        public bool WriteFloat(int address, float value, bool virtualProtect = false)
        {
            buffer = BitConverter.GetBytes(value);
            return WriteBytes(address, buffer, virtualProtect);
        }
        #endregion
        #region Read
        public byte[] ReadBytes(int address, int length)
        {
            byte[] readBytes = new byte[length];
            int numBytesChanged = 0;
     
            Win32.x86.ReadProcessMemory(pHandel, address, readBytes, (uint)length, out numBytesChanged);
     
            return readBytes;
        }
     
        public int ReadInt(int address)
        {
            return BitConverter.ToInt32(ReadBytes(address, 4), 0);
        }
     
        public byte ReadByte(int address)
        {
            return ReadBytes(address, 1)[0];
        }
     
        public string ReadString(int address, int length)
        {//No unicode support
            return Encoding.ASCII.GetString(ReadBytes(address, length));
        }
     
        public string ReadStringAdvanced(int address, int maxStringLength = 1000)
        {//No unicode support
            string result = null;
            byte currentByte = 0;
     
            for (int i = 0; i < maxStringLength; i++)
            {
                currentByte = ReadByte(address + i);
     
                if (currentByte == 0x00)
                    break;
                else
                    result += (char)currentByte;
            }
     
            return result;
        }
     
        public float ReadFloat(int address)
        {
            return BitConverter.ToSingle(ReadBytes(address, 4), 0);
        }
        #endregion
        #region Scans
        public int PatternScan(string pattern)
        {
            string[] splitPattern = pattern.Split(' ');
            bool[] indexValid = new bool[splitPattern.Length];
            byte[] indexValue = new byte[splitPattern.Length];
     
            byte tempByte = (byte)0x00;
     
            for (int i = 0; i < splitPattern.Length; i++)
            {
                indexValid[i] = !(splitPattern[i] == "??" || splitPattern[i] == "?");
                if (Byte.TryParse(splitPattern[i], out tempByte))
                    indexValue[i] = tempByte;
                else
                    indexValid[i] = false;
            }
     
            int startOfMemory = attachedProcess.MainModule.BaseAddress.ToInt32();
            int endOfMemory = attachedProcess.MainModule.ModuleMemorySize;
     
            for (int currentMemAddy = startOfMemory; currentMemAddy < endOfMemory; currentMemAddy++)
            {
                bool complete = false;
                for (int i = 0; i < splitPattern.Length; i++)
                {
                    if (!indexValid[i])
                        continue;
     
                    tempByte = ReadByte(currentMemAddy + i);
     
                    if (tempByte != indexValue[i])
                        break;
     
                    if (i == splitPattern.Length - 1)
                        complete = true;
     
                    if (complete)
                        break;
                }
     
                if (complete)
                    return currentMemAddy;
            }
     
            throw new Exception("Pattern not found!");
            return 0;
        }
        #endregion
        #endregion
     
        private static class Win32
        {
            public static class NativeMethods
            {
                #region IsWow64Process
                public static bool IsWow64Process(IntPtr handel)
                {
                    bool isTarget64Bit = false;
                    IsWow64Process(handel, out isTarget64Bit);
                    return isTarget64Bit;
                }
     
                [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
                [return: MarshalAs(UnmanagedType.Bool)]
                private static extern bool IsWow64Process([In] IntPtr process, [Out] out bool wow64Process);
                #endregion
            }
     
            public static class x64
            {
                [DllImport("kernel32.dll", SetLastError = true)]
                public static extern bool VirtualProtectEx(IntPtr hProcess, long lpAddress, UInt32 dwSize, uint flNewProtect, out uint lpflOldProtect);
     
                [DllImport("kernel32.dll")]
                public static extern bool ReadProcessMemory(IntPtr hProcess, long lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out int lpNumberOfBytesWritten);
     
                [DllImport("kernel32.dll")]
                public static extern bool WriteProcessMemory(IntPtr hProcess, long lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out int lpNumberOfBytesWritten);
            }
     
            public static class x86
            {
                [DllImport("kernel32.dll", SetLastError = true)]
                public static extern bool VirtualProtectEx(IntPtr hProcess, int lpAddress, UInt32 dwSize, uint flNewProtect, out uint lpflOldProtect);
     
                [DllImport("kernel32.dll")]
                public static extern bool ReadProcessMemory(IntPtr hProcess, int lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out int lpNumberOfBytesWritten);
     
                [DllImport("kernel32.dll")]
                public static extern bool WriteProcessMemory(IntPtr hProcess, int lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out int lpNumberOfBytesWritten);
            }
        }
    }
    usage:
    Code:
    if(Open_pHandel("processName"))
    {
         int address = PatternScan("02 255 12 41 ?? 54 ? 12 ? 52 ?? 23");
         WriteBytes(address, new byte[] {0x00, 0x00});
    }
    Midway typing this I noticed I left the gas on, on the stove and I got a massive headache xd whoops

    Features I will add later:
    x64 support.
    idk what else


    Press thanks if this helps you!
    Last edited by Hero; 02-03-2017 at 08:13 PM.
    Click Here to visit the official MPGH wiki! Keep up with the latest news and information on games and MPGH! To check out pages dedicated to games, see the links below!











    dd/mm/yyyy
    Member - 31/01/2015
    Premium - 12/09/2016
    Call of Duty minion - 05/11/2016 - 05/11/2019
    BattleOn minion - 28/02/2017 - 05/11/2019
    Battlefield minion - 30/05/2017 - 05/11/2019
    Other Semi-Popular First Person Shooter Hacks minion - 21/09/2017 - 17/09/2019
    Publicist - 07/11/2017 - 02/08/2018
    Cock Sucker - 01/12/2017 - Unknown
    Minion+ - 06/03/2018 - 05/11/2019
    Fortnite minion - 08/05/2018 - 05/11/2019
    Head Publicist - 08/10/2018 - 10/01/2020
    Developer Team - 26/10/2019 - 10/01/2020
    Former Staff - 10/01/2020



  2. The Following 9 Users Say Thank You to Silent For This Useful Post:

    Gill Bates (09-01-2017),hongbii (07-04-2018),Hydra (01-27-2017),Lucky8888 (09-09-2018),mjts140914 (09-29-2018),mosinu (02-17-2017),reaperscythe02 (04-16-2017),someone0815 (05-25-2017),Ussser23231 (01-22-2017)

  3. #2
    Ussser23231's Avatar
    Join Date
    Jan 2017
    Gender
    male
    Posts
    24
    Reputation
    10
    Thanks
    196
    My Mood
    Psychedelic
    Thanks James, greet work,helpfull for newbie

  4. The Following User Says Thank You to Ussser23231 For This Useful Post:

    Silent (01-22-2017)

  5. #3
    Hydra's Avatar
    Join Date
    Feb 2015
    Gender
    male
    Posts
    7,250
    Reputation
    1004
    Thanks
    7,469
    My Mood
    Psychedelic
    Quote Originally Posted by JamesBond View Post
    Hello MPGH, Today I'm going to be uploading a basic memory class for C# that I created in my spare time.

    Features:
    haha thanks man, just started to switch to C#, very useful
    Goal: Reached 1000+ Rep (YeY)

  6. The Following User Says Thank You to Hydra For This Useful Post:

    Silent (01-27-2017)

  7. #4
    Hero's Avatar
    Join Date
    Feb 2011
    Gender
    male
    Location
    memes
    Posts
    40,134
    Reputation
    4764
    Thanks
    9,674
    THANK YOU @JamesBond
    [] [] [] [][]

    Editor from 06•14•2011 • 2014
    Donator since 09•16•2011
    Minion from 10•10•2011 • 01•06•2011
    Minion+ from 01•06•2012 • 08•08•2012
    Moderator from 08•08•2012 • 10•06•2012
    Global Moderator from 10•06•2012 • 12•05•2017
    Staff Administrator from 12•05•2017 • 05•01•2019
    Trusted Member since 07•13•2019
    Global Moderator since 09•11•2020




  8. The Following User Says Thank You to Hero For This Useful Post:

    Silent (02-03-2017)

  9. #5
    Recigy's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Posts
    815
    Reputation
    78
    Thanks
    1,576
    Quote Originally Posted by JamesBond View Post
    Hello MPGH, Today I'm going to be uploading a basic memory class for C# that I created in my spare time.

    Features:
    WriteBytes
    WriteByte
    WriteInt
    WriteString
    WriteFloat
    ReadBytes
    ReadByte
    ReadInt
    ReadString
    ReadString Advanced
    ReadFloat
    PatternScan


    Source:
    Code:
    using System;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    using System.Text;
     
    class Memory
    {
        private IntPtr pHandel = IntPtr.Zero;
        private Process attachedProcess = null;
        private byte[] buffer;
     
        public bool Open_pHandel(string processName)
        {
            Process[] proc = Process.GetProcessesByName(processName);
     
            if (proc.Length == 0)
                return false;
            else if (proc.Length > 1)
                throw new Exception("More then one process found.");
            else
            {
                attachedProcess = proc[0];
                pHandel = proc[0].Handle;
                return true;
            }
        }
     
        #region x86
        #region Write
        public bool WriteBytes(int address, byte[] value, bool virtualProtect = false)
        {
            int countOfUsed = 0;
            bool result = false;
            uint oldProtection = 0;
     
     
            if (virtualProtect)
                Win32.x86.VirtualProtectEx(pHandel, address, (uint)value.Length, 0x40, out oldProtection);
     
            result = Win32.x86.WriteProcessMemory(pHandel, address, value, (uint)value.Length, out countOfUsed);
     
            if (virtualProtect)
                Win32.x86.VirtualProtectEx(pHandel, address, (uint)value.Length, oldProtection, out oldProtection);
     
            return result;
        }
     
        public bool WriteInt(int address, int value, bool virtualProtect = false)
        {
            buffer = BitConverter.GetBytes(value);
            return WriteBytes(address, buffer, virtualProtect);
        }
     
        public bool WriteByte(int address, byte value, bool virtualProtect = false)
        {
            buffer = new byte[] { value };
            return WriteBytes(address, buffer, virtualProtect);
        }
     
        public bool WriteString(int address, string value, bool virtualProtect = false)
        {
            buffer = Encoding.ASCII.GetBytes(value);//No unicode support atm
            return WriteBytes(address, buffer, virtualProtect);
        }
     
        public bool WriteFloat(int address, float value, bool virtualProtect = false)
        {
            buffer = BitConverter.GetBytes(value);
            return WriteBytes(address, buffer, virtualProtect);
        }
        #endregion
        #region Read
        public byte[] ReadBytes(int address, int length)
        {
            byte[] readBytes = new byte[length];
            int numBytesChanged = 0;
     
            Win32.x86.ReadProcessMemory(pHandel, address, readBytes, (uint)length, out numBytesChanged);
     
            return readBytes;
        }
     
        public int ReadInt(int address)
        {
            return BitConverter.ToInt32(ReadBytes(address, 4), 0);
        }
     
        public byte ReadByte(int address)
        {
            return ReadBytes(address, 1)[0];
        }
     
        public string ReadString(int address, int length)
        {//No unicode support
            return Encoding.ASCII.GetString(ReadBytes(address, length));
        }
     
        public string ReadStringAdvanced(int address, int maxStringLength = 1000)
        {//No unicode support
            string result = null;
            byte currentByte = 0;
     
            for (int i = 0; i < maxStringLength; i++)
            {
                currentByte = ReadByte(address + i);
     
                if (currentByte == 0x00)
                    break;
                else
                    result += (char)currentByte;
            }
     
            return result;
        }
     
        public float ReadFloat(int address)
        {
            return BitConverter.ToSingle(ReadBytes(address, 4), 0);
        }
        #endregion
        #region Scans
        public int PatternScan(string pattern)
        {
            string[] splitPattern = pattern.Split(' ');
            bool[] indexValid = new bool[splitPattern.Length];
            byte[] indexValue = new byte[splitPattern.Length];
     
            byte tempByte = (byte)0x00;
     
            for (int i = 0; i < splitPattern.Length; i++)
            {
                indexValid[i] = !(splitPattern[i] == "??" || splitPattern[i] == "?");
                if (Byte.TryParse(splitPattern[i], out tempByte))
                    indexValue[i] = tempByte;
                else
                    indexValid[i] = false;
            }
     
            int startOfMemory = attachedProcess.MainModule.BaseAddress.ToInt32();
            int endOfMemory = attachedProcess.MainModule.ModuleMemorySize;
     
            for (int currentMemAddy = startOfMemory; currentMemAddy < endOfMemory; currentMemAddy++)
            {
                bool complete = false;
                for (int i = 0; i < splitPattern.Length; i++)
                {
                    if (!indexValid[i])
                        continue;
     
                    tempByte = ReadByte(currentMemAddy + i);
     
                    if (tempByte != indexValue[i])
                        break;
     
                    if (i == splitPattern.Length - 1)
                        complete = true;
     
                    if (complete)
                        break;
                }
     
                if (complete)
                    return currentMemAddy;
            }
     
            throw new Exception("Pattern not found!");
            return 0;
        }
        #endregion
        #endregion
     
        private static class Win32
        {
            public static class NativeMethods
            {
                #region IsWow64Process
                public static bool IsWow64Process(IntPtr handel)
                {
                    bool isTarget64Bit = false;
                    IsWow64Process(handel, out isTarget64Bit);
                    return isTarget64Bit;
                }
     
                [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
                [return: MarshalAs(UnmanagedType.Bool)]
                private static extern bool IsWow64Process([In] IntPtr process, [Out] out bool wow64Process);
                #endregion
            }
     
            public static class x64
            {
                [DllImport("kernel32.dll", SetLastError = true)]
                public static extern bool VirtualProtectEx(IntPtr hProcess, long lpAddress, UInt32 dwSize, uint flNewProtect, out uint lpflOldProtect);
     
                [DllImport("kernel32.dll")]
                public static extern bool ReadProcessMemory(IntPtr hProcess, long lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out int lpNumberOfBytesWritten);
     
                [DllImport("kernel32.dll")]
                public static extern bool WriteProcessMemory(IntPtr hProcess, long lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out int lpNumberOfBytesWritten);
            }
     
            public static class x86
            {
                [DllImport("kernel32.dll", SetLastError = true)]
                public static extern bool VirtualProtectEx(IntPtr hProcess, int lpAddress, UInt32 dwSize, uint flNewProtect, out uint lpflOldProtect);
     
                [DllImport("kernel32.dll")]
                public static extern bool ReadProcessMemory(IntPtr hProcess, int lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out int lpNumberOfBytesWritten);
     
                [DllImport("kernel32.dll")]
                public static extern bool WriteProcessMemory(IntPtr hProcess, int lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out int lpNumberOfBytesWritten);
            }
        }
    }
    usage:
    Code:
    if(Open_pHandel("processName"))
    {
         int address = PatternScan("02 255 12 41 ?? 54 ? 12 ? 52 ?? 23");
         WriteBytes(address, new byte[] {0x00, 0x00});
    }
    Midway typing this I noticed I left the gas on, on the stove and I got a massive headache xd whoops

    Features I will add later:
    x64 support.
    idk what else


    Press thanks if this helps you!
    Little Question, Is It Like
    Code:
    WriteByte(Addres, Value)

  10. #6
    Silent's Avatar
    Join Date
    Jan 2015
    Gender
    male
    Location
    Melbourne, Australia
    Posts
    5,070
    Reputation
    2172
    Thanks
    8,474
    My Mood
    Bitchy
    Quote Originally Posted by Recigy View Post
    Little Question, Is It Like
    Code:
    WriteByte(Addres, Value)
    You need to call open phandle before writing memoery though.

    EDIT: and you need to add ";" at the end
    Last edited by Silent; 02-04-2017 at 10:29 PM.
    Click Here to visit the official MPGH wiki! Keep up with the latest news and information on games and MPGH! To check out pages dedicated to games, see the links below!











    dd/mm/yyyy
    Member - 31/01/2015
    Premium - 12/09/2016
    Call of Duty minion - 05/11/2016 - 05/11/2019
    BattleOn minion - 28/02/2017 - 05/11/2019
    Battlefield minion - 30/05/2017 - 05/11/2019
    Other Semi-Popular First Person Shooter Hacks minion - 21/09/2017 - 17/09/2019
    Publicist - 07/11/2017 - 02/08/2018
    Cock Sucker - 01/12/2017 - Unknown
    Minion+ - 06/03/2018 - 05/11/2019
    Fortnite minion - 08/05/2018 - 05/11/2019
    Head Publicist - 08/10/2018 - 10/01/2020
    Developer Team - 26/10/2019 - 10/01/2020
    Former Staff - 10/01/2020



  11. The Following User Says Thank You to Silent For This Useful Post:

    Recigy (02-05-2017)

  12. #7
    Recigy's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Posts
    815
    Reputation
    78
    Thanks
    1,576
    Quote Originally Posted by JamesBond View Post


    You need to call open phandle before writing memoery though.

    EDIT: and you need to add ";" at the end
    Thanks Bro!
    I'm Using AMDUser's MemoryClass So Yeh I'm Kinda New To This =)

  13. The Following User Says Thank You to Recigy For This Useful Post:

    Silent (02-05-2017)

  14. #8
    HexMurder's Avatar
    Join Date
    Apr 2011
    Gender
    male
    Location
    System.Diagnostics
    Posts
    344
    Reputation
    96
    Thanks
    3,170
    Why did you decide not to include unicode support? Literally the same thing as your ascii code...

    Code:
    public string ReadStringUnicode(int address, int length)
        {//Now with unicode support.
            return Encoding.Unicode.GetString(ReadBytes(address, length));
        }

  15. The Following User Says Thank You to HexMurder For This Useful Post:

    Silent (03-06-2017)

  16. #9
    Recigy's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Posts
    815
    Reputation
    78
    Thanks
    1,576
    Quote Originally Posted by HexMurder View Post
    Why did you decide not to include unicode support? Literally the same thing as your ascii code...

    Code:
    public string ReadStringUnicode(int address, int length)
        {//Now with unicode support.
            return Encoding.Unicode.GetString(ReadBytes(address, length));
        }
    Hahahaahha broo could u please accept my skype? I still remember the zombies hack u made xD

  17. #10
    HexMurder's Avatar
    Join Date
    Apr 2011
    Gender
    male
    Location
    System.Diagnostics
    Posts
    344
    Reputation
    96
    Thanks
    3,170
    Quote Originally Posted by Recigy View Post
    Hahahaahha broo could u please accept my skype? I still remember the zombies hack u made xD
    I have a lot of skype requests. What is your name? lol

  18. #11
    Recigy's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Posts
    815
    Reputation
    78
    Thanks
    1,576
    Quote Originally Posted by HexMurder View Post


    I have a lot of skype requests. What is your name? lol
    Secret.recigy

  19. #12
    Silent's Avatar
    Join Date
    Jan 2015
    Gender
    male
    Location
    Melbourne, Australia
    Posts
    5,070
    Reputation
    2172
    Thanks
    8,474
    My Mood
    Bitchy
    Quote Originally Posted by HexMurder View Post
    Why did you decide not to include unicode support? Literally the same thing as your ascii code...

    Code:
    public string ReadStringUnicode(int address, int length)
        {//Now with unicode support.
            return Encoding.Unicode.GetString(ReadBytes(address, length));
        }
    Never thought to add the option. thanks though.
    Click Here to visit the official MPGH wiki! Keep up with the latest news and information on games and MPGH! To check out pages dedicated to games, see the links below!











    dd/mm/yyyy
    Member - 31/01/2015
    Premium - 12/09/2016
    Call of Duty minion - 05/11/2016 - 05/11/2019
    BattleOn minion - 28/02/2017 - 05/11/2019
    Battlefield minion - 30/05/2017 - 05/11/2019
    Other Semi-Popular First Person Shooter Hacks minion - 21/09/2017 - 17/09/2019
    Publicist - 07/11/2017 - 02/08/2018
    Cock Sucker - 01/12/2017 - Unknown
    Minion+ - 06/03/2018 - 05/11/2019
    Fortnite minion - 08/05/2018 - 05/11/2019
    Head Publicist - 08/10/2018 - 10/01/2020
    Developer Team - 26/10/2019 - 10/01/2020
    Former Staff - 10/01/2020



  20. #13
    Biesi's Avatar
    Join Date
    Dec 2011
    Gender
    male
    Posts
    4,993
    Reputation
    374
    Thanks
    8,808
    My Mood
    Twisted
    Quote Originally Posted by HexMurder View Post
    Why did you decide not to include unicode support? Literally the same thing as your ascii code...
    Taking it a step further

    Code:
    public string ReadString(int address, int length, Encoding encoding)
    {
      //Now with everything support.
      return encoding.GetString(this.ReadBytes(address, length));
    }

  21. The Following User Says Thank You to Biesi For This Useful Post:

    [MPGH]Mayion (03-13-2017)

  22. #14
    HexMurder's Avatar
    Join Date
    Apr 2011
    Gender
    male
    Location
    System.Diagnostics
    Posts
    344
    Reputation
    96
    Thanks
    3,170
    Quote Originally Posted by Biesi View Post


    Taking it a step further

    Code:
    public string ReadString(int address, int length, Encoding encoding)
    {
      //Now with everything support.
      return encoding.GetString(this.ReadBytes(address, length));
    }
    Sad to admit this but i actually had to boot my IDE up to see if that was a read thing lmao.

  23. #15
    Biesi's Avatar
    Join Date
    Dec 2011
    Gender
    male
    Posts
    4,993
    Reputation
    374
    Thanks
    8,808
    My Mood
    Twisted
    Some general improvements I'd recommend for this class are:

    - Use the sealed (and optionally internal) keyword unless you explicitly want people to overwrite your class (which doesn't make sense in this case imo)
    - Make the class open the handle on creation of the instance.
    - Use Win32 calls to get the handle and pass the VMRead and VMWrite access rights.
    As Microsoft states
    Only processes started through a call to M:System.Diagnostics.Process.Start set the P:System.Diagnostics.Process.Handle property of the corresponding T:System.Diagnostics.Process instances.
    - Implement IDisposable and a finalizer and close the handle when the class gets finalized or disposed (in case you're opening a native handle yourself)
    - Implement support for Encodings (best would be to passed as a parameter in the constructor and then used for read and write operations)
    - Fix your code-style and naming to obey the general rules that apply for C#
    - Don't use constant numbers for your calls to VirtualProtectEx, create an enum (using the Flags attribute) for that
    - Throw a Win32Exception depending on Marshal.GetLastWin32Error
    - Do not throw exceptions of type Exception (that's considered bad practice since they're a pain in the ass to catch)
    - Use method overloading rather than optional parameters

    I hope you won't consider this as hate or bashing in any way. I just want you to improve your coding style (regarding C# and .NET) to things that might be considered best practice

    I'd also recommend you to get your hands on an educational copy of ReSharper or use the Visual Studio Code Analysis (I don't know whether this is part of the community edition) as they provide great features to analyze your code and recommend (or enforce) changes

    Feel free to contact me for resources or questions regarding the suggestions I made. I'm always glad to help people who are interested in learning
    Last edited by Biesi; 03-08-2017 at 01:36 PM.

  24. The Following User Says Thank You to Biesi For This Useful Post:

    Silent (03-08-2017)

Page 1 of 3 123 LastLast

Similar Threads

  1. C# Memory Class (Writen by Jorndel)
    By Jorndel in forum Call of Duty Modern Warfare 3 Coding, Programming & Source Code
    Replies: 12
    Last Post: 03-03-2019, 08:45 AM
  2. VB.Net Memory Class (Writen by Jorndel)
    By Jorndel in forum Call of Duty Modern Warfare 3 Coding, Programming & Source Code
    Replies: 25
    Last Post: 11-02-2017, 09:59 PM
  3. BO2 Memory Class [VB]
    By Jorndel in forum Call of Duty Black Ops 2 Coding, Programming & Source Code
    Replies: 24
    Last Post: 08-15-2016, 02:18 PM
  4. [Help] c# memory class
    By xXFleshpoundXx in forum C# Programming
    Replies: 8
    Last Post: 01-12-2013, 05:24 AM
  5. [Help Request] memory class
    By Coper in forum Call of Duty Black Ops 2 Help
    Replies: 5
    Last Post: 01-04-2013, 03:19 AM