Shrooms

Horse

Jan 30th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.54 KB | None | 0 0
  1. #region Declarations
  2. using System;
  3. using System.IO;
  4. using System.Net;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Drawing;
  9. using System.Threading;
  10. using System.Diagnostics;
  11. using System.Windows.Forms;
  12. using System.ComponentModel;
  13. using System.Collections.Generic;
  14. using System.Runtime.InteropServices;
  15. using Microsoft.Win32;
  16. using Horse.Properties;
  17. #endregion
  18.  
  19. #region namespace Horse
  20. namespace Horse
  21. {
  22.     #region public partial class Form1 : Form
  23.     public partial class Form1 : Form
  24.     {
  25.         #region Global Variables
  26.         [DllImport("user32.dll", SetLastError = true)]
  27.         private static extern int FindWindow(string lpClassName, string lpWindowName);
  28.  
  29.         [DllImport("kernel32")]
  30.         public static extern IntPtr CreateRemoteThread(
  31.           IntPtr hProcess,
  32.           IntPtr lpThreadAttributes,
  33.           uint dwStackSize,
  34.           UIntPtr lpStartAddress,
  35.           IntPtr lpParameter,
  36.           uint dwCreationFlags,
  37.           out IntPtr lpThreadId
  38.         );
  39.  
  40.         [DllImport("kernel32.dll")]
  41.         public static extern IntPtr OpenProcess(
  42.             UInt32 dwDesiredAccess,
  43.             Int32 bInheritHandle,
  44.             Int32 dwProcessId
  45.             );
  46.  
  47.         [DllImport("kernel32.dll")]
  48.         public static extern Int32 CloseHandle(
  49.         IntPtr hObject
  50.         );
  51.  
  52.         [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
  53.         static extern bool VirtualFreeEx(
  54.             IntPtr hProcess,
  55.             IntPtr lpAddress,
  56.             UIntPtr dwSize,
  57.             uint dwFreeType
  58.             );
  59.  
  60.         [DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
  61.         public static extern UIntPtr GetProcAddress(
  62.             IntPtr hModule,
  63.             string procName
  64.             );
  65.  
  66.         [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
  67.         static extern IntPtr VirtualAllocEx(
  68.             IntPtr hProcess,
  69.             IntPtr lpAddress,
  70.             uint dwSize,
  71.             uint flAllocationType,
  72.             uint flProtect
  73.             );
  74.  
  75.         [DllImport("kernel32.dll")]
  76.         static extern bool WriteProcessMemory(
  77.             IntPtr hProcess,
  78.             IntPtr lpBaseAddress,
  79.             string lpBuffer,
  80.             UIntPtr nSize,
  81.             out IntPtr lpNumberOfBytesWritten
  82.         );
  83.  
  84.         [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
  85.         public static extern IntPtr GetModuleHandle(
  86.             string lpModuleName
  87.             );
  88.  
  89.         [DllImport("kernel32", SetLastError = true, ExactSpelling = true)]
  90.         internal static extern Int32 WaitForSingleObject(
  91.             IntPtr handle,
  92.             Int32 milliseconds
  93.             );
  94.  
  95.         string HorseLibpath = @"C:\ProgramData\HorseLib.dll";
  96.         #endregion
  97.  
  98.         #region public void InjectDLL(IntPtr hProcess, string strDLLName)
  99.         public void InjectDLL(IntPtr hProcess, String strDLLName)
  100.         {
  101.             IntPtr bytesout;
  102.  
  103.             Int32 LenWrite = strDLLName.Length + 1;
  104.             IntPtr AllocMem = (IntPtr)VirtualAllocEx(hProcess, (IntPtr)null, (uint)LenWrite, 0x1000, 0x40);
  105.  
  106.             WriteProcessMemory(hProcess, AllocMem, strDLLName, (UIntPtr)LenWrite, out bytesout);
  107.  
  108.             UIntPtr Injector = (UIntPtr)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
  109.  
  110.             if (Injector == null)
  111.             {
  112.                 return;
  113.             }
  114.  
  115.             IntPtr hThread = (IntPtr)CreateRemoteThread(hProcess, (IntPtr)null, 0, Injector, AllocMem, 0, out bytesout);
  116.  
  117.             if (hThread == null)
  118.             {
  119.                 return;
  120.             }
  121.  
  122.             int Result = WaitForSingleObject(hThread, 10 * 1000);
  123.  
  124.             if (Result == 0x00000080L || Result == 0x00000102L)
  125.             {
  126.                 if (hThread != null)
  127.                 {
  128.                     CloseHandle(hThread);
  129.                 }
  130.                 return;
  131.             }
  132.  
  133.             Thread.Sleep(1000);
  134.             VirtualFreeEx(hProcess, AllocMem, (UIntPtr)0, 0x8000);
  135.  
  136.             if (hThread != null)
  137.             {
  138.                 CloseHandle(hThread);
  139.             }
  140.             timer1.Enabled = false;
  141.             timer2.Enabled = true;
  142.             return;
  143.         }
  144.         #endregion
  145.  
  146.         #region public Int32 GetProcessId(String proc)
  147.         public Int32 GetProcessId(String proc)
  148.         {
  149.             Process[] ProcList;
  150.             ProcList = Process.GetProcessesByName(proc);
  151.             return ProcList[0].Id;
  152.         }
  153.         #endregion
  154.  
  155.         #region public Form1()
  156.         public Form1()
  157.         {
  158.             InitializeComponent();
  159.             if (!File.Exists(HorseLibpath))
  160.             {
  161.                 try
  162.                 {
  163.                     byte[] HorseLib = Resources.HorseLib;
  164.                     File.WriteAllBytes(HorseLibpath, HorseLib);
  165.                 }
  166.                 catch { }
  167.             }
  168.         }
  169.         #endregion
  170.  
  171.         #region private void Form1_Load(object sender, EventArgs e)
  172.         private void Form1_Load(object sender, EventArgs e)
  173.         {
  174.             if (Properties.Settings.Default.MSLocationbool == true)
  175.             {
  176.                 Process.Start(Properties.Settings.Default.MSLocation);
  177.             }
  178.             else
  179.             {
  180.                 RegistryKey MSSubKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wizet\\");
  181.                 RegistryKey MSRegFolder = MSSubKey.OpenSubKey("MapleStory");
  182.  
  183.                 if (MSRegFolder == null)
  184.                 {
  185.                     MessageBox.Show("Can't find the MapleStory location, please launch manually.", "Problem Launching MapleStory", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  186.  
  187.                     this.openFileDialog1.Title = "Find MapleStory...";
  188.                     this.openFileDialog1.FileName = "GameLauncher.exe";
  189.                     this.openFileDialog1.Filter = "Executable | *.exe";
  190.  
  191.                     if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
  192.                     {
  193.                         Properties.Settings.Default.MSLocation = openFileDialog1.FileName;
  194.                         Properties.Settings.Default.MSLocationbool = true;
  195.                         Properties.Settings.Default.Save();
  196.                     }
  197.                     return;
  198.                 }
  199.  
  200.                 string MSLocation = MSRegFolder.GetValue("ExecPath").ToString();
  201.  
  202.                 if (!File.Exists(MSLocation + "\\GameLauncher.exe"))
  203.                 {
  204.                     MessageBox.Show("Can't find the MapleStory location, please launch manually.", "Problem Launching MapleStory", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  205.  
  206.                     this.openFileDialog1.Title = "Find Maple...";
  207.                     this.openFileDialog1.FileName = "GameLauncher.exe";
  208.                     this.openFileDialog1.Filter = "Executable | *.exe";
  209.  
  210.                     if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
  211.                     {
  212.                         Properties.Settings.Default.MSLocation = openFileDialog1.FileName;
  213.                         Properties.Settings.Default.MSLocationbool = true;
  214.                         Properties.Settings.Default.Save();
  215.                     }
  216.                     return;
  217.                 }
  218.                 Process.Start(MSLocation + "\\GameLauncher.exe");
  219.             }
  220.         }
  221.         #endregion
  222.  
  223.         #region private void timer1_Tick(object sender, EventArgs e)
  224.         private void timer1_Tick(object sender, EventArgs e)
  225.         {
  226.             if (File.Exists(HorseLibpath) && (FindWindow("StartUpDlgClass", null) != 0))
  227.             {
  228.                 string strProcessName = "MapleStory";
  229.  
  230.                 Int32 ProcID = GetProcessId(strProcessName);
  231.  
  232.                 if (ProcID >= 0)
  233.                 {
  234.                     IntPtr hProcess = (IntPtr)OpenProcess(0x1F0FFF, 1, ProcID);
  235.                     if (hProcess == null)
  236.                     {
  237.                         MessageBox.Show("OpenProcess() Failed!");
  238.                         return;
  239.                     }
  240.                     else
  241.                         InjectDLL(hProcess, HorseLibpath);
  242.                 }
  243.             }
  244.         }
  245.         #endregion
  246.  
  247.         #region private void timer2_Tick(object sender, EventArgs e)
  248.         private void timer2_Tick(object sender, EventArgs e)
  249.         {
  250.             if (FindWindow(null, "MapleStory") == 0)
  251.             {
  252.                 Environment.Exit(0);
  253.             }
  254.         }
  255.         #endregion
  256.     }
  257.     #endregion
  258. }
  259. #endregion
Advertisement
Add Comment
Please, Sign In to add comment