I have two files:
FILE* fileToScan = fopen("c:/fileToScan.png", "rb");
FILE* contentFile = fopen("c:/virusFile.jpg", "rb");
I want to check if the content of contentFile is in (/part of) fileToScan. Any help?
"Simple" solution:
char *haystack;
with size size_t haystack_len;
char *needle;
with size size_t needle_len;
memchr()
on haystack using the first character of needlememcmp()
from that pointmemcmp()
fails you can update the haystack pointer to one past the memchr()
result and go back to step 3This is using no optimization at all! You can find definitely find better implementations like the glibc one.
If the file doesn't fit in memory, things are going to be harder. You basically need to work in chunks.