Update PDF code for Python2

This commit is contained in:
Florian Bach 2022-01-16 18:34:52 +01:00
parent 6d72506fad
commit 05a302424c
3 changed files with 24 additions and 5 deletions

View File

@ -17,6 +17,7 @@ popd
# Delete cache
rm -r __pycache__
rm *.pyc
# Set module ID. This needs to be changed if any of the module ZIPs change.
echo -n "2021-12-19-03" > module_id.txt

View File

@ -392,6 +392,8 @@ def encrypt_with_device_key(data):
for _ in range(remain):
data.append(remain)
data = bytes(data)
iv = Random.get_random_bytes(16)
cip = AES.new(devkey_bytes, AES.MODE_CBC, iv)

View File

@ -1,25 +1,37 @@
import os, zlib, base64, time
import sys, os, zlib, base64, time
class BackwardReader:
def __init__(self, file):
self.file = file
def readlines(self):
BLKSIZE = 4096
# Move reader to the end of file
self.file.seek(0, os.SEEK_END)
buffer = bytearray()
if sys.version_info[0] >= 3:
buffer = bytearray()
else:
buffer = ""
while True:
pos_newline = buffer.rfind(bytes([0x0a]))
if sys.version_info[0] >= 3:
pos_newline = buffer.rfind(bytes([0x0a]))
else:
pos_newline = buffer.rfind("\n")
# Get the current position of the reader
current_pos = self.file.tell()
if pos_newline != -1:
# Newline is found
line = buffer[pos_newline+1:]
buffer = buffer[:pos_newline]
yield line.decode("latin-1")
if sys.version_info[0] >= 3:
yield line.decode("latin-1")
else:
yield line
elif current_pos:
# Need to fill the buffer
to_read = min(BLKSIZE, current_pos)
@ -27,13 +39,17 @@ class BackwardReader:
buffer = self.file.read(to_read) + buffer
self.file.seek(current_pos-to_read, 0)
if current_pos is to_read:
buffer = bytes([0x0a]) + buffer
if sys.version_info[0] >= 3:
buffer = bytes([0x0a]) + buffer
else:
buffer = "\n" + buffer
else:
# Start of file
return
def trim_encrypt_string(encrypt):
string_list = list(encrypt)