当前位置:操作系统 > Windows 2003 >>

Win2000/XP/2003下的密码探测器

  在Win98下,对于别的程序的密码框,我们可以用SendMessage函数可以对这个密码框下一个WM_GETTEXT 的命令获取这个密码框的内容。但自2000以后,微软的安全意识似乎强了一点,用这个命令对普通的窗口管用,但对于密码框已经不起作用了。

  有不少类似的程序是通过建立动态链接库的方式来获取,但是那样做太麻烦了,其实我们有更简便的作法。那就是对它先下一个命令,去除它的密码框的属性,然后再获取它的内容,最后恢复它密码框的属性。

{
 项目 :Win2000/XP/2003 下*号密码探测器
 作者 :黄涛 Hunter@Shentong.com.cn
 日期 :2004年1月18日
}
unit uPassword;

interface

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

type
 TfrmPassword = class(TForm)
  edPassword: TEdit;       //显示密码的文本框
  Timer1: TTimer;       //定时器
  procedure Timer1Timer(Sender: TObject);
 private
  { Private declarations }
 public
  { Public declarations }
 end;

var
 frmPassword: TfrmPassword;

implementation

{$R *.dfm}

procedure TfrmPassword.Timer1Timer(Sender: TObject);
var s:pchar;
 i,n:integer;
 p:Tpoint;h:integer;
 c:integer;
begin
 getcursorpos(p);     //得到当前光标的位置
 h:=windowfrompoint(p);   //当到光标处窗口的句柄
 n:=getwindowlong(h ,GWL_STYLE ); //取窗口的属性
 if (n and $20) <>0 then begin    //判断是否为密码框
  c:=sendMessage(h, EM_GETPASSWORDCHAR,0, 0);
  //得到密码框当前的字符 如''*''等
  PostMessage(h,EM_SETPASSWORDCHAR,0,0);
  //设置密码框的字符为空,即去除密码框的密码属性,

   //此处一定要用PostMessage,而不能用 SendMessage,用后者无效
  i:= sendmessage(h,WM_GETTEXTLENGTH,0,0);inc(i);
  //取得密码串的长度
  getmem(s,i);   //分配内存
  sendmessage(h,WM_GETTEXT,i,longint(s)); //获取密码字符串
  edPassword.Text := s;    //将密码放入文本框中
  postMessage(h,EM_SETPASSWORDCHAR,c,0); //恢复原来的密码属性
  freemem(s); //释放内存
 end;
end;

end.

  本程序在 Window Server 2003 ,Delphi 7.0 Enterprise 下编译通过。但这个程序只对那些没有防范的程序有效,如QQ ganme 等,但对有些防范的程序来说还是无能为力的,如QQ2004 Beta的密码框是没用的。可见Win2000/XP/2003密码框的安全也是相对的,要想安全还要自己想办法。



CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,