Continue mixing ... Continue some bored code ... Waiting for work ... strstr is a function that is often used. Many people always think that this function Windows is not available, so I am writing, I am also one of them ... (actual There is a LSTRSTR function in Advapi32.dll). Now write a simple strstr, no algorithm is used ... Simple can be directly plagiarized ...
The first is a general idea written in C language:
01 #include
Just like this ... well, write it now:
01 strstr proc pszHaystack: PTR BYTE, pszNeedle: PTR BYTE, dwCaseSensitive: DWORD02 push esi03 push edi04 xor eax, eax05 xor ecx, ecx06 xor edx, edx07 mov esi, [pszHaystack] 08 mov edi, [pszNeedle] 09 @@ char: Mov Al, Byte Ptr [ESI] 10 MOV AH, BYTE PTR [EDI] 11 CMP [DWCaseSensitive], 012 JNE @@ cmp113 CMP AL, "Z" 14 JA @@ cmp015 cmp Al, "a" 16 jb @@ cmp017 Add Al, 3218 @@ cmp0: CMP [dwcasesensitive], 019 JNE @@ cmp120 CMP AH, "Z" 21 JA @@ cmp122 CMP AH, "a" 23 JB @@ cmp124 add AH, 3225 @@ cmp1: CMP Al , AH26 JNE @@ next27 incc ECX28 MOV EAX, ESI29 Inc EDI30 Inc ESI31 Inc EAX32 CMP BYTE PTR [ESI], 033 JE @@ Zero34 CMP BYTE PTR [EDI], 035 JE @@ quit36 jmp @@ char37 @@ zero: MOV DL, BYTE PTR [EDI] 38 CMP DL, BYTE PTR [ESI] 39 JE @@ quit40 xor EAX, EAX41 XOR ECX, ECX42 JMP @@ quit43 @@ Next: Mov Edi, [PszNeedle] 44 Test ECX, ECX45 Setz DL46 Add ESI, EDX47 XOR ECX, ECX48 XOR EAX, EAX49 CMP BYTE PTR [ESI ], 050 JNE @@ char51 @@ quit: Sub Eax, ECX52 POP EDI53 POP ESI54 RET55 STRSTR ENDP seems to have a copy ... Because it is judged to the case, ......
I have time to realize the KMP algorithm with compilation, of course, this "later" is a long time ...