Files
Pyarmor-Static-Unpack-1shot/pyc_module.h

96 lines
2.3 KiB
C
Raw Normal View History

2009-07-24 08:35:21 +00:00
#ifndef _PYC_MODULE_H
#define _PYC_MODULE_H
2011-10-23 17:48:10 -07:00
#include "pyc_code.h"
2022-12-01 11:35:14 -08:00
#include <vector>
2009-07-24 08:35:21 +00:00
enum PycMagic {
MAGIC_1_0 = 0x00999902,
MAGIC_1_1 = 0x00999903, /* Also covers 1.2 */
MAGIC_1_3 = 0x0A0D2E89,
MAGIC_1_4 = 0x0A0D1704,
MAGIC_1_5 = 0x0A0D4E99,
MAGIC_1_6 = 0x0A0DC4FC,
MAGIC_2_0 = 0x0A0DC687,
MAGIC_2_1 = 0x0A0DEB2A,
MAGIC_2_2 = 0x0A0DED2D,
MAGIC_2_3 = 0x0A0DF23B,
MAGIC_2_4 = 0x0A0DF26D,
MAGIC_2_5 = 0x0A0DF2B3,
MAGIC_2_6 = 0x0A0DF2D1,
MAGIC_2_7 = 0x0A0DF303,
2009-07-24 08:35:21 +00:00
MAGIC_3_0 = 0x0A0D0C3A,
MAGIC_3_1 = 0x0A0D0C4E,
2011-01-06 17:15:48 -08:00
MAGIC_3_2 = 0x0A0D0C6C,
MAGIC_3_3 = 0x0A0D0C9E,
MAGIC_3_4 = 0x0A0D0CEE,
2015-10-01 16:06:09 -07:00
MAGIC_3_5 = 0x0A0D0D16,
MAGIC_3_5_3 = 0x0A0D0D17,
2016-12-14 14:39:22 -08:00
MAGIC_3_6 = 0x0A0D0D33,
2018-07-02 13:13:50 -07:00
MAGIC_3_7 = 0x0A0D0D42,
MAGIC_3_8 = 0x0A0D0D55,
MAGIC_3_9 = 0x0A0D0D61,
2021-10-10 06:48:34 +05:30
MAGIC_3_10 = 0x0A0D0D6F,
MAGIC_3_11 = 0x0A0D0DA7,
MAGIC_3_12 = 0x0A0D0DCB,
MAGIC_3_13 = 0x0A0D0DF3,
INVALID = 0,
2009-07-24 08:35:21 +00:00
};
class PycModule {
public:
2014-01-20 22:21:56 -08:00
PycModule() : m_maj(-1), m_min(-1), m_unicode(false) { }
2009-07-24 08:35:21 +00:00
void loadFromFile(const char* filename);
void loadFromMarshalledFile(const char *filename, int major, int minor);
2009-07-24 08:35:21 +00:00
bool isValid() const { return (m_maj >= 0) && (m_min >= 0); }
2017-07-05 15:53:35 -07:00
int majorVer() const { return m_maj; }
int minorVer() const { return m_min; }
2012-05-26 13:50:23 -07:00
int verCompare(int maj, int min) const
{
if (m_maj == maj)
return m_min - min;
return m_maj - maj;
}
2009-07-24 08:35:21 +00:00
bool isUnicode() const { return m_unicode; }
bool strIsUnicode() const
{
return (m_maj >= 3) || (m_code->flags() & PycCode::CO_FUTURE_UNICODE_LITERALS) != 0;
}
bool internIsBytes() const
{
return (m_maj < 3) && (m_code->flags() & PycCode::CO_FUTURE_UNICODE_LITERALS) != 0;
}
2009-07-24 08:35:21 +00:00
PycRef<PycCode> code() const { return m_code; }
2022-12-01 11:35:14 -08:00
void intern(PycRef<PycString> str) { m_interns.emplace_back(std::move(str)); }
PycRef<PycString> getIntern(int ref) const;
2022-12-01 11:35:14 -08:00
void refObject(PycRef<PycObject> obj) { m_refs.emplace_back(std::move(obj)); }
PycRef<PycObject> getRef(int ref) const;
2009-07-24 08:35:21 +00:00
static bool isSupportedVersion(int major, int minor);
2009-07-24 08:35:21 +00:00
private:
void setVersion(unsigned int magic);
private:
2017-07-05 15:53:35 -07:00
int m_maj, m_min;
2009-07-24 08:35:21 +00:00
bool m_unicode;
PycRef<PycCode> m_code;
2022-12-01 11:35:14 -08:00
std::vector<PycRef<PycString>> m_interns;
std::vector<PycRef<PycObject>> m_refs;
2009-07-24 08:35:21 +00:00
};
#endif