LyogZW50ZXJub3dfcGNpLmMsdiAwLjk5IDIwMDEvMTAvMDIKICoKICogZW50ZXJub3dfcGNpLmMgICAgICAgQ2FyZC1zcGVjaWZpYyByb3V0aW5lcyBmb3IKICogICAgICAgICAgICAgICAgICAgICAgRm9ybXVsYS1uIGVudGVyOm5vdyBJU0ROIFBDSSBhYgogKiAgICAgICAgICAgICAgICAgICAgICBHZXJkZXMgQUcgUG93ZXIgSVNETiBQQ0kKICogICAgICAgICAgICAgICAgICAgICAgV29lcmx0cm9uaWMgU0EgMTYgUENJCiAqICAgICAgICAgICAgICAgICAgICAgIChiYXNlZCBvbiBIaVNheCBkcml2ZXIgYnkgS2Fyc3RlbiBLZWlsKQogKgogKiBBdXRob3IgICAgICAgICAgICAgICBDaHJpc3RvcGggRXJzZmVsZCA8aW5mb0Bmb3JtdWxhLW4uZGU+CiAqICAgICAgICAgICAgICAgICAgICAgIEZvcm11bGEtbiBFdXJvcGUgQUcgKHd3dy5mb3JtdWxhLW4uY29tKQogKiAgICAgICAgICAgICAgICAgICAgICBwcmV2aW91c2x5IEdlcmRlcyBBRwogKgogKgogKiAgICAgICAgICAgICAgICAgICAgICBUaGlzIGZpbGUgaXMgKGMpIHVuZGVyIEdOVSBQVUJMSUMgTElDRU5TRQogKgogKiBOb3RlczoKICogVGhpcyBkcml2ZXIgaW50ZXJmYWNlcyB0byBuZXRqZXQuYyB3aGljaCBwZXJmb3JtcyBCLWNoYW5uZWwKICogcHJvY2Vzc2luZy4KICoKICogVmVyc2lvbiAwLjk5IGlzIHRoZSBmaXJzdCByZWxlYXNlIG9mIHRoaXMgZHJpdmVyIGFuZCB0aGVyZSBhcmUKICogY2VydGFpbmx5IGEgZmV3IGJ1Z3MuCiAqIEl0IGlzbid0IHRlc3RldCBvbiBsaW51eCAyLjQgeWV0LCBzbyBjb25zaWRlciB0aGlzIGNvZGUgdG8gYmUKICogYmV0YS4KICoKICogUGxlYXNlIGRvbid0IHJlcG9ydCBtZSBhbnkgbWFsZnV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mY3MtPmxvY2ssIGZsYWdzKTsKCQkJcmVzZXRfZW5wY2koY3MpOwogICAgICAgICAgICAgICAgICAgICAgICBBbWQ3OTMwX2luaXQoY3MpOwogICAgICAgICAgICAgICAgICAgICAgICBzcGluX3VubG9ja19pcnFyZXN0b3JlKCZjcy0+bG9jaywgZmxhZ3MpOwoJCQlicmVhazsKCQljYXNlIENBUkRfUkVMRUFTRToKCQkJcmVsZWFzZV9pb19uZXRqZXQoY3MpOwoJCQlicmVhazsKCQljYXNlIENBUkRfSU5JVDoKCQkJcmVzZXRfZW5wY2koY3MpOwoJCQlpbml0dGlnZXIoY3MpOwoJCQkvKiBpcnEgbXVzdCBiZSBvbiBoZXJlICovCgkJCUFtZDc5MzBfaW5pdChjcyk7CgkJCWJyZWFrOwoJCWNhc2UgQ0FSRF9URVNUOgoJCQlicmVhazsKICAgICAgICAgICAgICAgIGNhc2UgTURMX0FTU0lHTjoKICAgICAgICAgICAgICAgICAgICAgICAgLyogVEVJIGFzc2lnbmVkLCBMRUQxIG9uICovCiAgICAgICAgICAgICAgICAgICAgICAgIGNzLT5ody5uamV0LmF1eGQgPSBUSl9BTURfSVJRIDw8IDE7CiAgICAgICAgICAgICAgICAgICAgICAgIG91dGIoY3MtPmh3Lm5qZXQuYXV4ZCwgY3MtPmh3Lm5qZXQuYmFzZSArIE5FVEpFVF9BVVhEQVRBKTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlIE1ETF9SRU1PVkU6CiAgICAgICAgICAgICAgICAgICAgICAgIC8qIFRFSSByZW1vdmVkLCBMRURzIG9mZiAqLwoJICAgICAgICAgICAgICAgIGNzLT5ody5uamV0LmF1eGQgPSAwOwogICAgICAgICAgICAgICAgICAgICAgICBvdXRiKDB4MDAsIGNzLT5ody5uamV0LmJhc2UgKyBORVRKRVRfQVVYREFUQSk7CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgY2FzZSBNRExfQkNfQVNTSUdOOgogICAgICAgICAgICAgICAgICAgICAgICAvKiBhY3RpdmF0ZSBCLWNoYW5uZWwgKi8KICAgICAgICAgICAgICAgICAgICAgICAgY2hhbiA9ICh1bnNpZ25lZCBjaGFyICopYXJnOwoKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGNzLT5kZWJ1ZyAmIEwxX0RFQl9JU0FDKQoJCSAgICAgICAgICAgICAgICBkZWJ1Z2wxKGNzLCAiZW50ZXI6bm93IFBDSTogYXNzaWduIHBoeXMuIEJDICVkIGluIEFNRCBMTVIxIiwgKmNoYW4pOwoKICAgICAgICAgICAgICAgICAgICAgICAgY3MtPmRjLmFtZDc5MzAucGhfY29tbWFuZChjcywgKGNzLT5kYy5hbWQ3OTMwLmxtcjEgfCAoKmNoYW4gKyAxKSksICJNRExfQkNfQVNTSUdOIik7CiAgICAgICAgICAgICAgICAgICAgICAgIC8qIGF0IGxlYXN0IG9uZSBiLWNoYW5uZWwgaW4gdXNlLCBMRUQgMiBvbiAqLwogICAgICAgICAgICAgICAgICAgICAgICBjcy0+aHcubmpldC5hdXhkIHw9IFRKX0FNRF9JUlEgPDwgMjsKICAgICAgICAgICAgICAgICAgICAgICAgb3V0Yihjcy0+aHcubmpldC5hdXhkLCBjcy0+aHcubmpldC5iYXNlICsgTkVUSkVUX0FVWERBVEEpOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGNhc2UgTURMX0JDX1JFTEVBU0U6CiAgICAgICAgICAgICAgICAgICAgICAgIC8qIGRlYWN0aXZhdGUgQi1jaGFubmVsICovCiAgICAgICAgICAgICAgICAgICAgICAgIGNoYW4gPSAodW5zaWduZWQgY2hhciAqKWFyZzsKCiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjcy0+ZGVidWcgJiBMMV9ERUJfSVNBQykKCQkgICAgICAgICAgICAgICAgZGVidWdsMShjcywgImVudGVyOm5vdyBQQ0k6IHJlbGVhc2UgcGh5cy4gQkMgJWQgaW4gQW1kIExNUjEiLCAqY2hhbik7CgogICAgICAgICAgICAgICAgICAgICAgICBjcy0+ZGMuYW1kNzkzMC5waF9jb21tYW5kKGNzLCAoY3MtPmRjLmFtZDc5MzAubG1yMSAmIH4oKmNoYW4gKyAxKSksICJNRExfQkNfUkVMRUFTRSIpOwogICAgICAgICAgICAgICAgICAgICAgICAvKiBubyBiLWNoYW5uZWwgYWN0aXZlIC0+IExFRDIgb2ZmICovCiAgICAgICAgICAgICAgICAgICAgICAgIGlmICghKGNzLT5kYy5hbWQ3OTMwLmxtcjEgJiAzKSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNzLT5ody5uamV0LmF1eGQgJj0gfihUSl9BTURfSVJRIDw8IDIpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dGIoY3MtPmh3Lm5qZXQuYXV4ZCwgY3MtPmh3Lm5qZXQuYmFzZSArIE5FVEpFVF9BVVhEQVRBKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwoKCX0KCXJldHVybigwKTsKfQoKc3RhdGljIGlycXJldHVybl90CmVucGNpX2ludGVycnVwdChpbnQgaW50bm8sIHZvaWQgKmRldl9pZCwgc3RydWN0IHB0X3JlZ3MgKnJlZ3MpCnsKCXN0cnVjdCBJc2RuQ2FyZFN0YXRlICpjcyA9IGRldl9pZDsKCXVuc2lnbmVkIGNoYXIgczB2YWwsIHMxdmFsLCBpcjsKCXVfbG9uZyBmbGFnczsKCglzcGluX2xvY2tfaXJxc2F2ZSgmY3MtPmxvY2ssIGZsYWdzKTsKCXMxdmFsID0gaW5iKGNzLT5ody5uamV0LmJhc2UgKyBORVRKRVRfSVJRU1RBVDEpOwoKICAgICAgICAvKiBBTUQgdGhyZXcgYW4gaW50ZXJydXB0ICovCglpZiAoIShzM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