Advertisement
Guest User

SAMP Weather Tool in c#, source code

a guest
Sep 24th, 2013
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Diagnostics;
  10. using System.Runtime.InteropServices;
  11. using System.Management.Instrumentation;
  12.  
  13. namespace Memory
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         #region Basic Stuff
  18.  
  19.         [DllImport("kernel32.dll")]
  20.         private static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesWritten);
  21.         [DllImport("kernel32.dll")]
  22.         private static extern Int32 WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesWritten);
  23.         IntPtr pHandel;
  24.         public bool Process_Handle(string ProcessName)
  25.         {
  26.             try
  27.             {
  28.                 Process[] ProcList = Process.GetProcessesByName(ProcessName);
  29.                 if (ProcList.Length == 0)
  30.                     return false;
  31.                 else
  32.                 {
  33.                     pHandel = ProcList[0].Handle;
  34.                     return true;
  35.                 }
  36.             }
  37.             catch (Exception ex)
  38.             { Console.Beep(); Console.WriteLine("Process_Handle - " + ex.Message); return false; }
  39.         }
  40.         private byte[] Read(int Address, int Length)
  41.         {
  42.             byte[] Buffer = new byte[Length];
  43.             IntPtr Zero = IntPtr.Zero;
  44.             ReadProcessMemory(pHandel, (IntPtr)Address, Buffer, (UInt32)Buffer.Length, out Zero);
  45.             return Buffer;
  46.         }
  47.         private void Write(int Address, int Value)
  48.         {
  49.             byte[] Buffer = BitConverter.GetBytes(Value);
  50.             IntPtr Zero = IntPtr.Zero;
  51.             WriteProcessMemory(pHandel, (IntPtr)Address, Buffer, (UInt32)Buffer.Length, out Zero);
  52.         }
  53.         private void Write2(int Address, float Value)
  54.         {
  55.             byte[] Buffer = BitConverter.GetBytes(Value);
  56.             IntPtr Zero = IntPtr.Zero;
  57.             WriteProcessMemory(pHandel, (IntPtr)Address, Buffer, (UInt32)Buffer.Length, out Zero);
  58.         }
  59.         public void WriteFloat(int Address, float Value)
  60.         {
  61.             Write2(Address, Value);
  62.         }
  63.         #endregion
  64.  
  65.         //This is the part you want to edit
  66.         #region Write Functions (Integer & String)
  67.         public void WriteInteger(int Address, int Value)
  68.         {
  69.             Write(Address, Value);
  70.         }
  71.  
  72.  
  73.         public void WriteString(int Address, string Text)
  74.         {
  75.             byte[] Buffer = new ASCIIEncoding().GetBytes(Text);
  76.             IntPtr Zero = IntPtr.Zero;
  77.             WriteProcessMemory(pHandel, (IntPtr)Address, Buffer, (UInt32)Buffer.Length, out Zero);
  78.         }
  79.         public void WriteBytes(int Address, byte[] Bytes)
  80.         {
  81.             IntPtr Zero = IntPtr.Zero;
  82.             WriteProcessMemory(pHandel, (IntPtr)Address, Bytes, (uint)Bytes.Length, out Zero);
  83.         }
  84.         public void WriteNOP(int Address)
  85.         {
  86.             byte[] Buffer = new byte[] { 0x90, 0x90, 0x90, 0x90, 0x90 };
  87.             IntPtr Zero = IntPtr.Zero;
  88.             WriteProcessMemory(pHandel, (IntPtr)Address, Buffer, (UInt32)Buffer.Length, out Zero);
  89.         }
  90.  
  91.  
  92.         #endregion
  93.         #region Read Functions (Integer & String)
  94.         public int ReadInteger(int Address, int Length = 4)
  95.         {
  96.             return BitConverter.ToInt32(Read(Address, Length), 0);
  97.  
  98.         }
  99.         public float ReadFloat(int Address, int Length = 8)
  100.         {
  101.             return BitConverter.ToSingle(Read(Address, Length), 0);
  102.  
  103.         }
  104.  
  105.         public string ReadString(int Address, int Length = 4)
  106.         {
  107.             return new ASCIIEncoding().GetString(Read(Address, Length));
  108.  
  109.         }
  110.         public byte[] ReadBytes(int Address, int Length)
  111.         {
  112.             return Read(Address, Length);
  113.  
  114.  
  115.         }
  116.  
  117.  
  118.         #endregion
  119.  
  120.         [DllImport("kernel32.dll")]
  121.         static extern bool VirtualProtectEx(IntPtr hProcess, int lpAddress,
  122.            UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);
  123.  
  124.         public enum Protection : uint
  125.         {
  126.             PAGE_NOACCESS = 0x01,
  127.             PAGE_READONLY = 0x02,
  128.             PAGE_READWRITE = 0x04,
  129.             PAGE_WRITECOPY = 0x08,
  130.             PAGE_EXECUTE = 0x10,
  131.             PAGE_EXECUTE_READ = 0x20,
  132.             PAGE_EXECUTE_READWRITE = 0x40,
  133.             PAGE_EXECUTE_WRITECOPY = 0x80,
  134.             PAGE_GUARD = 0x100,
  135.             PAGE_NOCACHE = 0x200,
  136.             PAGE_WRITECOMBINE = 0x400
  137.         }
  138.  
  139.         public Form1()
  140.         {
  141.             InitializeComponent();
  142.         }
  143.  
  144.         private void Form1_Load(object sender, EventArgs e)
  145.         {
  146.            
  147.  
  148.             System.Management.ManagementObjectSearcher Processes = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_Process Where Name ='gta_sa.exe' ");
  149.  
  150.             string user = Environment.UserName;
  151.  
  152.             foreach (System.Management.ManagementObject process in Processes.Get())
  153.             {
  154.                 if (process["ExecutablePath"] != null)
  155.                 {
  156.                     string[] OwnerInfo = new string[2];
  157.                     process.InvokeMethod("GetOwner", (object[])OwnerInfo);
  158.  
  159.  
  160.                     if (OwnerInfo[0] == user)
  161.                     {
  162.                         uint processId = (uint)process["ProcessId"];
  163.                         Process pro = Process.GetProcessById((int)processId);
  164.                         pHandel = pro.Handle;
  165.                     }
  166.  
  167.  
  168.                 }
  169.  
  170.             }
  171.            
  172.         }
  173.  
  174.        
  175.    
  176.         private void button1_Click_1(object sender, EventArgs e)
  177.         {
  178.             if (listBox1.SelectedIndex == -1)
  179.                 MessageBox.Show("Noob, you didn't selected any weather.", "Newbie eror 404");
  180.             else
  181.             {
  182.                 #region luam gta in useru asta
  183.  
  184.                 System.Management.ManagementObjectSearcher Processes = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_Process Where Name ='gta_sa.exe' ");
  185.  
  186.                 string user = Environment.UserName;
  187.  
  188.                 foreach (System.Management.ManagementObject process in Processes.Get())
  189.                 {
  190.                     if (process["ExecutablePath"] != null)
  191.                     {
  192.                         string[] OwnerInfo = new string[2];
  193.                         process.InvokeMethod("GetOwner", (object[])OwnerInfo);
  194.  
  195.  
  196.                         if (OwnerInfo[0] == user)
  197.                         {
  198.                             uint processId = (uint)process["ProcessId"];
  199.                             Process pro = Process.GetProcessById((int)processId);
  200.                             pHandel = pro.Handle;
  201.                         }
  202.  
  203.  
  204.                     }
  205.  
  206.                 }
  207.                 #endregion
  208.  
  209.                 WriteInteger(0xC81320, listBox1.SelectedIndex);
  210.             }
  211.              
  212.         }
  213.  
  214.         private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  215.         {
  216.             System.Diagnostics.Process.Start("http://ugbase.eu/");
  217.         }
  218.        
  219.      
  220.     }
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement