1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[help] code to trainer in C#

Discussion in 'Programming' started by blabba2, Sep 10, 2010.

  1. blabba2

    blabba2 CCPLZ Donor Donor

    Oke i figured out im gonna try create own trainer and this is my "try" but im getting this errors i dont really understand how to fix.


    pic off errors:
    http://i52.tinypic.com/6f2yh5.jpg


    I used a.. CSharp trainer making or some but.. needed to edit a little on the code what it gave o.o''


    No i cant really some basic C#, im looking for a translated c# book in norwegian so i can teach (:


    Thx for help
     
  2. highlights

    highlights Well-Known Member

    should not
    byte{}
    be
    byte[]
     
  3. blabba2

    blabba2 CCPLZ Donor Donor

  4. Lapheoria

    Lapheoria New Member

    Change "memory" to something else.
    Add a new class and include this in :
    Code (Text):
    1. using System;
    2. using System.Diagnostics;
    3. using System.Runtime.InteropServices;
    4.  
    5. namespace ProcessMemoryReaderLib
    6. {
    7.     /// <summary>
    8.     /// ProcessMemoryReader is a class that enables direct reading a process memory
    9.     /// </summary>
    10.     class ProcessMemoryReaderApi
    11.     {
    12.         // constants information can be found in <winnt.h>
    13.         [Flags]
    14.         public enum ProcessAccessType
    15.         {
    16.             PROCESS_TERMINATE           = (0x0001),
    17.             PROCESS_CREATE_THREAD       = (0x0002),
    18.             PROCESS_SET_SESSIONID       = (0x0004),
    19.             PROCESS_VM_OPERATION        = (0x0008),
    20.             PROCESS_VM_READ             = (0x0010),
    21.             PROCESS_VM_WRITE            = (0x0020),
    22.             PROCESS_DUP_HANDLE          = (0x0040),
    23.             PROCESS_CREATE_PROCESS      = (0x0080),
    24.             PROCESS_SET_QUOTA           = (0x0100),
    25.             PROCESS_SET_INFORMATION     = (0x0200),
    26.             PROCESS_QUERY_INFORMATION   = (0x0400)
    27.         }
    28.        
    29.         // function declarations are found in the MSDN and in <winbase.h>
    30.        
    31.         //      HANDLE OpenProcess(
    32.         //          DWORD dwDesiredAccess,  // access flag
    33.         //          BOOL bInheritHandle,    // handle inheritance option
    34.         //          DWORD dwProcessId       // process identifier
    35.         //          );
    36.         [DllImport("kernel32.dll")]
    37.         public static extern IntPtr OpenProcess(UInt32 dwDesiredAccess, Int32 bInheritHandle, UInt32 dwProcessId);
    38.  
    39.         //      BOOL CloseHandle(
    40.         //          HANDLE hObject   // handle to object
    41.         //          );
    42.         [DllImport("kernel32.dll")]
    43.         public static extern Int32 CloseHandle(IntPtr hObject);
    44.  
    45.         //      BOOL ReadProcessMemory(
    46.         //          HANDLE hProcess,              // handle to the process
    47.         //          LPCVOID lpBaseAddress,        // base of memory area
    48.         //          LPVOID lpBuffer,              // data buffer
    49.         //          SIZE_T nSize,                 // number of bytes to read
    50.         //          SIZE_T * lpNumberOfBytesRead  // number of bytes read
    51.         //          );
    52.         [DllImport("kernel32.dll")]
    53.         public static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,[In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead);
    54.    
    55.         //      BOOL WriteProcessMemory(
    56.         //          HANDLE hProcess,                // handle to process
    57.         //          LPVOID lpBaseAddress,           // base of memory area
    58.         //          LPCVOID lpBuffer,               // data buffer
    59.         //          SIZE_T nSize,                   // count of bytes to write
    60.         //          SIZE_T * lpNumberOfBytesWritten // count of bytes written
    61.         //          );
    62.         [DllImport("kernel32.dll")]
    63.         public static extern Int32 WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,[In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesWritten);
    64.    
    65.        
    66.     }
    67.  
    68.     public class ProcessMemoryReader
    69.     {
    70.  
    71.         public ProcessMemoryReader()
    72.         {
    73.         }
    74.  
    75.         /// <summary>  
    76.         /// Process from which to read     
    77.         /// </summary>
    78.         public Process ReadProcess
    79.         {
    80.             get
    81.             {
    82.                 return m_ReadProcess;
    83.             }
    84.             set
    85.             {
    86.                 m_ReadProcess = value;
    87.             }
    88.         }
    89.  
    90.         private Process m_ReadProcess = null;
    91.  
    92.         private IntPtr m_hProcess = IntPtr.Zero;
    93.  
    94.         public void OpenProcess()
    95.         {
    96. //          m_hProcess = ProcessMemoryReaderApi.OpenProcess(ProcessMemoryReaderApi.PROCESS_VM_READ, 1, (uint)m_ReadProcess.Id);
    97.             ProcessMemoryReaderApi.ProcessAccessType access;
    98.             access = ProcessMemoryReaderApi.ProcessAccessType.PROCESS_VM_READ
    99.                 | ProcessMemoryReaderApi.ProcessAccessType.PROCESS_VM_WRITE
    100.                 | ProcessMemoryReaderApi.ProcessAccessType.PROCESS_VM_OPERATION;
    101.                 m_hProcess = ProcessMemoryReaderApi.OpenProcess((uint)access, 1, (uint)m_ReadProcess.Id);
    102.         }
    103.  
    104.         public void CloseHandle()
    105.         {
    106.             int iRetValue;
    107.             iRetValue = ProcessMemoryReaderApi.CloseHandle(m_hProcess);
    108.             if (iRetValue == 0)
    109.                 throw new Exception("CloseHandle failed");
    110.         }
    111.  
    112.         public byte[] ReadProcessMemory(IntPtr MemoryAddress, uint bytesToRead, out int bytesRead)
    113.         {
    114.             byte[] buffer = new byte[bytesToRead];
    115.            
    116.             IntPtr ptrBytesRead;
    117.             ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess,MemoryAddress,buffer ,bytesToRead,out ptrBytesRead);
    118.            
    119.             bytesRead = ptrBytesRead.ToInt32();
    120.  
    121.             return buffer;
    122.         }
    123.  
    124.         public void WriteProcessMemory(IntPtr MemoryAddress, byte[] bytesToWrite ,out int bytesWritten)
    125.         {
    126.             IntPtr ptrBytesWritten;
    127.             ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess,MemoryAddress,bytesToWrite,(uint)bytesToWrite.Length,out ptrBytesWritten);
    128.            
    129.             bytesWritten = ptrBytesWritten.ToInt32();
    130.         }
    131.  
    132.        
    133.  
    134.  
    135.     }
    136. }
     
  5. highlights

    highlights Well-Known Member

  6. GroundZero

    GroundZero LOL Banned Coder Donor

    so partymagnus is 100% right you cann?t use a already token variable/namespace .
    so you try in this example to load the bytes in a namespace
     

Share This Page