2 Commits
v0.2.0 ... main

Author SHA1 Message Date
e892da34cf fix: check output_dir is dir 2025-09-19 20:02:24 +08:00
146cd01f35 fix: opcode stores for PyarmorAssert bytes type 4 2025-09-13 16:25:46 +08:00
2 changed files with 45 additions and 0 deletions

View File

@@ -309,6 +309,10 @@ def main():
if args.output_dir and not os.path.exists(args.output_dir):
os.makedirs(args.output_dir)
if args.output_dir and not os.path.isdir(args.output_dir):
logger.error(f'{Fore.RED}Cannot use {repr(args.output_dir)} as output directory{Style.RESET_ALL}')
return
if os.path.isfile(args.directory):
if specified_runtime is None:
logger.error(f'{Fore.RED}Please specify `pyarmor_runtime` file by `-r` if input is a file{Style.RESET_ALL}')

View File

@@ -2394,6 +2394,19 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> 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<ASTImport>();
auto fromlist_tuple = import->fromlist().try_cast<ASTTuple>()->values();
auto store_tuple = tup.try_cast<ASTTuple>()->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<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
curblock.cast<ASTIterBlock>()->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<ASTImport>();
auto fromlist_tuple = import->fromlist().try_cast<ASTTuple>()->values();
auto store_tuple = tup.try_cast<ASTTuple>()->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<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
curblock.cast<ASTIterBlock>()->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<ASTImport>();
auto fromlist_tuple = import->fromlist().try_cast<ASTTuple>()->values();
auto store_tuple = tup.try_cast<ASTTuple>()->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<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
curblock.cast<ASTIterBlock>()->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<ASTImport>();
@@ -2555,6 +2595,7 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> 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));
}