Comments (22)
Thanks for the kind words!
That's not "officially" supported, but I took a look at python-adb and I think you should be able to accomplish this via:
from adb_shell.adb_device import AdbDeviceTcp, _AdbTransactionInfo
dev = AdbDeviceTcp(...)
# you could use timeout_s=None and total_timeout_s=10.0
adb_info = _AdbTransactionInfo(None, None, timeout_s, total_timeout_s)
dev._streaming_command(b'root', b'', adb_info)
Please let me know if that works.
from adb_shell.
Interesting.. Thanks for your quick response.. I'll try it and let you know.
Thanks!
from adb_shell.
Unfortunately, it's not quite working..
The command itself maybe works but the reason I'm trying to enter the "root mode" is so I could pull data from the "/data/data" path which is only available via root.
Trying to do the following:
adb = AdbDeviceTcp(...)
adb_info = _AdbTransactionInfo(None, None, 10, 10)
b = adb._streaming_command(b'root', b'', adb_info)
response = adb.shell('ls -l /data/data')
still resolved in ls: /data/data: Permission denied
as before
from adb_shell.
Try
# same as above, and then
b''.join(adb._streaming_command(b'root', b'', adb_info))
What is the output of that?
Also, are you able to get root access using the official adb binary?
from adb_shell.
@alonroth have you had a chance to try
# same as above, and then
b''.join(adb._streaming_command(b'root', b'', adb_info))
And are you able to get root access using the ADB binary?
from adb_shell.
Hi @JeffLIrion
Sorry for the delay I've been sick for the last couple of days..
I tried the following and it didn't work.:
b''.join(adb._streaming_command(b'root', b'', adb_info))
When I try the offical adb library it kind of works:
adb_commands.Root()
After running this command, I see it's been switched to root when I run on my CLI:
adb shell whoami
Although, I get this exception on my app:
ConnectionResetError: [Errno 54] Connection reset by peer
Currently, I have a workaround to make it work - I use the offical library in order to move to root mode and I catch the above exception so I could continue working with the ADB.
What do you think?
from adb_shell.
How did you check that b''.join(adb._streaming_command(b'root', b'', adb_info))
didn't work? Was there any output from that command?
from adb_shell.
The command above that you ran using adb-shell
is exactly equivalent to the adb_commands.Root()
command in the adb
package, so I don't understand why one would work but not the other.
When you connect via CLI (i.e., using the ADB binary), I think that will break the connection established by the adb
and/or adb-shell
packages. I think that's what caused the ConnectionResetError
that you got. Furthermore, I'm not sure that running adb shell whoami
via CLI is a valid check that the command run by the adb
/ adb-shell
Python package actually got you root access; you should be able to run dev.shell("whoami")
in adb-shell
or dev.Shell("whoami")
in adb
to check this.
If you really want to know what's going on in adb-shell
, do
import logging
logging.getLogger().setLevel(logging.DEBUG)
# run the adb-shell commands from above
from adb_shell.
For reference:
adb
adb-shell
from adb_shell.
Any updates on this?
from adb_shell.
I agree, I saw that it's quite the same thing as well, I don't understand either why one works and the other doesn't... I just keep using both of the libraries :)
from adb_shell.
I pushed out a new release. If you install it via pip install --upgrade adb-shell
, you can try to gain root access via:
import logging
logging.getLogger().setLevel(logging.DEBUG) # show debugging log info
dev = AdbDeviceTcp(...) # fill in the arguments here
dev._service(b'root', b'')
from adb_shell.
Interesting, I'll try and keep you posted
from adb_shell.
Not working for me... :|
File "ADB.py", line 20, in __init__
dev._service(b'root', b'')
File "server/env/lib/python3.7/site-packages/adb_shell/adb_device.py", line 404, in _service
return b''.join(self._streaming_command(service, command, adb_info)).decode('utf8')
File "server/env/lib/python3.7/site-packages/adb_shell/adb_device.py", line 1011, in _streaming_command
self._open(b'%s:%s' % (service, command), adb_info)
File "server/env/lib/python3.7/site-packages/adb_shell/adb_device.py", line 795, in _open
self._send(msg, adb_info)
File "server/env/lib/python3.7/site-packages/adb_shell/adb_device.py", line 980, in _send
self._handle.bulk_write(msg.pack(), adb_info.timeout_s)
File "server/env/lib/python3.7/site-packages/adb_shell/handle/tcp_handle.py", line 151, in bulk_write
_, writeable, _ = select.select([], [self._connection], [], timeout)
TypeError: argument must be an int, or have a fileno() method.
from adb_shell.
I forgot: you have to connect to the device.
import os
from adb_shell.adb_device import AdbDeviceTcp
from adb_shell.auth.sign_pythonrsa import PythonRSASigner
import logging
logging.getLogger().setLevel(logging.DEBUG) # show debugging log info
with open(os.path.expanduser('~/.android/adbkey')) as f: # update the path to the key file accordingly
priv = f.read()
signer = PythonRSASigner('', priv)
dev = AdbDeviceTcp('192.168.0.222', 5555, default_timeout_s=9.)
dev.connect(rsa_keys=[signer], auth_timeout_s=0.1)
dev._service(b'root', b'')
print(dev.shell('whoami'))
from adb_shell.
@alonroth have you tried using the latest code that I posted?
from adb_shell.
import os from adb_shell.adb_device import AdbDeviceTcp from adb_shell.auth.sign_pythonrsa import PythonRSASigner import logging logging.getLogger().setLevel(logging.DEBUG) # show debugging log info with open(os.path.expanduser('~/.android/adbkey')) as f: # update the path to the key file accordingly priv = f.read() signer = PythonRSASigner('', priv) dev = AdbDeviceTcp('192.168.0.222', 5555, default_timeout_s=9.) dev.connect(rsa_keys=[signer], auth_timeout_s=0.1) dev._service(b'root', b'') print(dev.shell('whoami'))
@Halastra or @matthieuxyz, can either of you confirm that the above code snippet successfully gets root access? You'll need to be running version 0.1.2 of adb-shell
or newer.
from adb_shell.
I don't have a rooted device at the moment. Sorry.
from adb_shell.
Neither do I, sorry.
from adb_shell.
Test with current master branch.
Device_Info: Android 6.0.1
import os
from adb_shell.adb_device import AdbDeviceTcp
from adb_shell.auth.sign_pythonrsa import PythonRSASigner
import logging
logging.getLogger().setLevel(logging.DEBUG) # show debugging log info
with open(os.path.expanduser('~/.android/adbkey')) as f: # update the path to the key file accordingly
priv = f.read()
signer = PythonRSASigner('', priv)
dev = AdbDeviceTcp('x.x.x.x', 5555, default_timeout_s=9.)
dev.connect(rsa_keys=[signer], auth_timeout_s=0.1)
dev._service(b'root', b'')
print("dev.shell('whoami'): {}".format(dev.shell('whoami')))
print("dev.shell('su -c whoami'): {}".format(dev.shell('su -c whoami')))
>>>dev.shell('whoami'): shell
>>>dev.shell('su -c whoami'): root
from adb_shell.
@dark-lbp thanks for testing! I'll add a root
method and close out this issue.
from adb_shell.
Closed via #92
from adb_shell.
Related Issues (20)
- Old adb server version (31) is not supported using AdbDeviceTcp HOT 11
- Issue in connecting adb over usb HOT 9
- Test failures with Python 3.10 HOT 1
- Using pull on BytesIO object HOT 3
- Pushing large files always timeouts HOT 12
- Implement the pair command for Android 11+ devices HOT 6
- How to connect more than two devices at the same time? HOT 3
- AdbDeviceUsb not working with MacOS X due to error 'LIBUSB_ERROR_ACCESS [-3]' HOT 2
- default_transport_timeout_s is ignored HOT 1
- Add support for pulling directories HOT 2
- usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3] HOT 2
- adb server claims usb device: results in USBErrorBusy
- Feature request install package analog to adb install HOT 4
- get return code of shell command HOT 4
- How can I get access to the device with password to adb? HOT 5
- Add adb forward functionality
- packaging this project for Debian HOT 3
- Improvement
- Streaming Shell doesn't result in a stream ?
- usb1.USBErrorBusy: LIBUSB_ERROR_BUSY [-6] when connect to device HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adb_shell.