1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <QApplication>
#include <QPushButton>
#include <QDebug>
#include <QFile>
static const char myTab[256] ="premiere execution";
const size_t msgSize = 18;
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
qDebug() << myTab;
QFile file(argv[0]);
qDebug() << "ouverture du binaire :" << file.open(QIODevice::ReadWrite);
char data;
quint64 fileIndex;
size_t stringIndex = 0;
do {
file.getChar(&data);
//On repère la chaine de caractères à remplacer
//ainsi que sa position dans le binaire
if (data == myTab[stringIndex]) ++stringIndex;
else {
fileIndex = file.pos();
stringIndex = 0;
}
//Si elle est identifiée, on la remplace
if (stringIndex == msgSize) {
file.seek(fileIndex);
const char *newData = QString("nouvelle execution").toLatin1().constData();
file.write(newData,msgSize);
}
} while(!file.atEnd());
file.close();
QPushButton quit("Exit");
QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
quit.show();
return app.exec();
} |
Partager