pattern searching of binary data
<p>I am trying to build antivirus in C.
I do that like this:</p>

<ol>
<li><p>Read data of virus and picture file to scanned.</p></li>
<li><p>Check if virus data appear in picture data.</p></li>
</ol>

<p>I read the data of scanned file and virus file like this: ( I read the file by binary mode because the file is picture(.png) )</p>

<pre><code>// open file
file = fopen(filePath, "rb");
if (!file)
{
    printf("Error: can't open file.\n");
    return 0;
}

// Allocate memory for fileData
char* fileData = calloc(fileLength + 1, sizeof(char));

// Read data of file.
fread(fileData, fileLength, 1, file);
</code></pre>

<p>after i read the file data and the Virus data i check if the virus appear in the file like this:</p>

<pre><code>char* ret = strstr(fileData, virusID);
if (ret != NULL)
    printf("Infetecd file");
</code></pre>

<p>It does not work even though in my picture i have VirusID.
I want to check if the binary data of virus appear in binary data of picture.</p>

<p>For example: my binary data of my virus <a href="http://pastebin.com/xZbWA9qu" rel="nofollow">http://pastebin.com/xZbWA9qu</a></p>

<p>And the binary data of my picture(with the virus): <a href="http://pastebin.com/yjXr84kr" rel="nofollow">http://pastebin.com/yjXr84kr</a></p>