Commit 40123cdd authored by Roberto Raggi's avatar Roberto Raggi

A simple, dummy, and probably buggy binary patched for Qt.

parent 8c8d8ed2
This diff is collapsed.
bin/Qt3Supportd4.dll
bin/QtCored4.dll
bin/QtGuid4.dll
bin/QtHelpd4.dll
bin/QtNetworkd4.dll
bin/QtOpenGLd4.dll
bin/QtScriptd4.dll
bin/QtScriptToolsd4.dll
bin/QtSqld4.dll
bin/QtSvgd4.dll
bin/QtTestd4.dll
bin/QtWebKitd4.dll
bin/QtXmld4.dll
bin/QtXmlPatternsd4.dll
lib/Qt3Supportd4.dll
lib/QtCored4.dll
lib/QtGuid4.dll
lib/QtHelpd4.dll
lib/QtNetworkd4.dll
lib/QtOpenGLd4.dll
lib/QtScriptd4.dll
lib/QtScriptToolsd4.dll
lib/QtSqld4.dll
lib/QtSvgd4.dll
lib/QtTestd4.dll
lib/QtWebKitd4.dll
lib/QtXmld4.dll
lib/QtXmlPatternsd4.dll
plugins/accessible/qtaccessiblecompatwidgetsd4.dll
plugins/accessible/qtaccessiblewidgetsd4.dll
plugins/codecs/qcncodecsd4.dll
plugins/codecs/qjpcodecsd4.dll
plugins/codecs/qkrcodecsd4.dll
plugins/codecs/qtwcodecsd4.dll
plugins/iconengines/qsvgicond4.dll
plugins/imageformats/qgifd4.dll
plugins/imageformats/qjpegd4.dll
plugins/imageformats/qmngd4.dll
plugins/imageformats/qsvgd4.dll
plugins/imageformats/qtiffd4.dll
plugins/sqldrivers/qsqlited4.dll
#include <QtCore>
#include <iostream>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QStringList args = app.arguments();
args.removeFirst();
if (args.size() != 3) {
std::cerr << "Usage: qpatch file oldQtDir newQtDir" << std::endl;
return EXIT_FAILURE;
}
const QString files = args.takeFirst();
const QByteArray qtDirPath = QFile::encodeName(args.takeFirst());
const QByteArray newQtPath = QFile::encodeName(args.takeFirst());
QString suffix;
if (! args.isEmpty())
suffix = args.takeFirst();
if (qtDirPath.size() < newQtPath.size()) {
std::cerr << "qpatch: error: newQtDir needs to be less than " << qtDirPath.size() << " characters."
<< std::endl;
return EXIT_FAILURE;
}
QFile fn(files);
if (! fn.open(QFile::ReadOnly)) {
std::cerr << "qpatch: error: file not found" << std::endl;
return EXIT_FAILURE;
}
QStringList filesToPatch;
QTextStream in(&fn);
forever {
QString line;
line = in.readLine();
if (line.isNull())
break;
filesToPatch.append(line);
}
foreach (QString fileName, filesToPatch) {
QString prefix;
prefix += newQtPath;
if (! prefix.endsWith(QLatin1Char('/')))
prefix += QLatin1Char('/');
fileName.prepend(prefix);
qDebug() << "patch file:" << fileName;
continue;
QFile file(fileName);
if (! file.open(QFile::ReadOnly)) {
std::cerr << "qpatch: warning: file not found" << std::endl;
continue;
}
const QFile::Permissions permissions = file.permissions();
const QByteArray source = file.readAll();
file.close();
int index = 0;
QVector<char> patched;
forever {
int start = source.indexOf(qtDirPath, index);
if (start == -1)
break;
int endOfString = start;
while (source.at(endOfString))
++endOfString;
++endOfString; // include the '\0'
//qDebug() << "*** found string:" << source.mid(start, endOfString - start);
for (int i = index; i < start; ++i)
patched.append(source.at(i));
int length = endOfString - start;
QVector<char> s;
for (const char *x = newQtPath.constData(); x != newQtPath.constEnd() - 1; ++x)
s.append(*x);
const int qtDirPathLength = qtDirPath.size();
for (const char *x = source.constData() + start + qtDirPathLength - 1;
x != source.constData() + endOfString; ++x)
s.append(*x);
const int oldSize = s.size();
for (int i = oldSize; i < length; ++i)
s.append('\0');
for (int i = 0; i < s.size(); ++i)
patched.append(s.at(i));
index = endOfString;
}
for (int i = index; i < source.size(); ++i)
patched.append(source.at(i));
QFile out(fileName /* + suffix*/);
out.setPermissions(permissions);
if (out.open(QFile::WriteOnly)) {
out.write(patched.constData(), patched.size());
}
}
return 0;
}
TARGET = qpatch
QT = core
CONFIG += console
macx:CONFIG -= app_bundle
SOURCES += qpatch.cpp
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment