⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 用delphi实现木马特征码扫描的简单代码!!!
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    ListBox1: TListBox;
    Button2: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    ProgressBar1: TProgressBar;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
function EnumFileInRecursion(path:PChar):Longint;stdcall;
var
    searchRec:TSearchRec;
    found:Integer;
    tmpStr:String;
begin
    Result:=0; //查找结果(文件数)
    //加上搜索后缀,得到类似'c:\*.*' 、'c:\windows\*.*'的搜索路径
    tmpStr:=StrPas(path)+'\*.*';
    //在当前目录查找第一个文件、子目录
    found:=FindFirst(tmpStr,faAnyFile,searchRec);
    while found=0 do
    //找到了一个文件或目录后
    begin
        //如果找到的是个目录
        if (searchRec.Attr and faDirectory)<>0 then   // 是一个目录
        begin
            {在搜索非根目录(C:\、D:\)下的子目录时会出现'.','..'的"虚拟目录"
            大概是表示上层目录和下层目录吧。。。要过滤掉才可以}
            if (searchRec.Name <> '.') and (searchRec.Name <> '..') then
            begin
                {由于查找到的子目录只有个目录名,所以要添上上层目录的路径
                searchRec.Name = 'Windows';tmpStr:='c:\Windows';
                加个断点就一清二楚了}
                tmpStr:=StrPas(path)+'\'+searchRec.Name;
                //自身调用,查找子目录,递归。。。。
                Result:=Result+EnumFileInRecursion(PChar(tmpStr));
            end;
        end
        //如果找到的是个文件
        {这个也是递归的结束条件,结束条件对于理解递归来说,相当重要}
        else                       //是一个文件
         begin
            {Result记录着搜索到的文件数。可是我是用CreateThread创建线程
            来调用函数的,不知道怎么得到这个返回值。。。我不想用全局变量}
            Result:=Result+1;
            //把找到的文件加到Memo控件
            Form1.Memo1.Lines.Add(StrPas(path)+'\'+searchRec.Name);
         end;
         //查找下一个文件或目录
        found:=FindNext(searchRec);
    end;
    //释放资源
    FindClose(searchRec);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   EnumFileInRecursion(pchar(edit1.text));
end;

procedure TForm1.Button2Click(Sender: TObject);
var
   i:integer;
   tmp1:tmemorystream;
   buf:array[0..1000] of char;

   offset1,offset2,ascii1,ascii2:integer;
begin
   progressbar1.Min:=0;
   progressbar1.Max:=memo1.Lines.Count;

   for i:=0 to memo1.Lines.Count-1 do
   begin
   try
      progressbar1.Position:=i;

      tmp1 := TMemoryStream.Create;
      tmp1.LoadFromFile(memo1.Lines.Strings[i]); //逐个载入文件
      tmp1.Position :=0;
      tmp1.ReadBuffer(buf,1001);

      offset1:=strtoint(edit2.Text);
      offset2:=strtoint(edit4.text);
      ascii1:=strtoint(edit3.text);
      ascii2:=strtoint(edit5.text);
      application.ProcessMessages;//防止程序假死

      if ord(buf[offset1])=ascii1 then
      begin
         listbox1.Items.Add(memo1.Lines.Strings[i]+'-->>含有木马!');
      end;

      tmp1.Free;  //释放内存流对象
   except
   end;   //END TRY
   end;  ///END IF
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -