Question
I want to call my secure website, which is using a self-signed certificate, and is running on my development machine, from my emulator that is running on the same machine
context
I create a self-signed certificate, and installed on my development machine, and edited the hosts file to link the localhost to my domail. So:
https://mydomain:8080 works perfectly on my development machine.
I installed the same certificate on my emulator, so:
https://10.0.2.2:8080 works but there emulator cannot verify the certificate because I am calling 10.0.2.2 while the certificate is issued for mydomain
The solutoin is to link the 10.0.2.2 to my mydomain on the hosts file
The problem is that I am not able to override (edit) the hosts file on the emulator, the error message states that the file is "read-only"
My attempts
It is being a long time and I am trying, I almost tried everything thing I could found, but no success, to list some:
First
adb shell
su
mount -o rw,remount /system
chmod 777 /system
The I get the same error message
Second
I run the emulator from adb command, with writable permission, but the same error happened
Third
I tried to root the emulator so I can use apps, such as Hosts Editor, but after so many trial and errors, I am not able to root the emulator
Well, I tried many, I hope you guys can give me some insights
Update
According to the aastefanov's answer, maybe the system/ folder is still not allowed to have write access on it
I found a solution:
The solution is to modify the hosts file from the shell script, without overtiring it.
Move technical stuff
adb root
adb shell
su //to get the root access
whoami // just to be sure we are the root user now
//now we are root but we cannot modify the hosts file because it is just on read-only state
mount -o rw,remount /system //to make it writable (you can be more specific and apply it to just system/etc folder)
echo "10.0.2.2 williamromadomain" >> /system/etc/hosts
This is just a work around, because I have to do that every time I run the simulator
Related
How to know which Emulator image will contain su?
I can see that often it only contains su or google play
Run adb root and you get a root shell ... otherwise su needs to be manually installed.
However, when already having a root shell available, installing it isn't much of a problem.
All images are rooted, but SDK apps requesting escalation of privileges do rely upon su.
This question here generally duplicates: How to get root access on Android emulator?
adb shell scripting must:
start the emulator
run adb root
run adb shell
remount system partition
adb push the su binary
chmod to set permissions
exit
Or to answer the question:
start the emulator
and check if the file exists, eg. with adb shell stat /usr/bin/su
Where stat gives this response, when it's not installed:
stat: '/usr/bin/su': No such file or directory
One could even loop all Android images installed in $ANDROID_SDK_HOME...
there's no "one click" solution, but adb can be fully automated with Bash or Batch. And one wouldn't even have to run the emulator, but can mount QCOW2 as a nbd network block device.
I'm trying to modify the hosts file on my android phone and I am using adb for this on Ubuntu 20.04 to pull the file, modify it and push it back as suggested here. I was able to pull the file but when I try to push it I get an error
adb: error: failed to copy 'Documents/hosts' to '/system/etc/hosts': remote couldn't create file: Read-only file system
One suggestion seems to be to run adb remount or adb shell mount -o rw,remount /system (I'm not sure if these meant to be run on the android device itself) and this doesn't work for me, I get
/system/bin/sh: /system/bin/remount: inaccessible or not found
To this, there seems to be a suggestion to run adb root which returns adbd cannot run as root in production builds. Now I'm not sure how to proceed. There are some threads online saying what to do about this but I feel this is way above my head already. I just want to push the hosts file back to the phone. Is there a simple way to do this?
I tried to create database file into
C:\Users\cammm\AppData\Local\Android\Sdk/platform-tools/data/data/com.cookandroid.cammm
Here are steps that I tried to get into the folder
click on "cmd" and run as administrator
cd C:\Users\cammm\AppData\Local\Android\Sdk/platform-tools
adb root
adb shell cd /data/data/com.cookandroid.cammm
Now this pops up: "/system/bin/sh: cd: /data/data/com.cookandroid.adb: Permission denied"
I used "ls" in "platform-tools" folder and saw that it was
"drwxrwx--x 37 system system 4096 2018-07-18 15:46 data"
which means file can only execute but not write or read in others.
using chmod did not work. (chmod: chmod '/data/data/com.cookandroid.adb' to 40702: Operation not permitted)
run as administor does not work
What should I do?
You will only be able to access the data/data folder if the device which you are accessing is rooted. when you have the device rooted then it will show # as prompt on the command line. so Make sure you have the rooted device to execute the above steps.
Please note: It's not advisable to use the rooted devices to carry out any function of the application as it's simply a hack of the device so you have to understand the risk associated with it.
My phone Samsung Galaxy S5 mini is rooted. I'm trying to pull files from /data/data/myapp.package/ to folder on my PC.
adb pull /data/data/myapp.package E:\myapp\myapp.package
it gives me this error
adb: error: failed to copy '/data/data/myapp.package' to 'E:\myapp\myapp.package': Permission denied
I found many questions like mine but no answer solved my problem. Some suggested to execute this command adb root before pulling files. Some suggested to install adbd insecure app to enable root access. In fact after installing that app, phone disappeared from adb terminal. Both solution didn't work for me.
BTW, I can copy files using cp command from adb shell but I have to copy files to sdcard and then pull from sdcard. I'm looking for solution which allows me to copy files directly from /data/data/myapp.package to my PC
Any solution?
For your adb to be able to access /data/data directly (for adb pull), your adbd should be running as root - which can generally be done by adb root command.
adb root would not work on commercial devices like Samsung Galaxy S5 mini as commercial devices have ro.secure=1, i.e., the adbd can't be restarted as root due to a check of property called ro.secure. adbd insecure app circumvents this and restarts adbd in root mode to enable adb pull, etc. to work.
In short, if adbd insecure app doesn't work for you, it's not possible to do adb pull from /data/data in your existing ROM. It might be possible if you change the ROM / do some boot.img tweaks, but I would probably suggest trying latest version / different versions of adbd insecure app before going for ROM changes.
Read more on rooting here.
First you need to hit these two command from command line
adb root
adb remount
then
adb pull /data/data/myapp.package E:\myapp\myapp.package
This is my example pulling DB file from the root directory
adb -e shell "run-as com.example.project cp /data/data/com.example.project/databases/project.db /sdcard"
The key is run-as
Here's a one-liner that lets you pull a file without installing anything else and without having to copy it to a public location on the device to then pull it to your computer:
adb exec-out su -c cat /data/data/myapp.package/my_file.apk > my_file.apk
What this does:
adb exec-out runs a command and outputs the raw binary output
su -c runs the provided command as root
cat <file> prints out the file contents
> <file> redirects the output from adb (i.e. the raw file contents) to a local file.
I am currently using 'Visual Studio Emulator for Android' to run android apps on my computer, i find that after using multiple types of emulators bluestacks, genymotion, andy etc. That VS is the most stable and easy-to-use out of them all.
The only problem that i have compared to the other emulators is running apps that require root permission, with this being an emulator i know that its not possible to go the route of rooting via fastboot/recovery, this is the only method i know of rooting as thats how i normally do it on my phone.
I have tried most of the 'rooting' APK's (kingo,towel,frama etc) and none of those have worked.
So would anybody happen to know how i can get root access on Visual Studio Android Emulator?
I am trying to run a touch-replication app (Frep & RepetiTouch) but all of them seem to require root access.
Any advice would be much appreciated. Thanks
Yes, you can. Here are some basics before the steps. Fundamentally all Visual Studio Emulator has root access; if you do adb shell you will get a root prompt. The only thing that is missing is the su binary and access for applications to connect to root shell through su. You can get the su binary from superuser apk from clockworkmod and the access to the root shell through the su daemon.
Installing su binary
Download superuser apk from clockworkmod. Ideal way is to download the app from google play store and navigate to /data/app/ and copy com.koushikdutta.superuser to your pc through adb pull /data/app/com.koushikdutta.superuser <local_path_in_your_system>
Change the .apk extension to .zip.
Navigate to assets/x86/ and copy the su binary to /system/xbin in your emulator
adb push <location_of_su> /system/xbin
chmod with suid and rwx
adb shell
chmod 6777 /system/xbin/su
symlink to /system/bin
ln -s /system/xbin/su /system/bin/su
Run the su daemon
/system/xbin/su --daemon
Giving Access to Applications through su
Install the superuser binary by either dragging and dropping into
the emulator or using adb install <path_to_superuser_apk>
Download rootchecker free\basic or even a terminal emulator for that
matter. We just want to check if our device is rooted.
Run the rootchecker app to check root and you should be able to get
the prompt from superuser.