Exemple #1
0
def main():
    parser = argparse.ArgumentParser(
        description="Apply IPS patch to ROM image")
    parser.add_argument("image_file")
    parser.add_argument("patch_file")

    args = parser.parse_args()

    try:
        image = open(args.image_file, 'rb+')
    except Exception as err:
        print(f"Error opening {args.image_file}: {err}")
        exit()

    try:
        patch = open(args.patch_file, 'rb')
    except Exception as err:
        print(f"Error opening {args.patch_file}: {err}")
        exit()

    try:
        for patch_line in ips.read_patch(patch):
            ips.apply_patch_line(image, patch_line)
    except Exception as err:
        print(f"Error patching {args.image_file}: {err}")
    finally:
        patch.close()
        image.close()
Exemple #2
0
    def patch_ips(self, widget):
        romfile = self.rom_textEntry.get_text()
        ipsfile = self.ips_textEntry.get_text()

        if self.backupCheckBox.get_active():
            try:
                os.rename(romfile, romfile + ".bak")
                shutil.copyfile(romfile + ".bak", romfile)
            except Exception:
                self.error_message("Can't create a backup file!")
                return

        try:
            with open(romfile, "rb+") as rom, open(ipsfile, "rb") as patch:
                patchsize = os.path.getsize(ipsfile)
                for patch_line in ips.read_patch(patch):
                    ips.apply_patch_line(rom, patch_line)
                    self.update_progress((patch.tell() * 100) / patchsize)

                self.progressbar.set_text("Done!")
        except Exception as err:
            self.error_message(f"Error: {err}")
    def test_apply_patch(self):
        with open(out_file, 'rb+') as out, open(patch_file, 'rb') as patch:
            for patch_line in ips.read_patch(patch):
                ips.apply_patch_line(out, patch_line)

        self.assertEqual(crc(out_file), out_crc)