Solved

Creating an Anti Happy Time

Posted on 2004-03-23
12
307 Views
Last Modified: 2010-04-04
Dear friends,

By the first time in my 15 years as user/programmer of computer I found a virus in my computer! The Happy Time.

Good programmer the author of Happy Time!

I have 25000 files infested in my computer, certainly thre is a way to ´delete´ the script from each file, BUT I unknow that
´script´ Them begin where the html file ends ´</html>´

Could you please help me to solve this hard problem? and
save hours of work?

Best regards



Yours

LeTchev
0
Comment
Question by:letchev
  • 4
  • 2
  • 2
  • +1
12 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10663314
may be this helps u
with these two procedures u can search all desired file in a drive


//-------------------------------------------------------------
// recursively searching all subfolders starting from Path
//-------------------------------------------------------------
procedure TFSzperacz.LookInDir(Path: string);
var
  NewPath: string;
  srd: TSearchRec;
  idir: integer;
begin
  idir := FindFirst(Path + '*.*', faDirectory, srd);
  while ((idir = 0) and (not ST.Terminated)) do
    begin
    if (((srd.Attr and faDirectory) > 0)
                   and (srd.Name[1] <> '.')) then
      begin
      NewPath := Path + srd.Name + '\';
      SearchFile(NewPath);
      LookInDir( NewPath);
    end;
    idir := FindNext(srd);
  end;
  FindClose(srd);
end;

//-------------------------------------------------------------
// finding files in a folder
//-------------------------------------------------------------
procedure TFSzperacz.SearchFile(Path: string);
var
  sr: TSearchRec;
  i: integer;
  j: integer;
begin
  StatusBar1.Panels[1].Text := Path;
  for j := 0 to ListBox1.Items.Count - 1 do
    begin
    i := FindFirst(Path + ListBox1.Items[j], faAnyFile, sr);
    while ((i = 0) and (not ST.Terminated)) do
      begin
//
// do cutting here
//
      i := FindNext(sr);
      end;
    FindClose(sr);
    end;
end;


0
 
LVL 17

Expert Comment

by:mokule
ID: 10663321
in ListBox1 You should have desired masks for searched files
0
 
LVL 17

Expert Comment

by:geobul
ID: 10664840
Hi,

First I have to say that I'm not familiar with that virus. If I understand you right it places something in your html files after their end. Let's presume you already created a list of these files in slFiles (if need help there let me know).

var
  slFiles, slText: TStringList;
  i,k: integer;
begin
  slFiles := TStringList.Create;
  slText := TStringList.Create;
  try
    // fill the list here
    ...
    // now remove everything after the html end
    for i := 0 to slFiles.Count - 1 do begin
       slText.LoadFromFile(slFiles[i]);
       k := Pos('</html>', slText.Text); // or  
       // k := Pos('</html>', LowerCase(slText.Text)); // if you may have </HTML> somewhere
       if k > 0 then begin
         slText.Text := Copy(slText.Text, 1, k+6);
         slText.SaveToFile(slFiles[i]);
       end;
    end;
  finally
    slFiles.Free;
    slText.Free;
  end;
end;

Regards, Geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 10664862
Try the code above on one or two files you know replacing the '...' with:

  slFiles.Add('c:\folder\file1.html');
  slFiles.Add('c:\folder\file2.html');

and see if this is what you want. Make copies of these files beforehand for safety.
0
 

Author Comment

by:letchev
ID: 10682191
Geobul,

I want a script such as Happy Time which scan all files from all drives and cut out the text after the end of an html page:
</html>. It is all I need.

Thank you again.

LeTchev
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 17

Expert Comment

by:mokule
ID: 10682978
//This program searches all drive and can remove Your script from files
// You should uncomment this * for full functionality
// Mind that you can't stop it
// It is not written on threads
// Main.pas

unit Main;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit3: TEdit;
    Edit4: TEdit;
    Label4: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    function  LookInDir(Path: string):boolean;
    function SearchFile(Path: string):boolean;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  LookInDir(Edit4.Text);
end;

//-------------------------------------------------------------
// recursively searching all subfolders starting from Path
//-------------------------------------------------------------
function TForm1.LookInDir(Path: string): boolean;
var
  NewPath: string;
  srd: TSearchRec;
  idir: integer;
begin
  result := True;
  idir := FindFirst(Path + '*.*', faDirectory, srd);
// it'll be better to use threads
//  while ((idir = 0) and (not ST.Terminated)) do
  while (idir = 0) do
    begin
    if (((srd.Attr and faDirectory) > 0)
                   and (srd.Name[1] <> '.')) then
      begin
      NewPath := Path + srd.Name + '\';
      if not SearchFile(NewPath) then
        begin
        result := False;
        break;
        end;
//----- uncoment below to look in directories
//*    if not LookInDir( NewPath) then
//*       begin
//*        result := False;
//*        break;
//*        end;

    end;
    idir := FindNext(srd);
  end;
  FindClose(srd);
end;

//-------------------------------------------------------------
// finding files in a folder
//-------------------------------------------------------------
function TForm1.SearchFile(Path: string):boolean;
var
  sr: TSearchRec;
  i: integer;
  j: integer;

  slText: TStringList;
  k: integer;
begin
  result := True;
  slText := TStringList.Create;
  Edit1.Text := Path;
  i := FindFirst(Path + Edit3.Text, faArchive, sr);
  try
// it'll be better to use threads
//    while ((i = 0) and (not ST.Terminated)) do
    while (i = 0) do
      begin
      Edit2.Text := Path + sr.Name;
//----------------------------------
//----------------------------------
// like geobul
// I don't test this
// it won't find '< / html>' and so on
       slText.LoadFromFile(Edit2.Text);
//       k := Pos('</html>', slText.Text); // or
       k := Pos('</html>', LowerCase(slText.Text)); // if you may have </HTML> somewhere
       if k > 0 then begin
         slText.Text := Copy(slText.Text, 1, k+6);

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//it can do a lot of harm. Be carefull
// uncomment the line below on your own resposibilty
//*         slText.SaveToFile(slFiles[i]);
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
         end;
//----------------------------------
//----------------------------------

//---- comment below but you can't stop then
    if Application.MessageBox(PChar('Continue?'),PChar('Find file'),MB_YESNO) <> IDYES then
      begin
      result := False;
      exit;
      end;
//----------------------------------


      i := FindNext(sr);
      end;
  except
  end;
    FindClose(sr);
    slText.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
  Edit4.Text := 'C:\';
  Edit3.Text := '*.*';
end;

end.

/////////////////////////////////////////////////////////
Main.dfm
/////////////////////////////////////////////////////////
object Form1: TForm1
  Left = 35
  Top = 2
  Width = 558
  Height = 264
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 16
    Top = 72
    Width = 42
    Height = 13
    Caption = 'Directory'
  end
  object Label2: TLabel
    Left = 16
    Top = 128
    Width = 16
    Height = 13
    Caption = 'File'
  end
  object Label3: TLabel
    Left = 416
    Top = 24
    Width = 44
    Height = 13
    Caption = 'File mask'
  end
  object Label4: TLabel
    Left = 16
    Top = 24
    Width = 79
    Height = 13
    Caption = 'Starting directory'
  end
  object Edit1: TEdit
    Left = 16
    Top = 88
    Width = 521
    Height = 21
    TabOrder = 0
  end
  object Button1: TButton
    Left = 240
    Top = 184
    Width = 75
    Height = 25
    Caption = 'Start'
    TabOrder = 1
    OnClick = Button1Click
  end
  object Edit2: TEdit
    Left = 16
    Top = 144
    Width = 521
    Height = 21
    TabOrder = 2
  end
  object Edit3: TEdit
    Left = 416
    Top = 40
    Width = 121
    Height = 21
    TabOrder = 3
    Text = '*.*'
  end
  object Edit4: TEdit
    Left = 16
    Top = 40
    Width = 345
    Height = 21
    TabOrder = 4
    Text = 'C:\'
  end
end
0
 

Author Comment

by:letchev
ID: 10696001
Dear Mokule,

I run your script, however it does not you promisses.

Thank you for your interest and patience.

Regards,

0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10722184
if you know the text saved from the virus, it could be replaced with the empty string (or one space) using my solution for the question:
http://experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20932619.html

emil
0
 
LVL 17

Expert Comment

by:mokule
ID: 10722458
Sorry for not answering so long. I've somehow missed Your post
Could You say a word what was wrong.
I cut it from working application.
Do You make necessary changes as in comment?
0
 
LVL 12

Accepted Solution

by:
esoftbg earned 125 total points
ID: 10729666
Here is a full working Anti Happy Time application (it is tested).

unit Unit_Q_20929545;

interface

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

type
  TForm_Q_20929545 = class(TForm)
    Button_Qure: TButton;
    Label1: TLabel;
    ListBox1: TListBox;
    ListBox2: TListBox;
    Edit_Count: TEdit;
    Checkbox_List: TCheckBox;
    procedure FormCreate(Sender: TObject);
    procedure Button_QureClick(Sender: TObject);
  private { Private declarations }
    Count_of_HTML: Integer;
    procedure Qure_Text(FName: string);
    procedure Qure_File(PathName: string; SL: TStringList);
  public  { Public declarations }
  end;

var
  Form_Q_20929545: TForm_Q_20929545;

implementation

{$R *.dfm}

procedure TForm_Q_20929545.FormCreate(Sender: TObject);
begin
  Count_of_HTML := 0;
end;

function  Load_From_File(FName: string; StrList: TStringList): Boolean;
var
  B:      Boolean;
begin
  B := True;
  try
    try
      StrList.LoadFromFile(FName);
    except
      B := False;
    end;
  finally
    Result := B;
  end;
end;

procedure TForm_Q_20929545.Qure_Text(FName: string);
var
  B:      Boolean;
  I:      Integer;
  P:      Integer;
  StrList:TStringList;
  SList:  TStringList;
  S:      string;
begin
  B := False;
  SList := TStringList.Create;
  try
    StrList := TStringList.Create;
    try
      if Load_From_File(FName, StrList) then
      for I := 0 to StrList.Count-1 do
      begin
        S := StrList.Strings[I];
        S := ANSIUpperCase(S);
        P := Pos('</HTML>', S);
        if B then
          Break
        else
        if (P=0) then
          SList.Add(S)
        else
        begin
          S := Copy(S, 1, P+6);
          SList.Add(S);
          B := True;
        end;
      end;
    finally
      if B then
      begin
        SList.SaveToFile(FName);
        if Checkbox_List.Checked then
          ListBox1.Items.Add(FName);
        Application.ProcessMessages;
      end;
      StrList.Destroy;
    end;
  finally
    SList.Destroy;
    Inc(Count_of_HTML);
    Edit_Count.Text := 'Count: ' + IntToStr(Count_of_HTML);
    Application.ProcessMessages;
  end;
end;

procedure TForm_Q_20929545.Qure_File(PathName: string; SL: TStringList);
var
  Found:         Integer;
  Attr:          Integer;
  I:             Integer;
  S:             string;
  T:             string;
  FName:         string;
  DirName:       string;
  SearchRec:     TSearchRec;
  procedure Prepare_For_Qure(Name: string);
  begin
    if ((FileGetAttr(Name) and faReadOnly) > 0) then
      FileSetAttr(Name, FileGetAttr(Name) xor faReadOnly);
    if ((FileGetAttr(Name) and faHidden) > 0) then
      FileSetAttr(Name, FileGetAttr(Name) xor faHidden);
    if ((FileGetAttr(Name) and faSysFile) > 0) then
      FileSetAttr(Name, FileGetAttr(Name) xor faSysFile);
  end;
begin
  Attr := faDirectory;
  Found := FindFirst(PathName+'*.*', Attr, SearchRec);
  while (Found=0) do
  try
    if (((FileGetAttr(SearchRec.Name) and faArchive) > 0)
    or  ((FileGetAttr(SearchRec.Name) and faAnyFile) > 0)) then
    for I := 0 to SL.Count-1 do
    begin
      FName := PathName + SearchRec.Name;
      if FileExists(FName) then
      begin
        Prepare_For_Qure(FName);
        S := UpperCase(ExtractFileExt(FName));
        T := UpperCase(SL.Strings[I]);
        T := UpperCase(ExtractFileExt(T));
        if (S=T) then
        begin
          Prepare_For_Qure(FName);
          Qure_Text(FName);
        end;
      end;
    end;
    if ((SearchRec.Attr=2064) or (SearchRec.Attr=16))
    and (not (SearchRec.Name[1]='.')) then
    begin
      DirName := PathName + SearchRec.Name + '\';
      Qure_File(DirName, SL);
    end;
  finally
    Found := FindNext(SearchRec);
  end;
  FindClose(SearchRec);
end;

procedure TForm_Q_20929545.Button_QureClick(Sender: TObject);
var
  C:             Char;
  PCRootPathName:PChar;
  DriveType:     DWORD;
  S:             string;
  SL:            TStringList;
begin
  ListBox1.Clear;
  Edit_Count.Font.Color := clBlack;
  Application.ProcessMessages;
  SL := TStringList.Create;
  try
    SL.Add('*.html');
    SL.Add('*.htm');
    for C := 'A' to 'Z' do
    begin
      S := C + ':\';
      PCRootPathName := PChar(S);
      DriveType := GetDriveType(PCRootPathName);
      if (DriveType=DRIVE_FIXED) then
      begin
        ListBox2.Items.Add(S);
        if Checkbox_List.Checked then
          ListBox1.Items.Add('Current scanned HDD is ' + S);
        Application.ProcessMessages;
        Qure_File(S, SL);
      end;
    end;
  finally
    SL.Destroy;
    ListBox1.Items.Add('Done.');
    Edit_Count.Text := Edit_Count.Text + ' Done.';
    Edit_Count.Font.Color := clBlue;
    ListBox2.Font.Color := clBlue;
    ListBox2.Repaint;
  end;
end;

end.

emil
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now