PyCrypto on FireTV (Android ARM)
#1
I'm trying to "port" an addon I've developed to the FireTV. This addon requires PyCrypto, which I had to compile on each platform I've wanted to use it on in the past.

Problem is, my FireTV is not rootable and I couldn't find any pre-built PyCrypto binaries that I could use.

I've tried building it through Kodi with a quickly hacked together script but it appears as if Makefile is not included with the Python build inside Kodi.

Any big brain around here that would have a solution for me? Big Grin

Thanks!
Reply
#2
Well pycrypto is part of the "acestreamengine bundle" I got from the original apk and that I use for p2p-streams. Download the bundle here:

http://p2p-strm.googlecode.com/svn/trunk...0.6.tar.gz

You can find pycrypto (crypto folder) under ~/org.acestream.engine/files/python/lib/python-2.7/lib-dynload/Crypto

Hope it's usefull,

Cheers
Reply
#3
I tried to extract the folder from latest apk and tried using on android but it failed.
Do you have the copy that works on android arm? I don't find any reference in your code, are you still using it in p2p?
Also where did you copy it? I am trying to load it from addons local folder but it says cannot find libAES etc. (will post the complete error later)

just jump on post 18 and see the solution i used.
http://forum.kodi.tv/showthread.php?tid=...pid2102490
Reply
#4
Google code is read-only, moved it here

https://plexus.svn.codeplex.com/svn/trun...0.6.tar.gz
Reply
#5
Thanks, but where you copy this folder? Ia m testing this on ftv arm android.
when i try to copy it to my code folder, it show this
Code:
18:52:53 T:27950688   ERROR:   File "/storage/sdcard/Android/data/org.xbmc.kodi/files/.kodi/addons/script.video.F4mProxy/lib/akhds.py", line 32, in <module>
18:52:53 T:27950688   ERROR:     from Crypto.Cipher import AES
18:52:53 T:27950688   ERROR:   File "/storage/sdcard/Android/data/org.xbmc.kodi/files/.kodi/addons/script.video.F4mProxy/lib/Crypto/Cipher/AES.py", line 50, in <module>
18:52:53 T:27950688   ERROR:     from Crypto.Cipher import _AES
18:52:53 T:27950688   ERROR: ImportError: Cannot load library: load_library(linker.cpp:771): library "lib_AES.so" not found
when i try to copy the files to assets\python2.6\lib\python2.6\site-packages or assets\python2.6\lib\python2.6\lib-dynload and build my apk and deploy, i get this
Code:
18:55:31 T:26425720   ERROR:   File "/storage/sdcard/Android/data/org.xbmc.kodi/files/.kodi/addons/script.video.F4mProxy/lib/akhds.py", line 32, in <module>
18:55:31 T:26425720   ERROR:     from Crypto.Cipher import AES
18:55:31 T:26425720   ERROR:   File "/data/app/org.xbmc.kodi-1.apk/assets/python2.6/lib/python2.6/site-packages/Crypto/Cipher/AES.py", line 50, in <module>
18:55:31 T:26425720   ERROR: ImportError: cannot import name _AES

feel like i am just missing the right folder., could you shed some light please? thanks
Reply
#6
The module is for python 2.7 (py4A): https://code.google.com/p/python-for-and...x-armv.egg

I doubt you'll be able to run in python 2.6 and specially without modifications. You can also ship py4a with your addon and run pycrypto there instead of using the python kodi provides.
Reply
#7
Yep, that why i was confused as how its working for you but i think you are not using the code directly and the crpto is loaded via python2.7.
I looked into the python for Android and was able to load Crypto there, so the easiest option is to write a server, and launch in py4A and then use kodi as client to get crypto working.
The prove of concept worked o my PC so will check later with my android.
Reply
#8
Instead of a server you can also (if the code is constant) just run it as any shell application and grab the std output. Probably better than running a server that steals memory (and ports) all the time.
Any executables might need also to be moved to the ext partition
Reply
#9
Yes the code is constant but not the data. I can easily do shell , but the server will be stated and stopped with the addon once etc. Launching python to decrypt each frame (there will be 100 in a seconds and few are quite bigger) which load the pycrypto and do the operation will definitely be slow. i will have to compare but first let me try this concept on Android and if it works i will look into script.
Reply
#10
OK - Update time. I am able to play the video on Android tablets. I have created a script that you can launch via py4a/sl4a and it creates the socket server.
The addon then use it to get the access to the Crypto.
Now, the problem is, py4a/sl4a is not working on FireTv as the requires components like Filebrowser/internet browser not available so need to find better/different solution Smile
So, how can you embed py4a in the addon and execute python2.7 there? as on android (unrooted atleast) you cannot execute anything from data directories.
Reply
#11
Just create a python bundle and move it to /data/data/org.xbmc.kodi/files/plugin.video.youraddon.

You can then start a subprocess from your python addon to run the python file as below:

edit: pastebin to avoid breaking the forum
Code:
http://pastebin.com/NAVKELG0

Refer to the acestream bundle above for a complete example (droidace.sh). $1 is the appid for kodi (it is different for xbmc, spmc, etc). In the addon I used to grab it from the userdata path.

This is what I do in the configuration step:
https://github.com/enen92/program.plexus...#L598-L653
https://github.com/enen92/program.plexus...#L661-L665

This is how I start it:
https://github.com/enen92/program.plexus...re.py#L285

This is how I kill it:
https://github.com/enen92/program.plexus...#L849-L857

I am not familiar with f4m or your proxy addon but I wonder if you need all this. I use it because it is compiled python code. Probably you can use simple solutions such as calling openssl directly (https://wiki.openssl.org/index.php/Android).

cheers
Reply
#12
oh, this looks promising but am i right in thinking that we can't do this without root? as you are accessing /data/data which is not available without root or i am missing a trick here?
Reply
#13
You can do it (and I do it) without root. As long as it is sandboxed to the application folder you won't have problems. You just can't access other app's folders from your application (in this case kodi) since everything is sandboxed, with individual uid's and in individual vm's for security purposes. In this case you are acessing /data/data/org.xbmc.kodi from kodi itself so it works.
Reply
#14
OK, so the trick is that the addon must access the /data/data folder not adb etc which make sense. This is the plan then! will try this on weekend! thanks a lot.
Reply
#15
Many Thanks enen92! Got it working by copying the files manually (just to test) and launching it via the Addon. Working great!
You are right about the SSL approach, as i just need a faster AES CBC decryption, is there any hints if i can simply call Android System functions and use ssl lib from python?
Reply

Logout Mark Read Team Forum Stats Members Help
PyCrypto on FireTV (Android ARM)0