摘要:[C#],[WinFrom]WinXp掃地雷外掛
只是用於WinXP版本的踩地雷掃雷外掛
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace winmine
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
#region 常量定義
public IntPtr ProcHwnd = IntPtr.Zero;
const int WM_LBUTTONDOWN = 0x201; //滑鼠左鍵按下
const int WM_LBUTTONUP = 0x202; //滑鼠左鍵彈起
const int WM_RBUTTONDOWN = 0x204; //滑鼠右鍵彈起
const int WM_RBUTTONUP = 0x205; //滑鼠右鍵彈起
#endregion
public const UInt32 PROCESS_VM_READ = (0x0010);//允許讀取踩地雷記憶體位置
public Process[] pro = Process.GetProcessesByName("winmine");//獲取踩地雷程式
#region WinAPI32
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(UInt32 dwDesiredAccess, Int32 bInheritHandle, UInt32 dwProcessId);
[DllImport("kernel32.dll")]
public static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead);
[DllImport("user32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
[DllImport("kernel32.dll")]
public static extern Int32 CloseHandle(IntPtr hObject);
#endregion
private void button1_Click(object sender, EventArgs e)
{
IntPtr hWnd = FindWindow(null, "踩地雷");
if (hWnd == IntPtr.Zero)//判斷是否有開啟踩地雷
{
MessageBox.Show("踩地雷沒有開啟嘿!!");
}
else
{
int iCellBaseAddress = 0x1005340;//地雷記憶體位置
//int iWidthAddress = 0x10056a8; //寬度
//int iHeightAddress = 0x10056ac; //高度
//int iMinesAddress = 0x1005194; //地雷總數
int lparam, x, y, Width, Height; //定義x座標、y座標、雷區寬度、高度。
byte[] memory;//記憶體暫存
byte[] buffer = new byte[1];//讀取記憶體內容
int iCellAddress;
IntPtr ptrBytesReaded;
ProcHwnd = OpenProcess(PROCESS_VM_READ, 1, (uint)pro[0].Id);//獲取踩地雷PID
//開始掃雷
for (Height = 0; Height <= 24; Height++)//迴圈開始....
{
y = 60 + 16 * Height;//y座標60加上踩地雷框框大小乘上第幾個位置等於y實際座標
for (Width = 0; Width <= 30; Width++)
{
x = 20 + 16 * Width;//x座標20加上踩地雷框框大小乘上第幾個位置等於x實際座標
iCellAddress = (iCellBaseAddress) + (32 * (Height + 1)) + (Width + 1);//記憶體位置+32乘上高+寬等於目前踩地雷ㄎ大小
ReadProcessMemory(ProcHwnd, (IntPtr)iCellAddress, buffer, 1, out ptrBytesReaded);//讀取踩地雷記憶體位置內容
memory = buffer;
if (memory[0] == 0x8f)//判斷是否為地雷
{
lparam = x + (y << 16);//y座標往左位移16+x座標
SendMessage(hWnd, WM_RBUTTONDOWN, 0, lparam);//傳送按下右鍵訊息給踩地雷程式
SendMessage(hWnd, WM_RBUTTONUP, 0, lparam); //傳送彈起右鍵訊息給踩地雷程式
Thread.Sleep(1);//延遲
}
else
{
lparam = x + (y << 16);//y座標往左位移16+x座標
SendMessage(hWnd, WM_LBUTTONDOWN, 0, lparam);//傳送按下左鍵訊息給踩地雷程式
SendMessage(hWnd, WM_LBUTTONUP, 0, lparam); //傳送彈起左鍵訊息給踩地雷程式
Thread.Sleep(1);//延遲
}
}
}
//迴圈結束...
int iRetValue;
iRetValue = CloseHandle(ProcHwnd);//關閉ProcHwnd,並釋放資源
if (iRetValue == 0)
throw new Exception("CloseHandle failed");
}
}
}
}
程式含原始碼:winmine.rar
參考:http://www.codeproject.com/KB/trace/minememoryreader.aspx
我只是個小小的入門者