forked from XenocodeRCE/AntiTamperEOF
/
EOFAntitamp.cs
25 lines (23 loc) · 883 Bytes
/
EOFAntitamp.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace AntiTamperEOF
{
class EOFAntitamp
{
static void Initialize()
{
string assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
Stream stream = new StreamReader(assemblyLocation).BaseStream;
BinaryReader reader = new BinaryReader(stream);
string realMd5 = null, newMd5 = null;
newMd5 = BitConverter.ToString(System.Security.Cryptography.MD5.Create().ComputeHash(reader.ReadBytes(System.IO.File.ReadAllBytes(assemblyLocation).Length - 16)));
stream.Seek(-16, SeekOrigin.End);
realMd5 = BitConverter.ToString(reader.ReadBytes(16));
if (newMd5 != realMd5)
throw new BadImageFormatException();
}
}
}