关闭

[无聊]扫雷外挂(for win2000)

标签: integerdestructorconstructorfunctionbuttondelphi
972人阅读 评论(0) 收藏 举报

终于有时间干些无聊的事情了.于是偶打开Delphi,在Form1上摆了一个按钮,命名为Button1(汗,多标准的名字),然后输入以下代码:

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;

type

  TWinMineData = class
  private
    FData: PByteArray;
    FWidth: Integer;
    FHeight: Integer;
  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;
  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;
begin
  ProcId := 0;
  GetWindowThreadProcessId(AWnd, ProcId);
  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);
  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.

于是偶也当了一回达淫-___-b 惭愧惭愧~~

这是运行后的截图

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:103923次
    • 积分:1513
    • 等级:
    • 排名:千里之外
    • 原创:41篇
    • 转载:0篇
    • 译文:0篇
    • 评论:65条
    最新评论