几年前写的《作弊器编程》的东西(续)

《模拟器编程》-(针对IE控件WebBrowser编程-自动登录操作)
利用Delphi的Olevariant类型

单个frames的输入

var
  o : Olevariant;
begin
  o := WebBrowser.OleObject.document.all.item(‘LoginUserID’,0);   //找到登录用户名的输入框
  o.value := ‘TEST’;
  o := WebBrowser.oleobject.document.all.item(‘LoginPassword’,0); //找到登录密码的输入框
  o.value := ‘TEST’
  WebBrowser.oleobject.document.Forms.Item(0, 0).submit;          //第一个表单提交

{

  o :=WebBrowser.oleobject.document.all.item(‘Login’,0);          //或者用指定表单名称提交
  o.Click;  //点击操作,对其它对象也可同样操作
}
end;

多个frames的输入,FrameIndex为Frame的序号

var
  o : Olevariant;
begin

//找到登录用户名的输入框
  o := WebBrowser.oleobject.document.documentelement.document.frames.item(FrameIndex).document.all.item(‘LoginUserID’,0);  
  o.value := ‘TEST’;

//找到登录密码的输入框
  o := WebBrowser.oleobject.document.documentelement.document.frames.item(FramIndex).document.all.item(‘LoginPassword’,0);
  o.value := ‘TEST’

//第一个表单提交
  WebBrowser.oleobject.document.documentelement.document.frames.item(FramIndex).document.Forms.Item(0, 0).submit;         

{

//或者用指定表单名称提交

  o :=WebBrowser.oleobject.document.documentelement.document.frames.item(FramIndex)..document.all.item(‘Login’,0);         
  o.Click;   //点击操作,对其它对象也可同样操作
}
end;

《模拟器编程》-(针对IE控件WebBrowser编程-找出所有LINK对象对应的Href)
在模拟器编程中,我们常要找出所有要操作的LINK对象。如果是我们需要的,就对它进行操作。在一个网页中作为判断的依据或其它用途

单个frames的LINK对象

var
   Count:Integer; 

  LinkList:TStringList;
begin

  LinkList:=TStringList.Create;

  Try

    for Count :=0 to WebBrowser.OleObject.Document.Links.Count -1 do

      LinkList.Add(WebBrowser.OleObject.Document.Links.Item(Count).Href);

    {以下对取得的LINK对象内容HREF做相应操作,如判断、Navigate等}

  finally

    LinkList.Free;

  end;

end;

多个frames的LINK对象,FrameIndex为Frame的序号

var
   Count:Integer;  

  LinkList:TStringList;
begin

  LinkList:=TStringList.Create;

  Try

    for Count =0 to WebBrowser.OleObject.Document.documentelement.document.frames.item(FrameIndex).Document.Links.Count -1 do

      LinkList.Add(WebBrowser.OleObject.Document.documentelement.document.frames.item(FrameIndex).Document.Links.Item(Count).Href);

    {以下对取得的LINK对象内容HREF做相应操作,如判断、Navigate等}

  finally

    LinkList.Free;

  end;

end;

《模拟器编程》-针对IE控件WebBrowser编程-TAGNAME属性和SOURCEINDEX属性
  如何取得HTML页面中某个位置的内容,如我的登录姓名,现在我取得的$数据,我还有多少SPIN可用等等;下面我们就来谈谈这个东西。

  HTML中每一个保留字都由开始和结束组成就像《和》一样,是成对出现的。在HTML语法中常见的如<HTML></HTML>,<TD></TD>等,我们不需自己去计算这些内容,因为使用了WebBrowser后,它已经帮我们做到了。

  同时,在WebBrowser中,有一个极有用的属性,即SourceIndex属性,它将所有上述成对出现的对象能够唯一在页面中标识(不信的话你试试看,查找TD属性的对象就会出一大堆),能使我们找出唯一我们所需的内容。

在单个frames中查找相同属性的对象

var
   Count:Integer; 

begin

  for Count :=0 to WebBrowser.OleObject.Document.All.Length -1 do  //当前页面中所有对象数量

  Begin

    if WebBrowser.OleObject.Document.All.Item(Count).TagName =’TD’ then  //找出所有属性为TD的对象

    Begin

       ShowMessage(WebBrowser.OleObject.Document.All.Item(Count).InnerText);  //显示找到的对象的文本信息

       ShowMessage(WebBrowser.OleObject.Document.All.Item(Count).InnerHtml);  //显示找到的对象的HTML源码信息

    end;

  end;

end;

OK,现在找出相同属性的内容了,唯一值呢?

  if WebBrowser.OleObject.Document.All.Item(Count).SourceIndex = XXX then

  …

当然,你需首先得到XXX的值,怎样得到它?难到你不知道?

  自己做个工具吧;如果你比我还懒,算了,我这里做了一个工具,它可取得当前所有对象的唯一ID,就是SourceIndex了,当然有其它几个功能,不过用来完成刚才所讲内容,足够了,如果你认为我做的不行,好了,你多加几个功能吧;记得做好后给我Email一份。

  下载地点?当然在我的源码荟萃里了;没有?哦,我还没上传呢,等等吧!

多个frames的LINK对象,FrameIndex为Frame的序号

  我就不想多写了,所有多个Frames和前面所讲操作一样,如果你连这个都颔会不了的话,我劝你还是不要学了,别人做好后你用这行了。

另外,取得HTML页面中有几个Frames就这样做

  WebBrowser.OleObject.Document.documentelement.document.frames.Length

明白了吗?

现在我们做一个通用的函数,可按TagName和SourceIndex取得相应的文本内容:

// 取得TAGNAME指定的元素文本内容
function GetWebBrowserDocumentInnerText(Web:TWebBrowser;Const FramIndex,SourceIndex:Integer;Const TagName:String):String;
Var
  Count,Index :Integer;
  Tmp:String;
begin
  Result :=”;

//如果FramIndex为-1的话,表示只有一个Frame,否则,就是想操作的Frame序号
  if FramIndex = -1 then
  Begin
    for Count := 0 to web.oleobject.document.All.Length -1 do
    Begin
      tmp :=web.oleobject.document.All.Item(Count).TagName;
      Index :=web.oleobject.document.All.Item(Count).SourceIndex;
      if (tmp = TagName) and (SourceIndex =Index) then
      Begin
        Result :=web.oleobject.document.All.Item(Count).InnerText;
        Exit;
      end;
    end;
    Exit;
  end;
  for Count := 0 to web.oleobject.document.documentelement.document.frames.item(FramIndex).document.All.Length -1 do
  Begin
    tmp :=web.oleobject.document.documentelement.document.frames.item(FramIndex).document.All.Item(Count).TagName;
    Index :=web.oleobject.document.documentelement.document.frames.item(FramIndex).document.All.Item(Count).SourceIndex;
    if (tmp = TagName) and (SourceIndex =Index) then
    Begin
      Result :=web.oleobject.document.documentelement.document.frames.item(FramIndex).document.All.Item(Count).InnerText;
      Exit;
    end;
  end;
end;

《作弊器编程》-WinAPI-Mouse控制
  作弊器主要利用程序完成人对计算机的某些操作,如Mouse、键盘等外设的操作,让其它程序认为是人在计算机旁操作一样。今天谈谈Mouse的模拟操作。这些内容就需要用到WinAPI中的函数了。

  WinAPI中对Mouse的操作函数有:

  1、移动Mouse位置:SetCursorPos

    SetCursorPos(
      X: Integer; {X coordinate of the cursor}
      Y: Integer {Y coordinate of the cursor}
    ): BOOL; {returns TRUE or FALSE}
    Description
      The SetCursorPos function relocates the mouse cursor to the location specified by the X and Y parameters, in screen     coordinates. If the cursor is confined to a rectangular region by calling the ClipCursor function, the system translates the coordinates to the appropriate coordinates within the rectangular region.
    Parameters
      X: Specifies the new x-coordinate for the cursor.
      Y: Specifies the new y-coordinate for the cursor.
    Return Value
      If the function succeeds, it returns TRUE; otherwise it returns FALSE. To get extended error information, call the     GetLastError function.

   2、取得Mouse位置:GetCursorPos

     GetCursorPos(

       var lpPoint: TPoint {receives coordinates of cursor}
      ): BOOL; {returns TRUE or FALSE}
     Description
       The GetCursorPos function retrieves the mouse cursor position relative to the screen.
     Parameters
       lpPoint: Points to TPoint structure which receives the current mouse cursor抯 position in screen coordinates. This   structure must be allocated by the caller.
     Return Value
If the function succeeds, it returns TRUE; otherwise it returns FALSE. To get extended error information, call the GetLastError function.

   3、模拟Mouse点击:Mouse_Event
     mouse_event(
       dwFlags: DWORD; {mouse activity codes}
       dx: DWORD; {horizontal location or change}
       dy: DWORD; {vertical location or change}
       dwData: DWORD; {wheel movement amount}
       dwExtraInfo: DWORD {application defined data}
     ); {this procedure does not return a value}
     Description
     The mouse_event function simulates mouse activity. The system generates mouse messages as if the mouse was actually moved or a mouse button was actually pressed.
     Parameters
       dwFlags: Specifies which kind of mouse activity to simulate.
       dx: Specifies the horizontal location or change in location. If the dwFlags parameter contains the MOUSEEVENTF_ABSOLUTE flag, this parameter specifies a location. Otherwise, this parameter specifies the amount of mickeys (a measurement of mouse distance) to move.
       dy: Specifies the vertical location or change in location. If the dwFlags parameter contains the MOUSEEVENTF_ABSOLUTE flag, this parameter specifies a location. Otherwise, this parameter specifies the amount of mickeys (a measurement of mouse distance) to move.
       dwData: Specifies the amount of wheel movement if the dwFlags parameter contains the MOUSEEVENTF_WHEEL flag. A positive value indicates wheel movement away from the user; a negative value indicates wheel movement toward the user. This value is in terms of WHEEL_DELTA, approximately 120 mickeys. If the dwFlags parameter does not contain the MOUSEEVENTF_WHEEL flag, dwData should be set to zero.
       dwExtraInfo: 32 bits of additional application defined data. To retrieve this data, call the GetMessageExtraInfo function.

下面的代码是我们的一个练习,将Mouse先移到屏幕0,0位置,然后移动至中间,并单击:

var

  Count:Integer;

Begin

  SetCursorPOS(0,0);        //称动Mouse到0,0;其实,用Mouse_Event也能移动操作

  for Count :=0 to 400 do   //屏幕大小为800*600

    SetCursorPOS(Count,0);  //Y为0

//以下为单击操作,双击怎么做?回去好好想想

  Mouse_Event(MOUSEEVENTF_LEFTDOWN ,400,0,0,0);  //在400,0处按下Mouse左键

//Mouse_Event(MOUSEEVENTF_RIGHTDOWN ,400,0,0,0);  //不用说,右键

  Mouse_Event(MOUSEEVENTF_LEFTUP ,400,0,0,0);  //在400,0处放开Mouse左键

//Mouse_Event(MOUSEEVENTF_RIGHTUP ,400,0,0,0);  //不用说,右键

end;

这不就是一个自动点击机吗?当然,不完全,但自动点击的操作不就完成了吗!就这么简单

《作弊器编程》-WinAPI-键盘控制

  WinAPI中对键盘的操作函数只能用于Application自身,要想用自己的程序给其它程序窗体发送键码,需用到Hook(天,Hook可就复杂多了):而取得其它窗口输入的键码,就需用全局的Dll了(我晕,太多了)

  就里不再写代码了,在CashSoldier造钱战士 1.0 VIP源码的窗体控制中有全部源码(太多,这里写不了)un_SendKey.pas

  使用方法:

Const

  ControlKey = ‘^’;
  AltKey = ‘@’;
  ShiftKey = ‘~’;
  KeyGroupOpen = ‘{‘;
  KeyGroupClose = ‘}’;

//如当前窗口是IE窗口

Var

  Keys:String;

Begin

  Keys :=’@D’;     //按下 Alt+D,焦点为IE的地址输入框

  SendKeys(Keys);   //向当前窗口发送键码

  WaitForHook;      //等待结束

  Keys :=’http://alin.51.net’+$13;  //输入内容并按回车

  SendKeys(Keys);   //向当前窗口发送键码

  WaitForHook;      //等待结束

end;

《作弊器编程》-WinAPI-窗口控制

      一般来讲,对于我们常用的窗口控制的功能有如下要求:

    1、得到当前运行中的所有窗口信息

    2、取得最前端的窗口信息

    3、取得想控制的窗口信息等等

    在WinAPI中针对窗口控制的函数很多,完成以上功能的一般用的就以下几个函数:

    EnumWindows     取得当前系统中所有窗口句柄

    FindWindow      查找窗口

    SetWindowPos    设置窗口位置

    GetWindowRect   取得窗口大小

    …

    作弊器的目的在于让被蒙弊的程序认为我们的程序操作是由人在控制。同时,作弊器需像人一样取得针对的窗口信息,对它进行相应的操作。以上几个函数能够基本完成我们现在现要的操作。在CashSoldier造钱战士中的窗口控制及Spedia模拟器中,大量使用了以上函数;当然,所有函数每一个人使用都会采用不同的方法,如ShowWindow,MoveWindow可以用SetWindowPos来完成相应的功能。

    现在我们利用以上函数做一个自动点击机,它能找出广告窗口,同时每隔十秒点击相应的广告位置;(我们假设该广告条要点击的窗口ClassName为TBanner,广告条程序名称为Banner.EXE。广告条标题为SpediaBanner)。

function EnumWindowsProc(AHWnd: HWnd;LPARAM: lParam): boolean; stdcall;
var
  WndCaption: array[0..254] of char;             //窗口标题
  WndClassName: array[0..254] of char;           //窗口类名

  ARect:TRect;                                   //窗口坐标
begin
  if IsWindowVisible(AHwnd) then                 //是否可见窗口(我们要的广告窗口难道是不可见的吗?)
  Begin
    GetWindowText(AHWnd, @WndCaption, 254);      //取得窗口标题
    GetClassName(AHWnd, @WndClassName, 254);     //取得窗口类名

    if (StrPas(WndCaption) = ‘SpediaBanner’) and //是否运行的Banner.exe

       (StrPas(WndClassName = ‘TBanner’) then    //是否运行的窗口类为TBanner

    Begin                                        //是我们想要的窗口

      GetWindowRect(AHwnd,ARect);                //取得广告窗口的坐标位置(为什么要取出来呢?)

      ShowWindow(AHwnd,SW_SHOWNORMAL);           //按正常方式显示广告窗口(如果被隐藏了,不就对了吗)

//设置窗口位置及大小;实际上并没有改变大小和位置,因为用ShowWindow时,如果窗口被最小化时,就不起作用了(现在知道为何要先取坐标位置了吧)
      SetWindowPos(AHwnd,HWND_TOP,AHwnd.Left,AHwnd.Top,AHwnd.Right,AHwnd.Bottom,SWP_SHOWWINDOW);
      SetCursorPos(AHwnd.Top+10,AHwnd.Left+30);  //移动鼠标到广告条上(我随便加的位置,根据实际位置设置)

//单击广告条
      Mouse_Event(MOUSEEVENTF_LEFTDOWN ,AHwnd.Top+10,AHwnd.Left+30,0,0);
      Mouse_Event(MOUSEEVENTF_LEFTUP ,AHwnd.Top+10,AHwnd.Left+30,0,0);   

      Result :=False;                            //没必要再作枚举吧

      Exit;

    end;
  end;
  Result := True;            //返回TRUE表示继续下一个,否则,不再枚举
end;

procedure TForm.tm_AutoTimer(Sender: TObject);   //时钟控件,每隔一秒触发一次
begin
  tm_Auto.Enabled :=False;

  tm_Auto.Tag :=tm_Auto.Tag +1                   //每秒加一

  if tm_Auto.Tag >= 10 then                      //十秒触发一次

  Begin

    tm_Auto.Tag :=0;                             //恢复计数
    EnumWindows(@EnumWindowsProc, 0);            //取当前所有窗口

  end;
  tm_Auto.Enabled :=True;
end;

end;

几年前写的《作弊器编程》的东西(续) — nibulblog — [北方博客]

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据