• 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tutorial C# Trainer Source
#1
PHP Code:
using System;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace 
MMOhaxCsharpTrainerBase
{
    public 
partial class Trainer Form
    
{
        public 
Trainer()
        {
            
InitializeComponent();
        }

        
// imports from WinAPI, for more information see http://www.pinvoke.net/ and http://msdn.microsoft.com/

        // http://www.pinvoke.net/default.aspx/kernel32/WriteProcessMemory.html
        // WriteProcessMemory writes memory to a specific address in the target process memory space
        
[DllImport("kernel32.dll"EntryPoint "WriteProcessMemory")]
        private static 
extern bool WriteProcessMemory(IntPtr hProcessIntPtr lpBaseAddressbyte[] lpBufferuint nSize, [Outint lpNumberOfBytesWritten);

        
// http://www.pinvoke.net/default.aspx/kernel32/ReadProcessMemory.html
        // ReadProcessMemory reads memory from a specified address in the target process memory space
        
[DllImport("kernel32.dll"EntryPoint "ReadProcessMemory")]
        private static 
extern bool ReadProcessMemory(IntPtr hProcessIntPtr lpBaseAddress, [Outbyte[] lpBufferint dwSize, [Outint lpNumberOfBytesRead);
        [
DllImport("kernel32.dll"EntryPoint "ReadProcessMemory")]
        private static 
extern bool ReadProcessMemory(IntPtr hProcessIntPtr lpBaseAddress, [OutIntPtr lpBufferint dwSize, [Outint lpNumberOfBytesRead);

        
// http://www.pinvoke.net/default.aspx/kernel32/OpenProcess.html
        // OpenProcess is used to open the process (obviously)
        
[DllImport("kernel32.dll"EntryPoint "OpenProcess")]
        private static 
extern IntPtr OpenProcess(uint dwDesiredAccessbool bInheritHandleint dwProcessId);

        private static 
int ProcessID = -1// will hold ID of the game process
        
private static IntPtr ProcessHandle IntPtr.Zero// will hold handle to the game process

        // Connect function will open the game process
        
private bool Connect()
        {
            
Process.EnterDebugMode(); // gain debug privileges

            // GetProcessesByName gets all running processes with the specified name
            
Process[] processes Process.GetProcessesByName("winmine"); // winmine.exe is Windows XP Minesweeper
            
ProcessID processes[0].Id// assume the first found process is the correct one, because otherwise 2 instances of the game would be running

            
if (ProcessID == 0)
            {
                
// game process not found
                
Process.LeaveDebugMode();
                return 
false;
            }

            
// open process and save the handle of it
            // we start looking up OpenProcess at MSDN http://msdn.microsoft.com/en-us/library/ms684320(VS.85).aspx
            // "The access to the process object. This access right is checked against the security descriptor for the process. This parameter can be one or more of the process access rights."
            // click the link to "process access rights", http://msdn.microsoft.com/en-us/library/ms684880(v=VS.85).aspx
            // PROCESS_ALL_ACCESS  -  All possible access rights for a process object.
            // yeah, we might aswell use that
            // if we look at http://www.pinvoke.net/default.aspx/kernel32/OpenProcess.html
            // we see that All = 0x001F0FFF
            
ProcessHandle OpenProcess(0x001F0FFF/*PROCESS_ALL_ACCESS*/falseProcessID);

            return 
true;
        }

        
// Disconnect function will close the game process & clean up
        
private void Disconnect()
        {
            
Process.LeaveDebugMode(); // no need to still have debug privileges
        
}

        private 
uint adrTime 0x0100579C// this is the address where time-variable is located in Windows XP Minesweeper, get this with Cheat Engine
        
private uint freezeTime 0;

        private 
void checkBox_CheckedChanged(object senderEventArgs e)
        {
            if (
Connect() == false) { return; }

            
byte[] buffer = new byte[4];
            
ReadProcessMemory(ProcessHandle, (IntPtr)adrTimebufferbuffer.Length0);
            
freezeTime BitConverter.ToUInt32(buffer0);

            
Disconnect();
        }

        private 
void timer_Tick(object senderEventArgs e)
        {
            if (
Connect() == false) { return; }

            if (
checkBox.Checked == true// if the "freeze value" checkbox is ticked, make sure the value is same as when frozen
            
{
                
WriteProcessMemory(ProcessHandle, (IntPtr)adrTimeBitConverter.GetBytes(freezeTime), 4/*an int is 4 bytes in size*/0);
            }

            
byte[] buffer = new byte[4];
            
ReadProcessMemory(ProcessHandle, (IntPtr)adrTimebufferbuffer.Length0);

            
uint Time BitConverter.ToUInt32(buffer0);
            
textBox.Text Time.ToString();

            
Disconnect();
        }

        private 
void button_Click(object senderEventArgs e)
        {
            if (
Connect() == false) { return; }

            
// set game timer to 0 when button is clicked
            
WriteProcessMemory(ProcessHandle, (IntPtr)adrTimeBitConverter.GetBytes(0), 4/*an int is 4 bytes in size*/0);
            
freezeTime 0;

            
Disconnect();
        }

        private 
void pictureBox_Click(object senderEventArgs e)
        {
            
// when picture is clicked, open website
            
System.Diagnostics.Process.Start("http://www.mmohax.com/");
        }
    }


Source used in this Trainer for example:
http://www.itsmods.com/forum/Thread-Call...ainer.html

Credits:
mmohax


Attached Files
.zip   MMOhaxCsharpTrainerBase.zip (Size: 20.94 KB / Downloads: 136)
[-] The following 4 users say Thank You to d0h! for this post:
  • AdamOwnz, Ferrari, Superbird, xplosiff
  Reply
#2
Cheers for this bro. The code is commented so its easy for me to understand it. I know enough C# to make something out of it already but I'm new to the memory editing.
  Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  [Release] [SOURCE] Random Weapons. [HARD] Tony. 1 1,174 11-08-2013, 11:11
Last Post: Nekochan
  Help source random weapons [HARD] Tony. 4 724 11-08-2013, 05:25
Last Post: [HARD] Tony.
  [Request] Health and Points on hud source robinvm 7 959 10-27-2013, 08:23
Last Post: robinvm
  [Release] [SOURCE] DOOR V2.0 [HARD] Tony. 5 1,386 09-26-2013, 14:01
Last Post: Nekochan
  [source] medic E-losev 6 1,144 07-26-2013, 06:18
Last Post: E-losev
  [source] vAmpIr E-losev 5 996 07-25-2013, 16:28
Last Post: Bandarigoda123
  [Release] Black Ops Single Player/Zombie Trainer V3.6 Craig87 52 32,578 07-01-2013, 15:12
Last Post: explosivebanana55
  [Release] Barata's REAL External Console Source C# barata 37 6,472 06-28-2013, 23:47
Last Post: barata
  [Release] LF's BO2 Trainer (Latest Version) LegitFlash 3 1,462 06-11-2013, 18:14
Last Post: surtek
  Black Ops 2 DLC camo trainer surtek 10 4,217 04-19-2013, 23:16
Last Post: Gladio

Forum Jump:


Users browsing this thread: 1 Guest(s)