Java Android:权限被拒绝 /data/local/tmp/*

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23424602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 22:57:02  来源:igfitidea点击:

Android: Permission denied for /data/local/tmp/*

javaandroidshell

提问by Harsh Chhatwani

I am trying to run a shell script through an android app. The script has a command which just runs a jar on the device. When I run this command directly on the shell using adb, everything works fine. But when I run it through the script using the android app, I get a permission denied exception (open failed: EACCES (Permission denied)) for the files created in /data/local/tmp folder. Can anyone guide in how to resolve this issue?

我正在尝试通过 android 应用程序运行 shell 脚本。该脚本有一个命令,它只在设备上运行一个 jar。当我使用 adb 在 shell 上直接运行此命令时,一切正常。但是,当我使用 android 应用程序通过脚本运行它时,我收到 /data/local/tmp 文件夹中创建的文件的权限被拒绝异常(打开失败:EACCES(权限被拒绝))。任何人都可以指导如何解决这个问题?

This is what my manifest looks like

这就是我的清单的样子

<manifest ….>
   <uses-sdk …>
    <uses-permission… .>
    …
    <uses-permission  android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    …
    <application …>
    …
    </application>
</manifest>

Thanks.

谢谢。

回答by u3458921

I think the reason is that your Andorid is not been rooted. the "/data" have the root Permission. So root your phone first, and give your app the permission. you can try command:"su" int the shell change to root.

我认为原因是你的Andorid没有被root。“/data”具有根权限。所以先root你的手机,然后给你的应用程序权限。您可以尝试 command:"su" 将 shell 更改为 root。

回答by Alex Cohn

If I understand the scenario correctly, you create the script on the fly, and use /data/local/tmpas an easy location that is both publicly writable and executable. Once, this was possible. But on recent versions of Android, security has been tightened.

如果我正确理解了场景,您可以即时创建脚本,并将其/data/local/tmp用作可公开写入和可执行的简单位置。曾经,这是可能的。但在最新版本的 Android 上,安全性已得到加强。

Your app can execute files under /data/data/${your.package}. You can use getContext().getFilesDir()to reliably obtain the full path. Note that you still need to use chmod 500to ensure that the file has executablepermission.

您的应用程序可以执行/data/data/${your.package}. 您可以使用getContext().getFilesDir()可靠地获取完整路径。请注意,您仍然需要使用chmod 500以确保该文件具有可执行权限。

If you have some fixed executables (binaries or scripts) that must be installed with your app, there is a clever trick to let the system package installer take care of all that for you: make sure the file has a name "libsomething.so" and put it in /libs/armeabidirectory under the Eclipse project root. After installation, the files will be present in getContext().getApplicationInfo().nativeLibraryDirdirectory with executable permissions set.

如果您有一些固定的可执行文件(二进制文件或脚本)必须与您的应用程序一起安装,那么有一个聪明的技巧可以让系统包安装程序为您处理所有这些:确保文件具有名称“ libsomething .so”"并将其放在/libs/armeabiEclipse 项目根目录下。安装后,这些文件将出现在getContext().getApplicationInfo().nativeLibraryDir目录中,并设置了可执行权限。



PSYou don't need the WRITE_EXTERNAL_STORAGEpermission for this to work (maybe you need it for other things your app does).

PS您不需要WRITE_EXTERNAL_STORAGE权限即可使其工作(也许您的应用程序执行其他操作需要它)。



PPSYou can run a shell script from anywhere, including /sdcard, and you don't need executable permission for the script. Instead, use sh -c source full.path.to.script.

PPS您可以从任何地方运行 shell 脚本,包括/sdcard,并且您不需要脚本的可执行权限。相反,使用sh -c source full.path.to.script.

回答by deven miles

You can use the adb interface to copy and/or push files to the /data/local/tmpfolder but if you want to use/see them in the terminal app you will need to (in adb interface) first

您可以使用 adb 界面将文件复制和/或推送到/data/local/tmp文件夹,但如果您想在终端应用程序中使用/查看它们,您需要先(在 adb 界面中)

cd /data/local/tmp 

then make a folder inside the folder. Example

然后在文件夹内创建一个文件夹。例子

mkdir folder 

next change the permissions

接下来更改权限

chmod - R 777 folder 

Now you have a folder you can read and write to.

现在您有了一个可以读写的文件夹。

A few things that I would like to know is how to make the system think that the subinary is in the /system/binfolder (without copying) because I can only get tmp... root access because even with root access, I can not remount the system directory as rwbecause the zte-paragon has its system partition formatted as a read-only file-system

我想知道的一些事情是如何让系统认为su二进制/system/bin文件在文件夹中(无需复制),因为我只能获得 tmp...root 访问权限,因为即使有 root 访问权限,我也无法重新安装系统目录,rw因为 zte-paragon 将其系统分区格式化为只读文件系统

回答by szym

Make sure the /data/local/tmplocation is world-executable on your device:

确保该/data/local/tmp位置在您的设备上是全局可执行的:

adb shell ls -ld /data/ /data/local/ /data/local/tmp/

drwxrwx--x system   system            XXXX-XX-XX XX:XX
drwxr-x--x root     root              XXXX-XX-XX XX:XX
drwxrwx--x shell    shell             XXXX-XX-XX XX:XX
#        ^ all x here == OK!

If it's not, there's nothing you can do, and you need to use the standard storage (internal /data/data/{package}or external /sdcard/).

如果不是,则您无能为力,您需要使用标准存储(内部/data/data/{package}或外部/sdcard/)。

Make sure you made the file world-readable.

确保您使文件世界可读。

adb shell chmod o+r /data/local/tmp/myfile.txt

You don't need any permissions.

您不需要任何权限。