-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathhash.h
46 lines (37 loc) · 892 Bytes
/
hash.h
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Taken from zerosum0x0 https://github.com/zerosum0x0/zeroload/blob/master/zdi/dll/zeroload/hash.h
#pragma once
#include "headers.h"
#include <Windows.h>
// this is a variation of the fnv1a_32 hash algorithm, but keeping the original primes,
// changed to allow both unicode and char*, slower but same distribution for ascii text
DWORD __forceinline compute_hash(const void* input, UINT32 len)
{
const unsigned char* data = (const unsigned char*)input;
DWORD hash = 2166136261;
while (1)
{
char current = *data;
if (len == 0)
{
if (*data == 0)
break;
}
else
{
if ((UINT32)(data - (const unsigned char*)input) >= len)
break;
if (*data == 0)
{
++data;
continue;
}
}
// toupper
if (current >= 'a')
current -= 0x20;
hash ^= current;
hash *= 16777619;
++data;
}
return hash;
}