-
Notifications
You must be signed in to change notification settings - Fork 88
/
Hash.c
60 lines (53 loc) · 956 Bytes
/
Hash.c
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
*
* Reflective Loader
*
* GuidePoint Security LLC
*
* Threat and Attack Simulation
*
**/
#include "Common.h"
/*!
*
* Purpose:
*
* Creates a hash summary of the input buffer.
* If a length is not provided, it assumes it
* is NULL terminated.
*
!*/
D_SEC( E ) UINT32 HashString( _In_ PVOID Buffer, _In_opt_ ULONG Length )
{
UCHAR Cur = 0;
ULONG Djb = 0;
PUCHAR Ptr = NULL;
Djb = 5381;
Ptr = C_PTR( Buffer );
while ( TRUE ) {
/* Get the current character */
Cur = * Ptr;
if ( ! Length ) {
/* NULL terminated? */
if ( ! * Ptr ) {
break;
};
} else {
/* Position exceed the length of the buffer? */
if ( ( ULONG )( Ptr - ( PUCHAR ) Buffer ) >= Length ) {
break;
};
/* NULL terminated? */
if ( ! * Ptr ) {
++Ptr; continue;
};
};
/* Lowercase */
if ( Cur >= 'a' ) {
Cur -= 0x20;
};
/* Hash the character */
Djb = ( ( Djb << 5 ) + Djb ) + Cur; ++Ptr;
};
return Djb;
};