I created a folder hdr in /sdcard/DCIM/Camera/ by linux c function: mkdir(), but when I set permission, I used '777' but not '0777' uncarefully, and the folder permission like this:
xxx:/sdcard/DCIM/Camera # ll
total 6
drwxrws--T 5 u0_a217 media_rw 3452 2022-03-01 09:26 hdrd
...
xxx:/sdcard/DCIM/Camera/hdrd # ll
total 9
drwxrws--T 2 u0_a217 media_rw 3452 2022-02-25 10:13 20220225_101334_1645755214821
...
xxx:/sdcard/DCIM/Camera/hdrd/20220225_101334_1645755214821 # ll
total 1952
-rw-rw---- 1 u0_a217 media_rw 460800 2022-02-25 10:13 IMG_20220225_101334_1645755214821_0_640x480_p_640x480_SRC.NV12
then , I wanna delete this hdrd folder so I used rm -r hdrd, there is an error:
xxx:/sdcard/DCIM/Camera # rm -r hdrd/
rm: IMG_20220225_101334_1645755214821_0_640x480_p_640x480_SRC.NV12: Math result not representable
...
I don't know why delete failed, I was in root state.
PS: I use lsattr fuction, but not succeed:
xxx:/sdcard/DCIM/Camera # lsattr hdrd
lsattr: reading flags 'hdrd/20220225_101334_1645755214821': Function not implemented
Related
At my first thought, I should know how to check the permissions of a folder in the Linux system(since the kernel of Android is linux) by C or C++.
Since C++17 is not available for me, so std::filesystem could not be used. And I searched on SO, I found access may be a solution. So I wrote the code snippet below:
if (access(folder_path, W_OK | X_OK) == 0) {
SDK_LOG_ERROR("folder is not writable");
}
But it seems not work as expected, I can manually create new files in a specific folder:
C:\tools>adb root
adbd is already running as root
C:\tools>adb remount
remount succeeded
C:\tools>adb shell
promotion:/system/etc/some_folder/.../config # ls -lhd .
drwxrwxrwx 2 root root 4.0K 2022-05-31 21:14 .
promotion:/system/etc/some_folder/.../config # touch a
promotion:/system/etc/some_folder/.../config # touch b
promotion:/system/etc/some_folder/.../config # ls -lh
total 14K
-rw-rw-rw- 1 root root 0 2022-05-31 21:14 a
-rw-rw-rw- 1 root root 0 2022-05-31 21:14 b
Before running the said code snippet, I call adb root; adb remount first, and then I call whoami in the terminal, the output is root.
But when I run the aforementioned code snippet on Android, the program tells me folder is not writable". What a surprise!
On my android 8.1.0 system, i try to write directly to a block device.
(partition on emmc)
I can write to P24, but not to P25 somehow, and i can't figure out why.
There is nothing in logcat or dmesg logs.
No avc: denied.
# whoami
root
# ls -lZ mmcblk1p24 mmcblk1p25
brwxrwxrwx 1 root root u:object_r:block_device:s0 259, 8 2011-11-11 11:11 mmcblk1p24
brwxrwxrwx 1 root root u:object_r:block_device:s0 259, 9 2011-11-11 11:11 mmcblk1p25
# dd if=/dev/zero of=mmcblk1p24 bs=1 count=1
1+0 records in
1+0 records out
1 bytes transferred in 0.001 secs (1000 bytes/sec)
# dd if=/dev/zero of=mmcblk1p25 bs=1 count=1
dd: mmcblk1p25: Operation not permitted
1+0 records in
0+0 records out
0 bytes transferred in 0.001 secs (0 bytes/sec)
# busybox lsattr mmcblk1p24 mmcblk1p25
lsattr: reading mmcblk1p24: Not supported
lsattr: reading mmcblk1p25: Not supported
Found it.
The block device had the ioctl BLKRO bit set
# blockdev --getro /dev/block/mmcblk1p24
0
# blockdev --getro /dev/block/mmcblk1p25
1
# blockdev --setrw /dev/block/mmcblk1p25
# blockdev --getro /dev/block/mmcblk1p25
0
I'm having android app that extracts some native executable on first run and uses it to do some work. It worked before Nougat and stopped working. After few days or investigation i've found that PATH environment variable is accepted but not taken into account! I'm, trying out if it's a feature or a bug.
First, let's see what we have and if we're able to do the same from cmd.
I've replaced actual android app package with 'my.app.package' and not related output with '...' for SO.
ZTE_BLADE_V0800:/ $ run-as my.app.package
ZTE_BLADE_V0800:/data/data/my.app.package $ whoami
u0_a129
ZTE_BLADE_V0800:/data/data/my.app.package $ ls -l
total 56
drwxrwx--x 2 u0_a129 u0_a129 4096 2017-03-14 16:15 app_build
drwxrwx--x 2 u0_a129 u0_a129 4096 2017-03-15 13:15 app_buildSources
drwxrwx--x 2 u0_a129 u0_a129 4096 2017-03-14 16:15 app_downloads
-rw------- 1 u0_a129 u0_a129 35 2017-03-14 16:16 app_repository
drwxrwx--x 14 u0_a129 u0_a129 4096 2017-03-14 16:16 app_sdk
drwxrwx--x 3 u0_a129 u0_a129 4096 2017-03-14 16:15 app_temp
drwxrwx--x 2 u0_a129 u0_a129 4096 2017-03-14 16:15 cache
lrwxrwxrwx 1 root root 54 2017-03-15 13:15 lib -> /data/app/my.app.package-2/lib/arm
ZTE_BLADE_V0800:/data/data/my.app.package $ ls -l ./app_sdk/
total 96
...
drwx------ 4 u0_a129 u0_a129 4096 2017-03-14 16:16 cppcheck#1.64#1
...
ZTE_BLADE_V0800:/data/data/my.app.package $ ls -l ./app_sdk/cppcheck\#1.64\#1/
total 16
...
drwx------ 3 u0_a129 u0_a129 4096 2017-03-14 16:16 bin
-rw------- 1 u0_a129 u0_a129 0 2017-03-14 16:16 init.done
ZTE_BLADE_V0800:/data/data/my.app.package $ ls -l ./app_sdk/cppcheck\#1.64\#1/bin
total 6960
drwx------ 2 u0_a129 u0_a129 4096 2017-03-14 16:16 cfg
-rwxr-xr-x 1 u0_a129 u0_a129 2345332 2017-03-14 16:16 cppcheck
-rwxr-xr-x 1 u0_a129 u0_a129 1211424 2017-03-14 16:16 libgnustl_shared.so
ZTE_BLADE_V0800:/data/data/my.app.package $ export PATH=$PATH:./app_sdk/cppcheck#1.64#1/bin
ZTE_BLADE_V0800:/data/data/my.app.package $ export LD_LIBRARY_PATH=./app_sdk/cppcheck#1.64#1/bin
ZTE_BLADE_V0800:/data/data/my.app.package $ cppcheck --version
Cppcheck 1.65 dev
ZTE_BLADE_V0800:/data/data/my.app.package $
Now let's try to do the same in Runtime:
ProcessBuilder processBuilder = new ProcessBuilder();
String path =
System.getenv("PATH") +
":./app_sdk/cppcheck#1.64#1/bin";
processBuilder.command(new String[] {
// "sh", "-c", "echo $PATH", // (1) working
// "sh", "-c", "echo $LD_LIBRARY_PATH", // (2) working
"./app_sdk/cppcheck#1.64#1/bin/cppcheck", "--version" // (3) working
// "cppcheck", "--version" // (4) NOT working even with PATH env variable passed
});
processBuilder.directory(new File("/data/data/my.app.package/"));
Map<String, String> env = processBuilder.environment();
env.put("PATH", path);
env.put("LD_LIBRARY_PATH", "./app_sdk/cppcheck#1.64#1/bin");
process = processBuilder.start();
and i get IOException thrown:
Cause: error=13, Permission denied
Cannot run program "cppcheck" (in directory
"/data/data/my.app.package"): error=13
Let's see if PATH is passed correctly.
Uncomment comment (1) and comment the other command lines, confirm it's set:
/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin:./app_sdk/cppcheck#1.64#1/bin
Let's see if LD_LIBRARY_PATH is passed correctly.
Uncomment comment (2) and comment the other command lines, confirm it's set:
./app_sdk/cppcheck#1.64#1/bin
Now let's see if i'm able to run the tool passing full path.
Uncomment comment (3) and comment the other command lines, see it's working now:
Cppcheck 1.65 dev
Wow, even with PATH passed i have to pass full path for the executable. If i use short tool name, i'm getting Permission denied error.
Is it Nougat (since i'm having it starting Nougat only) feature or issue or i missed anything?
I know Nougat introduced more strict security policies but i see no reason for this in my case to stop working as all the files are in app sandbox (internal directory in my app directory).
PS. I can't just replace all short executable names in command-lines as executable can run another executable too using short executable name, so i need to get PATH variable taken into account eventually.
I did not get any response from Google (they are working on it starting Jan 25) so i had to workaround it passing full executable path like in comment (3).
Using a terminal emulator in my android phone I accidentally copied /proc directory into another user directory. Now I want to delete the copy but I don't have the permissions to do so. I tried to change ownership and permissions to 777 but with no success. I am using Oneplus 2 and termux application. Any suggestions?
Edit:
The original /proc directory :
dr-xr-xr-x 459 root root 0 Jan 1 1970 proc/
it was copied to /.../line/proc:
Line:
drwxrwxrwx 4 u0_a45 u0_a45 4096 Oct 17 12:23 line/
Line/proc:
dr-xr-xr-x 52 u0_a45 u0_a45 4096 Jan 1 1970
proc/
The new proc directories are not removable:
rm -rf line/proc
rm: can't remove 'line/proc/12159/task/12247': Permission denied
...
I use the smartphone emulator in Android Studio for a Nexus 4, API 23.
I took a picture through its camera, and I can check that the file is present at this different paths through the Android Device Monitor:
/data/media/0/DCIM/Camera/IMG_20160408_143726.jpg (rw-rw-r)
/storage/emulated/0/DCIM/Camera/IMG_20160408_143726.jpg (rw-rw)
Nevertheless, in my Activity I got different behaviors when I try to read the file:
new File("/data/media/0/DCIM/Camera/IMG_20160408_143726.jpg");
// isFile at false, canRead at false, length at 0
new File("/storage/emulated/0/DCIM/Camera/IMG_20160408_143726.jpg");
// isFile at true, canRead at true, length with a real value
Why is it so?
it depends on contructor, use this method to get the sdcard path instead, that will find the correct path for all devices
new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera/IMG_20160408_143726.jpg")
You probably would like to grant your app root permission so as to let it work properly. Take a look at this example:
u0_a1#android:/ $ toolbox ls -l /storage/emulated/0/UPDATE*
-rw-rw---- root sdcard_r 4997896 2016-09-08 20:08 UPDATE-SuperSU-v2.78.zip
u0_a1#android:/ $ toolbox ls -l /data/media/0/UPDATE*
/data/media/0/*: Permission denied
1|u0_a1#android:/ $ su
root#android:/ # toolbox ls -l /data/media/0/UPDATE*
-rw-rw-r-- media_rw media_rw 4997896 2016-09-08 20:08 UPDATE-SuperSU-v2.78.zip