Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytransform.PytransformError: Could not find "/myapp/app/platforms/android/armv7/_pytransform.so" #207

Closed
leond08 opened this issue Mar 17, 2020 · 25 comments

Comments

@leond08
Copy link

leond08 commented Mar 17, 2020

Hi i'm gettiing an error when i tried to run my obfuscated python script in my target machine

Target Machine:
Device: Raspberry PI 3B+
OS: Custom Embedded Linux by Buildroot

Build Machine:
OS: Ubuntu 18.04

Script run on my build machine:

PYTHONPATH=python3 pyarmor obfuscate --recursive --output ../myapp/app app/__init__.py --platform linux.armv7.3

I used linux.armv7.3 is it correct for my target machine or not?
I copied the obfuscated script in my target machine
The pytransform is included with _pytransform.so.
When I tried to run my python scripts i got an error _pytransform.so. File not Found

I tried your suggestion in the document :

from pytransform import _load_library
m = _load_library(path='/myapp/app')
Traceback (most recent call last):
File "", line 1, in
File "/myapp/app/pytransform/init.py", line 256, in _load_library
raise PytransformError('Could not find "%s"' % filename)
pytransform.PytransformError: Could not find "/myapp/app/platforms/android/armv7/_pytransform.so"

Got this error instead.
I don't have the platforms folder since this is the target machine. And why is the platform android/armv7

Thanks..

@leond08 leond08 changed the title pytransform.PytransformError: Could not find "/path/to/dist/platforms/android/armv7/_pytransform.so" pytransform.PytransformError: Could not find "/myapp/app/platforms/android/armv7/_pytransform.so" Mar 17, 2020
@jondy
Copy link
Contributor

jondy commented Mar 17, 2020

Try to use this platform --platform android.armv7 in the build command, this works for those platform without dynamic libc but static libc. If this platform not found as building, please upgrade pyarmor to latest version.

@leond08
Copy link
Author

leond08 commented Mar 17, 2020

i am currently using 5.9.3. I will try.

Thanks @jondy for the reply. I'll let you know.

@leond08
Copy link
Author

leond08 commented Mar 17, 2020

Hi @jondy,

>>INFO        Search library for platform: android.linux
>>ERROR    Unsupport platform android.linux
>>ERROR    No available library for this platform

I'am currently using the trial version since i would like to test it first on my current project
PyArmor Trial Version 5.9.3

@jondy
Copy link
Contributor

jondy commented Mar 17, 2020

Sorry, the platform name should be android.armv7

@leond08
Copy link
Author

leond08 commented Mar 17, 2020

Hi @jondy, same error

> app.pytransform.PytransformError: Load /myapp/app/pytransform/_pytransform.so failed:
> File not found

Here is the result of uname -a

Linux HOSTNAME 4.14.95-v7 #1 SMP Tue Mar 17 16:20:20 PST 2020 armv7l GNU/Linux

@jondy
Copy link
Contributor

jondy commented Mar 17, 2020

What's the output of following commands?

echo "" > a.c

# what I care about is the line starts with COLLECT_GCC_OPTIONS 
gcc -shared --verbose a.c

# The whole output of ldd
ldd a.out

@leond08
Copy link
Author

leond08 commented Mar 17, 2020

where should i run this in my build machine?

@jondy
Copy link
Contributor

jondy commented Mar 17, 2020

No, run it in the target machine. It's better to check the _pystransform.so by ldd either.

@leond08
Copy link
Author

leond08 commented Mar 17, 2020

Hi @jondy ,
I don't have gcc in my target machine,

but her is the gcc the buildroot using
./arm-buildroot-linux-uclibcgnueabihf-gcc -shared --verbose a.c

the result

COLLECT_GCC_OPTIONS='-shared' '-v' '-mcpu=cortex-a53' '-mfloat-abi=hard' '-mfpu=neon-vfpv4' '-mabi=aapcs-linux' '-marm' '-mtls-dialect=gnu'

@jondy
Copy link
Contributor

jondy commented Mar 17, 2020

I think the problem that the target machine uses uclibc, it need build new one for this platform. Where I could download this cross compile tool arm-buildroot-linux-uclibcgnueabihf-gcc?

@leond08
Copy link
Author

leond08 commented Mar 17, 2020

Here's the result

ldd _pytransform.so

checking sub-depends for 'not found'
libc.so.6 => not found (0x00000000)
not a dynamic executable

@leond08
Copy link
Author

leond08 commented Mar 17, 2020

Hi @jondy,

Not sure you can you can check https://buildroot.org/downloads/manual/manual.html#_cross_compilation_toolchain

Then you can use the available config of raspberrypi3_defconfig

@jondy
Copy link
Contributor

jondy commented Mar 17, 2020

Please download this new one
https://github.com/dashingsoft/pyarmor-core/raw/master/platforms/uclibc.armv7.0/_pytransform.so

Save it in the build machine "~/.pyarmor/platforms/android/armv7/0/_pytransform.so", then obfuscate the script with --platform android.armv7

If not work, check it in the target machine by ldd _pytransform.so

@leond08
Copy link
Author

leond08 commented Mar 17, 2020

Hi @jondy,

I saved the file and tried ldd _pytransform.so

same error

i used --platform android.armv7

INFO 17 scripts have been obfuscated
INFO Generating runtime files to ../myapp/app/pytransform
INFO Extract pytransform.key
INFO Extract license.lic
INFO Load platforms information from /home/falcon/.local/lib/python3.6/site-packages/pyarmor/platforms/index.json
INFO No dynamic library found for android.armv7 with features [7, 3]
INFO Load platforms information from /home/falcon/.local/lib/python3.6/site-packages/pyarmor/platforms/index.json
INFO Search library for platform: android.armv7
INFO Found available libraries: ['android.armv7.0']
INFO Downloading library file for android.armv7.0 ...
INFO Getting remote file: https://github.com/dashingsoft/pyarmor-core/raw/r16.10/platforms/android.armv7.0/_pytransform.so
INFO Writing target file: /home/falcon/.pyarmor/platforms/android/armv7/0/_pytransform.so
INFO Download dynamic library android.armv7.0 OK
ERROR No dynamic library found for android.armv7 with features [7, 3]

it downloaded again the file and overwrite the file i copied.

Thanks.

@jondy
Copy link
Contributor

jondy commented Mar 17, 2020

Only download this file to target machine
https://github.com/dashingsoft/pyarmor-core/raw/master/platforms/uclibc.armv7.0/_pytransform.so

Then run ldd _pytransform.so, what does it say?

@leond08
Copy link
Author

leond08 commented Mar 18, 2020

Hi jondy,

ldd _pytransform.so

checking sub-depends for '/lib/libc.so.0'
ld-uClibc.so.1 => /lib/ld-uClibc.so.1 (0x76f82000)
libc.so.0 => /lib/libc.so.0 (0x00000000)
/lib/ld-uClibc.so.1 => /lib/ld-uClibc.so.1 (0x00000000)

I didn't get an error now

@jondy
Copy link
Contributor

jondy commented Mar 18, 2020

In build machine, first download this file, save it to any path, for example /home/falcon/.pyarmor/uclibc/_pytransform.so, then specify the platform as absolute path instead of name, it will not be overwritten. For example,

PYARMOR_PLATFORM=linux.x86_64.0 pyarmor obfuscate --platform /home/falcon/.pyarmor/uclibc/_pytransform.so ...

Note that PYARMOR_PLATFORM should be set for this platform, refer to
https://pyarmor.readthedocs.io/en/latest/advanced.html#obfuscating-scripts-with-different-features

@leond08
Copy link
Author

leond08 commented Mar 18, 2020

Hi @jondy,

Got an error:

Script:

PYTHONPATH=python3.7 PYARMOR_PLATFORM=linux.x86_64.0 pyarmor -d obfuscate --recursive --platform /home/falcon/.pyarmor/platforms/linux/uclibc/ --output ../myapp/app app/init.py

Traceback (most recent call last):
  File "/home/falcon/.local/bin/pyarmor", line 11, in <module>
    sys.exit(main_entry())
  File "/home/falcon/.local/lib/python3.6/site-packages/pyarmor/pyarmor.py", line 1241, in main_entry
    main(sys.argv[1:])
  File "/home/falcon/.local/lib/python3.6/site-packages/pyarmor/pyarmor.py", line 1233, in main
    args.func(args)
  File "/home/falcon/.local/lib/python3.6/site-packages/pyarmor/pyarmor.py", line 629, in _obfuscate
    package=package, suffix=suffix)
  File "/home/falcon/.local/lib/python3.6/site-packages/pyarmor/utils.py", line 499, in make_runtime
    filename = _build_platforms(platforms, restrict)[0]
  File "/home/falcon/.local/lib/python3.6/site-packages/pyarmor/utils.py", line 433, in _build_platforms
    filename = _get_platform_library_filename(platid, features)
  File "/home/falcon/.local/lib/python3.6/site-packages/pyarmor/utils.py", line 413, in _get_platform_library_filename
    n = int(path[-1])
ValueError: invalid literal for int() with base 10: '/'

@jondy
Copy link
Contributor

jondy commented Mar 18, 2020

Create an extra path 0, and move this file here, for example, /home/falcon/.pyarmor/uclibc/0/_pytransform.so. The last path must be feature number.

@leond08
Copy link
Author

leond08 commented Mar 18, 2020

Hi @jondy,

> /usr/bin/python3.7: symbol '__ctype_b_loc': can't resolve symbol

Traceback (most recent call last):
File "/myapp/app/pytransform/init.py", line 259, in _load_library
m = cdll.LoadLibrary(filename)
File "/usr/lib/python3.7/ctypes/init.py", line 434, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python3.7/ctypes/init.py", line 356, in init
self._handle = _dlopen(self._name, mode)
OSError: dlopen() error

Got this error now:

I used same version of python with my build machine and target machine
Python Version: 3.7.2

@jondy
Copy link
Contributor

jondy commented Mar 18, 2020

It seems the uclibc in the target machine misses this function __ctype_b_loc, one solution is rebuild your uclibc with this function, the other solution is to rebuild _pytransform.so with some other options to remove this dependency if possible.

@leond08
Copy link
Author

leond08 commented Mar 18, 2020

Hi @jondy,

Can you rebuild the _pytransform.so to remove this dependency?

@leond08
Copy link
Author

leond08 commented Mar 18, 2020

Hi @jondy,

I rebuild my uclibc, it work now. Thanks a lot!

@leond08
Copy link
Author

leond08 commented Mar 18, 2020

Hi @jondy,

i got an error running this:

Python 3.7.2 (default, Mar 18 2020, 12:43:35)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

from pytransform import get_license_info
m = get_license_info()
Traceback (most recent call last):
File "", line 1, in
File "/myapp/app/pytransform/init.py", line 148, in get_license_info
rcode = get_registration_code().decode()
File "/myapp/app/pytransform/init.py", line 55, in wrap
return func(*args, **kwargs)
File "/myapp/app/pytransform/init.py", line 115, in get_registration_code
dlfunc = prototype(('get_registration_code', _pytransform))
AttributeError: 'NoneType' object has no attribute '_handle'

@jondy
Copy link
Contributor

jondy commented Mar 18, 2020

This function should be called in the obfuscated scripts. If just debug in the plain script, call pyarmor_init at frist. For example,

from pytransform import pyarmor_init
pyarmor_init()
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants