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dGlvbiAqLwogICAgdWludDhfdCBoZWFkOwogICAgdWludDhfdCB0cmFjazsKICAgIHVpbnQ4X3Qgc2VjdDsKICAgIC8qIE1lZGlhICovCiAgICBGRGlza0ZsYWdzIGZsYWdzOwogICAgdWludDhfdCBsYXN0X3NlY3Q7ICAgICAgICAvKiBOYiBzZWN0b3IgcGVyIHRyYWNrICAgICovCiAgICB1aW50OF90IG1heF90cmFjazsgICAgICAgIC8qIE5iIG9mIHRyYWNrcyAgICAgICAgICAgKi8KICAgIHVpbnQxNl90IGJwczsgICAgICAgICAgICAgLyogQnl0ZXMgcGVyIHNlY3RvciAgICAgICAqLwogICAgdWludDhfdCBybzsgICAgICAgICAgICAgICAvKiBJcyByZWFkLW9ubHkgICAgICAgICAgICovCn0gRkRyaXZlOwoKc3RhdGljIHZvaWQgZmRfaW5pdChGRHJpdmUgKmRydikKewogICAgLyogRHJpdmUgKi8KICAgIGRydi0+YnMgPSBkcnYtPmRpbmZvID8gZHJ2LT5kaW5mby0+YmRydiA6IE5VTEw7CiAgICBkcnYtPmRyaXZlID0gRkRSSVZFX0RSVl9OT05FOwogICAgZHJ2LT5wZXJwZW5kaWN1bGFyID0gMDsKICAgIC8qIERpc2sgKi8KICAgIGRydi0+bGFzdF9zZWN0ID0gMDsKICAgIGRydi0+bWF4X3RyYWNrID0gMDsKfQoKc3RhdGljIGludCBmZF9zZWN0b3JfY2FsYyh1aW50OF90IGhlYWQsIHVpbnQ4X3QgdHJhY2ssIHVpbnQ4X3Qgc2VjdCwKICAgICAgICAgICAgICAgICAgICAgICAgICB1aW50OF90IGxhc3Rfc2VjdCkKewogICAgcmV0dXJuICgoKHRyYWNrICogMikgKyBoZWFkKSAqIGxhc3Rfc2VjdCkgKyBzZWN0IC0gMTsKfQoKLyogUmV0dXJucyBjdXJyZW50IHBvc2l0aW9uLCBpbiBzZWN0b3JzLCBmb3IgZ2l2ZW4gZHJpdmUgKi8Kc3RhdGljIGludCBmZF9zZWN0b3IoRkRyaXZlICp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AgICAgICAgICAgICAgICBkcnYtPmRyaXZlID09IEZEUklWRV9EUlZfTk9ORSkgewogICAgICAgICAgICAgICAgICAgIHNpemUgPSAocGFyc2UtPm1heF9oZWFkICsgMSkgKiBwYXJzZS0+bWF4X3RyYWNrICoKICAgICAgICAgICAgICAgICAgICAgICAgcGFyc2UtPmxhc3Rfc2VjdDsKICAgICAgICAgICAgICAgICAgICBpZiAobmJfc2VjdG9ycyA9PSBzaXplKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIG1hdGNoID0gaTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChmaXJzdF9tYXRjaCA9PSAtMSkKICAgICAgICAgICAgICAgICAgICAgICAgZmlyc3RfbWF0Y2ggPSBpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChtYXRjaCA9PSAtMSkgewogICAgICAgICAgICAgICAgaWYgKGZpcnN0X21hdGNoID09IC0xKQogICAgICAgICAgICAgICAgICAgIG1hdGNoID0gMTsKICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgICBtYXRjaCA9IGZpcnN0X21hdGNoOwogICAgICAgICAgICAgICAgcGFyc2UgPSAmZmRfZm9ybWF0c1ttYXRjaF07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbmJfaGVhZHMgPSBwYXJzZS0+bWF4X2hlYWQgKyAxOwogICAgICAgICAgICBtYXhfdHJhY2sgPSBwYXJzZS0+bWF4X3RyYWNrOwogICAgICAgICAgICBsYXN0X3NlY3QgPSBwYXJzZS0+bGFzdF9zZWN0OwogICAgICAgICAgICBkcnYtPmRyaXZlID0gcGFyc2UtPmRyaXZlOwogICAgICAgICAgICBGTE9QUFlfRFBSSU5URigiJXMgZmxvcHB5IGRpc2sgKCVkIGggJWQgdCAlZCBzKSAlc1xuIiwgcGFyc2UtPnN0ciwKICAgICAgICAgICAgICAgICAgICAgICAgICAgbmJfaGVhZHMsIG1heF90cmFjaywgbGFzdF9zZWN0LCBybyA/ICJybyIgOiAicnciKTsKICAgICAgICB9CiAgICAgICAgaWYgKG5iX2hlYWRzID09IDEpIHsKICAgICAgICAgICAgZHJ2LT5mbGFncyAmPSB+RkRJU0tfREJMX1NJREVTOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGRydi0+ZmxhZ3MgfD0gRkRJU0tfREJMX1NJREVTOwogICAgICAgIH0KICAgICAgICBkcnYtPm1heF90cmFjayA9IG1heF90cmFjazsKICAgICAgICBkcnYtPmxhc3Rfc2VjdCA9IGxhc3Rfc2VjdDsKICAgICAgICBkcnYtPnJvID0gcm87CiAgICB9IGVsc2UgewogICAgICAgIEZMT1BQWV9EUFJJTlRGKCJObyBkaXNrIGluIGRyaXZlXG4iKTsKICAgICAgICBkcnYtPmxhc3Rfc2VjdCA9IDA7CiAgICAgICAgZHJ2LT5tYXhfdHJhY2sgPSAwOwogICAgICAgIGRydi0+ZmxhZ3MgJj0gfkZESVNLX0RCTF9TSURFUzsKICAgIH0KfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwovKiBJbnRlbCA4MjA3OCBmbG9wcHkgZGlzayBjb250cm9sbGVyIGVtdWxhdGlvbiAgICAgICAgICAqLwoKc3RhdGljIHZvaWQgZmRjdHJsX3Jlc2V0KEZEQ3RybCAqZmRjdHJsLCBpbnQgZG9faXJxKTsKc3RhdGljIHZvaWQgZmRjdHJsX3Jlc2V0X2ZpZm8oRkRDdHJsICpmZGN0cmwpOwpzdGF0aWMgaW50IGZkY3RybF90cmFuc2Zlcl9oYW5kbGVyICh2b2lkICpvcGFxdWUsIGludCBuY2hhbiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaW50IGRtYV9wb3MsIGludCBkbWFfbGVuKTsKc3RhdGljIHZvaWQgZmRjdHJsX3JhaXNlX2lycShGREN0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Rydi0+bGFzdF9zZWN0IHx8CiAgICAgICAgY3VyX2Rydi0+c2VjdCA9PSBmZGN0cmwtPmVvdCkgewogICAgICAgIGN1cl9kcnYtPnNlY3QgPSAxOwogICAgICAgIGlmIChGRF9NVUxUSV9UUkFDSyhmZGN0cmwtPmRhdGFfc3RhdGUpKSB7CiAgICAgICAgICAgIGlmIChjdXJfZHJ2LT5oZWFkID09IDAgJiYKICAgICAgICAgICAgICAgIChjdXJfZHJ2LT5mbGFncyAmIEZESVNLX0RCTF9TSURFUykgIT0gMCkgewogICAgICAgICAgICAgICAgY3VyX2Rydi0+aGVhZCA9IDE7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBjdXJfZHJ2LT5oZWFkID0gMDsKICAgICAgICAgICAgICAgIGN1cl9kcnYtPnRyYWNrKys7CiAgICAgICAgICAgICAgICBpZiAoKGN1cl9kcnYtPmZsYWdzICYgRkRJU0tfREJMX1NJREVTKSA9PSAwKQogICAgICAgICAgICAgICAgICAgIHJldHVybiAwOwogICAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY3VyX2Rydi0+dHJhY2srKzsKICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQogICAgICAgIEZMT1BQWV9EUFJJTlRGKCJzZWVrIHRvIG5leHQgdHJhY2sgKCVkICUwMnggJTAyeCA9PiAlZClcbiIsCiAgICAgICAgICAgICAgICAgICAgICAgY3VyX2Rydi0+aGVhZCwgY3VyX2Rydi0+dHJhY2ssCiAgICAgICAgICAgICAgICAgICAgICAgY3VyX2Rydi0+c2VjdCwgZmRfc2VjdG9yKGN1cl9kcnYpKTsKICAgIH0gZWxzZSB7CiAgICAgICAgY3VyX2Rydi0+c2VjdCsrOwogICAgfQogICAgcmV0dXJuIDE7Cn0KCi8qIENhbGxiYWNrIGZvciB0cmFuc2ZlciBlbmQgKHN0b3Agb3IgYWJvcnQpICovCnN0YXRpYyB2b2lkIGZkY3RybF9zdG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ZG1hX21vZGUsIGRpcmVjdGlvbiwKICAgICAgICAgICAgICAgICAgICAgICAoMTI4IDw8IGZkY3RybC0+Zmlmb1s1XSkgKgogICAgICAgICAgICAgICAgICAgICAgIChjdXJfZHJ2LT5sYXN0X3NlY3QgLSBrcyArIDEpLCBmZGN0cmwtPmRhdGFfbGVuKTsKICAgICAgICBpZiAoKChkaXJlY3Rpb24gPT0gRkRfRElSX1NDQU5FIHx8IGRpcmVjdGlvbiA9PSBGRF9ESVJfU0NBTkwgfHwKICAgICAgICAgICAgICBkaXJlY3Rpb24gPT0gRkRfRElSX1NDQU5IKSAmJiBkbWFfbW9kZSA9PSAwKSB8fAogICAgICAgICAgICAoZGlyZWN0aW9uID09IEZEX0RJUl9XUklURSAmJiBkbWFfbW9kZSA9PSAyKSB8fAogICAgICAgICAgICAoZGlyZWN0aW9uID09IEZEX0RJUl9SRUFEICYmIGRtYV9tb2RlID09IDEpKSB7CiAgICAgICAgICAgIC8qIE5vIGFjY2VzcyBpcyBhbGxvd2VkIHVudGlsIERNQSB0cmFuc2ZlciBoYXMgY29tcGxldGVkICovCiAgICAgICAgICAgIGZkY3RybC0+bXNyICY9IH5GRF9NU1JfUlFNOwogICAgICAgICAgICAvKiBOb3csIHdlIGp1c3QgaGF2ZSB0byB3YWl0IGZvciB0aGUgRE1BIGNvbnRyb2xsZXIgdG8KICAgICAgICAgICAgICogcmVjYWxsIHVzLi4uCiAgICAgICAgICAgICAqLwogICAgICAgICAgICBETUFfaG9sZF9EUkVRKGZkY3RybC0+ZG1hX2NoYW5uKTsKICAgICAgICAgICAgRE1BX3NjaGVkdWxlKGZkY3RybC0+ZG1hX2NoYW5uKTsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIEZMT1BQWV9FUlJPUigiZG1hX21vZGU9JWQgZGlyZWN0aW9uPSVkXG4iLCBkbWFfbW9kZSwgZGlyZWN0aW9uKTsKICAgICAgICB9CiAgICB9CiAgICBGTE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5OiBlcnJvciBnZXR0aW5nIHNlY3RvciAlZFxuIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZkX3NlY3RvcihjdXJfZHJ2KSk7CiAgICAgICAgICAgICAgICAvKiBTdXJlLCBpbWFnZSBzaXplIGlzIHRvbyBzbWFsbC4uLiAqLwogICAgICAgICAgICAgICAgbWVtc2V0KGZkY3RybC0+ZmlmbywgMCwgRkRfU0VDVE9SX0xFTik7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgc3dpdGNoIChmZGN0cmwtPmRhdGFfZGlyKSB7CiAgICAgICAgY2FzZSBGRF9ESVJfUkVBRDoKICAgICAgICAgICAgLyogUkVBRCBjb21tYW5kcyAqLwogICAgICAgICAgICBETUFfd3JpdGVfbWVtb3J5IChuY2hhbiwgZmRjdHJsLT5maWZvICsgcmVsX3BvcywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmRjdHJsLT5kYXRhX3BvcywgbGVuKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSBGRF9ESVJfV1JJVEU6CiAgICAgICAgICAgIC8qIFdSSVRFIGNvbW1hbmRzICovCiAgICAgICAgICAgIERNQV9yZWFkX21lbW9yeSAobmNoYW4sIGZkY3RybC0+ZmlmbyArIHJlbF9wb3MsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmRjdHJsLT5kYXRhX3BvcywgbGVuKTsKICAgICAgICAgICAgaWYgKGJkcnZfd3JpdGUoY3VyX2Rydi0+YnMsIGZkX3NlY3RvcihjdXJfZHJ2KSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgZmRjdHJsLT5maWZvLCAxKSA8IDApIHsKICAgICAgICAgICAgICAgIEZMT1BQWV9FUlJPUigid3JpdGluZyBzZWN0b3IgJWRcbiIsIGZkX3NlY3RvcihjdXJfZHJ2KSk7CiAgICAgICAgICAgICAgICBmZGN0cmxfc3RvcF90cmFuc2ZlcihmZGN0cmwsIEZEX1NSMF9BQk5URVJNIHwgRkRfU1IwX1NFRUssIDB4MDAsIDB4MDApOwogICAgICAgICAgICAgICAgZ290byB0cmFuc2Zlcl9lcnJvcjsKICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAvKiBTQ0FOIGNvbW1hbmRzICovCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHVpbnQ4X3QgdG1wYnVmW0ZEX1NFQ1RPUl9MRU5dOwogICAgICAgICAgICAgICAgaW50IHJldDsKICAgICAgICAgICAgICAgIERNQV9yZWFkX21lbW9yeSAobmNoYW4sIHRtcGJ1ZiwgZmRjdHJsLT5kYXRhX3BvcywgbGVuKTsKICAgICAgICAgICAgICAgIHJldCA9IG1lbWNtcCh0bXBidWYsIGZkY3RybC0+ZmlmbyArIHJlbF9wb3MsIGxlbik7CiAgICAgICAgICAgICAgICBpZiAocmV0ID09IDApIHsKICAgICAgICAgICAgICAgICAgICBzdGF0dXMyID0gRkRfU1IyX1NFSDsKICAgICAgICAgICAgICAgICAgICBnb3RvIGVuZF90cmFuc2ZlcjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICgocmV0IDwgMCAmJiBmZGN0cmwtPmRhdGFfZGlyID09IEZEX0RJUl9TQ0FOTCkgfHwKICAgICAgICAgICAgICAgICAgICAocmV0ID4gMCAmJiBmZGN0cmwtPmRhdGFfZGlyID09IEZEX0RJUl9TQ0FOSCkpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0dXMyID0gMHgwMDsKICAgICAgICAgICAgICAgICAgICBnb3RvIGVuZF90cmFuc2ZlcjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgZmRjdHJsLT5kYXRhX3BvcyArPSBsZW47CiAgICAgICAgcmVsX3BvcyA9IGZkY3RybC0+ZGF0YV9wb3MgJSBGRF9TRUNUT1JfTEVOOwogICAgICAgIGlmIChy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J2KGZkY3RybCk7CiAgICBmZGN0cmwtPmRzciAmPSB+RkRfRFNSX1BXUkRPV047CiAgICBpZiAoIShmZGN0cmwtPm1zciAmIEZEX01TUl9SUU0pIHx8ICEoZmRjdHJsLT5tc3IgJiBGRF9NU1JfRElPKSkgewogICAgICAgIEZMT1BQWV9FUlJPUigiY29udHJvbGxlciBub3QgcmVhZHkgZm9yIHJlYWRpbmdcbiIpOwogICAgICAgIHJldHVybiAwOwogICAgfQogICAgcG9zID0gZmRjdHJsLT5kYXRhX3BvczsKICAgIGlmIChmZGN0cmwtPm1zciAmIEZEX01TUl9OT05ETUEpIHsKICAgICAgICBwb3MgJT0gRkRfU0VDVE9SX0xFTjsKICAgICAgICBpZiAocG9zID09IDApIHsKICAgICAgICAgICAgaWYgKGZkY3RybC0+ZGF0YV9wb3MgIT0gMCkKICAgICAgICAgICAgICAgIGlmICghZmRjdHJsX3NlZWtfdG9fbmV4dF9zZWN0KGZkY3RybCwgY3VyX2RydikpIHsKICAgICAgICAgICAgICAgICAgICBGTE9QUFlfRFBSSU5URigiZXJyb3Igc2Vla2luZyB0byBuZXh0IHNlY3RvciAlZFxuIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmZF9zZWN0b3IoY3VyX2RydikpOwogICAgICAgICAgICAgICAgICAgIHJldHVybiAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoYmRydl9yZWFkKGN1cl9kcnYtPmJzLCBmZF9zZWN0b3IoY3VyX2RydiksIGZkY3RybC0+ZmlmbywgMSkgPCAwKSB7CiAgICAgICAgICAgICAgICBGTE9QUFlfRFBSSU5URigiZXJyb3IgZ2V0dGluZyBzZWN0b3IgJWRcbiIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmZF9zZWN0b3IoY3VyX2RydikpOwogICAgICAgICAgICAgICAgLyogU3VyZSwgaW1hZ2Ugc2l6ZSBpcyB0b28gc21hbGwuLi4gKi8KICAgICAgICAgICAgICAgIG1l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1cywgYnVzZGV2LnFkZXYsIGRldik7CiAgICBmZGN0cmwgPSAmc3lzLT5zdGF0ZTsKICAgIHN5c2J1c19jb25uZWN0X2lycSgmc3lzLT5idXNkZXYsIDAsIGlycSk7CiAgICBzeXNidXNfbW1pb19tYXAoJnN5cy0+YnVzZGV2LCAwLCBpb19iYXNlKTsKICAgICpmZGNfdGMgPSBxZGV2X2dldF9ncGlvX2luKGRldiwgMCk7CgogICAgcmV0dXJuIGZkY3RybDsKfQoKc3RhdGljIGludCBmZGN0cmxfaW5pdF9jb21tb24oRkRDdHJsICpmZGN0cmwsIHRhcmdldF9waHlzX2FkZHJfdCBpb19iYXNlKQp7CiAgICBpbnQgaSwgajsKICAgIHN0YXRpYyBpbnQgY29tbWFuZF90YWJsZXNfaW5pdGVkID0gMDsKCiAgICAvKiBGaWxsICdjb21tYW5kX3RvX2hhbmRsZXInIGxvb2t1cCB0YWJsZSAqLwogICAgaWYgKCFjb21tYW5kX3RhYmxlc19pbml0ZWQpIHsKICAgICAgICBjb21tYW5kX3RhYmxlc19pbml0ZWQgPSAxOwogICAgICAgIGZvciAoaSA9IEFSUkFZX1NJWkUoaGFuZGxlcnMpIC0gMTsgaSA+PSAwOyBpLS0pIHsKICAgICAgICAgICAgZm9yIChqID0gMDsgaiA8IHNpemVvZihjb21tYW5kX3RvX2hhbmRsZXIpOyBqKyspIHsKICAgICAgICAgICAgICAgIGlmICgoaiAmIGhhbmRsZXJzW2ldLm1hc2spID09IGhhbmRsZXJzW2ldLnZhbHVlKSB7CiAgICAgICAgICAgICAgICAgICAgY29tbWFuZF90b19oYW5kbGVyW2pdID0gaTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICBGTE9QUFlfRFBSSU5URigiaW5pdCBjb250cm9sbGVyXG4iKTsKICAgIGZkY3RybC0+ZmlmbyA9IHFlbXVfbWVtYWxpZ24oNTEyLCBGRF9TRUNUT1JfTEVOKTsKICAgIGZkY3RybC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