forked from benheise/ANGRYORCHARD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hash.c
50 lines (45 loc) · 742 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
/*!
*
* Exploit
*
* GuidePoint Security LLC
*
* Threat and Attack Simulation
*
!*/
#include "Common.h"
/*!
*
* Purpose:
*
* Creates a hash of an input buffer. If a length
* is not provided, it assumes it is a null
* terminated string.
*
!*/
D_SEC( E ) UINT32 HashString( _In_ PVOID Buffer, _In_opt_ UINT32 Length )
{
UINT8 Cur = 0;
UINT32 Djb = 5381;
PUINT8 Ptr = C_PTR( Buffer );
while ( TRUE ) {
Cur = * Ptr;
if ( ! Length ) {
if ( ! * Ptr ) {
break;
};
} else {
if ( ( UINT32 )( Ptr - ( PUINT8 ) Buffer ) >= Length ) {
break;
};
if ( ! * Ptr ) {
++Ptr; continue;
};
};
if ( Cur >= 'a' ) {
Cur -= 0x20;
};
Djb = ( ( Djb << 5 ) + Djb ) + Cur; ++Ptr;
};
return Djb;
};