Hi,

i'm looking for a fast function to scan a given blockbuffer for a string.

Because i have to scan also for 00h chars inside the invoke InString function is pretty much useless for this.

That means i have to scan for a string that looks like this:
20002000 ( means space, zero, space and zero again )

InPos PROC BlockBuffer: DWORD, ScanSize: DWORD, SearchString: DWORD

BlockBuffer is the Buffer, let's say a 6kb Byte Buffer
ScanSize is the size of the Searchstring ( because it contains 00h so we cannot use stringlen functions here )
and SearchString is the SearchString for what i am looking for.

In Pascal this function looks as follows:

function BPos(var MyBuffer; BufferSize: LongInt; S: String): LongInt;
var
{&H+}
St: String;
{&H-}
begin
SetLength(St, BufferSize);
Move(MyBuffer, Pointer(St)^, BufferSize);
Result := Pos(S, St);
end;

I need excactly the same function in asm ( MASM ).
Can somebody help me here ?

Thanks in advance.
Posted on 2005-01-30 22:15:07 by Smarty32
PEterWolf was solving this recently, see
General -> Main -> Searching a string in a file
Posted on 2005-01-31 10:42:18 by vit$oft
Thanks, but can anybody post a short sample source which is equal to this Delphi funtion ? I need search also with 00h inside strings, so i dont know how to handle this because the string compare instructions stoping if they found 00h :shock:
Posted on 2005-01-31 18:31:25 by Smarty32
InString function
source in m32lib folder of masm

Binary search for substring within larger string, 0 irrelevant :)
Posted on 2005-01-31 23:04:58 by Homer
What abt rep scasd?
Posted on 2005-02-01 06:05:36 by roticv
can anybody post a short sample source



MOV EDI,OFFSET BlockBuffer
MOV ECX,SIZEOF BlockBuffer
MOV ESI,OFFSET String
MOV EDX,SIZEOF String - 1
CLD
LODSB ; 1st Char of String
Find1stChar:
REPNE SCASB ; find 1st Char in BlockBuffer
JNE NotFound ; all BlockBuffer searched
PUSH ECX,ESI,EDI
CMP ECX,EDX
JB NearEnd
MOV ECX,EDX
REPE CMPSB ; compare the rest of String
NearEnd:
POP EDI,ESI,ECX
JNE Find1stChar ; if not found, continue with 1st Char
Found: DEC EDI ; to point at string in BlockBuffer
Posted on 2005-02-01 10:26:37 by vit$oft