-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodedictionary.c
More file actions
91 lines (75 loc) · 2.52 KB
/
modedictionary.c
File metadata and controls
91 lines (75 loc) · 2.52 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <uthash.h>
#include "libabikeccak.h"
#include "libdictionary.h"
struct FunctionHash {
char *hash;
char *identifier;
UT_hash_handle hh;
};
int insert_hashmap(char *entry, struct FunctionHash **hashTable) {
struct FunctionHash *fh =
(struct FunctionHash *)malloc(sizeof(struct FunctionHash));
calculate_contract_abi_hash(entry, &(fh->hash));
fh->identifier = strdup(entry);
HASH_ADD_KEYPTR(hh, *hashTable, fh->hash, strlen(fh->hash), fh);
return 0;
}
int test_against_hashmap(char *entry, struct FunctionHash **hashTable) {
struct FunctionHash *fh;
char *hash;
int returnValue = 0;
calculate_contract_abi_hash(entry, &hash);
HASH_FIND_STR(*hashTable, hash, fh);
if (fh) {
printf("hash(\"%s\") = hash(\"%s\") = %s\n", entry, fh->identifier, hash);
returnValue = 1;
}
free(hash);
return returnValue;
}
void iterate_dictionary(char *dictionaryFile, struct FunctionHash **hashTable,
char *prefix, char *suffix,
int (*functionPtr)(char *,
struct FunctionHash **hashTable)) {
struct Dictionary *dictionary = NULL;
dictionary_allocate(&dictionary);
if (prefix != NULL) {
dictionary_addWord(&dictionary, prefix);
dictionary_newSegment(&dictionary);
}
dictionary_fromFile(dictionaryFile, &dictionary);
if (prefix != NULL) {
dictionary_newSegment(&dictionary);
dictionary_addWord(&dictionary, suffix);
}
struct DictionaryIterator *dictionaryIterator = NULL;
dictionaryIterator_allocate(&dictionaryIterator, &dictionary);
char *generated = NULL;
while (dictionaryIterator_nextEntry(&dictionaryIterator, &generated)) {
(*functionPtr)(generated, hashTable);
}
if (generated) {
free(generated);
}
dictionaryIterator_free(&dictionaryIterator);
dictionary_free(&dictionary);
}
int bruteforce_mode_dictionary(char *fromDictionaryFile, char *toDictionaryFile,
char *fromPrefix, char *fromSuffix,
char *toPrefix, char *toSuffix) {
struct FunctionHash *s, *tmp, *hashTable = NULL;
iterate_dictionary(fromDictionaryFile, &hashTable, fromPrefix, fromSuffix,
&insert_hashmap);
iterate_dictionary(toDictionaryFile, &hashTable, toPrefix, toSuffix,
&test_against_hashmap);
HASH_ITER(hh, hashTable, s, tmp) {
HASH_DEL(hashTable, s);
free(s->hash);
free(s->identifier);
free(s);
}
return EXIT_SUCCESS;
}