LyoqDQogKiBAZmlsZSBmbGFnc19hcGkuYw0KICogQGJyaWVmIGZsYWdzt9bH+L3Tv9rKtc/WDQogKg0KICogQ29weXJpZ2h0IChDKSAyMDIzIFNhbmVjaGlwcyBUZWNobm9sb2d5IENvLiwgTHRkLg0KICogQGF1dGhvciANCiAqIA0KICogVGhpcyBwcm9ncmFtIGlzIGZyZWUgc29mdHdhcmU7IHlvdSBjYW4gcmVkaXN0cmlidXRlIGl0IGFuZC9vciBtb2RpZnkNCiAqIGl0IHVuZGVyIHRoZSB0ZXJtcyBvZiB0aGUgR05VIEdlbmVyYWwgUHVibGljIExpY2Vuc2UgdmVyc2lvbiAyIGFzDQogKiBwdWJsaXNoZWQgYnkgdGhlIEZyZWUgU29mdHdhcmUgRm91bmRhdGlvbi4go6ix2NGho7pHUEx2MiBMaWNlbmNlo6kNCiAqDQogKi8NCg0KDQovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg0KICogICAgICAgICAgICAgICAgICAgICAgICAgICBJbmNsdWRlIGhlYWRlciBmaWxlcyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICoNCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovDQojaW5jbHVkZSA8c3RkaW8uaD4NCiNpbmNsdWRlIDxzdGRsaWIuaD4NCiNpbmNsdWRlIDx1bmlzdGQuaD4NCiNpbmNsdWRlIDxzdHJpbmcuaD4NCiNpbmNsdWRlIDxlcnJuby5oPg0KI2luY2x1ZGUgPHN5cy9pb2N0bC5oPg0KI2luY2x1ZGUgPHN5cy9zdGF0Lmg+DQojaW5jbHVkZSA8ZmNudGwuaD4NCiNpbmNsdWRlIDxtdGQvbXRkLWFiaS5oPg0KDQojaW5jbHVkZSAicHViX2ZsYWdzLmgiDQoNCiNpbmNsdWRlICJmbGFnc19sb2cuaCINCiNpbmNsdWRlICJmbGFnc19hcGkuaCINCg0KDQovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg0KICogICAgICAgICAgICAgICAgICAgICAgICAgICAgIE1hY3JvIGRlZmluaXRpb25zICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICoNCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovDQojZGVmaW5lIE1BWF9QQVRIX0xFTiAoMjU2KQ0KDQojZGVmaW5lIFBBUlRJVElPTl9OQU1FX0ZMQUdTICJmbGFncyINCg0KI2RlZmluZSBGTEFHU19JTklUX1ZBTElEX0JMT0NLU19OVU0JKDgpDQoNCiNkZWZpbmUgR09PRF9CTE9DSyAoMCkNCiNkZWZpbmUgQkFEX0JMT0NLICgxKQ0KDQojZGVmaW5lIEZJTEVfUEFUSF9QUk9DX0NNRExJTkUgIi9wcm9jL2NtZGxpbmUiDQoNCiNkZWZpbmUgUFJPQ19DTURMSU5FX1NZU1RFTV9BX0ZMQUcgICAic3lzdGVtPXN5c3RlbV9hIg0KI2RlZmluZSBQUk9DX0NNRExJTkVfU1lTVEVNX0JfRkxBRyAgICJzeXN0ZW09c3lzdGVtX2IiDQoNCiNkZWZpbmUgU1lTVEVNX0lOREVYX1VOS05PV04gKC0xKQ0KI2RlZmluZSBTWVNURU1fSU5ERVhfMSAoMSkNCiNkZWZpbmUgU1lTVEVNX0lOREVYXzIgKDIpDQoNCg0KLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioNCiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICBUeXBlIGRlZmluaXRpb25zICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAqDQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLw0KdHlwZWRlZiBzdHJ1Y3QNCnsNCiAgICB1bnNpZ25lZCBpbnQgbXRkX3RvdGFsc2l6ZTsJCQkJLy8gbXRkIGRldmljZSB0b3RhbCBzaXplDQogICAgdW5zaWduZWQgaW50IG10ZF9wYWdlcGVyYmxvY2s7CQkJLy8gbXRkIGRldmljZSBwYWdlIHBlciBibG9jaw0KICAgIHVuc2lnbmVkIGludCBtdGRfYmxvY2tzaXplOwkJCQkvLyBtdGQgZGV2aWNlIGJsb2NrIHNpemUNCiAgICB1bnNpZ25lZCBpbnQgbXRkX3BhZ2VzaXplOwkJCQkvLyBtdGQgZGV2aWNlIHBhZ2Ugc2l6ZQ0KICAgIHVuc2lnbmVkIGludCBtdGRfb29ic2l6ZTsJCQkJLy8gbXRkIGRldmljZSBvb2Igc2l6ZQ0KICAgIGludCBwYXJ0aV9maWxlX2Rlc2M7CQkJCQkvLyBwYXJ0aXRpb24gdXBkYXRlIGZpbGUgZGVzY3JpcHRpb24NCn0gcGFydGl0aW9uX210ZF9pbmZvX3Q7DQoNCg0KdHlwZWRlZiBlbnVtDQp7DQogICAgREVWSUNFX01URCA9IDAsDQogICAgREVWSUNFX1pGVEwgPSAxLA0KICAgIERFVklDRV9NVERfQkxPQ0ssDQp9IGRldmljZV90eXBlX3Q7DQoNCg0KLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioNCiAqCQkJCQkJICAgTG9jYWwgdmFyaWFibGUgZGVmaW5pdGlvbnMJCQkJCQkgICAqDQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLw0KDQoNCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqDQogKgkJCQkJCSAgR2xvYmFsIHZhcmlhYmxlIGRlZmluaXRpb25zCQkJCQkJICAgKg0KICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8NCg0KDQovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg0KICogCQkJCQkgICBMb2NhbCBmdW5jdGlvbiBkZWNsYXJhdGlvbnMJCQkJCQkJICAgKg0KICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8NCnN0YXRpYyBpbnQgbXRkX2dldChjb25zdCBjaGFyICppX3BhcnRpX25hbWUsIGRldmljZV90eXBlX3QgZGV2aWNlX3R5cGUsIGNoYXIgKm9fbXRkX3BhdGgsIHVuc2lnbmVkIGludCBvX210ZF9wYXRoX2xlbik7DQpzdGF0aWMgaW50IHdyaXRlX2ZsYWdzX2luZm8ocGFydGl0aW9uX210ZF9pbmZvX3QgKnBfbXRkX2luZm8sIGludCBpbmRleCwgdW5zaWduZWQgY2hhciAqY29udGVudCwgaW50IGxlbik7DQoNCnN0YXRpYyBpbnQgZ2V0X2ZsYWdzX2luZm8oVF9GTEFHU19JTkZPICpwX21haW4sIGludCAqcF9tYWluX2luZGV4LCBUX0ZMQUdTX0lORk8gKnBfYmFja3VwLCBpbnQgKnBfYmFja3VwX2luZGV4KTsNCnN0YXRpYyBpbnQgc2V0X2ZsYWdzX2luZm8oVF9GTEFHU19JTkZPICpwX2ZsYWdzX2luZm8sIGludCAqcF9tYWluX2luZGV4LCBpbnQgKnBfYmFja3VwX2luZGV4KTsNCg0Kc3RhdGljIHZvaWQgY29weV9mbGFnc19pbmZvKFRfRkxBR1NfSU5GTyAqZHN0LCBUX0ZMQUdTX0lORk8gKnNyYyk7DQoNCnN0YXRpYyBpbnQgZ2V0X2N1cnJlbnRfc3lzdGVtKCk7DQoNCg0KLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioNCiAqIAkJCQkJIExvY2FsIGZ1bmN0aW9uIGltcGxlbWVudGF0aW9ucyAJCQkJCQkgICAqDQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLw0Kc3RhdGljIGludCBtdGRfZ2V0KGNvbnN0IGNoYXIgKmlfcGFydGlfbmFtZSwgZGV2aWNlX3R5cGVfdCBkZXZpY2VfdHlwZSwgY2hhciAqb19tdGRfcGF0aCwgdW5zaWduZWQgaW50IG9fbXRkX3BhdGhfbGVuKQ0Kew0KICAgIEZJTEUgKmZwX210ZCA9IDA7DQogICAgY2hhciBidWZbMTI4XTsNCiAgICBjaGFyICpsaW5lX3N0cjsNCg0KICAgIGlmICghb19tdGRfcGF0aF9sZW4pDQogICAgew0KICAgICAgICByZXR1cm4gLTE7DQogICAgfQ0KDQogICAgZnBfbXRkID0gZm9wZW4oIi9wcm9jL210ZCIsICJyKyIpOw0KICAgIGlmIChOVUxMID09IGZwX210ZCkNCiAgICB7DQogICAgICAgIGZsYWdzX2Vycigib3BlbiBmaWxlIGVycm9yOiAlcyIsIHN0cmVycm9yKGVycm5vKSk7DQogICAgICAgIHJldHVybiAtMTsNCiAgICB9DQogICAgLy8gcHJpbnRmKCJbbGlibXRkXTogcGFydGl0aW9uIG5hbWU6JXNcbiIsIGlfcGFydGlfbmFtZSk7DQoNCiAgICB3aGlsZSAoMSkNCiAgICB7DQogICAgICAgIGludCBtYXRjaGVzID0gMDsNCiAgICAgICAgY2hhciBtdGRuYW1lWzY0XSA9IHswfTsNCiAgICAgICAgaW50IG10ZG51bSA9IDA7DQogICAgICAgIHVuc2lnbmVkIGludCBtdGRzaXplLCBtdGRlcmFzZXNpemU7DQogICAgICAgIG1lbXNldChidWYsIDAsIHNpemVvZihidWYpKTsNCiAgICAgICAgbGluZV9zdHIgPSBmZ2V0cyhidWYsIHNpemVvZihidWYpIC0gMSwgZnBfbXRkKTsNCg0KICAgICAgICBpZiAoTlVMTCA9PSBsaW5lX3N0cikNCiAgICAgICAgew0KICAgICAgICAgICAgZmxhZ3NfZXJyKCJnZXQgaW5mbyBmcm9tIG10ZCBlcnJvcjogJXMiLCBzdHJlcnJvcihlcnJubykpOw0KICAgICAgICAgICAgZmNsb3NlKGZwX210ZCk7DQogICAgICAgICAgICByZXR1cm4gLTE7DQogICAgICAgIH0NCiAgICAgICAgLy8gbXRkNTogMDAxMDAwMDAgMDAwMjAwMDAgImZvdGFmbGFnIg0KICAgICAgICBtYXRjaGVzID0gc3NjYW5mKGJ1ZiwgIm10ZCVkOiAleCAleCBcIiU2M1teXCJdIiwNCiAgICAgICAgICAgICAgICAgICAgICAgICAmbXRkbnVtLCAmbXRkc2l6ZSwgJm10ZGVyYXNlc2l6ZSwgbXRkbmFtZSk7DQogICAgICAgIG10ZG5hbWVbNjNdID0gJ1wwJzsNCg0KICAgICAgICBpZiAoKG1hdGNoZXMgPT0gNCkgJiYgKHN0cmNtcChtdGRuYW1lLCBpX3BhcnRpX25hbWUpID09IDApKQ0KICAgICAgICB7DQogICAgICAgICAgICBtZW1zZXQob19tdGRfcGF0aCwgMCwgb19tdGRfcGF0aF9sZW4pOw0KICAgICAgICAgICAgaWYgKGRldmljZV90eXBlID09IERFVklDRV9NVERfQkxPQ0spDQogICAgICAgICAgICB7DQogICAgICAgICAgICAgICAgc25wcmludGYob19tdGRfcGF0aCwgb19tdGRfcGF0aF9sZW4sICIvZGV2L210ZGJsb2NrJWQiLCBtdGRudW0pOw0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgZWxzZSBpZiAoZGV2aWNlX3R5cGUgPT0gREVWSUNFX01URCkNCiAgICAgICAgICAgIHsNCiAgICAgICAgICAgICAgICBzbnByaW50ZihvX210ZF9wYXRoLCBvX210ZF9wYXRoX2xlbiwgIi9kZXYvbXRkJWQiLCBtdGRudW0pOw0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgZWxzZSBpZiAoZGV2aWNlX3R5cGUgPT0gREVWSUNFX1pGVEwpDQogICAgICAgICAgICB7DQogICAgICAgICAgICAgICAgc25wcmludGYob19tdGRfcGF0aCwgb19tdGRfcGF0aF9sZW4sICIvZGV2L3pmdGwlZCIsIG10ZG51bSk7DQogICAgICAgICAgICB9DQogICAgICAgICAgICBlbHNlDQogICAgICAgICAgICB7DQogICAgICAgICAgICAgICAgZmxhZ3NfZXJyKCJ1bmtub3duIGRldmljZSB0eXBlICVkIiwgZGV2aWNlX3R5cGUpOw0KICAgICAgICAgICAgICAgIGZjbG9zZShmcF9tdGQpOw0KICAgICAgICAgICAgICAgIHJldHVybiAtMTsNCiAgICAgICAgICAgIH0NCiAgICAgICAgICAgIC8vIHByaW50ZigiW2xpYm10ZF06IG9fbXRkX3BhdGg9WyVzXVxuIiwgb19tdGRfcGF0aCk7DQogICAgICAgICAgICBicmVhazsNCiAgICAgICAgfQ0KICAgIH0NCiAgICBmY2xvc2UoZnBfbXRkKTsNCiAgICByZXR1cm4gMDsNCn0NCg0KDQpzdGF0aWMgaW50IHdyaXRlX2ZsYWdzX2luZm8ocGFydGl0aW9uX210ZF9pbmZvX3QgKnBfbXRkX2luZm8sIGludCBpbmRleCwgdW5zaWduZWQgY2hhciAqY29udGVudCwgaW50IGxlbikNCnsNCiAgICBzdHJ1Y3QgZXJhc2VfaW5mb191c2VyIGVyYXNlX2luZm87DQogICAgaW50IHdyaXRlX2xlbiA9IDA7DQogICAgbG9uZyBsb25nICBvZmZzID0gMDsNCg0KICAgIGVyYXNlX2luZm8uc3RhcnQgPSBpbmRleCAqIHBfbXRkX2luZm8tPm10ZF9ibG9ja3NpemU7DQogICAgZXJhc2VfaW5mby5sZW5ndGggPSBwX210ZF9pbm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ZmcykgPT0gMCkNCiAgICAgICAgew0KICAgICAgICAgICAgYmxvY2tfZmxhZyA9IEdPT0RfQkxPQ0s7DQogICAgICAgIH0NCiAgICAgICAgZWxzZQ0KICAgICAgICB7DQogICAgICAgICAgICBmbGFnc19lcnIoImZsYWdzIGJsb2NrIFslZF0gaXMgYmFkLCBlcnJubz0lZCwgc3RyZXJyb3I9WyVzXSIsIGluZGV4LCBlcnJubywgc3RyZXJyb3IoZXJybm8pKTsNCiAgICAgICAgICAgIGJsb2NrX2ZsYWcgPSAgQkFEX0JMT0NLOw0KICAgICAgICB9DQoNCiAgICAgICAgaWYgKGJsb2NrX2ZsYWcgPT0gR09PRF9CTE9DSykNCiAgICAgICAgew0KICAgICAgICAgICAgaWYgKGxzZWVrKG10ZF9pbmZvLnBhcnRpX2ZpbGVfZGVzYywgaW5kZXggKiBtdGRfaW5mby5tdGRfYmxvY2tzaXplLCBTRUVLX1NFVCkgPCAwKQ0KICAgICAgICAgICAgew0KICAgICAgICAgICAgICAgIGZsYWdzX2VycigibHNlZWsgZXJyb3IsIGVycm5vPSVkLCBzdHJlcnJvcj1bJXNdIiwgZXJybm8sIHN0cmVycm9yKGVycm5vKSk7DQogICAgICAgICAgICAgICAgZ290byBlcnJvcl9jbG9zZTsNCiAgICAgICAgICAgIH0NCg0KICAgICAgICAgICAgaWYgKGdvb2RfaW5kZXggPT0gMCkNCiAgICAgICAgICAgIHsNCiAgICAgICAgICAgICAgICByZWFkX2xlbiA9IHJlYWQobXRkX2luZm8ucGFydGlfZmlsZV9kZXNjLCAodW5zaWduZWQgY2hhciopcF9tYWluLCBzaXplb2YoVF9GTEFHU19JTkZPKSk7DQogICAgICAgICAgICAgICAgKnBfbWFpbl9pbmRleCA9IGluZGV4Ow0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgZWxzZSBpZiAoZ29vZF9pbmRleCA9PSAxKQ0KICAgICAgICAgICAgew0KICAgICAgICAgICAgICAgIHJlYWRfbGVuID0gcmVhZChtdGRfaW5mby5wYXJ0aV9maWxlX2Rlc2MsICh1bnNpZ25lZCBjaGFyKilwX2JhY2t1cCwgc2l6ZW9mKFRfRkxBR1NfSU5GTykpOw0KICAgICAgICAgICAgICAgICpwX2JhY2t1cF9pbmRleCA9IGluZGV4Ow0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgZWxzZQ0KICAgICAgICAgICAgew0KICAgICAgICAgICAgICAgIGJyZWFrOw0KICAgICAgICAgICAgfQ0KDQogICAgICAgICAgICBpZiAocmVhZF9sZW4gPCBzaXplb2YoVF9GTEFHU19JTkZPKSkNCiAgICAgICAgICAgIHsNCiAgICAgICAgICAgICAgICBmbGFnc19lcnIoInJlYWQgbGVuICglZCkgPCBuZWVkIGxlbiAoJWQpIiwgcmVhZF9sZW4sIHNpemVvZihUX0ZMQUdTX0lORk8pKTsNCiAgICAgICAgICAgICAgICBnb3RvIGVycm9yX2Nsb3NlOw0KICAgICAgICAgICAgfQ0KDQogICAgICAgICAgICBnb29kX2luZGV4Kys7DQogICAgICAgIH0NCg0KICAgIH0NCg0KICAgIGNsb3NlKGZkX2RzdCk7DQoNCiAgICByZXR1cm4gMDsNCg0KZXJyb3JfY2xvc2U6DQogICAgY2xvc2UoZmRfZHN0KTsNCg0KZXJyb3I6DQogICAgcmV0dXJuIC0xOw0KfQ0KDQoNCnN0YXRpYyBpbnQgc2V0X2ZsYWdzX2luZm8oVF9GTEFHU19JTkZPICpwX2ZsYWdzX2luZm8sIGludCAqcF9tYWluX2luZGV4LCBpbnQgKnBfYmFja3VwX2luZGV4KQ0Kew0KICAgIGludCByZXQgPSAtMTsNCiAgICBpbnQgZmRfZHN0ID0gLTE7DQogICAgY2hhciBtdGRfcGF0aFtNQVhfUEFUSF9MRU5dID0gezB9Ow0KICAgIHN0cnVjdCBtdGRfaW5mb191c2VyIG1lbWluZm8gPSB7MH07DQogICAgcGFydGl0aW9uX210ZF9pbmZvX3QgbXRkX2luZm8gPSB7MH07DQoNCiAgICB1bnNpZ25lZCB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ZV9jb250ZW50LCBtdGRfaW5mby5tdGRfYmxvY2tzaXplKTsNCiAgICAgICAgaWYgKHJldCA9PSAwKQ0KICAgICAgICB7DQogICAgICAgICAgICAvLyDQtLPJuaajrM3Ls/ajrLKiuPzQwrXa0ru/6c671sMNCiAgICAgICAgICAgIGZsYWdzX2xvZygibWFpbiBmbGFncyBsb2NhdGlvbjogWyVkXS0+WyVkXSIsIG1haW5faW5kZXgsIGluZGV4KTsNCiAgICAgICAgICAgIG1haW5faW5kZXggPSBpbmRleDsNCiAgICAgICAgICAgIGJyZWFrOw0KICAgICAgICB9DQogICAgICAgIGVsc2UgaWYgKHJldCA9PSBCQURfQkxPQ0spDQogICAgICAgIHsNCiAgICAgICAgICAgIC8vINP2tb27tb/po6zP8rrzzPjSu7/pDQogICAgICAgICAgICBmbGFnc19sb2coImZsYWdzIGJsb2NrIGluZGV4IFslZF0gaXMgYmFkIiwgaW5kZXgpOw0KICAgICAgICAgICAgY29udGludWU7DQogICAgICAgIH0NCiAgICAgICAgZWxzZQ0KICAgICAgICB7DQogICAgICAgICAgICBmbGFnc19lcnIoIndyaXRlIG1haW4gZmxhZ3MgZmFpbCIpOw0KICAgICAgICAgICAgbWFpbl9pbmRleCA9IC0xOw0KICAgICAgICAgICAgYnJlYWs7DQogICAgICAgIH0NCiAgICB9DQoNCiAgICBmbGFnc19sb2coImJlZ2luIHRvIHdyaXRlIGJhY2t1cCBmbGFncyIpOw0KDQogICAgZm9yIChpbmRleCA9IDA7IGluZGV4IDwgYmxvY2tfbnVtOyBpbmRleCsrKQ0KICAgIHsNCiAgICAgICAgaWYgKGluZGV4ID09IG1haW5faW5kZXgpDQogICAgICAgIHsNCiAgICAgICAgICAgIGNvbnRpbnVlOw0KICAgICAgICB9DQoNCiAgICAgICAgZmxhZ3NfbG9nKCJ3cml0ZSBiYWNrdXAgdG8gWyVkXSBibG9jayIsIGluZGV4KTsNCiAgICAgICAgcmV0ID0gd3JpdGVfZmxhZ3NfaW5mbygmbXRkX2luZm8sIGluZGV4LCByZWFsX3dyaXRlX2NvbnRlbnQsIG10ZF9pbmZvLm10ZF9ibG9ja3NpemUpOw0KICAgICAgICBpZiAocmV0ID09IDApDQogICAgICAgIHsNCiAgICAgICAgICAgIC8vINC0s8m5pqOszcuz9qOssqK4/NDCtdrSu7/pzrvWww0KICAgICAgICAgICAgZmxhZ3NfbG9nKCJiYWNrdXAgZmxhZ3MgbG9jYXRpb246IFslZF0tPlslZF0iLCBiYWNrX2luZGV4LCBpbmRleCk7DQogICAgICAgICAgICBiYWNrX2luZGV4ID0gaW5kZXg7DQogICAgICAgICAgICBicmVhazsNCiAgICAgICAgfQ0KICAgICAgICBlbHNlIGlmIChyZXQgPT0gQkFEX0JMT0NLKQ0KICAgICAgICB7DQogICAgICAgICAgICAvLyDT9rW9u7W/6aOsz/K688z40ru/6Q0KICAgICAgICAgICAgY29udGludWU7DQogICAgICAgIH0NCiAgICAgICAgZWxzZQ0KICAgICAgICB7DQogICAgICAgICAgICBmbGFnc19lcnIoIndyaXRlIGJhY2t1cCBmbGFncyBmYWlsIik7DQogICAgICAgICAgICBiYWNrX2luZGV4ID0gLTE7DQogICAgICAgICAgICBicmVhazsNCiAgICAgICAgfQ0KICAgIH0NCg0KICAgIGlmIChtYWluX2luZGV4ID09IC0xICYmIGJhY2tfaW5kZXggPT0gLTEpDQogICAgew0KICAgICAgICBnb3RvIGVycm9yOw0KICAgIH0NCiAgICBlbHNlDQogICAgew0KICAgICAgICByZXQgPSAwOw0KICAgICAgICBnb3RvIGVuZDsNCiAgICB9DQoNCmVycm9yOg0KICAgIHJldCA9IC0xOw0KDQplbmQ6DQogICAgY2xvc2UoZmRfZHN0KTsNCgkNCglpZihOVUxMICE9IHJlYWxfd3JpdGVfY29udGVudCkNCgl7DQoJCWZyZWUocmVhbF93cml0ZV9jb250ZW50KTsNCgkJcmVhbF93cml0ZV9jb250ZW50ID0gTlVMTDsNCgl9DQoJDQogICAgcmV0dXJuIHJldDsNCn0NCg0KDQ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gU1lTVEVNX0lOREVYX1VOS05PV047DQogICAgfQ0KDQogICAgd2hpbGUgKCFmZW9mKGZkX2NtZCkpDQogICAgew0KICAgICAgICBtZW1zZXQoYnVmLCAwLCBzaXplb2YoYnVmKSk7DQogICAgICAgIGxpbmVfc3RyID0gZmdldHMoYnVmLCBzaXplb2YoYnVmKSwgZmRfY21kKTsNCg0KICAgICAgICBpZiAoTlVMTCA9PSBsaW5lX3N0cikNCiAgICAgICAgew0KICAgICAgICAgICAgZmxhZ3NfZXJyKCJnZXQgaW5mbyBmcm9tIC9wcm9jL2NtZGxpbmUgZXJyb3I6JXMiLCBzdHJlcnJvcihlcnJubykpOw0KICAgICAgICAgICAgZ290byBlbmQ7DQogICAgICAgIH0NCg0KICAgICAgICBmbGFnc19sb2coImJ1ZmY6JXMiLCBidWYpOw0KDQogICAgICAgIHBhcmEgPSBzdHJ0b2soYnVmLCAiICIpOw0KICAgICAgICB3aGlsZSAocGFyYSkNCiAgICAgICAgew0KICAgICAgICAgICAgZmxhZ3NfbG9nKCJwYXJhOiVzIiwgcGFyYSk7DQogICAgICAgICAgICBpZiAoc3RybmNtcChwYXJhLCBQUk9DX0NNRExJTkVfU1lTVEVNX0FfRkxBRywgc3RybGVuKFBST0NfQ01ETElORV9TWVNURU1fQV9GTEFHKSkgPT0gMCkNCiAgICAgICAgICAgIHsNCiAgICAgICAgICAgICAgICBjdXJyZW50X3N5c3RlbSA9IFNZU1RFTV9JTkRFWF8xOw0KICAgICAgICAgICAgICAgIGdvdG8gZW5kOw0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgZWxzZSBpZiAoc3RybmNtcChwYXJhLCBQUk9DX0NNRExJTkVfU1lTVEVNX0JfRkxBRywgc3RybGVuKFBST0NfQ01ETElORV9TWVNURU1fQl9GTEFHKSkgPT0gMCkNCiAgICAgICAgICAgIHsNCiAgICAgICAgICAgICAgICBjdXJyZW50X3N5c3RlbSA9IFNZU1RFTV9JTkRFWF8yOw0KICAgICAgICAgICAgICAgIGdvdG8gZW5kOw0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgZWxzZQ0KICAgICAgICAgICAgew0KICAgICAgICAgICAgICAgIC8vOg0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgcGFyYSA9IHN0cnRvayhOVUxMLCAiICIpOw0KICAgICAgICB9DQogICAgfQ0KDQplbmQ6DQogICAgaWYgKGZkX2NtZCkNCiAgICB7DQogICAgICAgIGZjbG9zZShmZF9jbWQpOw0KICAgIH0NCgkNCiAgICByZXR1cm4gY3VycmVudF9zeXN0ZW07DQp9DQoNCg0KLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioNCiAqIAkJCQkJIEdsb2JhbCBmdW5jdGlvbiBpbXBsZW1lbnRhdGlvbnMJCQkJCQkgICAqDQogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLw0KaW50IGZsYWdzX2luaXQoKQ0Kew0KCVRfRkxBR1NfSU5GTyBmbGFnc19pbmZvID0gezB9Ow0KCWludCBtYWluX2luZGV4ID0gMDsNCglpbnQgYmFja19pbmRleCA9IDE7DQoJaW50IHJldCA9IC0xOw0KCWludCBmZF9kc3QgPSAtMTsNCgljaGFyIG10ZF9wYXRoW01BWF9QQVRIX0xFTl0gPSB7MH07DQoJc3RydWN0IG10ZF9pbmZvX3VzZXIgbWVtaW5mbyA9IHswfTsNCglwYXJ0aXRpb25fbXRkX2luZm9fdCBtdGRfaW5mbyA9IHswfTsNCg0KCXVuc2lnbmVkIGNoYXIgKnJlYWxfd3JpdGVfY29udGVudCA9IE5VTEw7DQoJVF9GTEFHU19JTkZPICpwX3dyaXRlID0gTlVMTDsNCg0KCWludCBpbmRleCAgPSAwOw0KCWludCBibG9ja19udW0gPSAwOw0KCWludCBhbHJlYWR5X3dyaXRlID0gMDsNCgkNCiAgIC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