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_tr/surya:10/QKQ1.200512.002/V12.0.5.0.QJGTRXM:user/release-keys");
ui_print("Target: POCO/surya_tr/surya:10/QKQ1.200512.002/V12.0.6.0.QJGTRXM:user/release-keys");
ui_print("Verifying current system...");
getprop("ro.build.fingerprint") == "POCO/surya_tr/surya:10/QKQ1.200512.002/V12.0.5.0.QJGTRXM:user/release-keys" ||
    getprop("ro.build.fingerprint") == "POCO/surya_tr/surya:10/QKQ1.200512.002/V12.0.6.0.QJGTRXM:user/release-keys" ||
    abort("E3001: Package expects build fingerprint of POCO/surya_tr/surya:10/QKQ1.200512.002/V12.0.5.0.QJGTRXM:user/release-keys or POCO/surya_tr/surya:10/QKQ1.200512.002/V12.0.6.0.QJGTRXM: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:e66adb5639591149bf989bdd5efaf2806795fe80",
                      "EMMC:/dev/block/bootdevice/by-name/boot:134217728:5988144869add6ea72da7f2f4f50a6adb5048dba") ||
    abort("E3005: \"EMMC:/dev/block/bootdevice/by-name/boot:134217728:e66adb5639591149bf989bdd5efaf2806795fe80\" or \"EMMC:/dev/block/bootdevice/by-name/boot:134217728:5988144869add6ea72da7f2f4f50a6adb5048dba\" 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"), "1028,1,198,226,235,288,289,549,553,565,566,585,586,1897,2327,2333,2334,26238,26239,27606,27607,32768,32770,32932,32952,33018,33019,33233,33235,33395,33399,33407,33408,33416,33420,33425,33426,33646,33647,33659,33663,33667,34911,34915,34916,34926,34936,34942,34948,34949,34950,34955,34961,34962,34963,35083,35089,35095,35096,36652,36653,36718,36719,37244,37248,37277,37278,37348,37350,37443,37447,37451,37452,37483,37489,37490,37491,37590,37596,37597,38965,41757,41761,41789,41790,41804,41810,41811,41812,41814,41815,45063,45067,45112,45113,45483,45487,45495,45496,45583,45589,45594,45595,45723,45727,45733,45734,45996,45997,46189,46193,46208,46209,50826,50830,50924,50925,50930,50936,50937,50938,51625,51629,51651,51652,51710,51711,51782,51786,51790,51791,53074,53078,53103,53104,53575,53581,53582,53583,55345,55349,55392,55393,55397,55403,55404,55405,55427,55431,55455,55456,57148,57152,57176,57177,58023,58027,58050,58051,58134,58138,58143,58144,61451,61453,65239,65240,65536,65556,66205,66206,66830,66834,68996,68997,69316,69320,69333,69334,69366,69370,69386,69387,69392,69393,69843,69847,70250,70251,70934,70938,70954,70955,73340,73344,73391,73392,73788,73792,73805,73806,75606,75607,81142,81146,81229,81230,82157,82161,82186,82187,84247,84248,86844,86845,89234,89238,89356,89357,98304,98306,98468,98488,102049,102053,102076,102077,104470,104474,104524,104525,106280,106284,106318,106319,106357,106363,106367,106368,109709,109710,110246,110250,110288,110289,112899,112900,114101,114105,114128,114129,114493,114499,114513,114514,115629,115633,115659,115660,115673,115679,115680,115681,131072,131092,136322,136323,136795,136796,137668,137672,137902,137903,138291,138297,138311,138312,138322,138326,138333,138334,143085,143086,145921,145925,146008,146009,148568,148572,148612,148613,148664,148668,148672,148673,148676,148682,148686,148687,148692,148698,148699,148700,152573,152577,152644,152645,152729,152733,152738,152739,152741,152747,152748,152749,152793,152799,152800,152801,154611,154617,154659,154660,155060,155066,155076,155077,155273,155277,155281,155282,155285,155289,155293,155294,155949,155955,155978,155979,156388,156392,156402,156403,156440,156446,156447,156448,159523,159527,159566,159567,159859,159863,159872,159873,159943,159947,159951,159952,160689,160693,160711,160712,160815,160819,160824,160825,162041,162045,162071,162072,163840,163842,164004,164024,167009,167085,167087,167088,168848,168852,168973,168974,168982,168988,168989,168990,169616,169620,169635,169636,171124,171128,171143,171144,173471,173475,173502,173503,174396,174400,174426,174427,174431,174437,174438,174439,174461,174467,174468,174469,174473,174477,174480,174481,174485,174486,174510,174516,174517,174518,177581,177585,177633,177634,177919,177923,177932,177933,178291,178297,178306,178307,179791,179795,179823,179824,180801,180805,181739,181740,183948,183952,183992,183995,184019,184020,184022,184023,184024,184025,184026,184027,184057,184058,186532,186536,186550,186551,187071,187075,187082,187083,189705,189710,189726,189727,190062,190063,190291,190292,191570,191571,192007,192008,192802,192913,193728,193729,194596,194635,195165,195217,196519,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,196628,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,196987,196989,196995,196996,197292,197293,197305,197306,197316,197319,197320,197321,197322,197323,197325,197326,197359,197360,197365,197366,197454,197457,197459,197460,198567,198568,198787,198789,198812,198813,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,664325,666359,676918,677063,677064") == "6437042203824021ac1b1b4b059adf53a7510af8" || 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"), "1028,1,198,226,235,288,289,549,553,565,566,585,586,1897,2327,2333,2334,26238,26239,27606,27607,32768,32770,32932,32952,33018,33019,33233,33235,33395,33399,33407,33408,33416,33420,33425,33426,33646,33647,33659,33663,33667,34911,34915,34916,34926,34936,34942,34948,34949,34950,34955,34961,34962,34963,35083,35089,35095,35096,36652,36653,36718,36719,37244,37248,37277,37278,37348,37350,37443,37447,37451,37452,37483,37489,37490,37491,37590,37596,37597,38965,41757,41761,41789,41790,41804,41810,41811,41812,41814,41815,45063,45067,45112,45113,45483,45487,45495,45496,45583,45589,45594,45595,45723,45727,45733,45734,45996,45997,46189,46193,46208,46209,50826,50830,50924,50925,50930,50936,50937,50938,51625,51629,51651,51652,51710,51711,51782,51786,51790,51791,53074,53078,53103,53104,53575,53581,53582,53583,55345,55349,55392,55393,55397,55403,55404,55405,55427,55431,55455,55456,57148,57152,57176,57177,58023,58027,58050,58051,58134,58138,58143,58144,61451,61453,65239,65240,65536,65556,66205,66206,66830,66834,68996,68997,69316,69320,69333,69334,69366,69370,69386,69387,69392,69393,69843,69847,70250,70251,70934,70938,70954,70955,73340,73344,73391,73392,73788,73792,73805,73806,75606,75607,81142,81146,81229,81230,82157,82161,82186,82187,84247,84248,86844,86845,89234,89238,89356,89357,98304,98306,98468,98488,102049,102053,102076,102077,104470,104474,104524,104525,106280,106284,106318,106319,106357,106363,106367,106368,109709,109710,110246,110250,110288,110289,112899,112900,114101,114105,114128,114129,114493,114499,114513,114514,115629,115633,115659,115660,115673,115679,115680,115681,131072,131092,136322,136323,136795,136796,137668,137672,137902,137903,138291,138297,138311,138312,138322,138326,138333,138334,143085,143086,145921,145925,146008,146009,148568,148572,148612,148613,148664,148668,148672,148673,148676,148682,148686,148687,148692,148698,148699,148700,152573,152577,152644,152645,152729,152733,152738,152739,152741,152747,152748,152749,152793,152799,152800,152801,154611,154617,154659,154660,155060,155066,155076,155077,155273,155277,155281,155282,155285,155289,155293,155294,155949,155955,155978,155979,156388,156392,156402,156403,156440,156446,156447,156448,159523,159527,159566,159567,159859,159863,159872,159873,159943,159947,159951,159952,160689,160693,160711,160712,160815,160819,160824,160825,162041,162045,162071,162072,163840,163842,164004,164024,167009,167085,167087,167088,168848,168852,168973,168974,168982,168988,168989,168990,169616,169620,169635,169636,171124,171128,171143,171144,173471,173475,173502,173503,174396,174400,174426,174427,174431,174437,174438,174439,174461,174467,174468,174469,174473,174477,174480,174481,174485,174486,174510,174516,174517,174518,177581,177585,177633,177634,177919,177923,177932,177933,178291,178297,178306,178307,179791,179795,179823,179824,180801,180805,181739,181740,183948,183952,183992,183995,184019,184020,184022,184023,184024,184025,184026,184027,184057,184058,186532,186536,186550,186551,187071,187075,187082,187083,189705,189710,189726,189727,190062,190063,190291,190292,191570,191571,192007,192008,192802,192913,193728,193729,194596,194635,195165,195217,196519,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,196628,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,196987,196989,196995,196996,197292,197293,197305,197306,197316,197319,197320,197321,197322,197323,197325,197326,197359,197360,197365,197366,197454,197457,197459,197460,198567,198568,198787,198789,198812,198813,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,664325,666359,676918,677063,677064") && 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,276640,277637,282040,282109,282110") == "2b2e53608e2e4d9aa2b7e79155bbcd74970b071d" || 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,276640,277637,282040,282109,282110") && 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,116271,116272,116610,116614,116618,116622,116623,116625,116630,116634,116635,116639,116640,116644,116645,116649,116650,116654,116655,116659,116660,116664,116665,116667,116674,116678,116679,116683,116684,116688,116689,116693,116694,116696,116697,116701,116702,116706,116707,116709,116710,116714,116715,116719,116720,116724,116725,116729,116730,116734,116735,116739,116740,116744,116745,116749,116750,116752,116756,116760,116761,116765,116766,116770,116771,116775,116776,116778,116779,116783,116784,116786,116787,116791,116792,116794,116795,116799,116800,116804,116805,116807,116808,116812,116813,116968,117995,117996,121600,121601,131072,131085,132339,132341,132351,132396,139268,139270,144619,144621,148553,148554,152603,152605,154135,154137,154363,154364,156054,156064,159574,159575,163840,163842,163911,163926,164371,164372,164374,164375,164978,164980,167239,167242,170291,170292,174328,174330,174375,174377,174517,174519,175775,175777,176854,176856,177316,177317,178944,178945,179589,179590,183222,183223,185855,185856,190607,190608,190633,190635,196608,196621,196622,196623,207626,207633,207664,207665,207666,207670,207786,207787,207960,207961,208255,208262,208293,208294,208860,208861,208994,208995,210241,210242,210816,210817,210895,210896,211669,229378,229447,283144,284013,288516,288586,288587") == "9ebf2089f6873c11283f0209563eb3ba39c35bba" || 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,116271,116272,116610,116614,116618,116622,116623,116625,116630,116634,116635,116639,116640,116644,116645,116649,116650,116654,116655,116659,116660,116664,116665,116667,116674,116678,116679,116683,116684,116688,116689,116693,116694,116696,116697,116701,116702,116706,116707,116709,116710,116714,116715,116719,116720,116724,116725,116729,116730,116734,116735,116739,116740,116744,116745,116749,116750,116752,116756,116760,116761,116765,116766,116770,116771,116775,116776,116778,116779,116783,116784,116786,116787,116791,116792,116794,116795,116799,116800,116804,116805,116807,116808,116812,116813,116968,117995,117996,121600,121601,131072,131085,132339,132341,132351,132396,139268,139270,144619,144621,148553,148554,152603,152605,154135,154137,154363,154364,156054,156064,159574,159575,163840,163842,163911,163926,164371,164372,164374,164375,164978,164980,167239,167242,170291,170292,174328,174330,174375,174377,174517,174519,175775,175777,176854,176856,177316,177317,178944,178945,179589,179590,183222,183223,185855,185856,190607,190608,190633,190635,196608,196621,196622,196623,207626,207633,207664,207665,207666,207670,207786,207787,207960,207961,208255,208262,208293,208294,208860,208861,208994,208995,210241,210242,210816,210817,210895,210896,211669,229378,229447,283144,284013,288516,288586,288587") && 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:e66adb5639591149bf989bdd5efaf2806795fe80",
                "EMMC:/dev/block/bootdevice/by-name/boot:134217728:5988144869add6ea72da7f2f4f50a6adb5048dba",
                package_extract_file("boot.img.p")) ||
    abort("E3008: Failed to apply patch to EMMC:/dev/block/bootdevice/by-name/boot:134217728:5988144869add6ea72da7f2f4f50a6adb5048dba");

# ---- 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/km4.mbn", "/dev/block/bootdevice/by-name/keymaster");
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/BTFM.bin", "/dev/block/bootdevice/by-name/bluetooth");
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/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/storsec.mbn", "/dev/block/bootdevice/by-name/storsec");
package_extract_file("firmware-update/xbl.elf", "/dev/block/bootdevice/by-name/xbl");
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/km4.mbn", "/dev/block/bootdevice/by-name/keymasterbak");
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");
show_progress(0.600000, 600);

# --- Start patching dynamic partitions ---


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

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