getprop("ro.product.device") == "surya" || abort("E3004: This package is for \"surya\" devices; this is a \"" + getprop("ro.product.device") + "\".");
ui_print("Source: POCO/surya_ru/surya:10/QKQ1.200512.002/V12.0.5.0.QJGRUXM:user/release-keys");
ui_print("Target: POCO/surya_ru/surya:10/QKQ1.200512.002/V12.0.6.0.QJGRUXM:user/release-keys");
ui_print("Verifying current system...");
getprop("ro.build.fingerprint") == "POCO/surya_ru/surya:10/QKQ1.200512.002/V12.0.5.0.QJGRUXM:user/release-keys" ||
    getprop("ro.build.fingerprint") == "POCO/surya_ru/surya:10/QKQ1.200512.002/V12.0.6.0.QJGRUXM:user/release-keys" ||
    abort("E3001: Package expects build fingerprint of POCO/surya_ru/surya:10/QKQ1.200512.002/V12.0.5.0.QJGRUXM:user/release-keys or POCO/surya_ru/surya:10/QKQ1.200512.002/V12.0.6.0.QJGRUXM: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:2b0ee54f8fc4801b0db68083e9d0cf3089dbe316",
                      "EMMC:/dev/block/bootdevice/by-name/boot:134217728:74b9f8b3f19445c93eb062cd8615407a9fb91303") ||
    abort("E3005: \"EMMC:/dev/block/bootdevice/by-name/boot:134217728:2b0ee54f8fc4801b0db68083e9d0cf3089dbe316\" or \"EMMC:/dev/block/bootdevice/by-name/boot:134217728:74b9f8b3f19445c93eb062cd8615407a9fb91303\" 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"), "1030,1,198,225,234,287,288,548,552,564,565,584,585,1896,2326,2332,2333,26237,26238,27605,27606,32768,32770,32932,32952,33017,33018,33232,33234,33394,33398,33406,33407,33415,33419,33424,33425,33645,33646,33658,33662,33666,34910,34914,34915,34925,34935,34941,34947,34948,34949,34954,34960,34961,34962,35082,35088,35094,35095,36651,36652,36717,36718,37243,37247,37276,37277,37347,37349,37442,37446,37450,37451,37482,37488,37489,37490,37589,37595,37596,38964,41756,41760,41788,41789,41803,41809,41810,41811,41813,41814,45062,45066,45111,45112,45482,45486,45494,45495,45582,45588,45593,45594,45722,45726,45732,45733,45995,45996,46188,46192,46207,46208,50825,50829,50923,50924,50929,50935,50936,50937,51624,51628,51650,51651,51709,51710,51781,51785,51789,51790,53073,53077,53102,53103,53574,53580,53581,53582,55344,55348,55391,55392,55396,55402,55403,55404,55426,55430,55454,55455,57147,57151,57175,57176,58022,58026,58049,58050,58133,58137,58142,58143,61450,61452,65238,65239,65536,65556,66204,66205,66829,66833,68995,68996,69315,69319,69332,69333,69365,69369,69385,69386,69391,69392,69842,69846,70249,70250,70933,70937,70953,70954,73339,73343,73390,73391,73787,73791,73804,73805,75605,75606,81141,81145,81228,81229,82156,82160,82185,82186,84246,84247,86843,86844,89233,89237,89355,89356,98304,98306,98468,98488,102048,102052,102075,102076,104469,104473,104523,104524,106279,106283,106317,106318,106356,106362,106366,106367,109708,109709,110245,110249,110287,110288,112898,112899,114100,114104,114127,114128,114492,114498,114512,114513,115628,115632,115658,115659,115672,115678,115679,115680,131072,131092,136321,136322,136794,136795,137667,137671,137901,137902,138290,138296,138310,138311,138321,138325,138332,138333,143084,143085,145920,145924,146007,146008,148567,148571,148611,148612,148663,148667,148671,148672,148675,148681,148685,148686,148691,148697,148698,148699,152572,152576,152643,152644,152728,152732,152737,152738,152740,152746,152747,152748,152792,152798,152799,152800,154610,154616,154658,154659,155059,155065,155075,155076,155272,155276,155280,155281,155284,155288,155292,155293,155948,155954,155977,155978,156387,156391,156401,156402,156439,156445,156446,156447,159522,159526,159565,159566,159858,159862,159871,159872,159942,159946,159950,159951,160688,160692,160710,160711,160814,160818,160823,160824,162040,162044,162070,162071,163840,163842,164004,164024,167008,167084,167086,167087,168847,168851,168972,168973,168981,168987,168988,168989,169615,169619,169634,169635,171123,171127,171142,171143,173470,173474,173501,173502,174395,174399,174425,174426,174430,174436,174437,174438,174460,174466,174467,174468,174472,174476,174479,174480,174484,174485,174509,174515,174516,174517,177580,177584,177632,177633,177918,177922,177931,177932,178290,178296,178305,178306,179790,179794,179822,179823,180800,180804,181738,181739,183947,183951,183991,183994,184018,184019,184021,184022,184023,184024,184025,184026,184056,184057,186531,186535,186549,186550,187070,187074,187081,187082,189704,189709,189725,189726,190061,190062,190290,190291,191232,191241,191569,191570,192006,192007,192801,192912,193727,193728,194595,194634,195164,195216,196518,196523,196524,196525,196526,196527,196528,196529,196530,196531,196532,196533,196534,196535,196536,196537,196538,196539,196540,196541,196542,196543,196544,196545,196546,196547,196548,196549,196550,196551,196552,196553,196554,196555,196556,196557,196558,196559,196560,196561,196562,196563,196564,196565,196566,196567,196568,196569,196570,196571,196572,196573,196574,196575,196576,196577,196578,196579,196580,196581,196582,196583,196584,196585,196586,196587,196588,196589,196590,196591,196592,196593,196594,196595,196596,196597,196598,196599,196600,196601,196602,196603,196604,196605,196606,196607,196608,196629,196630,196631,196632,196633,196634,196635,196636,196637,196638,196639,196640,196641,196642,196643,196644,196645,196646,196647,196648,196649,196650,196651,196652,196653,196654,196655,196656,196657,196658,196659,196660,196661,196662,196663,196664,196665,196666,196667,196668,196669,196670,196671,196672,196673,196674,196675,196676,196677,196678,196679,196680,196681,196682,196683,196684,196685,196686,196687,196688,196689,196690,196691,196692,196693,196694,196695,196696,196697,196698,196699,196700,196701,196702,196703,196704,196705,196706,196707,196708,196709,196710,196711,196712,196713,196714,196715,196716,196717,196718,196719,196720,196721,196722,196723,196724,196725,196726,196727,196728,196729,196730,196731,196732,196733,196734,196735,196736,196737,196738,196739,196740,196741,196742,196743,196744,196745,196746,196747,196748,196749,196750,196751,196752,196753,196754,196755,196756,196757,196758,196759,196760,196761,196762,196763,196764,196765,196766,196767,196768,196769,196770,196771,196772,196773,196774,196775,196776,196777,196778,196779,196780,196781,196782,196783,196784,196785,196786,196787,196788,196789,196790,196791,196792,196793,196794,196795,196796,196797,196798,196799,196800,196801,196802,196803,196804,196805,196806,196807,196808,196809,196810,196811,196812,196813,196814,196815,196816,196817,196818,196819,196820,196821,196822,196823,196824,196825,196826,196827,196828,196829,196830,196831,196832,196833,196834,196835,196836,196837,196838,196839,196840,196841,196842,196843,196844,196845,196846,196847,196848,196849,196850,196851,196852,196853,196854,196855,196856,196857,196858,196859,196860,196861,196862,196863,196864,196865,196866,196867,196868,196869,196870,196871,196872,196873,196874,196875,196876,196877,196878,196879,196880,196881,196882,196883,196884,196885,196886,196887,196888,196889,196890,196891,196892,196893,196894,196895,196896,196897,196898,196899,196900,196901,196902,196903,196904,196905,196906,196907,196908,196909,196910,196911,196912,196913,196914,196915,196916,196917,196918,196919,196920,196921,196922,196923,196924,196925,196926,196927,196928,196929,196930,196931,196932,196933,196934,196935,196936,196937,196938,196939,196940,196941,196942,196943,196944,196945,196946,196947,196948,196949,196950,196951,196952,196953,196954,196955,196956,196957,196958,196959,196960,196961,196962,196963,196964,196965,196966,196967,196968,196969,196970,196971,196972,196973,196974,196975,196976,196977,196978,196979,196980,196981,196982,196983,196984,196985,196986,196988,196994,196995,197291,197292,197304,197305,197315,197318,197319,197320,197321,197322,197324,197325,197358,197359,197364,197365,197453,197456,197458,197459,198566,198567,198786,198788,198811,198812,198881,198882,198885,198890,198891,198892,198893,198894,198895,198896,199826,199827,199834,199835,200388,200392,200393,200394,200395,200396,200397,200398,200399,200400,200401,200402,200403,200404,200406,200407,200408,200411,201178,201180,201181,201182,201266,201267,201269,201270,201273,201275,221994,222083,223269,223525,224847,229378,229540,239226,239451,239492,239499,241671,244268,244363,244424,244425,245758,246072,247637,294914,295076,622609,622612,655361,655380,664326,666360,676919,677064,677065") == "a415015eb4b818f7671aabeeb8d94e01eadf9bde" || 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"), "1030,1,198,225,234,287,288,548,552,564,565,584,585,1896,2326,2332,2333,26237,26238,27605,27606,32768,32770,32932,32952,33017,33018,33232,33234,33394,33398,33406,33407,33415,33419,33424,33425,33645,33646,33658,33662,33666,34910,34914,34915,34925,34935,34941,34947,34948,34949,34954,34960,34961,34962,35082,35088,35094,35095,36651,36652,36717,36718,37243,37247,37276,37277,37347,37349,37442,37446,37450,37451,37482,37488,37489,37490,37589,37595,37596,38964,41756,41760,41788,41789,41803,41809,41810,41811,41813,41814,45062,45066,45111,45112,45482,45486,45494,45495,45582,45588,45593,45594,45722,45726,45732,45733,45995,45996,46188,46192,46207,46208,50825,50829,50923,50924,50929,50935,50936,50937,51624,51628,51650,51651,51709,51710,51781,51785,51789,51790,53073,53077,53102,53103,53574,53580,53581,53582,55344,55348,55391,55392,55396,55402,55403,55404,55426,55430,55454,55455,57147,57151,57175,57176,58022,58026,58049,58050,58133,58137,58142,58143,61450,61452,65238,65239,65536,65556,66204,66205,66829,66833,68995,68996,69315,69319,69332,69333,69365,69369,69385,69386,69391,69392,69842,69846,70249,70250,70933,70937,70953,70954,73339,73343,73390,73391,73787,73791,73804,73805,75605,75606,81141,81145,81228,81229,82156,82160,82185,82186,84246,84247,86843,86844,89233,89237,89355,89356,98304,98306,98468,98488,102048,102052,102075,102076,104469,104473,104523,104524,106279,106283,106317,106318,106356,106362,106366,106367,109708,109709,110245,110249,110287,110288,112898,112899,114100,114104,114127,114128,114492,114498,114512,114513,115628,115632,115658,115659,115672,115678,115679,115680,131072,131092,136321,136322,136794,136795,137667,137671,137901,137902,138290,138296,138310,138311,138321,138325,138332,138333,143084,143085,145920,145924,146007,146008,148567,148571,148611,148612,148663,148667,148671,148672,148675,148681,148685,148686,148691,148697,148698,148699,152572,152576,152643,152644,152728,152732,152737,152738,152740,152746,152747,152748,152792,152798,152799,152800,154610,154616,154658,154659,155059,155065,155075,155076,155272,155276,155280,155281,155284,155288,155292,155293,155948,155954,155977,155978,156387,156391,156401,156402,156439,156445,156446,156447,159522,159526,159565,159566,159858,159862,159871,159872,159942,159946,159950,159951,160688,160692,160710,160711,160814,160818,160823,160824,162040,162044,162070,162071,163840,163842,164004,164024,167008,167084,167086,167087,168847,168851,168972,168973,168981,168987,168988,168989,169615,169619,169634,169635,171123,171127,171142,171143,173470,173474,173501,173502,174395,174399,174425,174426,174430,174436,174437,174438,174460,174466,174467,174468,174472,174476,174479,174480,174484,174485,174509,174515,174516,174517,177580,177584,177632,177633,177918,177922,177931,177932,178290,178296,178305,178306,179790,179794,179822,179823,180800,180804,181738,181739,183947,183951,183991,183994,184018,184019,184021,184022,184023,184024,184025,184026,184056,184057,186531,186535,186549,186550,187070,187074,187081,187082,189704,189709,189725,189726,190061,190062,190290,190291,191232,191241,191569,191570,192006,192007,192801,192912,193727,193728,194595,194634,195164,195216,196518,196523,196524,196525,196526,196527,196528,196529,196530,196531,196532,196533,196534,196535,196536,196537,196538,196539,196540,196541,196542,196543,196544,196545,196546,196547,196548,196549,196550,196551,196552,196553,196554,196555,196556,196557,196558,196559,196560,196561,196562,196563,196564,196565,196566,196567,196568,196569,196570,196571,196572,196573,196574,196575,196576,196577,196578,196579,196580,196581,196582,196583,196584,196585,196586,196587,196588,196589,196590,196591,196592,196593,196594,196595,196596,196597,196598,196599,196600,196601,196602,196603,196604,196605,196606,196607,196608,196629,196630,196631,196632,196633,196634,196635,196636,196637,196638,196639,196640,196641,196642,196643,196644,196645,196646,196647,196648,196649,196650,196651,196652,196653,196654,196655,196656,196657,196658,196659,196660,196661,196662,196663,196664,196665,196666,196667,196668,196669,196670,196671,196672,196673,196674,196675,196676,196677,196678,196679,196680,196681,196682,196683,196684,196685,196686,196687,196688,196689,196690,196691,196692,196693,196694,196695,196696,196697,196698,196699,196700,196701,196702,196703,196704,196705,196706,196707,196708,196709,196710,196711,196712,196713,196714,196715,196716,196717,196718,196719,196720,196721,196722,196723,196724,196725,196726,196727,196728,196729,196730,196731,196732,196733,196734,196735,196736,196737,196738,196739,196740,196741,196742,196743,196744,196745,196746,196747,196748,196749,196750,196751,196752,196753,196754,196755,196756,196757,196758,196759,196760,196761,196762,196763,196764,196765,196766,196767,196768,196769,196770,196771,196772,196773,196774,196775,196776,196777,196778,196779,196780,196781,196782,196783,196784,196785,196786,196787,196788,196789,196790,196791,196792,196793,196794,196795,196796,196797,196798,196799,196800,196801,196802,196803,196804,196805,196806,196807,196808,196809,196810,196811,196812,196813,196814,196815,196816,196817,196818,196819,196820,196821,196822,196823,196824,196825,196826,196827,196828,196829,196830,196831,196832,196833,196834,196835,196836,196837,196838,196839,196840,196841,196842,196843,196844,196845,196846,196847,196848,196849,196850,196851,196852,196853,196854,196855,196856,196857,196858,196859,196860,196861,196862,196863,196864,196865,196866,196867,196868,196869,196870,196871,196872,196873,196874,196875,196876,196877,196878,196879,196880,196881,196882,196883,196884,196885,196886,196887,196888,196889,196890,196891,196892,196893,196894,196895,196896,196897,196898,196899,196900,196901,196902,196903,196904,196905,196906,196907,196908,196909,196910,196911,196912,196913,196914,196915,196916,196917,196918,196919,196920,196921,196922,196923,196924,196925,196926,196927,196928,196929,196930,196931,196932,196933,196934,196935,196936,196937,196938,196939,196940,196941,196942,196943,196944,196945,196946,196947,196948,196949,196950,196951,196952,196953,196954,196955,196956,196957,196958,196959,196960,196961,196962,196963,196964,196965,196966,196967,196968,196969,196970,196971,196972,196973,196974,196975,196976,196977,196978,196979,196980,196981,196982,196983,196984,196985,196986,196988,196994,196995,197291,197292,197304,197305,197315,197318,197319,197320,197321,197322,197324,197325,197358,197359,197364,197365,197453,197456,197458,197459,198566,198567,198786,198788,198811,198812,198881,198882,198885,198890,198891,198892,198893,198894,198895,198896,199826,199827,199834,199835,200388,200392,200393,200394,200395,200396,200397,200398,200399,200400,200401,200402,200403,200404,200406,200407,200408,200411,201178,201180,201181,201182,201266,201267,201269,201270,201273,201275,221994,222083,223269,223525,224847,229378,229540,239226,239451,239492,239499,241671,244268,244363,244424,244425,245758,246072,247637,294914,295076,622609,622612,655361,655380,664326,666360,676919,677064,677065") && 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"), "402,1,100,110,114,119,120,201,205,210,211,216,217,480,484,488,489,491,492,494,505,517,521,525,526,529,535,536,537,545,549,553,554,1096,1146,1165,1502,1579,1580,2701,3424,12263,12264,12441,12492,12917,12918,12922,12924,12943,12944,12948,12949,12954,12955,12956,12957,12960,12961,12962,12963,12966,12967,12968,12969,12972,12973,12974,12975,12978,12979,12980,12981,12984,12985,12986,12987,12991,12992,12997,12998,13002,13003,13007,13008,13012,13013,13486,13487,14391,14397,25648,25649,25931,25932,28740,28741,32768,32770,32837,32874,33991,33992,34830,34831,34835,34837,34854,34855,34890,34891,34900,34901,34903,34904,34956,34957,35007,35008,35014,35015,35040,35041,35191,35192,35590,35591,35593,35595,35659,35660,35730,35731,35798,35799,35801,35802,35804,35805,35864,35866,35868,35869,35933,35934,36004,36005,36072,36073,36075,36076,36078,36081,36082,36083,36145,36146,36212,36213,36215,36216,36219,36223,36225,36226,36228,36230,36291,36292,36294,36296,36356,36357,36359,36360,36421,36422,36424,36425,36485,36486,36488,36489,36556,36557,36625,36626,36693,36694,36760,36761,36763,36764,36827,36828,36894,36895,36897,36898,36959,36960,36962,36963,37027,37028,37030,37031,37093,37094,37096,37097,37161,37162,37164,37165,37226,37227,37229,37230,37294,37295,37297,37298,37362,37363,37365,37366,37430,37431,37433,37434,37498,37499,37501,37502,37569,37570,37571,37572,37638,37639,37640,37641,37646,37647,37707,37708,37774,37775,37777,37778,37841,37842,37908,37909,37911,37912,37973,37974,37976,37977,38041,38042,38044,38045,38107,38108,38110,38111,38175,38176,38178,38179,38240,38241,38243,38244,38308,38309,38311,38312,38376,38377,38379,38380,38444,38445,38447,38448,38512,38513,38515,38516,38583,38584,38585,38586,38652,38653,38654,38655,38720,38721,38793,38794,38796,38797,38859,38860,38930,38931,38939,38943,38944,38945,39144,39145,39211,39212,39214,39215,39218,39223,46643,46644,46808,46809,47118,47119,47180,47181,47330,47331,47410,47411,47443,47444,47520,47521,47588,47589,47661,47662,47754,47755,47827,47828,47873,47874,47978,47979,48022,48023,48025,48026,48058,48059,48220,48221,48292,48293,48345,48346,48670,48671,48673,48674,48768,48769,48893,48894,48968,48969,49002,49003,49066,49067,49138,49139,49689,49691,49696,49698,49766,49767,49819,49820,50347,50348,50633,98306,98373,163842,163909,229378,229445,262165,262167,276477,277473,281872,281942,281943") == "8006b37a839413eadc01a67b90a3da6883c18f7a" || 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"), "402,1,100,110,114,119,120,201,205,210,211,216,217,480,484,488,489,491,492,494,505,517,521,525,526,529,535,536,537,545,549,553,554,1096,1146,1165,1502,1579,1580,2701,3424,12263,12264,12441,12492,12917,12918,12922,12924,12943,12944,12948,12949,12954,12955,12956,12957,12960,12961,12962,12963,12966,12967,12968,12969,12972,12973,12974,12975,12978,12979,12980,12981,12984,12985,12986,12987,12991,12992,12997,12998,13002,13003,13007,13008,13012,13013,13486,13487,14391,14397,25648,25649,25931,25932,28740,28741,32768,32770,32837,32874,33991,33992,34830,34831,34835,34837,34854,34855,34890,34891,34900,34901,34903,34904,34956,34957,35007,35008,35014,35015,35040,35041,35191,35192,35590,35591,35593,35595,35659,35660,35730,35731,35798,35799,35801,35802,35804,35805,35864,35866,35868,35869,35933,35934,36004,36005,36072,36073,36075,36076,36078,36081,36082,36083,36145,36146,36212,36213,36215,36216,36219,36223,36225,36226,36228,36230,36291,36292,36294,36296,36356,36357,36359,36360,36421,36422,36424,36425,36485,36486,36488,36489,36556,36557,36625,36626,36693,36694,36760,36761,36763,36764,36827,36828,36894,36895,36897,36898,36959,36960,36962,36963,37027,37028,37030,37031,37093,37094,37096,37097,37161,37162,37164,37165,37226,37227,37229,37230,37294,37295,37297,37298,37362,37363,37365,37366,37430,37431,37433,37434,37498,37499,37501,37502,37569,37570,37571,37572,37638,37639,37640,37641,37646,37647,37707,37708,37774,37775,37777,37778,37841,37842,37908,37909,37911,37912,37973,37974,37976,37977,38041,38042,38044,38045,38107,38108,38110,38111,38175,38176,38178,38179,38240,38241,38243,38244,38308,38309,38311,38312,38376,38377,38379,38380,38444,38445,38447,38448,38512,38513,38515,38516,38583,38584,38585,38586,38652,38653,38654,38655,38720,38721,38793,38794,38796,38797,38859,38860,38930,38931,38939,38943,38944,38945,39144,39145,39211,39212,39214,39215,39218,39223,46643,46644,46808,46809,47118,47119,47180,47181,47330,47331,47410,47411,47443,47444,47520,47521,47588,47589,47661,47662,47754,47755,47827,47828,47873,47874,47978,47979,48022,48023,48025,48026,48058,48059,48220,48221,48292,48293,48345,48346,48670,48671,48673,48674,48768,48769,48893,48894,48968,48969,49002,49003,49066,49067,49138,49139,49689,49691,49696,49698,49766,49767,49819,49820,50347,50348,50633,98306,98373,163842,163909,229378,229445,262165,262167,276477,277473,281872,281942,281943") && 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"), "382,1,90,106,110,114,115,4451,4455,5930,5931,6595,6598,6602,6603,6644,6645,6652,6658,6659,6660,7377,7381,7388,7389,7395,7401,7402,7403,7463,7467,7472,7473,10228,10229,13701,13702,14340,14344,15114,15115,17522,17523,17886,17890,18397,18398,18410,18416,18417,18418,25311,25312,25713,25714,32768,32770,32839,32850,32953,32954,40964,40965,42428,42429,53498,53499,55757,55758,56134,56135,56213,56215,59583,59585,65536,65547,67076,67077,67083,67084,67086,67087,67093,67099,67100,67101,67229,67235,67236,67237,67249,67255,67256,67257,67260,67261,67267,67273,67274,67275,67298,67304,67305,67306,68150,68151,81849,81850,81869,81870,83836,83837,97655,97656,97832,97833,98200,98201,98304,98306,98375,98386,99034,99035,105418,105419,110171,110172,112423,112424,112611,112612,112623,112629,112630,112631,112641,112642,112647,112651,112656,112657,112661,112667,112671,112672,112678,112684,112685,112686,112698,112704,112705,112706,112716,112722,112723,112724,112726,112733,112739,112740,114497,114498,114504,114505,114639,114640,115848,115855,115909,115916,115921,115928,115953,115960,115979,115986,116004,116011,116027,116028,116039,116041,116210,116211,116212,116213,116214,116215,116216,116217,116254,116256,116264,116265,116270,116271,116609,116613,116617,116621,116622,116624,116629,116633,116634,116638,116639,116643,116644,116648,116649,116653,116654,116658,116659,116663,116664,116666,116673,116677,116678,116682,116683,116687,116688,116692,116693,116695,116696,116700,116701,116705,116706,116708,116709,116713,116714,116718,116719,116723,116724,116728,116729,116733,116734,116738,116739,116743,116744,116748,116749,116751,116755,116759,116760,116764,116765,116769,116770,116774,116775,116777,116778,116782,116783,116785,116786,116790,116791,116793,116794,116798,116799,116803,116804,116806,116807,116811,116812,116967,117994,117995,121599,121600,131072,131085,132338,132340,132350,132395,139267,139269,144618,144620,148552,148553,152602,152604,154134,154136,154362,154363,156053,156063,159573,159574,163840,163842,163911,163926,164370,164371,164373,164374,164977,164979,167238,167241,170290,170291,174327,174329,174374,174376,174516,174518,175774,175776,176853,176855,177315,177316,178943,178944,179588,179589,183221,183222,185854,185855,190606,190607,190632,190634,196608,196621,196622,196623,207625,207632,207663,207664,207665,207669,207785,207786,207959,207960,208254,208261,208292,208293,208859,208860,208993,208994,210240,210241,210815,210816,210894,210895,211668,229378,229447,283143,284012,288515,288585,288586") == "f8e2ea664a212615427a482723e47fbb2d1189c6" || 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"), "382,1,90,106,110,114,115,4451,4455,5930,5931,6595,6598,6602,6603,6644,6645,6652,6658,6659,6660,7377,7381,7388,7389,7395,7401,7402,7403,7463,7467,7472,7473,10228,10229,13701,13702,14340,14344,15114,15115,17522,17523,17886,17890,18397,18398,18410,18416,18417,18418,25311,25312,25713,25714,32768,32770,32839,32850,32953,32954,40964,40965,42428,42429,53498,53499,55757,55758,56134,56135,56213,56215,59583,59585,65536,65547,67076,67077,67083,67084,67086,67087,67093,67099,67100,67101,67229,67235,67236,67237,67249,67255,67256,67257,67260,67261,67267,67273,67274,67275,67298,67304,67305,67306,68150,68151,81849,81850,81869,81870,83836,83837,97655,97656,97832,97833,98200,98201,98304,98306,98375,98386,99034,99035,105418,105419,110171,110172,112423,112424,112611,112612,112623,112629,112630,112631,112641,112642,112647,112651,112656,112657,112661,112667,112671,112672,112678,112684,112685,112686,112698,112704,112705,112706,112716,112722,112723,112724,112726,112733,112739,112740,114497,114498,114504,114505,114639,114640,115848,115855,115909,115916,115921,115928,115953,115960,115979,115986,116004,116011,116027,116028,116039,116041,116210,116211,116212,116213,116214,116215,116216,116217,116254,116256,116264,116265,116270,116271,116609,116613,116617,116621,116622,116624,116629,116633,116634,116638,116639,116643,116644,116648,116649,116653,116654,116658,116659,116663,116664,116666,116673,116677,116678,116682,116683,116687,116688,116692,116693,116695,116696,116700,116701,116705,116706,116708,116709,116713,116714,116718,116719,116723,116724,116728,116729,116733,116734,116738,116739,116743,116744,116748,116749,116751,116755,116759,116760,116764,116765,116769,116770,116774,116775,116777,116778,116782,116783,116785,116786,116790,116791,116793,116794,116798,116799,116803,116804,116806,116807,116811,116812,116967,117994,117995,121599,121600,131072,131085,132338,132340,132350,132395,139267,139269,144618,144620,148552,148553,152602,152604,154134,154136,154362,154363,156053,156063,159573,159574,163840,163842,163911,163926,164370,164371,164373,164374,164977,164979,167238,167241,170290,170291,174327,174329,174374,174376,174516,174518,175774,175776,176853,176855,177315,177316,178943,178944,179588,179589,183221,183222,185854,185855,190606,190607,190632,190634,196608,196621,196622,196623,207625,207632,207663,207664,207665,207669,207785,207786,207959,207960,208254,208261,208292,208293,208859,208860,208993,208994,210240,210241,210815,210816,210894,210895,211668,229378,229447,283143,284012,288515,288585,288586") && 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:2b0ee54f8fc4801b0db68083e9d0cf3089dbe316",
                "EMMC:/dev/block/bootdevice/by-name/boot:134217728:74b9f8b3f19445c93eb062cd8615407a9fb91303",
                package_extract_file("boot.img.p")) ||
    abort("E3008: Failed to apply patch to EMMC:/dev/block/bootdevice/by-name/boot:134217728:74b9f8b3f19445c93eb062cd8615407a9fb91303");

# ---- 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/NON-HLOS.bin", "/dev/block/bootdevice/by-name/modem");
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/imagefv.elf", "/dev/block/bootdevice/by-name/imagefv");
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/dspso.bin", "/dev/block/bootdevice/by-name/dsp");
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/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/imagefv.elf", "/dev/block/bootdevice/by-name/imagefvbak");
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 ---


# Update dynamic partition metadata

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

# 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.");

# 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");
