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JpdHkqIiwKKyAgICAgICAgImFuZHJvaWQtKiIsCiAgICAgXSwKICAgICB0aWR5X2ZsYWdzOiBbCiAgICAgICAgICItd2FybmluZ3MtYXMtZXJyb3JzPWNsYW5nLWFuYWx5emVyLXNlY3VyaXR5KixjZXJ0LSoiLApAQCAtMjksOCArMzAsMTEgQEAKICAgICBzdGF0aWNfbGliczogWwogICAgICAgICAibGliYXZiIiwKICAgICAgICAgImxpYmJvb3Rsb2FkZXJfbWVzc2FnZSIsCisgICAgICAgICJsaWJkbSIsCisgICAgICAgICJsaWJleHQyX3V1aWQiLAogICAgICAgICAibGliZmVjIiwKICAgICAgICAgImxpYmZlY19ycyIsCisgICAgICAgICJsaWJmc19hdmIiLAogICAgICAgICAibGliZnNfbWdyIiwKICAgICAgICAgImxpYnNjcnlwdF9zdGF0aWMiLAogICAgICAgICAibGlic3F1YXNoZnNfdXRpbHMiLApAQCAtMzksNiArNDMsNyBAQAogICAgIHNoYXJlZF9saWJzOiBbCiAgICAgICAgICJhbmRyb2lkLmhhcmR3YXJlLmtleW1hc3RlckAzLjAiLAogICAgICAgICAiYW5kcm9pZC5oYXJkd2FyZS5rZXltYXN0ZXJANC4wIiwKKyAgICAgICAgImFuZHJvaWQuaGFyZHdhcmUua2V5bWFzdGVyQDQuMSIsCiAgICAgICAgICJhbmRyb2lkLmhhcmR3YXJlLmJvb3RAMS4wIiwKICAgICAgICAgImxpYmJhc2UiLAogICAgICAgICAibGliYmluZGVyIiwKQEAgLTQ4LDEyICs1MywxMiBAQAogICAgICAgICAibGliZGlza2NvbmZpZyIsCiAgICAgICAgICJsaWJleHQ0X3V0aWxzIiwKICAgICAgICAgImxpYmYyZnNfc3BhcnNlYmxvY2siLAotICAgICAgICAibGliZnNjcnlwdCIsCiAgICAgICAgICJsaWJoYXJkd2FyZSIsCiAgICAgICAgICJsaWJoYXJkd2FyZV9sZWdhY3kiLAorICAgICAgICAibGliaW5jZnMiLAogICAgICAgICAibGliaGlkbGJhc2UiLAotICAgICAgICAibGliaHdiaW5kZXIiLAogICAgICAgICAibGlia2V5bWFzdGVyNHN1cHBvcnQiLAorICAgICAgICAibGlia2V5bWFzdGVyNF8xc3VwcG9ydCIsCiAgICAgICAgICJsaWJrZXl1dGlscyIsCiAgICAgICAgICJsaWJsb2ciLAogICAgICAgICAibGlibG9nd3JhcCIsCkBAIC03NiwxMyArODEsMjAgQEAKICAgICBdLAogICAgIGFpZGw6IHsKICAgICAgICAgbG9jYWxfaW5jbHVkZV9kaXJzOiBbImJpbmRlciJdLAotICAgICAgICBpbmNsdWRlX2RpcnM6IFsiZnJhbWV3b3Jrcy9uYXRpdmUvYWlkbC9iaW5kZXIiXSwKKyAgICAgICAgaW5jbHVkZV9kaXJzOiBbCisgICAgICAgICAgICAiZnJhbWV3b3Jrcy9uYXRpdmUvYWlkbC9iaW5kZXIiLAorICAgICAgICAgICAgImZyYW1ld29ya3MvYmFzZS9jb3JlL2phdmEiLAorICAgICAgICBdLAogICAgICAgICBleHBvcnRfYWlkbF9oZWFkZXJzOiB0cnVlLAogICAgIH0sCisgICAgd2hvbGVfc3RhdGljX2xpYnM6IFsKKyAgICAgICAgImxpYmluY3JlbWVudGFsX2FpZGwtY3BwIiwKKyAgICBdLAogfQogCiBjY19saWJyYXJ5X2hlYWRlcnMgewogICAgIG5hbWU6ICJsaWJ2b2xkX2hlYWRlcnMiLAorICAgIHJlY292ZXJ5X2F2YWlsYWJsZTogdHJ1ZSwKICAgICBleHBvcnRfaW5jbHVkZV9kaXJzOiBbIi4iXSwKIH0KIApAQCAtOTksNiArMTExLDcgQEAKICAgICAgICAgIkJlbmNobWFyay5jcHAiLAogICAgICAgICAiQ2hlY2tFbmNyeXB0aW9uLmNwcCIsCiAgICAgICAgICJDaGVja3BvaW50LmNwcCIsCisgICAgICAgICJDcnlwdG9UeXBlLmNwcCIsCiAgICAgICAgICJEZXZtYXBwZXIuY3BwIiwKICAgICAgICAgIkVuY3J5cHRJbnBsYWNlLmNwcCIsCiAgICAgICA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KGludCBpID0gMDsgaSA8IG1vdW50cy0+bnVtX2VudHJpZXM7ICsraSkgewotICAgICAgICBjb25zdCBmc3RhYl9yZWMqIG1vdW50X3JlYyA9ICZtb3VudHMtPnJlY3NbaV07Ci0gICAgICAgIGNvbnN0IGZzdGFiX3JlYyogZnN0YWJfcmVjID0KLSAgICAgICAgICAgIGZzX21ncl9nZXRfZW50cnlfZm9yX21vdW50X3BvaW50KGZzdGFiX2RlZmF1bHQuZ2V0KCksIG1vdW50X3JlYy0+bW91bnRfcG9pbnQpOworICAgIGZvciAoY29uc3QgYXV0byYgbW91bnRfcmVjIDogbW91bnRzKSB7CisgICAgICAgIGNvbnN0IGF1dG8gZnN0YWJfcmVjID0gR2V0RW50cnlGb3JNb3VudFBvaW50KCZmc3RhYl9kZWZhdWx0LCBtb3VudF9yZWMubW91bnRfcG9pbnQpOwogICAgICAgICBpZiAoIWZzdGFiX3JlYykgY29udGludWU7CiAKLSAgICAgICAgaWYgKGZzX21ncl9pc19jaGVja3BvaW50X2ZzKGZzdGFiX3JlYykpIHsKLSAgICAgICAgICAgIGlmICghc3RyY21wKGZzdGFiX3JlYy0+ZnNfdHlwZSwgImYyZnMiKSkgewotICAgICAgICAgICAgICAgIG1vdW50KG1vdW50X3JlYy0+YmxrX2RldmljZSwgbW91bnRfcmVjLT5tb3VudF9wb2ludCwgIm5vbmUiLAotICAgICAgICAgICAgICAgICAgICAgIE1TX1JFTU9VTlQgfCBmc3RhYl9yZWMtPmZsYWdzLCAiY2hlY2twb2ludD1lbmFibGUiKTsKKyAgICAgICAgaWYgKGZzdGFiX3JlYy0+ZnNfbWdyX2ZsYWdzLmNoZWNrcG9pbnRfZnMpIHsKKyAgICAgICAgICAgIGlmIChmc3RhYl9yZWMtPmZzX3R5cGUgPT0gImYyZnMiKSB7CisgICAgICAgICAgICAgICAgc3RkOjpzdHJpbmcgb3B0aW9ucyA9IG1vdW50X3JlYy5mc19vcHRpb25zICsgIixjaGVja3BvaW50PWVuYWJsZSI7CisgICAgICAgICAgICAgICAgaWYgKG1vdW50KG1vdW50X3JlYy5ibGtfZGV2aWNlLmNfc3RyKCksIG1vdW50X3JlYy5tb3VudF9wb2ludC5jX3N0cigpLCAibm9uZSIsCisgICAgICAgICAgICAgICAgICAgICAgICAgIE1TX1JFTU9VTlQgfCBmc3RhYl9yZWMtPmZsYWdzLCBvcHRpb25zLmNfc3RyKCkpKSB7CisgICAgICAgICAgICAgICAgICAgIHJldHVybiBlcnJvcihFSU5WQUwsICJGYWlsZWQgdG8gcmVtb3VudCIpOworICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgIH0KLSAgICAgICAgfSBlbHNlIGlmIChmc19tZ3JfaXNfY2hlY2twb2ludF9ibGsoZnN0YWJfcmVjKSkgewotICAgICAgICAgICAgc2V0Qm93U3RhdGUobW91bnRfcmVjLT5ibGtfZGV2aWNlLCAiMiIpOworICAgICAgICB9IGVsc2UgaWYgKGZzdGFiX3JlYy0+ZnNfbWdyX2ZsYWdzLmNoZWNrcG9pbnRfYmxrKSB7CisgICAgICAgICAgICBpZiAoIXNldEJvd1N0YXRlKG1vdW50X3JlYy5ibGtfZGV2aWNlLCAiMiIpKQorICAgICAgICAgICAgICAgIHJldHVybiBlcnJvcihFSU5WQUwsICJGYWlsZWQgdG8gc2V0IGJvdyBzdGF0ZSIpOwogICAgICAgICB9CiAgICAgfQotICAgIGlmIChhbmRyb2lkOjpiYXNlOjpSZW1vdmVGaWxlSWZFeGlzdHMoa01ldGFkYXRhQ1BGaWxlLCAmZXJyX3N0cikpCi0gICAgICAgIHJldHVybiBTdGF0dXM6OmZyb21FeGNlcHRpb25Db2RlKGVycm5vLCBlcnJfc3RyLmNfc3RyKCkpOworICAgIFNldFByb3BlcnR5KCJ2b2xkLmNoZWNrcG9pbnRfY29tbWl0dGVkIiwgIjEiKTsKKyAgICBMT0coSU5GTykgPDwgIkNoZWNrcG9pbnQgaGFzIGJlZW4gY29tbWl0dGVkLiI7CisgICAgaXNDaGVja3BvaW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XNsZWVwdGltZSAqIDEwMDAwMDA7CisgICAgd2hpbGUgKGlzQ2hlY2twb2ludGluZykgeworICAgICAgICB1aW50NjRfdCBmcmVlX2J5dGVzID0gMDsKKyAgICAgICAgaWYgKGlzX2ZzX2NwKSB7CisgICAgICAgICAgICBzdGF0dmZzKG1udF9wbnQuY19zdHIoKSwgJmRhdGEpOworICAgICAgICAgICAgZnJlZV9ieXRlcyA9ICgodWludDY0X3QpIGRhdGEuZl9iYXZhaWwpICogZGF0YS5mX2Zyc2l6ZTsKKyAgICAgICAgfSBlbHNlIHsKKyAgICAgICAgICAgIHN0ZDo6c3RyaW5nIGJvd19kZXZpY2UgPSBmc19tZ3JfZmluZF9ib3dfZGV2aWNlKGJsa19kZXZpY2UpOworICAgICAgICAgICAgaWYgKCFib3dfZGV2aWNlLmVtcHR5KCkpIHsKKyAgICAgICAgICAgICAgICBzdGQ6OnN0cmluZyBjb250ZW50OworICAgICAgICAgICAgICAgIGlmIChhbmRyb2lkOjpiYXNlOjpSZWFkRmlsZVRvU3RyaW5nKGJvd19kZXZpY2UgKyAiL2Jvdy9mcmVlIiwgJmNvbnRlbnQpKSB7CisgICAgICAgICAgICAgICAgICAgIGZyZWVfYnl0ZXMgPSBzdGQ6OnN0cnRvdWxsKGNvbnRlbnQuY19zdHIoKSwgTlVMTCwgMTApOworICAgICAgICAgICAgICAgIH0KKyAgICAgICAgICAgIH0KKyAgICAgICAgfQorICAgICAgICBpZiAoZnJlZV9ieXRlcyA8IG1pbl9mcmVlX2J5dGVzKSB7CisgICAgICAgICAgICBpZiAoY29tbWl0X29uX2Z1bGwpIHsKKyAgICAgICAgICAgICAgICBMT0coSU5GTykgPDwgIkxvdyBzcGFjZSBmb3IgY2hlY2twb2ludGluZy4gQ29tbWl0aW5nIGNoYW5nZXMiOworICAgICAgICAgICAgICAgIGNwX2NvbW1pdENoYW5nZXMoKTsKKyAgICAgICAgICAgICAgICBicmVhazsKKyAgICAgICAgICAgIH0gZWxzZSB7CisgICA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U6OnVuaXF1ZV9mZCBmZCgKLSAgICAgICAgICAgICAgICBURU1QX0ZBSUxVUkVfUkVUUlkob3Blbihtb3VudF9yZWMtPm1vdW50X3BvaW50LCBPX1JET05MWSB8IE9fQ0xPRVhFQykpKTsKLSAgICAgICAgICAgIGlmICghZmQpIHsKLSAgICAgICAgICAgICAgICBQTE9HKEVSUk9SKSA8PCAiRmFpbGVkIHRvIG9wZW4gbW91bnQgcG9pbnQiIDw8IG1vdW50X3JlYy0+bW91bnRfcG9pbnQ7CisgICAgICAgICAgICAgICAgVEVNUF9GQUlMVVJFX1JFVFJZKG9wZW4obW91bnRfcmVjLm1vdW50X3BvaW50LmNfc3RyKCksIE9fUkRPTkxZIHwgT19DTE9FWEVDKSkpOworICAgICAgICAgICAgaWYgKGZkID09IC0xKSB7CisgICAgICAgICAgICAgICAgUExPRyhFUlJPUikgPDwgIkZhaWxlZCB0byBvcGVuIG1vdW50IHBvaW50IiA8PCBtb3VudF9yZWMubW91bnRfcG9pbnQ7CiAgICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICB9CiAKICAgICAgICAgICAgIHN0cnVjdCBmc3RyaW1fcmFuZ2UgcmFuZ2UgPSB7fTsKICAgICAgICAgICAgIHJhbmdlLmxlbiA9IFVMTE9OR19NQVg7CisgICAgICAgICAgICBuc2Vjc190IHN0YXJ0ID0gc3lzdGVtVGltZShTWVNURU1fVElNRV9CT09UVElNRSk7CiAgICAgICAgICAgICBpZiAoaW9jdGwoZmQsIEZJVFJJTSwgJnJhbmdlKSkgewotICAgICAgICAgICAgICAgIFBMT0coRVJST1IpIDw8ICJGYWlsZWQgdG8gdHJpbSAiIDw8IG1vdW50X3JlYy0+bW91bnRfcG9pbnQ7CisgICAgICAgICAgICAgICAgUExPRyhFUlJPUikgPDwgIkZhaWxlZCB0byB0cmltICIgPDwgbW91bnRfcmVjLm1vdW50X3BvaW50OwogICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgfQorICAgICAgICAgICAgbnNlY3NfdCB0aW1lID0gc3lzdGVtVGltZShTWVNURU1fVElNRV9CT09UVElNRSkgLSBzdGFydDsKKyAgICAgICAgICAgIExPRyhJTkZPKSA8PCAiVHJpbW1lZCAiIDw8IHJhbmdlLmxlbiA8PCAiIGJ5dGVzIG9uICIgPDwgbW91bnRfcmVjLm1vdW50X3BvaW50IDw8ICIgaW4gIgorICAgICAgICAgICAgICAgICAgICAgIDw8IG5hbm9zZWNvbmRzX3RvX21pbGxpc2Vjb25kcyh0aW1lKSA8PCAibXMgZm9yIGNoZWNrcG9pbnQiOwogCi0gICAgICAgICAgICBzZXRCb3dTdGF0ZShtb3VudF9yZWMtPmJsa19kZXZpY2UsICIxIik7CisgICAgICAgICAgICBzZXRCb3dTdGF0ZShtb3VudF9yZWMuYmxrX2RldmljZSwgIjEiKTsKKyAgICAgICAgfQorICAgICAgICBpZiAoZnN0YWJfcmVjLT5mc19tZ3JfZmxhZ3MuY2hlY2twb2ludF9ibGsgfHwgZnN0YWJfcmVjLT5mc19tZ3JfZmxhZ3MuY2hlY2twb2ludF9mcykgeworICAgICAgICAgICAgc3RkOjp0aHJlYWQoY3BfaGVhbHRoRGFlbW9uLCBzdGQ6OnN0cmluZyhtb3VudF9yZWMubW91bnRfcG9pbnQpLAorICAgICAgICAgICAgICAgICAgICAgICAgc3RkOjpzdHJpbmcobW91bnRfcmVjLmJsa19kZXZpY2UpLAorICAgICAgICAgICAgICAgICAgICAgICAgZnN0YWJfcmVjLT5mc19tZ3JfZmxhZ3MuY2hlY2twb2ludF9mcyA9PSAxKQorICAgICAgICAgICAgICAgIC5kZXRhY2goKTsKICAgICAgICAgfQogICAgIH0KICAgICByZXR1cm4gU3RhdHVzOjpvaygpOwogfQogCiBuYW1lc3BhY2UgewotY29uc3QgaW50IGtCbG9ja1NpemUgPSA0MDk2OwogY29uc3QgaW50IGtTZWN0b3JTaXplID0gNTEyOwogCiB0eXBlZGVmIHVpbnQ2NF90IHNlY3Rvcl90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AgICAgICAgICAgc3RkOjp2ZWN0b3I8Y2hhcj4gYnVmZmVyKGxlLT5zaXplKTsKLSAgICAgICAgICAgIGRldmljZS5zZWVrZyhsZS0+ZGVzdCAqIGtTZWN0b3JTaXplKTsKLSAgICAgICAgICAgIGRldmljZS5yZWFkKCZidWZmZXJbMF0sIGxlLT5zaXplKTsKKyAgICAgICAgICAgIFVzZWRfU2VjdG9ycyB1c2VkX3NlY3RvcnM7CisgICAgICAgICAgICB1c2VkX3NlY3RvcnNbMF0gPSBmYWxzZTsKIAotICAgICAgICAgICAgdWludDMyX3QgY2hlY2tzdW0gPSBsZS0+c291cmNlIC8gKGtCbG9ja1NpemUgLyBrU2VjdG9yU2l6ZSk7Ci0gICAgICAgICAgICBmb3IgKHNpemVfdCBpID0gMDsgaSA8IGxlLT5zaXplOyBpICs9IGtCbG9ja1NpemUpIHsKLSAgICAgICAgICAgICAgICBjcmMzMigmYnVmZmVyW2ldLCBrQmxvY2tTaXplLCAmY2hlY2tzdW0pOworICAgICAgICAgICAgaWYgKGxzLm1hZ2ljICE9IGtNYWdpYyAmJiAobHMubWFnaWMgIT0ga1BhcnRpYWxSZXN0b3JlTWFnaWMgfHwgdmFsaWRhdGluZykpIHsKKyAgICAgICAgICAgICAgICBzdGF0dXMgPSBlcnJvcihFSU5WQUwsICJObyBtYWdpYyIpOworICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgfQogCi0gICAgICAgICAgICBpZiAobGUtPmNoZWNrc3VtICYmIGNoZWNrc3VtICE9IGxlLT5jaGVja3N1bSkgewotICAgICAgICAgICAgICAgIExPRyhFUlJPUikgPDwgIkNoZWNrc3VtcyBkb24ndCBtYXRjaCAiIDw8IHN0ZDo6aGV4IDw8IGNoZWNrc3VtOwotICAgICAgICAgICAgICAgIHJldHVybiBTdGF0dXM6OmZyb21FeGNlcHRpb25Db2RlKEVJTlZBTCwgIkNoZWNrc3VtcyBkb24ndCBtYXRjaCIpOworICAgICAgICAgICAgaWYgKGxzLmJsb2NrX3NpemUgIT0gb3JpZ2luYWxfbHMuYmxvY2tfc2l6ZSkgeworICAgICAgICAgICAgICAgIHN0YXR1cyA9IGVycm9yKEVJTlZBTCwgIkJsb2NrIHNpemUgbWlzbWF0Y2giKTsKKyAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgIH0KIAotICAgICAgICAgICAgZGV2aWNlLnNlZWtnKGxlLT5zb3VyY2UgKiBrU2VjdG9yU2l6ZSk7Ci0gICAgICAgICAgICBkZXZpY2Uud3JpdGUoJmJ1ZmZlclswXSwgbGUtPnNpemUpOworICAgICAgICAgICAgaWYgKChpbnQpbHMuc2VxdWVuY2UgIT0gc2VxdWVuY2UpIHsKKyAgICAgICAgICAgICAgICBzdGF0dXMgPSBlcnJvcihFSU5WQUwsICJFeHBlY3RpbmcgbG9nIHNlY3RvciAiICsgc3RkOjp0b19zdHJpbmcoc2VxdWVuY2UpICsKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAiIGJ1dCBnb3QgIiArIHN0ZDo6dG9fc3RyaW5nKGxzLnNlcXVlbmNlKSk7CisgICAgICAgICAgICAgICAgYnJlYWs7CisgICAgICAgICAgICB9CisKKyAgICAgICAgICAgIExPRyhJTkZPKSA8PCBhY3Rpb24gPDwgIiBmcm9tIGxvZyBzZWN0b3IgIiA8PCBscy5zZXF1ZW5jZTsKKyAgICAgICAgICAgIGZvciAobG9nX2VudHJ5KiBsZSA9CisgICAgICAgICAgICAgICAgICAgICByZWludGVycHJldF9jYXN0PGxvZ19lbnRyeSo+KCZsc19idWZmZXJbbHMuaGVhZGVyX3NpemVdKSArIGxzLmNvdW50IC0gMTsKKyAgICAgICAgICAgICAgICAgbGUgPj0gcmVpbnRlcnByZXRfY2FzdDxsb2dfZW50cnkqPigmbHNfYnVmZmVyW2xzLmhlYWRlcl9zaXplXSk7IC0tbGUpIHsKKyAgICAgICAgICAgICAgICAvLyBUaGlzIGlzIHZlcnkgbm9pc3kgLSBsaW1pdCB0byBERUJVRyBvbmx5CisgICAgICAgICAgICAgICAgTE9HKFZFUkJPU0UpIDw8IGFjdGlvbiA8PCAiICIgPDwgbGUtPnNpemUgPDwgIiBieXRlcyBmcm9tIHNlY3RvciAiIDw8IGxlLT5kZXN0CisgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDw8ICIgdG8gIiA8PCBsZS0+c291cmNlIDw8ICIgd2l0aCBjaGVja3N1bSAiIDw8IHN0ZDo6aGV4CisgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDw8IGxlLT5jaGVja3N1bTsKKworICAgICAgICAgICAgICAgIGF1dG8gYnVmZmVyID0gcmVsb2NhdGVkUmVhZChkZXZpY2VfZmQsIHJlbG9jYXRpb25zLCB2YWxpZGF0aW5nLCBsZS0+ZGVzdCwgbGUtPnNpemUsCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxzLmJsb2NrX3NpemUpOworICAgICAgICAgICAgICAgIHVpbnQzMl90IGNoZWNrc3VtID0gbGUtPnNvdXJjZSAvIChscy5ibG9ja19zaXplIC8ga1NlY3RvclNpemUpOworICAgICAgICAgICAgICAgIGZvciAoc2l6ZV90IGkgPSAwOyBpIDwgbGUtPnNpemU7IGkgKz0gbHMuYmxvY2tfc2l6ZSkgeworICAgICAgICAgICAgICAgICAgICBjcmMzMigmYnVmZmVyW2ldLCBscy5ibG9ja19zaXplLCAmY2hlY2tzdW0pOworICAgICAgICAgICAgICAgIH0KKworICAgICAgICAgICAgICAgIGlmIChsZS0+Y2hlY2tzdW0gJiYgY2hlY2tzdW0gIT0gbGUtPmNoZWNrc3VtKSB7CisgICAgICAgICAgICAgICAgICAgIHN0YXR1cyA9IGVycm9yKEVJTlZBTCwgIkNoZWNrc3VtcyBkb24ndCBtYXRjaCIpOworICAgICAgICAgICAgICAgICAgICBicmVhazsKKyAgICAgICAgICAgICAgICB9CisKKyAgICAgICAgICAgICAgICBpZiAodmFsaWRhdGluZykgeworICAgICAgICAgICAgICAgICAgICByZWxvY2F0ZShyZWxvY2F0aW9ucywgbGUtPnNvdXJjZSwgbGUtPmRlc3QsIChsZS0+c2l6ZSAtIDEpIC8ga1NlY3RvclNpemUgKyAxKTsKKyAgICAgICAgICAgICAgICB9IGVsc2UgeworICAgICAgICAgICAgICAgICAgICByZXN0b3JlU2VjdG9yKGRldmljZV9mZCwgdXNlZF9zZWN0b3JzLCBsc19idWZmZXIsIGxlLCBidWZmZXIpOworICAgICAgICAgICAgICAgICAgICByZXN0b3JlX2NvdW50Kys7CisgICAgICAgICAgICAgICAgICAgIGlmIChyZXN0b3JlX2xpbWl0ICYmIHJlc3RvcmVfY291bnQgPj0gcmVzdG9yZV9saW1pdCkgeworICAgICAgICAgICAgICAgICAgICAgICAgc3RhdHVzID0gZXJyb3IoRUFHQUlOLCAiSGl0IHRoZSB0ZXN0IGxpbWl0Iik7CisgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKKyAgICAgICAgICAgICAgICAgICAgfQorICAgICAgICAgICAgICAgIH0KKyAgICAgICAgICAgIH0KICAgICAgICAgfQorCisgICAgICAgIGlmICghc3RhdHVzLmlzT2soKSkgeworICAgICAgICAgICAgaWYgKCF2YWxpZGF0aW5nKSB7CisgICAgICAgICAgICAgICAgTE9HKEVSUk9SKSA8PCAiQ2hlY2twb2ludCByZXN0b3JlIGZhaWxlZCBldmVuIHRob3VnaCBjaGVja3BvaW50IHZhbGlkYXRpb24gcGFzc2VkIjsKKyAgICAgICAgICAgICAgICByZXR1cm4gc3RhdHVzOworICAgICAgICAgICAgfQorCisgICAgICAgICAgICBMT0coV0FSTklORykgPDwgIkNoZWNrcG9pbnQgdmFsaWRhdGlvbiBmYWlsZWQgLSBhdHRlbXB0aW5nIHRvIHJvbGwgZm9yd2FyZCI7CisgICAgICAgICAgICBhdXRvIGJ1ZmZlciA9IHJlbG9jYXRlZFJlYWQoZGV2aWNlX2ZkLCByZWxvY2F0aW9ucywgZmFsc2UsIG9yaWdpbmFsX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gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLnNldF9rZXlzaXplKDY0KTsKKworY29uc3RleHByIENyeXB0b1R5cGUgYWRpYW50dW0gPSBDcnlwdG9UeXBlKCkKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAuc2V0X2NvbmZpZ19uYW1lKCJhZGlhbnR1bSIpCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLnNldF9rZXJuZWxfbmFtZSgieGNoYWNoYTEyLGFlcy1hZGlhbnR1bS1wbGFpbjY0IikKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAuc2V0X2tleXNpemUoMzIpOworCisvLyBTdXBwb3J0IGNvbXBpbGUtdGltZSB2YWxpZGF0aW9uIG9mIGEgY3J5cHRvIHR5cGUgdGFibGUKKwordGVtcGxhdGUgPHR5cGVuYW1lIFQsIHNpemVfdCBOPgorY29uc3RleHByIHNpemVfdCBhcnJheV9sZW5ndGgoVCAoJilbTl0pIHsKKyAgICByZXR1cm4gTjsKK30KKworY29uc3RleHByIGJvb2wgaXNWYWxpZENyeXB0b1R5cGUoc2l6ZV90IG1heF9rZXlsZW4sIGNvbnN0IENyeXB0b1R5cGUmIGNyeXB0b190eXBlKSB7CisgICAgcmV0dXJuICgoY3J5cHRvX3R5cGUuZ2V0X2NvbmZpZ19uYW1lKCkgIT0gbnVsbHB0cikgJiYKKyAgICAgICAgICAgIChjcnlwdG9fdHlwZS5nZXRfa2VybmVsX25hbWUoKSAhPSBudWxscHRyKSAmJgorICAgICAgICAgICAgKGNyeXB0b190eXBlLmdldF9rZXlzaXplKCkgPD0gbWF4X2tleWxlbikpOworfQorCisvLyBDb25maXJtcyB0aGF0IGFsbCBzdXBwb3J0ZWRfY3J5cHRvX3R5cGVzIGhhdmUgYSBzbWFsbCBlbm91Z2gga2V5c2l6ZSBhbmQKKy8vIGhhZCBib3RoIHNldF9jb25maWdfbmFtZSgpIGFuZ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ZXR0aW1lKENMT0NLX01PTk9UT05JQywgJnRpbWVfc3RhcnRlZCkpIHsKKyAgICAgICAgTE9HKFdBUk5JTkcpIDw8ICJFcnJvciBnZXR0aW5nIHRpbWUgYXQgc3RhcnQiOworICAgICAgICAvLyBOb3RlIC0gY29udGludWUgYW55d2F5IC0gd2UnbGwgcnVuIHdpdGggMAorICAgIH0KKyAgICBkYXRhLnRpbWVfc3RhcnRlZCA9IHRpbWVfc3RhcnRlZC50dl9zZWM7CiAgICAgZGF0YS5yZW1haW5pbmdfdGltZSA9IC0xOwogCisKICAgICBkYXRhLmJ1ZmZlciA9IChjaGFyKiltYWxsb2MoZjJmc19pbmZvLT5ibG9ja19zaXplKTsKICAgICBpZiAoIWRhdGEuYnVmZmVyKSB7CiAgICAgICAgIExPRyhFUlJPUikgPDwgIkZhaWxlZCB0byBhbGxvY2F0ZSBjcnlwdG8gYnVmZmVyIjsKQEAgLTQ1Nyw4ICs0NjUsOCBAQAogICAgIHJldHVybiByYzsKIH0KIAotc3RhdGljIGludCBjcnlwdGZzX2VuYWJsZV9pbnBsYWNlX2Z1bGwoY2hhciogY3J5cHRvX2Jsa2RldiwgY2hhciogcmVhbF9ibGtkZXYsIG9mZjY0X3Qgc2l6ZSwKLSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9mZjY0X3QqIHNpemVfYWxyZWFkeV9kb25lLCBvZmY2NF90IHRvdF9zaXplLAorc3RhdGljIGludCBjcnlwdGZzX2VuYWJsZV9pbnBsYWNlX2Z1bGwoY29uc3QgY2hhciogY3J5cHRvX2Jsa2RldiwgY29uc3QgY2hhciogcmVhbF9ibGtkZXYsCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvZmY2NF90IHNpemUsIG9mZjY0X3QqIHNpemVfYWxyZWFkeV9kb25lLCBvZmY2NF90IHRvdF9zaXplLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb2ZmNjRfdCBwcmV2a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AgLy8gZm9yIGRldmljZXMgbGF1bmNoaW5nIG9uIHZlcnNpb25zIGFib3ZlIEFuZHJvaWQgMTAuCisgICAgYXV0byBmaXJzdF9hcGlfbGV2ZWwgPSBHZXRGaXJzdEFwaUxldmVsKCk7CisgICAgY29uc3RleHByIHVpbnQ2NF90IHByZV9na2lfbGV2ZWwgPSAyOTsKKyAgICBhdXRvIGZpbGVuYW1lc19tb2RlID0KKyAgICAgICAgICAgIGFuZHJvaWQ6OmJhc2U6OkdldFByb3BlcnR5KCJyby5jcnlwdG8udm9sdW1lLmZpbGVuYW1lc19tb2RlIiwKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZpcnN0X2FwaV9sZXZlbCA+IHByZV9na2lfbGV2ZWwgPyAiIiA6ICJhZXMtMjU2LWhlaCIpOworICAgIGF1dG8gb3B0aW9uc19zdHJpbmcgPSBhbmRyb2lkOjpiYXNlOjpHZXRQcm9wZXJ0eSgicm8uY3J5cHRvLnZvbHVtZS5vcHRpb25zIiwKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29udGVudHNfbW9kZSArICI6IiArIGZpbGVuYW1lc19tb2RlKTsKKyAgICBpZiAoIVBhcnNlT3B0aW9uc0ZvckFwaUxldmVsKGZpcnN0X2FwaV9sZXZlbCwgb3B0aW9uc19zdHJpbmcsIG9wdGlvbnMpKSB7CisgICAgICAgIExPRyhFUlJPUikgPDwgIlVuYWJsZSB0byBwYXJzZSB2b2x1bWUgZW5jcnlwdGlvbiBvcHRpb25zOiAiIDw8IG9wdGlvbnNfc3RyaW5nOworICAgICAgICByZXR1cm4gZmFsc2U7CisgICAgfQorICAgIHJldHVybiB0cnVlOworfQorCiBzdGF0aWMgYm9vbCByZWFkX2FuZF9pbnN0YWxsX3VzZXJfY2Vfa2V5KHVzZXJpZF90IHVzZXJfaWQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvb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sc2U7CiAKICAgICAgICAgaWYgKGZzY3J5cHRfaXNfbmF0aXZlKCkpIHsKLSAgICAgICAgICAgIFBvbGljeUtleVJlZiBkZV9yZWY7CisgICAgICAgICAgICBFbmNyeXB0aW9uUG9saWN5IGRlX3BvbGljeTsKICAgICAgICAgICAgIGlmICh2b2x1bWVfdXVpZC5lbXB0eSgpKSB7Ci0gICAgICAgICAgICAgICAgaWYgKCFsb29rdXBfa2V5X3JlZihzX2RlX2tleV9yYXdfcmVmcywgdXNlcl9pZCwgJmRlX3JlZi5rZXlfcmF3X3JlZikpIHJldHVybiBmYWxzZTsKLSAgICAgICAgICAgICAgICBnZXRfZGF0YV9maWxlX2VuY3J5cHRpb25fbW9kZXMoJmRlX3JlZik7Ci0gICAgICAgICAgICAgICAgaWYgKCFlbnN1cmVfcG9saWN5KGRlX3JlZiwgc3lzdGVtX2RlX3BhdGgpKSByZXR1cm4gZmFsc2U7Ci0gICAgICAgICAgICAgICAgaWYgKCFlbnN1cmVfcG9saWN5KGRlX3JlZiwgbWlzY19kZV9wYXRoKSkgcmV0dXJuIGZhbHNlOwotICAgICAgICAgICAgICAgIGlmICghZW5zdXJlX3BvbGljeShkZV9yZWYsIHZlbmRvcl9kZV9wYXRoKSkgcmV0dXJuIGZhbHNlOworICAgICAgICAgICAgICAgIGlmICghbG9va3VwX3BvbGljeShzX2RlX3BvbGljaWVzLCB1c2VyX2lkLCAmZGVfcG9saWN5KSkgcmV0dXJuIGZhbHNlOworICAgICAgICAgICAgICAgIGlmICghRW5zdXJlUG9saWN5KGRlX3BvbGljeSwgc3lzdGVtX2RlX3BhdGgpKSByZXR1cm4gZmFsc2U7CisgICAgICAgICAgICAgICAgaWYgKCFFbnN1cmVQb2xpY3koZGVfcG9saWN5LCBtaXNjX2RlX3BhdGgpKSByZXR1cm4gZmFsc2U7CisgICAgICAgICAgICAgICAgaWYgKCFFbnN1cmVQb2xpY3koZGVfcG9saWN5LCB2ZW5kb3JfZGVfcGF0aCkpIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgIH0gZWxzZSB7Ci0gICAgICAgICAgICAgICAgaWYgKCFyZWFkX29yX2NyZWF0ZV92b2xrZXkobWlzY19kZV9wYXRoLCB2b2x1bWVfdXVpZCwgJmRlX3JlZikpIHJldHVybiBmYWxzZTsKKyAgICAgICAgICAgICAgICBpZiAoIXJlYWRfb3JfY3JlYXRlX3ZvbGtleShtaXNjX2RlX3BhdGgsIHZvbHVtZV91dWlkLCAmZGVfcG9saWN5KSkgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICAgfQotICAgICAgICAgICAgaWYgKCFlbnN1cmVfcG9saWN5KGRlX3JlZiwgdXNlcl9kZV9wYXRoKSkgcmV0dXJuIGZhbHNlOworICAgICAgICAgICAgaWYgKCFFbnN1cmVQb2xpY3koZGVfcG9saWN5LCB1c2VyX2RlX3BhdGgpKSByZXR1cm4gZmFsc2U7CiAgICAgICAgIH0KICAgICB9CiAKQEAgLTcxNCwxOSArODI0LDE3IEBACiAgICAgICAgIGlmICghcHJlcGFyZV9kaXIodXNlcl9jZV9wYXRoLCAwNzcxLCBBSURfU1lTVEVNLCBBSURfU1lTVEVNKSkgcmV0dXJuIGZhbHNlOwogCiAgICAgICAgIGlmIChmc2NyeXB0X2lzX25hdGl2ZSgpKSB7Ci0gICAgICAgICAgICBQb2xpY3lLZXlSZWYgY2VfcmVmOworICAgICAgICAgICAgRW5jcnlwdGlvblBvbGljeSBjZV9wb2xpY3k7CiAgICAgICAgICAgICBpZiAodm9sdW1lX3V1aWQuZW1wdHkoKSkgewotICAgICAgICAgICAgICAgIGlmICghbG9va3VwX2tleV9yZWYoc19jZV9rZXlfcmF3X3JlZnMsIHVzZXJfaWQsICZjZV9yZWYua2V5X3Jhd19yZWYpKSByZXR1cm4gZmFsc2U7Ci0gICAgICAgICAgICAgICAgZ2V0X2RhdGFfZmlsZV9lbmNyeXB0aW9uX21vZGVzKCZjZV9yZWYpOwotICAgICAgICAgICAgICAgIGlmICghZW5zdXJlX3BvbGljeShjZV9yZWYsIHN5c3RlbV9jZV9wYXRoKSkgcmV0dXJuIGZhbHNlOwotICAgICAgICAgICAgICAgIGlmICghZW5zdXJlX3BvbGljeShjZV9yZWYsIG1pc2NfY2VfcGF0aCkpIHJldHVybiBmYWxzZTsKLSAgICAgICAgICAgICAgICBpZiAoIWVuc3VyZV9wb2xpY3koY2VfcmVmLCB2ZW5kb3JfY2VfcGF0aCkpIHJldHVybiBmYWxzZTsKLQorICAgICAgICAgICAgICAgIGlmICghbG9va3VwX3BvbGljeShzX2NlX3BvbGljaWVzLCB1c2VyX2lkLCAmY2VfcG9saWN5KSkgcmV0dXJuIGZhbHNlOworICAgICAgICAgICAgICAgIGlmICghRW5zdXJlUG9saWN5KGNlX3BvbGljeSwgc3lzdGVtX2NlX3BhdGgpKSByZXR1cm4gZmFsc2U7CisgICAgICAgICAgICAgICAgaWYgKCFFbnN1cmVQb2xpY3koY2VfcG9saWN5LCBtaXNjX2NlX3BhdGgpKSByZXR1cm4gZmFsc2U7CisgICAgICAgICAgICAgICAgaWYgKCFFbnN1cmVQb2xpY3koY2VfcG9saWN5LCB2ZW5kb3JfY2VfcGF0aCkpIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgIH0gZWxzZSB7Ci0gICAgICAgICAgICAgICAgaWYgKCFyZWFkX29yX2NyZWF0ZV92b2xrZXkobWlzY19jZV9wYXRoLCB2b2x1bWVfdXVpZCwgJmNlX3JlZikpIHJldHVybiBmYWxzZTsKKyAgICAgICAgICAgICAgICBpZiAoIXJlYWRfb3JfY3JlYXRlX3ZvbGtleShtaXNjX2NlX3BhdGgsIHZvbHVtZV91dWlkLCAmY2VfcG9saWN5KSkgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICAgfQotICAgICAgICAgICAgaWYgKCFlbnN1cmVfcG9saWN5KGNlX3JlZiwgbWVkaWFfY2VfcGF0aCkpIHJldHVybiBmYWxzZTsKLSAgICAgICAgICAgIGlmICghZW5zdXJlX3BvbGljeShjZ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UkRPTkxZKSB7CisgICAgICAgIC8vIFNraXAgcmVhZC1vbmx5IGZpbGVzeXN0ZW1zCisgICAgICAgIGlmIChlbnRyeS5mbGFncyAmIE1TX1JET05MWSkgewogICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgIH0KLSAgICAgICAgaWYgKGZzX21ncl9pc192b2xkbWFuYWdlZCgmZnN0YWItPnJlY3NbaV0pKSB7Ci0gICAgICAgICAgICBjb250aW51ZTsgLyogU2hvdWxkIHdlIHRyaW0gZmF0MzIgZmlsZXN5c3RlbXM/ICovCisgICAgICAgIGlmIChlbnRyeS5mc19tZ3JfZmxhZ3Mudm9sZF9tYW5hZ2VkKSB7CisgICAgICAgICAgICBjb250aW51ZTsgIC8vIFNob3VsZCB3ZSB0cmltIGZhdDMyIGZpbGVzeXN0ZW1zPwogICAgICAgICB9Ci0gICAgICAgIGlmIChmc19tZ3JfaXNfbm90cmltKCZmc3RhYi0+cmVjc1tpXSkpIHsKKyAgICAgICAgaWYgKGVudHJ5LmZzX21ncl9mbGFncy5ub190cmltKSB7CiAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgfQogCi0gICAgICAgIC8qIFNraXAgdGhlIG11bHRpLXR5cGUgcGFydGl0aW9ucywgd2hpY2ggYXJlIHJlcXVpcmVkIHRvIGJlIGZvbGxvd2luZyBlYWNoIG90aGVyLgotICAgICAgICAgKiBTZWUgZnNfbWdyLmMncyBtb3VudF93aXRoX2FsdGVybmF0aXZlcygpLgotICAgICAgICAgKi8KLSAgICAgICAgaWYgKHByZXZfcmVjICYmICFzdHJjbXAocHJldl9yZWMtPm1vdW50X3BvaW50LCBmc3RhYi0+cmVjc1tpXS5tb3VudF9wb2ludCkpIHsKKyAgICAgICAgLy8gU2tpcCB0aGUgbXVsdGktdHlwZSBwYXJ0aXRpb25zLCB3aGljaCBhcmUgcmVxdWlyZWQgdG8gYmUgZm9sbG93aW5nIGVhY2ggb3RoZXIuCisgICAgICAgIC8vIFNlZSBmc19tZ3IuYydzIG1vdW50X3dpdGhfYWx0ZXJuYXRpdmVzKCkuCisgICAgICAgIGlmIChlbnRyeS5tb3VudF9wb2ludCA9PSBwcmV2aW91c19tb3VudF9wb2ludCkgewogICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgIH0KIAogICAgICAgICBpZiAocGF0aF90eXBlID09IFBhdGhUeXBlczo6a01vdW50UG9pbnQpIHsKLSAgICAgICAgICAgIHBhdGhzLT5wdXNoX2JhY2soZnN0YWItPnJlY3NbaV0ubW91bnRfcG9pbnQpOworICAgICAgICAgICAgcGF0aHMtPnB1c2hfYmFjayhlbnRyeS5tb3VudF9wb2ludCk7CiAgICAgICAgIH0gZWxzZSBpZiAocGF0aF90eXBlID09IFBhdGhUeXBlczo6a0Jsa0RldmljZSkgewogICAgICAgICAgICAgc3RkOjpzdHJpbmcgZ2NfcGF0aDsKLSAgICAgICAgICAgIGlmIChzdGQ6OnN0cmluZyhmc3RhYi0+cmVjc1tpXS5mc190eXBlKSA9PSAiZjJmcyIgJiYKLSAgICAgICAgICAgICAgICBSZWFscGF0aCgKLSAgICAgICAgICAgICAgICAgICAgYW5kcm9pZDo6dm9sZDo6QmxvY2tEZXZpY2VGb3JQYXRoKHN0ZDo6c3RyaW5nKGZzdGFiLT5yZWNzW2ldLm1vdW50X3BvaW50KSArICIvIiksCi0gICAgICAgICAgICAgICAgICAgICZnY19wYXRoKSkgewotICAgICAgICAgICAgICAgIHBhdGhzLT5wdXNoX2JhY2soc3RkOjpzdHJpbmcoIi9zeXMvZnMvIikgKyBmc3RhYi0+cmVjc1tpXS5mc190eXBlICsgIi8iICsKLSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEJhc2VuYW1lKGdjX3BhdGgpKTsKKyAgICAgICAgICAgIGlmIChlbnRyeS5mc190eXBlID09ICJmMmZzIiAmJgorICAgICAgICAgICAgICAgIFJlYWxwYXRoKGFuZHJvaWQ6OnZvbGQ6OkJsb2NrRGV2aWNlRm9yUGF0aChlbnRyeS5tb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ICAgTE9HKEVSUk9SKSA8PCAiRGVmZXJlZCBLZXkgZGVsZXRpb24gZmFpbGVkIGR1cmluZyB1cGdyYWRlIjsKKyAgICB9Cit9CisKK2Jvb2wga21EZWxldGVLZXkoS2V5bWFzdGVyJiBrZXltYXN0ZXIsIGNvbnN0IHN0ZDo6c3RyaW5nJiBrbUtleSkgeworICAgIGJvb2wgbmVlZHNfY3AgPSBjcF9uZWVkc0NoZWNrcG9pbnQoKTsKKworICAgIGlmIChuZWVkc19jcCkgeworICAgICAgICBzdGQ6OnRocmVhZChkZWZlcmVkS21EZWxldGVLZXksIGttS2V5KS5kZXRhY2goKTsKKyAgICAgICAgTE9HKElORk8pIDw8ICJEZWZlcnJpbmcgS2V5IGRlbGV0aW9uIGR1cmluZyB1cGdyYWRlIjsKKyAgICAgICAgcmV0dXJuIHRydWU7CisgICAgfSBlbHNlIHsKKyAgICAgICAgcmV0dXJuIGtleW1hc3Rlci5kZWxldGVLZXkoa21LZXkpOworICAgIH0KK30KKwogc3RhdGljIEtleW1hc3Rlck9wZXJhdGlvbiBiZWdpbihLZXltYXN0ZXImIGtleW1hc3RlciwgY29uc3Qgc3RkOjpzdHJpbmcmIGRpciwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAga206OktleVB1cnBvc2UgcHVycG9zZSwgY29uc3Qga206OkF1dGhvcml6YXRpb25TZXQmIGtleVBhcmFtcywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3Qga206OkF1dGhvcml6YXRpb25TZXQmIG9wUGFyYW1zLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBrbTo6SGFyZHdhcmVBdXRoVG9rZW4mIGF1dGhUb2tlbiwKLSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAga206OkF1dGhvcml6YXRpb25TZXQqIG91dFBhcmFtcykgeworICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBrbTo6QXV0aG9yaXphdGlvblNldCogb3V0UGFyYW1z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LZXlQYXRoLmNfc3RyKCksIGttS2V5UGF0aC5jX3N0cigpKSAhPSAwKSB7CisgICAgICAgICAgICAgICAgUExPRyhFUlJPUikgPDwgIlVuYWJsZSB0byBtb3ZlIHVwZ3JhZGVkIGtleSB0byBsb2NhdGlvbjogIiA8PCBrbUtleVBhdGg7CisgICAgICAgICAgICAgICAgcmV0dXJuIEtleW1hc3Rlck9wZXJhdGlvbigpOworICAgICAgICAgICAgfQorICAgICAgICAgICAgaWYgKCFhbmRyb2lkOjp2b2xkOjpGc3luY0RpcmVjdG9yeShkaXIpKSB7CisgICAgICAgICAgICAgICAgTE9HKEVSUk9SKSA8PCAiS2V5IGRpciBzeW5jIGZhaWxlZDogIiA8PCBkaXI7CisgICAgICAgICAgICAgICAgcmV0dXJuIEtleW1hc3Rlck9wZXJhdGlvbigpOworICAgICAgICAgICAgfQorICAgICAgICAgICAgaWYgKCFrbURlbGV0ZUtleShrZXltYXN0ZXIsIGttS2V5KSkgeworICAgICAgICAgICAgICAgIExPRyhFUlJPUikgPDwgIktleSBkZWxldGlvbiBmYWlsZWQgZHVyaW5nIHVwZ3JhZGUsIGNvbnRpbnVpbmcgYW55d2F5OiAiIDw8IGRpcjsKKyAgICAgICAgICAgIH0KICAgICAgICAgfQogICAgICAgICBrbUtleSA9IG5ld0tleTsKICAgICAgICAgTE9HKElORk8pIDw8ICJLZXkgdXBncmFkZWQ6ICIgPDwgZGlyOwpAQCAtMjMzLDEyICsyNjgsMTIgQEAKIAogc3RhdGljIGJvb2wgZW5jcnlwdFdpdGhLZXltYXN0ZXJLZXkoS2V5bWFzdGVyJiBrZXltYXN0ZXIsIGNvbnN0IHN0ZDo6c3RyaW5nJiBkaXIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBrbTo6QXV0aG9yaXphdGlvblNldCYga2V5UGFyYW1zLAotICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3Qga206OkhhcmR3YXJlQXV0aFRva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zdGQ6OnN0cmluZyYgZGlyLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3Qga206OkF1dGhvcml6YXRpb25TZXQmIGtleVBhcmFtcywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IGttOjpIYXJkd2FyZUF1dGhUb2tlbiYgYXV0aFRva2VuLAotICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3Qgc3RkOjpzdHJpbmcmIGNpcGhlcnRleHQsIEtleUJ1ZmZlciogbWVzc2FnZSkgeworICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3Qgc3RkOjpzdHJpbmcmIGNpcGhlcnRleHQsIEtleUJ1ZmZlciogbWVzc2FnZSwKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJvb2wga2VlcE9sZCkgewogICAgIGF1dG8gbm9uY2UgPSBjaXBoZXJ0ZXh0LnN1YnN0cigwLCBHQ01fTk9OQ0VfQllURVMpOwogICAgIGF1dG8gYm9keUFuZE1hYyA9IGNpcGhlcnRleHQuc3Vic3RyKEdDTV9OT05DRV9CWVRFUyk7CiAgICAgYXV0byBvcFBhcmFtcyA9IGttOjpBdXRob3JpemF0aW9uU2V0QnVpbGRlcigpLkF1dGhvcml6YXRpb24oa206OlRBR19OT05DRSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBrbTo6c3VwcG9ydDo6YmxvYjJoaWRsVmVjKG5vbmNlKSk7Ci0gICAgYXV0byBvcEhhbmRsZSA9Ci0gICAgICAgIGJlZ2luKGtleW1hc3RlciwgZGlyLCBrbTo6S2V5UHVycG9zZTo6REVDUllQVCwga2V5UGFyYW1zLCBvcFBhcmFtcywgYXV0aFRva2VuLCBudWxscHRyKTsKKyAgICBhdXRvIG9wSGFuZGxlID0gYmVnaW4oa2V5bWFzdGVyLCBkaXIsIGttOjpLZXlQd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c0tleXJpbmdTdXBwb3J0ZWQodm9pZCkgeworICAgIHN0YXRpYyBib29sIGluaXRpYWxpemVkID0gZmFsc2U7CisgICAgc3RhdGljIGJvb2wgc3VwcG9ydGVkOworCisgICAgaWYgKCFpbml0aWFsaXplZCkgeworICAgICAgICBhbmRyb2lkOjpiYXNlOjp1bmlxdWVfZmQgZmQob3BlbigiL2RhdGEiLCBPX1JET05MWSB8IE9fRElSRUNUT1JZIHwgT19DTE9FWEVDKSk7CisKKyAgICAgICAgLy8gRlNfSU9DX0FERF9FTkNSWVBUSU9OX0tFWSB3aXRoIGEgTlVMTCBhcmd1bWVudCB3aWxsIGZhaWwgd2l0aCBFTk9UVFkKKyAgICAgICAgLy8gaWYgdGhlIGlvY3RsIGlzbid0IHN1cHBvcnRlZC4gIE90aGVyd2lzZSBpdCB3aWxsIGZhaWwgd2l0aCBhbm90aGVyCisgICAgICAgIC8vIGVycm9yIGNvZGUgc3VjaCBhcyBFRkFVTFQuCisgICAgICAgIGVycm5vID0gMDsKKyAgICAgICAgKHZvaWQpaW9jdGwoZmQsIEZTX0lPQ19BRERfRU5DUllQVElPTl9LRVksIE5VTEwpOworICAgICAgICBpZiAoZXJybm8gPT0gRU5PVFRZKSB7CisgICAgICAgICAgICBMT0coSU5GTykgPDwgIktlcm5lbCBkb2Vzbid0IHN1cHBvcnQgRlNfSU9DX0FERF9FTkNSWVBUSU9OX0tFWS4gIEZhbGxpbmcgYmFjayB0byAiCisgICAgICAgICAgICAgICAgICAgICAgICAgInNlc3Npb24ga2V5cmluZyI7CisgICAgICAgICAgICBzdXBwb3J0ZWQgPSBmYWxzZTsKKyAgICAgICAgfSBlbHNlIHsKKyAgICAgICAgICAgIGlmIChlcnJubyAhPSBFRkFVTFQpIHsKKyAgICAgICAgICAgICAgICBQTE9HKFdBUk5JTkcpIDw8ICJVbmV4cGVjdGVkIGVycm9yIGZyb20gRlNfSU9DX0FERF9FTkNSWVBUSU9OX0tFWSI7CisgICAgICAgICAgICB9Cisg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T1JfU0laRSkgeworICAgICAgICAgICAgICAgIExPRyhFUlJPUikgPDwgIkludmFsaWQga2V5IHNwZWNpZmllciBzaXplIGZvciB2MSBlbmNyeXB0aW9uIHBvbGljeTogIgorICAgICAgICAgICAgICAgICAgICAgICAgICAgPDwgcG9saWN5LmtleV9yYXdfcmVmLnNpemUoKTsKKyAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7CisgICAgICAgICAgICB9CisgICAgICAgICAgICBzcGVjLT50eXBlID0gRlNDUllQVF9LRVlfU1BFQ19UWVBFX0RFU0NSSVBUT1I7CisgICAgICAgICAgICBtZW1jcHkoc3BlYy0+dS5kZXNjcmlwdG9yLCBwb2xpY3kua2V5X3Jhd19yZWYuY19zdHIoKSwgRlNDUllQVF9LRVlfREVTQ1JJUFRPUl9TSVpFKTsKKyAgICAgICAgICAgIHJldHVybiB0cnVlOworICAgICAgICBjYXNlIDI6CisgICAgICAgICAgICBpZiAocG9saWN5LmtleV9yYXdfcmVmLnNpemUoKSAhPSBGU0NSWVBUX0tFWV9JREVOVElGSUVSX1NJWkUpIHsKKyAgICAgICAgICAgICAgICBMT0coRVJST1IpIDw8ICJJbnZhbGlkIGtleSBzcGVjaWZpZXIgc2l6ZSBmb3IgdjIgZW5jcnlwdGlvbiBwb2xpY3k6ICIKKyAgICAgICAgICAgICAgICAgICAgICAgICAgIDw8IHBvbGljeS5rZXlfcmF3X3JlZi5zaXplKCk7CisgICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlOworICAgICAgICAgICAgfQorICAgICAgICAgICAgc3BlYy0+dHlwZSA9IEZTQ1JZUFRfS0VZX1NQRUNfVFlQRV9JREVOVElGSUVSOworICAgICAgICAgICAgbWVtY3B5KHNwZWMtPnUuaWRlbnRpZmllciwgcG9saWN5LmtleV9yYXdfcmVmLmNfc3RyKCksIEZTQ1JZUFRfS0VZX0lERU5USUZJRVJfU0laRSk7CisgICAgICAgICAgICByZXR1cm4gdHJ1ZTsKKyAgICAgICAgZGVmYX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MjoKKyAgICAgICAgICAgIC8vIEEga2V5IGZvciBhIHYyIHBvbGljeSBpcyBzcGVjaWZpZWQgYnkgYW4gMTYtYnl0ZSAiaWRlbnRpZmllciIsCisgICAgICAgICAgICAvLyB3aGljaCBpcyBhIGNyeXB0b2dyYXBoaWMgaGFzaCBvZiB0aGUga2V5IGl0c2VsZiB3aGljaCB0aGUga2VybmVsCisgICAgICAgICAgICAvLyBjb21wdXRlcyBhbmQgcmV0dXJucy4gIEFueSB1c2VyLXByb3ZpZGVkIHZhbHVlIGlzIGlnbm9yZWQ7IHdlCisgICAgICAgICAgICAvLyBqdXN0IG5lZWQgdG8gc2V0IHRoZSBzcGVjaWZpZXIgdHlwZSB0byBpbmRpY2F0ZSB0aGF0IHdlJ3JlIGFkZGluZworICAgICAgICAgICAgLy8gdGhpcyB0eXBlIG9mIGtleS4KKyAgICAgICAgICAgIGFyZy0+a2V5X3NwZWMudHlwZSA9IEZTQ1JZUFRfS0VZX1NQRUNfVFlQRV9JREVOVElGSUVSOworICAgICAgICAgICAgYnJlYWs7CisgICAgICAgIGRlZmF1bHQ6CisgICAgICAgICAgICBMT0coRVJST1IpIDw8ICJJbnZhbGlkIGVuY3J5cHRpb24gcG9saWN5IHZlcnNpb246ICIgPDwgb3B0aW9ucy52ZXJzaW9uOworICAgICAgICAgICAgcmV0dXJuIGZhbHNlOworICAgIH0KKworICAgIGFyZy0+cmF3X3NpemUgPSBrZXkuc2l6ZSgpOworICAgIG1lbWNweShhcmctPnJhdywga2V5LmRhdGEoKSwga2V5LnNpemUoKSk7CisKKyAgICBpZiAoIWluc3RhbGxGc0tleXJpbmdLZXkobW91bnRwb2ludCwgb3B0aW9ucywgYXJnKSkgcmV0dXJuIGZhbHNlOworCisgICAgaWYgKGFyZy0+a2V5X3NwZWMudHlwZSA9PSBGU0NSWVBUX0tFWV9TUEVDX1RZUEVfSURFTlRJRklFUikgeworICAgICAgICAvLyBSZXRyaWV2ZSB0aGUga2V5IGlkZW50aWZpZXIg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Z2FjeUtleU5hbWUoKm5hbWVfcHJlZml4LCByYXdfcmVmKTsKICAgICAgICAgYXV0byBrZXlfc2VyaWFsID0ga2V5Y3RsX3NlYXJjaChkZXZpY2Vfa2V5cmluZywgImxvZ29uIiwgcmVmLmNfc3RyKCksIDApOwogCiAgICAgICAgIC8vIFVubGluayB0aGUga2V5IGZyb20gdGhlIGtleXJpbmcuICBQcmVmZXIgdW5saW5raW5nIHRvIHJldm9raW5nIG9yCkBAIC0xNDQsNDYgKzMzNiwxMDcgQEAKICAgICByZXR1cm4gc3VjY2VzczsKIH0KIAotYm9vbCByZXRyaWV2ZUFuZEluc3RhbGxLZXkoYm9vbCBjcmVhdGVfaWZfYWJzZW50LCBjb25zdCBLZXlBdXRoZW50aWNhdGlvbiYga2V5X2F1dGhlbnRpY2F0aW9uLAotICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3Qgc3RkOjpzdHJpbmcmIGtleV9wYXRoLCBjb25zdCBzdGQ6OnN0cmluZyYgdG1wX3BhdGgsCi0gICAgICAgICAgICAgICAgICAgICAgICAgICBzdGQ6OnN0cmluZyoga2V5X3JlZikgewotICAgIEtleUJ1ZmZlciBrZXk7Ci0gICAgaWYgKHBhdGhFeGlzdHMoa2V5X3BhdGgpKSB7Ci0gICAgICAgIExPRyhERUJVRykgPDwgIktleSBleGlzdHMsIHVzaW5nOiAiIDw8IGtleV9wYXRoOwotICAgICAgICBpZiAoIXJldHJpZXZlS2V5KGtleV9wYXRoLCBrZXlfYXV0aGVudGljYXRpb24sICZrZXkpKSByZXR1cm4gZmFsc2U7Ci0gICAgfSBlbHNlIHsKLSAgICAgICAgaWYgKCFjcmVhdGVfaWZfYWJzZW50KSB7Ci0gICAgICAgICAgICBMT0coRVJST1IpIDw8ICJObyBrZXkgZm91bmQgaW4gIiA8PCBrZXlfcGF0aDsKLSAgICAgICAgICAgIHJldHVybiBmYWxzZTsKLSAgICAgICAgfQotICAgICAgICBMT0coSU5GTykgPDwgIkNyZWF0aW5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8PCAiLiAgVGhlc2UgZmlsZXMgd2VyZSBub3QgbG9ja2VkISI7CisgICAgfQorCisgICAgaWYgKCFldmljdFByb3Zpc2lvbmluZ0tleShyZWYpKSByZXR1cm4gZmFsc2U7CisgICAgcmV0dXJuIHRydWU7Cit9CisKK2Jvb2wgcmV0cmlldmVPckdlbmVyYXRlS2V5KGNvbnN0IHN0ZDo6c3RyaW5nJiBrZXlfcGF0aCwgY29uc3Qgc3RkOjpzdHJpbmcmIHRtcF9wYXRoLAorICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgS2V5QXV0aGVudGljYXRpb24mIGtleV9hdXRoZW50aWNhdGlvbiwgY29uc3QgS2V5R2VuZXJhdGlvbiYgZ2VuLAorICAgICAgICAgICAgICAgICAgICAgICAgICAgS2V5QnVmZmVyKiBrZXksIGJvb2wga2VlcE9sZCkgewogICAgIGlmIChwYXRoRXhpc3RzKGtleV9wYXRoKSkgewogICAgICAgICBMT0coREVCVUcpIDw8ICJLZXkgZXhpc3RzLCB1c2luZzogIiA8PCBrZXlfcGF0aDsKLSAgICAgICAgaWYgKCFyZXRyaWV2ZUtleShrZXlfcGF0aCwga0VtcHR5QXV0aGVudGljYXRpb24sIGtleSkpIHJldHVybiBmYWxzZTsKKyAgICAgICAgaWYgKCFyZXRyaWV2ZUtleShrZXlfcGF0aCwga2V5X2F1dGhlbnRpY2F0aW9uLCBrZXksIGtlZXBPbGQpKSByZXR1cm4gZmFsc2U7CiAgICAgfSBlbHNlIHsKLSAgICAgICAgaWYgKCFjcmVhdGVfaWZfYWJzZW50KSB7CisgICAgICAgIGlmICghZ2VuLmFsbG93X2dlbikgewogICAgICAgICAgICAgTE9HKEVSUk9SKSA8PCAiTm8ga2V5IGZvdW5kIGluICIgPDwga2V5X3BhdGg7CiAgICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgIH0KICAgICAgICAgTE9HKElORk8pIDw8ICJDcmVhdGluZyBuZXcga2V5IGluICIgPDwga2V5X3Bhd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ik7CisgICAgICAgIHJldHVybiBmYWxzZTsKKyAgICB9CisgICAgcmV0dXJuIHRydWU7Cit9CisKIGJvb2wgS2V5bWFzdGVyOjpkZWxldGVLZXkoY29uc3Qgc3RkOjpzdHJpbmcmIGtleSkgewogICAgIGF1dG8ga2V5QmxvYiA9IGttOjpzdXBwb3J0OjpibG9iMmhpZGxWZWMoa2V5KTsKICAgICBhdXRvIGVycm9yID0gbURldmljZS0+ZGVsZXRlS2V5KGtleUJsb2IpOwpAQCAtMjA3LDYgKzIyOCwyMyBAQAogICAgIHJldHVybiBtRGV2aWNlLT5oYWxWZXJzaW9uKCkuc2VjdXJpdHlMZXZlbCAhPSBrbTo6U2VjdXJpdHlMZXZlbDo6U09GVFdBUkU7CiB9CiAKK3ZvaWQgS2V5bWFzdGVyOjplYXJseUJvb3RFbmRlZCgpIHsKKyAgICBhdXRvIGRldmljZXMgPSBLbURldmljZTo6ZW51bWVyYXRlQXZhaWxhYmxlRGV2aWNlcygpOworICAgIGZvciAoYXV0byYgZGV2IDogZGV2aWNlcykgeworICAgICAgICBhdXRvIGVycm9yID0gZGV2LT5lYXJseUJvb3RFbmRlZCgpOworICAgICAgICBpZiAoIWVycm9yLmlzT2soKSkgeworICAgICAgICAgICAgTE9HKEVSUk9SKSA8PCAiZWFybHlCb290RW5kZWQgY2FsbCBmYWlsZWQ6ICIgPDwgZXJyb3IuZGVzY3JpcHRpb24oKSA8PCAiIGZvciAiCisgICAgICAgICAgICAgICAgICAgICAgIDw8IGRldi0+aGFsVmVyc2lvbigpLmtleW1hc3Rlck5hbWU7CisgICAgICAgIH0KKyAgICAgICAga206OlY0XzFfRXJyb3JDb2RlIGttX2Vycm9yID0gZXJyb3I7CisgICAgICAgIGlmIChrbV9lcnJvciAhPSBrbTo6VjRfMV9FcnJvckNvZGU6Ok9LICYmIGttX2Vycm9yICE9IGttOjpWNF8xX0Vycm9yQ29kZTo6VU5JTVBMRU1FTlRFRCkgeworICAgICAgICAgICAgTE9HKEVSUk9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ihjaXBoZXJfbmFtZSk7CisgICAgaWYgKG9wdGlvbnMtPmNpcGhlci5nZXRfa2VybmVsX25hbWUoKSA9PSBudWxscHRyKSB7CisgICAgICAgIExPRyhFUlJPUikgPDwgIk5vIG1ldGFkYXRhIGNpcGhlciBuYW1lZCAiIDw8IGNpcGhlcl9uYW1lIDw8ICIgZm91bmQiOworICAgICAgICByZXR1cm4gZmFsc2U7CisgICAgfQorCisgICAgaWYgKHBhcnRzLnNpemUoKSA9PSAyKSB7CisgICAgICAgIGlmIChwYXJ0c1sxXSA9PSAid3JhcHBlZGtleV92MCIpIHsKKyAgICAgICAgICAgIG9wdGlvbnMtPnVzZV9od193cmFwcGVkX2tleSA9IHRydWU7CisgICAgICAgIH0gZWxzZSB7CisgICAgICAgICAgICBMT0coRVJST1IpIDw8ICJJbnZhbGlkIG1ldGFkYXRhIGVuY3J5cHRpb24gZmxhZzogIiA8PCBwYXJ0c1sxXTsKKyAgICAgICAgICAgIHJldHVybiBmYWxzZTsKKyAgICAgICAgfQorICAgIH0KKyAgICByZXR1cm4gdHJ1ZTsKK30KKworYm9vbCBmc2NyeXB0X21vdW50X21ldGFkYXRhX2VuY3J5cHRlZChjb25zdCBzdGQ6OnN0cmluZyYgYmxrX2RldmljZSwgY29uc3Qgc3RkOjpzdHJpbmcmIG1vdW50X3BvaW50LAorICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBib29sIG5lZWRzX2VuY3J5cHQpIHsKICAgICBMT0coREVCVUcpIDw8ICJmc2NyeXB0X21vdW50X21ldGFkYXRhX2VuY3J5cHRlZDogIiA8PCBtb3VudF9wb2ludCA8PCAiICIgPDwgbmVlZHNfZW5jcnlwdDsKICAgICBhdXRvIGVuY3J5cHRlZF9zdGF0ZSA9IGFuZHJvaWQ6OmJhc2U6OkdldFByb3BlcnR5KCJyby5jcnlwdG8uc3RhdGUiLCAiIik7Ci0gICAgaWYgKGVuY3J5cHRlZF9zdGF0ZSAhPSAiIikgeworICAgIGlm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JuIE9LOwogfQogCitzdGF0dXNfdCBTeW1saW5rKGNvbnN0IHN0ZDo6c3RyaW5nJiB0YXJnZXQsIGNvbnN0IHN0ZDo6c3RyaW5nJiBsaW5rcGF0aCkgeworICAgIGlmIChVbmxpbmsobGlua3BhdGgpIDwgMCkgeworICAgICAgICByZXR1cm4gLWVycm5vOworICAgIH0KKyAgICBpZiAoVEVNUF9GQUlMVVJFX1JFVFJZKHN5bWxpbmsodGFyZ2V0LmNfc3RyKCksIGxpbmtwYXRoLmNfc3RyKCkpKSA8IDApIHsKKyAgICAgICAgUExPRyhFUlJPUikgPDwgIkZhaWxlZCB0byBjcmVhdGUgc3ltbGluayAiIDw8IGxpbmtwYXRoIDw8ICIgdG8gIiA8PCB0YXJnZXQ7CisgICAgICAgIHJldHVybiAtZXJybm87CisgICAgfQorICAgIHJldHVybiBPSzsKK30KKworc3RhdHVzX3QgVW5saW5rKGNvbnN0IHN0ZDo6c3RyaW5nJiBsaW5rcGF0aCkgeworICAgIGlmIChURU1QX0ZBSUxVUkVfUkVUUlkodW5saW5rKGxpbmtwYXRoLmNfc3RyKCkpKSA8IDAgJiYgZXJybm8gIT0gRUlOVkFMICYmIGVycm5vICE9IEVOT0VOVCkgeworICAgICAgICBQTE9HKEVSUk9SKSA8PCAiRmFpbGVkIHRvIHVubGluayAiIDw8IGxpbmtwYXRoOworICAgICAgICByZXR1cm4gLWVycm5vOworICAgIH0KKyAgICByZXR1cm4gT0s7Cit9CisKK3N0YXR1c190IENyZWF0ZURpcihjb25zdCBzdGQ6OnN0cmluZyYgZGlyLCBtb2RlX3QgbW9kZSkgeworICAgIHN0cnVjdCBzdGF0IHNiOworICAgIGlmIChURU1QX0ZBSUxVUkVfUkVUUlkoc3RhdChkaXIuY19zdHIoKSwgJnNiKSkgPT0gMCkgeworICAgICAgICBpZiAoU19JU0RJUihzYi5zdF9tb2RlKSkgeworICAgICAgICAgICAgcmV0dXJuIE9LOworICAgICAgICB9IGVsc2UgaWYgKFRFTVBf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IGNtZCArPSBhcmdzW2ldICsgIiAiOwotICAgICAgICBpZiAoaSA9PSAwKSB7Ci0gICAgICAgICAgICBMT0coREVCVUcpIDw8IGFyZ3NbaV07Ci0gICAgICAgIH0gZWxzZSB7Ci0gICAgICAgICAgICBMT0coREVCVUcpIDw8ICIgICAgIiA8PCBhcmdzW2ldOwotICAgICAgICB9Ci0gICAgfQotICAgIG91dHB1dC5jbGVhcigpOwotCi0gICAgaWYgKGNvbnRleHQpIHsKLSAgICAgICAgaWYgKHNldGV4ZWNjb24oY29udGV4dCkpIHsKLSAgICAgICAgICAgIExPRyhFUlJPUikgPDwgIkZhaWxlZCB0byBzZXRleGVjY29uIjsKLSAgICAgICAgICAgIGFib3J0KCk7Ci0gICAgICAgIH0KLSAgICB9Ci0gICAgRklMRSogZnAgPSBwb3BlbihjbWQuY19zdHIoKSwgInIiKTsgIC8vIE5PTElOVAotICAgIGlmIChjb250ZXh0KSB7Ci0gICAgICAgIGlmIChzZXRleGVjY29uKG51bGxwdHIpKSB7Ci0gICAgICAgICAgICBMT0coRVJST1IpIDw8ICJGYWlsZWQgdG8gc2V0ZXhlY2NvbiI7Ci0gICAgICAgICAgICBhYm9ydCgpOwotICAgICAgICB9Ci0gICAgfQotCitzdGF0aWMgc3RhdHVzX3QgUmVhZExpbmVzRnJvbUZkQW5kTG9nKHN0ZDo6dmVjdG9yPHN0ZDo6c3RyaW5nPiogb3V0cHV0LAorICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhbmRyb2lkOjpiYXNlOjp1bmlxdWVfZmQgdWZkKSB7CisgICAgc3RkOjp1bmlxdWVfcHRyPEZJTEUsIGludCAoKikoRklMRSopPiBmcChhbmRyb2lkOjpiYXNlOjpGZG9wZW4oc3RkOjptb3ZlKHVmZCksICJyIiksIGZjbG9zZSk7CiAgICAgaWYgKCFmcCkgewotICAgICAgICBQTE9HKEVSUk9SKSA8PCAiRmFpbGVkIHRvIHBvcGVuICIgPDwgY21kOworICAgICAgIC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jdnAiOwogICAgICAgICByZXR1cm4gLWVycm5vOwogICAgIH0KIAorICAgIHBpZF90IHBpZCA9IGZvcmsoKTsKKyAgICBpZiAocGlkID09IDApIHsKKyAgICAgICAgaWYgKGNvbnRleHQpIHsKKyAgICAgICAgICAgIGlmIChzZXRleGVjY29uKGNvbnRleHQpKSB7CisgICAgICAgICAgICAgICAgTE9HKEVSUk9SKSA8PCAiRmFpbGVkIHRvIHNldGV4ZWNjb24gaW4gRm9ya0V4ZWN2cCI7CisgICAgICAgICAgICAgICAgYWJvcnQoKTsKKyAgICAgICAgICAgIH0KKyAgICAgICAgfQorICAgICAgICBwaXBlX3JlYWQucmVzZXQoKTsKKyAgICAgICAgaWYgKGR1cDIocGlwZV93cml0ZS5nZXQoKSwgU1RET1VUX0ZJTEVOTykgPT0gLTEpIHsKKyAgICAgICAgICAgIFBMT0coRVJST1IpIDw8ICJkdXAyIGluIEZvcmtFeGVjdnAiOworICAgICAgICAgICAgX2V4aXQoRVhJVF9GQUlMVVJFKTsKKyAgICAgICAgfQorICAgICAgICBwaXBlX3dyaXRlLnJlc2V0KCk7CisgICAgICAgIGV4ZWN2cChhcmd2WzBdLCBjb25zdF9jYXN0PGNoYXIqKj4oYXJndi5kYXRhKCkpKTsKKyAgICAgICAgUExPRyhFUlJPUikgPDwgImV4ZWMgaW4gRm9ya0V4ZWN2cCI7CisgICAgICAgIF9leGl0KEVYSVRfRkFJTFVSRSk7CisgICAgfQorICAgIGlmIChwaWQgPT0gLTEpIHsKKyAgICAgICAgUExPRyhFUlJPUikgPDwgImZvcmsgaW4gRm9ya0V4ZWN2cCI7CisgICAgICAgIHJldHVybiAtZXJybm87CisgICAgfQorCisgICAgcGlwZV93cml0ZS5yZXNldCgpOworICAgIGF1dG8gc3QgPSBSZWFkTGluZXNGcm9tRmRBbmRMb2cob3V0cHV0LCBzdGQ6Om1vdmUocGlwZV9yZWFkKSk7CisgICAgaWYgKHN0ICE9IDApIHJldHVybiBzdDsKKworICAgIGludCBz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geworICAgICAgICBQTE9HKEVSUk9SKSA8PCAiRmFpbGVkIHRvIHVubW91bnQgIiA8PCBtb3VudFBvaW50OworICAgICAgICByZXR1cm4gLWVycm5vOworICAgIH0KKyAgICByZXR1cm4gT0s7Cit9CisKK3N0YXRpYyBzdGF0dXNfdCBkZWxldGVfZGlyX2NvbnRlbnRzKERJUiogZGlyKSB7CisgICAgLy8gU2hhbWVsZXNzbHkgYm9ycm93ZWQgZnJvbSBhbmRyb2lkOjppbnN0YWxsZAorICAgIGludCBkZmQgPSBkaXJmZChkaXIpOworICAgIGlmIChkZmQgPCAwKSB7CisgICAgICAgIHJldHVybiAtZXJybm87CisgICAgfQorCisgICAgc3RhdHVzX3QgcmVzdWx0ID0gT0s7CisgICAgc3RydWN0IGRpcmVudCogZGU7CisgICAgd2hpbGUgKChkZSA9IHJlYWRkaXIoZGlyKSkpIHsKKyAgICAgICAgY29uc3QgY2hhciogbmFtZSA9IGRlLT5kX25hbWU7CisgICAgICAgIGlmIChkZS0+ZF90eXBlID09IERUX0RJUikgeworICAgICAgICAgICAgLyogYWx3YXlzIHNraXAgIi4iIGFuZCAiLi4iICovCisgICAgICAgICAgICBpZiAobmFtZVswXSA9PSAnLicpIHsKKyAgICAgICAgICAgICAgICBpZiAobmFtZVsxXSA9PSAwKSBjb250aW51ZTsKKyAgICAgICAgICAgICAgICBpZiAoKG5hbWVbMV0gPT0gJy4nKSAmJiAobmFtZVsyXSA9PSAwKSkgY29udGludWU7CisgICAgICAgICAgICB9CisKKyAgICAgICAgICAgIGFuZHJvaWQ6OmJhc2U6OnVuaXF1ZV9mZCBzdWJmZCgKKyAgICAgICAgICAgICAgICBvcGVuYXQoZGZkLCBuYW1lLCBPX1JET05MWSB8IE9fRElSRUNUT1JZIHwgT19OT0ZPTExPVyB8IE9fQ0xPRVhFQykpOworICAgICAgICAgICAgaWYgKHN1YmZkLmdldCgpID09IC0xKSB7CisgICAgICAgICAgICAgICAgUExPRyhFUlJPUikgPDwgIkNvdWxkbid0IG9wZW5hdCAiIDw8IG5hbWU7CisgICAgICAgICAgICAgICAgcmVzdWx0ID0gLWVycm5vOworICAgICAgICAgICAgICAgIGNvbnRpbnVlOworICAgICAgICAgICAgfQorICAgICAgICAgICAgc3RkOjp1bmlxdWVfcHRyPERJUiwgZGVjbHR5cGUoJmNsb3NlZGlyKT4gc3ViZGlycCgKKyAgICAgICAgICAgICAgICBhbmRyb2lkOjpiYXNlOjpGZG9wZW5kaXIoc3RkOjptb3ZlKHN1YmZkKSksIGNsb3NlZGlyKTsKKyAgICAgICAgICAgIGlmICghc3ViZGlycCkgeworICAgICAgICAgICAgICAgIFBMT0coRVJST1IpIDw8ICJDb3VsZG4ndCBmZG9wZW5kaXIgIiA8PCBuYW1lOworICAgICAgICAgICAgICAgIHJlc3VsdCA9IC1lcnJubzsKKyAgICAgICAgICAgICAgICBjb250aW51ZTsKKyAgICAgICAgICAgIH0KKyAgICAgICAgICAgIHJlc3VsdCA9IGRlbGV0ZV9kaXJfY29udGVudHMoc3ViZGlycC5nZXQoKSk7CisgICAgICAgICAgICBpZiAodW5saW5rYXQoZGZkLCBuYW1lLCBBVF9SRU1PVkVESVIpIDwgMCkgeworICAgICAgICAgICAgICAgIFBMT0coRVJST1IpIDw8ICJDb3VsZG4ndCB1bmxpbmthdCAiIDw8IG5hbWU7CisgICAgICAgICAgICAgICAgcmVzdWx0ID0gLWVycm5vOworICAgICAgICAgICAgfQorICAgICAgICB9IGVsc2UgeworICAgICAgICAgICAgaWYgKHVubGlua2F0KGRmZCwgbmFtZSwgMCkgPCAwKSB7CisgICAgICAgICAgICAgICAgUExPRyhFUlJPUikgPDwgIkNvdWxkbid0IHVubGlua2F0ICIgPDwgbmFtZTsKKyAgICAgICAgICAgICAgICByZXN1bHQgPSAtZXJybm87CisgICAgICAgICAgICB9CisgICAgICAgIH0KKyAgICB9CisgICAgcmV0dXJuIHJlc3VsdDsKK30KKworc3RhdHVzX3QgRGVsZXRlRGlyQ29udGVudHNBbmREaXI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TsKLX0KLQotYmluZGVyOjpTdGF0dXMgY2hlY2tBcmd1bWVudEhleChjb25zdCBzdGQ6OnN0cmluZyYgaGV4KSB7Ci0gICAgLy8gRW1wdHkgaGV4IHN0cmluZ3MgYXJlIGFsbG93ZWQKLSAgICBmb3IgKGNvbnN0IGNoYXImIGMgOiBoZXgpIHsKLSAgICAgICAgaWYgKCFzdGQ6OmlzeGRpZ2l0KGMpICYmIGMgIT0gJzonICYmIGMgIT0gJy0nKSB7Ci0gICAgICAgICAgICByZXR1cm4gZXhjZXB0aW9uKGJpbmRlcjo6U3RhdHVzOjpFWF9JTExFR0FMX0FSR1VNRU5ULAotICAgICAgICAgICAgICAgICAgICAgICAgICAgICBTdHJpbmdQcmludGYoIkhleCAlcyBpcyBtYWxmb3JtZWQiLCBoZXguY19zdHIoKSkpOwotICAgICAgICB9Ci0gICAgfQotICAgIHJldHVybiBvaygpOwotfQotCi0jZGVmaW5lIEVORk9SQ0VfVUlEKHVpZCkgICAgICAgICAgICAgICAgICAgICAgICAgXAotICAgIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKLSAgICAgICAgYmluZGVyOjpTdGF0dXMgc3RhdHVzID0gY2hlY2tVaWQoKHVpZCkpOyBcCi0gICAgICAgIGlmICghc3RhdHVzLmlzT2soKSkgeyAgICAgICAgICAgICAgICAgICAgXAotICAgICAgICAgICAgcmV0dXJuIHN0YXR1czsgICAgICAgICAgICAgICAgICAgICAgIFwKLSAgICAgICAgfSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCisjZGVmaW5lIEVORk9SQ0VfU1lTVEVNX09SX1JPT1QgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCisgICAgeyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCisgICAgICAgIGJpbmRlcjo6U3RhdHVzIHN0YXR1cyA9IENoZWNrVWlkT3JSb290KEFJRF9TWVNURU0pOyBcCisgICAgICAgIGlmICghc3RhdHVzLmlzT2soKSkgeyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCisgICAgICAgICAgICByZXR1cm4gc3RhdHVzOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCisgICAgICAgIH0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgfQogCiAjZGVmaW5lIENIRUNLX0FSR1VNRU5UX0lEKGlkKSAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKLSAgICAgICAgYmluZGVyOjpTdGF0dXMgc3RhdHVzID0gY2hlY2tBcmd1bWVudElkKChpZCkpOyBcCisgICAgICAgIGJpbmRlcjo6U3RhdHVzIHN0YXR1cyA9IENoZWNrQXJndW1lbnRJZCgoaWQpKTsgXAogICAgICAgICBpZiAoIXN0YXR1cy5pc09rKCkpIHsgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgIHJldHVybiBzdGF0dXM7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgICAgIH0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXApAQCAtMTY1LDcgKzk0LDcgQEAKIAogI2RlZmluZSBDSEVDS19BUkdVTUVOVF9QQVRIKHBhdGgpICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgICAgeyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKLSAgICAgICAgYmluZGVyOjpTdGF0dXMgc3RhdHVzID0gY2hlY2tBcmd1bWVudFBhdGgoKHBhdGgpKTsgXAorICAgICAgICBiaW5kZXI6OlN0YXR1cyBzdGF0dXMgPSBDaGVja0FyZ3VtZW50UGF0aCgocGF0aCkpOyBcCiAgICAgICAgIGlmICghc3RhdHVzLmlzT2soKSkgeyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgICAgICAgIHJldHVybiBzdGF0dXM7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICB9ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCkBAIC0xNzMsNyArMTAyLDcgQEAKIAogI2RlZmluZSBDSEVDS19BUkdVTUVOVF9IRVgoaGV4KSAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAotICAgICAgICBiaW5kZXI6OlN0YXR1cyBzdGF0dXMgPSBjaGVja0FyZ3VtZW50SGV4KChoZXgpKTsgXAorICAgICAgICBiaW5kZXI6OlN0YXR1cyBzdGF0dXMgPSBDaGVja0FyZ3VtZW50SGV4KChoZXgpKTsgXAogICAgICAgICBpZiAoIXN0YXR1cy5pc09rKCkpIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICAgICAgcmV0dXJuIHN0YXR1czsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogICAgICAgICB9ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXApAQCAtMjAzLDcgKzEzMiw3IEBACiAKIHN0YXR1c190IFZvbGROYXRpdmVTZXJ2aWNlOjpkdW1wKGludCBmZCwgY29uc3QgVmVjdG9yPFN0cmluZzE2PiYgLyogYXJncyAqLykgewogICAgIGF1dG8gb3V0ID0gc3RkOjpmc3RyZWFtKFN0cmluZ1ByaW50ZigiL3Byb2Mvc2VsZi9mZC8lZCIsIGZkKSk7Ci0gICAgY29uc3QgYmluZGVyOjpTdGF0dXMgZHVtcF9wZXJtaXNzaW9uID0gY2hlY2tQZXJtaXNzaW9uKGtEdW1wKTsKKyAgICBjb25zdCBiaW5kZXI6OlN0YXR1cyBkdW1wX3Blcm1pc3Npb24gPSBDaGVja1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0s7CiAKICAgICByZXR1cm4gdHJhbnNsYXRlQm9vbChmc2NyeXB0X2Rlc3Ryb3lfdXNlcl9rZXkodXNlcklkKSk7CkBAIC03NTMsMTQgKzY4MiwyMyBAQAogYmluZGVyOjpTdGF0dXMgVm9sZE5hdGl2ZVNlcnZpY2U6OmFkZFVzZXJLZXlBdXRoKGludDMyX3QgdXNlcklkLCBpbnQzMl90IHVzZXJTZXJpYWwsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3Qgc3RkOjpzdHJpbmcmIHRva2VuLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IHN0ZDo6c3RyaW5nJiBzZWNyZXQpIHsKLSAgICBFTkZPUkNFX1VJRChBSURfU1lTVEVNKTsKKyAgICBFTkZPUkNFX1NZU1RFTV9PUl9ST09UOwogICAgIEFDUVVJUkVfQ1JZUFRfTE9DSzsKIAogICAgIHJldHVybiB0cmFuc2xhdGVCb29sKGZzY3J5cHRfYWRkX3VzZXJfa2V5X2F1dGgodXNlcklkLCB1c2VyU2VyaWFsLCB0b2tlbiwgc2VjcmV0KSk7CiB9CiAKK2JpbmRlcjo6U3RhdHVzIFZvbGROYXRpdmVTZXJ2aWNlOjpjbGVhclVzZXJLZXlBdXRoKGludDMyX3QgdXNlcklkLCBpbnQzMl90IHVzZXJTZXJpYWwsCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBzdGQ6OnN0cmluZyYgdG9rZW4sCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBzdGQ6OnN0cmluZyYgc2VjcmV0KSB7CisgICAgRU5GT1JDRV9TWVNURU1fT1JfUk9PVDsKKyAgICBBQ1FVSVJFX0NSWVBUX0xPQ0s7CisKKyAgICByZXR1cm4gdHJhbnNsYXRlQm9vbChmc2NyeXB0X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W5nJiBwYWNrYWdlTmFtZSwKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBzdGQ6OnN0cmluZyYgc2FuZGJveElkLAorICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGludDMyX3QgdXNlcklkKSB7CisgICAgcmV0dXJuIE9rKCk7Cit9CisKIGJpbmRlcjo6U3RhdHVzIFZvbGROYXRpdmVTZXJ2aWNlOjpzdGFydENoZWNrcG9pbnQoaW50MzJfdCByZXRyeSkgewotICAgIEVORk9SQ0VfVUlEKEFJRF9TWVNURU0pOworICAgIEVORk9SQ0VfU1lTVEVNX09SX1JPT1Q7CiAgICAgQUNRVUlSRV9MT0NLOwogCiAgICAgcmV0dXJuIGNwX3N0YXJ0Q2hlY2twb2ludChyZXRyeSk7CiB9CiAKIGJpbmRlcjo6U3RhdHVzIFZvbGROYXRpdmVTZXJ2aWNlOjpuZWVkc1JvbGxiYWNrKGJvb2wqIF9haWRsX3JldHVybikgewotICAgIEVORk9SQ0VfVUlEKEFJRF9TWVNURU0pOworICAgIEVORk9SQ0VfU1lTVEVNX09SX1JPT1Q7CiAgICAgQUNRVUlSRV9MT0NLOwogCiAgICAgKl9haWRsX3JldHVybiA9IGNwX25lZWRzUm9sbGJhY2soKTsKLSAgICByZXR1cm4gb2soKTsKKyAgICByZXR1cm4gT2soKTsKIH0KIAogYmluZGVyOjpTdGF0dXMgVm9sZE5hdGl2ZVNlcnZpY2U6Om5lZWRzQ2hlY2twb2ludChib29sKiBfYWlkbF9yZXR1cm4pIHsKLSAgICBFTkZPUkNFX1VJRChBSURfU1lTVEVNKTsKKyAgICBFTkZPUkNFX1NZU1RFTV9PUl9ST09UOwogICAgIEFDUVVJUkVfTE9DSzsKIAogICAgICpfYWlkbF9yZXR1cm4gPSBjcF9uZWVkc0NoZWNrcG9pbnQoKTsKLSAgICByZXR1cm4gb2soKTsKKyAgICByZXR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geworaW50IFZvbHVtZU1hbmFnZXI6OnJlbW91bnRVaWQodWlkX3QgdWlkLCBpbnQzMl90IG1vdW50TW9kZSkgeworICAgIHN0ZDo6c3RyaW5nIG1vZGU7CisgICAgc3dpdGNoIChtb3VudE1vZGUpIHsKKyAgICAgICAgY2FzZSBWb2xkTmF0aXZlU2VydmljZTo6UkVNT1VOVF9NT0RFX05PTkU6CisgICAgICAgICAgICBtb2RlID0gIm5vbmUiOworICAgICAgICAgICAgYnJlYWs7CisgICAgICAgIGNhc2UgVm9sZE5hdGl2ZVNlcnZpY2U6OlJFTU9VTlRfTU9ERV9ERUZBVUxUOgorICAgICAgICAgICAgbW9kZSA9ICJkZWZhdWx0IjsKKyAgICAgICAgICAgIGJyZWFrOworICAgICAgICBjYXNlIFZvbGROYXRpdmVTZXJ2aWNlOjpSRU1PVU5UX01PREVfUkVBRDoKKyAgICAgICAgICAgIG1vZGUgPSAicmVhZCI7CisgICAgICAgICAgICBicmVhazsKKyAgICAgICAgY2FzZSBWb2xkTmF0aXZlU2VydmljZTo6UkVNT1VOVF9NT0RFX1dSSVRFOgorICAgICAgICBjYXNlIFZvbGROYXRpdmVTZXJ2aWNlOjpSRU1PVU5UX01PREVfTEVHQUNZOgorICAgICAgICBjYXNlIFZvbGROYXRpdmVTZXJ2aWNlOjpSRU1PVU5UX01PREVfSU5TVEFMTEVSOgorICAgICAgICAgICAgbW9kZSA9ICJ3cml0ZSI7CisgICAgICAgICAgICBicmVhazsKKyAgICAgICAgY2FzZSBWb2xkTmF0aXZlU2VydmljZTo6UkVNT1VOVF9NT0RFX0ZVTEw6CisgICAgICAgICAgICBtb2RlID0gImZ1bGwiOworICAgICAgICAgICAgYnJlYWs7CisgICAgICAgIGRlZmF1bHQ6CisgICAgICAgICAgICBQTE9HKEVSUk9SKSA8PCAiVW5rbm93biBtb2RlICIgPDwgc3RkOjp0b19zdHJpbmcobW91bnRNb2RlKTsKKyAgICAgICAgICAgIHJldHVybiAtMTsKKyAgICB9Ci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UMKKyAgICAgICAgLy8gTk9MSU5UTkVYVExJTkUoYW5kcm9pZC1jbG9leGVjLW9wZW4pOiBEZWxpYmVyYXRlbHkgbm90IE9fQ0xPRVhFQworICAgICAgICBuc0ZkID0gb3BlbmF0KHBpZEZkLCAibnMvbW50IiwgT19SRE9OTFkpOwogICAgICAgICBpZiAobnNGZCA8IDApIHsKICAgICAgICAgICAgIFBMT0coV0FSTklORykgPDwgIkZhaWxlZCB0byBvcGVuIG5hbWVzcGFjZSBmb3IgIiA8PCBkZS0+ZF9uYW1lOwogICAgICAgICAgICAgZ290byBuZXh0OwpAQCAtNDk3LDYgKzU1Myw4IEBACiAgICAgICAgICAgICAgICAgc3RvcmFnZVNvdXJjZSA9ICIvbW50L3J1bnRpbWUvcmVhZCI7CiAgICAgICAgICAgICB9IGVsc2UgaWYgKG1vZGUgPT0gIndyaXRlIikgewogICAgICAgICAgICAgICAgIHN0b3JhZ2VTb3VyY2UgPSAiL21udC9ydW50aW1lL3dyaXRlIjsKKyAgICAgICAgICAgIH0gZWxzZSBpZiAobW9kZSA9PSAiZnVsbCIpIHsKKyAgICAgICAgICAgICAgICBzdG9yYWdlU291cmNlID0gIi9tbnQvcnVudGltZS9mdWxsIjsKICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgLy8gU2FuZSBkZWZhdWx0IG9mIG5vIHN0b3JhZ2UgdmlzaWJsZQogICAgICAgICAgICAgICAgIF9leGl0KDApOwpAQCAtNTkwLDcgKzY0OCw3IEBACiAKICAgICAvLyBXb3JzdCBjYXNlIHdlIG1pZ2h0IGhhdmUgc29tZSBzdGFsZSBtb3VudHMgbHVya2luZyBhcm91bmQsIHNvCiAgICAgLy8gZm9yY2UgdW5tb3VudCB0aG9zZSBqdXN0IHRvIGJlIHNhZmUuCi0gICAgRklMRSogZnAgPSBzZXRtbnRlbnQoIi9wcm9jL21vdW50cyIsICJyIik7CisgICAgRklMRSogZnAgPSBzZXRtbnRlbnQoIi9wcm9jL21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KKyAgICAweDggLyogU2V0IHdoZW4gZW5jcnlwdGlvbiBpcyBmaW5lLCBidXQgdGhlIFwKKyAgICAgICAgICAgdW5kZXJseWluZyB2b2x1bWUgaXMgY29ycnVwdCAqLworI2RlZmluZSBDUllQVF9GT1JDRV9FTkNSWVBUSU9OICAgICAgICAgICAgICAgICAgICAgICAgXAorICAgIDB4MTAgLyogU2V0IHdoZW4gaXQgaXMgdGltZSB0byBlbmNyeXB0IHRoaXMgICAgICAgXAorICAgICAgICAgICAgdm9sdW1lIG9uIGJvb3QuIEV2ZXJ5dGhpbmcgaW4gdGhpcyAgICAgICAgXAorICAgICAgICAgICAgc3RydWN0dXJlIGlzIHNldCB1cCBjb3JyZWN0bHkgYXMgICAgICAgICAgXAorICAgICAgICAgICAgdGhvdWdoIGRldmljZSBpcyBlbmNyeXB0ZWQgZXhjZXB0ICAgICAgICAgXAorICAgICAgICAgICAgdGhhdCB0aGUgbWFzdGVyIGtleSBpcyBlbmNyeXB0ZWQgd2l0aCB0aGUgXAorICAgICAgICAgICAgZGVmYXVsdCBwYXNzd29yZC4gKi8KKyNkZWZpbmUgQ1JZUFRfRk9SQ0VfQ09NUExFVEUgICAgICAgICAgICAgICAgICAgICAgICAgICBcCisgICAgMHgyMCAvKiBTZXQgd2hlbiB0aGUgYWJvdmUgZW5jcnlwdGlvbiBjeWNsZSBpcyAgICAgXAorICAgICAgICAgICAgY29tcGxldGUuIE9uIG5leHQgY3J5cHRrZWVwZXIgZW50cnksIG1hdGNoIFwKKyAgICAgICAgICAgIHRoZSBwYXNzd29yZC4gSWYgaXQgbWF0Y2hlcyBmaXggdGhlIG1hc3RlciBcCisgICAgICAgICAgICBrZXkgYW5kIHJlbW92ZSB0aGlzIGZsYWcuICovCisKKy8qIEFsbG93ZWQgdmFsdWVzIGZvciB0eXBlIGluIHRoZSBzdHJ1Y3R1cmUgYmVsb3cgKi8KKyNkZWZpbmUgQ1JZUFRfVFlQRV9QQVNTV09SRCAgICAgICAgICAgICAgIC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aW9uIGlmIHRoZSBjcnlwdF9tbnRfZnRyIGxpdmVzIGF0IHRoZSBlbmQgb2YgdGhlCisgKiBwYXJ0aXRpb24uCisgKi8KKworc3RydWN0IGNyeXB0X21udF9mdHIgeworICAgIF9fbGUzMiBtYWdpYzsgLyogU2VlIGFib3ZlICovCisgICAgX19sZTE2IG1ham9yX3ZlcnNpb247CisgICAgX19sZTE2IG1pbm9yX3ZlcnNpb247CisgICAgX19sZTMyIGZ0cl9zaXplOyAgICAgICAgICAgICAvKiBpbiBieXRlcywgbm90IGluY2x1ZGluZyBrZXkgZm9sbG93aW5nICovCisgICAgX19sZTMyIGZsYWdzOyAgICAgICAgICAgICAgICAvKiBTZWUgYWJvdmUgKi8KKyAgICBfX2xlMzIga2V5c2l6ZTsgICAgICAgICAgICAgIC8qIGluIGJ5dGVzICovCisgICAgX19sZTMyIGNyeXB0X3R5cGU7ICAgICAgICAgICAvKiBob3cgbWFzdGVyX2tleSBpcyBlbmNyeXB0ZWQuIE11c3QgYmUgYQorICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICogQ1JZUFRfVFlQRV9YWFggdmFsdWUgKi8KKyAgICBfX2xlNjQgZnNfc2l6ZTsgICAgICAgICAgICAgIC8qIFNpemUgb2YgdGhlIGVuY3J5cHRlZCBmcywgaW4gNTEyIGJ5dGUgc2VjdG9ycyAqLworICAgIF9fbGUzMiBmYWlsZWRfZGVjcnlwdF9jb3VudDsgLyogY291bnQgb2YgIyBvZiBmYWlsZWQgYXR0ZW1wdHMgdG8gZGVjcnlwdCBhbmQKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG1vdW50LCBzZXQgdG8gMCBvbiBzdWNjZXNzZnVsIG1vdW50ICovCisgICAgdW5zaWduZWQgY2hhciBjcnlwdG9fdHlwZV9uYW1lW01BWF9DUllQVE9fVFlQRV9OQU1FX0xFTl07IC8qIFRoZSB0eXBlIG9mIGVuY3J5cHRpb24KKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbmVlZGVkIHRvIGRlY3J5cHQgdGhpcworICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwYXJ0aXRpb24sIG51bGwgdGVybWluYXRlZCAqLworICAgIF9fbGUzMiBzcGFyZTI7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvKiBpZ25vcmVkICovCisgICAgdW5zaWduZWQgY2hhciBtYXN0ZXJfa2V5W01BWF9LRVlfTEVOXTsgLyogVGhlIGVuY3J5cHRlZCBrZXkgZm9yIGRlY3J5cHRpbmcgdGhlIGZpbGVzeXN0ZW0gKi8KKyAgICB1bnNpZ25lZCBjaGFyIHNhbHRbU0FMVF9MRU5dOyAgICAgICAgICAvKiBUaGUgc2FsdCB1c2VkIGZvciB0aGlzIGVuY3J5cHRpb24gKi8KKyAgICBfX2xlNjQgcGVyc2lzdF9kYXRhX29mZnNldFsyXTsgICAgICAgICAvKiBBYnNvbHV0ZSBvZmZzZXQgdG8gYm90aCBjb3BpZXMgb2YgY3J5cHRfcGVyc2lzdF9kYXRhCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICogb24gZGV2aWNlIHdpdGggdGhhdCBpbmZvLCBlaXRoZXIgdGhlIGZvb3RlciBvZiB0aGUKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKiByZWFsX2Jsa2RldmljZSBvciB0aGUgbWV0YWRhdGEgcGFydGl0aW9uLiAqLworCisgICAgX19sZTMyIHBlcnNpc3RfZGF0YV9zaXplOyAvKiBUaGUgbnVtYmVyIG9mIGJ5dGVzIGFsbG9jYXRlZCB0byBlYWNoIGNvcHkgb2YgdGhlCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKiBwZXJzaXN0ZW50IGRhdGEgdGFibGUqLworCisgICAgX19sZTgga2RmX3R5cGU7IC8qIFRoZSBrZXkgZGVyaXZhdGlvbiBmdW5jdGlvbiB1c2VkLiAqLworCisgICAgLyogc2NyeXB0IHBhcmFtZXRlcnMuIFNlZSB3d3cudGFyc25hcC5jb20vc2NyeXB0L3NjcnlwdC5wZGYgKi8KKyAgICBfX2xlOCBOX2ZhY3RvcjsgICAgICAgIC8qICgxIDw8IE4pICovCisgICAgX19sZTggcl9mYWN0b3I7ICAgICAgICAvKiAoMSA8PCByKSAqLworICAgIF9fbGU4IHBfZmFjdG9yOyAgICAgICAgLyogKDEgPDwgcCkgKi8KKyAgICBfX2xlNjQgZW5jcnlwdGVkX3VwdG87IC8qIElmIHdlIGFyZSBpbiBzdGF0ZSBDUllQVF9FTkNSWVBUSU9OX0lOX1BST0dSRVNTIGFuZAorICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgd2UgaGF2ZSB0byBzdG9wIChlLmcuIHBvd2VyIGxvdykgdGhpcyBpcyB0aGUgbGFzdAorICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZW5jcnlwdGVkIDUxMiBieXRlIHNlY3Rvci4qLworICAgIF9fbGU4IGhhc2hfZmlyc3RfYmxvY2tbU0hBMjU2X0RJR0VTVF9MRU5HVEhdOyAvKiBXaGVuIENSWVBUX0VOQ1JZUFRJT05fSU5fUFJPR1JFU1MKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2V0LCBoYXNoIG9mIGZpcnN0IGJsb2NrLCB1c2VkCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRvIHZhbGlkYXRlIGJlZm9yZSBjb250aW51aW5nKi8KKworICAgIC8qIGtleV9tYXN0ZXIga2V5LCB1c2VkIHRvIHNpZ24gdGhlIGRlcml2ZWQga2V5IHdoaWNoIGlzIHRoZW4gdXNlZCB0byBnZW5lcmF0ZQorICAgICAqIHRoZSBpbnRlcm1lZGlhdGUga2V5CisgICA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ICAgICAgICAgICAoZW50cnkuZnNfbWdyX2ZsYWdzLmNyeXB0IHx8IGVudHJ5LmZzX21ncl9mbGFncy5mb3JjZV9jcnlwdCB8fAorICAgICAgICAgICAgIGVudHJ5LmZzX21ncl9mbGFncy5mb3JjZV9mZGVfb3JfZmJlIHx8IGVudHJ5LmZzX21ncl9mbGFncy5maWxlX2VuY3J5cHRpb24pKSB7CisgICAgICAgICAgICBpZiAoa2V5X2xvYyAhPSBudWxscHRyKSB7CisgICAgICAgICAgICAgICAgKmtleV9sb2MgPSBlbnRyeS5rZXlfbG9jOworICAgICAgICAgICAgfQorICAgICAgICAgICAgaWYgKHJlYWxfYmxrX2RldmljZSAhPSBudWxscHRyKSB7CisgICAgICAgICAgICAgICAgKnJlYWxfYmxrX2RldmljZSA9IGVudHJ5LmJsa19kZXZpY2U7CisgICAgICAgICAgICB9CisgICAgICAgICAgICByZXR1cm47CisgICAgICAgIH0KKyAgICB9Cit9CisKIHN0YXRpYyBpbnQgZ2V0X2NyeXB0X2Z0cl9pbmZvKGNoYXIqKiBtZXRhZGF0YV9mbmFtZSwgb2ZmNjRfdCogb2ZmKSB7CiAgICAgc3RhdGljIGludCBjYWNoZWRfZGF0YSA9IDA7CiAgICAgc3RhdGljIHVpbnQ2NF90IGNhY2hlZF9vZmYgPSAwOwpAQCAtNDQwLDIyICs1MzUsMjQgQEAKICAgICBpbnQgcmMgPSAtMTsKIAogICAgIGlmICghY2FjaGVkX2RhdGEpIHsKLSAgICAgICAgZnNfbWdyX2dldF9jcnlwdF9pbmZvKGZzdGFiX2RlZmF1bHQsIGtleV9sb2MsIHJlYWxfYmxrZGV2LCBzaXplb2Yoa2V5X2xvYykpOworICAgICAgICBzdGQ6OnN0cmluZyBrZXlfbG9jOworICAgICAgICBzdGQ6OnN0cmluZyByZWFsX2Jsa2RldjsKKyAgICAgICAgZ2V0X2NyeXB0X2luZm8oJmtleV9sb2MsICZyZWFsX2Jsa2Rldik7CiAKLSAgICAgICAgaWYgKCFz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AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBleHRyYV9wYXJhbXNfYXNfc3RyaW5nKGV4dHJhX3BhcmFtc192ZWMpLmNfc3RyKCkpOwotICAgIGlmIChsb2FkX2NvdW50IDwgMCkgeworICAgIGlmIChhZGRfc2VjdG9yX3NpemVfcGFyYW0odGFyZ2V0LmdldCgpLCBjcnlwdF9mdHIpKSB7CisgICAgICAgIFNMT0dFKCJFcnJvciBwcm9jZXNzaW5nIGRtLWNyeXB0IHNlY3RvciBzaXplIHBhcmFtXG4iKTsKKyAgICAgICAgcmV0dXJuIC0xOworICAgIH0KKworICAgIERtVGFibGUgdGFibGU7CisgICAgdGFibGUuQWRkVGFyZ2V0KHN0ZDo6bW92ZSh0YXJnZXQpKTsKKworICAgIGludCBsb2FkX2NvdW50ID0gMTsKKyAgICB3aGlsZSAobG9hZF9jb3VudCA8IFRBQkxFX0xPQURfUkVUUklFUykgeworICAgICAgICBpZiAoZG0uQ3JlYXRlRGV2aWNlKG5hbWUsIHRhYmxlKSkgeworICAgICAgICAgICAgYnJlYWs7CisgICAgICAgIH0KKyAgICAgICAgbG9hZF9jb3VudCsrOworICAgIH0KKworICAgIGlmIChsb2FkX2NvdW50ID49IFRBQkxFX0xPQURfUkVUUklFUykgewogICAgICAgICBTTE9HRSgiQ2Fubm90IGxvYWQgZG0tY3J5cHQgbWFwcGluZyB0YWJsZS5cbiIpOwotICAgICAgICBnb3RvIGVycm91dDsKLSAgICB9IGVsc2UgaWYgKGxvYWRfY291bnQgPiAxKSB7CisgICAgICAgIHJldHVybiAtMTsKKyAgICB9CisgICAgaWYgKGxvYWRfY291bnQgPiAxKSB7CiAgICAgICAgIFNMT0dJKCJUb29rICVkIHRyaWVzIHRvIGxvYWQgZG1jcnlwdCB0YWJsZS5cbiIsIGxvYWRfY291bnQpOwogICAgIH0KIAotICAgIC8qIFJlc3VtZSB0aGlzIGRldmljZSB0byBhY3RpdmF0ZSBpdCAqLwotICAgIGlvY3RsX2lu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ugc2V0ZXhlY2NvbiB0byBydW4gdHJ1c3RlZAogICAgICAgICAgKiBwYXJ0aXRpb25zIGluIHRoZSBmc2NrIGRvbWFpbi4KICAgICAgICAgICovCi0gICAgICAgIGlmIChzZXRleGVjY29uKHNlY29udGV4dEZzY2soKSkpIHsKKyAgICAgICAgaWYgKHNldGV4ZWNjb24oYW5kcm9pZDo6dm9sZDo6c0ZzY2tDb250ZXh0KSkgewogICAgICAgICAgICAgU0xPR0UoIkZhaWxlZCB0byBzZXRleGVjY29uIik7CiAgICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgIH0KICAgICAgICAgYm9vbCBuZWVkc19jcCA9IGFuZHJvaWQ6OnZvbGQ6OmNwX25lZWRzQ2hlY2twb2ludCgpOwotICAgICAgICB3aGlsZSAoKG1vdW50X3JjID0gZnNfbWdyX2RvX21vdW50KGZzdGFiX2RlZmF1bHQsIERBVEFfTU5UX1BPSU5ULCBjcnlwdG9fYmxrZGV2LCAwLAorICAgICAgICB3aGlsZSAoKG1vdW50X3JjID0gZnNfbWdyX2RvX21vdW50KCZmc3RhYl9kZWZhdWx0LCBEQVRBX01OVF9QT0lOVCwgY3J5cHRvX2Jsa2RldiwgMCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBuZWVkc19jcCkpICE9IDApIHsKICAgICAgICAgICAgIGlmIChtb3VudF9yYyA9PSBGU19NR1JfRE9NTlRfQlVTWSkgewogICAgICAgICAgICAgICAgIC8qIFRPRE86IGludm9rZSBzb21ldGhpbmcgc2ltaWxhciB0bwpAQCAtMTYyNyw3ICsxNjcxLDYgQEAKIHN0YXRpYyBpbnQgZG9fY3J5cHRvX2NvbXBsZXRlKGNvbnN0IGNoYXIqIG1vdW50X3BvaW50KSB7CiAgICAgc3RydWN0IGNyeXB0X21udF9mdHIgY3J5cHRfZnRyOwogICAgIGNoYXIgZW5jcnlwdGVkX3N0YXRlW1BST1BFUlRZX1ZBTFVFX01BWF07Ci0gICAgY2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sIGRlY3J5cHRlZF9tYXN0ZXJfa2V5LCByZWFsX2Jsa2RldiwgY3J5cHRvX2Jsa2RldiwgbGFiZWwsCi0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAwKSkgeworICAgIGlmIChjcmVhdGVfY3J5cHRvX2Jsa19kZXYoY3J5cHRfZnRyLCBkZWNyeXB0ZWRfbWFzdGVyX2tleSwgcmVhbF9ibGtkZXYuY19zdHIoKSwgJmNyeXB0b19ibGtkZXYsCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsYWJlbCwgMCkpIHsKICAgICAgICAgU0xPR0UoIkVycm9yIGNyZWF0aW5nIGRlY3J5cHRlZCBibG9jayBkZXZpY2VcbiIpOwogICAgICAgICByYyA9IC0xOwogICAgICAgICBnb3RvIGVycm91dDsKQEAgLTE3MzUsNyArMTc3OSw4IEBACiAgICAgICAgICAqIHRoZSBmb290ZXIsIG5vdCB0aGUga2V5LiAqLwogICAgICAgICBzbnByaW50Zih0bXBfbW91bnRfcG9pbnQsIHNpemVvZih0bXBfbW91bnRfcG9pbnQpLCAiJXMvdG1wX21udCIsIG1vdW50X3BvaW50KTsKICAgICAgICAgbWtkaXIodG1wX21vdW50X3BvaW50LCAwNzU1KTsKLSAgICAgICAgaWYgKGZzX21ncl9kb19tb3VudChmc3RhYl9kZWZhdWx0LCBEQVRBX01OVF9QT0lOVCwgY3J5cHRvX2Jsa2RldiwgdG1wX21vdW50X3BvaW50KSkgeworICAgICAgICBpZiAoZnNfbWdyX2RvX21vdW50KCZmc3RhYl9kZWZhdWx0LCBEQVRBX01OVF9QT0lOVCwKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdF9jYXN0PGNoYXIqPihjcnlwdG9fYmxrZGV2LmNfc3RyKCkpLCB0bXBfbW91bnRfcG9pbnQpKSB7CiAgICAgICAgICAgICBTTE9HRSgiRXJyb3IgdGVtcCBtb3VudGluZyBkZWNyeXB0ZWQgYmxvY2sgZGV2aWNlXG4iKTsKICAgICAg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GJvb3Qgc2VxdWVuY2UgKi8KICAgICAgICAgICAgICAgICBwcm9wZXJ0eV9zZXQoInJvLmNyeXB0by5zdGF0ZSIsICJlbmNyeXB0ZWQiKTsKICAgICAgICAgICAgICAgICBwcm9wZXJ0eV9zZXQoInJvLmNyeXB0by50eXBlIiwgImJsb2NrIik7Ci0gICAgICAgICAgICAgICAgcmVsZWFzZV93YWtlX2xvY2sobG9ja2lkKTsKKyAgICAgICAgICAgICAgICB3YWtlTG9jay5yZXNldChudWxscHRyKTsKICAgICAgICAgICAgICAgICBpZiAocmVib290RW5jcnlwdGlvbiAmJiBjcnlwdF9mdHIuY3J5cHRfdHlwZSAhPSBDUllQVF9UWVBFX0RFRkFVTFQpIHsKICAgICAgICAgICAgICAgICAgICAgLy8gQnJpbmcgdXAgY3J5cHRrZWVwZXIgdGhhdCB3aWxsIGNoZWNrIHRoZSBwYXNzd29yZCBhbmQgc2V0IGl0CiAgICAgICAgICAgICAgICAgICAgIHByb3BlcnR5X3NldCgidm9sZC5kZWNyeXB0IiwgInRyaWdnZXJfc2h1dGRvd25fZnJhbWV3b3JrIik7CkBAIC0yMzY5LDcgKzI0MTIsNiBAQAogICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgLyogc2V0IHByb3BlcnR5IHRvIHRyaWdnZXIgZGlhbG9nICovCiAgICAgICAgICAgICBwcm9wZXJ0eV9zZXQoInZvbGQuZW5jcnlwdF9wcm9ncmVzcyIsICJlcnJvcl9wYXJ0aWFsbHlfZW5jcnlwdGVkIik7Ci0gICAgICAgICAgICByZWxlYXNlX3dha2VfbG9jayhsb2NraWQpOwogICAgICAgICB9CiAgICAgICAgIHJldHVybiAtMTsKICAgICB9CkBAIC0yMzc5LDE0ICsyNDIxLDEwIEBACiAgICAgICogU2V0IHRoZSBwcm9wZXJ0eSBhbmQgcmV0dXJuLiAgSG9wZSB0aGUgZnJhbWV3b3JrIGNhbiBkZWFsIHdpdGggaXQuCiAgICAgICovCiAgICAgcHJvcGVydHlf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ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBhcnRpdGlvbiwgbnVsbCB0ZXJtaW5hdGVkICovCi0gICAgX19sZTMyIHNwYXJlMjsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8qIGlnbm9yZWQgKi8KLSAgICB1bnNpZ25lZCBjaGFyIG1hc3Rlcl9rZXlbTUFYX0tFWV9MRU5dOyAvKiBUaGUgZW5jcnlwdGVkIGtleSBmb3IgZGVjcnlwdGluZyB0aGUgZmlsZXN5c3RlbSAqLwotICAgIHVuc2lnbmVkIGNoYXIgc2FsdFtTQUxUX0xFTl07ICAgICAgICAgIC8qIFRoZSBzYWx0IHVzZWQgZm9yIHRoaXMgZW5jcnlwdGlvbiAqLwotICAgIF9fbGU2NCBwZXJzaXN0X2RhdGFfb2Zmc2V0WzJdOyAgICAgICAgIC8qIEFic29sdXRlIG9mZnNldCB0byBib3RoIGNvcGllcyBvZiBjcnlwdF9wZXJzaXN0X2RhdGEKLSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKiBvbiBkZXZpY2Ugd2l0aCB0aGF0IGluZm8sIGVpdGhlciB0aGUgZm9vdGVyIG9mIHRoZQotICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAqIHJlYWxfYmxrZGV2aWNlIG9yIHRoZSBtZXRhZGF0YSBwYXJ0aXRpb24uICovCi0KLSAgICBfX2xlMzIgcGVyc2lzdF9kYXRhX3NpemU7IC8qIFRoZSBudW1iZXIgb2YgYnl0ZXMgYWxsb2NhdGVkIHRvIGVhY2ggY29weSBvZiB0aGUKLSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAqIHBlcnNpc3RlbnQgZGF0YSB0YWJsZSovCi0KLSAgICBfX2xlOCBrZGZfdHlwZTsgLyogVGhlIGtleSBkZXJpdmF0aW9uIGZ1bmN0aW9uIHVzZWQu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ZXNzID0gZmFsc2U7CisgICAgZm9yIChhdXRvJiBlbnRyeSA6IGZzdGFiX2RlZmF1bHQpIHsKKyAgICAgICAgaWYgKGVudHJ5LmZzX21ncl9mbGFncy5xdW90YSkgeworICAgICAgICAgICAgY29uZmlncy0+aGFzX3F1b3RhID0gdHJ1ZTsKICAgICAgICAgfQotICAgICAgICBpZiAocmVjLT5yZXNlcnZlZF9zaXplID4gMCkgewotICAgICAgICAgICAgKmhhc19yZXNlcnZlZCA9IHRydWU7CisgICAgICAgIGlmIChlbnRyeS5yZXNlcnZlZF9zaXplID4gMCkgeworICAgICAgICAgICAgY29uZmlncy0+aGFzX3Jlc2VydmVkID0gdHJ1ZTsKKyAgICAgICAgfQorICAgICAgICBpZiAoZW50cnkuZnNfbWdyX2ZsYWdzLmZzX2NvbXByZXNzKSB7CisgICAgICAgICAgICBjb25maWdzLT5oYXNfY29tcHJlc3MgPSB0cnVlOwogICAgICAgICB9CiAKLSAgICAgICAgaWYgKGZzX21ncl9pc192b2xkbWFuYWdlZChyZWMpKSB7Ci0gICAgICAgICAgICBpZiAoZnNfbWdyX2lzX25vbnJlbW92YWJsZShyZWMpKSB7CisgICAgICAgIC8qIE1ha2Ugc3VyZSBsb2dpY2FsIHBhcnRpdGlvbnMgaGF2ZSBhbiB1cGRhdGVkIGJsa19kZXZpY2UuICovCisgICAgICAgIGlmIChlbnRyeS5mc19tZ3JfZmxhZ3MubG9naWNhbCAmJiAhZnNfbWdyX3VwZGF0ZV9sb2dpY2FsX3BhcnRpdGlvbigmZW50cnkpICYmCisgICAgICAgICAgICAhZW50cnkuZnNfbWdyX2ZsYWdzLm5vX2ZhaWwpIHsKKyAgICAgICAgICAgIFBMT0coRkFUQUwpIDw8ICJjb3VsZCBub3QgZmluZCBsb2dpY2FsIHBhcnRpdGlvbiAiIDw8IGVudHJ5LmJsa19kZXZpY2U7CisgICAgICAgIH0KKworICAgICAgICBpZiAoZW50cnkuZnNfbWdyX2ZsYWdzLnZvbGRfbWFuYWdlZCkgeworICAgICAgICAgICAgaWYgKGVudHJ5LmZzX21ncl9mbGFncy5ub25yZW1vdmFibGUpIHsKICAgICAgICAgICAgICAgICBMT0coV0FSTklORykgPDwgIm5vbnJlbW92YWJsZSBubyBsb25nZXIgc3VwcG9ydGVkOyBpZ25vcmluZyB2b2x1bWUiOwogICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgfQogCi0gICAgICAgICAgICBzdGQ6OnN0cmluZyBzeXNQYXR0ZXJuKHJlYy0+YmxrX2RldmljZSk7Ci0gICAgICAgICAgICBzdGQ6OnN0cmluZyBuaWNrbmFtZShyZWMtPmxhYmVsKTsKKyAgICAgICAgICAgIHN0ZDo6c3RyaW5nIHN5c1BhdHRlcm4oZW50cnkuYmxrX2RldmljZSk7CisgICAgICAgICAgICBzdGQ6OnN0cmluZyBuaWNrbmFtZShlbnRyeS5sYWJlbCk7CiAgICAgICAgICAgICBpbnQgZmxhZ3MgPSAwOwogCi0gICAgICAgICAgICBpZiAoZnNfbWdyX2lzX2VuY3J5cHRhYmxlKHJlYykpIHsKKyAgICAgICAgICAgIGlmIChlbnRyeS5pc19lbmNyeXB0YWJsZSgpKSB7CiAgICAgICAgICAgICAgICAgZmxhZ3MgfD0gYW5kcm9pZDo6dm9sZDo6RGlzazo6RmxhZ3M6OmtBZG9wdGFibGU7Ci0gICAgICAgICAgICAgICAgKmhhc19hZG9wdGFibGUgPSB0cnVlOworICAgICAgICAgICAgICAgIGNvbmZpZ3MtPmhhc19hZG9wdGFibGUgPSB0cnVlOwogICAgICAgICAgICAgfQotICAgICAgICAgICAgaWYgKGZzX21ncl9pc19ub2VtdWxhdGVkc2QocmVjKSB8fAorICAgICAgICAgICAgaWYgKGVudHJ5LmZzX21ncl9mbGFncy5ub19lbXVsYXRlZF9zZCB8fAogICAgICAgICAgICAgICAgIGFuZHJvaWQ6OmJhc2U6OkdldEJvb2xQcm9wZXJ0eSgidm9sZC5kZWJ1Zy5kZWZhdWx0X3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xlLCAwNzAwLCBBSURfU1lTVEVNLCBBSURfU1lTVEVNLAorICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzeXN0ZW1fY2VfcGF0aCArICIvYmFja3VwX3N0YWdlIikpIHsKKyAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7CisgICAgICAgICAgICB9CisgICAgICAgICAgICBhdXRvIHZlbmRvcl9jZV9wYXRoID0gYW5kcm9pZDo6dm9sZDo6QnVpbGREYXRhVmVuZG9yQ2VQYXRoKHVzZXJfaWQpOworICAgICAgICAgICAgYXV0byBmYWNlZGF0YV9wYXRoID0gdmVuZG9yX2NlX3BhdGggKyAiL2ZhY2VkYXRhIjsKKyAgICAgICAgICAgIGlmICghcHJlcGFyZV9kaXIoc2VoYW5kbGUsIDA3MDAsIEFJRF9TWVNURU0sIEFJRF9TWVNURU0sIGZhY2VkYXRhX3BhdGgpKSB7CisgICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlOworICAgICAgICAgICAgfQogICAgICAgICB9CiAgICAgfQogICAgIHJldHVybiB0cnVlOwo=