From dc5d2b95e02bee1b82244286291eae67bd42c037 Mon Sep 17 00:00:00 2001 From: Lil-Ran Date: Wed, 5 Mar 2025 20:07:46 +0800 Subject: [PATCH] fix: py3.11 limited support --- ASTree.cpp | 55 +++++++++++++++++++++++++++++++++++++++---------- helpers/shot.py | 7 +++++-- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/ASTree.cpp b/ASTree.cpp index 2d84e35..952cbe4 100644 --- a/ASTree.cpp +++ b/ASTree.cpp @@ -765,6 +765,10 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) stack.pop(); PycRef func = stack.top(); stack.pop(); + if (stack.top() == nullptr) + { + stack.pop(); + } PycRef call = new ASTCall(func, ASTCall::pparam_t(), ASTCall::kwparam_t()); if (operand & 0x01) @@ -1560,7 +1564,8 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) blocks.push(except); } } else { - fprintf(stderr, "Something TERRIBLE happened!!\n"); + fprintf(stderr, "Something TERRIBLE happened!! at %s\n", + mod->verCompare(3, 11) >= 0 ? code->qualName()->value() : code->name()->value()); } prev = nil; } else { @@ -1792,7 +1797,8 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) stack = stack_hist.top(); stack_hist.pop(); } else { - fprintf(stderr, "Warning: Stack history is empty, something wrong might have happened\n"); + fprintf(stderr, "Warning: Stack history is empty, something wrong might have happened at %s\n", + mod->verCompare(3, 11) >= 0 ? code->qualName()->value() : code->name()->value()); } } PycRef tmp = curblock; @@ -2076,7 +2082,8 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) stack.pop(); if (none != NULL) { - fprintf(stderr, "Something TERRIBLE happened!\n"); + fprintf(stderr, "Something TERRIBLE happened! at %s\n", + mod->verCompare(3, 11) >= 0 ? code->qualName()->value() : code->name()->value()); break; } @@ -2184,7 +2191,8 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) if (tup.type() == ASTNode::NODE_TUPLE) tup.cast()->add(attr); else - fputs("Something TERRIBLE happened!\n", stderr); + fprintf(stderr, "Something TERRIBLE happened! at %s\n", + mod->verCompare(3, 11) >= 0 ? code->qualName()->value() : code->name()->value()); if (--unpack <= 0) { stack.pop(); @@ -2219,7 +2227,8 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) if (tup.type() == ASTNode::NODE_TUPLE) tup.cast()->add(name); else - fputs("Something TERRIBLE happened!\n", stderr); + fprintf(stderr, "Something TERRIBLE happened! at %s\n", + mod->verCompare(3, 11) >= 0 ? code->qualName()->value() : code->name()->value()); if (--unpack <= 0) { stack.pop(); @@ -2259,7 +2268,8 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) if (tup.type() == ASTNode::NODE_TUPLE) tup.cast()->add(name); else - fputs("Something TERRIBLE happened!\n", stderr); + fprintf(stderr, "Something TERRIBLE happened! at %s\n", + mod->verCompare(3, 11) >= 0 ? code->qualName()->value() : code->name()->value()); if (--unpack <= 0) { stack.pop(); @@ -2318,7 +2328,8 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) if (tup.type() == ASTNode::NODE_TUPLE) tup.cast()->add(name); else - fputs("Something TERRIBLE happened!\n", stderr); + fprintf(stderr, "Something TERRIBLE happened! at %s\n", + mod->verCompare(3, 11) >= 0 ? code->qualName()->value() : code->name()->value()); if (--unpack <= 0) { stack.pop(); @@ -2360,7 +2371,8 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) if (tup.type() == ASTNode::NODE_TUPLE) tup.cast()->add(name); else - fputs("Something TERRIBLE happened!\n", stderr); + fprintf(stderr, "Something TERRIBLE happened! at %s\n", + mod->verCompare(3, 11) >= 0 ? code->qualName()->value() : code->name()->value()); if (--unpack <= 0) { stack.pop(); @@ -2481,7 +2493,8 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) if (tup.type() == ASTNode::NODE_TUPLE) tup.cast()->add(save); else - fputs("Something TERRIBLE happened!\n", stderr); + fprintf(stderr, "Something TERRIBLE happened! at %s\n", + mod->verCompare(3, 11) >= 0 ? code->qualName()->value() : code->name()->value()); if (--unpack <= 0) { stack.pop(); @@ -2661,6 +2674,24 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) break; // BEGIN ONESHOT TEMPORARY PATCH // These opcodes are not implemented + case Pyc::COPY_A: + { + FastStack tmp_stack(20); + for (int i = 0; i < operand - 1; i++) { + tmp_stack.push(stack.top()); + stack.pop(); + } + auto value = stack.top(); + for (int i = 0; i < operand - 1; i++) { + stack.push(tmp_stack.top()); + tmp_stack.pop(); + } + stack.push(value); + } + case Pyc::PUSH_EXC_INFO: + { + stack.push(stack.top()); + } case Pyc::JUMP_IF_NOT_EXC_MATCH_A: { PycRef ex_type = stack.top(); @@ -2688,7 +2719,8 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) } if (stack_hist.size()) { - fputs("Warning: Stack history is not empty!\n", stderr); + fprintf(stderr, "Warning: Stack history is not empty! at %s\n", + mod->verCompare(3, 11) >= 0 ? code->qualName()->value() : code->name()->value()); while (stack_hist.size()) { stack_hist.pop(); @@ -2696,7 +2728,8 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) } if (blocks.size() > 1) { - fputs("Warning: block stack is not empty!\n", stderr); + fprintf(stderr, "Warning: block stack is not empty! at %s\n", + mod->verCompare(3, 11) >= 0 ? code->qualName()->value() : code->name()->value()); while (blocks.size() > 1) { PycRef tmp = blocks.top(); diff --git a/helpers/shot.py b/helpers/shot.py index eba85b7..5d98d31 100644 --- a/helpers/shot.py +++ b/helpers/shot.py @@ -66,14 +66,17 @@ def decrypt_process(runtimes: Dict[str, RuntimeInfo], sequences: List[Tuple[str, for line in stderr: if line.startswith(( 'Warning: Stack history is empty', - 'Warning: Stack history is not empty!', - 'Warning: block stack is not empty!', + 'Warning: Stack history is not empty', + 'Warning: block stack is not empty', )): if args.show_warn_stack or args.show_all: logger.warning(f'PYCDC: {line} ({path})') elif line.startswith('Unsupported opcode:'): if args.show_err_opcode or args.show_all: logger.error(f'PYCDC: {line} ({path})') + elif line.startswith('Something TERRIBLE happened'): + if args.show_all: + logger.error(f'PYCDC: {line} ({path})') else: logger.error(f'PYCDC: {line} ({path})') if sp.returncode != 0: