Solved WriteProccessMemory

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

danivegas

Newbie
Full Member
Oct 20, 2012
12
244
0
Hi Everyone,

I'm trying to WriteProccessMemory to a program but it seems that it doesn't work.

C++:
const int PROCESS_VM_WRITE = 0x0020;
        const int PROCESS_VM_OPERATION = 0x0008;

        [DllImport("kernel32.dll")]
        public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);

        [DllImport("kernel32.dll", SetLastError = true)]
        static extern bool WriteProcessMemory(int hProcess, int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesWritten);



        public static void Main1()
        {

            try
            {
                Process process = Process.GetProcessesByName("123")[0];
                IntPtr processHandle = OpenProcess(0x1F0FFF, false, process.Id);

                int bytesWritten = 2;
                byte[] buffer = { 0xB0, 0x01 };

                int lpBaseAddress = 0x0031C0A4;

                WriteProcessMemory((int)processHandle, lpBaseAddress, buffer, buffer.Length, ref bytesWritten);
            }
            catch
            {
                MessageBox.Show("123 is not running.");
            }

        }
I found that working before I have made some changes but I don't know why it is not working now..
Any ideas?
 

gmastergreatee

Jr.Coder
Full Member
Nobleman
Aug 5, 2014
55
588
3
For me, the above code you wrote is working perfectly. There are some cases in which the above code may not work. Two of those which I came across in the past are :-

1> Make sure that you are running the application in admin mode.
[You may set it in the application manifest file.]

2> Also check, if you are trying to change the bytes of the memory region which is set to READ ONLY (this may be possible). Check for those cases using Cheat Engine's Memory Regions dialog(CE->Memory Viewer->View->Memory Regions or just press Ctrl+R at the Memory Viewer).
In case you want to change the memory access property, you may use ReadWriteAccess method as :-

C#:
        [DllImport("kernel32.dll")]

        public static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, long dwSize, long flNewProtect, out int lpflOldProtect);

        public bool ReadWriteAccess(long startAddress, long endAddress)
        {
            /*
             * Flags::-
             * ==========================
             * NOACCESS          0x01   
             * READONLY          0x02   
             * READWRITE         0x04   
             * WRITECOPY         0x08

             */

            int oldProtectType;

            try

            {

                return VirtualProtectEx(m_hProcess, (IntPtr)startAddress, endAddress - startAddress, 0x04, out oldProtectType);

            }

            catch (Exception ex)
            {
                throw new Exception("An error has occured. Error :: " + ex.Message);
            }
        }
-part of Memory Trainer(Help - C# AOB Scan)

where m_hProcess is handle obtained from OpenProcess method.

Hope it helps you. Enjoy game-hacking.;)
 
Last edited by a moderator:
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Thread starter Similar threads Forum Replies Date
W Solved Read/WriteProccessMemory with base and offset Questions & Answers - Hacking Help 3
Community Mods