Einzelnen Beitrag anzeigen

mohfa

Registriert seit: 11. Feb 2007
97 Beiträge
 
Delphi 7 Enterprise
 
#1

What's incorrect with this

  Alt 23. Jan 2009, 03:38
This an antivirus scanner i'm working on , i want to add the Wildcard search function but , it doesn't work

could somebody take a look at it , and tell me what's the Problem with it

The attachment contains 3 files :

+ The scanner.pas = the main Scanner Engine
+ FastStrings.pas = i use for FastPos + i adapted it with patternPos to be able to Use the WildCards
+ MD5.pas = Use it in my Databases
+ DB.txt = the Main database .

SO if i add a Signature Like this : AB??EFG it won't work although the patternPos works very well .

// Here an extract from the scanner.pas

// I use this in the WildCard Search :
Delphi-Quellcode:
function Matches(const AString, Pattern: string; startpos:integer): boolean;
var
   j, n, n1, n2: integer ;
   p1, p2: pchar ;
label
   match, nomatch;
begin
   n1 := Length(AString) ;
   n2 := Length(Pattern) ;
   if n1 < n2 then
     n := n1
   else
     n := n2;
   p1 := pchar(AString) +startpos-1;
   p2 := pchar(Pattern) ;
   for j := 1 to n do
   begin
     if p2^ = '*then
       goto match;
     if (p2^ <> '?') and ( p2^ <> p1^ ) then
       goto nomatch;
     inc(p1) ; inc(p2) ;
   end;
   if n1 > n2 then
   begin
     goto match;
nomatch:
     Result := False;
     exit;
   end else
     if n1 < n2 then
     begin
       for j := n1 + 1 to n2 do
       begin
         if not ( p2^ in ['*','?'] ) then
           goto nomatch ;
         inc(p2) ;
       end;
     end;
match:
   Result := True
end;
 
function patternPos(const ASourceString, APatternString : string; StartPos:integer):integer;
var l, ll,i,delta:integer;
    p:string;
begin
  Assert(StartPos>0);
  Assert(length(APatternString)>0);
  result:=0;
  l:=length(ASourceString);
  if StartPos>l then
    exit;

  p:=findText(APatternString, delta);
  if p='then
  begin
    if Matches(ASourceString, APatternString, StartPos) then
      result:=StartPos;
    exit;
  end else
  begin
    i:=StartPos-1;
    ll:=length(p);
    repeat

    {
    FastPos( s,lVirus^.Signature,sLen,lVirus^.SigLen, 1) > 0
    }

      i:=FastPos(ASourceString, p, length(ASourceString), ll, i+1);
      if i=0 then
        exit;
      if Matches(ASourceString, APatternString, i-delta) then
      begin
        if APatternString[1]='*then
          result:=StartPos
        else
          result:=i-delta;
        exit;
      end;
    until i=0;
  end;
end;
 //-----------pattern
// I use it like this way :

Delphi-Quellcode:

if ((FastPos( s,
                  lVirus^.Signature,
                  sLen,
                  lVirus^.SigLen, 1) > 0)Or
                  (patternPos(s,lVirus^.Signature,1) > 0)) then
                    result := gSignatures.IndexOf(lVirus);
But all this doesn't work with WildCard .


It makes me crazy why the patternPos doesn't give any result .


Please see the Attachment
Angehängte Dateien
Dateityp: rar scanner_124.rar (14,6 KB, 12x aufgerufen)
  Mit Zitat antworten Zitat