WinAPI use in C#

06/09/2008 16:51 Term!nX#16
Hm, irgendwas wehrt sich:

Code:
            IntPtr phdl = OpenProcess(0x10, false, (uint)po.Id);
            IntPtr wrthdl = OpenProcess(0x20, false, (uint)po.Id);
            if (phdl == null)
                MessageBox.Show("Prozesshandle konnte nicht erstellt werden! Prozess aktiv?", "Fehler!");
            if (wrthdl == null)
                MessageBox.Show("WRITE-ProcHdl nicht erstellt!");
            uint size = 4;
            // uint vNumberOfBytesRead = 0;
            byte[] bytes = new byte[size];
            uint adress = 0x560264;
            uint size2 = sizeof(int);
            IntPtr rw;
            bool read;
            read = ReadProcessMemory(phdl, (IntPtr)adress, bytes, (UIntPtr)size2, out rw);
            if (!read)
                MessageBox.Show("Fehlschlag beim Lesen");
            else
            {
                MessageBox.Show(BitConverter.ToInt32(bytes, 0).ToString());
            }
            int money = BitConverter.ToInt32(bytes, 0);
            money = money + 10000;
            byte[] bytes2 = new byte[4];
            bytes2 = BitConverter.GetBytes(money);
            bool write;
            write = WriteProcessMemory(wrthdl, (IntPtr)adress, bytes2, (UIntPtr)size2, out rw);
            if (write)
                MessageBox.Show("Write kk");
            else if (!write)
                MessageBox.Show("Write not kk...");
Compiler muckt nicht, bytes entspricht nach testweiser reconvertierung in int dem neuen Wert und die handles sind auch alle != null.
Ist entweder 0x20 nicht der Write-Access code, was ich kaum glauben kann, da:
PROCESS_VM_WRITE (0x0020) Required to write to memory in a process using WriteProcessMemory.

Was ich vermute ist:
ReadProcessMemory hat ja in C++ bei baseadress den Datentyp LPCVOID, WriteProcessMemory den Typ LPVOID. In c# sind die Datentypen aber gleich.. es ist nur ne Vermutung.