[再次无聊]扫雷外挂for win2000&xp

原创 2006年06月14日 18:20:00

在form1上摆了button1之后,偶又改写了如下的东东,让偶的外挂可以支持xp的扫雷。真是大快人心(-___-b)

unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

const
  BOMB_MAP_MAX_SIZE = 32 * 24;
  ADDR_MAPHEIGHT    = $01005A68;
  ADDR_MAPWIDTH     = $010056F8;
  ADDR_BOMBMAP      = $01005720;
  ADDR_MAPHEIGHT_XP = $01005338;
  ADDR_MAPWIDTH_XP  = $01005334;
  ADDR_BOMBMAP_XP   = $01005360;

type

  TWinMineData = class
  private
    FData: PByteArray;
    FWidth: Integer;
    FHeight: Integer;
    FIsXP: Boolean;
  public
    constructor Create;
    destructor Destroy; override;
    procedure Init(AWnd: HWND);
    function GetAt(X, Y: Integer): Byte;
    property Width: Integer read FWidth;
    property Height: Integer read FHeight;
    property IsXP: Boolean read FIsXP;
  end;

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    function GetBlockPoint(AWnd: HWND; X, Y: Integer): TPoint;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  Wnd: HWND;
  Data: TWinMineData;
  I, J: Integer;
  Pt: TPoint;
begin
  Wnd := FindWindow('扫雷', nil);
  if Wnd = 0 then ShowMessage('请先启动扫雷')
  else
  begin
    Data := TWinMineData.Create;
    try
      Data.Init(Wnd);
      for J := 0 to Data.Height - 1 do
      begin
        for I := 0 to Data.Width - 1 do
        begin
          Pt := GetBlockPoint(Wnd, I, J);
          if (Data.GetAt(I, J) and $80) <> 0 then
          begin
            PostMessage(Wnd, WM_RBUTTONDOWN, 0, MAKELPARAM(Pt.X, Pt.Y));
            PostMessage(Wnd, WM_RBUTTONUP, 0, MAKELPARAM(Pt.X, Pt.Y));
          end
          else
          begin
            PostMessage(Wnd, WM_LBUTTONDOWN, 0, MAKELPARAM(Pt.X, Pt.Y));
            PostMessage(Wnd, WM_LBUTTONUP, 0, MAKELPARAM(Pt.X, Pt.Y));
          end;
        end;
      end;
    finally
      FreeAndNil(Data);
    end;
  end;
end;

{ TWinMineData }

constructor TWinMineData.Create;
begin
  FData := AllocMem(BOMB_MAP_MAX_SIZE);
end;

destructor TWinMineData.Destroy;
begin
  FreeMem(FData);
  inherited;
end;

function TWinMineData.GetAt(X, Y: Integer): Byte;
begin
  Result := FData[Y * 32 + (X + 1)];
end;

procedure TWinMineData.Init(AWnd: HWND);
var
  ProcId: Cardinal;
  HProc: HMODULE;
  Readed: Cardinal;
  R: TRect;
  L: Integer;
begin
  ProcId := 0;
  GetWindowThreadProcessId(AWnd, ProcId);
  GetClientRect(AWnd, R);
  if ProcId = 0 then raise Exception.Create('process id get failed');
  HProc := OpenProcess(PROCESS_VM_READ, False, ProcId);
  try
    ReadProcessMemory(HProc, Pointer(ADDR_MAPWIDTH), @FWidth, 4, Readed);
    ReadProcessMemory(HProc, Pointer(ADDR_MAPHEIGHT), @FHeight, 4, Readed);
    ReadProcessMemory(HProc, Pointer(ADDR_BOMBMAP), FData, BOMB_MAP_MAX_SIZE, Readed);
    L := R.Bottom - R.Top - FHeight * 16;
    if L <> 83 then
    begin
      FIsXP := True;
      ReadProcessMemory(HProc, Pointer(ADDR_MAPWIDTH_XP), @FWidth, 4, Readed);
      ReadProcessMemory(HProc, Pointer(ADDR_MAPHEIGHT_XP), @FHeight, 4, Readed);
      ReadProcessMemory(HProc, Pointer(ADDR_BOMBMAP_XP), FData, BOMB_MAP_MAX_SIZE, Readed);
    end;
  finally
    CloseHandle(HProc);
  end;
end;

function TForm1.GetBlockPoint(AWnd: HWND; X, Y: Integer): TPoint;
begin
  Result.X := X * 16 + 19;
  Result.Y := Y * 16 + 64;
end;

end.

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

在Win 2000/XP下调整硬盘分区与盘符 转

在Win 2000/XP下调整硬盘分区与盘符 中国电脑教育报 飞鱼 很多用户都知道,使用Windows XP的安装盘,可以直接在没有进行分区和格式化的硬盘上安装Windows XP。其实,W...

WinCE和Win2000/XP设备驱动开发的区别

关键字:WinCE Win2000/XP 驱动程序 引 言     Windows CE是一个32位、多任务、多线程的嵌入式操作系统,是微软专门为信息设备、移动应用、消费类电子产品、嵌入式应用等...

解决SQL server 2000 个人版 XP能用 不能在win7 64位系统上安装的问题

最近学习到数据库这个课程,但是看见
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)