-
Notifications
You must be signed in to change notification settings - Fork 4
/
bootcodecrypto.c
64 lines (55 loc) · 1.33 KB
/
bootcodecrypto.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
//Handles bootcode crypto of disk started bootcode.
#include <stdio.h>
#include <string.h>
void decrypt(unsigned char* enc, unsigned char* dec)
{
int i, t = 0;
for (i = 0; i < 0x100; i++)
{
t = (i * 0x11) & 0xFF;
dec[t] = enc[i];
}
}
void encrypt(unsigned char* dec, unsigned char* enc)
{
int i, t = 0;
for (i = 0; i < 0x100; i++)
{
t = (i * 0x11) & 0xFF;
enc[i] = dec[t];
}
}
int main(int argc, char const *argv[])
{
FILE *pFileIn;
FILE *pFileOut;
unsigned char in[0x100];
unsigned char out[0x100];
if (argc < 4)
{
printf("usage: bootcodecrypto <cmd> <in> <out>\n<cmd> can be:\n -d = decrypt\n -e = encrypt\n");
}
else
{
if (strncmp(argv[1],"-d",2) != 0 && strncmp(argv[1],"-e",2) != 0)
{
printf("Unknown command");
return 1;
}
pFileIn = fopen(argv[2], "rb");
if (pFileIn == NULL)
return 1;
fread(in, 1, 0x100, pFileIn);
fclose(pFileIn);
if (strncmp(argv[1],"-d",2) == 0)
decrypt(in, out);
else
encrypt(in, out);
pFileOut = fopen(argv[3], "wb");
if (pFileOut == NULL)
return 1;
fwrite(out, 1, 0x100, pFileOut);
fclose(pFileOut);
}
return 0;
}