Skip to content

Instantly share code, notes, and snippets.

@mefff
Created July 8, 2022 21:59
Show Gist options
  • Save mefff/11773fdf0a71e64f52ebd3e930e08a51 to your computer and use it in GitHub Desktop.
Save mefff/11773fdf0a71e64f52ebd3e930e08a51 to your computer and use it in GitHub Desktop.

file:///home/meff/eclypsium/chipsec/chipsec/modules/common/smm.py

def is_supported(self):
    if self.cs.is_core() and self.cs.is_register_defined('PCI0.0.0_SMRAMC'):
	return True
    self.logger.log("Either not a Core (client) platform or 'PCI0.0.0_SMRAMC' not defined for platform. Skipping module.")
    self.res = ModuleResult.NOTAPPLICABLE
    return False

Se le puede hacer un refactor para que no haga early return. Para testear se necesita mockear cs.is_core y cs.is_register_defined aunque se puede hacer sin Mock

Medio pavo..

Somewhere

def read_file( filename, size=0 ):
    #with open( filename, 'rb' ) as f:
    #  _file = f.read()
    #f.closed

    try:
	f = open(filename, 'rb')
    except:
	logger().log_error("Unable to open file '{:.256}' for read access".format(filename))
	return 0

    if size:
	_file = f.read( size )
    else:
	_file = f.read()
	f.close()

    if logger().DEBUG: logger().log( "[file] read {:d} bytes from '{:256}'".format( len(_file), filename ) )
    return _file

def write_file( filename, buffer, append=False ):
    #with open( filename, 'wb' ) as f:
    #  f.write( buffer )
    #f.closed
    perm = 'a' if append else 'w'
    if isinstance(buffer, bytes) or isinstance(buffer, bytearray):
	perm += 'b'
    try:
	f = open(filename, perm)
    except:
	logger().log_error("Unable to open file '{:.256}' for write access".format(filename))
	return 0
    f.write( buffer )
    f.close()

    if logger().DEBUG: logger().log( "[file] wrote {:d} bytes to '{:.256}'".format( len(buffer), filename ) )
    return True

Por que existen estas funciones??

file:///home/meff/eclypsium/chipsec/chipsec/hal/acpi.py

def _parse_table_header( self, header ):
    acpi_table_hdr = ACPI_TABLE_HEADER( *struct.unpack_from( ACPI_TABLE_HEADER_FORMAT, header ) )
    if logger().HAL: logger().log( acpi_table_hdr )
    return acpi_table_hdr

staticmethod. Facil de testear

file:///home/meff/eclypsium/chipsec/chipsec/hal/acpi_tables.py

def parse( self, table_content ):
    return

raise NotImplementedError. No mucho para testear…

file:///home/meff/eclypsium/chipsec/chipsec/hal/acpi_tables.py

def parseTime(self, table_content):
    seconds = struct.unpack('<B', table_content[0:1])[0]
    minutes = struct.unpack('<B', table_content[1:2])[0]
    hours = struct.unpack('<B', table_content[2:3])[0]
    percision = struct.unpack('<B', table_content[3:4])[0]
    day = struct.unpack('<B', table_content[4:5])[0]
    month = struct.unpack('<B', table_content[5:6])[0]
    year = struct.unpack('<B', table_content[6:7])[0]
    century = struct.unpack('<B', table_content[7:8])[0]
    precision_str = ''
    if percision > 0:
	precision_str = '(time is percise and correlates to time of event)'
    return ''' {:d}:{:d}:{:d} {:d}/{:d}/{:d}{:d} [m/d/y] {}'''.format(hours, minutes, seconds, month, day, century, year, precision_str)

staticmethod. facil de testear. presicionstr puede ser mejor. f-strings?

file:///home/meff/eclypsium/chipsec/chipsec/modules/tools/uefi/uefivar_fuzz.py

def rnd(self, n=1):
    rnum = b''
    for j in range(n):
	rnum += struct.pack("B", random.randint(0, 255))
    return rnum

staticmethod. simple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment