mirror of
https://github.com/platomav/BIOSUtilities.git
synced 2025-05-13 06:34:42 -04:00
Initial refactor commit
Added AMI UCP BIOS Extractor v2.0_a1 Added AMI BIOS Guard Extractor v4.0_a1
This commit is contained in:
parent
2029ffc8b7
commit
132457afda
14 changed files with 1240 additions and 731 deletions
51
common/efi_comp.py
Normal file
51
common/efi_comp.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env python3
|
||||
#coding=utf-8
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from common.script_get import get_script_dir
|
||||
from common.system import get_os_ver
|
||||
from common.text_ops import padder
|
||||
|
||||
def get_compress_sizes(data):
|
||||
size_compress = int.from_bytes(data[0x0:0x4], 'little')
|
||||
size_original = int.from_bytes(data[0x4:0x8], 'little')
|
||||
|
||||
return size_compress, size_original
|
||||
|
||||
def is_efi_compressed(data, strict=True):
|
||||
size_comp,size_orig = get_compress_sizes(data)
|
||||
|
||||
check_diff = size_comp < size_orig
|
||||
|
||||
if strict: check_size = size_comp + 0x8 == len(data)
|
||||
else: check_size = size_comp + 0x8 <= len(data)
|
||||
|
||||
return check_diff and check_size
|
||||
|
||||
# Get TianoCompress path
|
||||
def tianocompress_path():
|
||||
exec_name = 'TianoCompress' + ('.exe' if get_os_ver()[1] else '')
|
||||
|
||||
exec_path = os.path.join(get_script_dir(), '..', 'external', exec_name)
|
||||
|
||||
return exec_path
|
||||
|
||||
# EFI/Tiano Decompression via TianoCompress
|
||||
def efi_decompress(in_path, out_path, padding, comp_type='--uefi'):
|
||||
try:
|
||||
subprocess.run([tianocompress_path(), '-d', in_path, '-o', out_path, '-q', comp_type], check=True, stdout=subprocess.DEVNULL)
|
||||
|
||||
with open(in_path, 'rb') as file: _,size_orig = get_compress_sizes(file.read())
|
||||
|
||||
if os.path.getsize(out_path) != size_orig: raise Exception('EFI_DECOMPRESS_ERROR')
|
||||
|
||||
except:
|
||||
print('\n%sError: TianoCompress could not extract file %s!' % (padder(padding), in_path))
|
||||
|
||||
return 1
|
||||
|
||||
print('\n%sSuccesfull EFI/Tiano decompression via TianoCompress!' % padder(padding))
|
||||
|
||||
return 0
|
Loading…
Add table
Add a link
Reference in a new issue