|
1 | | -#ifndef PYINSTARCHIVE_H |
2 | | -#define PYINSTARCHIVE_H |
3 | | - |
4 | | -#include <iostream> |
5 | | -#include <fstream> |
6 | | -#include <vector> |
7 | | -#include <string> |
8 | | -#include <cstring> |
9 | | -#include <cstdint> |
10 | | -#include <mutex> |
11 | | - |
12 | | -// Structure for Table of Contents Entry |
13 | | -struct CTOCEntry { |
14 | | - uint32_t position; // Position of the entry |
15 | | - uint32_t cmprsdDataSize; // Compressed data size |
16 | | - uint32_t uncmprsdDataSize; // Uncompressed data size |
17 | | - uint8_t cmprsFlag; // Compression flag |
18 | | - char typeCmprsData; // Type of compressed data |
19 | | - std::string name; // Name of the entry |
20 | | - |
21 | | - // Constructor |
22 | | - CTOCEntry(uint32_t pos, uint32_t cmprsdSize, uint32_t uncmprsdSize, uint8_t flag, char type, const std::string& n) |
23 | | - : position(pos), cmprsdDataSize(cmprsdSize), uncmprsdDataSize(uncmprsdSize), cmprsFlag(flag), typeCmprsData(type), name(n) {} |
24 | | - |
25 | | - // Getters for entry details |
26 | | - uint32_t getCompressedDataSize() const { |
27 | | - return cmprsdDataSize; |
28 | | - } |
29 | | - |
30 | | - const std::string& getName() const { |
31 | | - return name; |
32 | | - } |
33 | | - |
34 | | - bool isCompressed() const { |
35 | | - return cmprsFlag != 0; |
36 | | - } |
37 | | -}; |
38 | | - |
39 | | -// Class for handling the PyInstaller Archive |
40 | | -class PyInstArchive { |
41 | | -public: |
42 | | - // Constructor |
43 | | - PyInstArchive(const std::string& path); |
44 | | - |
45 | | - // Member functions |
46 | | - bool open(); |
47 | | - void close(); |
48 | | - bool checkFile(); |
49 | | - bool getCArchiveInfo(); |
50 | | - void parseTOC(); |
51 | | - void timeExtractionProcess(const std::string& outputDir); |
52 | | - void decompressAndExtractFile(const CTOCEntry& tocEntry, const std::string& outputDir); |
53 | | - void displayInfo(); |
54 | | - void decompressData(const std::vector<char>& compressedData, std::vector<char>& decompressedData); |
55 | | - |
56 | | -private: |
57 | | - std::mutex mtx; |
58 | | - std::mutex printMtx; // Mutex for synchronizing print statements |
59 | | - std::string filePath; // Path to the archive file |
60 | | - std::ifstream fPtr; // File stream for reading the archive |
61 | | - uint64_t fileSize; // Size of the file |
62 | | - uint64_t cookiePos; // Position of the cookie |
63 | | - uint64_t overlayPos; // Position of the overlay |
64 | | - uint64_t overlaySize; // Size of the overlay |
65 | | - uint64_t tableOfContentsPos; // Position of the TOC |
66 | | - uint64_t tableOfContentsSize; // Size of the TOC |
67 | | - uint8_t pyinstVer; // PyInstaller version |
68 | | - uint8_t pymaj; // Python major version |
69 | | - uint8_t pymin; // Python minor version |
70 | | - std::vector<CTOCEntry> tocList; // List of TOC entries |
71 | | - uint32_t lengthofPackage; // Length of the package |
72 | | - uint32_t toc; // Table of contents |
73 | | - uint32_t tocLen; // Length of the table of contents |
74 | | - |
75 | | - // Constants for PyInstaller cookie sizes |
76 | | - static const uint8_t PYINST20_COOKIE_SIZE = 24; |
77 | | - static const uint8_t PYINST21_COOKIE_SIZE = 24 + 64; |
78 | | - static const std::string MAGIC; |
79 | | -}; |
80 | | - |
81 | | -#endif // PYINSTARCHIVE_H |
| 1 | +#ifndef PYINSTARCHIVE_H |
| 2 | +#define PYINSTARCHIVE_H |
| 3 | + |
| 4 | +#include <iostream> |
| 5 | +#include <fstream> |
| 6 | +#include <vector> |
| 7 | +#include <string> |
| 8 | +#include <cstring> |
| 9 | +#include <cstdint> |
| 10 | +#include <mutex> |
| 11 | + |
| 12 | +// Structure for Table of Contents Entry |
| 13 | +struct CTOCEntry { |
| 14 | + uint32_t position; // Position of the entry |
| 15 | + uint32_t cmprsdDataSize; // Compressed data size |
| 16 | + uint32_t uncmprsdDataSize; // Uncompressed data size |
| 17 | + uint8_t cmprsFlag; // Compression flag |
| 18 | + char typeCmprsData; // Type of compressed data |
| 19 | + std::string name; // Name of the entry |
| 20 | + |
| 21 | + // Constructor |
| 22 | + CTOCEntry(uint32_t pos, uint32_t cmprsdSize, uint32_t uncmprsdSize, uint8_t flag, char type, const std::string& n) |
| 23 | + : position(pos), cmprsdDataSize(cmprsdSize), uncmprsdDataSize(uncmprsdSize), cmprsFlag(flag), typeCmprsData(type), name(n) {} |
| 24 | + |
| 25 | + // Getters for entry details |
| 26 | + uint32_t getCompressedDataSize() const { |
| 27 | + return cmprsdDataSize; |
| 28 | + } |
| 29 | + |
| 30 | + const std::string& getName() const { |
| 31 | + return name; |
| 32 | + } |
| 33 | + |
| 34 | + bool isCompressed() const { |
| 35 | + return cmprsFlag != 0; |
| 36 | + } |
| 37 | +}; |
| 38 | + |
| 39 | +// Class for handling the PyInstaller Archive |
| 40 | +class PyInstArchive { |
| 41 | +public: |
| 42 | + // Constructor |
| 43 | + PyInstArchive(const std::string& path); |
| 44 | + |
| 45 | + // Member functions |
| 46 | + bool open(); |
| 47 | + void close(); |
| 48 | + bool checkFile(); |
| 49 | + bool getCArchiveInfo(); |
| 50 | + void parseTOC(); |
| 51 | + void timeExtractionProcess(const std::string& outputDir); |
| 52 | + void decompressAndExtractFile(const CTOCEntry& tocEntry, const std::string& outputDir); |
| 53 | + void displayInfo(); |
| 54 | + void decompressData(const std::vector<char>& compressedData, std::vector<char>& decompressedData); |
| 55 | + |
| 56 | +private: |
| 57 | + std::mutex mtx; |
| 58 | + std::mutex printMtx; // Mutex for synchronizing print statements |
| 59 | + std::string filePath; // Path to the archive file |
| 60 | + std::ifstream fPtr; // File stream for reading the archive |
| 61 | + uint64_t fileSize; // Size of the file |
| 62 | + uint64_t cookiePos; // Position of the cookie |
| 63 | + uint64_t overlayPos; // Position of the overlay |
| 64 | + uint64_t overlaySize; // Size of the overlay |
| 65 | + uint64_t tableOfContentsPos; // Position of the TOC |
| 66 | + uint64_t tableOfContentsSize; // Size of the TOC |
| 67 | + uint8_t pyinstVer; // PyInstaller version |
| 68 | + uint8_t pymaj; // Python major version |
| 69 | + uint8_t pymin; // Python minor version |
| 70 | + std::vector<CTOCEntry> tocList; // List of TOC entries |
| 71 | + uint32_t lengthofPackage; // Length of the package |
| 72 | + uint32_t toc; // Table of contents |
| 73 | + uint32_t tocLen; // Length of the table of contents |
| 74 | + |
| 75 | + // Constants for PyInstaller cookie sizes |
| 76 | + static const uint8_t PYINST20_COOKIE_SIZE = 24; |
| 77 | + static const uint8_t PYINST21_COOKIE_SIZE = 24 + 64; |
| 78 | + static const std::string MAGIC; |
| 79 | +}; |
| 80 | + |
| 81 | +#endif // PYINSTARCHIVE_H |
0 commit comments