Skip to content

Commit

Permalink
Add Python 3.5 disassembly support
Browse files Browse the repository at this point in the history
  • Loading branch information
zrax committed Oct 1, 2015
1 parent 6883a7e commit 5fae3e2
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 210 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
endif()

set(PYTHON_VERSIONS
10 11 13 14 15 16 # Python 1.1 and 1.2 are marshall-identical
10 11 13 14 15 16 # Python 1.1 and 1.2 are marshal-identical
20 21 22 23 24 25 26 27
30 31 32 33 34
30 31 32 33 34 35
)

foreach(ver ${PYTHON_VERSIONS})
Expand Down
391 changes: 197 additions & 194 deletions PythonBytecode.txt

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions bytecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ DECLARE_PYTHON(3, 1)
DECLARE_PYTHON(3, 2)
DECLARE_PYTHON(3, 3)
DECLARE_PYTHON(3, 4)
DECLARE_PYTHON(3, 5)

const char* Pyc::OpcodeName(int opcode)
{
Expand All @@ -49,8 +50,11 @@ const char* Pyc::OpcodeName(int opcode)
"INPLACE_MULTIPLY", "INPLACE_DIVIDE", "INPLACE_MODULO", "INPLACE_POWER",
"GET_ITER", "PRINT_ITEM_TO", "PRINT_NEWLINE_TO", "INPLACE_LSHIFT",
"INPLACE_RSHIFT", "INPLACE_AND", "INPLACE_XOR", "INPLACE_OR",
"WITH_CLEANUP", "IMPORT_STAR", "YIELD_VALUE", "LOAD_BUILD_CLASS",
"STORE_LOCALS", "POP_EXCEPT", "SET_ADD", "YIELD_FROM",
"WITH_CLEANUP", "WITH_CLEANUP_START", "WITH_CLEANUP_FINISH", "IMPORT_STAR",
"YIELD_VALUE", "LOAD_BUILD_CLASS", "STORE_LOCALS", "POP_EXCEPT", "SET_ADD",
"YIELD_FROM", "BINARY_MATRIX_MULTIPLY", "INPLACE_MATRIX_MULTIPLY",
"GET_AITER", "GET_ANEXT", "BEFORE_ASYNC_WITH", "GET_YEILD_FROM_ITER",
"GET_AWAITABLE",

"STORE_NAME", "DELETE_NAME", "UNPACK_TUPLE", "UNPACK_LIST", "UNPACK_ARG",
"STORE_ATTR", "DELETE_ATTR", "STORE_GLOBAL", "DELETE_GLOBAL",
Expand All @@ -66,9 +70,16 @@ const char* Pyc::OpcodeName(int opcode)
"POP_JUMP_IF_FALSE", "POP_JUMP_IF_TRUE", "CONTINUE_LOOP", "MAKE_CLOSURE",
"LOAD_CLOSURE", "LOAD_DEREF", "STORE_DEREF", "DELETE_DEREF",
"EXTENDED_ARG", "SETUP_WITH", "SET_ADD", "MAP_ADD", "UNPACK_EX",
"LIST_APPEND", "LOAD_CLASSDEREF",
"LIST_APPEND", "LOAD_CLASSDEREF", "BUILD_LIST_UNPACK", "BUILD_MAP_UNPACK",
"BUILD_MAP_UNPACK_WITH_CALL", "BUILD_TUPLE_UNPACK", "BUILD_SET_UNPACK",
"SETUP_ASYNC_WITH",
};

#if __cplusplus >= 201103L
static_assert(sizeof(opcode_names) / sizeof(opcode_names[0]) == PYC_LAST_OPCODE,
"Pyc::OpcodeName opcode_names not in sync with opcode enum");
#endif

if (opcode < 0)
return "<INVALID>";

Expand Down Expand Up @@ -112,6 +123,7 @@ int Pyc::ByteToOpcode(int maj, int min, int opcode)
case 2: return python_32_map(opcode);
case 3: return python_33_map(opcode);
case 4: return python_34_map(opcode);
case 5: return python_35_map(opcode);
}
break;
}
Expand Down
10 changes: 7 additions & 3 deletions bytecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ enum Opcode {
INPLACE_MULTIPLY, INPLACE_DIVIDE, INPLACE_MODULO, INPLACE_POWER,
GET_ITER, PRINT_ITEM_TO, PRINT_NEWLINE_TO, INPLACE_LSHIFT,
INPLACE_RSHIFT, INPLACE_AND, INPLACE_XOR, INPLACE_OR, WITH_CLEANUP,
IMPORT_STAR, YIELD_VALUE, LOAD_BUILD_CLASS, STORE_LOCALS,
POP_EXCEPT, SET_ADD, YIELD_FROM,
WITH_CLEANUP_START, WITH_CLEANUP_FINISH, IMPORT_STAR, YIELD_VALUE,
LOAD_BUILD_CLASS, STORE_LOCALS, POP_EXCEPT, SET_ADD, YIELD_FROM,
BINARY_MATRIX_MULTIPLY, INPLACE_MATRIX_MULTIPLY, GET_AITER, GET_ANEXT,
BEFORE_ASYNC_WITH, GET_YIELD_FROM_ITER, GET_AWAITABLE,

/* Has parameter word */
PYC_HAVE_ARG,
Expand All @@ -42,7 +44,9 @@ enum Opcode {
POP_JUMP_IF_FALSE_A, POP_JUMP_IF_TRUE_A, CONTINUE_LOOP_A, MAKE_CLOSURE_A,
LOAD_CLOSURE_A, LOAD_DEREF_A, STORE_DEREF_A, DELETE_DEREF_A,
EXTENDED_ARG_A, SETUP_WITH_A, SET_ADD_A, MAP_ADD_A, UNPACK_EX_A,
LIST_APPEND_A, LOAD_CLASSDEREF_A,
LIST_APPEND_A, LOAD_CLASSDEREF_A, BUILD_LIST_UNPACK_A, BUILD_MAP_UNPACK_A,
BUILD_MAP_UNPACK_WITH_CALL_A, BUILD_TUPLE_UNPACK_A, BUILD_SET_UNPACK_A,
SETUP_ASYNC_WITH_A,

PYC_LAST_OPCODE,
PYC_INVALID_OPCODE = -1,
Expand Down
4 changes: 2 additions & 2 deletions bytes/comp_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
if not os.path.exists(sys.argv[2]):
os.mkdir(sys.argv[2])

maplist = [ 10, 11, 13, 14, 15, 16,
maplist = [ 10, 11, 13, 14, 15, 16,
20, 21, 22, 23, 24, 25, 26, 27,
30, 31, 32, 33, 34 ]
30, 31, 32, 33, 34, 35 ]

for mapver in maplist:
infile = open(os.path.join(sys.argv[1], 'python_%d.map' % mapver), 'rt')
Expand Down
3 changes: 3 additions & 0 deletions pyc_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ class PycCode : public PycObject {
CO_NESTED = 0x10,
CO_GENERATOR = 0x20,
CO_NOFREE = 0x40,
CO_COROUTINE = 0x80,
CO_ITERABLE_COROUTINE = 0x100,
CO_GENERATOR_ALLOWED = 0x1000,
CO_FUTURE_DIVISION = 0x2000,
CO_FUTURE_ABSOLUTE_IMPORT = 0x4000,
CO_FUTURE_WITH_STATEMENT = 0x8000,
CO_FUTURE_PRINT_FUNCTION = 0x10000,
CO_FUTURE_UNICODE_LITERALS = 0x20000,
CO_FUTURE_BARRY_AS_BDFL = 0x40000,
CO_FUTURE_GENERATOR_STOP = 0x80000,
};

PycCode(int type = TYPE_CODE)
Expand Down
6 changes: 6 additions & 0 deletions pyc_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ void PycModule::setVersion(unsigned int magic)
m_unicode = true;
break;

case MAGIC_3_5:
m_maj = 3;
m_min = 5;
m_unicode = true;
break;

/* Bad Magic detected */
default:
m_maj = -1;
Expand Down
1 change: 1 addition & 0 deletions pyc_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum PycMagic {
MAGIC_3_2 = 0x0A0D0C6C,
MAGIC_3_3 = 0x0A0D0C9E,
MAGIC_3_4 = 0x0A0D0CEE,
MAGIC_3_5 = 0x0A0D0D16,
};

#define PYC_VERSION(maj, min) MAGIC_##maj##_##min
Expand Down
13 changes: 7 additions & 6 deletions pycdas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@

static const char* flag_names[] = {
"CO_OPTIMIZED", "CO_NEWLOCALS", "CO_VARARGS", "CO_VARKEYWORDS",
"CO_NESTED", "CO_GENERATOR", "CO_NOFREE", "<0x80>", "<0x100>", "<0x200>",
"<0x400>", "<0x800>", "CO_GENERATOR_ALLOWED", "CO_FUTURE_DIVISION",
"CO_NESTED", "CO_GENERATOR", "CO_NOFREE", "CO_COROUTINE",
"CO_ITERABLE_COROUTINE", "<0x200>", "<0x400>", "<0x800>",
"CO_GENERATOR_ALLOWED", "CO_FUTURE_DIVISION",
"CO_FUTURE_ABSOLUTE_IMPORT", "CO_FUTURE_WITH_STATEMENT",
"CO_FUTURE_PRINT_FUNCTION", "CO_FUTURE_UNICODE_LITERALS",
"CO_FUTURE_BARRY_AS_BDFL", "<0x80000>", "<0x100000>", "<0x200000>",
"<0x400000>", "<0x800000>", "<0x1000000>", "<0x2000000>", "<0x4000000>",
"<0x8000000>", "<0x10000000>", "<0x20000000>", "<0x40000000>",
"<0x80000000>"
"CO_FUTURE_BARRY_AS_BDFL", "CO_FUTURE_GENERATOR_STOP",
"<0x100000>", "<0x200000>", "<0x400000>", "<0x800000>",
"<0x1000000>", "<0x2000000>", "<0x4000000>", "<0x8000000>",
"<0x10000000>", "<0x20000000>", "<0x40000000>", "<0x80000000>"
};

static void print_coflags(unsigned long flags)
Expand Down

0 comments on commit 5fae3e2

Please sign in to comment.