diff --git a/ffsengine.cpp b/ffsengine.cpp index 6f041b9..953a257 100644 --- a/ffsengine.cpp +++ b/ffsengine.cpp @@ -24,6 +24,8 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "LZMA/LzmaCompress.h" #include "LZMA/LzmaDecompress.h" +#include + FfsEngine::FfsEngine(QObject *parent) : QObject(parent) { @@ -44,9 +46,14 @@ TreeModel* FfsEngine::treeModel() const void FfsEngine::msg(const QString & message, const QModelIndex & index) { +#ifndef _CONSOLE messageItems.enqueue(MessageListItem(message, NULL, 0, index)); +#else + std::cout << message.toLatin1().constData() << std::endl; +#endif } +#ifndef _CONSOLE QQueue FfsEngine::messages() const { return messageItems; @@ -56,6 +63,7 @@ void FfsEngine::clearMessages() { messageItems.clear(); } +#endif bool FfsEngine::hasIntersection(const UINT32 begin1, const UINT32 end1, const UINT32 begin2, const UINT32 end2) { diff --git a/ffsengine.h b/ffsengine.h index 4113efd..f8a3d47 100644 --- a/ffsengine.h +++ b/ffsengine.h @@ -20,9 +20,12 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "basetypes.h" #include "treemodel.h" -#include "messagelistitem.h" #include "peimage.h" +#ifndef _CONSOLE +#include "messagelistitem.h" +#endif + class TreeModel; class FfsEngine : public QObject @@ -37,11 +40,12 @@ public: // Returns model for Qt view classes TreeModel* treeModel() const; +#ifndef _CONSOLE // Returns message items queue QQueue messages() const; - // Clears message items queue void clearMessages(); +#endif // Firmware image parsing UINT8 parseImageFile(const QByteArray & buffer); @@ -110,8 +114,10 @@ private: // Patch routines UINT8 patchVtf(QByteArray &vtf); - // Message helper +#ifndef _CONSOLE QQueue messageItems; +#endif + // Message helper void msg(const QString & message, const QModelIndex &index = QModelIndex()); // Internal operations diff --git a/uefiextract.cpp b/uefiextract.cpp new file mode 100644 index 0000000..974c3ae --- /dev/null +++ b/uefiextract.cpp @@ -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; +} \ No newline at end of file diff --git a/uefiextract.h b/uefiextract.h new file mode 100644 index 0000000..88bd301 --- /dev/null +++ b/uefiextract.h @@ -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 +#include +#include +#include + +#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 diff --git a/uefiextract.pro b/uefiextract.pro new file mode 100644 index 0000000..b7be22a --- /dev/null +++ b/uefiextract.pro @@ -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 + \ No newline at end of file diff --git a/uefiextract_main.cpp b/uefiextract_main.cpp new file mode 100644 index 0000000..45cd668 --- /dev/null +++ b/uefiextract_main.cpp @@ -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 +#include +#include +#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(); +} \ No newline at end of file diff --git a/uefitool.pro b/uefitool.pro index 19cbc09..7ce3ed9 100644 --- a/uefitool.pro +++ b/uefitool.pro @@ -4,7 +4,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = UEFITool TEMPLATE = app -SOURCES += main.cpp \ +SOURCES += uefitool_main.cpp \ uefitool.cpp \ searchdialog.cpp \ types.cpp \ diff --git a/main.cpp b/uefitool_main.cpp similarity index 97% rename from main.cpp rename to uefitool_main.cpp index 5a9bd62..05275d6 100644 --- a/main.cpp +++ b/uefitool_main.cpp @@ -1,4 +1,4 @@ -/* main.cpp +/* uefitool_main.cpp Copyright (c) 2014, Nikolaj Schlej. All rights reserved. This program and the accompanying materials