Skip to content

Commit

Permalink
Merge pull request #27 from theopolis/setup_improvements
Browse files Browse the repository at this point in the history
Various Setup improvements
  • Loading branch information
Teddy Reed committed Dec 28, 2015
2 parents e5b4b83 + 2144c08 commit c8a4fc9
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 78 deletions.
79 changes: 71 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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='[email protected]',
license=license,
license=LICENSE,
packages=find_packages(exclude=('tests', 'docs')),
test_suite="tests",
cmdclass={
"lint": LintCommand,
},

ext_modules=[
Extension(
Expand Down Expand Up @@ -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",
)
2 changes: 2 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

import test_compression
7 changes: 7 additions & 0 deletions uefi_firmware/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
30 changes: 21 additions & 9 deletions uefi_firmware/base.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
'''Base provides basic firmware object structures.
'''

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os
import ctypes

from .utils import dump_data, sguid, blue


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 ""

Expand All @@ -24,15 +34,15 @@ 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
return ""

@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)

Expand All @@ -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 {}

Expand Down Expand Up @@ -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.'''
Expand All @@ -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):
Expand All @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions uefi_firmware/generator/uefi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion uefi_firmware/guids/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
12 changes: 6 additions & 6 deletions uefi_firmware/guids/efiguids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand All @@ -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],
Expand Down
Loading

0 comments on commit c8a4fc9

Please sign in to comment.