Posts

    Showing posts with label python. Show all posts
    Showing posts with label python. Show all posts

    Saturday, 3 January 2015

    Installing python on Android 5.0

    Executables with PIE (Position Independent Execution) have been supported since Android 4.1. It is a security feature involving address space layout randomization(ASLR) to prevent attacks such as buffer overflow. In Android's latest release Lollipop, PIE has been made a requirement. Similar to the way the shift from Dalvik to ART has crippled so many applications, this move has caused a lot of problems to developers.  Even some of the binaries shipped with android itself were broken because of this.

    I will be showing you how to install RunPythonFromShell. If you have already installed it and want to see how to bypass PIE go to the section Bypassing PIE.

    Step 1

    Download apk

    Install the apk and open it. Click the install button in the app to install all the modules and binaries.

    Step 2 

    If you don't want to run python from everywhere, skip this step. 
    • Open adb shell
    • Download the following gist. Move it to /system/bin and change set executable permission.
    • If you are running an android version older than lollipop then you are done! Lollipop users have to bypass PIE.

    Bypassing PIE

    Due to the PIE restrictions you get the following error when you run python:
              
             error: only position independent executables (PIE) are supported.

     The idea here is to replace the default linker with a custom linker (You need a rooted device. duh!).  First mount /system in write mode and backup the default linker.

    mount -o remount,rw /system /system
    mv /system/bin/linker /system/bin/linker.old

    Download custom linker

    Move custom linker to /system/bin. Then set proper permissions.

    chmod 0755 /system/bin/linker

    You can also use ES File Explorer or Root Explorer to do this. Permission of the file should look like this:

    You are done! You can run python from terminal!


    I will be writing a post on what all cool things you can do with python on android. Stay tuned! 

    Update

    Some of the users with 64 bit architecture were facing some linking problem. Here is what you have to do.
    Create a new lib64 directory and move the library file to that folder.

    mkdir /data/data/com.googlecode.pythonforandroid/files/python/lib64
    cp /usr/lib64/libcrypto.so   /data/data/com.googlecode.pythonforandroid/files/python/lib64

    Then you have to add this to the library path. To do that you have to update the variable LD_LIBRARY_PATH in the "/system/bin/python" script above.


    Thanks Yan Bellavance for pointing it out!

    Saturday, 18 May 2013

    Jarvis, at your sevice


    Hello everyone! Its been a long time since I blogged. Today I will show you how to use 'Jarvis' which is an open source software which can be used to control your Linux system using your hand motion, gestures which was made as my Human Computer Interaction project. This is mainly an image processing based project developed using python.



    Things u can do using Jarvis:


    1. The first thing you can do using Jarvis is control your mouse. You just need a colored object (preferably has color different from its background). So you can do things like draw in air!
    2. The second thing is that you can assign any gesture which is a combination of
      Left->Right, Right->Left, Top->Bottom, Bottom->Top to any command. So using this you can literally perform anything!!! The following are the things you can do by default:

    • Maximize/Minimize/Close current window
    • Go next and forward in PPT presentation
    • Page up and Page down
    • Switch window (Alt+tab)
    • Take screenshot
    • Shutdown/Suspend system
    • Mute and unmute
    • Open Calculator, File manager, Gedit


    You can practically add anything else also. All you need to know is the command which does that and the equivalent of the gesture which you want to assign in the combination of Left->Right, Right->Left, Top->Bottom, Bottom->Top.

    Getting dependencies:

    Ubuntu:
    $ sudo apt-get install python-opencv xdotool
    Fedora:
    $ sudo yum install python-opencv xdotool

    Installation:

    $ git clone https://github.com/alseambusher/jarvis.git
    $ cd jarvis
    $ ./install

    Now you need to set the screen resolution of your screen. If your screen resolution is 1366x768 then skip this step.
    $ gedit ~/.jarvis/config.py
    change the value of variable RESOLUTION corresponding to your screen resolution.

    Running:

    Now simply open Jarvis from your Applications menu
    OR
    Do this:
    $ cd ~/.jarvis
    $ python main.py
    Now click on Start Jarvis 

    Add new gesture:

    1. Go to settings from the File menu


    2. Click on Add gesture from the File menu of settings


    3. Suppose say that you want to add a gesture which opens terminal.
    Say the gesture you wish to give is (Left to Right)->(Right to Left)->(Top to Bottom)->(Bottom to Top)
    The command corresponding to open gnome terminal is 'gnome-terminal'

    4. Fill the details and save it.


    You are done!!!

    Editing and deleting gestures are simple :P

    How to use?

    We need two different colored objects which are required to run. One the tracker and the other one is the flag!

    1. If the flag is not exposed then the gesture is disabled and Jarvis works as a mouse controller.
    2. When both tracker and flag are exposed the gesture begins. Perform the gesture using the tracker. Once the gesture is complete hide the flag. Jarvis then processes and analyses the gesture performed and checks for any matches from the existing database. If there is a match then it executes it!.

    Customizing Tracker and Flag color:

    By default the tracker is yellow color and flag is blue color.
    You can change it by editing the config.py file

    $ gedit ~/.jarvis/config.py

    Change the min and max values of TRACKER_COLOR and GESTURE_COLOR corresponding to the HSV values of the color intended

    By default these are the values:
    TRACKER_COLOR={'MIN':[20,100,100],'MAX':[30,255,255]}
    GESTURE_COLOR={'MIN': [108.0, 100, 10],'MAX': [118.0, 255, 255]}

    Thank you. Dont forget to contribute to this open source project as there is a lot of scope for improvements. :)

    Fork the project from here: https://github.com/alseambusher/jarvis