pycdc icon indicating copy to clipboard operation
pycdc copied to clipboard

Python 3.5: new opcodes for "with" statement unsupported (WITH_CLEANUP_START and _FINISH)

Open asmunder opened this issue 9 years ago • 2 comments

In Python 3.5 the opcode for WITH_CLEANUP is replaced by the pair of opcodes WITH_CLEANUP_START and WITH_CLEANUP_FINISH. This is to support async "with". These opcodes are not handled by pycdc, so the "with" statement compiled to bytecode with python 3.5 cannot be decompiled.

A quick and dirty solution is to add the following after the Pyc::WITH_CLEANUP block in ASTree.cpp. As the comment below says, this does not support async "with". In the case of not using async "with", the two opcodes will follow eachother immediately, and so should do the same as the old WITH_CLEANUP.

        case Pyc::WITH_CLEANUP_START:
            {
                // This is just a copy of the WITH_CLEANUP block
                // Stack top should be a None. Ignore it.
                PycRef<ASTNode> none = stack.top();
                stack.pop();

                if (none != Node_NULL) {
                    fprintf(stderr, "Something TERRIBLE happened!\n");
                    break;
                }

                if (curblock->blktype() == ASTBlock::BLK_WITH
                        && curblock->end() == curpos) {
                    PycRef<ASTBlock> with = curblock;
                    blocks.pop();
                    curblock = blocks.top();
                    curblock->append(with.cast<ASTNode>());
                }
                else {
                    fprintf(stderr, "Something TERRIBLE happened! No matching with block found for WITH_CLEANUP at %d\n", curpos);
                }
            }
            break;
        case Pyc::WITH_CLEANUP_FINISH:
            {
                // Do nothing. (This does not support async with.)
            }
            break;

asmunder avatar Nov 27 '15 09:11 asmunder

Also: pycdc just saved my day after an early morning git facepalm. Thank you all so much for this wonderful tool.

asmunder avatar Nov 27 '15 09:11 asmunder

@asmunder @zrax this work, but i get more problems with BUILD_CONST_KEY_MAP

geting this too # WARNING: Decompyle incomplete #172

MythodeaLoL avatar Feb 05 '20 07:02 MythodeaLoL

this issue can be closed also after this merge #460 @zrax

TiZCrocodile avatar Feb 29 '24 01:02 TiZCrocodile