-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnks.py
32 lines (30 loc) · 1.07 KB
/
nks.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
#!/usr/bin/env python
import numpy
def getInd(fileHandle, address, xor=False):
fileHandle.seek(address)
if xor == True:
bxor = int.from_bytes(fileHandle.read(1), byteorder='little')
address = int.from_bytes(fileHandle.read(4), byteorder='little')
if xor == True:
address ^= bxor
return address
def getStr(fileHandle, address, xor=True, maxlength=20000):
fileHandle.seek(address)
if xor == True:
bxor = fileHandle.read(1)
length = int.from_bytes(fileHandle.read(4), byteorder='little')
if xor == True:
length ^= int.from_bytes(bxor, byteorder='little')
if length > maxlength or length == 0:
return None, None
string = fileHandle.read(length)
decoded = (numpy.frombuffer(bxor,dtype=numpy.uint8)^numpy.frombuffer(string, dtype=numpy.uint8)).tobytes()
try:
decoded = decoded.decode('utf8')
except UnicodeDecodeError:
decoded = decoded.decode('cp1251')
except:
return None, None
if decoded[:6] != "<BODY>":
return None, None
return length, decoded