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