-
Notifications
You must be signed in to change notification settings - Fork 14
/
pyXoredBinEn-Decoder.py
65 lines (49 loc) · 1.46 KB
/
pyXoredBinEn-Decoder.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
54
55
56
57
58
59
60
61
62
63
64
65
# -*- encoding: utf-8 -*-
#
# FECT/pyXoredBinEn-Decoder.py
#
# Author: Jean-Philippe Teissier ( @Jipe_ )
#
# This work is licensed under the GNU General Public License
#
import binascii
import argparse
import sys
__version__ = '0.1'
def Main():
''' main '''
parser = argparse.ArgumentParser(description='[En|De]code a xored binary')
parser.add_argument('-i', '--input', help='Input filename')
parser.add_argument('-o', '--output', help='Output filename')
parser.add_argument('-k', '--key', help='optional Key (Default is 0x42)')
args = parser.parse_args()
xor_key = 0x42
if args.input and args.output:
bytes = None
if args.key:
xor_key = int(args.key)
print '[*] ' + args.input + ' -> ' + args.output
try:
filein = open(args.input, 'rb')
fileout = open(args.output, 'wb')
block = 10000000
bytes_ = filein.read(block)
while bytes_ != "":
print '[*] Reading... ' + str(len(bytes_)) + ' bytes to xor'
bytearray_ = bytearray(bytes_)
bytearray_len = len(bytearray_)
for i in range(bytearray_len):
bytearray_[i] ^= xor_key
fileout.write(bytearray_)
bytes_ = filein.read(block)
except IOError as e:
print '[!] Error({0}): {1}'.format(e.errno, e.strerror)
except:
print '[!] Unexpected error: ' + str(sys.exc_info()[0]) + ' ' + str(sys.exc_info()[1])
finally:
filein.close()
fileout.close()
else:
print '[!] Error: missing parameter (-i or -o)'
if __name__ == '__main__':
Main()