First approach to implement console UI

UEFIExtract utility will be done soon, the only thing to be done is
actual extractAll code. :)
This commit is contained in:
Nikolaj Schlej 2014-04-21 18:05:29 +02:00
parent 72829ee0a3
commit 8aba0766e5
8 changed files with 186 additions and 5 deletions

View File

@ -24,6 +24,8 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "LZMA/LzmaCompress.h" #include "LZMA/LzmaCompress.h"
#include "LZMA/LzmaDecompress.h" #include "LZMA/LzmaDecompress.h"
#include <iostream>
FfsEngine::FfsEngine(QObject *parent) FfsEngine::FfsEngine(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
@ -44,9 +46,14 @@ TreeModel* FfsEngine::treeModel() const
void FfsEngine::msg(const QString & message, const QModelIndex & index) void FfsEngine::msg(const QString & message, const QModelIndex & index)
{ {
#ifndef _CONSOLE
messageItems.enqueue(MessageListItem(message, NULL, 0, index)); messageItems.enqueue(MessageListItem(message, NULL, 0, index));
#else
std::cout << message.toLatin1().constData() << std::endl;
#endif
} }
#ifndef _CONSOLE
QQueue<MessageListItem> FfsEngine::messages() const QQueue<MessageListItem> FfsEngine::messages() const
{ {
return messageItems; return messageItems;
@ -56,6 +63,7 @@ void FfsEngine::clearMessages()
{ {
messageItems.clear(); messageItems.clear();
} }
#endif
bool FfsEngine::hasIntersection(const UINT32 begin1, const UINT32 end1, const UINT32 begin2, const UINT32 end2) bool FfsEngine::hasIntersection(const UINT32 begin1, const UINT32 end1, const UINT32 begin2, const UINT32 end2)
{ {

View File

@ -20,9 +20,12 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "basetypes.h" #include "basetypes.h"
#include "treemodel.h" #include "treemodel.h"
#include "messagelistitem.h"
#include "peimage.h" #include "peimage.h"
#ifndef _CONSOLE
#include "messagelistitem.h"
#endif
class TreeModel; class TreeModel;
class FfsEngine : public QObject class FfsEngine : public QObject
@ -37,11 +40,12 @@ public:
// Returns model for Qt view classes // Returns model for Qt view classes
TreeModel* treeModel() const; TreeModel* treeModel() const;
#ifndef _CONSOLE
// Returns message items queue // Returns message items queue
QQueue<MessageListItem> messages() const; QQueue<MessageListItem> messages() const;
// Clears message items queue // Clears message items queue
void clearMessages(); void clearMessages();
#endif
// Firmware image parsing // Firmware image parsing
UINT8 parseImageFile(const QByteArray & buffer); UINT8 parseImageFile(const QByteArray & buffer);
@ -110,8 +114,10 @@ private:
// Patch routines // Patch routines
UINT8 patchVtf(QByteArray &vtf); UINT8 patchVtf(QByteArray &vtf);
// Message helper #ifndef _CONSOLE
QQueue<MessageListItem> messageItems; QQueue<MessageListItem> messageItems;
#endif
// Message helper
void msg(const QString & message, const QModelIndex &index = QModelIndex()); void msg(const QString & message, const QModelIndex &index = QModelIndex());
// Internal operations // Internal operations

48
uefiextract.cpp Normal file
View File

@ -0,0 +1,48 @@
/* uefiextract.cpp
Copyright (c) 2014, 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 "uefiextract.h"
UEFIExtract::UEFIExtract(QObject *parent) :
QObject(parent)
{
ffsEngine = new FfsEngine(this);
}
UEFIExtract::~UEFIExtract()
{
delete ffsEngine;
}
UINT8 UEFIExtract::extractAll(QString path)
{
QFileInfo fileInfo = QFileInfo(path);
if (!fileInfo.exists())
return ERR_FILE_OPEN;
QFile inputFile;
inputFile.setFileName(path);
if (!inputFile.open(QFile::ReadOnly))
return ERR_FILE_OPEN;
QByteArray buffer = inputFile.readAll();
inputFile.close();
UINT8 result = ffsEngine->parseImageFile(buffer);
if (result)
return result;
return ERR_SUCCESS;
}

39
uefiextract.h Normal file
View File

@ -0,0 +1,39 @@
/* uefiextract.h
Copyright (c) 2014, 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.
*/
#ifndef __UEFIEXTRACT_H__
#define __UEFIEXTRACT_H__
#include <QObject>
#include <QByteArray>
#include <QString>
#include <QFileInfo>
#include "basetypes.h"
#include "ffsengine.h"
class UEFIExtract : public QObject
{
Q_OBJECT
public:
explicit UEFIExtract(QObject *parent = 0);
~UEFIExtract();
UINT8 extractAll(QString path);
private:
FfsEngine* ffsEngine;
};
#endif

41
uefiextract.pro Normal file
View File

@ -0,0 +1,41 @@
QT += core
QT -= gui
TARGET = UEFIExtract
TEMPLATE = app
CONFIG += console
SOURCES += uefiextract_main.cpp \
uefiextract.cpp \
types.cpp \
descriptor.cpp \
ffs.cpp \
ffsengine.cpp \
treeitem.cpp \
treemodel.cpp \
messagelistitem.cpp \
LZMA/LzmaCompress.c \
LZMA/LzmaDecompress.c \
LZMA/SDK/C/LzFind.c \
LZMA/SDK/C/LzmaDec.c \
LZMA/SDK/C/LzmaEnc.c \
Tiano/EfiTianoDecompress.c \
Tiano/EfiTianoCompress.c
HEADERS += uefiextract.h \
basetypes.h \
descriptor.h \
gbe.h \
me.h \
ffs.h \
peimage.h \
types.h \
ffsengine.h \
treeitem.h \
treemodel.h \
messagelistitem.h \
LZMA/LzmaCompress.h \
LZMA/LzmaDecompress.h \
Tiano/EfiTianoDecompress.h \
Tiano/EfiTianoCompress.h

39
uefiextract_main.cpp Normal file
View File

@ -0,0 +1,39 @@
/* uefiextract_main.cpp
Copyright (c) 2014, 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 <QCoreApplication>
#include <QString>
#include <iostream>
#include "uefiextract.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
a.setOrganizationName("CodeRush");
a.setOrganizationDomain("coderush.me");
a.setApplicationName("UEFIExtract");
UEFIExtract w;
if (a.arguments().length() > 1) {
UINT8 result = w.extractAll(a.arguments().at(1));
//!TODO: error messages
return result;
}
else {
std::cout << "UEFIExtract 0.1.0" << std::endl << std::endl <<
"Usage: uefiextract imagefile\n" << std::endl;
return 0;
}
return a.exec();
}

View File

@ -4,7 +4,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = UEFITool TARGET = UEFITool
TEMPLATE = app TEMPLATE = app
SOURCES += main.cpp \ SOURCES += uefitool_main.cpp \
uefitool.cpp \ uefitool.cpp \
searchdialog.cpp \ searchdialog.cpp \
types.cpp \ types.cpp \

View File

@ -1,4 +1,4 @@
/* main.cpp /* uefitool_main.cpp
Copyright (c) 2014, Nikolaj Schlej. All rights reserved. Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials This program and the accompanying materials