-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGenerateHash.c
99 lines (94 loc) · 1.94 KB
/
GenerateHash.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//written by Rick2600 rick2600s[at]gmail{dot}com
//tweaked just a little by Peter Van Eeckhoutte
//http://www.corelan.be:8800
//This script will produce a hash for a given function name
//If no arguments are given, a list with some common function
//names and their corresponding hashes will be displayed
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
long rol(long value, int n);
long ror(long value, int n);
long calculate_hash(char *function_name);
void banner();
int main(int argc, char *argv[])
{
banner();
if (argc < 2)
{
int i=0;
char *func[] =
{
"FatalAppExitA",
"LoadLibraryA",
"GetProcAddress",
"WriteFile",
"CloseHandle",
"Sleep",
"ReadFile",
"GetStdHandle",
"CreatePipe",
"SetHandleInformation",
"WinExec",
"ExitProcess",
0x0
};
printf("HASH\t\t\tFUNCTION\n----\t\t\t--------\n");
while ( *func )
{
printf("0x%X\t\t%s\n", calculate_hash(*func), *func);
i++;
*func = func[i];
}
}
else
{
char *manfunc[] = {argv[1]};
printf("HASH\t\t\tFUNCTION\n----\t\t\t--------\n");
printf("0x%X\t\t%s\n", calculate_hash(*manfunc), *manfunc);
}
return 0;
}
long calculate_hash( char *function_name )
{
int aux = 0;
unsigned long hash = 0;
while (*function_name)
{
hash = ror(hash, 13);
hash += *function_name;
*function_name++;
}
while ( hash > 0 )
{
aux = aux << 8;
aux += (hash & 0x00000FF);
hash = hash >> 8;
}
hash = aux;
return hash;
}
long rol(long value, int n)
{
__asm__ ("rol %%cl, %%eax"
: "=a" (value)
: "a" (value), "c" (n)
);
return value;
}
long ror(long value, int n)
{
__asm__ ("ror %%cl, %%eax"
: "=a" (value)
: "a" (value), "c" (n)
);
return value;
}
void banner()
{
printf("----------------------------------------------\n");
printf(" --==[ GenerateHash v1.0 ]==--\n");
printf(" written by rick2600 and Peter Van Eeckhoutte\n");
printf(" http://www.corelan.be:8800\n");
printf("----------------------------------------------\n");
}