Germany2896 Posts
for matching the signature you can use a simple binary safe StringPos function. If you want to code it yourself you can use sth like the following:
function CheckForSig(File:String;Sig:String); var i,j:integer; hit:boolean; for i:=0 to length(file)-1 do hit:=true; for j:=0 to min(length(file)-1-i,length(sig)-1) do if file[i+j]!=sig[j]then hit:=false;break;end; end; if hit then return true; end; end; return false; end; of cause that is not the fastest possible way of doing it, for a large signature set.
edit: Pos function used by Delphi (asmcode ) + Show Spoiler +(* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1 * * The implementation of function Pos is subject to the * Mozilla Public License Version 1.1 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is Fastcode * * The Initial Developer of the Original Code is Fastcode * * Portions created by the Initial Developer are Copyright (C) 2002-2004 * the Initial Developer. All Rights Reserved. * * Contributor(s): Aleksandr Sharahov * * ***** END LICENSE BLOCK ***** *) function Pos(const substr, str: AnsiString): Integer; overload; asm push ebx push esi add esp, -16 test edx, edx jz @NotFound test eax, eax jz @NotFound mov esi, [edx-4] //Length(Str) mov ebx, [eax-4] //Length(Substr) cmp esi, ebx jl @NotFound test ebx, ebx jle @NotFound dec ebx add esi, edx add edx, ebx mov [esp+8], esi add eax, ebx mov [esp+4], edx neg ebx movzx ecx, byte ptr [eax] mov [esp], ebx jnz @FindString sub esi, 2 mov [esp+12], esi @FindChar2: cmp cl, [edx] jz @Matched0ch cmp cl, [edx+1] jz @Matched1ch add edx, 2 cmp edx, [esp+12] jb @FindChar4 cmp edx, [esp+8] jb @FindChar2 @NotFound: xor eax, eax jmp @Exit0ch @FindChar4: cmp cl, [edx] jz @Matched0ch cmp cl, [edx+1] jz @Matched1ch cmp cl, [edx+2] jz @Matched2ch cmp cl, [edx+3] jz @Matched3ch add edx, 4 cmp edx, [esp+12] jb @FindChar4 cmp edx, [esp+8] jb @FindChar2 xor eax, eax jmp @Exit0ch @Matched2ch: add edx, 2 @Matched0ch: inc edx mov eax, edx sub eax, [esp+4] @Exit0ch: add esp, 16 pop esi pop ebx ret @Matched3ch: add edx, 2 @Matched1ch: add edx, 2 xor eax, eax cmp edx, [esp+8] ja @Exit1ch mov eax, edx sub eax, [esp+4] @Exit1ch: add esp, 16 pop esi pop ebx ret @FindString4: cmp cl, [edx] jz @Test0 cmp cl, [edx+1] jz @Test1 cmp cl, [edx+2] jz @Test2 cmp cl, [edx+3] jz @Test3 add edx, 4 cmp edx, [esp+12] jb @FindString4 cmp edx, [esp+8] jb @FindString2 xor eax, eax jmp @Exit1 @FindString: sub esi, 2 mov [esp+12], esi @FindString2: cmp cl, [edx] jz @Test0 @AfterTest0: cmp cl, [edx+1] jz @Test1 @AfterTest1: add edx, 2 cmp edx, [esp+12] jb @FindString4 cmp edx, [esp+8] jb @FindString2 xor eax, eax jmp @Exit1 @Test3: add edx, 2 @Test1: mov esi, [esp] @Loop1: movzx ebx, word ptr [esi+eax] cmp bx, word ptr [esi+edx+1] jnz @AfterTest1 add esi, 2 jl @Loop1 add edx, 2 xor eax, eax cmp edx, [esp+8] ja @Exit1 @RetCode1: mov eax, edx sub eax, [esp+4] @Exit1: add esp, 16 pop esi pop ebx ret @Test2: add edx,2 @Test0: mov esi, [esp] @Loop0: movzx ebx, word ptr [esi+eax] cmp bx, word ptr [esi+edx] jnz @AfterTest0 add esi, 2 jl @Loop0 inc edx @RetCode0: mov eax, edx sub eax, [esp+4] add esp, 16 pop esi pop ebx end;
|