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 


[C#] Trainer template (for the beginners!)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Wed Oct 22, 2008 3:02 pm    Post subject: [C#] Trainer template (for the beginners!) Reply with quote

I had some time to kill so I wrote an extremely simple application that modifies the target process memory using FindWindow() as an entry point to open up the process for memory editing.
I know that this isn't the ideal way, but this also shows how to use a window handle which is useful if you/they want to implement a botting feature to their trainer.

Anyways, I just wanted to post it here since I know people are struggling to understand the hard terms of programming, and I'm trying to show you that it's not hard at all.

* This will require basic skill with the C# GUI editor and variable understanding, nothing more - nothing less.
- Create one button called Write, then another one called Get handles or something.
- Continue to code (?) Smile

Code:
using System;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace TrainerTemplate
{
    public partial class Form1 : Form
    {
        //C# Signature for the FindWindow() API
        [DllImport("USER32.DLL")] // Let the computer know where the below function will be imported from (user32.dll)
        public static extern IntPtr FindWindow( // Create a function "template"
            string lpClassName, // The function has two arguments, lpClassName (=Window class name) and lpWindowName (=Window name)
            string lpWindowName // Example of FindWindow() call using the arguments -> FindWindow("WindowClass" <- this is the lpClassName type string, "WindowName" <- this is the lpWindowName type string);
        );

        //C# Signature for the WriteProcessMemory() API
        [DllImport("kernel32.dll")]
        static extern bool WriteProcessMemory(
            IntPtr hProcess,
            IntPtr lpBaseAddress,
            byte[] lpBuffer,
            UIntPtr nSize,
            out IntPtr lpNumberOfBytesWritten
        );

        //C# Signature for the OpenProcess() API
        [DllImport("kernel32.dll")]
        public static extern IntPtr OpenProcess(
            UInt32 dwDesiredAccess,
            Int32 bInheritHandle,
            UInt32 dwProcessId
        );

        //C# Signature for the GetWindowThreadProcessId() API
        [DllImport("user32.dll", SetLastError = true)]
        static extern uint GetWindowThreadProcessId(
            IntPtr hWnd,
            out uint lpdwProcessId
        );

        //C# Signature for the ReadProcessMemory() API
        [DllImport("kernel32.dll", SetLastError = true)]
        static unsafe extern bool ReadProcessMemory(
         IntPtr hProcess,
         IntPtr lpBaseAddress,
         void* lpBuffer,
         int dwSize,
         out IntPtr lpNumberOfBytesRead
        );

        // Global variables (containers)
        UInt32 ProcID;
        IntPtr WindowHandle;
        IntPtr ProcessHandle;
        IntPtr bytesout; // If using ReadProcessMemory(), dump the successfully read bytes here.

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            byte[] InfiniteMoney = { 0x90, 0x90 }; // Byte array
            WriteProcessMemory(ProcessHandle, (IntPtr)0x00C47F74 /*Target address*/, InfiniteMoney /*Byte array call*/, (UIntPtr)2 /*Byte array size*/, out bytesout);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            WindowHandle = FindWindow("WindowClass", "WindowTitle"); // Establish a Window Handle (hWnd)
            GetWindowThreadProcessId(WindowHandle, out ProcID); // Get the Process ID (PID) from the targeted window/window class
            ProcessHandle = OpenProcess(0x1F0FFF, 1, ProcID); // Gain access to the process memory with OpenProcess() using Process ID as an entry
        }
    }
}


Now let the coding begin!
Razz

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Fuzz
Grandmaster Cheater
Reputation: 0

Joined: 12 Nov 2006
Posts: 531

PostPosted: Wed Oct 22, 2008 3:44 pm    Post subject: Reply with quote

Good post spawn. Commented and everthing. Good thinking.
Back to top
View user's profile Send private message AIM Address
Hieroglyphics
I post too much
Reputation: 0

Joined: 06 Dec 2007
Posts: 2007
Location: Your bedroom

PostPosted: Wed Oct 22, 2008 4:31 pm    Post subject: Reply with quote

Good Job. Though I don't like C# Sad I shall make one for C++, still not sure yet though.
_________________

Back to top
View user's profile Send private message AIM Address MSN Messenger
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Oct 22, 2008 4:37 pm    Post subject: Reply with quote

Good work but I would personally not encourage handing out templates like this since they generate more and more template coders, eg. ^
Back to top
View user's profile Send private message
13
I post too much
Reputation: 0

Joined: 24 Apr 2007
Posts: 4603

PostPosted: Wed Oct 22, 2008 6:21 pm    Post subject: Reply with quote

Thanks spawn :D I've just begun learning C# and this is extremely useful.
Back to top
View user's profile Send private message
Zan.exe
Grandmaster Cheater
Reputation: 0

Joined: 22 Feb 2007
Posts: 752
Location: The U.S. of A.

PostPosted: Wed Oct 22, 2008 6:22 pm    Post subject: Reply with quote

why do I get an error when posting it in a clean new project in project.cs?

Error 1 The name 'InitializeComponent' does not exist in the current context C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Program.cs 61 13 WindowsFormsApplication1

_________________
PM Me if you play FFXI - Bismark Server
Lv75 BST

Almost all the mods on CEF are morons.

<3 SunBeam
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Oct 22, 2008 11:20 pm    Post subject: Reply with quote

You don't need to go through all that to get the process handle in .NET

You can just use the Process class.

Process[] p = Process.GetProcessesByName("winmine");
WriteProcessMemory(p[0].Handle, ...);


Last edited by hcavolsdsadgadsg on Thu Oct 23, 2008 9:29 am; edited 1 time in total
Back to top
View user's profile Send private message
RAKO
Master Cheater
Reputation: 0

Joined: 26 Jun 2006
Posts: 454

PostPosted: Thu Oct 23, 2008 2:39 am    Post subject: Reply with quote

do you know how to use asm in c#? other wise we can't hook hop so might as well program in c++ but i like c# gui.
_________________
Dark Byte wrote:
Who knows, perhaps i'm a maple gm!!!!
Back to top
View user's profile Send private message
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Thu Oct 23, 2008 9:59 am    Post subject: Reply with quote

slovach wrote:
You don't need to go through all that to get the process handle in .NET

You can just use the Process class.

Process[] p = Process.GetProcessesByName("winmine");
WriteProcessMemory(p[0].Handle, ...);

Usually you implement a bot within a trainer, and they should get to know how to get the window handle anyways so it doesn't really matter.

Zan.exe wrote:
why do I get an error when posting it in a clean new project in project.cs?

Error 1 The name 'InitializeComponent' does not exist in the current context C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Program.cs 61 13 WindowsFormsApplication1

You can't just copy and paste the code. You have to actually read it.

RAKO wrote:
do you know how to use asm in c#? other wise we can't hook hop so might as well program in c++ but i like c# gui.

Easily import a DLL made in C++ into your C# project and use the function from there, it'll work just as nicely.

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Thu Oct 23, 2008 10:11 am    Post subject: Reply with quote

Spawnfestis wrote:
slovach wrote:
You don't need to go through all that to get the process handle in .NET

You can just use the Process class.

Process[] p = Process.GetProcessesByName("winmine");
WriteProcessMemory(p[0].Handle, ...);

Usually you implement a bot within a trainer, and they should get to know how to get the window handle anyways so it doesn't really matter.

p[x].MainWindowHandle?
Back to top
View user's profile Send private message
Zan.exe
Grandmaster Cheater
Reputation: 0

Joined: 22 Feb 2007
Posts: 752
Location: The U.S. of A.

PostPosted: Thu Oct 23, 2008 1:42 pm    Post subject: Reply with quote

Spawnfestis wrote:


Zan.exe wrote:
why do I get an error when posting it in a clean new project in project.cs?

Error 1 The name 'InitializeComponent' does not exist in the current context C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Program.cs 61 13 WindowsFormsApplication1

You can't just copy and paste the code. You have to actually read it.


got it working, ty

_________________
PM Me if you play FFXI - Bismark Server
Lv75 BST

Almost all the mods on CEF are morons.

<3 SunBeam
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu Oct 23, 2008 1:56 pm    Post subject: Reply with quote

Spawnfestis wrote:
slovach wrote:
You don't need to go through all that to get the process handle in .NET

You can just use the Process class.

Process[] p = Process.GetProcessesByName("winmine");
WriteProcessMemory(p[0].Handle, ...);

Usually you implement a bot within a trainer, and they should get to know how to get the window handle anyways so it doesn't really matter


Pointless to reinvent the wheel if it already has a implementation in .NET. The process class has everything you need and then some.
Back to top
View user's profile Send private message
Hieroglyphics
I post too much
Reputation: 0

Joined: 06 Dec 2007
Posts: 2007
Location: Your bedroom

PostPosted: Thu Oct 23, 2008 4:51 pm    Post subject: Reply with quote

Zan.exe wrote:
why do I get an error when posting it in a clean new project in project.cs?

Error 1 The name 'InitializeComponent' does not exist in the current context C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Program.cs 61 13 WindowsFormsApplication1


You just showed us that the bot in your siggy is fake

_________________

Back to top
View user's profile Send private message AIM Address MSN Messenger
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Fri Oct 24, 2008 7:07 am    Post subject: Reply with quote

Hieroglyphics wrote:
Zan.exe wrote:
why do I get an error when posting it in a clean new project in project.cs?

Error 1 The name 'InitializeComponent' does not exist in the current context C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Program.cs 61 13 WindowsFormsApplication1


You just showed us that the bot in your siggy is fake

They always are. Rolling Eyes

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Zan.exe
Grandmaster Cheater
Reputation: 0

Joined: 22 Feb 2007
Posts: 752
Location: The U.S. of A.

PostPosted: Fri Oct 24, 2008 9:58 am    Post subject: Reply with quote

did I say it was real?
It's the GUI for the bot I plan to make.
what's wrong with that? anyone?
If you don't like it, faggot it (hopefully your smart enough to be using firefox and faggot)

_________________
PM Me if you play FFXI - Bismark Server
Lv75 BST

Almost all the mods on CEF are morons.

<3 SunBeam
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