objutils package¶
Subpackages¶
Submodules¶
objutils.ash module¶
-
class
objutils.ash.
Reader
(address_pattern='^(?:(?P<stx>[\x02])\s+)?\$A(?P<address>[0-9a-zA-Z]{2,8})[,.]\s*$', data_pattern='^(?:[0-9a-zA-Z]{{2,4}}[{0}]?)*\s*$', etx_pattern='^q.*$')¶ Bases:
objutils.hexfile.ASCIIHexReader
-
VALID_CHARS
= re.compile("^[a-fA-F0-9 %,\\'\\$\\x02\\x03\\n\\r]*$")¶
-
codecName
= 'ash'¶
-
-
class
objutils.ash.
Writer
(address_designator='$A')¶ Bases:
objutils.hexfile.ASCIIHexWriter
-
ADDRESS_DESIGNATOR
= '$A'¶
-
MAX_ADDRESS_BITS
= 16¶
-
codecName
= 'ash'¶
-
compose_header
(meta)¶
-
row_callout
(address, length, row)¶
-
-
objutils.ash.
checksum
(data, *, width=16, comp=0)¶ Longitudinal redundancy check.
objutils.binfile module¶
Reader/Writer for plain binfiles.
-
class
objutils.binfile.
BinZipWriter
¶ Bases:
object
-
MANIFEST_FILE_NAME
= 'IMAGES.mf'¶
-
SECTION_FILE_NAME
= 'image{0:d}.bin'¶
-
codecName
= 'binzip'¶
-
dump
(fp, image, **kws)¶
-
dumps
(image, **kws)¶
-
-
exception
objutils.binfile.
NoContiniousError
¶ Bases:
Exception
objutils.cc2vmc module¶
objutils.checksums module¶
-
objutils.checksums.
ADD11
(frame)¶
-
objutils.checksums.
ADD12
(frame)¶
-
objutils.checksums.
ADD14
(frame)¶
-
objutils.checksums.
ADD22
(frame)¶
-
objutils.checksums.
ADD24
(frame)¶
-
objutils.checksums.
ADD44
(frame)¶
-
class
objutils.checksums.
Algorithm
¶ Bases:
enum.IntEnum
Enumerates available checksum algorithms
-
CHK_ADD_11
= 1¶
-
CHK_ADD_12
= 2¶
-
CHK_ADD_14
= 3¶
-
CHK_ADD_22
= 4¶
-
CHK_ADD_24
= 5¶
-
CHK_ADD_44
= 6¶
-
CHK_CRC_16
= 7¶
-
CHK_CRC_16_CCITT
= 8¶
-
CHK_CRC_32
= 9¶
-
CHK_USER_DEFINED
= 10¶
-
-
objutils.checksums.
CRC32
(x)¶
-
class
objutils.checksums.
Crc16
(table, initalRemainder, finalXorValue, reflectData, reflectRemainder)¶ Bases:
object
Calculate CRC (16-bit)
Parameters: - table (list-like) – lookup table for CRC calculation
- initalRemainder (int) – value to start with
- finalXorValue (int) – final XOR value
- reflectData (bool) – reflect input data
- reflectRemainder (bool) – reflect output data
- [1] A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS (.) – http://www.ross.net/crc/download/crc_v3.txt
- [2] Understanding and implementing CRC (Cyclic Redundancy Check) (.) – calculation http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html
- [3] Online CRC calculator (.) – http://zorc.breitbandkatze.de/crc.html
-
WIDTH
= 16¶
-
reflectIn
(ch, remainder)¶
-
reflectOut
(remainder)¶
-
objutils.checksums.
ROTATE_LEFT
(value)¶ Rotate byte left.
-
objutils.checksums.
ROTATE_RIGHT
(value)¶ Rotate byte right.
-
objutils.checksums.
adder
(modulus)¶ Factory function for modulus adders
Parameters: modulus (int) – modulus to use Returns: adder function Return type: function Examples
>>> a256=adder(256) >>> a256([11, 22, 33, 44, 55, 66, 77, 88, 99]) 239
-
objutils.checksums.
check
(frame, algo)¶ Calculate checksum using given algorithm
Parameters: - frame (list of integers) –
- algo (ALGO) –
Returns: Return type: int
-
objutils.checksums.
lrc
(data, width, comp=0)¶ Longitudinal redundancy check.
-
objutils.checksums.
nibble_sum
(data)¶
-
objutils.checksums.
reflect
(data, nBits)¶ Reflect data, i.e. reverse bit order.
Parameters: - data (int) –
- nBits (int) – width in bits of data
-
objutils.checksums.
rolb
(value)¶ Rotate byte left.
-
objutils.checksums.
rorb
(value)¶ Rotate byte right.
-
objutils.checksums.
rotatedXOR
(values, width, rotator)¶ Rotated XOR cipher.
-
objutils.checksums.
userDefined
(x)¶ User defined algorithms are not supported yet.
-
objutils.checksums.
wordSum
(modulus, step)¶ Factory function for (double-)word modulus sums
Parameters: - modulus (int) –
- step ([2, 4]) – 2 - word wise 4 - double-word wise
Returns: summation function
Return type: function
-
objutils.checksums.
xor
(frame, invert=True)¶
objutils.cosmac module¶
-
class
objutils.cosmac.
Reader
¶ Bases:
objutils.hexfile.Reader
-
FORMAT_SPEC
= ((1, '!MAAAA DD'), (2, '\\?MAAAA DD'), (3, 'AAAA DD'), (4, 'DD'))¶
-
check_line
(line, format_type)¶
-
codecName
= 'cosmac'¶
-
is_data_line
(line, format_type)¶
-
previous_address
= 0¶
-
previous_length
= 0¶
-
-
class
objutils.cosmac.
Writer
¶ Bases:
objutils.hexfile.Writer
-
MAX_ADDRESS_BITS
= 16¶
-
codecName
= 'cosmac'¶
-
compose_row
(address, length, row)¶
-
objutils.emon52 module¶
-
class
objutils.emon52.
Reader
¶ Bases:
objutils.hexfile.Reader
-
DATA_SEPARATOR
= ' '¶
-
FORMAT_SPEC
= ((0, 'LL AAAA:DD CCCC'),)¶
-
check_line
(line, format_type)¶
-
codecName
= 'emon52'¶
-
is_data_line
(line, format_type)¶
-
-
class
objutils.emon52.
Writer
¶ Bases:
objutils.hexfile.Writer
-
MAX_ADDRESS_BITS
= 16¶
-
codecName
= 'emon52'¶
-
compose_row
(address, length, row)¶
-
objutils.etek module¶
-
class
objutils.etek.
Reader
¶ Bases:
objutils.hexfile.Reader
-
FORMAT_SPEC
= ((1, '%LL6CCAAAAADD'), (2, '%LL3CCU'), (3, '%LL8CCAAAAADD'))¶
-
VALID_CHARS
= re.compile('^[a-zA-Z0-9_ %\\n\\r]*$')¶
-
check_line
(line, format_type)¶
-
codecName
= 'etek'¶
-
is_data_line
(line, format_type)¶
-
parseData
(line, format_type)¶
-
-
class
objutils.etek.
Writer
¶ Bases:
objutils.hexfile.Writer
-
MAX_ADDRESS_BITS
= 24¶
-
codecName
= 'etek'¶
-
compose_row
(address, length, row)¶
-
objutils.exceptions module¶
-
exception
objutils.exceptions.
FeatureNotAvailableError
¶ Bases:
Exception
Raised if something is missing, e.g. Numpy for certain operations.
-
exception
objutils.exceptions.
FileCorruptedError
¶ Bases:
Exception
-
exception
objutils.exceptions.
InvalidAddressError
¶ Bases:
Exception
Raised if address information is out of range.
-
exception
objutils.exceptions.
PrematureEndOfFileError
¶ Bases:
Exception
objutils.fpc module¶
-
class
objutils.fpc.
Reader
¶ Bases:
objutils.hexfile.Reader
-
FORMAT_SPEC
= ((1, 'CCLL0000AAAAAAAADD'), (2, 'CCLL0001DD'), (3, 'CCLL0002AAAAAAAADD'), (4, '00000000'))¶
-
check_line
(line, format_type)¶
-
codecName
= 'fpc'¶
-
convert_quintuple
(quintuple)¶
-
decode
(fp)¶
-
is_data_line
(line, format_type)¶
-
probe
(fp)¶ Determine if object is valid.
-
read
(fp)¶
-
split_quintuples
(line)¶
-
objutils.hexdiff module¶
objutils.hexdump module¶
-
class
objutils.hexdump.
CanonicalDumper
(fp=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, num_address_bits=32)¶ Bases:
objutils.hexdump.Dumper
-
LINE_LENGTH
= 16¶
-
dump_row
(row, startAddr)¶
-
printhex_bytes
(row)¶
-
-
class
objutils.hexdump.
Dumper
(fp=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, num_address_bits=32)¶ Bases:
object
-
dump_data
(section, offset=0)¶
-
-
objutils.hexdump.
isprintable
(ch)¶
-
objutils.hexdump.
unpack
(*args)¶
objutils.hexfile module¶
-
class
objutils.hexfile.
ASCIIHexReader
(address_pattern, data_pattern, etx_pattern, separators=', ')¶ Bases:
objutils.hexfile.Reader
-
FORMAT_SPEC
= None¶
-
getAddress
(line, match)¶
-
nop
(line, match)¶
-
parse_line
(line, match)¶
-
read
(fp)¶
-
-
class
objutils.hexfile.
ASCIIHexWriter
(address_designator)¶ Bases:
objutils.hexfile.Writer
-
MAX_ADDRESS_BITS
= 16¶
-
compose_row
(address, length, row)¶
-
previous_address
= None¶
-
row_callout
(address, length, row)¶
-
-
exception
objutils.hexfile.
AddressRangeToLargeError
¶ Bases:
Exception
-
class
objutils.hexfile.
FormatParser
(fmt, data_separator=None)¶ Bases:
object
-
parse
()¶
-
translateFormat
(group)¶
-
-
exception
objutils.hexfile.
InvalidRecordChecksumError
¶ Bases:
Exception
-
exception
objutils.hexfile.
InvalidRecordLengthError
¶ Bases:
Exception
-
exception
objutils.hexfile.
Invalidrecord_typeError
¶ Bases:
Exception
-
class
objutils.hexfile.
MetaRecord
(format_type, address, chunk)¶ Bases:
tuple
-
address
¶ Alias for field number 1
-
chunk
¶ Alias for field number 2
-
format_type
¶ Alias for field number 0
-
-
class
objutils.hexfile.
Reader
¶ Bases:
objutils.hexfile.BaseType
-
ALIGMENT
= 0¶
-
DATA_SEPARATOR
= None¶
-
VALID_CHARS
= re.compile('^[a-fA-F0-9 :/;,%\\n\\r!?S]*$')¶
-
check_line
(line, format_type)¶
-
classifyLine
(line)¶
-
is_data_line
(line, format_type)¶
-
load
(fp, **kws)¶
-
loads
(image, **kws)¶
-
maybe_binary_file
(fp)¶
-
parseData
(line, format_type)¶
-
probe
(fp)¶ Determine if object is valid.
-
probes
(image)¶
-
read
(fp)¶
-
special_processing
(line, format_type)¶
-
-
class
objutils.hexfile.
Writer
¶ Bases:
objutils.hexfile.BaseType
-
calculate_address_bits
(image)¶
-
compose_header
(meta)¶
-
compose_row
(address, length, row)¶
-
dump
(fp, image, row_length=16, **kws)¶
-
dumps
(image, row_length=16, **kws)¶
-
static
hex_bytes
(row, spaced=False)¶
-
post_processing
(data)¶
-
pre_processing
(image)¶
-
set_parameters
(**kws)¶
-
word_to_bytes
(word)¶
-
objutils.ihex module¶
-
class
objutils.ihex.
Reader
¶ Bases:
objutils.hexfile.Reader
-
FORMAT_SPEC
= ((0, ':LLAAAATTDDCC'),)¶
-
calculate_extended_address
(line, shift_by, name)¶
-
check_line
(line, format_type)¶
-
codecName
= 'ihex'¶
-
is_data_line
(line, format_type)¶
-
special_processing
(line, format_type)¶
-
-
class
objutils.ihex.
Writer
¶ Bases:
objutils.hexfile.Writer
-
MAX_ADDRESS_BITS
= 32¶
-
checksum
= functools.partial(<function lrc>, width=8, comp=2)¶
-
codecName
= 'ihex'¶
-
compose_row
(address, length, row)¶
-
pre_processing
(image)¶
-
-
objutils.ihex.
divmod
(a, b)¶
objutils.image module¶
-
class
objutils.image.
AddressSpace
¶ Bases:
enum.IntEnum
Adress-space constants.
-
AS_16
= 0¶
-
AS_24
= 1¶
-
AS_32
= 2¶
-
AS_64
= 3¶
-
-
class
objutils.image.
Image
(sections=None, join=True, meta=None)¶ Bases:
object
Manage images.
An image is a collection of :class:`Section`s and meta-data.
Parameters: - sections (iteratable (typically list`or `tuple) – The sections the image should initialized with.
- meta (object) – Arbitrary meta-data.
-
delete_section
(address=None)¶
-
get_section
(address)¶ Get
Section
containing address. :param address: :type address: intReturns: Return type: Section
Raises: InvalidAddressError –
-
hexdump
(fp=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>)¶
-
insert_section
(data, start_address=None, join=True)¶ Insert/add a new section to image.
Parameters: - data (convertible to bytearray() – s.
_data_converter()
.) – Bytes making up the section. - start_address (int) –
- join (bool) – Join/merge adjacent section.
Raises: Notes
Overlapping sections are not supported. To update/replace a section use
update_section()
.- data (convertible to bytearray() – s.
-
join_sections
()¶
-
read
(addr, length, **kws)¶ Read bytes from image.
Parameters: - addr (int) – Startaddress.
- length (int) – Number of bytes to read.
Returns: Return type: bytes
Raises: InvalidAddressError – if addr is out of range
Note
if addr + len is out of range, result is silently truncated, i.e. without raising an exception.
-
read_ndarray
(addr, length, dtype, shape=None, order=None, **kws)¶
-
read_numeric
(addr, dtype, **kws)¶
-
read_numeric_array
(addr, length, dtype, **kws)¶
-
read_string
(addr, encoding='latin1', length=-1, **kws)¶
-
sections
¶
-
split
(at=None, equal_parts=None, remap=None)¶
-
update_section
(data, address=None)¶
-
write
(addr, data, **kws)¶ Write bytes to image.
Parameters: - addr (int) – Startaddress.
- data (bytes) –
Raises: InvalidAddressError – if addr is out of range
-
write_ndarray
(addr, array, order=None, **kws)¶
-
write_numeric
(addr, value, dtype, **kws)¶
-
write_numeric_array
(addr, data, dtype, **kws)¶
-
write_string
(addr, value, encoding='latin1', **kws)¶
objutils.logger module¶
objutils.mostec module¶
-
class
objutils.mostec.
Reader
¶ Bases:
objutils.hexfile.Reader
-
FORMAT_SPEC
= ((1, ';LLAAAADDCCCC'), (2, ';00'))¶
-
check_line
(line, format_type)¶
-
codecName
= 'mostec'¶
-
is_data_line
(line, format_type)¶
-
-
class
objutils.mostec.
Writer
¶ Bases:
objutils.hexfile.Writer
-
MAX_ADDRESS_BITS
= 16¶
-
codecName
= 'mostec'¶
-
compose_row
(address, length, row)¶
-
objutils.pickleif module¶
objutils.rca module¶
-
class
objutils.rca.
Reader
¶ Bases:
objutils.hexfile.Reader
-
FORMAT_SPEC
= ((1, 'AAAA DD;'), (2, ':0000'))¶
-
check_line
(line, format_type)¶
-
codecName
= 'rca'¶
-
is_data_line
(line, format_type)¶
-
-
class
objutils.rca.
Writer
¶ Bases:
objutils.hexfile.Writer
-
MAX_ADDRESS_BITS
= 16¶
-
SEPARATOR
= '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\r\n'¶
-
codecName
= 'rca'¶
-
compose_header
(meta)¶
-
compose_row
(address, length, row)¶
-
objutils.readers module¶
objutils.registry module¶
-
class
objutils.registry.
Codec
(Reader, Writer, description)¶ Bases:
tuple
-
Reader
¶ Alias for field number 0
-
Writer
¶ Alias for field number 1
-
description
¶ Alias for field number 2
-
-
exception
objutils.registry.
CodecAlreadyExistError
¶ Bases:
Exception
-
exception
objutils.registry.
CodecDoesNotExistError
¶ Bases:
Exception
objutils.section module¶
-
class
objutils.section.
NumberRange
(lower, upper)¶ Bases:
tuple
-
lower
¶ Alias for field number 0
-
upper
¶ Alias for field number 1
-
-
class
objutils.section.
Section
(start_address: int = 0, data=bytearray(b''))¶ Bases:
object
Manage sections.
A section is a continuous block of bytes, with a start-address and known length.
-
address
¶
-
apply_bitmask
(data, dtype, bit_mask)¶
-
find
(expr, addr=-1)¶
-
hexdump
(fp=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>)¶
-
length
¶
-
read
(addr, length, **kws)¶ Parameters: - addr (int) –
- length (int) –
-
read_ndarray
(addr, length, dtype, shape=None, order=None, **kws)¶
-
read_numeric
(addr, dtype, **kws)¶
-
read_numeric_array
(addr, length, dtype, **kws)¶
-
read_string
(addr, encoding='latin1', length=-1, **kws)¶
-
tobytes
()¶
-
tolist
()¶
-
write
(addr, data, **kws)¶ Parameters: - addr (int) –
- length (int) –
- data (array-like) –
-
write_ndarray
(addr, array, order=None, **kws)¶
-
write_numeric
(addr, value, dtype, **kws)¶
-
write_numeric_array
(addr, data, dtype, **kws)¶
-
write_string
(addr, value, encoding='latin1', **kws)¶
-
-
class
objutils.section.
TypeInformation
(type, byte_order, size)¶ Bases:
tuple
-
byte_order
¶ Alias for field number 1
-
size
¶ Alias for field number 2
-
type
¶ Alias for field number 0
-
-
objutils.section.
filler
(ch, n)¶ Create an bytearray consisting of n `ch`s.
Parameters: - ch (int (0 <= ch <= 255)) – fill char
- n (int) – repetition count
Returns: Return type: bytearray
-
objutils.section.
join_sections
(sections)¶
-
objutils.section.
signed_range
(x)¶
-
objutils.section.
unsigned_range
(x)¶
objutils.sig module¶
-
class
objutils.sig.
Reader
¶ Bases:
objutils.hexfile.Reader
-
FORMAT_SPEC
= ((1, ':AAAALLBBDDCC'), (2, ':00'))¶
-
check_line
(line, format_type)¶
-
codecName
= 'sig'¶
-
is_data_line
(line, format_type)¶
-
-
class
objutils.sig.
Writer
¶ Bases:
objutils.hexfile.Writer
-
MAX_ADDRESS_BITS
= 16¶
-
codecName
= 'sig'¶
-
compose_row
(address, length, row)¶
-
objutils.srec module¶
-
class
objutils.srec.
Reader
¶ Bases:
objutils.hexfile.Reader
-
FORMAT_SPEC
= ((1, 'S0LLAAAADDCC'), (2, 'S1LLAAAADDCC'), (3, 'S2LLAAAAAADDCC'), (4, 'S3LLAAAAAAAADDCC'), (5, 'S5LLAAAACC'), (6, 'S7LLAAAAAAAACC'), (7, 'S8LLAAAAAACC'), (8, 'S9LLAAAACC'))¶
-
check_line
(line, format_type)¶
-
codecName
= 'srec'¶
-
is_data_line
(line, format_type)¶
-
load
(fp, **kws)¶
-
special_processing
(line, format_type)¶
-
-
class
objutils.srec.
Writer
¶ Bases:
objutils.hexfile.Writer
-
MAX_ADDRESS_BITS
= 32¶
-
checksum
= functools.partial(<function lrc>, width=8, comp=1)¶
-
codecName
= 'srec'¶
-
compose_header
(meta)¶
-
compose_row
(address, length, row)¶
-
pre_processing
(image)¶
-
record_type
= None¶
-
s5record
= False¶
-
srecord
(record_type, length, address, data=None)¶
-
start_address
= None¶
-
objutils.tek module¶
-
class
objutils.tek.
Reader
¶ Bases:
objutils.hexfile.Reader
-
FORMAT_SPEC
= ((1, '/AAAALLBBDDCC'), (2, '/AAAA00BB'))¶
-
check_line
(line, format_type)¶
-
codecName
= 'tek'¶
-
is_data_line
(line, format_type)¶
-
-
class
objutils.tek.
Writer
¶ Bases:
objutils.hexfile.Writer
-
MAX_ADDRESS_BITS
= 16¶
-
codecName
= 'tek'¶
-
compose_row
(address, length, row)¶
-
objutils.titxt module¶
-
class
objutils.titxt.
Reader
(address_pattern='^@(?P<address>[0-9a-zA-Z]{2, 8})\s*$', data_pattern='^(?:[0-9a-zA-Z]{{2, 4}}[{0}]?)*\s*$', etx_pattern='^q.*$')¶ Bases:
objutils.hexfile.ASCIIHexReader
-
codecName
= 'titxt'¶
-
-
class
objutils.titxt.
Writer
(address_designator='@')¶ Bases:
objutils.hexfile.ASCIIHexWriter
-
codecName
= 'titxt'¶
-
objutils.utils module¶
-
exception
objutils.utils.
CommandError
¶ Bases:
Exception
-
class
objutils.utils.
Curry
(fun, *args, **kwargs)¶ Bases:
object
-
class
objutils.utils.
SingletonBase
¶ Bases:
object
-
class
objutils.utils.
StructureWithEnums
¶ Bases:
_ctypes.Structure
Add missing enum feature to ctypes Structures.
-
objutils.utils.
bin_extractor
(fname, offset, length)¶ Extract a junk of data from a file.
-
objutils.utils.
create_memorymapped_fileview
(filename, writeable=False)¶
-
objutils.utils.
create_string_buffer
(*args)¶ Create a string with file-like behaviour (StringIO on Python 2.x).
-
objutils.utils.
cygpath_to_win
(path)¶
-
objutils.utils.
get_python_version
()¶
-
objutils.utils.
identity
(self, x)¶
-
objutils.utils.
int_to_array
(value)¶
-
objutils.utils.
make_list
(*args)¶
-
objutils.utils.
runCommand
(cmd)¶
-
objutils.utils.
slicer
(iterable, sliceLength, converter=None)¶
Module contents¶
Package entry-point.
Registers CODECS and implements an interface to them.
The first parameter is always the codec name.
-
objutils.
dump
(codec_name, *args, **kws)¶ Save hex data to file.
Parameters: codec_name (str) – Name of a registered codec. Returns: Return type: bytes
-
objutils.
dumps
(codec_name, *args, **kws)¶ Save hex data to bytes.
Parameters: codec_name (str) – Name of a registered codec. Returns: Return type: bytes
-
objutils.
load
(codec_name, *args, **kws)¶ Load hex data from file.
Parameters: codec_name (str) – Name of a registered codec. Returns: class Return type: Image
-
objutils.
loads
(codec_name, *args, **kws)¶ Load hex data from bytes.
Parameters: codec_name (str) – Name of a registered codec. Returns: class Return type: Image
-
objutils.
probe
(*args, **kws)¶ Try to guess codec from file.
Parameters: codec_name (str) – Name of a registered codec. Returns: Return type: str
-
objutils.
probes
(*args, **kws)¶ Try to guess codec from bytes.
Parameters: codec_name (str) – Name of a registered codec. Returns: Return type: str