-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdec.c
More file actions
88 lines (67 loc) · 2.11 KB
/
dec.c
File metadata and controls
88 lines (67 loc) · 2.11 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
/*
Decoder for Vortex Pok3r firmware. Firmware comes as windows PE,
containing block of data encrypted with some bit shifting and byte swapping,
this simple c program decrypts it.
Copyright © 2016 Eugene Mihailenco <mihailencoe@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <unistd.h>
#define SIZE_B 5
// Each byte decreased by 7 and cyclic shifted by 4bits, then
// for things greater or less then 0x90 we add 1 to low nibble
void decode(unsigned char* p, int len)
{
for (int i = 0; i < len; i++)
{
unsigned char c = p[i];
c -= 7;
c = (c << 4) | (c >> 4);
if (c >= 0x90)
c = (c & 0xf0) | ((c + 1) & 0x0f);
p[i] = c;
}
}
void swap(unsigned char* a, unsigned char* b)
{
unsigned char c = *a; *a = *b; *b = c;
}
int main(int argc, const char* argv[])
{
// Read block of 10 a time
unsigned char ch[SIZE_B * 2];
for (;;)
{
int t = read(0, ch, SIZE_B * 2);
// Swapping 1st and 5th (and 6th and 10th if any) bytes
if (t == SIZE_B * 2)
{
swap(ch, ch + SIZE_B - 1);
swap(ch + SIZE_B, ch + SIZE_B * 2 - 1);
}
else if (t >= SIZE_B)
{
swap(ch, ch + SIZE_B - 1);
}
// Swap each even with odd bytes
for (int i = 0; i < t - 1; i += 2)
{
swap(ch + i, ch + i + 1);
}
// Do bitshifting decryption
decode(ch, t);
write(1, ch, t);
if (t != SIZE_B * 2)
break;
}
return 0;
}