-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathstrxor.py
executable file
·57 lines (45 loc) · 1.19 KB
/
strxor.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
#!/usr/bin/python
import pefile
import sys, os
# Xor a file with "strin" key.
# v 0.1
# Need https://code.google.com/p/pefile et on lui doit TOUT
#
# Extract PEFile from "Dump"
#
# Copyleft Thanat0s
# http://Thanat0s.trollprod.org
#
# Licence GNU GPL
# Needs two arg if not... help
if len(sys.argv) <= 2:
print 'Xor a file with Byte key'
print 'To Use: '+ sys.argv[0]+ ' filename xorkey '
print ' xorkey is a strning'
sys.exit(1)
FILENAME = sys.argv[1]
# Test if file exists
if not os.path.isfile(FILENAME):
print 'ERROR: File not found'
sys.exit(1)
INC = 0
# Get xor key
KEYS = sys.argv[2]
print "data, key, inc, base, result"
LINE=0
PK = 0
with open(FILENAME, 'rb') as f:
filearray = bytearray(f.read())
for I in range(0, len(filearray)):
BCK = int(filearray[I])
KEY = ord(KEYS[PK % len(KEYS)])
PK = PK + 1
filearray[I] = (filearray[I] ^ KEY) % 255
LINE =LINE+1
if LINE < 10:
print (int(BCK), KEY, INC, int(filearray[I]))
if LINE == 11:
print "... "
print ('writing output to %s.xor' % FILENAME)
with open(('%s.xor' % FILENAME), 'w') as outfile:
outfile.write(filearray)