LyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF8gICBfIF9fX18gIF8gICAgIAogKiAgUHJvamVjdCAgICAgICAgICAgICAgICAgICAgIF9fX3wgfCB8IHwgIF8gXHwgfCAgICAKICogICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8gX198IHwgfCB8IHxfKSB8IHwgICAgCiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgIHwgKF9ffCB8X3wgfCAgXyA8fCB8X19fIAogKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXF9fX3xcX19fL3xffCBcX1xfX19fX3wKICoKICogQ29weXJpZ2h0IChDKSAxOTk4IC0gMjAwMiwgRGFuaWVsIFN0ZW5iZXJnLCA8ZGFuaWVsQGhheHguc2U+LCBldCBhbC4KICoKICogSW4gb3JkZXIgdG8gYmUgdXNlZnVsIGZvciBldmVyeSBwb3RlbnRpYWwgdXNlciwgY3VybCBhbmQgbGliY3VybCBhcmUKICogZHVhbC1saWNlbnNlZCB1bmRlciB0aGUgTVBMIGFuZCB0aGUgTUlUL1gtZGVyaXZhdGUgbGljZW5zZXMuCiAqCiAqIFlvdSBtYXkgb3B0IHRvIHVzZSwgY29weSwgbW9kaWZ5LCBtZXJnZSwgcHVibGlzaCwgZGlzdHJpYnV0ZSBhbmQvb3Igc2VsbAogKiBjb3BpZXMgb2YgdGhlIFNvZnR3YXJlLCBhbmQgcGVybWl0IHBlcnNvbnMgdG8gd2hvbSB0aGUgU29mdHdhcmUgaXMKICogZnVybmlzaGVkIHRvIGRvIHNvLCB1bmRlciB0aGUgdGVybXMgb2YgdGhlIE1QTCBvciB0aGUgTUlUL1gtZGVyaXZhdGUKICogbGljZW5zZXMuIFlvdSBtYXkgcGljayBvbmUgb2YgdGhlc2UgbGljZW5zZXMuCiAqCiAqIFRoaXMgc29mdHdhcmUgaXMgZGlzdHJpYnV0ZWQgb24gYW4gIkFTIElTIiBiYXNpcywgV0lUSE9VVCBXQVJSQU5UWSBPRiBBTlkKICogS0lORCwgZWl0aGVyIGV4cHJlc3Mgb3IgaW1wbGllZC4KICoKICogJElkJAogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCgovKioqCgoKUkVDRUlWSU5HIENPT0tJRSBJTkZPUk1BVElPTgo9PT09PT09PT09PT09PT09PT09PT09PT09PT09CgpzdHJ1Y3QgQ29va2llSW5mbyAqY29va2llX2luaXQoY2hhciAqZmlsZSk7CgkKCUluaXRzIGEgY29va2llIHN0cnVjdCB0byBzdG9yZSBkYXRhIGluIGEgbG9jYWwgZmlsZS4gVGhpcyBpcyBhbHdheXMKCWNhbGxlZCBiZWZvcmUgYW55IGNvb2tpZXMgYXJlIHNldC4KCmludCBjb29raWVzX3NldChzdHJ1Y3QgQ29va2llSW5mbyAqY29va2llLCBjaGFyICpjb29raWVfbGluZSk7CgoJVGhlICdjb29raWVfbGluZScgcGFyYW1ldGVyIGlzIGEgZnVsbCAiU2V0LWNvb2tpZToiIGxpbmUgYXMKCXJlY2VpdmVkIGZyb20gYSBzZXJ2ZXIuCgoJVGhlIGZ1bmN0aW9uIG5lZWQgdG8gcmVwbGFjZSBwcmV2aW91c2x5IHN0b3JlZCBsaW5lcyB0aGF0IHRoaXMgbmV3CglsaW5lIHN1cGVyY2VlZHMuCgoJSXQgbWF5IHJlbW92ZSBsaW5lcyB0aGF0IGFyZSBleHBpcmVkLgoKCUl0IHNob3VsZCByZXR1cm4gYW4gaW5kaWNhdGlvbiBvZiBzdWNjZXNzL2Vycm9yLgoKClNFTkRJTkcgQ09PS0lFIElORk9STUFUSU9OCj09PT09PT09PT09PT09PT09PT09PT09PT09CgpzdHJ1Y3QgQ29va2llcyAqY29va2llX2dldGxpc3Qoc3RydWN0IENvb2tpZUluZm8gKmNvb2tpZ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bi0tOwogICAgICAgICAgfQoKICAgICAgICAgIC8qIFNraXAgbGVhZGluZyB3aGl0ZXNwYWNlIGZyb20gdGhlICd3aGF0JyAqLwogICAgICAgICAgd2hhdHB0cj13aGF0OwogICAgICAgICAgd2hpbGUoaXNzcGFjZSgoaW50KSp3aGF0cHRyKSkgewogICAgICAgICAgICB3aGF0cHRyKys7CiAgICAgICAgICB9CgogICAgICAgICAgaWYoc3RyZXF1YWwoInBhdGgiLCBuYW1lKSkgewogICAgICAgICAgICBjby0+cGF0aD1zdHJkdXAod2hhdHB0cik7CiAgICAgICAgICB9CiAgICAgICAgICBlbHNlIGlmKHN0cmVxdWFsKCJkb21haW4iLCBuYW1lKSkgewogICAgICAgICAgICBjby0+ZG9tYWluPXN0cmR1cCh3aGF0cHRyKTsKICAgICAgICAgICAgY28tPmZpZWxkMT0gKHdoYXRwdHJbMF09PScuJyk/MjoxOwogICAgICAgICAgfQogICAgICAgICAgZWxzZSBpZihzdHJlcXVhbCgidmVyc2lvbiIsIG5hbWUpKSB7CiAgICAgICAgICAgIGNvLT52ZXJzaW9uPXN0cmR1cCh3aGF0cHRyKTsKICAgICAgICAgIH0KICAgICAgICAgIGVsc2UgaWYoc3RyZXF1YWwoIm1heC1hZ2UiLCBuYW1lKSkgewogICAgICAgICAgICAvKiBEZWZpbmVkIGluIFJGQzIxMDk6CgogICAgICAgICAgICAgICBPcHRpb25hbC4gIFRoZSBNYXgtQWdlIGF0dHJpYnV0ZSBkZWZpbmVzIHRoZSBsaWZldGltZSBvZiB0aGUKICAgICAgICAgICAgICAgY29va2llLCBpbiBzZWNvbmRzLiAgVGhlIGRlbHRhLXNlY29uZHMgdmFsdWUgaXMgYSBkZWNpbWFsIG5vbi0KICAgICAgICAgICAgICAgbmVnYXRpdmUgaW50ZWdlci4gIEFmdGVyIGRlbHRhLXNlY29uZHMgc2Vjb25kcyBlbGFwc2UsIHRoZQogICAgICAgICAgICAgICBjbGllbnQgc2hvdWxkIGRpc2NhcmQgdGhlIGNvb2tpZS4gIEEgdmFsdWUgb2YgemVybyBtZWFucyB0aGUKICAgICAgICAgICAgICAgY29va2llIHNob3VsZCBiZSBkaXNjYXJkZWQgaW1tZWRpYXRlbHkuCgogICAgICAgICAgICAgKi8KICAgICAgICAgICAgY28tPm1heGFnZSA9IHN0cmR1cCh3aGF0cHRyKTsKICAgICAgICAgICAgY28tPmV4cGlyZXMgPQogICAgICAgICAgICAgIGF0b2koKCpjby0+bWF4YWdlPT0nXCInKT8mY28tPm1heGFnZVsxXTomY28tPm1heGFnZVswXSkgKyBub3c7CiAgICAgICAgICB9CiAgICAgICAgICBlbHNlIGlmKHN0cmVxdWFsKCJleHBpcmVzIiwgbmFtZSkpIHsKICAgICAgICAgICAgY28tPmV4cGlyZXN0cj1zdHJkdXAod2hhdHB0cik7CiAgICAgICAgICAgIGNvLT5leHBpcmVzID0gY3VybF9nZXRkYXRlKHdoYXQsICZub3cpOwogICAgICAgICAgfQogICAgICAgICAgZWxzZSBpZighY28tPm5hbWUpIHsKICAgICAgICAgICAgY28tPm5hbWUgPSBzdHJkdXAobmFtZSk7CiAgICAgICAgICAgIGNvLT52YWx1ZSA9IHN0cmR1cCh3aGF0cHRyKTsKICAgICAgICAgIH0KICAgICAgICAgIC8qCiAgICAgICAgICAgIGVsc2UgdGhpcyBpcyB0aGUgc2Vjb25kIChvciBtb3JlKSBuYW1lIHdlIGRvbid0IGtub3cKICAgICAgICAgICAgYWJvdXQhICovCiAgICAgICAgfQogICAgICAgIGVsc2UgewogICAgICAgICAgLyogdGhpcyBpcyBhbiAiaWxsZWdhbCIgPHdoYXQ+PTx0aGlzPiBwYWlyICovCiAgICAgICAgfQogICAgICB9CiAgICAgIGVsc2UgewogICAgICAgIGlmKHNzY2FuZihwdHIsICIlIiBNQVhfQ09PS0lFX0xJTkVfVFhUICJbXjtcclxuXSIsCiAgICAgICAgICAgICAgICAgIHdoYXQpKSB7CiAgICAgICAgICBpZihzdHJlcXVhbCgic2VjdXJlIiwgd2hhdCkpCiAgICAgICAgICAgIGNvLT5zZWN1cmUgPSBUUlVFOwogICAgICAgICAgLyogZWxzZSwKICAgICAgICAgICAgIHVuc3VwcG9ydGVkIGtleXdvcmQgd2l0aG91dCBhc3NpZ24hICovCgogICAgICAgIH0KICAgICAgfQogICAgICBpZighc2VtaXB0ciB8fCAhKnNlbWlwdHIpIHsKICAgICAgICAvKiB3ZSBhbHJlYWR5IGtub3cgdGhlcmUgYXJlIG5vIG1vcmUgY29va2llcyAqLwogICAgICAgIHNlbWlwdHIgPSBOVUxMOwogICAgICAgIGNvbnRpbnVlOwogICAgICB9CgogICAgICBwdHI9c2VtaXB0cisxOwogICAgICB3aGlsZShwdHIgJiYgKnB0ciAmJiBpc3NwYWNlKChpbnQpKnB0cikpCiAgICAgICAgcHRyKys7CiAgICAgIHNlbWlwdHI9c3RyY2hyKHB0ciwgJzsnKTsgLyogbm93LCBmaW5kIHRoZSBuZXh0IHNlbWljb2xvbiAqLwoKICAgICAgaWYoIXNlbWlwdHIgJiYgKnB0cikKICAgICAgICAvKiBUaGVyZSBhcmUgbm8gbW9yZSBzZW1pY29sb25zLCBidXQgdGhlcmUncyBhIGZpbmFsIG5hbWU9dmFsdWUgcGFpcgogICAgICAgICAgIGNvbWluZyB1cCAqLwogICAgICAgIHNlbWlwdHI9c3RyY2hyKHB0ciwgJ1wwJyk7CiAgICB9IHdoaWxlKHNlbWlwdHIpOwoKICAgIGlmKE5VTEwgPT0gY28tPm5hbWUpIHsKICAgICAgLyogd2UgZGlkbid0IGdldCBhIGNvb2tpZSBuYW1lLCB0aGlzIGlzIGFuIGlsbGVnYWwgbGluZSwgYmFpbCBvdXQgKi8KICAgICAgaWYoY28tPmRvbWFpbikKICAgICAgICBmcmVlKGNvLT5kb21haW4pOwogICAgICBpZihjby0+cGF0aCkKICAgICAgICBmcmVlKGNvLT5wYXRoKTsKICAgICAgaWYoY28tPm5hbWUpCiAgICAgICAgZnJlZShjby0+bmFtZSk7CiAgICAgIGlmKGNv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AgIC5kb21haW4uY29tIGFuZCB0byBmYWxzZSB3aGVuIHRoZSBkb21haW4gaXMgY29tcGxldGUgd3d3LmRvbWFpbi5jb20KCiAgICAgICAgICAgV2UgZG9uJ3QgY3VycmVudGx5IHRha2UgYWR2YW50YWdlIG9mIHRoaXMga25vd2xlZGdlLgogICAgICAgICovCiAgICAgICAgY28tPmZpZWxkMT1zdHJlcXVhbChwdHIsICJUUlVFIikrMTsgLyogc3RvcmUgaW5mb3JtYXRpb24gKi8KICAgICAgICBicmVhazsKICAgICAgY2FzZSAyOgogICAgICAgIC8qIEl0IHR1cm5zIG91dCwgdGhhdCBzb21ldGltZXMgdGhlIGZpbGUgZm9ybWF0IGFsbG93cyB0aGUgcGF0aAogICAgICAgICAgIGZpZWxkIHRvIHJlbWFpbiBub3QgZmlsbGVkIGluLCB3ZSB0cnkgdG8gZGV0ZWN0IHRoaXMgYW5kIHdvcmsKICAgICAgICAgICBhcm91bmQgaXQhIEFuZHLpcyBHYXJj7WEgbWFkZSB1cyBhd2FyZSBvZiB0aGlzLi4uICovCiAgICAgICAgaWYgKHN0cmNtcCgiVFJVRSIsIHB0cikgJiYgc3RyY21wKCJGQUxTRSIsIHB0cikpIHsKICAgICAgICAgIC8qIG9ubHkgaWYgdGhlIHBhdGggZG9lc24ndCBsb29rIGxpa2UgYSBib29sZWFuIG9wdGlvbiEgKi8KICAgICAgICAgIGNvLT5wYXRoID0gc3RyZHVwKHB0cik7CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgLyogdGhpcyBkb2Vzbid0IGxvb2sgbGlrZSBhIHBhdGgsIG1ha2Ugb25lIHVwISAqLwogICAgICAgIGNvLT5wYXRoID0gc3RyZHVwKCIvIik7CiAgICAgICAgZmllbGRzKys7IC8qIGFkZCBhIGZpZWxkIGFuZCBmYWxsIGRvd24gdG8gc2VjdXJlICovCiAgICAgICAgLyogRkFMTFRIUk9VR0ggKi8KICAgICAgY2FzZSAzOgogICAgICAgIGNvLT5zZWN1cmUgPSBzdHJlcXVhbChwdHIsICJUUlVFIik7CiAgICAgICAgYnJlYWs7CiAgICAgIGNhc2UgNDoKICAgICAgICBjby0+ZXhwaXJlcyA9IGF0b2kocHRyKTsKICAgICAgICBicmVhazsKICAgICAgY2FzZSA1OgogICAgICAgIGNvLT5uYW1lID0gc3RyZHVwKHB0cik7CiAgICAgICAgYnJlYWs7CiAgICAgIGNhc2UgNjoKICAgICAgICBjby0+dmFsdWUgPSBzdHJkdXAocHRyKTsKICAgICAgICBicmVhazsKICAgICAgfQogICAgfQoKICAgIGlmKDcgIT0gZmllbGRzKSB7CiAgICAgIC8qIHdlIGRpZCBub3QgZmluZCB0aGUgc3VmZmljaWVudCBudW1iZXIgb2YgZmllbGRzIHRvIHJlY29nbml6ZSB0aGlzCiAgICAgICAgIGFzIGEgdmFsaWQgbGluZSwgYWJvcnQgYW5kIGdvIGhvbWUgKi8KCiAgICAgIGlmKGNvLT5kb21haW4pCiAgICAgICAgZnJlZShjby0+ZG9tYWluKTsKICAgICAgaWYoY28tPnBhdGgpCiAgICAgICAgZnJlZShjby0+cGF0aCk7CiAgICAgIGlmKGNvLT5uYW1lKQogICAgICAgIGZyZWUoY28tPm5hbWUpOwogICAgICBpZihjby0+dmFsdWUpCiAgICAgICAgZnJlZShjby0+dmFsdWUpOwoKICAgICAgZnJlZShjbyk7CiAgICAgIHJldHVybiBOVUxMOwogICAgfQoKICB9CgogIGNvLT5saXZlY29va2llID0gYy0+cnVubmluZzsKCiAgLyogbm93LCB3ZSBoYXZlIHBhcnNlZCB0aGUgaW5jb21pbmcgbGluZSwgd2UgbXVzdCBub3cgY2hlY2sgaWYgdGhpcwogICAgIHN1cGVyY2VlZHMgYW4gYWxyZWFkeSBleGlzdGluZyBjb29raWUsIHdoaWNoIGl0IG1heSBpZiB0aGUgcHJldmlvdXMgaGF2ZQogICAgIHRoZSBzYW1lIGRvbWFpbiBhbmQgcGF0aCBhcyB0aGlzICovCgogIGNsaXN0ID0gYy0+Y29va2llczsKICByZXBsYWNlX29sZCA9IEZBTFNFOwogIHdoaWxlKGNsaXN0KSB7CiAgICBpZihzdHJlcXVhbChjbGlzdC0+bmFtZSwgY28tPm5hbWUpKSB7CiAgICAgIC8qIHRoZSBuYW1lcyBhcmUgaWRlbnRpY2FsICovCgogICAgICBpZihjbGlzdC0+ZG9tYWluICYmIGNvLT5kb21haW4pIHsKICAgICAgICBpZihzdHJlcXVhbChjbGlzdC0+ZG9tYWluLCBjby0+ZG9tYWluKSB8fAogICAgICAgICAgIChjbGlzdC0+ZG9tYWluWzBdPT0nLicgJiYKICAgICAgICAgICAgc3RyZXF1YWwoJihjbGlzdC0+ZG9tYWluWzFdKSwgY28tPmRvbWFpbikpIHx8CiAgICAgICAgICAgKGNvLT5kb21haW5bMF09PScuJyAmJgogICAgICAgICAgICBzdHJlcXVhbChjbGlzdC0+ZG9tYWluLCAmKGNvLT5kb21haW5bMV0pKSkgKQogICAgICAgICAgLyogVGhlIGRvbWFpbnMgYXJlIGlkZW50aWNhbCwgb3IgYXQgbGVhc3QgaWRlbnRpY2FsIGlmIHlvdSBza2lwIHRoZQogICAgICAgICAgICAgcHJlY2VlZGluZyBkb3QgKi8KICAgICAgICAgIHJlcGxhY2Vfb2xkPVRSVUU7CiAgICAgIH0KICAgICAgZWxzZSBpZighY2xpc3QtPmRvbWFpbiAmJiAhY28tPmRvbWFpbikKICAgICAgICByZXBsYWNlX29sZCA9IFRSVUU7CgogICAgICBpZihyZXBsYWNlX29sZCkgewogICAgICAgIC8qIHRoZSBkb21haW5zIHdlcmUgaWRlbnRpY2FsICovCgogICAgICAgIGlmKGNsaXN0LT5wYXRoICYmIGNvLT5wYXRoKSB7CiAgICAgICAgICBpZihzdHJlcXVhbChjbGlzdC0+cGF0aCwgY28tPnBhdGgpKSB7CiAgICAgICAgICAgIHJlcGxhY2Vfb2xkID0gVFJVRTsKICAgICAgICAgIH0KICAgICAgICAgIGVsc2UKICAgICAgICAgICAgcmVwbGFjZV9vbGQgPSBGQUxTRTsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZighY2xpc3QtPnBhdGggJiYgIWNvLT5wYXRoKQogICAgICAgICAgcmVwbGFjZV9vbGQgPSBUUlVFOwogICAgICAgIGVsc2UKICAgICAgICAgIHJlcGxhY2Vfb2xkID0gRkFMU0U7CiAgICAgICAgCiAgICAgIH0KCiAgICAgIGlmKHJlcGxhY2Vfb2xkICYmICFjby0+bGl2ZWNvb2tpZSAmJiBjbGlzdC0+bGl2ZWNvb2tpZSkgewogICAgICAgIC8qIEJvdGggY29va2llcyBtYXRjaGVkIGZpbmUsIGV4Y2VwdCB0aGF0IHRoZSBhbHJlYWR5IHByZXNlbnQKICAgICAgICAgICBjb29raWUgaXMgImxpdmUiLCB3aGljaCBtZWFucyBpdCB3YXMgc2V0IGZyb20gYSBoZWFkZXIsIHdoaWxlCiAgICAgICAgICAgdGhlIG5ldyBvbmUgaXNuJ3QgImxpdmUiIGFuZCB0aHVzIG9ubHkgcmVhZCBmcm9tIGEgZmlsZS4gV2UgbGV0CiAgICAgICAgICAgbGl2ZSBjb29raWVzIHN0YXkgYWxpdmUgKi8KCiAgICAgICAgLyogRnJlZSB0aGUgbmV3Y29tZXIgYW5kIGdldCBvdXQgb2YgaGVyZSEgKi8KICAgICAgICBpZihjby0+ZG9tYWluKQogICAgICAgICAgZnJlZShjby0+ZG9tYWluKTsKICAgICAgICBpZihjby0+cGF0aCkKICAgICAgICAgIGZyZWUoY28tPnBhdGgpOwogICAgICAgIGlmKGNvLT5uYW1lKQogICAgICAgICAgZnJlZShjby0+bmFtZSk7CiAgICAgICAgaWYoY28tPnZhbHVlKQogICAgICAgICAgZnJlZShjby0+dmFsdWUpOwoKICAgICAgICBmcmVlKGNvKTsKICAgICAgICByZXR1cm4gTlVMTDsKICAgICAgfQoKICAgICAgaWYocmVwbGFjZV9vbGQpIHsKICAgICAgICBjby0+bmV4dCA9IGNsaXN0LT5uZXh0OyAvKiBnZXQgdGhlIG5leHQtcG9pbnRl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AgICAgICAgfSB3aGlsZShjbGlzdCk7CiAgICAgICAgYnJlYWs7CiAgICAgIH0KICAgIH0KICAgIGxhc3RjID0gY2xpc3Q7CiAgICBjbGlzdCA9IGNsaXN0LT5uZXh0OwogIH0KCiAgaWYoIXJlcGxhY2Vfb2xkKSB7CiAgICAvKiB0aGVuIG1ha2UgdGhlIGxhc3QgaXRlbSBwb2ludCBvbiB0aGlzIG5ldyBvbmUgKi8KICAgIGlmKGxhc3RjKQogICAgICBsYXN0Yy0+bmV4dCA9IGNvOwogICAgZWxzZQogICAgICBjLT5jb29raWVzID0gY287CiAgfQoKICBjLT5udW1jb29raWVzKys7IC8qIG9uZSBtb3JlIGNvb2tpZSBpbiB0aGUgamFyICovCgogIHJldHVybiBjbzsKfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCiAqCiAqIEN1cmxfY29va2llX2luaXQoKQogKgogKiBJbml0cyBhIGNvb2tpZSBzdHJ1Y3QgdG8gcmVhZCBkYXRhIGZyb20gYSBsb2NhbCBmaWxlLiBUaGlzIGlzIGFsd2F5cwogKiBjYWxsZWQgYmVmb3JlIGFueSBjb29raWVzIGFyZSBzZXQuIEZpbGUgbWF5IGJlIE5VTEwuCiAqCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwpzdHJ1Y3QgQ29va2llSW5mbyAqQ3VybF9jb29raWVfaW5pdChjaGFyICpmaWxlLCBzdHJ1Y3QgQ29va2llSW5mbyAqaW5jKQp7CiAgY2hhciBsaW5lW01BWF9DT09LSUVfTElORV07CiAgc3RydWN0IENvb2tpZUluZm8gKmM7CiAgRklMRSAqZnA7CiAgYm9vbCBmcm9tZmlsZT1UUlVFOwogIAogIGlmKE5VTEwgPT0gaW5jKSB7CiAgICAvKiB3ZSBkaWRuJ3QgZ2V0IGEgc3R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gICAgfQogICAgICB3aGlsZSgqbGluZXB0ciAmJiBpc3NwYWNlKChpbnQpKmxpbmVwdHIpKQogICAgICAgIGxpbmVwdHIrKzsKCiAgICAgIEN1cmxfY29va2llX2FkZChjLCBoZWFkZXJsaW5lLCBsaW5lcHRyLCBOVUxMKTsKICAgIH0KICAgIGlmKGZyb21maWxlKQogICAgICBmY2xvc2UoZnApOwogIH0KCiAgYy0+cnVubmluZyA9IFRSVUU7IC8qIG5vdywgd2UncmUgcnVubmluZyAqLwoKICByZXR1cm4gYzsKfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCiAqCiAqIEN1cmxfY29va2llX2dldGxpc3QoKQogKgogKiBGb3IgYSBnaXZlbiBob3N0IGFuZCBwYXRoLCByZXR1cm4gYSBsaW5rZWQgbGlzdCBvZiBjb29raWVzIHRoYXQgdGhlCiAqIGNsaWVudCBzaG91bGQgc2VuZCB0byB0aGUgc2VydmVyIGlmIHVzZWQgbm93LiBUaGUgc2VjdXJlIGJvb2xlYW4gaW5mb3JtcwogKiB0aGUgY29va2llIGlmIGEgc2VjdXJlIGNvbm5lY3Rpb24gaXMgYWNoaWV2ZWQgb3Igbm90LgogKgogKiBJdCBzaGFsbCBvbmx5IHJldHVybiBjb29raWVzIHRoYXQgaGF2ZW4ndCBleHBpcmVkLgogKgogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KCnN0cnVjdCBDb29raWUgKkN1cmxfY29va2llX2dldGxpc3Qoc3RydWN0IENvb2tpZUluZm8gKmMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY2hhciAqaG9zdCwgY2hhciAqcGF0aCwgYm9vbCBzZWN1cmUpCnsKICAgc3RydWN0IENvb2tpZSAqbmV3Y287CiAgIHN0cnVjdCBDb29raWUgKmNvOwogICB0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gICAgICAgcmVxdWlyZW1lbnQgKi8KCSAgICBpZighY28tPnBhdGggfHwKCSAgICAgICBzdHJuZXF1YWwocGF0aCwgY28tPnBhdGgsIHN0cmxlbihjby0+cGF0aCkpKSB7CgoJICAgICAgIC8qIGFuZCBub3csIHdlIGtub3cgdGhpcyBpcyBhIG1hdGNoIGFuZCB3ZSBzaG91bGQgY3JlYXRlIGFuCgkJICBlbnRyeSBmb3IgdGhlIHJldHVybi1saW5rZWQtbGlzdCAqLwoKCSAgICAgICBuZXdjbyA9IChzdHJ1Y3QgQ29va2llICopbWFsbG9jKHNpemVvZihzdHJ1Y3QgQ29va2llKSk7CgkgICAgICAgaWYobmV3Y28pIHsKCQkgIC8qIGZpcnN0LCBjb3B5IHRoZSB3aG9sZSBzb3VyY2UgY29va2llOiAqLwoJCSAgbWVtY3B5KG5ld2NvLCBjbywgc2l6ZW9mKHN0cnVjdCBDb29raWUpKTsKCgkJICAvKiB0aGVuIG1vZGlmeSBvdXIgbmV4dCAqLwoJCSAgbmV3Y28tPm5leHQgPSBtYWluY287CgoJCSAgLyogcG9pbnQgdGhlIG1haW4gdG8gdXMgKi8KCQkgIG1haW5jbyA9IG5ld2NvOwoJICAgICAgIH0KCSAgICB9CgkgfQogICAgICB9CiAgICAgIGNvID0gY28tPm5leHQ7CiAgIH0KCiAgIHJldHVybiBtYWluY287IC8qIHJldHVybiB0aGUgbmV3IGxpc3QgKi8KfQoKCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgogKgogKiBDdXJsX2Nvb2tpZV9mcmVlbGlzdCgpCiAqCiAqIEZyZWUgYSBsaXN0IG9mIGNvb2tpZXMgcHJldmlvdXNseSByZXR1cm5lZCBieSBDdXJsX2Nvb2tpZV9nZXRsaXN0KCk7CiAqCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwoKdm9pZCBDdXJsX2Nvb2tpZV9mcmVlbGlzdChzdHJ1Y3QgQ29va2llICpjbykKewogICBzdHJ1Y3QgQ29va2llICpuZXh0OwogICBpZihjbykgewogICAgICB3aGlsZShjbykgewoJIG5leHQgPSBjby0+bmV4dDsKCSBmcmVlKGNvKTsgLyogd2Ugb25seSBmcmVlIHRoZSBzdHJ1Y3Qgc2luY2UgdGhlICJtZW1iZXJzIiBhcmUgYWxsCgkJICAgICAganVzdCBjb3BpZWQhICovCgkgY28gPSBuZXh0OwogICAgICB9CiAgIH0KfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCiAqCiAqIEN1cmxfY29va2llX2NsZWFudXAoKQogKgogKiBGcmVlIGEgImNvb2tpZSBvYmplY3QiIHByZXZpb3VzIGNyZWF0ZWQgd2l0aCBjb29raWVfaW5pdCgpLgogKgogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8Kdm9pZCBDdXJsX2Nvb2tpZV9jbGVhbnVwKHN0cnVjdCBDb29raWVJbmZvICpjKQp7CiAgIHN0cnVjdCBDb29raWUgKmNvOwogICBzdHJ1Y3QgQ29va2llICpuZXh0OwogICBpZihjKSB7CiAgICAgIGlmKGMtPmZpbGVuYW1lKQoJIGZyZWUoYy0+ZmlsZW5hbWUpOwogICAgICBjbyA9IGMtPmNvb2tpZXM7CgogICAgICB3aGlsZShjbykgewoJIGlmKGNvLT5uYW1lKQoJICAgIGZyZWUoY28tPm5hbWUpOwoJIGlmKGNvLT52YWx1ZSkKCSAgICBmcmVlKGNvLT52YWx1ZSk7CgkgaWYoY28tPmRvbWFpbikKCSAgICBmcmVlKGNvLT5kb21haW4pOwoJIGlmKGNvLT5wYXRoKQoJICAgIGZyZWUoY28tPnBhdGgpOwoJIGlmKGNvLT5leHB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ZHVtcGhlcmUsICJ3Iik7CiAgICBpZighb3V0KQogICAgICByZXR1cm4gMTsgLyogZmFpbHVyZSAqLwogIH0KCiAgaWYoYykgewogICAgZnB1dHMoIiMgTmV0c2NhcGUgSFRUUCBDb29raWUgRmlsZVxuIgogICAgICAgICAgIiMgaHR0cDovL3d3dy5uZXRzY2FwZS5jb20vbmV3c3JlZi9zdGQvY29va2llX3NwZWMuaHRtbFxuIgogICAgICAgICAgIiMgVGhpcyBmaWxlIHdhcyBnZW5lcmF0ZWQgYnkgbGliY3VybCEgRWRpdCBhdCB5b3VyIG93biByaXNrLlxuXG4iLAogICAgICAgICAgb3V0KTsKICAgIGNvID0gYy0+Y29va2llczsKICAgICAKICAgIHdoaWxlKGNvKSB7CiAgICAgIGZwcmludGYob3V0LAogICAgICAgICAgICAgICIlc1x0IiAvKiBkb21haW4gKi8KICAgICAgICAgICAgICAiJXNcdCIgLyogZmllbGQxICovCiAgICAgICAgICAgICAgIiVzXHQiIC8qIHBhdGggKi8KICAgICAgICAgICAgICAiJXNcdCIgLyogc2VjdXJlICovCiAgICAgICAgICAgICAgIiV1XHQiIC8qIGV4cGlyZXMgKi8KICAgICAgICAgICAgICAiJXNcdCIgLyogbmFtZSAqLwogICAgICAgICAgICAgICIlc1xuIiwgLyogdmFsdWUgKi8KICAgICAgICAgICAgICBjby0+ZG9tYWluP2NvLT5kb21haW46InVua25vd24iLAogICAgICAgICAgICAgIGNvLT5maWVsZDE9PTI/IlRSVUUiOiJGQUxTRSIsCiAgICAgICAgICAgICAgY28tPnBhdGg/Y28tPnBhdGg6Ii8iLAogICAgICAgICAgICAgIGNvLT5zZWN1cmU/IlRSVUUiOiJGQUxTRSIsCiAgICAgICAgICAgICAgKHVuc2lnbmVkIGludCljby0+ZXhwaXJlcywKICAgICAgICAgICAgICBjby0+bmFtZSwKICAgICAgICAgICAgICBjby0+dmFsdWU/Y28tPnZhbHVlOiIiKTsKCiAgICAgIGNvPWNvLT5uZXh0OwogICAgfQogIH0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