1010#include " ../../Common/LimitedStreams.h"
1111#include " ../../Common/StreamUtils.h"
1212#include " PyInstallerHandler.h"
13-
13+ # include < cstdint >
1414
1515using namespace NWindows ;
1616namespace NArchive {
@@ -27,10 +27,10 @@ namespace NArchive {
2727 class CHandler : public IInArchive , public IInArchiveGetStream , public CMyUnknownImp {
2828 public:
2929 MY_UNKNOWN_IMP2 (IInArchive, IInArchiveGetStream) // Implementing unknown interface
30- INTERFACE_IInArchive (;)
30+ INTERFACE_IInArchive (;)
3131
32- // Default constructor
33- CHandler () = default ;
32+ // Default constructor
33+ CHandler () = default ;
3434
3535 // Constructor that accepts a PyInstallerHandler reference
3636 CHandler (PyInstallerHandler& handler) : pyHandler(handler) {}
@@ -44,16 +44,16 @@ namespace NArchive {
4444
4545 // Implement interface functions for the archive properties
4646 IMP_IInArchive_Props
47- IMP_IInArchive_ArcProps_NO_Table
48-
49- /* *
50- * @brief Retrieves a property of the archive based on the provided property ID.
51- *
52- * @param propID The ID of the property to retrieve.
53- * @param value Output parameter to receive the property value.
54- * @return HRESULT indicating success or failure.
55- */
56- STDMETHODIMP CHandler::GetArchiveProperty (PROPID propID, PROPVARIANT* value)
47+ IMP_IInArchive_ArcProps_NO_Table
48+
49+ /* *
50+ * @brief Retrieves a property of the archive based on the provided property ID.
51+ *
52+ * @param propID The ID of the property to retrieve.
53+ * @param value Output parameter to receive the property value.
54+ * @return HRESULT indicating success or failure.
55+ */
56+ STDMETHODIMP CHandler::GetArchiveProperty (PROPID propID, PROPVARIANT* value)
5757 {
5858 NCOM::CPropVariant prop; // Property variant to hold the property value
5959 switch (propID)
@@ -289,11 +289,32 @@ namespace NArchive {
289289 return S_OK; // Indicate success
290290 }
291291
292- // Register the archive handler for .exe files
293- REGISTER_ARC_I_NO_SIG (
294- " exe" , " exe" , 0 , 0xAA ,
295- 0 ,
296- 0 ,
297- NULL )
292+ const uint8_t pyinstallerMagic[] = { ' M' , ' E' , ' I' , 0x0C , 0x0B , 0x0A , 0x0B , 0x0E };
293+ /* *
294+ * @brief Registers an archive handler for .exe files containing PyInstaller archives.
295+ *
296+ * This function registers a handler that detects .exe files with a specific magic number
297+ * and processes them as PyInstaller archives. The handler is triggered when an .exe file
298+ * containing the defined magic sequence is encountered.
299+ *
300+ * @param "exe" The file extension that this handler applies to. In this case, it is for .exe files.
301+ * @param "exe" The file type this handler is associated with, which is also '.exe'.
302+ * @param 0 Flags for the handler, currently set to 0 (no flags).
303+ * @param 0xAA Unique ID for this archive handler, ensuring it's distinguishable.
304+ * @param pyinstallerMagic Array containing the magic number (byte sequence) used to identify PyInstaller archives.
305+ * @param 0 Reserved field, currently set to 0.
306+ * @param NArcInfoFlags::kStartOpen Indicates that the archive should be opened immediately when detected.
307+ * @return None.
308+ */
309+ REGISTER_ARC_I (
310+ " exe" ,
311+ " exe" ,
312+ 0 ,
313+ 0xAA ,
314+ pyinstallerMagic,
315+ 0 ,
316+ NArcInfoFlags::kStartOpen
317+ )
318+
298319 }
299- }
320+ }
0 commit comments