python的bytecode文件格式
时间:2010-11-28 来源:cornsea
1. bytecode file general format
------------------------------------------------
| 4 bytes | 4 bytes | ~
|magic number | modification time | byte codes
-----------------------------------------------
2. bytecode detail format
2.1 element type(grab from python)
#define TYPE_NULL '0'
#define TYPE_NONE 'N'
#define TYPE_FALSE 'F'
#define TYPE_TRUE 'T'
#define TYPE_STOPITER 'S'
#define TYPE_ELLIPSIS '.'
#define TYPE_INT 'i'
#define TYPE_INT64 'I'
#define TYPE_FLOAT 'f'
#define TYPE_BINARY_FLOAT 'g'
#define TYPE_COMPLEX 'x'
#define TYPE_BINARY_COMPLEX 'y'
#define TYPE_LONG 'l'
#define TYPE_STRING 's'
#define TYPE_TUPLE '('
#define TYPE_LIST '['
#define TYPE_DICT '{'
#define TYPE_CODE 'c'
#define TYPE_UNICODE 'u'
#define TYPE_UNKNOWN '?'
#define TYPE_SET '<'
#define TYPE_FROZENSET '>'
2.2 go through type by type
--TYPE_NULL, TYPE_NONE, TYPE_STOPITER, TYPE_ELLIPSIS, TYPE_FALSE, TYPE_TRUE
just a byte of placeholder
--TYPE_INT
little endian
|TYPE_INT|byte0|byte1|byte2|byte3|
--TYPE_INT64
|TYPE_INT64|LOW 4 bytes|HIGH 4 bytes|
--TYPE_LONG
TBD
--TYPE_FLOAT(ascii codec)
| byte 0 | byte 1 | byte 2...n|
|TYPE_FLOAT|string length of float number|float string|
--TYPE_STRING
|TYPE_STRING|string length(4bytes)|string|
--TYPE_TUPLE
|TYPE_TUPLE|tuple length(4bytes)|objects|
--TYPE_LIST
|TYPE_LIST|list length(4bytes)|objects|
--TYPE_DICT (null terminated)
|TYPE_DICT|key|val|NULL|
--TYPE_SET
|TYPE_SET|element number(4bytes)|element|
--TYPE_CODE
|argument count|keyword argument count|locals number|stack size|
|flags|code|consts|names|varnames|freevars|cellvars|file name|name|
|fistlineno|line number table|