发新话题
打印

[原创]批量替换系统文件夹图标(delphi含源码)

[原创]批量替换系统文件夹图标(delphi含源码)

文章作者:kebin
信息来源:邪恶八进制信息安全团队(www.eviloctal.com


以前用 delphi7写的 本来想写成一个恶意工具 后来想想 一看我就是正经人 算了
刚才在电脑里无意中发了 共享出来
这个程序有个小BUG  自已发现一下哈哈 因为电脑里没有 delphi了 就不改了 直接把源码发上来

各位老大别看控件名了  看点能学技术的地方 N久以前写的 我感觉我这delphi写的还比较规范
Code Language : Delphi
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.  Dialogs, StdCtrls, Grids, Buttons, FileCtrl, ExtCtrls, ExtDlgs;
  8.  
  9. type
  10.  TForm1 = class(TForm)
  11.   btn_Scan: TButton;
  12.   edt_Path: TEdit;
  13.   mem_FilePath: TMemo;
  14.   mem_FileName: TMemo;
  15.   btn_Stop: TButton;
  16.   Label1: TLabel;
  17.   Label3: TLabel;
  18.   lbl_Directory: TLabel;
  19.   Label2: TLabel;
  20.   lbl_FileName: TLabel;
  21.   Label5: TLabel;
  22.   Label4: TLabel;
  23.   lbl_Time: TLabel;
  24.   Label7: TLabel;
  25.   cb_All: TCheckBox;
  26.   btn_Path: TSpeedButton;
  27.   Label6: TLabel;
  28.   Label8: TLabel;
  29.   DListBox: TDirectoryListBox;
  30.   img_Pic: TImage;
  31.   OpenPictureDialog: TOpenPictureDialog;
  32.   cb_AddDesktopini: TCheckBox;
  33.   cb_DelDesktopini: TCheckBox;
  34.   procedure btn_ScanClick(Sender: TObject);
  35.   procedure btn_PathClick(Sender: TObject);
  36.   procedure DListBoxDblClick(Sender: TObject);
  37.   procedure edt_PathClick(Sender: TObject);
  38.   procedure img_PicDblClick(Sender: TObject);
  39.   procedure btn_StopClick(Sender: TObject);
  40.   procedure cb_AddDesktopiniClick(Sender: TObject);
  41.   procedure cb_DelDesktopiniClick(Sender: TObject);
  42.  private
  43.   { Private declarations }
  44.  public
  45.   bTemiated: Boolean;
  46.   { Public declarations }
  47.  end;
  48.  
  49. var
  50.  Form1: TForm1;
  51.  
  52. implementation
  53.  
  54. uses Unit2;
  55.  
  56. {$R *.dfm}
  57.  
  58. procedure TForm1.btn_ScanClick(Sender: TObject);
  59. var
  60.  sSystemPath: string;
  61. begin
  62.  bTemiated := False;
  63.  mem_FileName.Lines.Clear;
  64.  mem_FilePath.Lines.Clear;
  65.  //释放图片文件
  66.  if cb_AddDesktopini.Checked then
  67.  begin
  68.   sSystemPath := 'C:\WINNT\SYSTEM32';
  69.   if not DirectoryExists(sSystemPath) then
  70.    sSystemPath := 'C:\WINDOWS\SYSTEM32';
  71.   if not DirectoryExists(sSystemPath) then
  72.    if not ForceDirectories(sSystemPath) then
  73.     Exit;
  74.   img_Pic.Hint := sSystemPath + '\None.ico';
  75.   img_Pic.Picture.SaveToFile(img_Pic.Hint);
  76.  end;
  77.  Count.Create;
  78. end;
  79.  
  80. procedure TForm1.btn_PathClick(Sender: TObject);
  81. begin
  82.  DListBox.Visible := not DListBox.Visible;
  83.  if DListBox.Visible then
  84.  begin
  85.   DListBox.Directory := edt_Path.Text;
  86.  end;
  87. end;
  88.  
  89. procedure TForm1.DListBoxDblClick(Sender: TObject);
  90. begin
  91.  edt_Path.Text := DListBox.GetItemPath(DListBox.ItemIndex);
  92. end;
  93.  
  94. procedure TForm1.edt_PathClick(Sender: TObject);
  95. begin
  96.  DListBox.Visible := False;
  97. end;
  98.  
  99. procedure TForm1.img_PicDblClick(Sender: TObject);
  100. begin
  101.  with OpenPictureDialog do
  102.  begin
  103.   if img_Pic.Hint <> '' then
  104.    InitialDir := ExtractFilePath(img_Pic.Hint);
  105.   if Execute then
  106.   begin
  107.    img_Pic.Picture.Bitmap.LoadFromFile(FileName);
  108.    img_Pic.Hint := FileName;
  109.   end;
  110.  end;
  111. end;
  112.  
  113. procedure TForm1.btn_StopClick(Sender: TObject);
  114. begin
  115.  //
  116.  bTemiated := True;
  117. end;
  118.  
  119. procedure TForm1.cb_AddDesktopiniClick(Sender: TObject);
  120. begin
  121.  if cb_AddDesktopini.Checked then
  122.   cb_DelDesktopini.Checked := not cb_AddDesktopini.Checked;
  123. end;
  124.  
  125. procedure TForm1.cb_DelDesktopiniClick(Sender: TObject);
  126. begin
  127.  if cb_DelDesktopini.Checked then
  128.   cb_AddDesktopini.Checked := not cb_DelDesktopini.Checked;
  129. end;
  130.  
  131. end.
  132.  
  133. unit Unit2;
  134.  
  135. interface
  136.  
  137. uses
  138.  Windows, Classes, SysUtils;
  139.  
  140. type
  141.  TDriveType = (dtUnKnown, dtNoDrive, dtFloppy, dtFixed, dtNetWork, dtCDROM, dtRAM);
  142.  
  143. type
  144.  Count = class(TThread)
  145.  private
  146.   iFCount, iDCount: Integer;
  147.   tCount: Cardinal;
  148.   sContent: string;
  149.   Drivers: array of string;
  150.   { Private declarations }
  151.   procedure ScanFile(sPath: string);
  152.   procedure GetDrivers;
  153.  public
  154.   bStop, bChangeDirectoryIcon, bDelDirectoryIcon: Boolean;
  155.   constructor Create;
  156.  protected
  157.   procedure Execute; override;
  158.  end;
  159.  
  160. implementation
  161.  
  162. uses Unit1;
  163.  
  164. { Important: Methods and properties of objects in visual components can only be
  165.  used in a method called using Synchronize, for example,
  166.  
  167.    Synchronize(UpdateCaption);
  168.  
  169.  and UpdateCaption could look like,
  170.  
  171.   procedure Count.UpdateCaption;
  172.   begin
  173.    Form1.Caption := 'Updated in a thread';
  174.   end; }
  175.  
  176. { Count }
  177.  
  178. constructor Count.Create;
  179. begin
  180.  FreeOnTerminate := True;
  181.  inherited Create(False);
  182. end;
  183.  
  184. procedure Count.ScanFile(sPath: string);
  185.  procedure CheckString(sTmp: string);
  186.  begin
  187.   sTmp := Trim(sTmp);
  188.   if Copy(sTmp, Length(sTmp), 1) = '\' then
  189.    sTmp := Copy(sTmp, 1, Length(sTmp) - 1);
  190.  end;
  191.  procedure SetDirectoryIcon(sTmp: string);
  192.  var
  193.   tFile: TextFile;
  194.  begin
  195.   try
  196.    //
  197.    if FileSetAttr(sTmp, faSysFile) <> 0 then
  198.     Exit;
  199.    try
  200.     if FileExists(sTmp + '\Desktop.ini') then
  201.      DeleteFile(sTmp + '\Desktop.ini');
  202.     AssignFile(tFile, sTmp + '\Desktop.ini');
  203.     Rewrite(tFile);
  204.     Writeln(tFile, sContent);
  205.    finally
  206.     CloseFile(tFile);
  207.    end;
  208.   except
  209.   end;
  210.  end;
  211.  procedure DelDirectoryIcon(sTmp: string);
  212.  begin
  213.   try
  214.    //
  215.    if FileExists(sTmp + '\Desktop.ini') then
  216.     DeleteFile(sTmp + '\Desktop.ini');
  217.   except
  218.   end;
  219.  end;
  220.  
  221. var
  222.  srTmp: TSearchRec;
  223. begin
  224.  bStop := Form1.bTemiated;
  225.  if bStop then
  226.   Exit;
  227.  CheckString(sPath);
  228.  if FindFirst(sPath + '\*.*', faDirectory, srTmp) = 0 then
  229.  begin
  230.   repeat
  231.    if (srTmp.Attr and faDirectory) <> 0 then
  232.    begin
  233.     if (srTmp.Name <> '.') and (srTmp.Name <> '..') then
  234.     begin
  235.      Inc(iDCount);
  236.      Form1.lbl_Directory.Caption := IntToStr(iDCount);
  237.      Form1.mem_FilePath.Lines.Add(sPath + '\' + srTmp.Name + '\');
  238.      if bChangeDirectoryIcon then
  239.       SetDirectoryIcon(sPath + '\' + srTmp.Name + '\')
  240.      else if bDelDirectoryIcon then
  241.       DelDirectoryIcon(sPath + '\' + srTmp.Name + '\');
  242.      ScanFile(sPath + '\' + srTmp.Name);
  243.     end;
  244.    end
  245.    else if (srTmp.Attr and faAnyFile) <> 0 then
  246.    begin
  247.     Inc(iFCount);
  248.     Form1.lbl_FileName.Caption := IntToStr(iFCount);
  249.     Form1.mem_FileName.Lines.Add(sPath + '\' + srTmp.Name);
  250.    end;
  251.   until FindNext(srTmp) <> 0;
  252.   FindClose(srTmp);
  253.  end;
  254.  if bChangeDirectoryIcon then
  255.   SetDirectoryIcon(sPath + '\');
  256.  Form1.lbl_Time.Caption := FloatToStr((GetTickCount - tCount) / 1000);
  257. end;
  258.  
  259. procedure Count.GetDrivers;
  260. var
  261.  DriveNum: Integer;
  262.  DriveType: TDriveType;
  263.  DriveBits: set of 0..25;
  264.  DriveChar: Char;
  265. begin
  266.  //Drivers;
  267.  Integer(DriveBits) := GetLogicalDrives;
  268.  for DriveNum := 2 to 25 do
  269.  begin
  270.   if not (DriveNum in DriveBits) then
  271.    Continue;
  272.   DriveChar := Char(DriveNum + Ord('A'));
  273.   DriveType := TDriveType(GetDriveType(PChar(DriveChar + ':\')));
  274.   if (DriveType <> dtFloppy) and (DriveType <> dtNetWork) and (DriveType <> dtCDROM)
  275.    and (DriveType <> dtRAM) then
  276.   begin
  277.    SetLength(Drivers, High(Drivers) + 2);
  278.    Drivers[High(Drivers)] := DriveChar + ':';
  279.   end;
  280.  end;
  281. end;
  282.  
  283. procedure Count.Execute;
  284. var
  285.  i: Integer;
  286.  sPic, sTmp: string;
  287. begin
  288.  { Place thread code here }
  289.  bStop := False;
  290.  bChangeDirectoryIcon := Form1.cb_AddDesktopini.Checked;
  291.  bDelDirectoryIcon := Form1.cb_DelDesktopini.Checked;
  292.  sPic := Form1.img_Pic.Hint;
  293.  if sPic = '' then
  294.  begin
  295.   sPic := ExtractFilePath(ParamStr(0)) + '\None.ico';
  296.   Form1.img_Pic.Picture.Bitmap.SaveToFile(sPic);
  297.  end;
  298.  sContent := '[.ShellClassInfo]' + #13#10 + 'IconFile=' + sPic + #13#10 + 'IconIndex=0';
  299.  tCount := GetTickCount;
  300.  if Form1.cb_All.Checked then
  301.  begin
  302.   GetDrivers;
  303.   for i := 0 to High(Drivers) do
  304.    ScanFile(Drivers[i]);
  305.  end
  306.  else
  307.   ScanFile(Form1.edt_Path.Text);
  308.  Terminate;
  309. end;
  310.  
  311. end.
Parsed in 0.160 seconds

附件

Project2.rar (198 KB)

2007-7-3 22:11, 下载次数: 65

TOP