getprop("ro.product.device") == "lime" || abort("E3004: This package is for \"lime\" devices; this is a \"" + getprop("ro.product.device") + "\".");
ui_print("Source: Redmi/lime/lime:10/QKQ1.200830.002/V12.0.4.0.QJQCNXM:user/release-keys");
ui_print("Target: Redmi/lime/lime:10/QKQ1.200830.002/V12.0.5.0.QJQCNXM:user/release-keys");
ui_print("Verifying current system...");
getprop("ro.build.fingerprint") == "Redmi/lime/lime:10/QKQ1.200830.002/V12.0.4.0.QJQCNXM:user/release-keys" ||
    getprop("ro.build.fingerprint") == "Redmi/lime/lime:10/QKQ1.200830.002/V12.0.5.0.QJQCNXM:user/release-keys" ||
    abort("E3001: Package expects build fingerprint of Redmi/lime/lime:10/QKQ1.200830.002/V12.0.4.0.QJQCNXM:user/release-keys or Redmi/lime/lime:10/QKQ1.200830.002/V12.0.5.0.QJQCNXM: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:100663296:7e6f84546b4b802ee813da1e78549d84c07bf715",
                      "EMMC:/dev/block/bootdevice/by-name/boot:100663296:56a33de77b5935b7ac1b82ded0b80a71013af155") ||
    abort("E3005: \"EMMC:/dev/block/bootdevice/by-name/boot:100663296:7e6f84546b4b802ee813da1e78549d84c07bf715\" or \"EMMC:/dev/block/bootdevice/by-name/boot:100663296:56a33de77b5935b7ac1b82ded0b80a71013af155\" has unexpected contents.");
apply_patch_space(100663296) || abort("E3006: Not enough free space on /cache to apply patches.");
show_progress(0.100000, 70);
if (range_sha1(map_partition("system"), "1560,1,225,252,261,281,282,542,546,558,559,578,579,1896,1897,3103,3104,8082,8083,8513,8514,32395,32396,32476,32478,32768,32770,32963,32979,33047,33051,33064,33065,33228,33232,33240,33241,33249,33253,33258,33259,38136,38137,38146,38150,38154,38155,39262,39268,39300,39301,39307,39313,39314,39315,39320,39326,39327,39328,39372,39378,39384,39385,40349,40350,41000,41002,42933,42934,42943,42944,42966,42967,42971,42972,43405,43406,43417,43423,43424,43425,43428,43429,43446,43452,43453,43454,45231,45235,45263,45264,45272,45278,45279,45280,45282,45283,48653,48657,48699,48700,48702,48708,48709,48710,48786,48792,48797,48798,49444,49445,49547,49562,49567,49570,49571,49607,49893,49894,49910,49911,50042,50043,50045,50046,50048,50049,57340,57344,57369,57370,57499,57503,57509,57510,57988,57992,58008,58009,60762,60766,60811,60812,60850,60856,60857,60858,61518,61522,61544,61545,61793,61794,61827,61833,61834,61835,62311,62315,62331,62332,63787,63791,63815,63816,64619,64623,64646,64647,64730,64734,64739,64740,65536,65552,70375,70377,75747,75748,76082,76084,76085,76086,76096,76102,76103,76104,76117,76121,76143,76144,76766,76770,76785,76786,78318,78322,78359,78360,78545,78546,78956,78960,78973,78974,81523,81524,82945,82949,82976,82977,85008,85009,86280,86281,89996,90000,90122,90123,98304,98306,98499,98515,102923,102927,102951,102952,105345,105349,105399,105400,111350,111353,111354,111357,111359,111363,111365,111374,111376,111378,115166,115168,118778,118780,118857,118859,121618,121620,124882,124884,128443,128445,129510,129512,132122,132124,132216,132218,132230,132232,134861,134863,134915,134919,136524,136526,136599,136603,136846,136848,137057,137059,137064,145234,145238,145240,145287,145296,145333,145334,145338,145366,145406,145410,147804,147806,147965,147967,148041,148043,148316,148318,156494,156496,159192,159194,165002,165004,165102,165106,165735,165737,166456,166458,166487,166491,168822,168824,188598,188600,188633,188637,188663,188667,188675,188677,188703,188707,189694,189696,191848,191850,191881,191885,194272,194274,194628,194630,194806,194808,194848,194850,196320,196322,196362,196366,201592,201594,209228,209230,211491,211493,211905,211907,217079,217088,217857,217858,222355,222358,249118,249120,295108,295123,295375,295376,295377,295378,297692,297693,301353,301354,302011,302012,305354,305355,306365,306366,307909,307910,312063,312064,314347,314348,315143,315144,315202,315203,320025,320026,320049,320050,324464,324465,327680,327696,328431,328432,333756,333757,343720,343721,344017,344018,344030,344031,344041,344044,344045,344046,344047,344048,344050,344051,344089,344090,344179,344182,344184,344185,345292,345293,345513,345514,345537,345538,345599,345600,345603,345608,345609,345610,345611,345612,345613,345614,346408,346409,346415,346416,346969,346973,346974,346975,346976,346977,346978,346979,346980,346981,346982,346983,346984,346985,346986,346987,346988,346991,348449,348451,348534,348535,348540,348542,348800,348801,348808,348810,349301,349303,349408,349409,349424,349425,349436,349437,349703,349704,349817,349818,349834,349836,351152,351153,356093,356095,360448,360464,365024,365025,372895,372896,374948,374949,375422,375423,378714,388845,393216,393232,394413,394929,397526,397527,397683,397684,401414,412047,420140,420826,423843,423853,425161,425162,425984,426000,427462,427463,427501,427502,428091,435738,436344,436846,436918,437198,437227,437231,437235,437239,437240,437244,437245,437249,437250,437254,437255,437257,437635,437637,437742,437746,437747,437751,437752,437756,437757,437761,437762,437766,437767,437771,437772,437776,437777,437781,437782,437786,437787,437789,437803,437807,437808,437810,437819,437823,437824,437828,437829,437834,437839,437843,437844,437848,437849,437853,437854,437858,437859,437861,437929,437931,437936,437940,437941,437945,437946,437950,437951,437955,437956,437960,437961,437963,437967,437969,437978,437982,437983,437987,437988,437992,437993,437995,438075,438079,438080,438082,438086,438088,438089,438091,438092,438096,438097,438101,438102,438106,438107,438109,438115,438119,438120,438124,438125,438129,438130,438134,438135,438139,438140,438144,438145,438147,438151,438153,438154,438158,438159,438161,438162,438166,438167,438171,438172,438176,438177,438179,438183,438185,438188,438189,438191,438193,438197,438220,438654,438656,438780,438817,438820,438826,438835,438864,438885,438891,438969,438971,438974,439018,439108,439487,447211,447254,447257,447279,447282,447284,449182,449192,455664,455665,458752,458768,460060,460061,460406,460407,460455,460456,460470,460471,460499,460500,460542,460543,460781,460782,461217,461227,461617,461618,461877,461980,462838,464324,467423,467424,467812,467813,469983,469984,471710,471711,472106,472107,472257,472260,474055,474056,474535,474536,476892,476893,476923,476924,476953,476954,478305,478307,478447,478448,478453,478454,478459,478460,478496,478497,478501,478502,478552,478553,478556,478557,478570,478571,478584,478585,478598,478599,478608,478609,478618,478619,478770,478771,478774,478775,478779,478780,478786,478787,478811,478812,478818,478819,478886,478887,478892,478893,478899,478900,478905,478906,478911,478912,478925,478926,478935,478936,478983,478984,478989,478990,479021,479022,479027,479028,479034,479035,479041,479042,479101,479102,479109,479110,479120,479121,479124,479125,479132,479133,479138,479139,479142,479143,479152,479153,479158,479159,479165,479166,479242,479243,479249,479250,479255,479256,479260,479261,479266,479267,479302,479303,479308,479309,479317,479318,479327,479328,479333,479334,479338,479339,479345,479346,479402,479403,479449,479450,479453,479454,479457,479458,479463,479464,479468,479469,479540,479541,479546,479547,479561,479562,479576,479577,479592,479593,479608,479609,479624,479625,479657,479658,479663,479664,479755,479756,479790,479791,479845,479846,479984,479985,479990,479991,479996,479997,480002,480003,480007,480008,480951,480952,480961,480962,481002,481003,481032,481033,481708,481709,481729,481730,481761,481762,481932,481933,481938,481939,482009,482010,482012,482013,482017,482018,482059,482060,482064,482065,482069,482070,482078,482079,482092,482093,482588,482589,482594,482595,482610,482611,482615,482617,482623,482624,482908,482909,482945,482947,482956,482957,482962,482963,482968,482969,482974,482975,482984,482985,482988,482989,482991,482992,482997,482998,483038,483039,483119,483120,483124,483125,483141,483142,483328,483329,483524,483525,483620,483621,483627,483629,484664,484665,485614,485615,486585,486586,486593,486594,486789,486790,487035,487036,489053,489054,489443,489444,489454,489455,490116,490117,490222,490223,491520,491541,495501,495502,496240,496251,496991,496992,498436,498580,499000,499001,499158,499189,500931,500932,504020,504021,504906,504907,505248,505311,511781,511782,512147,512148,513563,513564,513922,513923,519955,519956,521343,521344,521346,521347,521460,521461,521464,521465,521466,521467,523092,523155,532647,532648,535131,535132,535137,535138,535145,535146,540853,540854,543516,543517,544814,544816,544820,544821,545312,545313,546495,546496,546953,546954,547443,547444,547897,547898,547909,547910,550998,550999,551088,551089,551685,551687,551897,551898,553683,553684,553692,553693,553876,553877,557056,557072,562863,562864,564598,564599,566140,566141,571988,571989,571991,571992,572130,572131,572394,572395,572486,572487,572493,572494,572500,572501,572527,572528,572537,572538,572556,572557,572758,572759,572765,572766,572769,572770,573179,573180,573184,573185,573237,573238,573241,573242,573251,573252,573261,573262,573267,573268,573303,573304,573308,573309,573312,573313,573322,573323,573328,573329,573337,573338,573352,573353,573362,573363,573379,573380,573436,573437,573448,573449,573457,573458,573535,573536,573599,573600,573603,573604,573700,573701,573740,573741,573744,573745,573813,573814,573822,573823,573938,573939,574093,574094,574101,574102,574186,574187,575366,575367,575371,575372,575376,575377,575396,575397,575954,575955,575957,575958,575959,575960,576000,576001,576246,576247,576338,576339,576341,576342,576363,576364,576368,576369,576377,576378,576379,576380,576386,576387,576883,576884,576888,576889,576986,576987,576989,576990,576996,576997,577001,577002,577443,577444,577456,577457,577466,577467,577471,577472,577477,577478,577483,577484,577533,577534,577606,577607,577651,577652,577686,577687,577690,577691,577699,577700,577750,577751,577794,577795,577896,577897,577899,577900,584950,584951,586012,586025,586030,595236,595375,595408,603492,603494,608659,608661,608764,608768,608843,608845,617904,617905,622592,622655,628640,628642,628649,628653,630016,630018,630022,630023,630707,630708,630710,630712,630714,630715,630725,630726,630737,630739,630755,630756,630777,630778,630967,630969,630970,630972,630973,630974,634906,634907,636294,636296,636531,636533,636546,636550,637295,637297,637374,637376,640274,640275,642189,642190,642193,642194,644218,644220,644568,644570,648430,648432,649762,649764,651378,651380,651419,651423,651443,651447,651456,651460,651732,651734,651749,651751,652986,652988,653426,653428,653537,653539,653567,653569,653580,653584,654328,654329,655080,655082,655186,655188,655360,655400,659156,659157,660656,660657,660830,660831,660935,660936,663920,663921,667510,667511,668927,668929,678519,678520,683782,683784,688128,688245,691989,691990,691998,691999,693133,693137,693404,693408,701494,701495,702603,702605,705444,705446,709916,709918,716013,716014,716918,716920,720896,720930,724474,724475,737560,737564,737712,737713,740830,740831,740847,740849,741569,741570,741572,741573,741575,741576,742291,742295,742363,742364,742381,742387,742388,742389,742415,742421,742422,742423,747300,747301,750100,750101,750119,750125,750126,750127,750138,750143,750144,750145,750612,750616,750624,750625,751553,751557,751578,751579,753664,753678,756980,756981,758548,758549,758582,758584,758618,758619,758621,758622,759331,759333,760340,760342,760354,760355,760359,760360,760445,760446,760498,760499,760501,760505,760506,760507,761023,761024,762161,762165,762172,762173,762177,762183,762184,762185,765441,765445,765487,765488,765549,765553,765557,765564,766201,766202,772945,772946,774660,774664,774735,774736,774803,774807,774904,774905,774909,774915,774916,774917,774969,774973,774977,774978,776888,776889,777668,777672,777719,777720,777735,777741,777742,777743,779486,779487,779675,779679,779720,779721,780480,780484,781663,781664,781814,781820,781822,781823,781828,781834,781835,781836,781848,781854,781855,781856,781884,781890,781894,781895,783000,783001,784055,784059,784098,784099,784868,784872,784897,784902,784984,786433,786448,788385,788724,788725,788728,788729,788748,788749,788803,788805,788814,788816,788931,788932,788933,788936,791571,804115,804281,804282") == "2f729ca0eae590a858fc25f3b9503d8d93226f2b" || 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"), "1560,1,225,252,261,281,282,542,546,558,559,578,579,1896,1897,3103,3104,8082,8083,8513,8514,32395,32396,32476,32478,32768,32770,32963,32979,33047,33051,33064,33065,33228,33232,33240,33241,33249,33253,33258,33259,38136,38137,38146,38150,38154,38155,39262,39268,39300,39301,39307,39313,39314,39315,39320,39326,39327,39328,39372,39378,39384,39385,40349,40350,41000,41002,42933,42934,42943,42944,42966,42967,42971,42972,43405,43406,43417,43423,43424,43425,43428,43429,43446,43452,43453,43454,45231,45235,45263,45264,45272,45278,45279,45280,45282,45283,48653,48657,48699,48700,48702,48708,48709,48710,48786,48792,48797,48798,49444,49445,49547,49562,49567,49570,49571,49607,49893,49894,49910,49911,50042,50043,50045,50046,50048,50049,57340,57344,57369,57370,57499,57503,57509,57510,57988,57992,58008,58009,60762,60766,60811,60812,60850,60856,60857,60858,61518,61522,61544,61545,61793,61794,61827,61833,61834,61835,62311,62315,62331,62332,63787,63791,63815,63816,64619,64623,64646,64647,64730,64734,64739,64740,65536,65552,70375,70377,75747,75748,76082,76084,76085,76086,76096,76102,76103,76104,76117,76121,76143,76144,76766,76770,76785,76786,78318,78322,78359,78360,78545,78546,78956,78960,78973,78974,81523,81524,82945,82949,82976,82977,85008,85009,86280,86281,89996,90000,90122,90123,98304,98306,98499,98515,102923,102927,102951,102952,105345,105349,105399,105400,111350,111353,111354,111357,111359,111363,111365,111374,111376,111378,115166,115168,118778,118780,118857,118859,121618,121620,124882,124884,128443,128445,129510,129512,132122,132124,132216,132218,132230,132232,134861,134863,134915,134919,136524,136526,136599,136603,136846,136848,137057,137059,137064,145234,145238,145240,145287,145296,145333,145334,145338,145366,145406,145410,147804,147806,147965,147967,148041,148043,148316,148318,156494,156496,159192,159194,165002,165004,165102,165106,165735,165737,166456,166458,166487,166491,168822,168824,188598,188600,188633,188637,188663,188667,188675,188677,188703,188707,189694,189696,191848,191850,191881,191885,194272,194274,194628,194630,194806,194808,194848,194850,196320,196322,196362,196366,201592,201594,209228,209230,211491,211493,211905,211907,217079,217088,217857,217858,222355,222358,249118,249120,295108,295123,295375,295376,295377,295378,297692,297693,301353,301354,302011,302012,305354,305355,306365,306366,307909,307910,312063,312064,314347,314348,315143,315144,315202,315203,320025,320026,320049,320050,324464,324465,327680,327696,328431,328432,333756,333757,343720,343721,344017,344018,344030,344031,344041,344044,344045,344046,344047,344048,344050,344051,344089,344090,344179,344182,344184,344185,345292,345293,345513,345514,345537,345538,345599,345600,345603,345608,345609,345610,345611,345612,345613,345614,346408,346409,346415,346416,346969,346973,346974,346975,346976,346977,346978,346979,346980,346981,346982,346983,346984,346985,346986,346987,346988,346991,348449,348451,348534,348535,348540,348542,348800,348801,348808,348810,349301,349303,349408,349409,349424,349425,349436,349437,349703,349704,349817,349818,349834,349836,351152,351153,356093,356095,360448,360464,365024,365025,372895,372896,374948,374949,375422,375423,378714,388845,393216,393232,394413,394929,397526,397527,397683,397684,401414,412047,420140,420826,423843,423853,425161,425162,425984,426000,427462,427463,427501,427502,428091,435738,436344,436846,436918,437198,437227,437231,437235,437239,437240,437244,437245,437249,437250,437254,437255,437257,437635,437637,437742,437746,437747,437751,437752,437756,437757,437761,437762,437766,437767,437771,437772,437776,437777,437781,437782,437786,437787,437789,437803,437807,437808,437810,437819,437823,437824,437828,437829,437834,437839,437843,437844,437848,437849,437853,437854,437858,437859,437861,437929,437931,437936,437940,437941,437945,437946,437950,437951,437955,437956,437960,437961,437963,437967,437969,437978,437982,437983,437987,437988,437992,437993,437995,438075,438079,438080,438082,438086,438088,438089,438091,438092,438096,438097,438101,438102,438106,438107,438109,438115,438119,438120,438124,438125,438129,438130,438134,438135,438139,438140,438144,438145,438147,438151,438153,438154,438158,438159,438161,438162,438166,438167,438171,438172,438176,438177,438179,438183,438185,438188,438189,438191,438193,438197,438220,438654,438656,438780,438817,438820,438826,438835,438864,438885,438891,438969,438971,438974,439018,439108,439487,447211,447254,447257,447279,447282,447284,449182,449192,455664,455665,458752,458768,460060,460061,460406,460407,460455,460456,460470,460471,460499,460500,460542,460543,460781,460782,461217,461227,461617,461618,461877,461980,462838,464324,467423,467424,467812,467813,469983,469984,471710,471711,472106,472107,472257,472260,474055,474056,474535,474536,476892,476893,476923,476924,476953,476954,478305,478307,478447,478448,478453,478454,478459,478460,478496,478497,478501,478502,478552,478553,478556,478557,478570,478571,478584,478585,478598,478599,478608,478609,478618,478619,478770,478771,478774,478775,478779,478780,478786,478787,478811,478812,478818,478819,478886,478887,478892,478893,478899,478900,478905,478906,478911,478912,478925,478926,478935,478936,478983,478984,478989,478990,479021,479022,479027,479028,479034,479035,479041,479042,479101,479102,479109,479110,479120,479121,479124,479125,479132,479133,479138,479139,479142,479143,479152,479153,479158,479159,479165,479166,479242,479243,479249,479250,479255,479256,479260,479261,479266,479267,479302,479303,479308,479309,479317,479318,479327,479328,479333,479334,479338,479339,479345,479346,479402,479403,479449,479450,479453,479454,479457,479458,479463,479464,479468,479469,479540,479541,479546,479547,479561,479562,479576,479577,479592,479593,479608,479609,479624,479625,479657,479658,479663,479664,479755,479756,479790,479791,479845,479846,479984,479985,479990,479991,479996,479997,480002,480003,480007,480008,480951,480952,480961,480962,481002,481003,481032,481033,481708,481709,481729,481730,481761,481762,481932,481933,481938,481939,482009,482010,482012,482013,482017,482018,482059,482060,482064,482065,482069,482070,482078,482079,482092,482093,482588,482589,482594,482595,482610,482611,482615,482617,482623,482624,482908,482909,482945,482947,482956,482957,482962,482963,482968,482969,482974,482975,482984,482985,482988,482989,482991,482992,482997,482998,483038,483039,483119,483120,483124,483125,483141,483142,483328,483329,483524,483525,483620,483621,483627,483629,484664,484665,485614,485615,486585,486586,486593,486594,486789,486790,487035,487036,489053,489054,489443,489444,489454,489455,490116,490117,490222,490223,491520,491541,495501,495502,496240,496251,496991,496992,498436,498580,499000,499001,499158,499189,500931,500932,504020,504021,504906,504907,505248,505311,511781,511782,512147,512148,513563,513564,513922,513923,519955,519956,521343,521344,521346,521347,521460,521461,521464,521465,521466,521467,523092,523155,532647,532648,535131,535132,535137,535138,535145,535146,540853,540854,543516,543517,544814,544816,544820,544821,545312,545313,546495,546496,546953,546954,547443,547444,547897,547898,547909,547910,550998,550999,551088,551089,551685,551687,551897,551898,553683,553684,553692,553693,553876,553877,557056,557072,562863,562864,564598,564599,566140,566141,571988,571989,571991,571992,572130,572131,572394,572395,572486,572487,572493,572494,572500,572501,572527,572528,572537,572538,572556,572557,572758,572759,572765,572766,572769,572770,573179,573180,573184,573185,573237,573238,573241,573242,573251,573252,573261,573262,573267,573268,573303,573304,573308,573309,573312,573313,573322,573323,573328,573329,573337,573338,573352,573353,573362,573363,573379,573380,573436,573437,573448,573449,573457,573458,573535,573536,573599,573600,573603,573604,573700,573701,573740,573741,573744,573745,573813,573814,573822,573823,573938,573939,574093,574094,574101,574102,574186,574187,575366,575367,575371,575372,575376,575377,575396,575397,575954,575955,575957,575958,575959,575960,576000,576001,576246,576247,576338,576339,576341,576342,576363,576364,576368,576369,576377,576378,576379,576380,576386,576387,576883,576884,576888,576889,576986,576987,576989,576990,576996,576997,577001,577002,577443,577444,577456,577457,577466,577467,577471,577472,577477,577478,577483,577484,577533,577534,577606,577607,577651,577652,577686,577687,577690,577691,577699,577700,577750,577751,577794,577795,577896,577897,577899,577900,584950,584951,586012,586025,586030,595236,595375,595408,603492,603494,608659,608661,608764,608768,608843,608845,617904,617905,622592,622655,628640,628642,628649,628653,630016,630018,630022,630023,630707,630708,630710,630712,630714,630715,630725,630726,630737,630739,630755,630756,630777,630778,630967,630969,630970,630972,630973,630974,634906,634907,636294,636296,636531,636533,636546,636550,637295,637297,637374,637376,640274,640275,642189,642190,642193,642194,644218,644220,644568,644570,648430,648432,649762,649764,651378,651380,651419,651423,651443,651447,651456,651460,651732,651734,651749,651751,652986,652988,653426,653428,653537,653539,653567,653569,653580,653584,654328,654329,655080,655082,655186,655188,655360,655400,659156,659157,660656,660657,660830,660831,660935,660936,663920,663921,667510,667511,668927,668929,678519,678520,683782,683784,688128,688245,691989,691990,691998,691999,693133,693137,693404,693408,701494,701495,702603,702605,705444,705446,709916,709918,716013,716014,716918,716920,720896,720930,724474,724475,737560,737564,737712,737713,740830,740831,740847,740849,741569,741570,741572,741573,741575,741576,742291,742295,742363,742364,742381,742387,742388,742389,742415,742421,742422,742423,747300,747301,750100,750101,750119,750125,750126,750127,750138,750143,750144,750145,750612,750616,750624,750625,751553,751557,751578,751579,753664,753678,756980,756981,758548,758549,758582,758584,758618,758619,758621,758622,759331,759333,760340,760342,760354,760355,760359,760360,760445,760446,760498,760499,760501,760505,760506,760507,761023,761024,762161,762165,762172,762173,762177,762183,762184,762185,765441,765445,765487,765488,765549,765553,765557,765564,766201,766202,772945,772946,774660,774664,774735,774736,774803,774807,774904,774905,774909,774915,774916,774917,774969,774973,774977,774978,776888,776889,777668,777672,777719,777720,777735,777741,777742,777743,779486,779487,779675,779679,779720,779721,780480,780484,781663,781664,781814,781820,781822,781823,781828,781834,781835,781836,781848,781854,781855,781856,781884,781890,781894,781895,783000,783001,784055,784059,784098,784099,784868,784872,784897,784902,784984,786433,786448,788385,788724,788725,788728,788729,788748,788749,788803,788805,788814,788816,788931,788932,788933,788936,791571,804115,804281,804282") && 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"), "62,1,109,119,123,128,129,211,215,220,221,1895,1899,2376,2377,2640,2644,2648,2649,2651,2655,2657,2668,2691,2692,2728,2732,2782,2783,2919,2920,2932,2936,2940,2941,2944,2950,2951,2952,2964,2968,2972,2979,2988,2989,4776,32770,32850,98306,98386,163842,163922,229378,229458,294914,294994,327691,327699,329997,331024,336272,336351,336352") == "70f1882f75215300fd8d1d77d5994915f904093e" || 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"), "62,1,109,119,123,128,129,211,215,220,221,1895,1899,2376,2377,2640,2644,2648,2649,2651,2655,2657,2668,2691,2692,2728,2732,2782,2783,2919,2920,2932,2936,2940,2941,2944,2950,2951,2952,2964,2968,2972,2979,2988,2989,4776,32770,32850,98306,98386,163842,163922,229378,229458,294914,294994,327691,327699,329997,331024,336272,336351,336352") && 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"), "268,1,54,70,74,78,79,86,92,93,94,740,744,751,752,758,764,765,766,768,769,775,781,782,783,898,904,905,906,918,924,925,926,929,930,936,942,943,944,967,973,974,975,1819,1820,15518,15519,15538,15539,31208,31209,31330,31331,31507,31508,31875,31876,32627,32628,32768,32770,32789,32814,36165,36166,36177,36183,36184,36185,36195,36196,36201,36205,36210,36211,36215,36221,36225,36226,36232,36238,36239,36240,36252,36258,36259,36260,36270,36276,36277,36278,36280,36287,36293,36294,38052,38053,38059,38060,38200,38201,39403,39410,39479,39486,39491,39498,39528,39535,39554,39561,39579,39586,39602,39603,39614,39616,39780,39781,39782,39783,39784,39785,39820,39822,39830,39831,40153,40157,40161,40165,40166,40170,40171,40175,40176,40180,40181,40185,40186,40190,40191,40195,40196,40200,40201,40203,40210,40214,40215,40219,40220,40224,40225,40229,40230,40234,40235,40239,40240,40244,40245,40247,40248,40252,40253,40257,40258,40262,40263,40267,40268,40272,40273,40277,40278,40282,40283,40287,40288,40290,40295,40299,40300,40304,40305,40309,40310,40314,40315,40317,40318,40322,40323,40325,40326,40330,40331,40335,40336,40338,40339,40343,40344,40348,40349,40351,40352,40356,40357,40462,40465,40513,41531,41532,45340,45341,46545,46546,51609,51610,53232,53235,55863,55867,56606,56608,56628,56632,57058,57059,61822,61823,61848,61850,65536,65613,68247,68248,70708,70712,76739,76740,77205,77209,77223,77224,77891,77895,77910,77911,77938,77944,77945,77946,77954,77959,77960,77961,78247,78253,78262,78269,78291,78296,78548,79795,79827,79828") == "811034f436a7d57cd0831e7609d7eab917f82d87" || 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
ifelse (block_image_recover(map_partition("product"), "268,1,54,70,74,78,79,86,92,93,94,740,744,751,752,758,764,765,766,768,769,775,781,782,783,898,904,905,906,918,924,925,926,929,930,936,942,943,944,967,973,974,975,1819,1820,15518,15519,15538,15539,31208,31209,31330,31331,31507,31508,31875,31876,32627,32628,32768,32770,32789,32814,36165,36166,36177,36183,36184,36185,36195,36196,36201,36205,36210,36211,36215,36221,36225,36226,36232,36238,36239,36240,36252,36258,36259,36260,36270,36276,36277,36278,36280,36287,36293,36294,38052,38053,38059,38060,38200,38201,39403,39410,39479,39486,39491,39498,39528,39535,39554,39561,39579,39586,39602,39603,39614,39616,39780,39781,39782,39783,39784,39785,39820,39822,39830,39831,40153,40157,40161,40165,40166,40170,40171,40175,40176,40180,40181,40185,40186,40190,40191,40195,40196,40200,40201,40203,40210,40214,40215,40219,40220,40224,40225,40229,40230,40234,40235,40239,40240,40244,40245,40247,40248,40252,40253,40257,40258,40262,40263,40267,40268,40272,40273,40277,40278,40282,40283,40287,40288,40290,40295,40299,40300,40304,40305,40309,40310,40314,40315,40317,40318,40322,40323,40325,40326,40330,40331,40335,40336,40338,40339,40343,40344,40348,40349,40351,40352,40356,40357,40462,40465,40513,41531,41532,45340,45341,46545,46546,51609,51610,53232,53235,55863,55867,56606,56608,56628,56632,57058,57059,61822,61823,61848,61850,65536,65613,68247,68248,70708,70712,76739,76740,77205,77209,77223,77224,77891,77895,77910,77911,77938,77944,77945,77946,77954,77959,77960,77961,78247,78253,78262,78269,78291,78296,78548,79795,79827,79828") && 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:100663296:7e6f84546b4b802ee813da1e78549d84c07bf715",
                "EMMC:/dev/block/bootdevice/by-name/boot:100663296:56a33de77b5935b7ac1b82ded0b80a71013af155",
                package_extract_file("boot.img.p")) ||
    abort("E3008: Failed to apply patch to EMMC:/dev/block/bootdevice/by-name/boot:100663296:56a33de77b5935b7ac1b82ded0b80a71013af155");

# ---- 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/featenabler.mbn", "/dev/block/bootdevice/by-name/featenabler");
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/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/rpm.mbn", "/dev/block/bootdevice/by-name/rpm");
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/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/storsec.mbn", "/dev/block/bootdevice/by-name/storsecbak");
package_extract_file("firmware-update/xbl.elf", "/dev/block/bootdevice/by-name/xblbak");
package_extract_file("firmware-update/rpm.mbn", "/dev/block/bootdevice/by-name/rpmbak");
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/dtbo.img", "/dev/block/bootdevice/by-name/dtbo");
package_extract_file("firmware-update/vbmeta.img", "/dev/block/bootdevice/by-name/vbmeta");
package_extract_file("firmware-update/vbmeta_system.img", "/dev/block/bootdevice/by-name/vbmeta_system");
