Filer
SqshArchiveReader.h
1 /*-
2  * Copyright (c) 2022-23 Simon Peter <probono@puredarwin.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 /*
28  * Example usage (in the real world, should use "this" instead of deleting the reader and elfBinary objects):
29 
30  const char* sqsh_file = "/home/user/Desktop/appimagetool-730-x86_64.AppImage";
31  qDebug() << "sqsh_file" << sqsh_file;
32 
33  qint64 offset = ElfSizeCalculator::calculateElfSize(sqsh_file);
34  qDebug() << "offset" << offset;
35  SqshArchiveReader *reader = new SqshArchiveReader(offset);
36 
37  QByteArray fileData = reader->readFileFromArchive(sqsh_file, ".DirIcon");
38  QIcon icon;
39  icon.addPixmap(QPixmap::fromImage(QImage::fromData(fileData)), QIcon::Normal, QIcon::Off);
40  qDebug() << icon.availableSizes();
41 
42  QByteArray desktopData = reader->readFileFromArchive(sqsh_file, "appimagetool.desktop");
43  QString desktopFile = QString::fromUtf8(desktopData);
44  QStringList desktopEntries = desktopFile.split("\n");
45  desktopEntries.removeAll("");
46  qDebug() << desktopEntries;
47 
48  QStringList results = reader->readSqshArchive(sqsh_file);
49  qDebug() << results;
50 
51  delete reader;
52  exit(0);
53 
54  (QSize(128, 128))
55  ("[Desktop Entry]", "Type=Application", "Name=appimagetool", "Exec=appimagetool", "Comment=Tool to generate AppImages from AppDirs", "Icon=appimagetool", "Categories=Development;", "Terminal=true")
56  (".DirIcon", "AppRun", "appimagetool.desktop", "appimagetool.png", "usr")
57 
58  */
59 
60 #ifndef SQSHARCHIVEREADER_H
61 #define SQSHARCHIVEREADER_H
62 
63 #include <QObject>
64 #include <QString>
65 #include <QByteArray>
66 
73 class SqshArchiveReader : public QObject {
74 Q_OBJECT
75 
76 public:
82  explicit SqshArchiveReader(uint64_t archive_offset = 0, QObject* parent = nullptr);
83 
89  QStringList readSqshArchive(const QString& sqsh_file);
90 
97  QByteArray readFileFromArchive(const QString& sqsh_file, const QString& file_path);
98 
99 private:
100  uint64_t archive_offset_;
101 };
102 
103 #endif // SQSHARCHIVEREADER_H
The SqshArchiveReader class provides functionality to read files from a SquashFS archive.
Definition: SqshArchiveReader.h:73
QByteArray readFileFromArchive(const QString &sqsh_file, const QString &file_path)
Reads the contents of a specific file from the SquashFS archive.
Definition: SqshArchiveReader.cpp:69
SqshArchiveReader(uint64_t archive_offset=0, QObject *parent=nullptr)
Constructs a SqshArchiveReader object with the specified archive offset.
Definition: SqshArchiveReader.cpp:33
QStringList readSqshArchive(const QString &sqsh_file)
Reads and returns the list of files present in the SquashFS archive.
Definition: SqshArchiveReader.cpp:36