Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <windows.h>
#define MSG(m, s) MessageBox(0, (m), "Simple Heuristic Detector", (s))
int main(int argc, char *argv[])
{
FILE *fp;
char *buffer;
int sz;
int offset;
IMAGE_DOS_HEADER *idh;
IMAGE_NT_HEADERS *inh;
IMAGE_SECTION_HEADER *ish;
if (argc < 2) return 1;
if (!(fp = fopen(argv[1], "rb")))
{
MSG("Konnte die Datei nicht öffnen", MB_ICONERROR);
return 2;
}
fseek(fp, 0, SEEK_END);
sz = ftell(fp);
fseek(fp, 0, SEEK_SET);
if (!(buffer = (char *) malloc(sz + 1)))
{
MSG("Nicht genug Speicher vorhanden", MB_ICONERROR);
return 3;
}
fread(buffer, 1, sz, fp);
fclose(fp);
idh = (IMAGE_DOS_HEADER *) buffer;
if (idh->e_magic != 0x5A4D)
{
MSG("Fehlerhafte Datei", MB_ICONERROR);
return 4;
}
inh = (IMAGE_NT_HEADERS *) &buffer[idh->e_lfanew];
if (inh->Signature != 0x4550)
{
MSG("Fehlerhafte Datei", MB_ICONERROR);
return 4;
}
offset = idh->e_lfanew + sizeof(IMAGE_NT_HEADERS) +
(inh->FileHeader.NumberOfSections - 1) * sizeof(IMAGE_SECTION_HEADER);
ish = (IMAGE_SECTION_HEADER *) &buffer[offset];
offset = ish->PointerToRawData + ish->SizeOfRawData;
if (offset < sz)
{
MSG("Datei scheint modifiziert", MB_ICONWARNING);
}
else
{
MSG("Datei scheint normal zu sein", MB_ICONINFORMATION);
}
return 0;
}