zrax / pycdc

C++ python bytecode disassembler and decompiler
GNU General Public License v3.0
3.38k stars 647 forks source link

Trying to decompile opcode PUSH_EXC_INFO failed #519

Open 1wxyz opened 2 months ago

1wxyz commented 2 months ago

Trying to implement opcode PUSH_EXC_INFO with the notes from https://docs.python.org/3/library/dis.html#opcode-PUSH_EXC_INFO

case Pyc::PUSH_EXC_INFO:
            {
                PycRef<ASTNode> popped = stack.top();
                stack.pop();

                PycRef<ASTBlock> except = new ASTCondBlock(ASTBlock::BLK_EXCEPT, 0, NULL, false);
                except->init();
                stack.push(except.cast<ASTNode>());
                stack.push(popped);
            }
            break;

Based on the code above, I was trying to implement: 'Pushes the current exception to the top of the stack. ', which ended up with Segmentation fault (core dumped).

When I change stack.push(except.cast<ASTNode>()); to blocks.push(except); , it gives this error: Error decompyling file.pyc: vector::_M_range_check: __n (which is 3) >= this->size() (which is 2)

Not sure what is the correct way to write in pycdc. Thanks for any advise given in advance.