예제 #1
0
// ////////////////////////////////////////////////////////////////////////////////
// @public 构造函数
//
GenerateDlg::GenerateDlg(QWidget *parent)
	: QDialog(parent)
	, m_genThread(NULL)
	, m_waitDlg(NULL)
{
	this->setWindowFlags(Qt::Dialog | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
	ui.setupUi(this);

	tab2 = ui.tabWidget->widget(1);

	QValidator* mask = new QRegExpValidator(QRegExp("[0-9]{1,8}"));
	ui.edtGroupId->setValidator(mask);

	m_ipMask = new QRegExpValidator(QRegExp("[0-9,\\.]+"));
	ui.edtIp->setValidator(m_ipMask);
	ui.edAlternateIp->setValidator(m_ipMask);

	QIntValidator* portMask = new QIntValidator(0, 65535);
	ui.edtPort->setValidator(portMask);
	ui.edtAlternatePort->setValidator(portMask);

	ui.lstPlatform->item(0)->setSelected(true);
	setWindowTitle(QString::fromLocal8Bit("生成植入模块 - Windows"));
	m_curSystem = L"WINDOWS";

	connect(ui.btnOk, SIGNAL(clicked()), this, SLOT(GenerateTarget()));
	connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(reject()));

	connect(ui.lstPlatform, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(PlatformChanged(QListWidgetItem*)));
	connect(ui.cmbIp1, SIGNAL(currentIndexChanged(int)), this, SLOT(ServerTypeChanged_1(int)));
	connect(ui.cmbIp2, SIGNAL(currentIndexChanged(int)), this, SLOT(ServerTypeChanged_2(int)));
	connect(ui.btnGetIP, SIGNAL(clicked()), this, SLOT(GetIP()));
	connect(ui.btnGetIP2, SIGNAL(clicked()), this, SLOT(GetIP()));
	connect(ui.chkRooted, SIGNAL(clicked()), this, SLOT(RootStatusChanged()));
	connect(ui.chkNotRooted, SIGNAL(clicked()), this, SLOT(RootStatusChanged()));
	connect(ui.chkLocal, SIGNAL(clicked()), this, SLOT(EnvironmentChanged()));
	connect(ui.chkRemote, SIGNAL(clicked()), this, SLOT(EnvironmentChanged()));

	EnvironmentChanged();

	InitCustomGui();

	m_waitDlg = new WaitDlg(this);
	m_waitDlg->hide();

	InitCustomText(this);
}
int applypatch(const char* source_filename,
               const char* target_filename,
               const char* target_sha1_str,
               size_t target_size,
               int num_patches,
               char** const patch_sha1_str,
               Value** patch_data,
               Value* bonus_data) {
    printf("patch %s: ", source_filename);

    if (target_filename[0] == '-' &&
        target_filename[1] == '\0') {
        target_filename = source_filename;
    }

    uint8_t target_sha1[SHA_DIGEST_SIZE];
    if (ParseSha1(target_sha1_str, target_sha1) != 0) {
        printf("failed to parse tgt-sha1 \"%s\"\n", target_sha1_str);
        return 1;
    }

    FileContents copy_file;
    FileContents source_file;
    copy_file.data = NULL;
    source_file.data = NULL;
    const Value* source_patch_value = NULL;
    const Value* copy_patch_value = NULL;

    // We try to load the target file into the source_file object.
    if (LoadFileContents(target_filename, &source_file,
                         RETOUCH_DO_MASK) == 0) {
        if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
            // The early-exit case:  the patch was already applied, this file
            // has the desired hash, nothing for us to do.
            printf("already ");
            print_short_sha1(target_sha1);
            putchar('\n');
            free(source_file.data);
            return 0;
        }
    }

    if (source_file.data == NULL ||
        (target_filename != source_filename &&
         strcmp(target_filename, source_filename) != 0)) {
        // Need to load the source file:  either we failed to load the
        // target file, or we did but it's different from the source file.
        free(source_file.data);
        source_file.data = NULL;
        LoadFileContents(source_filename, &source_file,
                         RETOUCH_DO_MASK);
    }

    if (source_file.data != NULL) {
        int to_use = FindMatchingPatch(source_file.sha1,
                                       patch_sha1_str, num_patches);
        if (to_use >= 0) {
            source_patch_value = patch_data[to_use];
        }
    }

    if (source_patch_value == NULL) {
        free(source_file.data);
        source_file.data = NULL;
        printf("source file is bad; trying copy\n");

        if (LoadFileContents(CACHE_TEMP_SOURCE, &copy_file,
                             RETOUCH_DO_MASK) < 0) {
            // fail.
            printf("failed to read copy file\n");
            return 1;
        }

        int to_use = FindMatchingPatch(copy_file.sha1,
                                       patch_sha1_str, num_patches);
        if (to_use >= 0) {
            copy_patch_value = patch_data[to_use];
        }

        if (copy_patch_value == NULL) {
            // fail.
            printf("copy file doesn't match source SHA-1s either\n");
            free(copy_file.data);
            return 1;
        }
    }

    int result = GenerateTarget(&source_file, source_patch_value,
                                &copy_file, copy_patch_value,
                                source_filename, target_filename,
                                target_sha1, target_size, bonus_data);
    free(source_file.data);
    free(copy_file.data);

    return result;
}
예제 #3
0
파일: applypatch.c 프로젝트: bju2000/MT6797
int applypatch(const char* source_filename,
               const char* target_filename,
               const char* target_sha1_str,
               size_t target_size,
               int num_patches,
               char** const patch_sha1_str,
               Value** patch_data,
               Value* bonus_data) {
    printf("patch %s: ", source_filename);

    if (target_filename[0] == '-' &&
        target_filename[1] == '\0') {
        target_filename = source_filename;
    }

    uint8_t target_sha1[SHA_DIGEST_SIZE];
    if (ParseSha1(target_sha1_str, target_sha1) != 0) {
        printf("failed to parse tgt-sha1 \"%s\"\n", target_sha1_str);
        return 1;
    }

    FileContents copy_file;
    FileContents source_file;
    copy_file.data = NULL;
    source_file.data = NULL;
    const Value* source_patch_value = NULL;
    const Value* copy_patch_value = NULL;

    // We try to load the target file into the source_file object.
    if (LoadFileContents(target_filename, &source_file) == 0) {
        if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
            // The early-exit case:  the patch was already applied, this file
            // has the desired hash, nothing for us to do.
            printf("already ");
            print_short_sha1(target_sha1);
            putchar('\n');
            free(source_file.data);
            return 0;
        }
    }

    if (source_file.data == NULL ||
        (target_filename != source_filename &&
         strcmp(target_filename, source_filename) != 0)) {
        // Need to load the source file:  either we failed to load the
        // target file, or we did but it's different from the source file.
        free(source_file.data);
        source_file.data = NULL;
        LoadFileContents(source_filename, &source_file);
    }

    if (source_file.data != NULL) {
        int to_use = FindMatchingPatch(source_file.sha1,
                                       patch_sha1_str, num_patches);
        if (to_use >= 0) {
            source_patch_value = patch_data[to_use];
        }
    }

    if (source_patch_value == NULL) {
        free(source_file.data);
        source_file.data = NULL;
        printf("source file is bad; trying copy\n");

        if (LoadFileContents(CACHE_TEMP_SOURCE, &copy_file) < 0) {
            // fail.
            printf("failed to read copy file\n");
            return 1;
        }

        int to_use = FindMatchingPatch(copy_file.sha1,
                                       patch_sha1_str, num_patches);
        if (to_use >= 0) {
            copy_patch_value = patch_data[to_use];
        }

        if (copy_patch_value == NULL) {
            // fail.
            printf("copy file doesn't match source SHA-1s either\n");
#if 0 //wschen 2013-05-23
            free(copy_file.data);
            return 1;
#else
            if (memcmp(copy_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
                printf("use cache temp file to replace \"%s\"\n", target_filename);

                if (strncmp(target_filename, "MTD:", 4) == 0 || strncmp(target_filename, "EMMC:", 5) == 0) {
                    if (WriteToPartition(copy_file.data, copy_file.size, target_filename) != 0) {
                        printf("write of patched data to %s failed\n", target_filename);
                        return 1;
                    }
                    //everything is fine
                    unlink(CACHE_TEMP_SOURCE);
                    sync();
                    return 0;
                } else {
                    if (SaveFileContents(target_filename, &copy_file) < 0) {
                        printf("failed to copy back %s\n", target_filename);
                        free(copy_file.data);
                        copy_file.data = NULL;
                        return 1;
                    } else {
                        //copy success
                        free(copy_file.data);
                        copy_file.data = NULL;

                        if (LoadFileContents(target_filename, &source_file) == 0) {
                            if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
                                free(source_file.data);
                                source_file.data = NULL;
                                //everything is fine
                                unlink(CACHE_TEMP_SOURCE);
                                sync();
                                return 0;
                            } else {
                                free(source_file.data);
                                source_file.data = NULL;
                                printf("copied target file (%s) SHA1 does not match\n", target_filename);
                                return 1;
                            }
                        } else {
                            printf("failed to read copied target file (%s)\n", target_filename);
                            return 1;
                        }
                    }
                }
            } else {
                printf("cache temp file doesn't match target SHA-1s (%s)\n", target_filename);
                free(copy_file.data);
                copy_file.data = NULL;
                return 1;
            }
#endif
        }
    }

    int result = GenerateTarget(&source_file, source_patch_value,
                                &copy_file, copy_patch_value,
                                source_filename, target_filename,
                                target_sha1, target_size, bonus_data);
    free(source_file.data);
    free(copy_file.data);

    return result;
}