精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● Delphi>>其他>>谈谈使用delphi读取获取密码缓存

主题:谈谈使用delphi读取获取密码缓存
发信人: cbb()
整理人: teleme(2000-12-06 19:41:09), 站内信件
谈谈使用delphi读取获取密码缓存

    通常而言,可以使用象pwltool.exe这样的工具来获取存于.pwl中的密码,但

有的时候也想自己动手试一试编程的乐趣,于是拜访了pwltool.exe作者的主页,

根据其中的一些资料,使用delphi编写了一个最简易的密码缓存读取程序。注意

本程序只能读取本机当前用户的密码缓存信息。
    实际上,该程序是调用了mpr.dll中未公开的WNetEnumCachedPasswords函数

来取得缓存信息的。
    特献上此文,望众高手能挖掘更深层次的核心,以自由博爱之精神将知识共
享。

unit test;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dia
logs,
  StdCtrls, shellApi;

type
  PPASSWORD_CACHE_ENTRY=^TPASSWORD_CACHE_ENTRY;
  TPASSWORD_CACHE_ENTRY=packed record
    cbEntry: word;                   //password entry的字节长度
    cbResource: word;                //resource name的字节长度
    cbPassword: word;                //password的字节长度
    iEntry: byte;                    //entry index
    nType: byte;                     //type of entry
    abResource : array[0..200] of char;  //start of resource name
                                     //password immediately follows re
source name
  end;
type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Passwordcount:integer;
  buffer1: array[0..200] of char;
implementation
{$R *.DFM}
function WNetEnumCachedPasswords(para0: pointer; para1:word; para2: by
te; para3:pointer; para4: dword): word; stdcall; external 'mpr.dll' na
me 'WNetEnumCachedPasswords';

function pce(x:PPASSWORD_CACHE_ENTRY;y:dword):boolean;stdcall;
begin
  passwordcount:=passwordcount+1;

  move(x.abResource,buffer1,x.cbResource);
  if x.cbResource<50 then
fillchar(buffer1[x.cbResource],50-x.cbResource,#32);

move(x.abResource[x.cbResource],buffer1[50],x.cbPassword);
buffer1[x.cbPassword+50]:=#0;
Form1.Memo1.Lines.Add(buffer1);

Result:=true;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
passwordcount:=0;
Memo1.Lines.Clear;
Memo1.Font.Color:=clBlack;
WNetEnumCachedPasswords(nil,0,255,@pce,0);
Memo1.Lines.Add('---------------------------------------------------
---------');
Memo1.Lines.Add(format('当前用户共有%d个密码资源缓存',[passwordcount
]));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
passwordcount:=0;
Memo1.Lines.Clear;
Memo1.Font.Color:=clBlack;
WNetEnumCachedPasswords(nil,0,255,@pce,0);
Memo1.Lines.Add('---------------------------------------------------
---------');
Memo1.Lines.Add(format('当前用户共有%d个密码资源缓存',[passwordcount
]));
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Memo1.Lines.clear;
Memo1.Font.Color:=clRed;
Memo1.Lines.Add(' 我们通常允许Windows替我们把各类密码(如上网帐号
,密码等)存入系统,这当然方便了我们的使用。但是,您必须知道,那些“保
密”的信息其实一点也不保密。');
Memo1.Lines.Add(' 这里只使用了一个标准的Windows Api程序,就能知道
您保存在机器里的大部分密码。');
Memo1.Lines.Add(' 本程序属免费性质,允许您将其任意拷贝,传播,您也
可直接使用或修改其中代码。尽管已经对程序进行了测试,但我不保证您在自己
的机器上运行时不发生故障。特申明:作者不对由于运行本程序而导致的任何后
果负责!');
Memo1.Lines.Add(' 不管您从何种渠道取得本程序,我都要求您合法地使用
本程序,如您不能做到,请立刻删除本程序,谢谢您的合作');
Memo1.Lines.Add('');
Memo1.Lines.Add(' ------ 版权所有,翻版不究;合法使用,慎防违法!
------');
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
ShellExecute( Handle, 'open', 'mailto:[email protected]','','',SHOW_FULL
SCREEN );
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
close;
end;

end.

--
※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 61.140.220.88]

[关闭][返回]