diff --git a/setup.py b/setup.py index f8944bf..e8bbb46 100755 --- a/setup.py +++ b/setup.py @@ -1,23 +1,74 @@ -# -*- coding: utf-8 -*- +#!/usr/bin/env python -from setuptools import setup, find_packages, Extension import os +import re +from setuptools import setup, find_packages, Extension, Command + + +class LintCommand(Command): + """Run pylint on implementation and test code""" + + description = "Run pylint on implementation and test code" + user_options = [] + + _pylint_options = [ + "--max-line-length 80", + "--ignore-imports yes" + ] + + _lint_paths = [ + "uefi_firmware/*.py", + "uefi_firmware/*/*.py", + "tests/*.py", + "scripts/*.py", + "scripts/contrib/*.py", + ] + + def initialize_options(self): + """Set default values for options.""" + pass + + def finalize_options(self): + """Post-process options.""" + pass + + def run(self): + """Run the command""" + os.system("pylint %s %s" % ( + " ".join(self._pylint_options), + " ".join(self._lint_paths), + )) with open('README.rst') as f: - readme = f.read() + README = f.read() with open('LICENSE') as f: - license = f.read() + LICENSE = f.read() + +with open("uefi_firmware/__init__.py", "r") as f: + __INIT__ = f.read() + +TITLE = re.search(r'^__title__\s*=\s*[\'"]([^\'"]*)[\'"]', + __INIT__, re.MULTILINE).group(1) +VERSION = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', + __INIT__, re.MULTILINE).group(1) +AUTHOR = re.search(r'^__author__\s*=\s*[\'"]([^\'"]*)[\'"]', + __INIT__, re.MULTILINE).group(1) setup( + title=TITLE, name='UEFI Firmware Parser', - version='0.2', + version=VERSION, description='Various data structures and parsing tools for UEFI firmware.', - long_description=readme, - author='Teddy Reed', + long_description=README, + author=AUTHOR, author_email='teddy@prosauce.org', - license=license, + license=LICENSE, packages=find_packages(exclude=('tests', 'docs')), + test_suite="tests", + cmdclass={ + "lint": LintCommand, + }, ext_modules=[ Extension( @@ -50,4 +101,16 @@ ], ) ], + + classifiers=[ + # https://pypi.python.org/pypi?%3Aaction=list_classifiers + 'Development Status :: 4 - Beta', + 'Intended Audience :: System Administrators', + 'Topic :: Security', + 'License :: OSI Approved :: BSD License', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', + ], + keywords="security uefi firmware parsing bios", ) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..eb83faf --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,2 @@ + +import test_compression diff --git a/uefi_firmware/__init__.py b/uefi_firmware/__init__.py index 2161406..5bc80da 100644 --- a/uefi_firmware/__init__.py +++ b/uefi_firmware/__init__.py @@ -1,4 +1,11 @@ +'''UEFI Firmware parser utils. +''' import uefi import pfs import me + +__title__ = "uefi_firmware" +__version__ = "0.3" +__author__ = "Teddy Reed" +__license__ = "BSD" diff --git a/uefi_firmware/base.py b/uefi_firmware/base.py index d44db99..6f45ba2 100644 --- a/uefi_firmware/base.py +++ b/uefi_firmware/base.py @@ -1,3 +1,10 @@ +'''Base provides basic firmware object structures. +''' + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + import os import ctypes @@ -5,16 +12,19 @@ class BaseObject(object): - '''A base object can be used to access direct content.''' class FirmwareObject(object): - data = None + def __init__(self): + self.data = None + self.name = None + self.attrs = None + self.guid = None @property def content(self): - if hasattr(self, "data"): + if hasattr(self, "data") and self.data is not None: return self.data return "" @@ -24,7 +34,7 @@ def objects(self): @property def label(self): - if hasattr(self, "name"): + if hasattr(self, "name") and self.name is not None: if self.name is None: return "" return self.name @@ -32,7 +42,7 @@ def label(self): @property def guid_label(self): - if not hasattr(self, "guid"): + if not hasattr(self, "guid") or self.guid is None: return "" return sguid(self.guid) @@ -42,7 +52,7 @@ def type_label(self): @property def attrs_label(self): - if hasattr(self, "attrs"): + if hasattr(self, "attrs") and self.attrs is not None: return self.attrs return {} @@ -70,6 +80,8 @@ def iterate_objects(self, include_content=False): class StructuredObject(object): + def __init__(self): + self.fields = [] def parse_structure(self, data, structure): '''Construct an instance object of the provided structure.''' @@ -87,7 +99,7 @@ def parse_structure(self, data, structure): def show_structure(self): for field in self.fields: - print "%s: %s" % (field, getattr(self.structure, field, None)) + print ("%s: %s" % (field, getattr(self.structure, field, None))) class RawObject(FirmwareObject, BaseObject): @@ -99,9 +111,9 @@ def build(self, generate_checksum, debug=False): return self.data def showinfo(self, ts='', index=None): - print "%s%s size= %d " % ( + print ("%s%s size= %d " % ( ts, blue("RawObject:"), len(self.data) - ) + )) def dump(self, parent='', index=None): path = os.path.join(parent, "object.raw") diff --git a/uefi_firmware/generator/uefi.py b/uefi_firmware/generator/uefi.py index d0072f1..ae3057d 100644 --- a/uefi_firmware/generator/uefi.py +++ b/uefi_firmware/generator/uefi.py @@ -95,7 +95,7 @@ def __init__(self, firmware_section=None, ts=''): self.ts = ts if firmware_section is not None: - if type(firmware_section) is not FirmwareFileSystemSection: + if not isinstance(firmware_section, FirmwareFileSystemSection): raise GeneratorException(firmware_section) self._generate(firmware_section) pass @@ -179,7 +179,7 @@ def __init__(self, firmware_file=None, type_label=None, guid=None): self.type_label = type self.guid_label = guid if firmware_file is not None: - if type(firmware_file) is not FirmwareFile: + if not isinstance(firmware_file, FirmwareFile): raise GeneratorException(firmware_file) self._generate(firmware_file) pass @@ -229,7 +229,7 @@ def __init__(self, volume=None, name="GENERIC"): self.name = name if volume is not None: - if type(volume) != FirmwareVolume: + if not isinstance(volume, FirmwareVolume): raise GeneratorException(volume) self._generate(volume) pass diff --git a/uefi_firmware/guids/__init__.py b/uefi_firmware/guids/__init__.py index 29b0e33..92ec7ba 100644 --- a/uefi_firmware/guids/__init__.py +++ b/uefi_firmware/guids/__init__.py @@ -16,7 +16,7 @@ def get_guid_name(guid): - raw_guid = aguid(guid) if type(guid) is str else guid + raw_guid = aguid(guid) if isinstance(guid, str) else guid for guid_table in GUID_TABLES: for name, match_guid in guid_table.iteritems(): diff --git a/uefi_firmware/guids/efiguids.py b/uefi_firmware/guids/efiguids.py index 6cc3603..25338ed 100644 --- a/uefi_firmware/guids/efiguids.py +++ b/uefi_firmware/guids/efiguids.py @@ -13,10 +13,10 @@ 'APPLE_REMOVABLE_MEDIA_PROTOCOL_GUID': [0x2ea9743a, 0x23d9, 0x425e, 0x87, 0x2c, 0xf6, 0x15, 0xaa, 0x19, 0x57, 0x88], 'ARM_GLOBAL_VARIABLE_PPI_GUID': [0xab1c1816, 0xd542, 0x4e6f, 0x9b, 0x1e, 0x8e, 0xcd, 0x92, 0x53, 0xe2, 0xe7], 'ARM_HOB_GLOBAL_VARIABLE_GUID': [0xc3253c90, 0xa24f, 0x4599, 0xa6, 0x64, 0x1f, 0x88, 0x13, 0x77, 0x8f, 0xc9], - 'ARM_MP_CORE_INFO_GUID': [0xa4ee0728, 0xe5d7, 0x4ac5, 0xb2, 0x1e, 0x65, 0x8e, 0xd8, 0x57, 0xe8, 0x34], + 'ARM_MP_CORE_INFO_GUID': [0xa4ee0728, 0xe5d7, 0x4ac5, 0xb2, 0x1e, 0x65, 0x8e, 0xd8, 0x57, 0xe8, 0x34], 'ARM_MP_CORE_INFO_PPI_GUID': [0x6847cc74, 0xe9ec, 0x4f8f, 0xa2, 0x9d, 0xab, 0x44, 0xe7, 0x54, 0xa8, 0xfc], 'BDS_LIB_STRING_PACKAGE_GUID': [0x3b4d9b23, 0x95ac, 0x44f6, 0x9f, 0xcd, 0xe, 0x95, 0x94, 0x58, 0x6c, 0x72], - 'BLOCKIO_VENDOR_GUID': [0xcf31fac5, 0xc24e, 0x11d2, 0x85, 0xf3, 0x0, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b], + 'BLOCKIO_VENDOR_GUID': [0xcf31fac5, 0xc24e, 0x11d2, 0x85, 0xf3, 0x0, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b], 'BLOCK_MMIO_PROTOCOL_GUID': [0x6b558ce3, 0x69e5, 0x4c67, 0xa6, 0x34, 0xf7, 0xfe, 0x72, 0xad, 0xbe, 0x84], 'BOOT_MAINT_FORMSET_GUID': [0x642237c7, 0x35d4, 0x472d, 0x83, 0x65, 0x12, 0xe0, 0xcc, 0xf2, 0x7a, 0x22], 'BOOT_MANAGER_FORMSET_GUID': [0x847bc3fe, 0xb974, 0x446d, 0x94, 0x49, 0x5a, 0xd5, 0x41, 0x2e, 0x99, 0x3b], @@ -136,7 +136,7 @@ 'EFI_EBC_INTERPRETER_PROTOCOL_GUID': [0x13AC6DD1, 0x73D0, 0x11D4, 0xB0, 0x6B, 0x00, 0xAA, 0x00, 0xBD, 0x6D, 0xE7], 'EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL_GUID': [0x2a72d11e, 0x7376, 0x40f6, 0x9c, 0x68, 0x23, 0xfa, 0x2f, 0xe3, 0x63, 0xf1], 'EFI_EBC_VM_TEST_PROTOCOL_GUID': [0xAAEACCFD, 0xF27B, 0x4C17, 0xB6, 0x10, 0x75, 0xCA, 0x1F, 0x2D, 0xFB, 0x52], - 'EFI_EBC_VM_TEST_PROTOCOL_GUID': [0xAAEACCFDL, 0xF27B, 0x4C17, 0xB6, 0x10, 0x75, 0xCA, 0x1F, 0x2D, 0xFB, 0x52], + 'EFI_EBC_VM_TEST_PROTOCOL_GUID': [0xAAEACCFD, 0xF27B, 0x4C17, 0xB6, 0x10, 0x75, 0xCA, 0x1F, 0x2D, 0xFB, 0x52], 'EFI_EDID_ACTIVE_PROTOCOL_GUID': [0xbd8c1056, 0x9f36, 0x44ec, 0x92, 0xa8, 0xa6, 0x33, 0x7f, 0x81, 0x79, 0x86], 'EFI_EDID_DISCOVERED_PROTOCOL_GUID': [0x1c0c34f6, 0xd380, 0x41fa, 0xa0, 0x49, 0x8a, 0xd0, 0x6c, 0x1a, 0x66, 0xaa], 'EFI_EDID_DISCOVERED_PROTOCOL_GUID': [0x1c0c34f6, 0xd380, 0x41fa, 0xa0, 0x49, 0x8a, 0xd0, 0x6c, 0x1a, 0x66, 0xaa], @@ -662,7 +662,7 @@ 'PEI_USB_HOST_CONTROLLER_PPI_GUID': [0x652b38a9, 0x77f4, 0x453f, 0x89, 0xd5, 0xe7, 0xbd, 0xc3, 0x52, 0xfc, 0x53], 'PEI_USB_IO_PPI_GUID': [0x7c29785c, 0x66b9, 0x49fc, 0xb7, 0x97, 0x1c, 0xa5, 0x55, 0xe, 0xf2, 0x83], 'PERFORMANCEPKG_TOKEN_SPACE_GUID': [0x669346ef, 0xFDad, 0x4aeb, 0x08, 0xa6, 0x21, 0x46, 0x2d, 0x3f, 0xef, 0x7d], - 'PERFORMANCE_EX_PROTOCOL_GUID': [0x1ea81bec, 0xf01a, 0x4d98, 0xa2, 0x1, 0x4a, 0x61, 0xce, 0x2f, 0xc0, 0x22], + 'PERFORMANCE_EX_PROTOCOL_GUID': [0x1ea81bec, 0xf01a, 0x4d98, 0xa2, 0x1, 0x4a, 0x61, 0xce, 0x2f, 0xc0, 0x22], 'PERFORMANCE_PROTOCOL_GUID': [0x76b6bdfa, 0x2acd, 0x4462, 0x9E, 0x3F, 0xcb, 0x58, 0xC9, 0x69, 0xd9, 0x37], 'PE_COFF_LOADER_PROTOCOL_GUID': [0xB323179B, 0x97FB, 0x477E, 0xB0, 0xFE, 0xD8, 0x85, 0x91, 0xFA, 0x11, 0xAB], 'PLAT_OVER_MNGR_GUID': [0x8614567d, 0x35be, 0x4415, 0x8d, 0x88, 0xbd, 0x7d, 0xc, 0x9c, 0x70, 0xc0], @@ -690,7 +690,7 @@ 'SHELL_VARIABLE_GUID': [0x158def5a, 0xf656, 0x419c, 0xb0, 0x27, 0x7a, 0x31, 0x92, 0xc0, 0x79, 0xd2], 'SMBIOS_TABLE_GUID': [0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d], 'SMM_COMMUNICATE_HEADER_GUID': [0xf328e36c, 0x23b6, 0x4a95, 0x85, 0x4b, 0x32, 0xe1, 0x95, 0x34, 0xcd, 0x75], - 'SMM_PERFORMANCE_EX_PROTOCOL_GUID': [0x931fc048, 0xc71d, 0x4455, 0x89, 0x30, 0x47, 0x6, 0x30, 0xe3, 0xe, 0xe5], + 'SMM_PERFORMANCE_EX_PROTOCOL_GUID': [0x931fc048, 0xc71d, 0x4455, 0x89, 0x30, 0x47, 0x6, 0x30, 0xe3, 0xe, 0xe5], 'SMM_PERFORMANCE_PROTOCOL_GUID': [0xf866226a, 0xeaa5, 0x4f5a, 0xa9, 0xa, 0x6c, 0xfb, 0xa5, 0x7c, 0x58, 0x8e], 'STATUS_CODE_CALLBACK_GUID': [0xe701458c, 0x4900, 0x4ca5, 0xb7, 0x72, 0x3d, 0x37, 0x94, 0x9f, 0x79, 0x27], 'SYSTEM_ROM_FILE_GUID': [0x1547B4F3, 0x3E8A, 0x4FEF, 0x81, 0xC8, 0x32, 0x8E, 0xD6, 0x47, 0xAB, 0x1A], @@ -699,7 +699,7 @@ 'TIANO_CUSTOM_DECOMPRESS_GUID': [0xA31280AD, 0x481E, 0x41B6, 0x95, 0xE8, 0x12, 0x7F, 0x4C, 0x98, 0x47, 0x79], 'UNIX_FWH_PPI_GUID': [0xf2f0dc30, 0x8985, 0x11db, 0xa1, 0x5b, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35], 'UNIX_PEI_LOAD_FILE_GUID': [0xf2f48768, 0x8985, 0x11db, 0xb8, 0xda, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35], - 'UNKNOWN_DEVICE_GUID': [0xcf31fac5, 0xc24e, 0x11d2, 0x85, 0xf3, 0x0, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b], + 'UNKNOWN_DEVICE_GUID': [0xcf31fac5, 0xc24e, 0x11d2, 0x85, 0xf3, 0x0, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b], 'USB_CREDENTIAL_PROVIDER_GUID': [0xd0849ed1, 0xa88c, 0x4ba6, 0xb1, 0xd6, 0xab, 0x50, 0xe2, 0x80, 0xb7, 0xa9], 'USB_KEYBOARD_LAYOUT_PACKAGE_GUID': [0xc0f3b43, 0x44de, 0x4907, 0xb4, 0x78, 0x22, 0x5f, 0x6f, 0x62, 0x89, 0xdc], 'USER_IDENTIFY_MANAGER_GUID': [0x3ccd3dd8, 0x8d45, 0x4fed, 0x96, 0x2d, 0x2b, 0x38, 0xcd, 0x82, 0xb3, 0xc4], diff --git a/uefi_firmware/guids/efiguids_ami.py b/uefi_firmware/guids/efiguids_ami.py index b2b4e30..eae3379 100644 --- a/uefi_firmware/guids/efiguids_ami.py +++ b/uefi_firmware/guids/efiguids_ami.py @@ -271,7 +271,7 @@ 'EFI_EVENT_LEGACY_BOOT_GUID': [0x2a571201, 0x4966, 0x47f6, 0x8b, 0x86, 0xf3, 0x1e, 0x41, 0xf3, 0x2f, 0x10], 'EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID': [0x5aea42b5, 0x31e1, 0x4515, 0xbc, 0x31, 0xb8, 0xd5, 0x25, 0x75, 0x65, 0xa6], 'EFI_EXTENDED_SAL_BASE_SERVICES_PROTOCOL_GUID': [0xd9e9fa06, 0x0fe0, 0x41c3, 0x96, 0xfb, 0x83, 0x42, 0x5a, 0x33, 0x94, 0xf8], - 'EFI_EXTENDED_SAL_CACHE_SERVICES_PROTOCOL_GUID': [0xedc9494, 0x2743, 0x4ba5, 0x88, 0x18, 0x0a, 0xef, 0x52, 0x13, 0xf1, 0x88], + 'EFI_EXTENDED_SAL_CACHE_SERVICES_PROTOCOL_GUID': [0xedc9494, 0x2743, 0x4ba5, 0x88, 0x18, 0x0a, 0xef, 0x52, 0x13, 0xf1, 0x88], 'EFI_EXTENDED_SAL_ELOG_SERVICES_PROTOCOL_GUID': [0xd5e4ee5f, 0x3e0a, 0x453c, 0xa7, 0x25, 0xb6, 0x92, 0xbb, 0x6, 0x36, 0x5a], 'EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID': [0xa2271df1, 0xbcbb, 0x4f1d, 0x98, 0xa9, 0x06, 0xbc, 0x17, 0x2f, 0x07, 0x1a], 'EFI_EXTENDED_SAL_LOCK_SERVICES_PROTOCOL_GUID': [0x76b75c23, 0xfe4f, 0x4e17, 0xa2, 0xad, 0x1a, 0x65, 0x3d, 0xbb, 0x49, 0x4a], @@ -284,7 +284,7 @@ 'EFI_EXTENDED_SAL_RESET_SERVICES_PROTOCOL_GUID': [0x7d019990, 0x8ce1, 0x46f5, 0xa7, 0x76, 0x3c, 0x51, 0x98, 0x67, 0x6a, 0xa0], 'EFI_EXTENDED_SAL_RTC_SERVICES_PROTOCOL_GUID': [0x7e97a470, 0xefdb, 0x4d02, 0x8f, 0xce, 0x61, 0x90, 0xd2, 0x7b, 0xa2, 0x96], 'EFI_EXTENDED_SAL_SENSOR_SERVICES_PROTOCOL_GUID': [0x4a153b6e, 0x85a1, 0x4982, 0x98, 0xf4, 0x6a, 0x8c, 0xfc, 0xa4, 0xab, 0xa1], - 'EFI_EXTENDED_SAL_SM_COM_LAYER_SERVICES_PROTOCOL_GUID': [0x4356799, 0x81b7, 0x4e08, 0xa3, 0x8d, 0xd9, 0x78, 0xfa, 0x47, 0xba, 0x42], + 'EFI_EXTENDED_SAL_SM_COM_LAYER_SERVICES_PROTOCOL_GUID': [0x4356799, 0x81b7, 0x4e08, 0xa3, 0x8d, 0xd9, 0x78, 0xfa, 0x47, 0xba, 0x42], 'EFI_EXTENDED_SAL_SST_GUID': [0x38802700, 0x868a, 0x4b4e, 0x81, 0xd4, 0x4f, 0x1b, 0xdc, 0xcf, 0xb4, 0x6f], 'EFI_EXTENDED_SAL_STALL_SERVICES_PROTOCOL_GUID': [0x53a58d06, 0xac27, 0x4d8c, 0xb5, 0xe9, 0xf0, 0x8a, 0x80, 0x65, 0x41, 0x70], 'EFI_EXTENDED_SAL_STATUS_CODE_SERVICES_PROTOCOL_GUID': [0xdbd91d, 0x55e9, 0x420f, 0x96, 0x39, 0x5e, 0x9f, 0x84, 0x37, 0xb4, 0x4f], @@ -328,7 +328,7 @@ 'EFI_GUID': [0x2362ea9c, 0x84e5, 0x4dff, 0x83, 0xbc, 0xb5, 0xac, 0xec, 0xb5, 0x7c, 0xbb], 'EFI_GUID': [0x2FE800BE, 0x8F01, 0x4aa6, 0x94, 0x6B, 0xD7, 0x13, 0x88, 0xE1, 0x83, 0x3F], 'EFI_GUID': [0x2ae9d80f, 0x3fb2, 0x4095, 0xb7, 0xb1, 0xe9, 0x31, 0x57, 0xb9, 0x46, 0xb6], - 'EFI_GUID': [0x379be4e, 0xd706, 0x437d, 0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4], + 'EFI_GUID': [0x379be4e, 0xd706, 0x437d, 0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4], 'EFI_GUID': [0x3B6686BD, 0x0D76, 0x4030, 0xB7, 0x0E, 0xB5, 0x51, 0x9E, 0x2F, 0xC5, 0xA0], 'EFI_GUID': [0x3ad9df29, 0x4501, 0x478d, 0xb1, 0xf8, 0x7f, 0x7f, 0xe7, 0x0e, 0x50, 0xf3], 'EFI_GUID': [0x3b95aa31, 0x3793, 0x434b, 0x86, 0x67, 0xc8, 0x07, 0x08, 0x92, 0xe0, 0x5e], @@ -343,7 +343,7 @@ 'EFI_GUID': [0x51aa59de, 0xfdf2, 0x4ea3, 0xbc, 0x63, 0x87, 0x5f, 0xb7, 0x84, 0x2e, 0xe9], 'EFI_GUID': [0x560bf58a, 0x1e0d, 0x4d7e, 0x95, 0x3f, 0x29, 0x80, 0xa2, 0x61, 0xe0, 0x31], 'EFI_GUID': [0x564b33cd, 0xc92a, 0x4593, 0x90, 0xbf, 0x24, 0x73, 0xe4, 0x3c, 0x63, 0x22], - 'EFI_GUID': [0x5c99a21, 0xc70f, 0x4ad2, 0x8a, 0x5f, 0x35, 0xdf, 0x33, 0x43, 0xf5, 0x1e], + 'EFI_GUID': [0x5c99a21, 0xc70f, 0x4ad2, 0x8a, 0x5f, 0x35, 0xdf, 0x33, 0x43, 0xf5, 0x1e], 'EFI_GUID': [0x6298fe18, 0xd5ef, 0x42b7, 0xbb, 0xc, 0x29, 0x53, 0x28, 0x3f, 0x57, 0x4], 'EFI_GUID': [0x65530BC7, 0xA359, 0x410f, 0xB0, 0x10, 0x5A, 0xAD, 0xC7, 0xEC, 0x2B, 0x62], 'EFI_GUID': [0x7671d9d0, 0x53db, 0x4173, 0xaa, 0x69, 0x23, 0x27, 0xf2, 0x1f, 0x0b, 0xc7], @@ -361,11 +361,11 @@ 'EFI_GUID': [0x9d7a05e9, 0xf740, 0x44c3, 0x85, 0x8b, 0x75, 0x58, 0x6a, 0x8f, 0x9c, 0x8e], 'EFI_GUID': [0x9d9a39d8, 0xbd42, 0x4a73, 0xa4, 0xd5, 0x8e, 0xe9, 0x4b, 0xe1, 0x13, 0x80], 'EFI_GUID': [0x9fe7de69, 0xaea, 0x470a, 0xb5, 0xa, 0x13, 0x98, 0x13, 0x64, 0x91, 0x89], - 'EFI_GUID': [0xCC0F8A3F, 0x3DEA, 0x4376, 0x96, 0x79, 0x54, 0x26, 0xba, 0x0a, 0x90, 0x7e], + 'EFI_GUID': [0xCC0F8A3F, 0x3DEA, 0x4376, 0x96, 0x79, 0x54, 0x26, 0xba, 0x0a, 0x90, 0x7e], 'EFI_GUID': [0xa6a72875, 0x2962, 0x4c18, 0x9f, 0x46, 0x8d, 0xa6, 0x44, 0xcc, 0xfe, 0x00], 'EFI_GUID': [0xaa31bc6, 0x3379, 0x41e8, 0x82, 0x5a, 0x53, 0xf8, 0x2c, 0xc0, 0xf2, 0x54], 'EFI_GUID': [0xabb74f50, 0xfd2d, 0x4072, 0xa3, 0x21, 0xca, 0xfc, 0x72, 0x97, 0x7e, 0xfa], - 'EFI_GUID': [0xaf7c79c, 0x65b5, 0x4319, 0xb0, 0xae, 0x44, 0xec, 0x48, 0x4e, 0x4a, 0xd7], + 'EFI_GUID': [0xaf7c79c, 0x65b5, 0x4319, 0xb0, 0xae, 0x44, 0xec, 0x48, 0x4e, 0x4a, 0xd7], 'EFI_GUID': [0xbb2f3c9d, 0xc7a1, 0x4283, 0x8a, 0xe2, 0x4f, 0x43, 0x62, 0x99, 0x0e, 0x2e], 'EFI_GUID': [0xbfd7dc1d, 0x24f1, 0x40d9, 0x82, 0xe7, 0x2e, 0x09, 0xbb, 0x6b, 0x4e, 0xbe], 'EFI_GUID': [0xc1bdd34e, 0x9ec0, 0x48aa, 0x80, 0x6a, 0x6c, 0x2e, 0xba, 0x0d, 0xc4, 0x45], @@ -377,7 +377,7 @@ 'EFI_GUID': [0xd84beff0, 0x159a, 0x4b60, 0x9a, 0xb9, 0xac, 0x5c, 0x47, 0x4b, 0xd3, 0xb1], 'EFI_GUID': [0xdbc9fd21, 0xfad8, 0x45b0, 0x9e, 0x78, 0x27, 0x15, 0x88, 0x67, 0xcc, 0x93], 'EFI_GUID': [0xe6f4f8f7, 0x4992, 0x47b2, 0x83, 0x2, 0x85, 0x8, 0x74, 0x5e, 0x4a, 0x23], - 'EFI_GUID': [0xedd35e31, 0x7b9, 0x11d2, 0x83, 0xa3, 0x00, 0xa0, 0xc9, 0x1f, 0xad, 0xcf], + 'EFI_GUID': [0xedd35e31, 0x7b9, 0x11d2, 0x83, 0xa3, 0x00, 0xa0, 0xc9, 0x1f, 0xad, 0xcf], 'EFI_GUID': [0xefa96432, 0xde33, 0x4dd2, 0xae, 0xe6, 0x32, 0x8c, 0x33, 0xdf, 0x77, 0x7a], 'EFI_GUID': [0xf328e36c, 0x23b6, 0x4a95, 0x85, 0x4b, 0x32, 0xe1, 0x95, 0x34, 0xcd, 0x75], 'EFI_GUID': [0xf36ff770, 0xa7e1, 0x42cf, 0x9e, 0xd2, 0x56, 0xf0, 0xf2, 0x71, 0xf4, 0x4c], @@ -406,12 +406,12 @@ 'EFI_HII_NEW_PROTOCOL_GUID': [0xea816d2c, 0xcee5, 0x4f02, 0x99, 0xb5, 0xd3, 0x90, 0x5c, 0xbb, 0xd0, 0x77], 'EFI_HII_OLD_PROTOCOL_GUID': [0xcd361957, 0xafbe, 0x425e, 0xa3, 0x58, 0x5f, 0x58, 0x89, 0xcf, 0xfe, 0x7b], 'EFI_HII_PACKAGE_LIST_PROTOCOL_GUID': [0x6a1ee763, 0xd47a, 0x43b4, 0xaa, 0xbe, 0xef, 0x1d, 0xe2, 0xab, 0x56, 0xfc], - 'EFI_HII_PLATFORM_SETUP_FORMSET_GUID': [0x93039971, 0x8545, 0x4b04, 0xb4, 0x5e, 0x32, 0xeb, 0x83, 0x26, 0x4, 0xe], + 'EFI_HII_PLATFORM_SETUP_FORMSET_GUID': [0x93039971, 0x8545, 0x4b04, 0xb4, 0x5e, 0x32, 0xeb, 0x83, 0x26, 0x4, 0xe], 'EFI_HII_PLATFORM_SETUP_FORMSET_GUID': [0x93039971, 0x8545, 0x4b04, 0xb4, 0x5e, 0x32, 0xeb, 0x83, 0x26, 0x4, 0xe], 'EFI_HII_PROTOCOL_GUID': [0xd7ad636e, 0xb997, 0x459b, 0xbf, 0x3f, 0x88, 0x46, 0x89, 0x79, 0x80, 0xe1], 'EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID': [0x14982a4f, 0xb0ed, 0x45b8, 0xa8, 0x11, 0x5a, 0x7a, 0x9b, 0xc2, 0x32, 0xdf], 'EFI_HII_STRING_PROTOCOL_GUID': [0xfd96974, 0x23aa, 0x4cdc, 0xb9, 0xcb, 0x98, 0xd1, 0x77, 0x50, 0x32, 0x2a], - 'EFI_HII_USER_CREDENTIAL_FORMSET_GUID': [0x337f4407, 0x5aee, 0x4b83, 0xb2, 0xa7, 0x4e, 0xad, 0xca, 0x30, 0x88, 0xcd], + 'EFI_HII_USER_CREDENTIAL_FORMSET_GUID': [0x337f4407, 0x5aee, 0x4b83, 0xb2, 0xa7, 0x4e, 0xad, 0xca, 0x30, 0x88, 0xcd], 'EFI_HOB_LIST_GUID': [0x7739f24c, 0x93d7, 0x11d4, 0x9a, 0x3a, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d], 'EFI_HOB_MEMORY_ALLOC_BSP_STORE_GUID': [0x564b33cd, 0xc92a, 0x4593, 0x90, 0xbf, 0x24, 0x73, 0xe4, 0x3c, 0x63, 0x22], 'EFI_HOB_MEMORY_ALLOC_BSP_STORE_GUID': [0x564b33cd, 0xc92a, 0x4593, 0x90, 0xbf, 0x24, 0x73, 0xe4, 0x3c, 0x63, 0x22], @@ -676,7 +676,7 @@ 'EFI_UGA_SPLASH_PROTOCOL_GUID': [0xa45b3a0d, 0x2e55, 0x4c03, 0xad, 0x9c, 0x27, 0xd4, 0x82, 0xb, 0x50, 0x7e], 'EFI_UNICODE_COLLATION2_PROTOCOL_GUID': [0xa4c751fc, 0x23ae, 0x4c3e, 0x92, 0xe9, 0x49, 0x64, 0xcf, 0x63, 0xf3, 0x49], 'EFI_UNICODE_COLLATION_PROTOCOL2_GUID': [0xa4c751fc, 0x23ae, 0x4c3e, 0x92, 0xe9, 0x49, 0x64, 0xcf, 0x63, 0xf3, 0x49], - 'EFI_UNICODE_COLLATION_PROTOCOL_GUID': [0x1d85cd7f, 0xf43d, 0x11d2, 0x9a, 0x0c, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d], + 'EFI_UNICODE_COLLATION_PROTOCOL_GUID': [0x1d85cd7f, 0xf43d, 0x11d2, 0x9a, 0x0c, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d], 'EFI_UNICODE_COLLATION_PROTOCOL_GUID': [0x1d85cd7f, 0xf43d, 0x11d2, 0x9a, 0xc, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d], 'EFI_USB2_HC_PROTOCOL_GUID': [0x3e745226, 0x9818, 0x45b6, 0xa2, 0xac, 0xd7, 0xcd, 0xe, 0x8b, 0xa2, 0xbc], 'EFI_USB_ATAPI_PROTOCOL_GUID': [0x2B2F68DA, 0x0CD2, 0x44cf, 0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75], @@ -899,7 +899,7 @@ 'TXT_INFO_HOB_GUID': [0x2986883F, 0x88E0, 0x48d0, 0x4B, 0x82, 0x20, 0xC2, 0x69, 0x48, 0xDD, 0xAC], 'TXT_ONE_TOUCH_GUID': [0x3D989471, 0xCFAC, 0x46B7, 0x9B, 0x1C, 0x8, 0x43, 0x1, 0x9, 0x40, 0x2D], 'TXT_ONE_TOUCH_OP_PROTOCOL_GUID': [0xFA2338AD, 0x80DF, 0x49D0, 0x93, 0x96, 0xCF, 0x71, 0x45, 0xD0, 0x3A, 0x76], - 'UNKNOWN_DEVICE_GUID': [0xcf31fac5, 0xc24e, 0x11d2, 0x85, 0xf3, 0x0, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b], + 'UNKNOWN_DEVICE_GUID': [0xcf31fac5, 0xc24e, 0x11d2, 0x85, 0xf3, 0x0, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b], 'USB_TIMING_POLICY_PROTOCOL_GUID': [0x89e3c1dc, 0xb5e3, 0x4d34, 0xae, 0xad, 0xdd, 0x7e, 0xb2, 0x82, 0x8c, 0x18], 'USER_DEFAULTS_GUID': [0xC4CC0DE8, 0x0687, 0x4422, 0x99, 0xC1, 0x65, 0x35, 0x1A, 0x5D, 0x5F, 0x95], 'WDT_APP_PROTOCOL_GUID': [0x92c7d0bb, 0x679e, 0x479d, 0x87, 0x8d, 0xd4, 0xb8, 0x29, 0x68, 0x57, 0x8b], diff --git a/uefi_firmware/me.py b/uefi_firmware/me.py index 22a6017..5392a34 100644 --- a/uefi_firmware/me.py +++ b/uefi_firmware/me.py @@ -152,7 +152,7 @@ def dump(self, parent=""): try: data = efi_compressor.LzmaDecompress(self.data, len(self.data)) dump_data("%s.module" % os.path.join(parent, self.name), data) - except Exception, e: + except Exception as e: print "Cannot extract GUID (%s), %s" % (sguid(self.guid), str(e)) return pass @@ -417,7 +417,7 @@ def process(self): elif self.structure.Tag == '$MAN': self.header_type = MeModuleHeader1Type else: - #Cannot parse modules... + # Cannot parse modules... return False # Parse the module headers (two types of headers, specified by the diff --git a/uefi_firmware/uefi.py b/uefi_firmware/uefi.py index aaa35b3..42ab3e8 100644 --- a/uefi_firmware/uefi.py +++ b/uefi_firmware/uefi.py @@ -1,4 +1,11 @@ -# -*- coding: utf-8 -*- +'''EFI and UEFI related structures. +This package defines firmware structures for unpacking, decompressing, +extracting, and rebuilding UEFI data. +''' + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function import os import struct @@ -8,11 +15,13 @@ from .guids import get_guid_name from .structs.uefi_structs import * from .structs.flash_structs import * -import efi_compressor + +from uefi_firmware import efi_compressor def _get_file_type(file_type): - return EFI_FILE_TYPES[file_type] if file_type in EFI_FILE_TYPES else ("unknown", "unknown") + return EFI_FILE_TYPES[file_type] if file_type in EFI_FILE_TYPES else ( + "unknown", "unknown") def _get_section_type(section_type): @@ -40,7 +49,7 @@ def compare(data1, data2): md5_1 = md5(data1).hexdigest() md5_2 = md5(data2).hexdigest() if (md5_1 != md5_2): - print "%s != %s" % (red(md5_1), red(md5_2)) + print ("%s != %s" % (red(md5_1), red(md5_2))) return False return True @@ -179,12 +188,12 @@ def dump(self, parent, index=0): def showinfo(self, ts="", index=0): '''Potential for A LOT of variables.''' if self.guid is not None and self.name is not None: - print "%s %s %s %s" % ( + print ("%s %s %s %s" % ( blue("%sVariable:" % ts), green(sguid(self.guid)), purple(self.name), "attrs= %s" % self.attrs["attrs"] - ) + )) class NVARVariableStore(FirmwareVariableStore): @@ -235,10 +244,10 @@ def dump(self, parent, index=0): def showinfo(self, ts="", index=0): if not self.valid_header: return - print "%s %s" % ( + print ("%s %s" % ( blue("%sNVAR Variable Store:" % ts), "variables: %d" % self.attrs["variables"] - ) + )) for i, variable in enumerate(self.variables): variable.showinfo("%s " % ts, i) @@ -253,7 +262,7 @@ def objects(self): def process_subsections(self): self.subsections = [] - if not self.data: + if self.data is None: return False subsection_offset = 0 @@ -401,7 +410,7 @@ def build(self, generate_checksum=False, debug=False): def showinfo(self, ts): if self.name is not None: - print "%s %s" % (blue("%sCompressed Name:" % ts), purple(self.name)) + print ("%s %s" % (blue("%sCompressed Name:" % ts), purple(self.name))) for i, _object in enumerate(self.subsections): _object.showinfo(ts, i) @@ -409,6 +418,7 @@ def showinfo(self, ts): class VersionSection(EfiSection): def __init__(self, data): + self.data = data self.build_number = struct.unpack("<16s", self.data[:16]) @@ -441,7 +451,7 @@ def build(self, generate_checksum=False, debug=False): def showinfo(self, ts='', index=-1): # print "%sGUID: %s" % (ts, green(sguid(self.guid))) if self.name is not None: - print "%sGUID Description: %s" % (ts, purple(self.name)) + print ("%sGUID Description: %s" % (ts, purple(self.name))) class GuidDefinedSection(EfiSection): @@ -532,10 +542,10 @@ def showinfo(self, ts='', index=0): auth_status = "AUTH_VALID" if self.attrs["attrs"] == self.ATTR_PROCESSING_REQUIRED: auth_status = "PROCESSING_REQUIRED" - print "%s%s %s offset= 0x%x attrs= 0x%x (%s)" % ( + print ("%s%s %s offset= 0x%x attrs= 0x%x (%s)" % ( ts, blue("Guid-Defined:"), green(sguid(self.guid)), self.offset, self.attrs["attrs"], purple(auth_status) - ) + )) if len(self.subsections) > 0: for i, section in enumerate(self.subsections): section.showinfo("%s " % ts, index=i) @@ -658,13 +668,13 @@ def build(self, generate_checksum=False, debug=False): pass def showinfo(self, ts='', index=-1): - print "%s type 0x%02x, size 0x%x (%d bytes) (%s section)" % ( + print ("%s type 0x%02x, size 0x%x (%d bytes) (%s section)" % ( blue("%sSection %d:" % (ts, index)), self.type, self.size, self.size, _get_section_type(self.type)[0] - ) + )) if self.type == 0x15 and self.name is not None: - print "%sName: %s" % (ts, purple(self.name)) + print ("%sName: %s" % (ts, purple(self.name))) if self.parsed_object is not None: '''If this is a specific object, show that object's info.''' @@ -703,7 +713,7 @@ def __init__(self, data): self.guid, self.checksum, self.type, self.attributes, \ self.size, self.state = struct.unpack("<16sHBB3sB", header) self.size = struct.unpack("