WriteProcessMemory to protected memory?

Posts 14 of 4 · Page 1 of 1
WriteProcessMemory to protected memory?
Hi, So i've been trying to make a "Fake lag" cheat for CS:GO, using engine.dll address + bSendPackets. But im running into a problem; it crashes the game with the error
"The Thread tried to read from or write to a virtual address for which it does not have the appropriate access."

So i Googled around for awhile, and found out that you're supposed to be using VirtualProtectEx to change the access "level" before you wpm to it, so I did that, and now im getting it to work, sort of... I can write to it so it disconnects me from the game eventually... BUT I get this error that the program is trying to write to protected memory, so the application just stalls. (Hence wont pursue to turn on sendPackets again, meaning I wont be lagging around any further than to the main menu.)

However, so i tried using "Try & catch" but it still just exits / stalls the application with the error.


This is what my code looks like:

Code:
     
   public void writeProtected(int addr, byte value, IntPtr pHandle)
        {
            uint oldProtect;
            try
            {
                VirtualProtectEx(pHandle, ((IntPtr)addr), (UIntPtr)4, 0x40, out oldProtect);

                WriteProcessMemory((int)pHandle, addr, BitConverter.GetBytes(value), 1, 1);


                VirtualProtectEx(pHandle, ((IntPtr)addr), (UIntPtr)4, oldProtect, out skrap);
            }
            catch (System.Exception)
            {
                Console.WriteLine("Error.");
            }
        }


Anybody knows what im doing wrong? why am I even getting the error after using the VirtualProtectEx function?



Thankful for any help
Quote Originally Posted by Plaii View Post
Hi, So i've been trying to make a "Fake lag" cheat for CS:GO, using engine.dll address + bSendPackets. But im running into a problem; it crashes the game with the error
"The Thread tried to read from or write to a virtual address for which it does not have the appropriate access."

So i Googled around for awhile, and found out that you're supposed to be using VirtualProtectEx to change the access "level" before you wpm to it, so I did that, and now im getting it to work, sort of... I can write to it so it disconnects me from the game eventually... BUT I get this error that the program is trying to write to protected memory, so the application just stalls. (Hence wont pursue to turn on sendPackets again, meaning I wont be lagging around any further than to the main menu.)

However, so i tried using "Try & catch" but it still just exits / stalls the application with the error.


This is what my code looks like:

Code:
     
   public void writeProtected(int addr, byte value, IntPtr pHandle)
        {
            uint oldProtect;
            try
            {
                VirtualProtectEx(pHandle, ((IntPtr)addr), (UIntPtr)4, 0x40, out oldProtect);

                WriteProcessMemory((int)pHandle, addr, BitConverter.GetBytes(value), 1, 1);


                VirtualProtectEx(pHandle, ((IntPtr)addr), (UIntPtr)4, oldProtect, out skrap);
            }
            catch (System.Exception)
            {
                Console.WriteLine("Error.");
            }
        }


Anybody knows what im doing wrong? why am I even getting the error after using the VirtualProtectEx function?



Thankful for any help
Problem is not int VirtualProtect.
I have FakeLag in my cheat and it doesn't need any special code to make it.
Simply write byte 1 for packets on and byte 0 for packets off.
I see 2 reasons why it happens:
1. outdated bSendPackets offset (it change every game update)
2. too low access rights in OpenProcess
basic access is 0x8 | 0x10 | 0x20
0x8 = operation (virtual protect, write process mem etc.)
0x10 = read access
0x20 = write access
Hmm weird, cuz I am already using OpenProcess with the ProcessAccessFlag.ALL (0x001F0FFF). Because the other ones dont even work...?

But even with that, Im allowed to write to all addresses except Engine.dll + 0xE5B5A (bSendPackets)
Am I declaring OpenProcess wrong maybe?


Code:
        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern IntPtr OpenProcess(
     ProcessAccessFlags processAccess,
     bool bInheritHandle,
     int processId);



  and this is the handle:
  IntPtr handle = OpenProcess(ProcessAccessFlags.All, false, p[0].Id);

Im doing this from a 2nd class and not main class, do you think that could potentially cause errors?
You can always use GetLastError to check the function failed or not.
Posts 14 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?