/* Utility to "un-patch" Qt5Core.dll, so that the cryptographic signature becomes valid. Issue: https://bugreports.qt.io/browse/QTBUG-76985 */ #include #include #include #include #include using namespace std; /** Replace the value in a "key=value" segment within the buffer. */ static bool PatchSegment (string & buffer, string key, string value) { key += "="; size_t idx = buffer.find(key); if (idx == std::string::npos) return false; idx += key.size(); for (size_t i = 0; i < value.size(); ++i) buffer[idx + i] = value[i]; return true; } /** Change specfic Qt5Core.dll sections hack to their original values from when the file was signed. Based on suggestions from in Patrick Morgenstern in https://bugreports.qt.io/browse/QTBUG-76985 */ static bool UnPatchQt5CoreDLL (string & buffer) { std::string instdate = "2012-12-20"; instdate.resize(11); // zero-extend to match size in https://github.com/qt/qtbase/blob/dev/configure.pri PatchSegment(buffer, "qt_instdate", instdate); // discard return-value, since the field is being removed std::string prfxpath = "c:/Users/qt/work/install"; prfxpath.resize(256); // zero-extend to match size in https://github.com/qt/qtbase/blob/dev/configure.pri return PatchSegment(buffer, "qt_prfxpath", prfxpath); } int main (int argc, char *argv[]) { if (argc != 3) { cout << "QtUnpatcher - Utility to un-patch Qt5Core.dll, so that the cryptographic signature becomes valid.\n"; cout << "Usage: QtUnpatcher \n"; return 1; } ifstream input(argv[1], ios::binary); if (!input) { cerr << "ERROR: Unable to open input file\n"; return -1; } // load file content into a string instead of a vector to ease search // this is safe, because std::string may contain '\0' characters string content(istreambuf_iterator(input), {}); bool patched = UnPatchQt5CoreDLL(content); if (!patched) { cerr << "ERROR: Unable to patch " << argv[1] << "\n"; return -2; } ofstream output(argv[2], ios::binary); if (!output) { cerr << "ERROR: Unable to open output file\n"; return -3; } output.write(content.data(), content.size()); cout << "Patched file " << argv[2] << " successfully written.\n"; return 0; }