def write_address(address, value_index, value): if not type(address) == int: try: address = int(address, 16) except: print(str(address) + " is not a valid address") return write_data = SysUtils.parse_string(value, value_index) if write_data is None: return encoding, option = type_defs.string_index_to_encoding_dict.get( value_index, (None, None)) if encoding is None: if value_index is type_defs.VALUE_INDEX.INDEX_AOB: write_data = bytearray(write_data) else: data_type = type_defs.index_to_struct_pack_dict.get( value_index, -1) write_data = struct.pack(data_type, write_data) else: write_data = write_data.encode(encoding, option) FILE = open(mem_file, "rb+") try: FILE.seek(address) FILE.write(write_data) FILE.close() except (OSError, ValueError): print("Can't access the memory at address " + hex(address) + " or offset " + hex(address + len(write_data)))
def set_single_address(address, value_index, value): if not type(address) == int: try: address = int(address, 16) except: print(str(address) + " is not a valid address") return write_data = SysUtils.parse_string(value, value_index) if write_data is None: return encoding, option = type_defs.string_index_to_encoding_dict.get( value_index, (None, None)) if encoding is None: if value_index is type_defs.VALUE_INDEX.INDEX_AOB: write_data = bytearray(write_data) else: data_type = type_defs.index_to_struct_pack_dict.get( value_index, -1) write_data = struct.pack(data_type, write_data) else: write_data = bytearray(write_data, encoding, option) FILE = open(mem_file, "rb+") # Check SetMultipleAddresses class in GDBCommandExtensions.py to see why we moved away the try/except block FILE.seek(address) FILE.write(write_data) FILE.close()
def set_single_address(address, value_index, value): try: address = int(address, 16) except: print(str(address) + " is not a valid address") return write_data = SysUtils.parse_string(value, value_index) if write_data is None: return if value_index is INDEX_STRING: write_data = bytearray(write_data, "utf-8", "replace") elif value_index is INDEX_AOB: write_data = bytearray(write_data) else: data_type = index_to_struct_pack_dict.get(value_index, -1) write_data = struct.pack(data_type, write_data) FILE = open(mem_file, "rb+") # Check SetMultipleAddresses class in GDBCommandExtensions.py to see why we moved away the try/except block FILE.seek(address) FILE.write(write_data) FILE.close()