3 Commits

2 changed files with 52 additions and 16 deletions

View File

@@ -320,27 +320,25 @@ def get_platform_executable(specified: str) -> str:
) )
return arch_exe_path return arch_exe_path
# Allow ".elf" and ".macho" suffixes, so that they can exist in the same folder
platform_map = { platform_map = {
"windows": "pyarmor-1shot.exe", "windows": ["pyarmor-1shot.exe", "pyarmor-1shot"],
"linux": "pyarmor-1shot", "linux": ["pyarmor-1shot", "pyarmor-1shot.elf"],
"darwin": "pyarmor-1shot", "darwin": ["pyarmor-1shot", "pyarmor-1shot.macho"],
} }
base_exe_name = platform_map.get(system, "pyarmor-1shot")
# Then check for platform-specific executable # Then check for platform-specific executable
platform_exe_path = os.path.join(oneshot_dir, base_exe_name) for base_exe_name in platform_map.get(system, ["pyarmor-1shot"]):
if os.path.exists(platform_exe_path): platform_exe_path = os.path.join(oneshot_dir, base_exe_name)
logger.info(f"{Fore.GREEN}Using executable: {base_exe_name}{Style.RESET_ALL}") if os.path.exists(platform_exe_path):
return platform_exe_path logger.info(
f"{Fore.GREEN}Using executable: {base_exe_name}{Style.RESET_ALL}"
# Finally, check for generic executable )
generic_exe_path = os.path.join(oneshot_dir, "pyarmor-1shot") return platform_exe_path
if os.path.exists(generic_exe_path):
logger.info(f"{Fore.GREEN}Using executable: pyarmor-1shot{Style.RESET_ALL}")
return generic_exe_path
platform_default = platform_map.get(system, ["pyarmor-1shot"])[0]
logger.critical( logger.critical(
f"{Fore.RED}Executable {base_exe_name} not found, please build it first or download on https://github.com/Lil-House/Pyarmor-Static-Unpack-1shot/releases {Style.RESET_ALL}" f"{Fore.RED}Executable {platform_default} not found, please build it first or download on https://github.com/Lil-House/Pyarmor-Static-Unpack-1shot/releases {Style.RESET_ALL}"
) )
exit(1) exit(1)

View File

@@ -267,6 +267,11 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
bool need_try = false; bool need_try = false;
bool variable_annotations = false; bool variable_annotations = false;
// BEGIN ONESHOT TEMPORARY PATCH
// For Pyarmor generated `NOP; JUMP_FORWARD` sequences
bool last_is_nop = false;
// END ONESHOT PATCH
while (!source.atEof()) { while (!source.atEof()) {
#if defined(BLOCK_DEBUG) || defined(STACK_DEBUG) #if defined(BLOCK_DEBUG) || defined(STACK_DEBUG)
fprintf(stderr, "%-7d", pos); fprintf(stderr, "%-7d", pos);
@@ -333,6 +338,33 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
} }
} }
// BEGIN ONESHOT TEMPORARY PATCH
// For Pyarmor generated `NOP; JUMP_FORWARD` sequences
if (last_is_nop && opcode == Pyc::JUMP_FORWARD_A) {
int offs = operand;
if (mod->verCompare(3, 10) >= 0)
offs *= sizeof(uint16_t);
// If destination is a:
// LOAD_CONST '__pyarmor_exit_N__'
// Then change JUMP_FORWARD to RETURN_VALUE
const char* code_bytes = code->code()->value();
for (int i = 0; i < 10; i += 2) {
if (pos + offs + i + 1 >= code->code()->length())
break;
int tested_opcode = Pyc::ByteToOpcode(mod->majorVer(), mod->minorVer(), code_bytes[pos + offs + i]);
if (tested_opcode == Pyc::LOAD_CONST_A) {
unsigned char tested_operand = code_bytes[pos + offs + i + 1];
auto str = code->getConst(tested_operand).try_cast<PycString>();
if (str != nullptr && str->startsWith("__pyarmor_exit_")) {
opcode = Pyc::RETURN_VALUE;
break;
}
}
}
}
// END ONESHOT PATCH
switch (opcode) { switch (opcode) {
case Pyc::BINARY_OP_A: case Pyc::BINARY_OP_A:
{ {
@@ -2164,7 +2196,9 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
curblock = blocks.top(); curblock = blocks.top();
curblock->append(prev.cast<ASTNode>()); curblock->append(prev.cast<ASTNode>());
bc_next(source, mod, opcode, operand, pos); // BEGIN ONESHOT TEMPORARY PATCH
// bc_next(source, mod, opcode, operand, pos);
// END ONESHOT PATCH
} }
} }
break; break;
@@ -3002,6 +3036,10 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
|| (curblock->blktype() == ASTBlock::BLK_IF) || (curblock->blktype() == ASTBlock::BLK_IF)
|| (curblock->blktype() == ASTBlock::BLK_ELIF) ) || (curblock->blktype() == ASTBlock::BLK_ELIF) )
&& (curblock->end() == pos); && (curblock->end() == pos);
// BEGIN ONESHOT TEMPORARY PATCH
last_is_nop = (opcode == Pyc::NOP);
// END ONESHOT PATCH
} }
if (stack_hist.size()) { if (stack_hist.size()) {