4 Commits

3 changed files with 54 additions and 18 deletions

View File

@@ -320,27 +320,25 @@ def get_platform_executable(specified: str) -> str:
)
return arch_exe_path
# Allow ".elf" and ".macho" suffixes, so that they can exist in the same folder
platform_map = {
"windows": "pyarmor-1shot.exe",
"linux": "pyarmor-1shot",
"darwin": "pyarmor-1shot",
"windows": ["pyarmor-1shot.exe", "pyarmor-1shot"],
"linux": ["pyarmor-1shot", "pyarmor-1shot.elf"],
"darwin": ["pyarmor-1shot", "pyarmor-1shot.macho"],
}
base_exe_name = platform_map.get(system, "pyarmor-1shot")
# Then check for platform-specific executable
platform_exe_path = os.path.join(oneshot_dir, base_exe_name)
if os.path.exists(platform_exe_path):
logger.info(f"{Fore.GREEN}Using executable: {base_exe_name}{Style.RESET_ALL}")
return platform_exe_path
# Finally, check for generic executable
generic_exe_path = os.path.join(oneshot_dir, "pyarmor-1shot")
if os.path.exists(generic_exe_path):
logger.info(f"{Fore.GREEN}Using executable: pyarmor-1shot{Style.RESET_ALL}")
return generic_exe_path
for base_exe_name in platform_map.get(system, ["pyarmor-1shot"]):
platform_exe_path = os.path.join(oneshot_dir, base_exe_name)
if os.path.exists(platform_exe_path):
logger.info(
f"{Fore.GREEN}Using executable: {base_exe_name}{Style.RESET_ALL}"
)
return platform_exe_path
platform_default = platform_map.get(system, ["pyarmor-1shot"])[0]
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)
@@ -424,7 +422,7 @@ def main():
| | |_| \_, |\__,_|_| |_||_||_|\___/|_| |_|___/|_||_|\___/ \__| | |
| | |__/ | |
|__|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|__|
(____) v0.2.1+ (____)
(____) v0.2.2 (____)
For technology exchange only. Use at your own risk.
GitHub: https://github.com/Lil-House/Pyarmor-Static-Unpack-1shot

View File

@@ -267,6 +267,11 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
bool need_try = 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()) {
#if defined(BLOCK_DEBUG) || defined(STACK_DEBUG)
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
auto code_bytes = (const unsigned char*)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) {
case Pyc::BINARY_OP_A:
{
@@ -2164,7 +2196,9 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
curblock = blocks.top();
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;
@@ -3002,6 +3036,10 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
|| (curblock->blktype() == ASTBlock::BLK_IF)
|| (curblock->blktype() == ASTBlock::BLK_ELIF) )
&& (curblock->end() == pos);
// BEGIN ONESHOT TEMPORARY PATCH
last_is_nop = (opcode == Pyc::NOP);
// END ONESHOT PATCH
}
if (stack_hist.size()) {

View File

@@ -23,7 +23,7 @@
#include "ASTree.h"
const char* VERSION = "v0.2.1+";
const char* VERSION = "v0.2.2";
#ifdef _WIN32