Ejemplo n.º 1
0
    def send(self, glob, connection):

        body_bytes = glob.pack()
        body_size = len(body_bytes)

        # Send a 1 at start of header to show that CRC and packet number should be valid.
        header_fmt = '<BBBHBB'
        header = (self.message_start_byte, 1, glob.id, glob.instance, self.next_packet_num, body_size)
        header_size = 7

        struct.pack_into(header_fmt, self.transfer_buffer, 0, *header)

        self.transfer_buffer[header_size : header_size + body_size] = body_bytes # array.array('c', body_bytes)

        crc = calculate_crc(self.transfer_buffer, header_size + body_size, 0xFFFF)

        struct.pack_into('<H', self.transfer_buffer, header_size + body_size, crc)
        footer_size = 2

        message_size = header_size + body_size + footer_size

        connection.write(self.transfer_buffer[:message_size])

        self.num_bytes_sent += message_size
        self.num_messages_sent += 1
        self.next_packet_num += 1
        if self.next_packet_num > 255:
            self.next_packet_num = 0
Ejemplo n.º 2
0
    def send(self, glob):
        
        if not self.connection_open():
            return
        
        body_bytes = glob.pack()
        body_size = len(body_bytes)
        
        # Send a 1 at start of header to show that CRC and packet number should be valid.
        header_fmt = '<BBBHBB'
        header = (self.message_start_byte, 1, glob.id, glob.instance, self.next_packet_num, body_size)
        header_size = 7
        
        struct.pack_into(header_fmt, self.transfer_buffer, 0, *header)
        
        self.transfer_buffer[header_size : header_size + body_size] = body_bytes # array.array('c', body_bytes)
        
        crc = calculate_crc(self.transfer_buffer, header_size + body_size, 0xFFFF)

        struct.pack_into('<H', self.transfer_buffer, header_size + body_size, crc)
        footer_size = 2
        
        message_size = header_size + body_size + footer_size

        self.connection.write(self.transfer_buffer[:message_size])
        
        self.num_bytes_sent += message_size
        self.num_messages_sent += 1
        self.next_packet_num += 1
        if self.next_packet_num > 255:
            self.next_packet_num = 0
Ejemplo n.º 3
0
    def verify_crc(self):

        expected_crc = self.expected_crc1 + (self.expected_crc2 << 8)
        actual_crc = calculate_crc(self.message_data, self.body_end_idx, 0xFFFF)

        if expected_crc != actual_crc:
            self.num_bad_crc_messages += 1
            return False # don't match

        return True # CRC matches
Ejemplo n.º 4
0
 def verify_crc(self):
     
     expected_crc = self.expected_crc1 + (self.expected_crc2 << 8)
     actual_crc = calculate_crc(self.message_data, self.body_end_idx, 0xFFFF)
     
     if expected_crc != actual_crc:
         self.num_bad_crc_messages += 1
         return False # don't match
     
     return True # CRC matches
Ejemplo n.º 5
0
 def update_header(self):
     crc = calculate_crc(self)
     self.write_bytes(0x10, crc)
Ejemplo n.º 6
0
# Compile code

os.environ['PATH'] = script_dir + os.pathsep + os.environ['PATH']

if compile_c:
    os.chdir(run_dir + '/c')
    call(['make'])

os.chdir(run_dir + '/src')
call(['armips', '-sym2', '../build/asm_symbols.txt', 'build.asm'])
os.chdir(run_dir)

# update crc
with open('roms/oot_mm.z64', 'r+b') as stream:
    buffer = bytearray(stream.read(0x101000))
    crc = calculate_crc(buffer)
    stream.seek(0x10)
    stream.write(bytearray(crc))

quit()

with open('build/asm_symbols.txt', 'rb') as f:
    asm_symbols_content = f.read()
asm_symbols_content = asm_symbols_content.replace(b'\r\n', b'\n')
asm_symbols_content = asm_symbols_content.replace(b'\x1A', b'')
with open('build/asm_symbols.txt', 'wb') as f:
    f.write(asm_symbols_content)

# Parse symbols

c_sym_types = {}
Ejemplo n.º 7
0
        data_symbols[name] = '{0:08X}'.format(addr)
with open('data/symbols.json', 'w') as f:
    json.dump(data_symbols, f, indent=4, sort_keys=True)

if pj64_sym_path:
    pj64_sym_path = os.path.realpath(pj64_sym_path)
    with open(pj64_sym_path, 'w') as f:
        key = lambda pair: pair[1]['address']
        for sym_name, sym in sorted(symbols.items(), key=key):
            f.write('{0},{1},{2}\n'.format(sym['address'], sym['type'], sym_name))

# Update CRC

with open('roms/patched.z64', 'r+b') as stream:
    buffer = bytearray(stream.read(0x101000))
    crc = calculate_crc(BigStream(buffer))
    stream.seek(0x10)
    stream.write(bytearray(crc))

# Patch output ROM

if not diff_only:
    try:
        os.chdir(run_dir + '/patch')
        call(['flips', '--ignore-checksum', 'patch.bps', '../roms/patched.z64'])
    except Exception:
        pass

# Diff ROMs

os.chdir(run_dir)
Ejemplo n.º 8
0
def update_crc(path):
    with open(path, 'r+b') as stream:
        buffer = bytearray(stream.read(0x101000))
        crc = calculate_crc(BigStream(buffer))
        stream.seek(0x10)
        stream.write(bytearray(crc))
Ejemplo n.º 9
0
 def update_header(self):
     self.write_bytes(0x35, get_version_bytes(__version__))
     crc = calculate_crc(self)
     self.write_int32s(0x10, [crc[0], crc[1]])