I am trying to write a program that finds certain data
patterns in files. FIND.EXE from DOS would do the trick
ofcourse but I want it to search from the end of the file too.
To achieve this I need a procedure which compares two
memory buffers. one with the search pattern, and one data
buffer which holds the file data. Both of an arbitrary size.
The procedure must be able to search from start to end, and
from end to start of the buffer.
The idea is to load the buffer with about 1024 bytes of the
file, search it using the routine, then read another 1024
bytes etc. until a match have been found.
It needs to be a 16 bit real mode DOS program.
I tried to write the procedure using a variety of string
instructions: scas, lods, cmps. By using these instructions
I could use the direction flag to search forward or
backward. I encountered a lot of problems along the way.
One of them is the question of what if the match overlaps
two buffers? I would have to save the state of the previous
search before I go on to the next.
I have written a lot of versions of the procedure, all
incomplete and flawed. So I will not post them here.
Has anybody had to write a similar algorithm, or does
anybody have an idea?
thx.
patterns in files. FIND.EXE from DOS would do the trick
ofcourse but I want it to search from the end of the file too.
To achieve this I need a procedure which compares two
memory buffers. one with the search pattern, and one data
buffer which holds the file data. Both of an arbitrary size.
The procedure must be able to search from start to end, and
from end to start of the buffer.
The idea is to load the buffer with about 1024 bytes of the
file, search it using the routine, then read another 1024
bytes etc. until a match have been found.
It needs to be a 16 bit real mode DOS program.
I tried to write the procedure using a variety of string
instructions: scas, lods, cmps. By using these instructions
I could use the direction flag to search forward or
backward. I encountered a lot of problems along the way.
One of them is the question of what if the match overlaps
two buffers? I would have to save the state of the previous
search before I go on to the next.
I have written a lot of versions of the procedure, all
incomplete and flawed. So I will not post them here.
Has anybody had to write a similar algorithm, or does
anybody have an idea?
thx.