From 146cd01f35feca0b081765d9543d6a530ac1e292 Mon Sep 17 00:00:00 2001 From: Lil-Ran Date: Sat, 13 Sep 2025 16:25:46 +0800 Subject: [PATCH] fix: opcode stores for PyarmorAssert bytes type 4 --- pycdc/ASTree.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/pycdc/ASTree.cpp b/pycdc/ASTree.cpp index c222d88..0e488db 100644 --- a/pycdc/ASTree.cpp +++ b/pycdc/ASTree.cpp @@ -2394,6 +2394,19 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) if (seq.type() == ASTNode::NODE_CHAINSTORE) { append_to_chain_store(seq, tup, stack, curblock); + // BEGIN ONESHOT TEMPORARY PATCH + } else if (seq.type() == ASTNode::NODE_IMPORT) { + // This node is generated when handling PyarmorAssert bytes type 4 + auto import = seq.try_cast(); + auto fromlist_tuple = import->fromlist().try_cast()->values(); + auto store_tuple = tup.try_cast()->values(); + auto real_import = new ASTImport(import->name(), nullptr); + for (size_t i = 0; i < fromlist_tuple.size() && i < store_tuple.size(); i++) + { + real_import->add_store(new ASTStore(fromlist_tuple[i], store_tuple[i])); + } + curblock->append(real_import); + // END ONESHOT PATCH } else { curblock->append(new ASTStore(seq, tup)); } @@ -2441,6 +2454,19 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) curblock.cast()->setIndex(tup); } else if (seq.type() == ASTNode::NODE_CHAINSTORE) { append_to_chain_store(seq, tup, stack, curblock); + // BEGIN ONESHOT TEMPORARY PATCH + } else if (seq.type() == ASTNode::NODE_IMPORT) { + // This node is generated when handling PyarmorAssert bytes type 4 + auto import = seq.try_cast(); + auto fromlist_tuple = import->fromlist().try_cast()->values(); + auto store_tuple = tup.try_cast()->values(); + auto real_import = new ASTImport(import->name(), nullptr); + for (size_t i = 0; i < fromlist_tuple.size() && i < store_tuple.size(); i++) + { + real_import->add_store(new ASTStore(fromlist_tuple[i], store_tuple[i])); + } + curblock->append(real_import); + // END ONESHOT PATCH } else { curblock->append(new ASTStore(seq, tup)); } @@ -2501,6 +2527,19 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) curblock.cast()->setIndex(tup); } else if (seq.type() == ASTNode::NODE_CHAINSTORE) { append_to_chain_store(seq, tup, stack, curblock); + // BEGIN ONESHOT TEMPORARY PATCH + } else if (seq.type() == ASTNode::NODE_IMPORT) { + // This node is generated when handling PyarmorAssert bytes type 4 + auto import = seq.try_cast(); + auto fromlist_tuple = import->fromlist().try_cast()->values(); + auto store_tuple = tup.try_cast()->values(); + auto real_import = new ASTImport(import->name(), nullptr); + for (size_t i = 0; i < fromlist_tuple.size() && i < store_tuple.size(); i++) + { + real_import->add_store(new ASTStore(fromlist_tuple[i], store_tuple[i])); + } + curblock->append(real_import); + // END ONESHOT PATCH } else { curblock->append(new ASTStore(seq, tup)); } @@ -2544,6 +2583,7 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) curblock.cast()->setIndex(tup); } else if (seq.type() == ASTNode::NODE_CHAINSTORE) { append_to_chain_store(seq, tup, stack, curblock); + // BEGIN ONESHOT TEMPORARY PATCH } else if (seq.type() == ASTNode::NODE_IMPORT) { // This node is generated when handling PyarmorAssert bytes type 4 auto import = seq.try_cast(); @@ -2555,6 +2595,7 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) real_import->add_store(new ASTStore(fromlist_tuple[i], store_tuple[i])); } curblock->append(real_import); + // END ONESHOT PATCH } else { curblock->append(new ASTStore(seq, tup)); }