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 in Pointer for C#

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

Joined: 19 Nov 2013
Posts: 1
Location: dasdas

PostPosted: Sun Aug 24, 2014 1:59 pm    Post subject: Help in Pointer for C# Reply with quote

My Pointer is : "AikaTH.exe"+00850670
How to use in C#


Please help me



I use this class ReadProcesMemory:


Code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;
 
namespace Claro
{
    public class Trainer
    {
        private const int PROCESS_ALL_ACCESS = 0x1F0FFF;
        [DllImport("kernel32")]
        private static extern int OpenProcess(int AccessType, int InheritHandle, int ProcessId);
        [DllImport("kernel32", EntryPoint = "WriteProcessMemory")]
        private static extern byte WriteProcessMemoryByte(int Handle, int Address, ref byte Value, int Size, ref int BytesWritten);
        [DllImport("kernel32", EntryPoint = "WriteProcessMemory")]
        private static extern int WriteProcessMemoryInteger(int Handle, int Address, ref int Value, int Size, ref int BytesWritten);
        [DllImport("kernel32", EntryPoint = "WriteProcessMemory")]
        private static extern float WriteProcessMemoryFloat(int Handle, int Address, ref float Value, int Size, ref int BytesWritten);
        [DllImport("kernel32", EntryPoint = "WriteProcessMemory")]
        private static extern double WriteProcessMemoryDouble(int Handle, int Address, ref double Value, int Size, ref int BytesWritten);
 
 
        [DllImport("kernel32", EntryPoint = "ReadProcessMemory")]
        private static extern byte ReadProcessMemoryByte(int Handle, int Address, ref byte Value, int Size, ref int BytesRead);
        [DllImport("kernel32", EntryPoint = "ReadProcessMemory")]
        private static extern int ReadProcessMemoryInteger(int Handle, int Address, ref int Value, int Size, ref int BytesRead);
        [DllImport("kernel32", EntryPoint = "ReadProcessMemory")]
        private static extern float ReadProcessMemoryFloat(int Handle, int Address, ref float Value, int Size, ref int BytesRead);
        [DllImport("kernel32", EntryPoint = "ReadProcessMemory")]
        private static extern double ReadProcessMemoryDouble(int Handle, int Address, ref double Value, int Size, ref int BytesRead);
        [DllImport("kernel32")]
        private static extern int CloseHandle(int Handle);
 
        [DllImport("user32")]
        private static extern int FindWindow(string sClassName, string sAppName);
        [DllImport("user32")]
        private static extern int GetWindowThreadProcessId(int HWND, out int processId);
 
 
        public static string CheckGame(string WindowTitle)
        {
            string result = "";
            checked
            {
                try
                {
                    int Proc;
                    int HWND = FindWindow(null, WindowTitle);
                    GetWindowThreadProcessId(HWND, out Proc);
                    int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc);
                    if (Handle != 0)
                    {
                        result = "Game is running...";
                    }
                    else
                    {
                        result = "Game is not running...";
                    }
                    CloseHandle(Handle);
                }
                catch
                { }
            }
            return result;
        }
        public static byte ReadByte(string EXENAME, int Address)
        {
            byte Value = 0;
            checked
            {
                try
                {
                    Process[] Proc = Process.GetProcessesByName(EXENAME);
                    if (Proc.Length != 0)
                    {
                        int Bytes = 0;
                        int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
                        if (Handle != 0)
                        {
                            ReadProcessMemoryByte(Handle, Address, ref Value, 2, ref Bytes);
                            CloseHandle(Handle);
                        }
                    }
                }
                catch
                { }
            }
            return Value;
        }
        public static int ReadInteger(string EXENAME, int Address)
        {
            int Value = 0;
            checked
            {
                try
                {
                    Process[] Proc = Process.GetProcessesByName(EXENAME);
                    if (Proc.Length != 0)
                    {
                        int Bytes = 0;
                        int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
                        if (Handle != 0)
                        {
                            ReadProcessMemoryInteger(Handle, Address, ref Value, 4, ref Bytes);
                            CloseHandle(Handle);
                        }
                    }
                }
                catch
                { }
            }
            return Value;
        }
        public static float ReadFloat(string EXENAME, int Address)
        {
            float Value = 0;
            checked
            {
                try
                {
                    Process[] Proc = Process.GetProcessesByName(EXENAME);
                    if (Proc.Length != 0)
                    {
                        int Bytes = 0;
                        int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
                        if (Handle != 0)
                        {
                            ReadProcessMemoryFloat((int)Handle, Address, ref Value, 4, ref Bytes);
                            CloseHandle(Handle);
                        }
                    }
                }
                catch
                { }
            }
            return Value;
        }
        public static double ReadDouble(string EXENAME, int Address)
        {
            double Value = 0;
            checked
            {
                try
                {
                    Process[] Proc = Process.GetProcessesByName(EXENAME);
                    if (Proc.Length != 0)
                    {
                        int Bytes = 0;
                        int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
                        if (Handle != 0)
                        {
                            ReadProcessMemoryDouble((int)Handle, Address, ref Value, 8, ref Bytes);
                            CloseHandle(Handle);
                        }
                    }
                }
                catch
                { }
            }
            return Value;
        }
 
        public static byte ReadPointerByte(string EXENAME, int Pointer, int[] Offset)
        {
            byte Value = 0;
            checked
            {
                try
                {
                    Process[] Proc = Process.GetProcessesByName(EXENAME);
                    if (Proc.Length != 0)
                    {
                        int Bytes = 0;
                        int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
                        if (Handle != 0)
                        {
                            foreach (int i in Offset)
                            {
                                ReadProcessMemoryInteger((int)Handle, Pointer, ref Pointer, 4, ref Bytes);
                                Pointer += i;
                            }
                            ReadProcessMemoryByte((int)Handle, Pointer, ref Value, 2, ref Bytes);
                            CloseHandle(Handle);
                        }
                    }
                }
                catch
                { }
            }
            return Value;
        }
        public static int ReadPointerInteger(string EXENAME, int Pointer, int[] Offset)
        {
            int Value = 0;
            checked
            {
                try
                {
                    Process[] Proc = Process.GetProcessesByName(EXENAME);
                    if (Proc.Length != 0)
                    {
                        int Bytes = 0;
                        int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
                        if (Handle != 0)
                        {
                            foreach (int i in Offset)
                            {
                                ReadProcessMemoryInteger((int)Handle, Pointer, ref Pointer, 4, ref Bytes);
                                Pointer += i;
                            }
                            ReadProcessMemoryInteger((int)Handle, Pointer, ref Value, 4, ref Bytes);
                            CloseHandle(Handle);
                        }
                    }
                }
                catch
                { }
            }
            return Value;
        }
        public static float ReadPointerFloat(string EXENAME, int Pointer, int[] Offset)
        {
            float Value = 0;
            checked
            {
                try
                {
                    Process[] Proc = Process.GetProcessesByName(EXENAME);
                    if (Proc.Length != 0)
                    {
                        int Bytes = 0;
                        int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
                        if (Handle != 0)
                        {
                            foreach (int i in Offset)
                            {
                                ReadProcessMemoryInteger((int)Handle, Pointer, ref Pointer, 4, ref Bytes);
                                Pointer += i;
                            }
                            ReadProcessMemoryFloat((int)Handle, Pointer, ref Value, 4, ref Bytes);
                            CloseHandle(Handle);
                        }
                    }
                }
                catch
                { }
            }
            return Value;
        }
        public static double ReadPointerDouble(string EXENAME, int Pointer, int[] Offset)
        {
            double Value = 0;
            checked
            {
                try
                {
                    Process[] Proc = Process.GetProcessesByName(EXENAME);
                    if (Proc.Length != 0)
                    {
                        int Bytes = 0;
                        int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
                        if (Handle != 0)
                        {
                            foreach (int i in Offset)
                            {
                                ReadProcessMemoryInteger((int)Handle, Pointer, ref Pointer, 4, ref Bytes);
                                Pointer += i;
                            }
                            ReadProcessMemoryDouble((int)Handle, Pointer, ref Value, 8, ref Bytes);
                            CloseHandle(Handle);
                        }
                    }
                }
                catch
                { }
            }
            return Value;
        }
 
        public static void WriteByte(string EXENAME, int Address, byte Value)
        {
            checked
            {
                try
                {
                    Process[] Proc = Process.GetProcessesByName(EXENAME);
                    if (Proc.Length != 0)
                    {
                        int Bytes = 0;
                        int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
                        if (Handle != 0)
                        {
                            WriteProcessMemoryByte(Handle, Address, ref Value, 2, ref Bytes);
                        }
                        CloseHandle(Handle);
                    }
                }
                catch
                { }
            }
        }
        public static void WriteInteger(string EXENAME, int Address, int Value)
        {
            checked
            {
                try
                {
                    Process[] Proc = Process.GetProcessesByName(EXENAME);
                    if (Proc.Length != 0)
                    {
                        int Bytes = 0;
                        int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
                        if (Handle != 0)
                        {
                            WriteProcessMemoryInteger(Handle, Address, ref Value, 4, ref Bytes);
                        }
                        CloseHandle(Handle);
                    }
                }
                catch
                { }
            }
        }
        public static void WriteFloat(string EXENAME, int Address, float Value)
        {
            checked
            {
                try
                {
                    Process[] Proc = Process.GetProcessesByName(EXENAME);
                    if (Proc.Length != 0)
                    {
                        int Bytes = 0;
                        int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
                        if (Handle != 0)
                        {
                            WriteProcessMemoryFloat(Handle, Address, ref Value, 4, ref Bytes);
                        }
                        CloseHandle(Handle);
                    }
 
                }
                catch
                { }
            }
        }
        public static void WriteDouble(string EXENAME, int Address, double Value)
        {
            checked
            {
                try
                {
                    Process[] Proc = Process.GetProcessesByName(EXENAME);
                    if (Proc.Length != 0)
                    {
                        int Bytes = 0;
                        int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
                        if (Handle != 0)
                        {
                            WriteProcessMemoryDouble(Handle, Address, ref Value, 8, ref Bytes);
                        }
                        CloseHandle(Handle);
                    }
                }
                catch
                { }
            }
        }
 
        public static void WritePointerByte(string EXENAME, int Pointer, int[] Offset, byte Value)
        {
            checked
            {
                try
                {
                    Process[] Proc = Process.GetProcessesByName(EXENAME);
                    if (Proc.Length != 0)
                    {
                        int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
                        if (Handle != 0)
                        {
                            int Bytes = 0;
                            foreach (int i in Offset)
                            {
                                ReadProcessMemoryInteger(Handle, Pointer, ref Pointer, 4, ref Bytes);
                                Pointer += i;
                            }
                            WriteProcessMemoryByte(Handle, Pointer, ref Value, 2, ref Bytes);
                        }
                        CloseHandle(Handle);
                    }
                }
                catch
                { }
            }
        }
        public static void WritePointerInteger(string EXENAME, int Pointer, int[] Offset, int Value)
        {
            checked
            {
                try
                {
                    Process[] Proc = Process.GetProcessesByName(EXENAME);
                    if (Proc.Length != 0)
                    {
                        int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
                        if (Handle != 0)
                        {
                            int Bytes = 0;
                            foreach (int i in Offset)
                            {
                                ReadProcessMemoryInteger(Handle, Pointer, ref Pointer, 4, ref Bytes);
                                Pointer += i;
                            }
                            WriteProcessMemoryInteger(Handle, Pointer, ref Value, 4, ref Bytes);
                        }
                        CloseHandle(Handle);
                    }
                }
                catch
                { }
            }
        }
        public static void WritePointerFloat(string EXENAME, int Pointer, int[] Offset, float Value)
        {
            checked
            {
                try
                {
                    Process[] Proc = Process.GetProcessesByName(EXENAME);
                    if (Proc.Length != 0)
                    {
                        int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
                        if (Handle != 0)
                        {
                            int Bytes = 0;
                            foreach (int i in Offset)
                            {
                                ReadProcessMemoryInteger(Handle, Pointer, ref Pointer, 4, ref Bytes);
                                Pointer += i;
                            }
                            WriteProcessMemoryFloat(Handle, Pointer, ref Value, 4, ref Bytes);
                        }
                        CloseHandle(Handle);
                    }
                }
                catch
                { }
            }
        }
        public static void WritePointerDouble(string EXENAME, int Pointer, int[] Offset, double Value)
        {
            checked
            {
                try
                {
                    Process[] Proc = Process.GetProcessesByName(EXENAME);
                    if (Proc.Length != 0)
                    {
                        int Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, Proc[0].Id);
                        if (Handle != 0)
                        {
                            int Bytes = 0;
                            foreach (int i in Offset)
                            {
                                ReadProcessMemoryInteger(Handle, Pointer, ref Pointer, 4, ref Bytes);
                                Pointer += i;
                            }
                            WriteProcessMemoryDouble(Handle, Pointer, ref Value, 8, ref Bytes);
                        }
                        CloseHandle(Handle);
                    }
                }
                catch
                { }
            }
        }
    }
}


[/code][img][/img]



Screenshot_2.png
 Description:
Pointer e Offsets
 Filesize:  11.73 KB
 Viewed:  6567 Time(s)

Screenshot_2.png



_________________
sdasdasdasd
Back to top
View user's profile Send private message
FrequentlyX
Newbie cheater
Reputation: 0

Joined: 29 Dec 2013
Posts: 14

PostPosted: Mon Sep 01, 2014 12:31 am    Post subject: Reply with quote

I dont understand,

so you found "AikaTH.exe"+00850670

and you need help using it using C# ? like a starter code that uses that the pointer you give it and it attaches to the processor ?
Back to top
View user's profile Send private message
WPHook
How do I cheat?
Reputation: 0

Joined: 14 Sep 2014
Posts: 2

PostPosted: Sun Sep 14, 2014 9:56 pm    Post subject: Reply with quote

Returns the Base Address of a process. Equivalent to GeModuleHandle, however to exe

Code:
public static IntPtr GetBaseAddress(string Processo)
        {
            try
            {
                Process[] ProcList = Process.GetProcessesByName(Processo);
                Process MYPROCESS = ProcList[0];
                IntPtr BaseAddress = IntPtr.Zero;

                foreach (System.Diagnostics.ProcessModule Module in MYPROCESS.Modules)
                {
                    if (Module.ModuleName.Contains(Processo))
                        BaseAddress = Module.BaseAddress;
                }

                if (BaseAddress != IntPtr.Zero)
                {
                    return BaseAddress;
                }
                else
                {
                    return IntPtr.Zero;
                }
            }
            catch
            {
                return IntPtr.Zero;
            }
        }


using:
Code:
IntPtr BaseAddress = GetBaseAddress("AikaTH");
int Address = (int)BaseAddress + 00850670;
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Mon Sep 15, 2014 1:53 am    Post subject: Reply with quote

Relying directly on error handling to catch faults in your code is not a real efficient method of coding. You should be doing error checks yourself. Also there is no need to loop the module list to get the base address of the process. You can use the .MainModule property to obtain the information that you are looking for.

You can do the similar via:
Code:
        private static IntPtr GetBaseAddress(string procName)
        {
            var proc = Process.GetProcessesByName(procName).FirstOrDefault();
            return proc == null ? IntPtr.Zero : proc.MainModule.BaseAddress;
        }

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
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