2013-10-08 15:07:03 +08:00
|
|
|
/* uefitool.cpp
|
|
|
|
|
|
|
|
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
|
|
|
|
This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "uefitool.h"
|
|
|
|
#include "ui_uefitool.h"
|
|
|
|
|
|
|
|
UEFITool::UEFITool(QWidget *parent) :
|
|
|
|
QMainWindow(parent),
|
|
|
|
ui(new Ui::UEFITool)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2013-10-15 23:19:15 +08:00
|
|
|
ffsEngine = NULL;
|
2013-10-08 15:07:03 +08:00
|
|
|
|
2013-10-15 23:19:15 +08:00
|
|
|
//Connect
|
|
|
|
connect(ui->actionOpenImageFile, SIGNAL(triggered()), this, SLOT(openImageFile()));
|
2013-11-17 17:01:11 +08:00
|
|
|
connect(ui->actionExtract, SIGNAL(triggered()), this, SLOT(extractAsIs()));
|
2013-11-07 21:46:28 +08:00
|
|
|
connect(ui->actionExtractBody, SIGNAL(triggered()), this, SLOT(extractBody()));
|
|
|
|
connect(ui->actionExtractUncompressed, SIGNAL(triggered()), this, SLOT(extractUncompressed()));
|
|
|
|
connect(ui->actionInsertInto, SIGNAL(triggered()), this, SLOT(insertInto()));
|
|
|
|
connect(ui->actionInsertBefore, SIGNAL(triggered()), this, SLOT(insertBefore()));
|
|
|
|
connect(ui->actionInsertAfter, SIGNAL(triggered()), this, SLOT(insertAfter()));
|
|
|
|
connect(ui->actionReplace, SIGNAL(triggered()), this, SLOT(replace()));
|
|
|
|
connect(ui->actionRemove, SIGNAL(triggered()), this, SLOT(remove()));
|
2013-11-18 23:23:59 +08:00
|
|
|
connect(ui->actionRebuild, SIGNAL(triggered()), this, SLOT(rebuild()));
|
2013-11-07 21:46:28 +08:00
|
|
|
connect(ui->actionSaveImageFile, SIGNAL(triggered()), this, SLOT(saveImageFile()));
|
2013-11-19 00:11:08 +08:00
|
|
|
connect(ui->actionChangeToNone, SIGNAL(triggered()), this, SLOT(changeToNone()));
|
2013-11-18 23:23:59 +08:00
|
|
|
connect(ui->actionChangeToEfi11, SIGNAL(triggered()), this, SLOT(changeToEfi11()));
|
|
|
|
connect(ui->actionChangeToTiano, SIGNAL(triggered()), this, SLOT(changeToTiano()));
|
|
|
|
connect(ui->actionChangeToLzma, SIGNAL(triggered()), this, SLOT(changeToLzma()));
|
|
|
|
connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
|
|
|
|
connect(ui->actionAboutQt, SIGNAL(triggered()), this, SLOT(aboutQt()));
|
|
|
|
connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(exit()));
|
2013-10-08 15:07:03 +08:00
|
|
|
// Enable Drag-and-Drop actions
|
|
|
|
this->setAcceptDrops(true);
|
|
|
|
|
2013-11-14 18:40:39 +08:00
|
|
|
// Initialize non-persistent data
|
2013-10-08 15:07:03 +08:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
UEFITool::~UEFITool()
|
|
|
|
{
|
|
|
|
delete ui;
|
2013-10-15 23:19:15 +08:00
|
|
|
delete ffsEngine;
|
2013-10-08 15:07:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void UEFITool::init()
|
|
|
|
{
|
2013-11-15 18:48:14 +08:00
|
|
|
// Clear components
|
2013-11-17 17:01:11 +08:00
|
|
|
ui->messageListWidget->clear();
|
2013-10-08 15:07:03 +08:00
|
|
|
ui->infoEdit->clear();
|
2013-10-15 23:19:15 +08:00
|
|
|
|
|
|
|
// Disable all actions except openImageFile
|
|
|
|
ui->actionExtract->setDisabled(true);
|
|
|
|
ui->actionExtractBody->setDisabled(true);
|
|
|
|
ui->actionExtractUncompressed->setDisabled(true);
|
|
|
|
ui->actionReplace->setDisabled(true);
|
2013-11-07 21:46:28 +08:00
|
|
|
ui->actionRemove->setDisabled(true);
|
2013-11-18 23:23:59 +08:00
|
|
|
ui->actionRebuild->setDisabled(true);
|
2013-11-07 21:46:28 +08:00
|
|
|
ui->actionInsertInto->setDisabled(true);
|
2013-10-15 23:19:15 +08:00
|
|
|
ui->actionInsertBefore->setDisabled(true);
|
|
|
|
ui->actionInsertAfter->setDisabled(true);
|
2013-11-07 21:46:28 +08:00
|
|
|
ui->actionSaveImageFile->setDisabled(true);
|
2013-10-15 23:19:15 +08:00
|
|
|
|
|
|
|
// Make new ffsEngine
|
2013-11-17 19:13:37 +08:00
|
|
|
if (ffsEngine)
|
|
|
|
delete ffsEngine;
|
2013-10-15 23:19:15 +08:00
|
|
|
ffsEngine = new FfsEngine(this);
|
|
|
|
ui->structureTreeView->setModel(ffsEngine->model());
|
|
|
|
|
|
|
|
// Connect
|
|
|
|
connect(ui->structureTreeView, SIGNAL(collapsed(const QModelIndex &)), this, SLOT(resizeTreeViewColums(void)));
|
|
|
|
connect(ui->structureTreeView, SIGNAL(expanded(const QModelIndex &)), this, SLOT(resizeTreeViewColums(void)));
|
2013-10-08 15:07:03 +08:00
|
|
|
connect(ui->structureTreeView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
|
|
|
|
this, SLOT(populateUi(const QModelIndex &)));
|
2013-11-17 17:01:11 +08:00
|
|
|
connect(ui->messageListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(scrollTreeView(QListWidgetItem*)));
|
2013-11-14 18:40:39 +08:00
|
|
|
|
|
|
|
resizeTreeViewColums();
|
2013-10-08 15:07:03 +08:00
|
|
|
}
|
|
|
|
|
2013-11-14 18:40:39 +08:00
|
|
|
void UEFITool::populateUi(const QModelIndex ¤t)
|
2013-10-08 15:07:03 +08:00
|
|
|
{
|
2013-11-17 17:01:11 +08:00
|
|
|
if (!current.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
TreeItem* item = static_cast<TreeItem*>(current.internalPointer());
|
|
|
|
UINT8 type = item->type();
|
|
|
|
UINT8 subtype = item->subtype();
|
2013-11-18 23:23:59 +08:00
|
|
|
UINT8 algorithm = item->compression();
|
2013-11-17 17:01:11 +08:00
|
|
|
|
|
|
|
ui->infoEdit->setPlainText(item->info());
|
|
|
|
ui->actionExtract->setDisabled(item->hasEmptyHeader() && item->hasEmptyBody() && item->hasEmptyTail());
|
2013-11-18 23:23:59 +08:00
|
|
|
ui->actionRebuild->setDisabled(item->hasEmptyHeader() && item->hasEmptyBody() && item->hasEmptyTail());
|
2013-11-17 17:01:11 +08:00
|
|
|
ui->actionExtractBody->setDisabled(item->hasEmptyHeader());
|
|
|
|
//ui->actionExtractUncompressed->setEnabled(ffsEngine->isCompressedFile(current));
|
|
|
|
ui->actionRemove->setEnabled(type == TreeItem::Volume || type == TreeItem::File || type == TreeItem::Section);
|
|
|
|
ui->actionInsertInto->setEnabled(type == TreeItem::Volume || type == TreeItem::File
|
|
|
|
|| (type == TreeItem::Section && (subtype == EFI_SECTION_COMPRESSION || subtype == EFI_SECTION_GUID_DEFINED || subtype == EFI_SECTION_DISPOSABLE)));
|
|
|
|
ui->actionInsertBefore->setEnabled(type == TreeItem::File || type == TreeItem::Section);
|
|
|
|
ui->actionInsertAfter->setEnabled(type == TreeItem::File || type == TreeItem::Section);
|
2013-11-14 18:40:39 +08:00
|
|
|
//ui->actionReplace->setEnabled(ffsEngine->isOfType(TreeItem::File, current));
|
2013-11-19 00:11:08 +08:00
|
|
|
ui->menuChangeCompressionTo->setEnabled(type == TreeItem::Section && subtype == EFI_SECTION_COMPRESSION &&
|
|
|
|
(algorithm == COMPRESSION_ALGORITHM_NONE || COMPRESSION_ALGORITHM_EFI11 || algorithm == COMPRESSION_ALGORITHM_TIANO || algorithm == COMPRESSION_ALGORITHM_LZMA));
|
2013-11-18 23:23:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void UEFITool::rebuild()
|
|
|
|
{
|
|
|
|
QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
|
|
|
|
if (!index.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
UINT8 result = ffsEngine->rebuild(index);
|
|
|
|
|
|
|
|
if (result == ERR_SUCCESS)
|
|
|
|
ui->actionSaveImageFile->setEnabled(true);
|
2013-11-07 21:46:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void UEFITool::remove()
|
|
|
|
{
|
2013-11-17 17:01:11 +08:00
|
|
|
QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
|
|
|
|
if (!index.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
UINT8 result = ffsEngine->remove(index);
|
|
|
|
|
|
|
|
if (result == ERR_SUCCESS)
|
2013-11-07 21:46:28 +08:00
|
|
|
ui->actionSaveImageFile->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
2013-11-14 18:40:39 +08:00
|
|
|
void UEFITool::insert(const UINT8 mode)
|
2013-11-07 21:46:28 +08:00
|
|
|
{
|
2013-11-17 17:01:11 +08:00
|
|
|
QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
|
|
|
|
if (!index.isValid())
|
|
|
|
return;
|
2013-11-14 18:40:39 +08:00
|
|
|
|
2013-11-17 17:01:11 +08:00
|
|
|
TreeItem* item = static_cast<TreeItem*>(index.internalPointer());
|
2013-11-14 18:40:39 +08:00
|
|
|
UINT8 type;
|
|
|
|
UINT8 objectType;
|
2013-11-17 17:01:11 +08:00
|
|
|
|
2013-11-15 18:48:14 +08:00
|
|
|
if (mode == INSERT_MODE_BEFORE || mode == INSERT_MODE_AFTER)
|
2013-11-14 18:40:39 +08:00
|
|
|
type = item->parent()->type();
|
|
|
|
else
|
|
|
|
type = item->type();
|
|
|
|
|
2013-11-17 17:01:11 +08:00
|
|
|
QString path;
|
2013-11-14 18:40:39 +08:00
|
|
|
switch (type) {
|
|
|
|
case TreeItem::Volume:
|
|
|
|
path = QFileDialog::getOpenFileName(this, tr("Select FFS file to insert"),".","FFS file (*.ffs *.bin);;All files (*.*)");
|
|
|
|
objectType = TreeItem::File;
|
|
|
|
break;
|
|
|
|
case TreeItem::File:
|
|
|
|
case TreeItem::Section:
|
2013-11-17 17:01:11 +08:00
|
|
|
path = QFileDialog::getOpenFileName(this, tr("Select section file to insert"),".","Section file (*.sct *.bin);;All files (*.*)");
|
2013-11-14 18:40:39 +08:00
|
|
|
objectType = TreeItem::Section;
|
|
|
|
break;
|
|
|
|
default:
|
2013-11-07 21:46:28 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFileInfo fileInfo = QFileInfo(path);
|
|
|
|
if (!fileInfo.exists())
|
|
|
|
{
|
2013-11-14 18:40:39 +08:00
|
|
|
ui->statusBar->showMessage(tr("Please select existing file"));
|
2013-11-07 21:46:28 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFile inputFile;
|
|
|
|
inputFile.setFileName(path);
|
|
|
|
|
|
|
|
if (!inputFile.open(QFile::ReadOnly))
|
|
|
|
{
|
|
|
|
ui->statusBar->showMessage(tr("Can't open file for reading"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray buffer = inputFile.readAll();
|
|
|
|
inputFile.close();
|
|
|
|
|
2013-11-17 17:01:11 +08:00
|
|
|
UINT8 result = ffsEngine->insert(index, buffer, objectType, mode);
|
2013-11-07 21:46:28 +08:00
|
|
|
if (result)
|
2013-11-14 18:40:39 +08:00
|
|
|
ui->statusBar->showMessage(tr("File can't be inserted (%1)").arg(result));
|
2013-11-07 21:46:28 +08:00
|
|
|
else
|
|
|
|
ui->actionSaveImageFile->setEnabled(true);
|
2013-10-08 15:07:03 +08:00
|
|
|
}
|
|
|
|
|
2013-11-14 18:40:39 +08:00
|
|
|
void UEFITool::insertInto()
|
2013-11-07 21:46:28 +08:00
|
|
|
{
|
2013-11-14 18:40:39 +08:00
|
|
|
insert(INSERT_MODE_PREPEND);
|
|
|
|
}
|
2013-11-07 21:46:28 +08:00
|
|
|
|
2013-11-14 18:40:39 +08:00
|
|
|
void UEFITool::insertBefore()
|
|
|
|
{
|
|
|
|
insert(INSERT_MODE_BEFORE);
|
|
|
|
}
|
2013-11-07 21:46:28 +08:00
|
|
|
|
2013-11-14 18:40:39 +08:00
|
|
|
void UEFITool::insertAfter()
|
|
|
|
{
|
|
|
|
insert(INSERT_MODE_AFTER);
|
2013-11-07 21:46:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void UEFITool::replace()
|
|
|
|
{
|
2013-11-14 18:40:39 +08:00
|
|
|
|
2013-11-07 21:46:28 +08:00
|
|
|
}
|
|
|
|
|
2013-11-18 23:23:59 +08:00
|
|
|
void UEFITool::changeToEfi11()
|
|
|
|
{
|
|
|
|
QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
|
|
|
|
if (!index.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
UINT8 result = ffsEngine->changeCompression(index, COMPRESSION_ALGORITHM_EFI11);
|
|
|
|
|
|
|
|
if (result == ERR_SUCCESS)
|
|
|
|
ui->actionSaveImageFile->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UEFITool::changeToTiano()
|
|
|
|
{
|
|
|
|
QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
|
|
|
|
if (!index.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
UINT8 result = ffsEngine->changeCompression(index, COMPRESSION_ALGORITHM_TIANO);
|
|
|
|
if (result == ERR_SUCCESS)
|
|
|
|
ui->actionSaveImageFile->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UEFITool::changeToLzma()
|
|
|
|
{
|
|
|
|
QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
|
|
|
|
if (!index.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
UINT8 result = ffsEngine->changeCompression(index, COMPRESSION_ALGORITHM_LZMA);
|
|
|
|
if (result == ERR_SUCCESS)
|
|
|
|
ui->actionSaveImageFile->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
2013-11-19 00:11:08 +08:00
|
|
|
void UEFITool::changeToNone()
|
|
|
|
{
|
|
|
|
QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
|
|
|
|
if (!index.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
UINT8 result = ffsEngine->changeCompression(index, COMPRESSION_ALGORITHM_NONE);
|
|
|
|
if (result == ERR_SUCCESS)
|
|
|
|
ui->actionSaveImageFile->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
2013-11-18 23:23:59 +08:00
|
|
|
void UEFITool::about()
|
|
|
|
{
|
|
|
|
QMessageBox::about(this, tr("About UEFITool"), tr(
|
|
|
|
"Copyright (c) 2013, Nikolaj Schlej aka CodeRush.\n\n"
|
|
|
|
"The program is dedicated to RevoGirl. Rest in peace, young genius.\n\n"
|
|
|
|
"The program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License.\n"
|
|
|
|
"The full text of the license may be found at\nhttp://opensource.org/licenses/bsd-license.php\n\n"
|
|
|
|
"THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN \"AS IS\" BASIS,\n"
|
|
|
|
"WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND,\n"
|
|
|
|
"EITHER EXPRESS OR IMPLIED."
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UEFITool::aboutQt()
|
|
|
|
{
|
|
|
|
QMessageBox::aboutQt(this, tr("About Qt"));
|
|
|
|
}
|
|
|
|
|
2013-11-07 21:46:28 +08:00
|
|
|
void UEFITool::saveImageFile()
|
|
|
|
{
|
2013-11-14 18:40:39 +08:00
|
|
|
QString path = QFileDialog::getSaveFileName(this, tr("Save BIOS image file"),".","BIOS image file (*.rom *.bin *.cap *.fd *.wph *.efi);;All files (*.*)");
|
2013-11-07 21:46:28 +08:00
|
|
|
|
|
|
|
QFile outputFile;
|
|
|
|
outputFile.setFileName(path);
|
|
|
|
if (!outputFile.open(QFile::WriteOnly))
|
|
|
|
{
|
|
|
|
ui->statusBar->showMessage(tr("Can't open file for writing"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray reconstructed;
|
|
|
|
UINT8 result = ffsEngine->reconstructImage(reconstructed);
|
2013-11-17 19:13:37 +08:00
|
|
|
showMessage();
|
2013-11-07 21:46:28 +08:00
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
ui->statusBar->showMessage(tr("Reconstruction failed (%1)").arg(result));
|
2013-11-17 19:13:37 +08:00
|
|
|
|
2013-11-07 21:46:28 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-14 18:40:39 +08:00
|
|
|
outputFile.resize(0);
|
2013-11-07 21:46:28 +08:00
|
|
|
outputFile.write(reconstructed);
|
|
|
|
outputFile.close();
|
|
|
|
ui->statusBar->showMessage(tr("Reconstructed image written"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UEFITool::resizeTreeViewColums()
|
2013-10-08 15:07:03 +08:00
|
|
|
{
|
2013-10-15 23:19:15 +08:00
|
|
|
int count = ffsEngine->model()->columnCount();
|
2013-10-08 15:07:03 +08:00
|
|
|
for(int i = 0; i < count; i++)
|
|
|
|
ui->structureTreeView->resizeColumnToContents(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UEFITool::openImageFile()
|
|
|
|
{
|
|
|
|
QString path = QFileDialog::getOpenFileName(this, tr("Open BIOS image file"),".","BIOS image file (*.rom *.bin *.cap *.bio *.fd *.wph *.efi);;All files (*.*)");
|
|
|
|
openImageFile(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UEFITool::openImageFile(QString path)
|
|
|
|
{
|
|
|
|
QFileInfo fileInfo = QFileInfo(path);
|
|
|
|
if (!fileInfo.exists())
|
|
|
|
{
|
2013-11-14 18:40:39 +08:00
|
|
|
ui->statusBar->showMessage(tr("Please select existing file"));
|
2013-10-08 15:07:03 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFile inputFile;
|
|
|
|
inputFile.setFileName(path);
|
|
|
|
|
|
|
|
if (!inputFile.open(QFile::ReadOnly))
|
|
|
|
{
|
2013-11-07 21:46:28 +08:00
|
|
|
ui->statusBar->showMessage(tr("Can't open file for reading"));
|
2013-10-08 15:07:03 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray buffer = inputFile.readAll();
|
|
|
|
inputFile.close();
|
|
|
|
|
|
|
|
init();
|
2013-10-15 23:19:15 +08:00
|
|
|
UINT8 result = ffsEngine->parseInputFile(buffer);
|
2013-11-17 19:13:37 +08:00
|
|
|
showMessage();
|
|
|
|
if (result)
|
2013-11-14 18:40:39 +08:00
|
|
|
ui->statusBar->showMessage(tr("Opened file can't be parsed (%1)").arg(result));
|
2013-10-08 15:07:03 +08:00
|
|
|
else
|
|
|
|
ui->statusBar->showMessage(tr("Opened: %1").arg(fileInfo.fileName()));
|
2013-11-17 19:13:37 +08:00
|
|
|
|
2013-10-08 15:07:03 +08:00
|
|
|
resizeTreeViewColums();
|
|
|
|
}
|
|
|
|
|
2013-11-17 17:01:11 +08:00
|
|
|
void UEFITool::extract(const UINT8 mode)
|
2013-10-08 15:07:03 +08:00
|
|
|
{
|
2013-11-17 17:01:11 +08:00
|
|
|
QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
|
|
|
|
if (!index.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
TreeItem* item = static_cast<TreeItem*>(index.internalPointer());
|
|
|
|
UINT8 type = item->type();
|
2013-10-08 15:07:03 +08:00
|
|
|
|
2013-11-17 17:01:11 +08:00
|
|
|
QString path;
|
|
|
|
switch (type) {
|
|
|
|
case TreeItem::Capsule:
|
|
|
|
path = QFileDialog::getSaveFileName(this, tr("Save capsule to binary file"),".","Capsule file (*.cap *.bin);;All files (*.*)");
|
|
|
|
break;
|
|
|
|
case TreeItem::Image:
|
|
|
|
path = QFileDialog::getSaveFileName(this, tr("Save image to binary file"),".","Image file (*.rom *.bin);;All files (*.*)");
|
|
|
|
break;
|
|
|
|
case TreeItem::Region:
|
|
|
|
path = QFileDialog::getSaveFileName(this, tr("Save region to binary file"),".","Region file (*.rgn *.bin);;All files (*.*)");
|
|
|
|
break;
|
|
|
|
case TreeItem::Padding:
|
|
|
|
path = QFileDialog::getSaveFileName(this, tr("Save padding to binary file"),".","Padding file (*.pad *.bin);;All files (*.*)");
|
|
|
|
break;
|
|
|
|
case TreeItem::Volume:
|
|
|
|
path = QFileDialog::getSaveFileName(this, tr("Save volume to binary file"),".","Volume file (*.vol *.bin);;All files (*.*)");
|
|
|
|
break;
|
|
|
|
case TreeItem::File:
|
|
|
|
path = QFileDialog::getSaveFileName(this, tr("Save FFS file to binary file"),".","FFS file (*.ffs *.bin);;All files (*.*)");
|
|
|
|
break;
|
|
|
|
case TreeItem::Section:
|
|
|
|
path = QFileDialog::getSaveFileName(this, tr("Select section file to insert"),".","Section file (*.sct *.bin);;All files (*.*)");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-08 15:07:03 +08:00
|
|
|
QFile outputFile;
|
|
|
|
outputFile.setFileName(path);
|
|
|
|
if (!outputFile.open(QFile::WriteOnly))
|
|
|
|
{
|
2013-11-14 18:40:39 +08:00
|
|
|
ui->statusBar->showMessage(tr("Can't open file for rewriting"));
|
2013-10-08 15:07:03 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-17 17:01:11 +08:00
|
|
|
QByteArray extracted;
|
|
|
|
UINT8 result = ffsEngine->extract(index, extracted, mode);
|
|
|
|
if (result)
|
|
|
|
ui->statusBar->showMessage(tr("File can't be extracted (%1)").arg(result));
|
|
|
|
else {
|
|
|
|
outputFile.resize(0);
|
|
|
|
outputFile.write(extracted);
|
|
|
|
outputFile.close();
|
|
|
|
}
|
2013-10-08 15:07:03 +08:00
|
|
|
}
|
|
|
|
|
2013-11-17 17:01:11 +08:00
|
|
|
void UEFITool::extractAsIs()
|
2013-10-08 15:07:03 +08:00
|
|
|
{
|
2013-11-17 17:01:11 +08:00
|
|
|
extract(EXTRACT_MODE_AS_IS);
|
|
|
|
}
|
2013-10-08 15:07:03 +08:00
|
|
|
|
2013-11-17 17:01:11 +08:00
|
|
|
void UEFITool::extractBody()
|
|
|
|
{
|
|
|
|
extract(EXTRACT_MODE_BODY_ONLY);
|
2013-10-15 23:19:15 +08:00
|
|
|
}
|
|
|
|
|
2013-11-07 21:46:28 +08:00
|
|
|
void UEFITool::extractUncompressed()
|
2013-10-15 23:19:15 +08:00
|
|
|
{
|
2013-11-17 17:01:11 +08:00
|
|
|
extract(EXTRACT_MODE_UNCOMPRESSED);
|
2013-10-08 15:07:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void UEFITool::dragEnterEvent(QDragEnterEvent* event)
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasFormat("text/uri-list"))
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UEFITool::dropEvent(QDropEvent* event)
|
|
|
|
{
|
|
|
|
QString path = event->mimeData()->urls().at(0).toLocalFile();
|
|
|
|
openImageFile(path);
|
|
|
|
}
|
|
|
|
|
2013-11-17 17:01:11 +08:00
|
|
|
void UEFITool::showMessage()
|
2013-11-15 18:48:14 +08:00
|
|
|
{
|
2013-11-17 17:01:11 +08:00
|
|
|
ui->messageListWidget->clear();
|
2013-11-17 19:13:37 +08:00
|
|
|
if (!ffsEngine)
|
|
|
|
return;
|
|
|
|
|
|
|
|
messageItems = ffsEngine->message();
|
2013-11-17 17:01:11 +08:00
|
|
|
for (int i = 0; i < messageItems.count(); i++) {
|
2013-11-17 19:13:37 +08:00
|
|
|
ui->messageListWidget->addItem(new MessageListItem(messageItems.at(i)));
|
2013-11-15 18:48:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UEFITool::scrollTreeView(QListWidgetItem* item)
|
|
|
|
{
|
2013-11-17 17:01:11 +08:00
|
|
|
MessageListItem* messageItem = (MessageListItem*) item;
|
|
|
|
QModelIndex index = messageItem->index();
|
2013-11-15 18:48:14 +08:00
|
|
|
if (index.isValid()) {
|
|
|
|
ui->structureTreeView->scrollTo(index);
|
2013-11-17 17:01:11 +08:00
|
|
|
ui->structureTreeView->selectionModel()->clearSelection();
|
2013-11-15 18:48:14 +08:00
|
|
|
ui->structureTreeView->selectionModel()->select(index, QItemSelectionModel::Select);
|
|
|
|
}
|
|
|
|
}
|