forked from DidierStevens/DidierStevensSuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decoder_rol1.py
53 lines (41 loc) · 1.31 KB
/
decoder_rol1.py
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
#!/usr/bin/env python
__description__ = 'ROL 1 byte decoder for oledump.py'
__author__ = 'Didier Stevens'
__version__ = '0.0.2'
__date__ = '2019/11/24'
"""
Source code put in public domain by Didier Stevens, no Copyright
https://DidierStevens.com
Use at your own risk
History:
2014/12/16: start
2019/11/24: Python 3 fixes
Todo:
"""
def ParseNumber(number):
if number.startswith('0x'):
return int(number[2:], 16)
else:
return int(number)
class cROL1Decoder(cDecoderParent):
name = 'ROL 1 byte decoder'
def __init__(self, stream, options):
self.stream = stream
self.options = options
if self.options.startswith('-k '):
self.keyROL1 = ParseNumber(self.options[3:])
else:
self.keyROL1 = 0x01
def Available(self):
return self.keyROL1 != 0x08
def Decode(self):
if sys.version_info[0] > 2:
decoded = bytes([(((c << self.keyROL1) | (c >> (8 - self.keyROL1))) & 0xFF) for c in self.stream])
else:
decoded = ''.join([chr(((ord(c) << self.keyROL1) | (ord(c) >> (8 - self.keyROL1))) & 0xFF) for c in self.stream])
self.name = 'ROL 1 byte key 0x%02X' % self.keyROL1
self.keyROL1 += 1
return decoded
def Name(self):
return self.name
AddDecoder(cROL1Decoder)