Use RWE/windows helpers when the corresponding driver is present

Fix error when calling decompress functionality using RWE helper
This commit is contained in:
Loucaides
2017-07-19 19:21:54 -04:00
committed by Erik Bjorge
parent 3c381eae94
commit 60504da1bc
5 changed files with 54 additions and 4 deletions
+1 -1
View File
@@ -22,6 +22,6 @@
from chipsec.helper.efi import *
from chipsec.helper.linux import *
from chipsec.helper.osx import *
#from chipsec.helper.rwe import *
from chipsec.helper.rwe import *
from chipsec.helper.win import *
+3 -1
View File
@@ -20,7 +20,9 @@
#
import platform, os
if "windows" == platform.system().lower() and os.environ.has_key("USERWE"):
if "windows" == platform.system().lower() and (os.path.isfile(os.path.join("C:\\Windows\\System32\\drivers\\RwDrv.sys")) or os.path.isfile(os.path.join(os.getcwd(), "win7_amd64\RwDrv.sys"))):
print "rwe"
__all__ = [ "rwehelper" ]
else:
print "no rwe"
__all__ = [ ]
+45
View File
@@ -356,6 +356,9 @@ class RweHelper(Helper):
if logger().VERBOSE: logger().log( "[helper] service control manager opened (handle = 0x%08x)" % hscm )
driver_path = os.path.join( chipsec.file.get_main_dir(), "chipsec", "helper", "rwe", self.win_ver, DRIVER_FILE_NAME )
if not os.path.isfile( driver_path ):
driver_path = os.path.join("C:\\", "Windows","System32","drivers", DRIVER_FILE_NAME)
if logger().VERBOSE: logger().log( "[helper] Did not find local RWE driver. Trying %s" % driver_path )
if os.path.isfile( driver_path ):
self.driver_path = driver_path
if logger().VERBOSE: logger().log( "[helper] driver path: '%s'" % os.path.abspath(self.driver_path) )
@@ -927,6 +930,48 @@ class RweHelper(Helper):
logger().error( "[helper] Message Bus is not supported yet" )
return None
def get_tool_path( self, tool_type ):
tool_name, tool_pathdef = self.get_tool_info( tool_type )
tool_path = tool_pathdef
try:
import pkg_resources
tool_path = pkg_resources.resource_filename( '%s.%s' % (chipsec.file.TOOLS_DIR,self.os_system.lower()), tool_name )
except ImportError:
pass
if not os.path.isfile( tool_path ):
tool_path = os.path.join( tool_pathdef, tool_name )
if not os.path.isfile( tool_path ): logger().error( "Couldn't find %s" % tool_path )
return tool_path
def get_compression_tool_path( self, compression_type ):
return self.get_tool_path( compression_type )
#
# Decompress binary with OS specific tools
#
def decompress_file( self, CompressedFileName, OutputFileName, CompressionType ):
import subprocess
if (CompressionType == 0): # not compressed
shutil.copyfile(CompressedFileName, OutputFileName)
else:
exe = self.get_compression_tool_path( CompressionType )
if exe is None: return None
try:
subprocess.call( [ exe, "-d", "-o", OutputFileName, CompressedFileName ], stdout=open(os.devnull, 'wb') )
except BaseException, msg:
logger().error( str(msg) )
if logger().DEBUG: logger().log_bad( traceback.format_exc() )
return None
return chipsec.file.read_file( OutputFileName )
#
# File system
#
+3 -2
View File
@@ -27,8 +27,9 @@
#
##################################################################################
import platform
if "windows" == platform.system().lower():
import platform, os
if "windows" == platform.system().lower() and os.path.isfile(os.path.join(os.getcwd(), "win7_amd64\chipsec_hlpr.sys")):
__all__ = [ "win32helper" ]
else:
__all__ = []
+2
View File
@@ -353,6 +353,8 @@ class Win32Helper(Helper):
if logger().VERBOSE: logger().log( "[helper] service control manager opened (handle = 0x%08x)" % hscm )
driver_path = os.path.join( chipsec.file.get_main_dir(), "chipsec", "helper", "win", self.win_ver, DRIVER_FILE_NAME )
if not os.path.isfile( driver_path ):
driver_path = os.path.join("C:\\Windows\\System32\\drivers\\RwDrv.sys"
if os.path.isfile( driver_path ):
self.driver_path = driver_path
if logger().VERBOSE: logger().log( "[helper] driver path: '%s'" % os.path.abspath(self.driver_path) )