- Joined
- Aug 6, 2005
- Messages
- 552
- Reaction score
- 298
MultiCore CheckSum.dat Generator *Optimized*
Hi guys,
I was bored and tried the new Parallel feature of .NET on the CheckSum.dat Generator Its pretty fast now, around 2.6s on my Intel i750.
Update: Optimized it a bit
How to use:
1. Copy the main.exe to this Generators Directory, or vice versa.
2. Run the Generator. It will automatically take the main.exe located in the same Directory, and also saves the CheckSum.dat in the same Directory. Note: It will overwrite an existing CheckSum.dat.
3. Use the generated CheckSum.dat for your Server.
4. Enjoy
To run this thing, you need .NET Framework 4 installed.
Source(C#):
Compiled .exe attached to this Post.
Credits: Deathway for the C++ Source
EDIT: Attachment didn´t work anymore, and cant attach it again, so i upped it at 1-click-hoster. Sry.
Download Mirrors:
Hi guys,
I was bored and tried the new Parallel feature of .NET on the CheckSum.dat Generator Its pretty fast now, around 2.6s on my Intel i750.
Update: Optimized it a bit
How to use:
1. Copy the main.exe to this Generators Directory, or vice versa.
2. Run the Generator. It will automatically take the main.exe located in the same Directory, and also saves the CheckSum.dat in the same Directory. Note: It will overwrite an existing CheckSum.dat.
3. Use the generated CheckSum.dat for your Server.
4. Enjoy
To run this thing, you need .NET Framework 4 installed.
Source(C#):
Code:
using System;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using System.Threading.Tasks;
namespace MainChecksumGen
{
static class Program
{
static uint filesize;
static void Main(string[] args)
{
CheckSumFile csf = new CheckSumFile();
csf.Checksums = new uint[1024];
byte[] lpFileBuffer;
int ms = 0;
try
{
using (FileStream fs = new FileStream("main.exe", FileMode.Open))
{
lpFileBuffer = new byte[fs.Length];
fs.Read(lpFileBuffer, 0, lpFileBuffer.Length);
}
filesize = (uint)lpFileBuffer.Length;
int start = Environment.TickCount;
Parallel.For(0, 1024, i =>
{
csf.Checksums[i] = GetChecksum(lpFileBuffer, (ushort)i);
});
ms = Environment.TickCount - start;
using (FileStream ss = File.Create("CheckSum.dat"))
{
ss.Write(Serialize(csf), 0, 4096);
}
}
catch (FileNotFoundException e)
{
Console.WriteLine("Couldn't find main.exe. Make sure its in the same directory as the Program");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("Completed in {0} ms. Saved to CheckSum.dat.\nPress Any Key to continue...", ms);
Console.ReadKey();
}
static uint GetChecksum(byte[] lpFileBuffer, ushort wChecksumKey)
{
uint dwResult = (uint)wChecksumKey << 9;
for (uint I = 0; I < filesize; I += 4)
{
uint dwKey = MakeDword(lpFileBuffer, I);
switch (((I >> 2) + wChecksumKey) % 3)
{
case 0:
dwResult ^= dwKey;
break;
case 1:
dwResult += dwKey;
break;
case 2:
dwResult = dwResult << (int)(dwKey % 11);
dwResult ^= dwKey;
break;
}
dwResult ^= (wChecksumKey + dwResult) >> (int)((I >> 2) % 16 + 3);
}
return dwResult;
}
public static byte[] Serialize(object Obj)
{
int rawsize = Marshal.SizeOf(Obj);
byte[] rawdata = new byte[rawsize];
GCHandle handle = GCHandle.Alloc(rawdata, GCHandleType.Pinned);
Marshal.StructureToPtr(Obj, handle.AddrOfPinnedObject(), false);
handle.Free();
return rawdata;
}
public static uint MakeDword(byte[] bytes, uint start)
{
return (uint)((bytes[start + 3] << 24) | (bytes[start + 2] << 16) | (bytes[start + 1] << 8) | bytes[start]);
}
}
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 4096)]
struct CheckSumFile
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]
internal uint[] Checksums;
}
}
Credits: Deathway for the C++ Source
EDIT: Attachment didn´t work anymore, and cant attach it again, so i upped it at 1-click-hoster. Sry.
Download Mirrors:
You must be registered to see links
Last edited: