acme minechan

Post on 05-Dec-2014

6.471 Views

Category:

Technology

6 Downloads

Preview:

Click to see full reader

DESCRIPTION

Perlで無理ゲーム攻略 (How to play Win32::GuiTest)http://yapcasia.org/2011/talk/32某MMORPGでゲーム中にPerlの同時起動を遮断する機能が追加されたことがありました。Win32::GuiTest や Win32::Screenshot などのモジュールを利用して、Windows上で動作するゲームを自動でプレイするPerlプログラムを作成する方法について解説します。Once upon a time, perl.exe was banned during a game by MMORPG.I will explain how to create the Perl bot program which playsautomatically games on Windows using some modules such asWin32::GuiTest and Win32::Screenshot.

TRANSCRIPT

Perlで無理ゲーム攻略 How to play Win32::GuiTest

TAKESAKO

<takesako@shibuya.pm.org>

Once upon a time

昔むかし

There was a MMORPG

あるところに MMORPG が

perl.exe was banned

Perl.exe を 遮断しました

http://www.ragnarokonline.jp/news/information/notice/item/7732

Perl.exe was banned…

Perl.exe was banned…

Why? どうして?

RMT (Real Money Trading) on MMORPG

Virtual Money Real Money

Making Bot (Computer game bot) with Perl

Hardware Bot

Hardware Bot

Making Software Bot

1. Network emulation

packet, socket, LWP (Perl)

2. Web Application

Selenium Core (JavaScript)

Selenium IDE (Firefox extension)

Selenium RC (Java/Python)

3. Windows Application

Win32::GuiTest (Perl)

Win32::Screenshot (Perl)

s.a. @turugina 日常業務でperlを使おう

http://yapcasia.org/2011/talk/109

Demo

(1) Win32::GuiTest

SendKeys($keys[,$delay])

use Win32::GuiTest qw(SendKeys); system("start notepad.exe"); # & sleep(1); SendKeys("foo{ENTER}"); SendKeys("bar{ENTER}"); SendKeys("bar{BS}z{ENTER}");

SendKeys($keys)

Name Action {BACKSPACE} Backspace {BS} Backspace {BKSP} Backspace {BREAK} Break {CAPS} Caps Lock {DELETE} Delete {DOWN} Down arrow {END} End {ENTER} Enter {ESCAPE} Escape {HELP} Help key {HOME} Home {INSERT} Insert {LEFT} Left arrow {NUMLOCK} Num lock {PGDN} Page down {PGUP} Page up

Name Action {PRTSCR} Print screen {RIGHT} Right arrow {SCROLL} Scroll lock {TAB} Tab {UP} Up arrow {PAUSE} Pause {F1} Function Key 1 ... ... {F24} Function Key 24 {SPC} Spacebar {SPACE} Spacebar {SPACEBAR} Spacebar {LWI} Left Windows Key {RWI} Right Windows Key {APP} Open Context Menu Key

(2) FindWindowLike, GetWindowRect

GetWindowText, GetClassName

use Win32::GuiTest qw(:ALL); system("start calc.exe"); sleep(1); my @id = FindWindowLike(undef,"^電卓","",undef,1);

my $id = $id[0]; print GetWindowText($id), "¥n"; print GetClassName ($id), "¥n"; my ($x1, $y1, $x2, $y2) = GetWindowRect($id); print "($x1, $y1)->($x2, $y2)", "¥n";

(3) Win32::Screenshot

CaputureRect #=> Image::Magick object

use Win32::Screenshot qw(CaptureRect); my $img = CaptureRect(20, 10, 800, 500); print $img; # Image::Magick=ARRAY(0xbeef) $img->Write("x.png"); # save system("start x.png"); # view

(4) Win32::GuiTest & Win32::Screenshot

Capture only “calc.exe” window

use Win32::GuiTest qw(:ALL); use Win32::Screenshot qw(CaptureRect); system("start calc.exe"); sleep(1); my @id = FindWindowLike(undef,"^電卓","",undef,1);

my ($x1, $y1, $x2, $y2) = GetWindowRect($id[0]); my $img = CaptureRect($x1,$y1, $x2-$x1,$y2-$y1); $img->Write("x.png"); # save system("start x.png"); # view

(5) {Image::Magick}->Get("signature")

Image binary SHA-256 digest string

use Win32::Screenshot qw(CaptureRect); my $img = CaptureRect(20, 10, 800, 500); $img; # Image::Magick=ARRAY(0xbeef) print $img->Get("signature"),"¥n"; # SHA-256 $img = new Image::Magick; $img->Read("x.png"); print $img->Get("signature"),"¥n"; # SHA-256

(6) Win32::GuiTest でマウスを操作する

MouseMoveAbsPix($x, $y)

use Win32::GuiTest qw(:ALL); for ($x = 0; $x < 900; $x += 2) { $y = sin($x / 60) * 300 + 400; MouseMoveAbsPix($x, $y); }

(7) Win32::GuiTest でマウスをクリックする

SendMouse($command)

use Win32::GuiTest qw(:ALL); for (1..5) { SendMouse("{LEFTCLICK}"); sleep(1); SendMouse("{RIGHTCLICK}"); sleep(1); }

Win32::GuiTest::SendMouse($command)

{LEFTDOWN} left button down {LEFTUP} left button up {MIDDLEDOWN} middle button down {MIDDLEUP} middle button up {RIGHTDOWN} right button down {RIGHTUP} right button up {LEFTCLICK} left button single click {MIDDLECLICK} middle button single click {RIGHTCLICK} right button single click {ABSx,y} move to absolute coordinate {RELx,y} move to relative coordinate

応用問題 practical lesson

無理ゲー攻略 mission impossible

Acme::MineChan

Minesweeper を ちゃんと解く。

マイン ちゃん

Demo

画像ファイルだけ、座標データは不要

FAQ. 役に立つの?

新しいスクリーンセーバーとして鑑賞する

Fun of the New Screen Saver

タイピングソフトでハイスコアを出す

Scoring champion for Key-Typing software

Windowsアプリの自動テスト化

Automation Testing for Win32 Applications

セキュリティ脆弱性検査

Fuzzing

その他 etc.

How to Debug

40

暴走 runaway

I Cannot control keyboard and mouse!

Oh…

Press Ctrl+C

infinite loooooooooooooop!!!(無限ループ)

I cannot use keyboard and mouse!!!

I want to kill

How to Kill the process on Win32

XP, 2003 Server …

New command line tools

tasklist

プロセスを一覧表示する

taskkill /F /IM notepad.exe

プロセスを kill する

成功: プロセス "notepad.exe" (PID 777) は強制終了されました。

How to kick?

I cannot use keyboard and mouse…

USB! USB!

Perl Killer USB Memory!

autorun.inf

[Autorun] open=taskkill /F /IM perl.exe

Insert USB Memory…

Successful!

Assign Desktop Shortcut Key (Ctrl+Alt+?)

KILLPERL.BAT Shortcut Desktop

@echo off taskkill /F /IM perl.exe

Ctrl + Alt + K

Perl is dead!

以上

all your minesweeper

are belong to us!

61

参考文献

Win32::GuiTest で Windows の GUI アプリをハックしよう(あまちゃん)

http://perl-users.jp/articles/advent-calendar/2008/13.html

Win32::GUITest と Win32::Clipboard で GUI 操作を自動化する(xaicron)

http://perl-users.jp/articles/advent-calendar/2010/win32/8

How To Get a Window Handle Without Specifying an Exact Title

http://support.microsoft.com/kb/147659/en

Minesweeper Clone

http://www.minesweeper.info/wiki/Minesweeper_Clone

アプリケーションをショートカット キーで起動する

http://www.microsoft.com/japan/athome/magazine/ucontents/users/tips/

windows/041.aspx

@turugina 日常業務でperlを使おう

http://yapcasia.org/2011/talk/109

@keroyonn_ Perlで次世代ゲーム開発 あらため Perl で次世代CUIゲーム開発

http://yapcasia.org/2011/talk/121

謝辞 acknowledgement

CPAN++

top related