[C#] ReadWritingMemory Error [NEED HELP]

08/20/2016 19:36 b0sted#1
Hallo Leute.

Ich hab gestern in Google eine ReadWritingMemory in C# gefunden und sie in meinem Projekt mit eingebunden:

So sieht es aus:
Code:
public class ReadWritingMemory
    {

        [Flags()]
        public enum ProcessAccessType
        {

            PROCESS_TERMINATE = 1,

            PROCESS_CREATE_THREAD = 2,

            PROCESS_SET_SESSIONID = 4,

            PROCESS_VM_OPERATION = 8,

            PROCESS_VM_READ = 16,

            PROCESS_VM_WRITE = 32,

            PROCESS_DUP_HANDLE = 64,

            PROCESS_CREATE_PROCESS = 128,

            PROCESS_SET_QUOTA = 256,

            PROCESS_SET_INFORMATION = 512,

            PROCESS_QUERY_INFORMATION = 1024,
        }

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

        [DllImport("kernel32.dll")]
        public static extern Int32 CloseHandle(IntPtr hObject);

        [DllImport("kernel32.dll")]
        public static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] buffer, UInt32 size, ref IntPtr lpNumberOfBytesRead);

        [DllImport("kernel32.dll")]
        public static extern Int32 WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] buffer, UInt32 size, ref IntPtr lpNumberOfBytesWritten);

        public static void WriteLong(string ProcessName, int Address, long Value, int nsize)
        {
            if (ProcessName.EndsWith(".exe"))
            {
                ProcessName = ProcessName.Replace(".exe", "");
            }
            Process[] processesByName = Process.GetProcessesByName(ProcessName);
            if ((processesByName.Length == 0))
            {
                MessageBox.Show((ProcessName + " is not running"));
            }
            else
            {
                IntPtr ptr = ((IntPtr)(OpenProcess(127231, 0, processesByName[0].Id)));
                if ((ptr == IntPtr.Zero))
                {
                    MessageBox.Show(("Failed to open: "
                                    + (ProcessName + "!")));
                }
                else
                {
                    int lpBaseAddress = Address;
                    long lpBuffer = Value;
                    int lpNumberOfBytesWritten = 0;
                    WriteProcessMemory3(((int)(ptr)), lpBaseAddress, ref lpBuffer, nsize, ref lpNumberOfBytesWritten);
                }
            }
        }

        [DllImport("kernel32.dll", EntryPoint = "WriteProcessMemory")]
        private static extern int WriteProcessMemory1(int hProcess, int lpBaseAddress, ref int lpBuffer, int nSize, ref int lpNumberOfBytesWritten);

        [DllImport("kernel32.dll", EntryPoint = "WriteProcessMemory")]
        private static extern float WriteProcessMemory2(int hProcess, int lpBaseAddress, ref float lpBuffer, int nSize, ref int lpNumberOfBytesWritten);

        [DllImport("kernel32.dll", EntryPoint = "WriteProcessMemory")]
        private static extern long WriteProcessMemory3(int hProcess, int lpBaseAddress, ref long lpBuffer, int nSize, ref int lpNumberOfBytesWritten);

        private const int PROCESS_ALL_ACCESS = 127231;
    }

Das ist Problem ist aber, wenn ich diesen Code einfüge, passiert nichts im Spiel:

Code:
if (checkBoxZ1.Checked == true)
            {
                ReadWritingMemory.WriteLong("S4Client.exe" + 0x5A40D6, 267620496);
            }
Ich wäre auf jeden Fall dankbar, wenn mir jemand helfen könnte.
08/27/2016 05:37 atom0s#2
You are calling the function incorrectly with the wrong parameters based on what it wants. You are also not using the function correctly with the address that you are trying to write to.
08/29/2016 16:06 Shawak#3
Instead of "S4Client.exe" you need to pass the base address of the s4 league process.
09/01/2016 11:48 theplake#4
Die pointer ändern sich auch mit jedem Update.