view o3pack.cpp @ 12:ac837fe1d590

Switch implementation for reqex class and added RFCOMM as label for Bluetooth based connection by Linux
author Ideenmodellierer
date Mon, 12 Jan 2026 13:58:41 +0000
parents 21ce6187d32e
children
line wrap: on
line source

#include <QApplication>
#include <QDir>
#include <QProgressBar>
#include <QProgressDialog>
#include <QtDebug>

#include "HexFile.h"

//////////////////////////////////////////////////////////////////////////////
static unsigned char frogSecretKey[16]
    = {111, 85, 190, 69, 108, 254, 242, 19, 231, 49, 248, 255, 233, 48, 176, 241};
static unsigned char ostc3SecretKey[16]
    = {241, 233, 176, 48, 69, 111, 190, 85, 255, 231, 248, 49, 19, 108, 242, 254};

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    app.processEvents();

    //---- Parse parameters --------------------------------------------------
    QString in, out;
    QDir current;
    bool force = false;
    bool ostc3 = true;

    if (argc < 2)
        goto Usage;

    if (QString(argv[1]).toLower() == "-frog") {
        ostc3 = false;
        argc--, argv++;
    } else if (QString(argv[1]).toLower() == "-ostc3") {
        ostc3 = true;
        argc--, argv++;
    }

    in = QDir::cleanPath(current.absoluteFilePath(argv[1]));
    out = QDir::cleanPath(current.absoluteFilePath(argv[2]));
    if (argv[2] == QString("-f") && argc >= 3) {
        out = QDir::cleanPath(current.absoluteFilePath(argv[3]));
        force = true;
    }

    //---- Check parameters consistency --------------------------------------
    {
        QFileInfo fi(in);
        if (!fi.exists() || !fi.isReadable()) {
            qWarning().nospace() << "Cannot read input file " << in;
            goto Usage;
        }
    }

    {
        QFileInfo fo(out);
        if (fo.exists()) {
            if (!force) {
                qWarning().nospace() << "File " << out << " exists. Use -f to force overwrite.";
                goto Usage;
            }

            if (!fo.isWritable()) {
                qWarning().nospace() << "Cannot write to " << out << ". Protected file ?";
                goto Usage;
            }
            current.remove(out);
        }
    }

    //---- Load the HEX file -------------------------------------------------
    {
        QProgressBar *progress = new QProgressBar(0);
        progress->setFormat("Loading %p%");
        progress->show();

        try {
            HexFile hex;
            hex.allocate(0x20000);

            hex.load(in, progress);
            hex.sqwiz(0x1E000);

            char sum[10];
            sprintf(sum, "%08X", hex.checksum());
            qDebug() << "Checksum " << sum;

            //---- Save encrypted HEX file -------------------------------------------
            progress->setFormat("Saving %p%");
            hex.saveEncrypted(out, (ostc3 ? ostc3SecretKey : frogSecretKey), progress);
        } catch (const char *msg) {
            qWarning() << "Failed: " << msg;
        }

        delete progress;
    }

    //---- End --------------------------------------------------------------
    return 0;

Usage:
    qWarning() << "Usage:" << endl
               << "    " << QString(app.arguments()[0]).section('/', -1).section('\\', -1)
               << "[-frog|-ostc3]"
               << " input.hex [-f] output.hex";
    exit(-1);
}