mirror of
https://github.com/chipsec/chipsec
synced 2026-06-08 13:31:00 +00:00
ac2ca7264f
UEFI shell. 2. Decompression of images in SPI flash parsing is only supported in Windows. 3. UEFI - Support for IA32 and i586 (Quark) 4. Added capability to use modules from an arbitrary path with the -I / --import command line option 5. Module functionality encapsulated in class inheriting BaseModule 6. Fixed loading platform specific configuration 7. Fixed issue with modules which run on multiple logical CPUs hanging on Bay Trail (Windows/Linux). The issue still exist when running from UEFI shell 8. Added template for a module - module_template.py 9. Added options to flush log files 10. Added ability to define custom platforms Driver changes: 1. Windows - Added IOCTL_ALLOC_PHYSMEM to allocate physical memory buffer 2. Linux - Fix wrpci defect
109 lines
3.0 KiB
Python
109 lines
3.0 KiB
Python
#!/usr/local/bin/python
|
|
#CHIPSEC: Platform Security Assessment Framework
|
|
#Copyright (c) 2010-2014, Intel Corporation
|
|
#
|
|
#This program is free software; you can redistribute it and/or
|
|
#modify it under the terms of the GNU General Public License
|
|
#as published by the Free Software Foundation; Version 2.
|
|
#
|
|
#This program is distributed in the hope that it will be useful,
|
|
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
#GNU General Public License for more details.
|
|
#
|
|
#You should have received a copy of the GNU General Public License
|
|
#along with this program; if not, write to the Free Software
|
|
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
#
|
|
#Contact information:
|
|
#chipsec@intel.com
|
|
#
|
|
|
|
|
|
|
|
#
|
|
# -------------------------------------------------------------------------------
|
|
#
|
|
# CHIPSEC: Platform Hardware Security Assessment Framework
|
|
# (c) 2010-2012 Intel Corporation
|
|
#
|
|
# -------------------------------------------------------------------------------
|
|
|
|
## \addtogroup core
|
|
#@{
|
|
# __chipsec/file.py__ -- reading from/writing to files
|
|
#@}
|
|
|
|
## file.py
|
|
# usage:
|
|
# read_file( filename )
|
|
# write_file( filename, buffer )
|
|
#
|
|
#
|
|
__version__ = '1.0'
|
|
|
|
import struct
|
|
import sys
|
|
import os
|
|
|
|
from chipsec.logger import logger
|
|
|
|
def read_file( filename, size=0 ):
|
|
# @TODO: this is Python 2.5+ syntax -- chipsec for UEFI uses Python 2.4
|
|
#with open( filename, 'rb' ) as f:
|
|
# _file = f.read()
|
|
#f.closed
|
|
|
|
try:
|
|
f = open(filename, "rb")
|
|
except:
|
|
logger().error( "Unable to open file '%.256s' for read access" % filename )
|
|
return 0
|
|
|
|
if size:
|
|
_file = f.read( size )
|
|
else:
|
|
_file = f.read()
|
|
f.close()
|
|
|
|
if logger().VERBOSE:
|
|
logger().log( "[file] read %d bytes from '%.256s'" % ( len(_file), filename ) )
|
|
return _file
|
|
|
|
def write_file( filename, buffer, append=False ):
|
|
# @TODO: this is Python 2.5+ syntax -- chipsec for UEFI uses Python 2.4
|
|
#with open( filename, 'wb' ) as f:
|
|
# f.write( buffer )
|
|
#f.closed
|
|
perm = "wb"
|
|
if (append): perm = "ab"
|
|
|
|
try:
|
|
f = open(filename, perm)
|
|
except:
|
|
logger().error( "Unable to open file '%.256s' for write access" % filename )
|
|
return 0
|
|
f.write( buffer )
|
|
f.close()
|
|
|
|
if logger().VERBOSE:
|
|
logger().log( "[file] wrote %d bytes to '%.256s'" % ( len(buffer), filename ) )
|
|
return True
|
|
|
|
|
|
def read_chunk( f, size=1024 ):
|
|
return f.read( size )
|
|
# intended usage
|
|
#for piece in iter(read1k, ''):
|
|
# process_data(piece)
|
|
|
|
# determine if CHIPSEC is loaded as chipsec.exe or in python
|
|
def main_is_frozen():
|
|
return (hasattr(sys, "frozen") or # new py2exe
|
|
hasattr(sys, "importers")) # old py2exe
|
|
|
|
def get_main_dir():
|
|
if main_is_frozen():
|
|
return os.path.dirname(sys.executable)
|
|
return os.path.dirname(sys.argv[0])
|