Skip to content

Commit 2d86457

Browse files
authored
PyInstaller in C++
1 parent 2fe998e commit 2d86457

File tree

6 files changed

+559
-0
lines changed

6 files changed

+559
-0
lines changed

PyInstArchive.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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> // Ensure you include this for fixed-width integer types
10+
11+
// Structure for Table of Contents Entry
12+
struct CTOCEntry {
13+
uint32_t position; // Position of the entry
14+
uint32_t cmprsdDataSize; // Compressed data size
15+
uint32_t uncmprsdDataSize; // Uncompressed data size
16+
uint8_t cmprsFlag; // Compression flag
17+
char typeCmprsData; // Type of compressed data
18+
std::string name; // Name of the entry
19+
20+
// Constructor
21+
CTOCEntry(uint32_t pos, uint32_t cmprsdSize, uint32_t uncmprsdSize, uint8_t flag, char type, const std::string& n)
22+
: position(pos), cmprsdDataSize(cmprsdSize), uncmprsdDataSize(uncmprsdSize), cmprsFlag(flag), typeCmprsData(type), name(n) {}
23+
24+
// Getters for entry details
25+
uint32_t getCompressedDataSize() const {
26+
return cmprsdDataSize; // Fixed the variable name here
27+
}
28+
29+
const std::string& getName() const {
30+
return name; // Fixed the variable name here
31+
}
32+
};
33+
34+
// Class for handling the PyInstaller Archive
35+
class PyInstArchive {
36+
public:
37+
// Constructor
38+
PyInstArchive(const std::string& path);
39+
40+
// Member functions
41+
bool open();
42+
void close();
43+
bool checkFile();
44+
bool getCArchiveInfo();
45+
void parseTOC();
46+
void viewFiles();
47+
48+
private:
49+
std::string filePath; // Path to the archive file
50+
std::ifstream fPtr; // File stream for reading the archive
51+
uint64_t fileSize; // Size of the file
52+
uint64_t cookiePos; // Position of the cookie
53+
uint64_t overlayPos; // Position of the overlay
54+
uint64_t overlaySize; // Size of the overlay
55+
uint64_t tableOfContentsPos; // Position of the TOC
56+
uint64_t tableOfContentsSize; // Size of the TOC
57+
uint8_t pyinstVer; // PyInstaller version
58+
uint8_t pymaj; // Python major version
59+
uint8_t pymin; // Python minor version
60+
std::vector<CTOCEntry> tocList; // List of TOC entries
61+
uint32_t lengthofPackage; // Length of the package
62+
uint32_t toc; // Table of contents
63+
uint32_t tocLen; // Length of the table of contents
64+
65+
// Constants for PyInstaller cookie sizes
66+
static const uint8_t PYINST20_COOKIE_SIZE = 24;
67+
static const uint8_t PYINST21_COOKIE_SIZE = 24 + 64;
68+
static const std::string MAGIC;
69+
};
70+
71+
#endif // PYINSTARCHIVE_H

PyInstaller-C++.vcxproj

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>17.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{f165ccfe-88b9-4fff-9b0a-96511007560b}</ProjectGuid>
25+
<RootNamespace>StaticLib2</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
<ProjectName>PyInstaller-C++</ProjectName>
28+
</PropertyGroup>
29+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
30+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
31+
<ConfigurationType>StaticLibrary</ConfigurationType>
32+
<UseDebugLibraries>true</UseDebugLibraries>
33+
<PlatformToolset>v143</PlatformToolset>
34+
<CharacterSet>Unicode</CharacterSet>
35+
</PropertyGroup>
36+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
37+
<ConfigurationType>StaticLibrary</ConfigurationType>
38+
<UseDebugLibraries>false</UseDebugLibraries>
39+
<PlatformToolset>v143</PlatformToolset>
40+
<WholeProgramOptimization>true</WholeProgramOptimization>
41+
<CharacterSet>Unicode</CharacterSet>
42+
</PropertyGroup>
43+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
44+
<ConfigurationType>StaticLibrary</ConfigurationType>
45+
<UseDebugLibraries>true</UseDebugLibraries>
46+
<PlatformToolset>v143</PlatformToolset>
47+
<CharacterSet>Unicode</CharacterSet>
48+
</PropertyGroup>
49+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
50+
<ConfigurationType>StaticLibrary</ConfigurationType>
51+
<UseDebugLibraries>false</UseDebugLibraries>
52+
<PlatformToolset>v143</PlatformToolset>
53+
<WholeProgramOptimization>true</WholeProgramOptimization>
54+
<CharacterSet>Unicode</CharacterSet>
55+
</PropertyGroup>
56+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
57+
<ImportGroup Label="ExtensionSettings">
58+
</ImportGroup>
59+
<ImportGroup Label="Shared">
60+
</ImportGroup>
61+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
62+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
63+
</ImportGroup>
64+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
65+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
66+
</ImportGroup>
67+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
68+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
69+
</ImportGroup>
70+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
71+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
72+
</ImportGroup>
73+
<PropertyGroup Label="UserMacros" />
74+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
75+
<OutDir>$(SolutionDir)ConsoleApplication2</OutDir>
76+
</PropertyGroup>
77+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
78+
<ClCompile>
79+
<WarningLevel>Level3</WarningLevel>
80+
<SDLCheck>true</SDLCheck>
81+
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
82+
<ConformanceMode>true</ConformanceMode>
83+
<PrecompiledHeader>Use</PrecompiledHeader>
84+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
85+
</ClCompile>
86+
<Link>
87+
<SubSystem>
88+
</SubSystem>
89+
<GenerateDebugInformation>true</GenerateDebugInformation>
90+
</Link>
91+
</ItemDefinitionGroup>
92+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
93+
<ClCompile>
94+
<WarningLevel>Level3</WarningLevel>
95+
<FunctionLevelLinking>true</FunctionLevelLinking>
96+
<IntrinsicFunctions>true</IntrinsicFunctions>
97+
<SDLCheck>true</SDLCheck>
98+
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
99+
<ConformanceMode>true</ConformanceMode>
100+
<PrecompiledHeader>Use</PrecompiledHeader>
101+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
102+
</ClCompile>
103+
<Link>
104+
<SubSystem>
105+
</SubSystem>
106+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
107+
<OptimizeReferences>true</OptimizeReferences>
108+
<GenerateDebugInformation>true</GenerateDebugInformation>
109+
</Link>
110+
</ItemDefinitionGroup>
111+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
112+
<ClCompile>
113+
<WarningLevel>Level3</WarningLevel>
114+
<SDLCheck>true</SDLCheck>
115+
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
116+
<ConformanceMode>true</ConformanceMode>
117+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
118+
<PrecompiledHeaderFile>
119+
</PrecompiledHeaderFile>
120+
</ClCompile>
121+
<Link>
122+
<SubSystem>
123+
</SubSystem>
124+
<GenerateDebugInformation>true</GenerateDebugInformation>
125+
</Link>
126+
</ItemDefinitionGroup>
127+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
128+
<ClCompile>
129+
<WarningLevel>Level3</WarningLevel>
130+
<FunctionLevelLinking>true</FunctionLevelLinking>
131+
<IntrinsicFunctions>true</IntrinsicFunctions>
132+
<SDLCheck>true</SDLCheck>
133+
<PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
134+
<ConformanceMode>true</ConformanceMode>
135+
<PrecompiledHeader>Use</PrecompiledHeader>
136+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
137+
</ClCompile>
138+
<Link>
139+
<SubSystem>
140+
</SubSystem>
141+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
142+
<OptimizeReferences>true</OptimizeReferences>
143+
<GenerateDebugInformation>true</GenerateDebugInformation>
144+
</Link>
145+
</ItemDefinitionGroup>
146+
<ItemGroup>
147+
<ClInclude Include="framework.h" />
148+
<ClInclude Include="pch.h" />
149+
<ClInclude Include="PyInstArchive.h" />
150+
</ItemGroup>
151+
<ItemGroup>
152+
<ClCompile Include="pch.cpp">
153+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
154+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
155+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
156+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
157+
</ClCompile>
158+
<ClCompile Include="Pyinstaller.cpp" />
159+
</ItemGroup>
160+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
161+
<ImportGroup Label="ExtensionTargets">
162+
</ImportGroup>
163+
</Project>

0 commit comments

Comments
 (0)