cs_Gerard
Messages postés121Date d'inscriptionjeudi 10 janvier 2002StatutMembreDernière intervention 7 août 2018
-
17 mars 2017 à 06:46
Cirec
Messages postés3833Date d'inscriptionvendredi 23 juillet 2004StatutModérateurDernière intervention18 septembre 2022
-
17 mars 2017 à 10:05
Bonjour,
J'ai modifié la fonction Posex de Delphi en assembleur pour en faire une fonction Posexact, qui elle ne fait que confirmer que la chaîne cherchée est à la place attendue.
par exemple la fonction PosExact('GET',Str1) va répondre True si Str1 commence par GET et false sinon.
la fonction PosExact(url,Str1,6) va répondre Vrai si l'url se trouve à la 6ème place dans un GET /url.
Cette fonction est particulièrement rapide puisqu'elle ne commence la recherche qu'à l'offset indiqué (1 par défaut) et cesse dès qu'il y a un écart : la chaîne entière n'est pas parcourue en vain....
elle est très utile dans un serveur...
--
function PosExact(const SubStr, S: string; Offset: Integer = 1): Boolean; asm test eax, eax jz @Nil test edx, edx jz @Nil dec ecx jl @Nil
push esi push ebx
mov esi, [edx-4] //Length(Str) mov ebx, [eax-4] //Length(Substr) sub esi, ecx //effective length of Str add edx, ecx //addr of the first char at starting position cmp esi, ebx jl @Past //jump if EffectiveLength(Str)<Length(Substr) test ebx, ebx jle @Past //jump if Length(Substr)<=0
add esp, -12 add ebx, -1 //Length(Substr)-1 add esi, edx //addr of the terminator add edx, ebx //addr of the last char at starting position mov [esp+8], esi //save addr of the terminator add eax, ebx //addr of the last char of Substr sub ecx, edx //-@Str[Length(Substr)] neg ebx //-(Length(Substr)-1) mov [esp+4], ecx //save -@Str[Length(Substr)] mov [esp], ebx //save -(Length(Substr)-1) movzx ecx, byte ptr [eax] //the last char of Substr
@Loop: cmp cl, [edx] jz @Test0 jmp @Exit //Le caractère est différent @AfterTest0: cmp cl, [edx+1] jz @TestT @AfterTestT: add edx, 4 cmp edx, [esp+8] jb @Continue @EndLoop: add edx, -2 cmp edx, [esp+8] jb @Loop @Exit: add esp, 12 @Past: pop ebx pop esi @Nil: xor eax, eax ret @Continue: cmp cl, [edx-2] jz @Test2 cmp cl, [edx-1] jnz @Loop @Test1: add edx, 1 @Test2: add edx, -2 @Test0: add edx, -1 @TestT: //le premier caractère colle mov esi, [esp] //En reste-t-il d'autres ? test esi, esi jz @Found @String: //Commencer à explorer la suite movzx ebx, word ptr [esi+eax] cmp bx, word ptr [esi+edx+1] //mettre les caractères suivants dans Bx jnz @exit cmp esi, -2 //reste caractères ? jge @Found movzx ebx, word ptr [esi+eax+2] //prendre deux autres caractères cmp bx, word ptr [esi+edx+3] jnz @exit //si cela ne coincide pas aller vers un autre test add esi, 4 //decrémenter le reste à explorer jl @String //si négatif il reste plus d'un caractères @Found: mov eax, [esp+4] add edx, 2
cmp edx, [esp+8] ja @Exit
add esp, 12 // add eax, edx //mettre la position dans eax pop ebx pop esi end;