Below is the image of how the android device automatically mounts on windows 10 (named: remdiz)
Actual Device: Redmi Note 5 Pro
1: https://i.stack.imgur.com/uOnI4.png
I am not able to get the list of files inside any given folder inside it because I see the path of it as This PC\redmiz\disk\Music which is not accessible in powershell, command prompt or even python.
All I need is to list the files inside Music as I have a same copy on my local and I want to find the difference
Accepted answer can be a batch file, windows command, powershell command, python script, command using git bash etc or any process that will give me a real path of the device named redmiz
MTP doesnt allow this on Windows. Found a tool named MTPDrive. It was a little buggy, but helped by mounting the internal storage and external storage of Android as mapped drive leading to now limitless possibilites for my use case
I wanted to have git available as a CLI tool on my android device, usable via a local terminal app. I've successfully cross-compiled git for aarch64-linux-android and if I use a root shell to move it to one of the ext4 filesystems on the device I can invoke it successfully.
However, installing and using it with root is not desirable. I normally leave my device unrooted and only temporarily enable root to do experiments like this. Installation as root is not so bad, but it seems that the only ext4 filesystems mounted read/write are in locations that the terminal app cannot read from, so I cannot use it as a non-root user, which is a deal breaker *.
I'd prefer to package it as an APK if possible, so it can be sideloaded as a normal user. I'd also like to be able to invoke it from the terminal app. If I have to manually adjust $PATH, that's fine, but bonus points if the APK can place it somewhere on $PATH or have the OS extend $PATH on installation.
* (I know I can remount /system as r/w to install it as root, and that would make it usable to all applications. I don't want to modify /system because then "factory resets" are not ensured to bring me back to a working state. I know it'd be a relatively safe change. If this really is impossible, I'll do that, but an APK would be so much nicer)
I don't think you can do this. Android is designed to prevent such things: each APK can only run in a (somewhat) isolated container.
An APK cannot install an executable in the root folders. Modifying $PATH will also not work (if the system would even allow you to modify it) because each APK is executed by a different user, thus the environment will be different. I'm not even sure you can mark a file as executable on common folders.
One workaround to this would be to make the path of the executable (if you can mark a file as executable, that is) available through a ContentResolver.
My Project runs C++ test cases on Android devices. An exectuable gets generated and along with that, couple of shared object files also gets copied over to the device and the executable is then run. Till now, all those data were being copied over to /data/local/tmp folder. After the test cases are run, the content from /data/local/tmp is deleted using adb shell command. With Pixel 2 devices, I am able to copy the exe and shared object files to the tmp folder, but unable to delete them once the test cases are completed. I tried using /data/local/temp folder, but I am unable to push files to that folder. Tried using /sdcard but it does not allow the exe files to be executed. I am clueless as to which specific directory I should be using to run my native test cases on Pixel 2 devices. Does anyone has any pointers? Please help.
if you create files from adb, uid:gid is set to 2000:2000 and permissions of /data/local/tmp is 0771, this means you always can remove your own files. There is no other location for this, you must have messed with permissions
adb shell
touch /data/local/tmp/my-file
ls -an /data/local/tmp
rm /data/local/tmp/my-file
I am developing an application using ionic framework.
The app creates files (*.json) and stores them in /data/user/0/ when i verify whether they exist or not, the result was true which means the files exist in the mentioned directory and I can access and modify their content without problem, but when I check the directory with a file manager or from the computer, no result, the directory is empty.
Could someone tell me what should I do?
use adb to copy the file. Even if it's in root dir, u should have access to it via adb.
Do adb pull data/user/0/filename.json path_on_ur_comp.json.
this will copy the file to the directory you define in the 2nd parameter.
// EDIT:
adb is part of the Android SDK, stands for Android Debug Bridge.
You can use this for MANY MANY different reason but of course, the "main" reason is to debug Android devices. You can use it to transfer files in your case.
In Windows, it's located here:
C:\Users\USERNAME\AppData\Local\Android\sdk\platform-tools\adb
In Mac, it's lcoated here:
/Users/USERNAME/Library/Android/sdk/platform-tools/adb
Depending on which OS you use, open that either with Terminal (Mac) or Command Prompt (Windows).
Once you do that, run the following command:
For Mac:
adb pull data/user/0/filename.json /Users/USERNAME/Desktop/somefile.json
For Windows:
adb pull data/user/0/filename.json c:\Users\USERNAME\Desktop\somefile.json
This will copy the file and put it on your desktop
I want to change the init.rc file of an android pad. But after I change it and reboot the system, the original init.rc comes back.
How can I make the change to the init.rc persistently without rebuild the system (since I don't have the source code of the system)? Or is there any way to work around?
Unpack the uramdisk using following command in host PC(Linux)
mkdir /tmp/initrc cd /tmp/initrd
sudo mount /dev/sdb1 /mnt
sdb1 is partion where uramdisk/uInitrd resides.
dd bs=1 skip=64 if=/mnt/uInitrd of=initrd.gz
gunzip initrd.gz
At this point running the command file initrd should show:
mkdir fs
cd fs
cpio -id < ../initrd
Make changes to init.rc
Pack uramdisk using following commands:
find ./ | cpio -H newc -o > ../newinitrd
cd ..
gzip newinitrd
mkimage -A arm -O linux -C gzip -T ramdisk -n "My Android Ramdisk Image" -d newinitrd.gz uInitrd-new
A number of Android devices include code to prevent root modifications to the system files. The way this is done is by using the recovery partition. On reboot, they basically restore the system partition using the recovery image. If your system is doing that then you cannot make persistent changes - the best you could do would be to hook up something to run after reboot to re-apply your change. In CyanogenMod they had hooks in the init.rc to run sdcard scripts if found. Perhaps you can create an app or widget to then launch a script to make the mods required using a setuid root script from the data partition. Without building your own ROM you are quite restricted in this area.
Possibly you could fetch the recovery image and try unpacking that, making your changes and repacking and flashing it. But make sure you can recover with fastboot before you try this.
Try this site:
http://bootloader.wikidot.com/linux:boot:android
Read the section at the bottom:
•The Android boot image: boot.img
◦Unpack, re-pack boot image: http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack%2C_Edit%2C_and_Re-Pack_Boot_Images#Background
When an android system boots, uboot unpacks a special compressed ball of files in your boot partition called 'uRamdisk' to RAM, and defines those files to comprise the root directory of the system. uRamdisk normally contains a bunch of directories (system, data, media, etc.) that serve as mountpoints for partitions that contain the files that go in them, but also has some very basic files vital to your system, including the init binary and startup scripts like init.rc.
when you edit the init.rc, you've actually just edited the unpackaged copy of init.rc that resides in your RAM. To really change it then, you have to copy your uRamdisk, extract it, edit the init.rc from there, repackage uRamdisk and then replace the new one with the old one in /boot.
Try looking up the 'xuramdisk' and 'mkuramdisk' scripts, these make the process very simple.
Your root partition (where /init.rc lives) is a ramdisk which is unpacked from an initrd file and mounted every time your device boots. Any changes you make are to the ramdisk only, and will be lost on the next reboot.
If you can get the initrd file, you can mount it on your Linux host system, modify the files there, unmount it, and write it back to your Android.
The initrd file exists in its own partition on the device. If you can figure out which partition it is, you can grab it from the device onto your host, mount it, modify it, and write it back to the device. This is what tripler was talking about above.
In general, modifying boot.img is something that only system developers do. If you're building the entire Android system, you'll have access to the necessary source code. My workflow for this looks like this:
# Modify init.rc
m -j8 bootimage_signed
adb reboot bootloader
fastboot flash boot $OUT/boot.img
fastboot reboot
I don't know if you are still trying to do this but without knowing your exact device nobody can give you an exact answer.
Try taking a dd image of all your internal partitions and use some scripts like those included with android kitchen on xda forums. Your recovery and boot partitions will both have a ram disk but odds are you want to modify the init.rc in the boot.img not recovery, unless you only want the changes present in recovery mode.
The unyaffs thing doesn't apply to all devices and most devices have different partition layouts so you have to figure out which is boot and what type of fs it is. Maybe if you give your device specs you can get a better answer.
Please note that it may be easier for you to use an app like Scripter to run a script at boot time than modify this file.
Before following #tripler's instructions above you need a file called boot.img which can be extracted by (run on rooted Android device, untested without root):
dd if=/dev/block/platform/<someplatform>/by-name/boot of=/sdcard/boot.img
Then connect your Android to your computer and copy the boot.img file from there.
Script:
http://linuxclues.blogspot.ca/2012/11/split-bootimg-python-android.html
Here is a modified, easier to see version of tripler's instructions (assuming boot.img is in tmp):
cd /tmp
mkdir fs
# Now use the linked script above to split the boot.img file into ramdisk.gz and kernel
python split_boot_img.py -i boot.img -o parts
cd fs
gunzip -c ../parts/ramdisk.gz | cpio -id
# make changes to init.rc
At that point you will have to rebuild the boot.img back together before reflashing, which will be device-specific. Can't help you with that, sorry!
You have to edit/change the init.rc before building your Android pad file system. This is the preferred way, and always works.