mirror of
https://github.com/platomav/BIOSUtilities.git
synced 2025-05-12 22:26:13 -04:00

Added AMI PFAT nested detection at each file Added Award BIOS payload naming at each file Switched Panasonic BIOS LZNT1 external library Improved Panasonic LZNT1 detection and length Improved Dell PFS code structure and fixed bugs Improved code exception handling (raise, catch) Improved code definitions (PEP8, docs, types) Fixed some arguments missing from help screens
48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
#!/usr/bin/env python3 -B
|
|
# coding=utf-8
|
|
|
|
"""
|
|
Copyright (C) 2022-2024 Plato Mavropoulos
|
|
"""
|
|
|
|
|
|
def padder(padd_count, tab=False):
|
|
""" Generate padding (spaces or tabs) """
|
|
|
|
return ('\t' if tab else ' ') * padd_count
|
|
|
|
|
|
def to_string(in_object, sep_char=''):
|
|
""" Get String from given input object """
|
|
|
|
if type(in_object).__name__ in ('list', 'tuple'):
|
|
out_string = sep_char.join(map(str, in_object))
|
|
else:
|
|
out_string = str(in_object)
|
|
|
|
return out_string
|
|
|
|
|
|
def file_to_bytes(in_object):
|
|
""" Get Bytes from given buffer or file path """
|
|
|
|
object_bytes = in_object
|
|
|
|
if type(in_object).__name__ not in ('bytes', 'bytearray'):
|
|
with open(to_string(in_object), 'rb') as object_data:
|
|
object_bytes = object_data.read()
|
|
|
|
return object_bytes
|
|
|
|
|
|
def bytes_to_hex(buffer: bytes, order: str, data_len: int, slice_len: int | None = None) -> str:
|
|
""" Converts bytes to hex string, controlling endianess, data size and string slicing """
|
|
|
|
# noinspection PyTypeChecker
|
|
return f'{int.from_bytes(buffer, order):0{data_len * 2}X}'[:slice_len]
|
|
|
|
|
|
def is_encased(in_string, chars):
|
|
""" Check if string starts and ends with given character(s) """
|
|
|
|
return in_string.startswith(chars) and in_string.endswith(chars)
|