Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Help] Delphi to C #

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
sgs_
How do I cheat?
Reputation: 0

Joined: 12 Mar 2014
Posts: 4

PostPosted: Wed Mar 12, 2014 12:47 am    Post subject: [Help] Delphi to C # Reply with quote

I'm trying to pass this code to C #
It is a WrittenProcessMemory writing a string.

Sorry my English (Google Translate) e.e

Code:
WriteProcessMemory(hProc,Ptr(NickChange),PChar(str+#0),Length(str)+1,Writen);
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Mar 12, 2014 3:00 pm    Post subject: Reply with quote

You will need to import the API call:
http://www.pinvoke.net/default.aspx/kernel32.writeprocessmemory

After that, to write data, C# uses byte arrays. So you will need to convert the string to a byte array using the Encoding class. After that you should be good to go.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Wed Mar 12, 2014 3:10 pm    Post subject: Reply with quote

WriteProcessMemory Prototype in C#
Code:

using System.Runtime.InteropServices;

//
// etc
//

[DllImport("Kernel32.dll")]
public static extern bool WriteProcessMemory( IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out Int32 lpNumberOfBytesWritten );

_________________
Stylo
Back to top
View user's profile Send private message
sgs_
How do I cheat?
Reputation: 0

Joined: 12 Mar 2014
Posts: 4

PostPosted: Thu Mar 13, 2014 2:11 pm    Post subject: Reply with quote

Sorry think esprecei me wrong, what I'm trying to do is write it in memory like mentioned above I'm using this:

Code:
public static void WriteString(string EXENAME, int Address, string Value)
        {
            checked
            {
                try
                {
                    Process[] Proc = Process.GetProcessesByName(EXENAME);
                    if (Proc.Length != 0)
                    {
                        char st = Convert.ToChar(Value + "\0");

                        int Bytes = 0;
                        int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
                        if (Handle != 0)
                        {
                            WriteProcessMemoryString(Handle, Address, ref st, Value.Length + 1, ref Bytes);
                        }
                        CloseHandle(Handle);
                    }
                }
                catch
                { }
            }
        }


However no avail.
Back to top
View user's profile Send private message
Matze500
Expert Cheater
Reputation: 8

Joined: 25 Jan 2012
Posts: 241
Location: Germany

PostPosted: Thu Mar 13, 2014 6:04 pm    Post subject: Reply with quote

it should be this in C# and then you can write a value to an address.

Code:

using System.Runtime.InteropServices;

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

public void WriteProcessMemory(IntPtr processId,IntPtr address, byte[] value)
        {
            WriteProcessMemory(processId, address.ToInt32(), value, value.Length, 0);
        }
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites