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

How to run a python script with root privileges using PythonAPK? #32

Open
GoogleCodeExporter opened this issue Apr 5, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

I was able to run a python script that does not need root privileges in my 
android phone, which is rooted, using PythonAPK. The problem is when I want to 
run a script that for some reason need to be run by root user. It returns this 
exception "Error code: 1 Message operation not permitted".
Is there a way to call my script from java code with root permissions 
(something like su)? 

Original issue reported on code.google.com by georgelo...@gmail.com on 18 Sep 2013 at 5:17

@GoogleCodeExporter
Copy link
Author

I'm seeing two potential ways:

1. using "Runtime.getRuntime().exec...", clean way is to use it through this 
lib: 
https://github.com/Chainfire/libsuperuser/tree/master/libsuperuser/src/eu/chainf
ire/libsuperuser

2. adding in com_googlecode_android_scripting_Exec.cpp 
(http://code.google.com/p/android-scripting/source/browse/android/ScriptingLayer
ForAndroid/jni/com_googlecode_android_scripting_Exec.cpp?r=28fd0c99780e713524ff0
8b0a362a56eaf803429) ability to launch process as root (setuid setgid...)

Original comment by anthony....@gmail.com on 18 Sep 2013 at 5:45

@GoogleCodeExporter
Copy link
Author

Thank you very much for your reply!! I tried the second solution by changing 
the cpp file and recreating the .so but again the same problem. I think I do 
not put setuid(0) and setgid(0) in the suitable position. Can you please give 
me a clarification? It would help me a lot. 

Original comment by georgelo...@gmail.com on 19 Sep 2013 at 12:49

@GoogleCodeExporter
Copy link
Author

I would try first of a simple example and printf output, smth like:

#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main(void)
{
    printf("euid=%4d uid=%4d egid=%4d gid=%4d\n", geteuid(), getuid(), getegid(), getgid() );

    printf("%i \n",seteuid(0));
    perror("seteuid");
    printf("%i \n",setegid(0));
    perror("setegid");

    printf("euid=%4d uid=%4d egid=%4d gid=%4d\n", geteuid(), getuid(), getegid(), getgid() );

    return 0;
}

Also some permission change might be needed in 
http://code.google.com/p/android-python27/source/browse/apk/src/com/android/pyth
on27/ScriptActivity.java , 6755 instead of 0755 in the line:                    


FileUtils.chmod(new File(this.getFilesDir().getAbsolutePath()+ 
"/python/bin/python" ), 0755);

Same in 
http://code.google.com/p/android-python27/source/browse/apk/src/com/android/pyth
on27/support/Utils.java



Original comment by anthony....@gmail.com on 19 Sep 2013 at 1:20

@GoogleCodeExporter
Copy link
Author

Any updates ? Did you manage to get it working ?

Original comment by anthony....@gmail.com on 28 Sep 2013 at 7:28

@GoogleCodeExporter
Copy link
Author

I didn't manage to get it working in this way. I used the project just to 
install python27 to android and then I managed to run the script with root 
privileges with terminal commands. Thank you!

Original comment by georgelo...@gmail.com on 1 Oct 2013 at 10:10

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

No branches or pull requests

1 participant