forked from brichard19/BitCrack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
58 lines (44 loc) · 1.04 KB
/
main.cpp
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
#include <stdio.h>
bool create(char *inputFile, char *outputFile, char *symbol)
{
char buf[1024];
FILE *fpIn = fopen(inputFile, "rb");
if(fpIn == NULL) {
printf("Error opening '%s' for reading\n", inputFile);
return false;
}
FILE *fpOut = fopen(outputFile, "w");
if(fpOut == NULL) {
printf("Error opening '%s' for writing\n", outputFile);
fclose(fpIn);
return false;
}
fprintf(fpOut, "char %s[] = {", symbol);
size_t bytesRead = 0;
while((bytesRead = fread(buf, 1, sizeof(buf), fpIn))) {
for(int i = 0; i < bytesRead; i++) {
fprintf(fpOut, "0x%x,", buf[i]);
}
}
fprintf(fpOut, "0x00};\n");
fclose(fpIn);
fclose(fpOut);
return true;
}
void usage()
{
printf("Usage:\n");
printf("<input_file> <output_file> <symbol>\n");
}
int main(int argc, char **argv)
{
if(argc != 4) {
usage();
return 1;
}
if(create(argv[1], argv[2], argv[3])) {
return 0;
} else {
return 1;
}
}