I want to create files with different sizes on an Android device.
The one approach I have already tried was to create dummy files using fsutil and push it to devices.
Is there any way to achieve similar result with a command inside adb shell?
Yes, you can do it using dd command. I am not pretty sure it's available in your device. It works fine in my device, you can give a try.
In your host which connects with your Android device, with adb debug turn on, using the following command to create dummy file.
adb shell 'dd if=/dev/zero of=/data/local/tmp/test.img bs=4k count=800'
# check the result
adb shell ls -l /data/local/tmp/test.img
-rw------- shell shell 3276800 2017-06-21 17:33 test.img
The command above will get data from /dev/zero and output to /data/local/tmp/test.img (a public writable directory for Android device), adjust bs and count value in your situation.
Related
I have a smartphone without the possibility to insert an SD-card.
I would like to make a dump of the biggest partition (cause I lost files and I'd like to use a dump to recover them).
The partition is 10GB.
I was looking for an ADB command to pull using dd but nothing...
I tried to use Carliv touch recovery with a 32GB usb key by OTG but the USB key didn't mount ... Then I couldn't use "dd" directly on the phone using Aroma file manager and a terminal emulation.
Thank you!
I don't understand why they closed a question that has already an accepted answer by linking a completely different question. Copying a file and copying a partition are 2 different things.
As said in comment, adb pull /dev/block/mmcblk0 mmcblk0.img worked for me. A "DD image" is only a binary image file of the device.
You want to copy a disk from your android device to your computer (preferably on your fastest drive) for faster and lossless analysis/recovery.
This is short step-by-step guide in windows (linux: scroll down) to achieve it using the linux tool dd intended for precise, bit-wise copies of data. Credits go to scandium on xda for the code, see his post for more details.
Prerequisites
make sure your device is rooted and busybox is installed
Windows:
install cygwin. During install, add netcat (under Net) and pv (under util-linux) packages; the standard install is located in C:\ so make sure you have enough disk space beforehand;
install adb e.g. through Android Studio. Make sure to add adb.exe executable file to the path variable to access it properly (guide).
Open two cygwin consoles/terminals (one sending data, one receiving data) and enter in one of the terminals to enter the device:
# terminal 1
adb forward tcp:5555 tcp:5555 # forward data over tcp connection
adb shell # open a connection
su # gain root access
BUSYBOX=/system/xbin/busybox # default location for most bb installers
# note: adapt the variable `BUSYBOX` to point to your install directory
# the TWRP default is `BUSYBOX=/sbin/busybox` (in case of bricked device)
Decide what partition to copy, the /dev/block/mmcblk0 partition is usually the one containing the data you typically would want.
In the following code, adapt the partition name according to 4. and quickly one after another type in terminal 1 and terminal 2:
# terminal 1
$BUSYBOX nc -l -p 5555 -e $BUSYBOX dd if=/dev/block/mmcblk0
# terminal 2
nc 127.0.0.1 5555 | pv -i 0.5 > $HOME/mmcblk0.raw
This saves the partition in the cygwin home directory (in a nutshell: it sends/receives output of dd over a tcp connection)
Look at the files / analysis
To mount the partition in Windows you can use (OSFmount).
To analyze the files I recommend Active# Undelete but there are tons of alternatives. With that program you can also directly load all partitions from the file (without mounting it, so step 5 is redundant in this case).
Guide for GNU/Linux users: install netcat and pv (step 1), use the Disks utility to analyze
Run as root:
adb root
Use dd to output content into stdout and write file on your computer:
adb shell 'dd if=/dev/block/platform/msm_sdcc.1/by-name/XXXXXX 2>/dev/null' > XXXXXX.img
Or all (see cat /proc/partitions)
adb shell 'dd if=/dev/block/mmcblk0 2>/dev/null' > mmcblk0.img
i want to redirect the Android developer tools logcat output to a file into the virtual device from a shell command, before than running the android app test.
The command i usually use to redirect the output to a file is:
adb shell logcat -v time - f log.txt packageName:F *:E > /folder/log.txt
but it puts the log file into a computer directory (/folder/ in this case).
I want to change it with a directory in the virtual device but like above, it says the folder does not exist.
There is way to do it via shell command?
You can simply do
adb shell "logcat -v time -f /mnt/sdcard/log.txt packageName:F *:E"
to accomplish it all in one command from the host shell. You do not need the redirect when you use the -f flag, in fact the redirect would not capture anything if you have directed the output of logcat to a file rather than to stdout.
If that is not working, it is either because you are using a version of Android which mounts the external storage at some other path, or you do not have an emulated sdcard attached to your virtual device.
You can investigate either of these problems by examining the output of
adb shell mount
If you do not have an sdcard at all on your AVD, follow the emulator documentation instructions for creating and attaching one.
For testing purposes only there may be other paths than the sdcard at which you can write, particularly on an emulator where the adb shell runs as root, for example on some versions /data/local or similar.
You can try this one adb shell then #logcat>/sdcard/log.txt now i am sure about the results.you just need a command prompt window to be opened for adb shell,that's not so bad i guess.
Trying to copy file from device to desktop, here is a command:
adb pull sdcard/log.txt Users/admin/Desktop
But this command creates a folder Users/admin/Desktop inside platform-tools folder where adb is located. How to pull file to my desktop ?
Use a fully-qualified path to the desktop (e.g., /home/mmurphy/Desktop).
Example: adb pull sdcard/log.txt /home/mmurphy/Desktop
Judging by the desktop folder location you are using Windows. The command in Windows would be:
adb pull /sdcard/log.txt %USERPROFILE%\Desktop\
Be root, Define file on device and define new filename.
adb root
adb pull /data/data/.../databases/launcher.db launcher.db
On Windows, start up Command Prompt (cmd.exe) or PowerShell (powershell.exe). To do this quickly, open a Run Command window by pressing Windows Key + R. In the Run Command window, type "cmd.exe" to launch Command Prompt; However, to start PowerShell instead, then type "powershell". If you are connecting your Android device to your computer using a USB cable, then you will need to check whether your device is communicating with adb by entering the command below:
# adb devices -l
Next, pull (copy) the file from your Android device over to Windows. This can be accomplished by entering the following command:
# adb pull /sdcard/log.txt %HOME%\Desktop\log.txt
Optionally, you may enter this command instead:
# adb pull /sdcard/log.txt C:\Users\admin\Desktop\log.txt
List item
Use following command to pull data from ADB
adb pull data/user/0/project package name/files/.local/share/dbname C:\Users\vijayalaxmi.k
data/user/0/project package name/files/.local/share/dbname this path you will get when you debug application. i.e database path
project package name example => com.example
instead of C:\Users\vijayalaxmi.k user your own path where you want to save your file. for example, c:\documents
do adb pull \sdcard\log.txt C:Users\admin\Desktop
I wish to send an adb shell command to an Android device that pipes output from 1 command to other command, but when I try to do that, only the 1st command is executed on the device, and the 2nd one is executed on the host machine. Here's what I tried:
adb shell command1 | command2
command1 is executed on the device, and command2 on the host machine.
How can I get this to work properly?
Thanks!
You could use something like this:
adb shell "command1 | command2"
One way is to create a shell script containing the commands you want and then run the shell script.
Since the Android root filesystem is not writeable at run time (usually, unless you have rooted your device and remount it), you can copy the file to the removable (or emulated) storage, for example /sdcard.
Then run the script using the command adb shell sh /sdcard/your-script-name. Because each script runs in its own subshell, both of your commands will be executed in the same shell on the device (you can confirm it with ps).
adb shell "command1 && command2"
example:
Recursive listing of all files under /system/lib that contain 'foo':
adb shell "cd /system/lib&&ls -lR .|grep -i foo"
The important thing is the double quotes and the double ampersand.
The only thing is that you cannot use it for input as well, meaning that running an executable that requires stdin using one-liner wouldn't work as it requires user intervention.
I need a way to install or somehow get access to sqlite3 in the adb shell. I have rooted my device.
I've tried to find an answer but the closed I could come is:
Why do I get a "sqlite3: not found" error on a rooted Nexus One when I try to open a database using the adb shell?
But I don't think it's good idea to push my windows sqlite3.exe on a linux system?
So is it possible to install the sqlite3 terminal browser somehow?
[SOLUTION]
From the different comments and some asking around at #android-dev (irc), I found a solution. First I copied the database file to my desktop. But fist I had to install BusyBox, because cp isn't included?!? After that ran I into the problem that I couldn't pull or push from anywhere but /sdcard/ . I could then use /sdcard/ as a "middle station" and pull/push my db.
Then I got exhausted! I really had to have my sqlite terminal explore. Then I got the idea to start the emulator pull the sqlite binary from /system/xbin/sqlite3. Then remount /system with rw:
# mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
and push sqlite to the /sdcard/, and from there copy it to /system/xbin/
Now it works :D
Download this app from google play will help you install sqlite3 on android https://play.google.com/store/apps/details?id=ptSoft.util.sqlite3forroot
You don't need root to pull the database from your device. Simply run the following commands:
adb shell run-as <package-name> "cp databases/<db_name>.db /sdcard/ && exit"
adb pull /sdcard/<db_name>.db ~/Downloads/
From there, you can use sqlite3 for whatever operating system you're using (http://www.sqlite.org/download.html), or a sqlite browser such as "DB Browser for SQLite" (http://sqlitebrowser.org/)
I use Rajath's technique... Adb "Pull" the db from the emulator/device, work on it, then adb "push" it back onto/into the emulator device.
also:
I use the free SQLite Editor from the Android Market. I have not rooted my LG Ally and therefor can only edit database tables on my sdcard with SQLite Editor.
Rajath suggests using the adb to push and pull the databases to and from the emulator/device. The work on the database with the windows (or whatever) sqlite3 program you have. He does not suggest pusing the windows sqlite3 onto the Android device, IMHO.
I note that java/android "query()" sends actual SQL commands programmacitacly to ones program with user input. I conclude that sqlite3 is in Android somewhere.
When using the emulator Dev Tools is available, and way down at the bottom of the list is the Terminal Emulator. This allows exploration of file structure of Android in the emulator. However using "adb shell" from the PC has root permissions.
good luck. cactus mitch
You can do this with adb shell without issue.
In terminal or CMD (assuming you have the ADB path set and your phone has ROOT) type:
$ adb shell
$ cd data/data/com.nameofyourpackage/databases/
$ ls to find the name of your database
$ sqlite3 nameofyourdb.db
Then you can use .tables .schema to see the data you need to create the appropriate query.