There is a binary file in which you need to find an ASCII string. Then, when the string is found, you need to go back a certain number of bytes until a double zero byte is found. Then, starting from this null byte and up to the desired string, copy the data. I did the search, but it works slowly. How can it all be optimized? And how is it better to count the number of characters in the opposite direction?
And is it worth rewriting it to 64 bits, will it be faster?
StringPos proc uses esi edi ebx szString, szSubStr,dwLen,subLen : DWORD
mov esi, szString ;string
mov edi, szSubStr ;substring
mov edx, subLen ;substring length
mov ecx, dwLen ;string length
xor eax, eax ;position
@@:
repz cmpsb ;compare
test ecx,ecx ;есх = 0 ?
jz @f ;exit
inc eax ;inc counter (position)
jmp @B ;compare again
@@:
sub eax,edx ;move pointer to the begin of string
inc eax ;without last char
ret
StringPos endp
;usage
str1 db "some fake d1ata a115huja",0,"flood data",0
str1_len equ ($-offset str1)-1
.code
start:
mov ebx,str1_len
invoke StringPos,offset str1,chr$("data"),ebx,4
lea ebx,str1
add ebx,eax
invoke OutputDebugStringA,ebx