mirror of
https://github.com/scito/extract_otp_secret_keys.git
synced 2025-12-07 15:25:06 +01:00
refactor image import and add Alpine docker image
- dynamic import of QR reader - build docker also for arm64
This commit is contained in:
parent
915efcf192
commit
9d052dc78a
21 changed files with 910 additions and 521 deletions
28
utils.py
28
utils.py
|
|
@ -14,12 +14,13 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import csv
|
||||
import glob
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
from io import StringIO
|
||||
import sys
|
||||
import glob
|
||||
|
||||
|
||||
# Ref. https://stackoverflow.com/a/16571630
|
||||
|
|
@ -31,9 +32,9 @@ with Capturing() as output:
|
|||
'''
|
||||
def __enter__(self):
|
||||
self._stdout = sys.stdout
|
||||
sys.stdout = self._stringio_std = StringIO()
|
||||
sys.stdout = self._stringio_std = io.StringIO()
|
||||
self._stderr = sys.stderr
|
||||
sys.stderr = self._stringio_err = StringIO()
|
||||
sys.stderr = self._stringio_err = io.StringIO()
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
|
|
@ -102,3 +103,22 @@ def read_file_to_list(filename):
|
|||
def read_file_to_str(filename):
|
||||
"""Returns a str."""
|
||||
return "".join(read_file_to_list(filename))
|
||||
|
||||
def read_binary_file_as_stream(filename):
|
||||
"""Returns binary file content."""
|
||||
with open(filename, "rb",) as infile:
|
||||
return io.BytesIO(infile.read())
|
||||
|
||||
def replace_escaped_octal_utf8_bytes_with_str(str):
|
||||
encoded_name_strings = re.findall(r'name: .*$', str, flags=re.MULTILINE)
|
||||
for encoded_name_string in encoded_name_strings:
|
||||
escaped_bytes = re.findall(r'((?:\\[0-9]+)+)', encoded_name_string)
|
||||
for byte_sequence in escaped_bytes:
|
||||
unicode_str = b''.join([int(byte, 8).to_bytes(1, 'little') for byte in byte_sequence.split('\\') if byte]).decode('utf-8')
|
||||
print("Replace '{}' by '{}'".format(byte_sequence, unicode_str))
|
||||
str = str.replace(byte_sequence, unicode_str)
|
||||
return str
|
||||
|
||||
|
||||
def quick_and_dirty_workaround_encoding_problem(str):
|
||||
return re.sub(r'name: "encoding: .*$', '', str, flags=re.MULTILINE)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue