getprop("ro.product.device") == "curtana" || abort("E3004: This package is for \"curtana\" devices; this is a \"" + getprop("ro.product.device") + "\".");
ui_print("Source: Redmi/curtana_global/curtana:10/QKQ1.191215.002/V11.0.9.0.QJWMIXM:user/release-keys");
ui_print("Target: Redmi/curtana_global/curtana:10/QKQ1.191215.002/V11.0.10.0.QJWMIXM:user/release-keys");
ui_print("Verifying current system...");
getprop("ro.build.fingerprint") == "Redmi/curtana_global/curtana:10/QKQ1.191215.002/V11.0.9.0.QJWMIXM:user/release-keys" ||
    getprop("ro.build.fingerprint") == "Redmi/curtana_global/curtana:10/QKQ1.191215.002/V11.0.10.0.QJWMIXM:user/release-keys" ||
    abort("E3001: Package expects build fingerprint of Redmi/curtana_global/curtana:10/QKQ1.191215.002/V11.0.9.0.QJWMIXM:user/release-keys or Redmi/curtana_global/curtana:10/QKQ1.191215.002/V11.0.10.0.QJWMIXM:user/release-keys; this device has " + getprop("ro.build.fingerprint") + ".");
show_progress(0.100000, 10);
patch_partition_check("EMMC:/dev/block/bootdevice/by-name/boot:134217728:ee7aa3cf6eced500926be19821e8789616508dcb",
                      "EMMC:/dev/block/bootdevice/by-name/boot:134217728:c6f44c97a6bb9600833a8b2239b54ae775904aed") ||
    abort("E3005: \"EMMC:/dev/block/bootdevice/by-name/boot:134217728:ee7aa3cf6eced500926be19821e8789616508dcb\" or \"EMMC:/dev/block/bootdevice/by-name/boot:134217728:c6f44c97a6bb9600833a8b2239b54ae775904aed\" has unexpected contents.");
apply_patch_space(134217728) || abort("E3006: Not enough free space on /cache to apply patches.");
show_progress(0.100000, 70);
if (range_sha1(map_partition("system"), "20,1,32770,32910,98306,98446,163842,163982,229378,229518,294914,295054,399226,399253,557065,557079,575719,577496,586648,586775,586776") == "891be23105c7050fd619d99987619ece9516906d" || block_image_verify(map_partition("system"), package_extract_file("system.transfer.list"), "system.new.dat", "system.patch.dat")) then
ui_print("Verified system image...");
else
check_first_block(map_partition("system"));
ifelse (block_image_recover(map_partition("system"), "20,1,32770,32910,98306,98446,163842,163982,229378,229518,294914,295054,399226,399253,557065,557079,575719,577496,586648,586775,586776") && block_image_verify(map_partition("system"), package_extract_file("system.transfer.list"), "system.new.dat", "system.patch.dat"), ui_print("system recovered successfully."), abort("E1004: system partition fails to recover"));
endif;
if (range_sha1(map_partition("vendor"), "66,1,107,117,121,126,127,208,212,217,218,1923,1927,2405,2406,2411,2412,2675,2679,2683,2684,2686,2692,2735,2743,2747,2748,2771,2772,2808,2812,2862,2863,2875,2879,2883,2884,2887,2893,2894,2895,3218,3219,3224,3228,3241,3248,3257,3258,3831,32770,32846,98306,98382,163842,163918,229378,229454,294914,294990,295010,295011,312861,313869,318846,318921,318922") == "22eb479661ef4d74ca51864bc1184dd001a72209" || block_image_verify(map_partition("vendor"), package_extract_file("vendor.transfer.list"), "vendor.new.dat", "vendor.patch.dat")) then
ui_print("Verified vendor image...");
else
check_first_block(map_partition("vendor"));
ifelse (block_image_recover(map_partition("vendor"), "66,1,107,117,121,126,127,208,212,217,218,1923,1927,2405,2406,2411,2412,2675,2679,2683,2684,2686,2692,2735,2743,2747,2748,2771,2772,2808,2812,2862,2863,2875,2879,2883,2884,2887,2893,2894,2895,3218,3219,3224,3228,3241,3248,3257,3258,3831,32770,32846,98306,98382,163842,163918,229378,229454,294914,294990,295010,295011,312861,313869,318846,318921,318922") && block_image_verify(map_partition("vendor"), package_extract_file("vendor.transfer.list"), "vendor.new.dat", "vendor.patch.dat"), ui_print("vendor recovered successfully."), abort("E2004: vendor partition fails to recover"));
endif;
if (range_sha1(map_partition("product"), "372,1,91,5381,5382,5398,5402,5406,5407,8051,8052,9628,9629,9675,9679,11799,11802,11806,11807,11846,11847,11854,11860,11861,12577,12584,12585,12591,12597,12598,12599,12659,12663,12668,12669,15424,15425,18897,18898,21305,21306,21669,21673,22180,22181,22193,22199,22200,22201,24041,24045,25482,25483,29495,29499,32768,32770,32839,32851,33569,33570,40463,40464,40865,40866,48031,48032,56034,56035,57498,57499,65536,65548,68580,68581,70707,70708,71062,71063,71577,71578,76081,76082,80924,80925,80931,80932,80938,80944,80945,80946,81074,81080,81081,81082,81094,81100,81101,81102,81105,81106,81112,81118,81119,81120,81143,81149,81150,81151,81995,81996,95442,95443,95462,95463,97143,97145,98304,98306,98375,98387,111022,111023,111437,111438,112036,112037,118420,118421,123173,123174,125425,125426,125613,125614,125625,125631,125632,125633,125643,125644,125649,125653,125658,125659,125663,125669,125673,125674,125680,125686,125687,125688,125700,125706,125707,125708,125718,125724,125725,125726,125728,125735,125741,125742,127499,127500,127506,127507,127641,127642,128850,128857,128911,128918,128923,128930,128955,128962,128982,128989,129007,129014,129030,129031,129039,129041,129211,129212,129213,129214,129215,129216,129217,129218,129256,129258,129266,129267,129272,129273,129545,129549,129553,129557,129558,129560,129565,129569,129570,129574,129575,129579,129580,129584,129585,129589,129590,129594,129595,129599,129600,129602,129609,129613,129614,129618,129619,129623,129624,129628,129629,129631,129632,129636,129637,129641,129642,129644,129645,129649,129650,129654,129655,129659,129660,129664,129665,129669,129670,129674,129675,129679,129680,129682,129686,129690,129691,129695,129696,129700,129701,129705,129706,129708,129709,129713,129714,129716,129717,129721,129722,129724,129725,129729,129730,129734,129735,129737,129738,129742,129743,129894,130866,130867,131072,131084,134448,134449,135612,135613,140341,140342,141933,141936,144828,144830,144840,144883,152006,152008,156987,156989,156997,156999,158981,158983,163130,163131,163840,163842,163911,163925,165133,165134,166746,166748,166773,166774,166796,166798,176212,176213,176216,176217,176819,176821,177247,177249,179166,179168,179338,179339,182171,182172,185683,185685,185730,185732,185857,185859,187113,187115,188192,188194,188335,188339,188455,188457,188909,188910,191182,191183,194815,194816,196608,196677,197517,197518,202247,202248,202273,202275,202293,229378,229447,262148,262156,284316,285179,289701,289771,289772") == "3b811fe7bc3212536a5fe73a616ec1c27cf1d0b6" || block_image_verify(map_partition("product"), package_extract_file("product.transfer.list"), "product.new.dat", "product.patch.dat")) then
ui_print("Verified product image...");
else
check_first_block(map_partition("product"));
ifelse (block_image_recover(map_partition("product"), "372,1,91,5381,5382,5398,5402,5406,5407,8051,8052,9628,9629,9675,9679,11799,11802,11806,11807,11846,11847,11854,11860,11861,12577,12584,12585,12591,12597,12598,12599,12659,12663,12668,12669,15424,15425,18897,18898,21305,21306,21669,21673,22180,22181,22193,22199,22200,22201,24041,24045,25482,25483,29495,29499,32768,32770,32839,32851,33569,33570,40463,40464,40865,40866,48031,48032,56034,56035,57498,57499,65536,65548,68580,68581,70707,70708,71062,71063,71577,71578,76081,76082,80924,80925,80931,80932,80938,80944,80945,80946,81074,81080,81081,81082,81094,81100,81101,81102,81105,81106,81112,81118,81119,81120,81143,81149,81150,81151,81995,81996,95442,95443,95462,95463,97143,97145,98304,98306,98375,98387,111022,111023,111437,111438,112036,112037,118420,118421,123173,123174,125425,125426,125613,125614,125625,125631,125632,125633,125643,125644,125649,125653,125658,125659,125663,125669,125673,125674,125680,125686,125687,125688,125700,125706,125707,125708,125718,125724,125725,125726,125728,125735,125741,125742,127499,127500,127506,127507,127641,127642,128850,128857,128911,128918,128923,128930,128955,128962,128982,128989,129007,129014,129030,129031,129039,129041,129211,129212,129213,129214,129215,129216,129217,129218,129256,129258,129266,129267,129272,129273,129545,129549,129553,129557,129558,129560,129565,129569,129570,129574,129575,129579,129580,129584,129585,129589,129590,129594,129595,129599,129600,129602,129609,129613,129614,129618,129619,129623,129624,129628,129629,129631,129632,129636,129637,129641,129642,129644,129645,129649,129650,129654,129655,129659,129660,129664,129665,129669,129670,129674,129675,129679,129680,129682,129686,129690,129691,129695,129696,129700,129701,129705,129706,129708,129709,129713,129714,129716,129717,129721,129722,129724,129725,129729,129730,129734,129735,129737,129738,129742,129743,129894,130866,130867,131072,131084,134448,134449,135612,135613,140341,140342,141933,141936,144828,144830,144840,144883,152006,152008,156987,156989,156997,156999,158981,158983,163130,163131,163840,163842,163911,163925,165133,165134,166746,166748,166773,166774,166796,166798,176212,176213,176216,176217,176819,176821,177247,177249,179166,179168,179338,179339,182171,182172,185683,185685,185730,185732,185857,185859,187113,187115,188192,188194,188335,188339,188455,188457,188909,188910,191182,191183,194815,194816,196608,196677,197517,197518,202247,202248,202273,202275,202293,229378,229447,262148,262156,284316,285179,289701,289771,289772") && block_image_verify(map_partition("product"), package_extract_file("product.transfer.list"), "product.new.dat", "product.patch.dat"), ui_print("product recovered successfully."), abort("E2004: product partition fails to recover"));
endif;

# ---- start making changes here ----

ui_print("Patching boot image...");
show_progress(0.100000, 10);
patch_partition("EMMC:/dev/block/bootdevice/by-name/boot:134217728:ee7aa3cf6eced500926be19821e8789616508dcb",
                "EMMC:/dev/block/bootdevice/by-name/boot:134217728:c6f44c97a6bb9600833a8b2239b54ae775904aed",
                package_extract_file("boot.img.p")) ||
    abort("E3008: Failed to apply patch to EMMC:/dev/block/bootdevice/by-name/boot:134217728:c6f44c97a6bb9600833a8b2239b54ae775904aed");

# ---- radio update tasks ----

ui_print("Patching firmware images...");
package_extract_file("firmware-update/cmnlib64.mbn", "/dev/block/bootdevice/by-name/cmnlib64");
package_extract_file("firmware-update/imagefv.elf", "/dev/block/bootdevice/by-name/imagefv");
package_extract_file("firmware-update/cmnlib.mbn", "/dev/block/bootdevice/by-name/cmnlib");
package_extract_file("firmware-update/hyp.mbn", "/dev/block/bootdevice/by-name/hyp");
package_extract_file("firmware-update/BTFM.bin", "/dev/block/bootdevice/by-name/bluetooth");
package_extract_file("firmware-update/tz.mbn", "/dev/block/bootdevice/by-name/tz");
package_extract_file("firmware-update/aop.mbn", "/dev/block/bootdevice/by-name/aop");
package_extract_file("firmware-update/xbl_config.elf", "/dev/block/bootdevice/by-name/xbl_config");
package_extract_file("firmware-update/storsec.mbn", "/dev/block/bootdevice/by-name/storsec");
package_extract_file("firmware-update/uefi_sec.mbn", "/dev/block/bootdevice/by-name/uefisecapp");
package_extract_file("firmware-update/NON-HLOS.bin", "/dev/block/bootdevice/by-name/modem");
package_extract_file("firmware-update/qupv3fw.elf", "/dev/block/bootdevice/by-name/qupfw");
package_extract_file("firmware-update/abl.elf", "/dev/block/bootdevice/by-name/abl");
package_extract_file("firmware-update/devcfg.mbn", "/dev/block/bootdevice/by-name/devcfg");
package_extract_file("firmware-update/xbl.elf", "/dev/block/bootdevice/by-name/xbl");
package_extract_file("firmware-update/km4.mbn", "/dev/block/bootdevice/by-name/keymaster");
package_extract_file("firmware-update/cmnlib64.mbn", "/dev/block/bootdevice/by-name/cmnlib64bak");
package_extract_file("firmware-update/imagefv.elf", "/dev/block/bootdevice/by-name/imagefvbak");
package_extract_file("firmware-update/cmnlib.mbn", "/dev/block/bootdevice/by-name/cmnlibbak");
package_extract_file("firmware-update/hyp.mbn", "/dev/block/bootdevice/by-name/hypbak");
package_extract_file("firmware-update/tz.mbn", "/dev/block/bootdevice/by-name/tzbak");
package_extract_file("firmware-update/aop.mbn", "/dev/block/bootdevice/by-name/aopbak");
package_extract_file("firmware-update/xbl_config.elf", "/dev/block/bootdevice/by-name/xbl_configbak");
package_extract_file("firmware-update/uefi_sec.mbn", "/dev/block/bootdevice/by-name/uefisecappbak");
package_extract_file("firmware-update/qupv3fw.elf", "/dev/block/bootdevice/by-name/qupfwbak");
package_extract_file("firmware-update/abl.elf", "/dev/block/bootdevice/by-name/ablbak");
package_extract_file("firmware-update/devcfg.mbn", "/dev/block/bootdevice/by-name/devcfgbak");
package_extract_file("firmware-update/xbl.elf", "/dev/block/bootdevice/by-name/xblbak");
package_extract_file("firmware-update/km4.mbn", "/dev/block/bootdevice/by-name/keymasterbak");
show_progress(0.600000, 600);

# --- Start patching dynamic partitions ---


# Patch partition product

ui_print("Patching product image after verification.");
block_image_update(map_partition("product"), package_extract_file("product.transfer.list"), "product.new.dat", "product.patch.dat") ||
  abort("E2001: Failed to update product image.");

# Update dynamic partition metadata

assert(update_dynamic_partitions(package_extract_file("dynamic_partitions_op_list")));

# Patch partition vendor

ui_print("Patching vendor image after verification.");
block_image_update(map_partition("vendor"), package_extract_file("vendor.transfer.list"), "vendor.new.dat", "vendor.patch.dat") ||
  abort("E2001: Failed to update vendor image.");

# Patch partition system

ui_print("Patching system image after verification.");
block_image_update(map_partition("system"), package_extract_file("system.transfer.list"), "system.new.dat", "system.patch.dat") ||
  abort("E1001: Failed to update system image.");

# --- End patching dynamic partitions ---

show_progress(0.100000, 2);

# ---- radio update tasks 2 ----

ui_print("Patching vbmeta dtbo logo binimages...");
package_extract_file("firmware-update/vbmeta_system.img", "/dev/block/bootdevice/by-name/vbmeta_system");
package_extract_file("firmware-update/dtbo.img", "/dev/block/bootdevice/by-name/dtbo");
package_extract_file("firmware-update/vbmeta.img", "/dev/block/bootdevice/by-name/vbmeta");
