STRSTR under Win32ASM

xiaoxiao2021-03-05  21

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 02 #include 03 04 int mySTR (char * addr1, char * addr2) 05 {06 INT M, N; 07 INT X; 08 x = Strlen (addr1); 09 FOR (n = 0; n <= strlen (addr1); n ) 10 {11 IF (* addr1 n == * addr2) 12 {13 for (m = 0; m <= strlen (addr2); m ) 14 {15 IF (* Addr1 N M! = * Addr2 M) 16 {17 Break; 18} 19 IF (M == Strlen (addr2)) 20 {21 Return N; 22} 23} 24} 25 26} 27 28 RETURN 0; 29} 30 int Main () 31 {32 int Num; 33 NUM = MySTRSTR ("12345678", "78"); 34 Printf ("% D", NUM); 35 return 0; 36} 37 38

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 ...

转载请注明原文地址:https://www.9cbs.com/read-38940.html

New Post(0)