pyarmor icon indicating copy to clipboard operation
pyarmor copied to clipboard

Illegal operations on a Raspberry Pi Zero W (ARMv6)

Open shedstrom opened this issue 4 years ago • 18 comments

Describe the bug Using a Raspberry pi zero (armv6) most commands will fail with "Illegal instruction" and terminate.

To Reproduce

  1. Running latest pyarmor from pip using the trial version on a Raspberry Pi Zero W running Raspbian 10 (buster) and python 3.7.3
  2. Commands used obfuscate, pack, download, hdinfo and -v
  3. Manually downloading armv6.0 and replacing the .3 version works Output from trying to obfuscate main.py
pyarmor -d obfuscate main.py
DEBUG    PyArmor installation path: /home/pi/.local/lib/python3.7/site-packages/pyarmor
DEBUG    PyArmor home path: /home/pi/.pyarmor
DEBUG    Native platform is linux.armv6
DEBUG    Search dynamic library in the path: /home/pi/.local/lib/python3.7/site-packages/pyarmor/platforms
DEBUG    Search dynamic library in the path: /home/pi/.pyarmor/platforms
DEBUG    Found available dynamic library linux/armv6/3
Illegal instruction

Additional context Tested on a Windows machine and had no problem running the pack option with our .spec file

shedstrom avatar Mar 10 '21 13:03 shedstrom

I seems there is something wrong with linux.armv6.3, I'll check it.

Since linux.armv6.0 works, now use it by exporting environment variable PYARMOR_PLATFORM=linux.armv6.0

jondy avatar Mar 10 '21 13:03 jondy

I rebuild linux.armv6.3, it may fix this issue, it has been packaged into the dev version https://pyarmor.readthedocs.io/en/latest/change-logs.html#dev-version

jondy avatar Mar 11 '21 00:03 jondy

For trial version, after v6.6.2, the latest extra platforms are not available to download.

I have uploaded the temporary one to https://pyarmor.dashingsoft.com/downloads/temp/_pytrasnform.so

Download it, then save it to /home/pi/.local/lib/python3.7/site-packages/pyarmor/platforms/linux/armv6

jondy avatar Mar 11 '21 05:03 jondy

I'm afraid it didn't work. We tested it on 2 Pi Zeros following your instructions and we still got "Illegal instruction"

shedstrom avatar Mar 11 '21 11:03 shedstrom

First make sure it's the latest one is loaded, run pyarmor -d obfuscate foo.py, the output log will print which _pytrasnfrom.so is loaded.

And check this file by ldd

ldd /home/pi/.local/lib/python3.7/site-packages/pyarmor/platforms/linux/armv6/_pytransform.so

What's the output of uname -a?

jondy avatar Mar 11 '21 12:03 jondy

Obfuscate output :

pi@raspberrypi:~/PerkinElmer/Source $ pyarmor -d obfuscate main.py
DEBUG    PyArmor installation path: /home/pi/.local/lib/python3.7/site-packages/pyarmor
DEBUG    PyArmor home path: /home/pi/.pyarmor
DEBUG    Native platform is linux.armv6
DEBUG    Search dynamic library in the path: /home/pi/.local/lib/python3.7/site-packages/pyarmor/platforms
Illegal instruction

ldd output:

pi@raspberrypi:~/PerkinElmer/Source $ ldd /home/pi/.local/lib/python3.7/site-packages/pyarmor/platforms/linux/armv6/_pytransform.so 
	/usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so => /usr/lib/arm-linux-gnueabihf/libarmmem-v6l.so (0xb6d69000)
	libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6c02000)
	/lib/ld-linux-armhf.so.3 (0xb6f94000)

uname:

pi@raspberrypi:~/PerkinElmer/Source $ uname -a
Linux raspberrypi 5.10.20+ #1404 Thu Mar 4 19:36:44 GMT 2021 armv6l GNU/Linux

shedstrom avatar Mar 11 '21 12:03 shedstrom

@shedstrom I uploaded 2 apps to print some debug information https://pyarmor.dashingsoft.com/downloads/temp/foo-arm-mode https://pyarmor.dashingsoft.com/downloads/temp/foo-thumb-mode

Could you test them in Pi zero? check them work or not.

jondy avatar Mar 12 '21 12:03 jondy

Here is the output from both:

pi@raspberrypi:~ $ ./foo-arm-mode 
carmor_set_key_iv at 0x0x91fc
Illegal instruction
pi@raspberrypi:~ $ ./foo-thumb-mode 
carmor_set_key_iv at 0x0x91fc
Illegal instruction

shedstrom avatar Mar 12 '21 13:03 shedstrom

How about these 2 files, they're compiled by another cross-compile tool? https://pyarmor.dashingsoft.com/downloads/temp/foo2a https://pyarmor.dashingsoft.com/downloads/temp/foo2t

jondy avatar Mar 12 '21 13:03 jondy

Output:

pi@raspberrypi:~ $ ./foo2t
carmor_set_key_iv at 0x0x11000
Illegal instruction
pi@raspberrypi:~ $ ./foo2a
carmor_set_key_iv at 0x0x11000
Illegal instruction

shedstrom avatar Mar 12 '21 13:03 shedstrom

What's COLLECT_GCC_OPTIONS in this platform? This is what I used to build dynamic library

$ echo "" > a.c
$ toolchain/bin/arm-buildroot-linux-gnueabihf-gcc --verbose -shared a.c
...
COLLECT_GCC_OPTIONS='-v' '-shared' '-mcpu=arm1176jzf-s' '-mfloat-abi=hard' '-mfpu=vfp' '-mabi=aapcs-linux' '-marm' '-mtls-dialect=gnu' '-march=armv6kz+fp'

jondy avatar Mar 13 '21 01:03 jondy

This is what I get:

COLLECT_GCC_OPTIONS='-v' '-shared'  '-mfloat-abi=hard' '-mfpu=vfp' '-mtls-dialect=gnu' '-marm' '-march=armv6+fp'

shedstrom avatar Mar 15 '21 06:03 shedstrom

Does this work? https://pyarmor.dashingsoft.com/downloads/temp/foo-armv6

It's built with extra cflags -march=armv6, not the default -march=armv6kz

If it works, also try this new linux.armv6.3 https://pyarmor.dashingsoft.com/downloads/temp/_pytrasnform.so

Download it, then save it to /home/pi/.local/lib/python3.7/site-packages/pyarmor/platforms/linux/armv6

jondy avatar Mar 15 '21 07:03 jondy

Does this work? https://pyarmor.dashingsoft.com/downloads/temp/foo-armv6

I'm afraid that it did not work

shedstrom avatar Mar 15 '21 08:03 shedstrom

It's a little difficult to fix it, because I can't reproduce this issue by qemu, the test app foo works in my test vm qemu-system-arm -M raspi0 with linux kernel 4.2.0 built as bcm2835_defconfig

So the current solution is linux.armv6.0

jondy avatar Mar 15 '21 08:03 jondy

Okay, will update my scripts to use armv6.0.

Do you think its possible for you to test on a qemu with a kernel that is 5.x?

shedstrom avatar Mar 15 '21 09:03 shedstrom

I think it could not help for this issue.

jondy avatar Mar 16 '21 02:03 jondy

I rebuild linux.armv6.3, it may fix this issue, it has been packaged into the dev version https://pyarmor.readthedocs.io/en/latest/change-logs.html#dev-version

I seems there is something wrong with linux.armv6.3, I'll check it.

Since linux.armv6.0 works, now use it by exporting environment variable PYARMOR_PLATFORM=linux.armv6.0

after exporting env variable as linux.armv6.0 i am getting [error 21] is a directory

dheerajluffy avatar Feb 06 '22 08:02 dheerajluffy