(1) we need a binary file and use symbols(Ericconfig_Bin) to token the address in the binary file, maybe need some assembly knowledge to understand the following codes.
.align 8 // I will analyze this later .global Ericonfig_Bin //define a global variable Ericonfig_Bin: .word 0x98765432 // define a identification token which used to verify the address in the binary .ascii "star" // "star" code (0x72617473); define a identification token which used to verify the address in the binary .rept ( 0x80 - 2 ) // define a space initiated to zero .word 0x0 .endr(2) write the specific value into the specific address
def read32(buf, addr): return struct.unpack('I', buffer(buf[addr:addr+4]))[0] def write32(buf, addr, value, mask=(~0x0)): data = read32(buf, address) data &= ~mask value &= mask data |= value buf[addr:addr+4] = array.array('B', struct.pack('I', data)) ##find and modify.... with open(file_path, 'rb') as f: if platform.system() == 'Linux' or sys.platform != 'cli': binary_start = bytearray(f.read()) else: binary_start = bytearray(f.read(), encoding='latin-1') f_length = os.path.getsize(file_path) row = ["1","0", "1", "0"] addr = 0 addr_end = addr + f_length - 0x4 while (addr < addr_end) and ((read32(binary_start, addr) != 0x98765432) or (read32(binary_start, addr+4) != 0x72617473)): addr += 0x100 write32(binary_start, addr, int(row[0],16))