def disassemble_symbol(self, sym_bytes, sym_type): if sym_type == "jtbl": sym_str = ".word " else: sym_str = f".{sym_type} " if sym_type == "double": slen = 8 elif sym_type in ["float", "word", "jtbl"]: slen = 4 elif sym_type == "short": slen = 2 else: slen = 1 i = 0 while i < len(sym_bytes): adv_amt = min(slen, len(sym_bytes) - i) bits = int.from_bytes(sym_bytes[i:i + adv_amt], "big") if sym_type == "jtbl": if bits == 0: byte_str = "0" else: rom_addr = self.ram_to_rom(bits) if rom_addr: byte_str = f"L{bits:X}_{rom_addr:X}" else: byte_str = f"0x{bits:X}" else: byte_str = self.provided_symbols.get( bits, '0x{0:0{1}X}'.format(bits, 2 * slen)) if sym_type in ["float", "double"]: if sym_type == "float": float_str = floats.format_f32_imm(bits) else: float_str = floats.format_f64_imm(bits) # Fall back to .word if we see weird float values # todo cut the symbol in half maybe where we see the first nan or something if "e-" in float_str or "nan" in float_str: return self.disassemble_symbol(sym_bytes, "word") else: byte_str = float_str sym_str += byte_str i += adv_amt if i < len(sym_bytes): sym_str += ", " return sym_str
def disassemble_symbol(self, sym_bytes, sym_type): if sym_type == "jtbl": sym_str = ".word " else: sym_str = f".{sym_type} " if sym_type == "double": slen = 8 elif sym_type == "short": slen = 2 elif sym_type == "byte": slen = 1 else: slen = 4 if sym_type == "ascii": try: ascii_str = sym_bytes.decode("EUC-JP") # ascii_str = ascii_str.rstrip("\x00") ascii_str = ascii_str.replace("\x00", "\\0") ascii_str = ascii_str.replace("\n", "\\n") sym_str += f'"{ascii_str}"' return sym_str except: return self.disassemble_symbol(sym_bytes, "word") i = 0 while i < len(sym_bytes): adv_amt = min(slen, len(sym_bytes) - i) bits = int.from_bytes(sym_bytes[i : i + adv_amt], "big") if sym_type == "jtbl": if bits == 0: byte_str = "0" else: rom_addr = self.parent.ram_to_rom(bits) if rom_addr: byte_str = f"L{bits:X}_{rom_addr:X}" else: byte_str = f"0x{bits:X}" elif slen == 4 and bits >= 0x80000000: sym = self.parent.get_symbol(bits, reference=True) if sym: byte_str = sym.name else: byte_str = '0x{0:0{1}X}'.format(bits, 2 * slen) else: byte_str = '0x{0:0{1}X}'.format(bits, 2 * slen) if sym_type in ["float", "double"]: if sym_type == "float": float_str = floats.format_f32_imm(bits) else: float_str = floats.format_f64_imm(bits) # Fall back to .word if we see weird float values # TODO: cut the symbol in half maybe where we see the first nan or something if "e-" in float_str or "nan" in float_str: return self.disassemble_symbol(sym_bytes, "word") else: byte_str = float_str sym_str += byte_str i += adv_amt if i < len(sym_bytes): sym_str += ", " return sym_str