dashingsoft / pyarmor

A tool used to obfuscate python scripts, bind obfuscated scripts to fixed machine or expire obfuscated scripts.
http://pyarmor.dashingsoft.com
Other
3.25k stars 277 forks source link

[BUG] `simple function encrypted with BCC crash on Windows after X variable declarations, but works on Linux` #1876

Closed cedrik31tlse closed 1 month ago

cedrik31tlse commented 1 month ago

This script, when encrypted with --enable-bcc, is not working on Windows x64. (Program crash without any Traceball) Tested on Linux = script BCC encoded is working well. but if you comment some variables declarations so there is not too much variables, then the script is working on Windows too.

venv python windows 3.9.9 command : pyarmor -d gen --enable-bcc test.py

import time

def main():

    try:

        print("BEGIN")
        check()
        print("END")

    except Exception as e:
        print(e)

def check() :

    try:

        #while True:

            print("checkpoint1")

            hash_nbactiv1 = "test"
            hash_nbactiv2 = "test"
            hash_nbactiv3 = "test"
            hash_nbactiv4 = "test"
            hash_nbactiv5 = "test"
            hash_nbactiv6 = "test"
            hash_nbactiv7 = "test"
            hash_nbactiv8 = "test"
            hash_nbactiv9 = "test"
            hash_nbactiv10 = "test"
            hash_nbactiv11 = "test"
            hash_nbactiv12 = "test"
            hash_nbactiv13 = "test"
            hash_nbactiv14 = "test"
            hash_nbactiv15 = "test"
            hash_nbactiv16 = "test"
            hash_nbactiv17 = "test"
            hash_nbactiv18 = "test"
            hash_nbactiv19 = "test"
            hash_nbactiv20 = "test"
            hash_nbactiv21 = "test"
            hash_nbactiv22 = "test"
            hash_nbactiv23 = "test"
            hash_nbactiv24 = "test"
            hash_nbactiv25 = "test"
            hash_nbactiv26 = "test"
            hash_nbactiv27 = "test"
            hash_nbactiv28 = "test"
            hash_nbactiv29 = "test"
            hash_nbactiv30 = "test"

            print("checkpoint2")           

            time.sleep(5)

    except Exception as e:
        print(e)

if __name__ == "__main__":

        main()
jondy commented 1 month ago

Please report Python version, pyarmor version and full command line

If python version is 3.12.0, try to upgrade the latest minor version 3.12.x

cedrik31tlse commented 1 month ago

i updated the post to include python version and command.

also i join here the debug file :

2024-07-21 14:07:54,916 Python 3.9.9
2024-07-21 14:07:54,926 Pyarmor 8.5.10 (pro), 005805, COYOTE BOTS
2024-07-21 14:07:54,973 Platform windows.x86_64
2024-07-21 14:07:54,973 native platform windows.amd64
2024-07-21 14:07:54,973 home path: C:\Users\Cedric\.pyarmor
2024-07-21 14:07:54,975 command options: {'no_runtime': False, 'enable_bcc': True, 'inputs': ['test.py']}
2024-07-21 14:07:54,975 install plugin: CodesignPlugin
2024-07-21 14:07:54,976 install plugin: DarwinUniversalPlugin
2024-07-21 14:07:54,976 search inputs ...
2024-07-21 14:07:54,977 find script test.py
2024-07-21 14:07:54,978 find 1 top resources
2024-07-21 14:07:55,150 start to generate runtime files
2024-07-21 14:07:55,152 target platforms {'windows.amd64'}
2024-07-21 14:07:55,193 got c:\myenvv\lib\site-packages\pyarmor\cli\core\pyarmor_runtime.pyd
2024-07-21 14:07:55,193 write dist\pyarmor_runtime_005805\pyarmor_runtime.pyd
2024-07-21 14:07:55,195 patching runtime data at 529440
2024-07-21 14:07:55,197 patch runtime file OK
2024-07-21 14:07:55,198 call post runtime plugin <class 'pyarmor.cli.plugin.CodesignPlugin'>
2024-07-21 14:07:55,199 generate runtime files OK
2024-07-21 14:07:55,200 start to obfuscate scripts
2024-07-21 14:07:55,201 process resource "test"
2024-07-21 14:07:55,202 obfuscating file test.py
2024-07-21 14:07:55,218 process inline marker
2024-07-21 14:07:55,218 parse script
2024-07-21 14:07:55,266 start to generate bcc code ...
2024-07-21 14:07:55,270 c sources has been patched by plugin
2024-07-21 14:07:55,270 CC: clang.exe
2024-07-21 14:07:55,530 cflags: -O3 -Wno-unsequenced -fno-asynchronous-unwind-tables -fno-unwind-tables --target=x86_64-elf-windows -c
2024-07-21 14:07:56,180 generate bcc code successfully
2024-07-21 14:07:56,181 process co
2024-07-21 14:07:56,183 patch bcc
2024-07-21 14:07:56,186 patch co
2024-07-21 14:07:56,197 write dist\test.py
2024-07-21 14:07:56,200 obfuscate scripts OK
2024-07-21 14:07:56,201 call post build plugin <class 'pyarmor.cli.plugin.DarwinUniversalPlugin'>

if we launch the script, it will print BEGIN then crash as the screenshot below. the function check() doesnt run at all. I also tested without the try except, same result.

image

But if we remove a few variable declarations, then the script run OK.

jondy commented 1 month ago

Reproduced it, I'll check it.

jondy commented 1 month ago

This bug will be fixed in next release.

As a quick workaround, run this command to add extra cflags -DENABLE_BCC_MEMSET, for example

pyarmor cfg windows.x86_64.bcc:cflags=" -O3 -Wno-unsequenced -fno-asynchronous-unwind-tables -fno-unwind-tables --target=x86_64-elf-windows -c -DENABLE_BCC_MEMSET"

Then obfuscate the script again

cedrik31tlse commented 1 month ago

it's working, thank you ! I also tested on my real program with all obfuscations enabled, and it's working too.

Thank you !

jondy commented 1 month ago

Fixed in 8.5.11