-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollision.c
More file actions
129 lines (115 loc) · 3.44 KB
/
collision.c
File metadata and controls
129 lines (115 loc) · 3.44 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <argp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libabikeccak.h"
#include "modedictionary.h"
#include "modenonce.h"
enum Mode { DICTIONARY, NONCE, HASH };
struct arguments {
enum Mode mode;
char *from;
char *fromPrefix;
char *to;
char *toPrefix;
int threadCount;
};
int arguments_parse_mode(char *string, enum Mode *toBeSet) {
if (string == NULL)
return 0;
else if (strcmp(string, "DICTIONARY") == 0) {
*toBeSet = DICTIONARY;
return 1;
} else if (strcmp(string, "NONCE") == 0) {
*toBeSet = NONCE;
return 1;
} else if (strcmp(string, "HASH") == 0) {
*toBeSet = NONCE;
return 1;
} else
return 0;
}
error_t arguments_parse(int key, char *arg, struct argp_state *state) {
struct arguments *arguments = state->input;
int parsed;
switch (key) {
case 'm':
if (!arguments_parse_mode(arg, &(arguments->mode))) argp_usage(state);
break;
case 'f':
arguments->fromPrefix = arg;
break;
case 't':
arguments->toPrefix = arg;
break;
case 'c':
parsed = atoi(arg);
if (parsed > 0) {
arguments->threadCount = parsed;
} else {
argp_usage(state);
}
break;
case ARGP_KEY_ARG:
if (state->arg_num >= 2)
argp_usage(state);
else if (state->arg_num == 0) {
arguments->from = arg;
break;
} else if (state->arg_num == 1) {
arguments->to = arg;
break;
}
break;
case ARGP_KEY_END:
if (!((arguments->mode == HASH && state->arg_num == 1) ||
(arguments->mode == NONCE && state->arg_num == 2) ||
(arguments->mode == DICTIONARY && state->arg_num == 2)))
argp_usage(state);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
int main(int argc, char *argv[]) {
char *argp_program_version = "SACT v1.0";
char *argp_program_bug_address = "konstantin.fickel@student.uni-augsburg.de";
char doc[] = "A program calculating collisions of the Solidity ABI.";
char args_doc[] = "from to";
struct argp_option options[] = {
{"mode", 'm', "HASH|DICTIONARY|NONCE", 0, "Mode of execution."},
{"from-prefix", 'f', "STRING", 0, "Prefix to be used on the from-side."},
{"to-prefix", 't', "FILE", 0, "Prefix to be used on the to-side."},
{"threads", 'c', "INTEGER", 0,
"Amount of threads used when no dictionary is used at the from-side."},
{0}};
struct arguments arguments;
arguments.mode = HASH;
arguments.from = NULL;
arguments.fromPrefix = NULL;
arguments.to = NULL;
arguments.toPrefix = NULL;
arguments.threadCount = 4;
struct argp argp = {options, arguments_parse, args_doc, doc};
argp_parse(&argp, argc, argv, 0, 0, &arguments);
if (arguments.mode == DICTIONARY) {
bruteforce_mode_dictionary(arguments.from, arguments.to,
arguments.fromPrefix, NULL, arguments.toPrefix,
NULL);
return EXIT_SUCCESS;
} else if (arguments.mode == NONCE) {
bruteforce_mode_nonce(
arguments.fromPrefix == NULL ? "" : arguments.fromPrefix,
arguments.from, arguments.toPrefix == NULL ? "" : arguments.toPrefix,
arguments.to, arguments.threadCount);
return EXIT_SUCCESS;
} else if (arguments.mode == HASH) {
char *hash;
calculate_contract_abi_hash(arguments.from, &hash);
printf("%s\n", hash);
free(hash);
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}