<s> from bowcaster . common . support import LittleEndian <EOL> from bowcaster . common . support import BigEndian <EOL> from bowcaster . development import OverflowBuffer <EOL> from bowcaster . development import SectionCreator <EOL> from bowcaster . common . support import Logging <EOL> from checksums . libacos import LibAcosChecksum <EOL> import re <EOL> import struct <EOL> class AmbitHeaderException ( Exception ) : <EOL> pass <EOL> class JankyAmbitHeader ( object ) : <EOL> """<STR_LIT>""" <EOL> MAGIC = "<STR_LIT>" <EOL> MAGIC_OFF = <NUM_LIT:0> <EOL> HEADER_SIZE = <NUM_LIT> <EOL> HEADER_SIZE_OFF = <NUM_LIT:4> <EOL> PART_1_SIZE_OFF = <NUM_LIT> <EOL> PART_2_SIZE = <NUM_LIT:0> <EOL> PART_2_SIZE_OFF = <NUM_LIT> <EOL> HEADER_CHECKSUM_OFF = <NUM_LIT> <EOL> BOARD_ID = "<STR_LIT>" <EOL> BOARD_ID_OFF = <NUM_LIT> <EOL> def __init__ ( self , image_data , logger = None ) : <EOL> """<STR_LIT>""" <EOL> if not logger : <EOL> logger = Logging ( max_level = Logging . DEBUG ) <EOL> self . logger = logger <EOL> logger . LOG_DEBUG ( "<STR_LIT>" ) <EOL> self . size = self . HEADER_SIZE <EOL> logger . LOG_INFO ( "<STR_LIT>" ) <EOL> self . trx_image_checksum = self . __checksum ( image_data ) <EOL> logger . LOG_DEBUG ( "<STR_LIT>" % self . trx_image_checksum ) <EOL> self . trx_image_sz = len ( image_data ) <EOL> logger . LOG_INFO ( "<STR_LIT>" ) <EOL> header = self . __build_header ( ) <EOL> logger . LOG_INFO ( "<STR_LIT>" ) <EOL> chksum = self . __checksum ( header ) <EOL> logger . LOG_DEBUG ( "<STR_LIT>" % chksum ) <EOL> logger . LOG_INFO ( "<STR_LIT>" ) <EOL> header = self . __build_header ( checksum = chksum ) <EOL> self . header = header <EOL> def __build_header ( self , checksum = <NUM_LIT:0> ) : <EOL> logger = self . logger <EOL> SC = SectionCreator ( BigEndian , logger = logger ) <EOL> SC . string_section ( self . MAGIC_OFF , self . MAGIC , <EOL> description = "<STR_LIT>" ) <EOL> SC . gadget_section ( self . HEADER_SIZE_OFF , self . size , "<STR_LIT>" ) <EOL> SC . gadget_section ( self . HEADER_CHECKSUM_OFF , checksum ) <EOL> SC . string_section ( self . BOARD_ID_OFF , self . BOARD_ID , <EOL> description = "<STR_LIT>" ) <EOL> SC . gadget_section ( self . PART_1_SIZE_OFF , <EOL> self . trx_image_sz , <EOL> description = "<STR_LIT>" ) <EOL> SC . gadget_section ( self . PART_2_SIZE_OFF , <EOL> self . PART_2_SIZE , <EOL> description = "<STR_LIT>" ) <EOL> buf = OverflowBuffer ( BigEndian , self . size , <EOL> overflow_sections = SC . section_list , <EOL> logger = logger ) <EOL> return buf <EOL> def __checksum ( self , header ) : <EOL> data = str ( header ) <EOL> size = len ( data ) <EOL> chksum = LibAcosChecksum ( data , size ) <EOL> return chksum . checksum <EOL> def __str__ ( self ) : <EOL> return str ( self . header ) <EOL> def find_offset ( self , value ) : <EOL> """<STR_LIT>""" <EOL> return self . header . find_offset ( value ) </s>
