[WIP][GUIDE] Adb beginner to Pro[In-Depth] - Android Software/Hacking General [Developers Only]

A thanks here would be highly appreciated :good::good::good:
Any developing you take with Android you need ADB its the acronym fo Android Debugging Bridge
Today I am going to show you how to use Adb , how to build it , how to play with its source
Beginner ​Lets introduce to you adb
Think adb as your messenger ,
You type a message / command
Then that message is taken by adb and delivered to the phone
the phone client would execute or perform any necessary tasks
Installing Adb
HOW TO INSTALL ADB [Linux]
On Ubunutu
Code:
sudo apt-get install android-tools-adb android-tools-fastboot
{I Need more distro's command if you know please contact me}
HOW TO INSTALL ADB ON WINDOWS
http://forum.xda-developers.com/showthread.php?p=48915118
Lets Now play with basic adb commands
================================================================================================
adb devices : This allows you to confirm that your pc and device are communicating
syntax
Code:
adb devices
adb pull : This allows you to pull specific files from the device
syntax
Code:
adb pull /sdcard/you_know_what.jpg
adb push : This allows you to send specific files to the device
syntax
Code:
adb push file.txt /sdcard/0/
================================================================================================
adb reboot : You can guess the command's function by looking at it and you were probably right it just "reboot" your phone
syntax
Code:
adb reboot
adb reboot-bootloader : This is same as its parent (adb reboot) but instead of rebooting to Android OS it boots to the bootloader
adb reboot-recovery : This is same as its parent (adb reboot) but instead of rebooting to Android OS it boots to the recovery
================================================================================================
adb shell : This executes a command on the device
Info : You can just pass a single command to the device to execute or you can also open an interactive shell
syntax ( single command ) :
Code:
adb shell [I]command[/I]
synatx ( interactive shell ) :
Code:
adb shell [ENTER]
command"s"
adb sideload : ADB sideload is a different ADB mode that you can use to push and install a zip using one command from your computer
Info : This was introduced in Jelly Bean Aosp
syntax :
Code:
adb sideload /sdcard/0/rom.zip
================================================================================================
adb install : This allows you to install any apps on the device using adb
syntax :
Code:
adb install TheApp.apk
info : running adb install with -r flag makes it install the app on the sdcard of the device (if the rom supports it)
adb uninstall : This allows you to uninstall an app on the device
syntax :
Code:
adb uninstall com.company.appname
info : using -k option uninstalls the application while retaining the data/cache.
At the moment, there is no way to remove the remaining data.
You will have to reinstall the application with the same signature, and fully uninstall it.
adb logcat : This allows you to access the logs / events of the system/apps
syntax :
Code:
adb logcat
{I would do a more in-depth synopsis of these command in my next post}
================================================================================================

Great post! This will be an excellent tool for anyone wanting to learn adb.

================================================================================================
After you have played with adb now lets gets the level
Amateur​Now after playing with commands your curiosity has risen and you want to know How does adb work ?
let me break the confusion
Adb has 3 major components
Adb client
adb server
adb daemon (adbd)
Lets see what each of them does
================================================================================================
adb server : You can consider this as a daemon running on the PC . It manages the communication between the adb client and adbd daemon. Its purpose if to sense the USB ports to know when devices are attached/removed, as well as when emulator instances start/stop.It thus maintains a list of "connected devices" and assigns a 'state' to each one of them: OFFLINE, BOOTLOADER, RECOVERY or ONLINE
================================================================================================
adb client: This is the clients that communicates with the server to give commands. It first tries to locate the ADB server on the host machine, and will start one automatically if none is found.
================================================================================================
Info: At this moment a single 'adb' binary is used for both the server and client
================================================================================================
adbd : The daemon runs on the device side and listens for for the commands on the usb or tcp. The adb server tries to communicate with the adbd daemon, if the connection is made then it labels the device as online else if , the connection to the device is made but the server cant communicate with the adbd then the device is labelled as offline.
In Android adbd is started when the data partition is mounted it is started by init.usb.{ro.hardware}.rc you can mod it to run earlier on your rom builds
================================================================================================

================================================================================================
Now lets move on to the next level
PROFESSIONAL​Before Moving in here please see familiarize your self with Android Building
After you have followed the guide , Now lets start building the adb
Prepare the environment
Code:
source ./build/envsetup.sh
lunch lineage_devicecodename-eng
mka adb fastboot
Now you can check $OUT directory for the executable
Code:
which adb
which fastboot
================================================================================================
Lets first see how the communication between the client and the adb server works
The adb server listens on tcp::localhost:5037
A diagram representing the structure
A Graphic by forum.xda-developers.com wiki
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
so the client connects to tcp:localhost:5037 and sends a request in the following way
A 4-byte hexadecimal string giving the length of the command
And then followed by the command itself
so a million dollar question how does the adb server responds to the client ?
Server would respond in 2 ways :
For success, the 4-byte "OKAY" string
For failure, the 4-byte "FAIL" string, followed by a 4-byte hex length, followed by a string giving the reason for failure.
Note : In a special case of adb's version the a 4-byte hex string corresponding to the server's internal version number would be returned
Note : For different commands the behavior is different so I would make a separate post About it
================================================================================================
Now for building the adb as you have already see you use mka adb fastboot
The main thing over here is Android.mk of the adb and the folder structure
Lets start by counting the number of modules built by the Android.mk
LOCAL_MODULE := libadbd
LOCAL_MODULE := libadb
LOCAL_MODULE := adbd_test
LOCAL_MODULE := libdiagnose_usb
LOCAL_MODULE := adb_test
LOCAL_MODULE := adb
LOCAL_MODULE := adbd
So these were the 7 module built by it
================================================================================================
Now I would leave you on your own to figure the source code ( i made it quite easy , didnt i ? )
I would continue writing in my next post how do the commands execution work
So this was the end of the professional I hope you learnt something If you need more stuff here please contact me
[WIP][If anyone can do the diagrams it would be a huge help i would give you the whole credit for images]

Related

[GUIDE]All About ANDROID SDK/AVD {Install/AVDs/Root/ADB}

ALL ABOUT ANDROID SOFTWARE DEVELOPMENT KIT\ANDROID VIRTUAL DEVICE(SDK\AVD)​
What we are going to learn?
What is Android SDK?
Installing SDK
Creating and Managing AVDs
Configuring ADB on your Computer
Root your Android Emulator
Thats It!
Part 1 - What is Android SDK?
​
Android Software Development Kit (abbreviation Android SDK) is an application which allows users to run and manage Virtual Android Emulator.
The Android Software Development Kit (SDK) includes a comprehensive set of development tools. These include a debugger, libraries, a handset emulator based on QEMU, documentation, sample code, and tutorials. Currently supported development platforms include computers running Linux (any modern desktop Linux distribution), Mac OS X 10.5.8 or later, Windows XP or later. The officially supported integrated development environment (IDE) is Eclipse using the Android Development Tools (ADT) Plugin, though IntelliJ IDEA IDE (all editions) fully supports Android development out of the box, and NetBeans IDE also supports Android development via a plugin. Additionally, developers may use any text editor to edit Java and XML files, then use command line tools (Java Development Kit and Apache Ant are required) to create, build and debug Android applications as well as control attached Android devices (e.g., triggering a reboot, installing software package(s) remotely).
Enhancements to Android's SDK go hand in hand with the overall Android platform development. The SDK also supports older versions of the Android platform in case developers wish to target their applications at older devices. Development tools are downloadable components, so after one has downloaded the latest version and platform, older platforms and tools can also be downloaded for compatibility testing.
Android applications are packaged in .apk format and stored under /data/app folder on the Android OS (the folder is accessible only to the root user for security reasons). APK package contains .dex files (compiled byte code files called Dalvik executables), resource files, etc.
Source :- Wikipedia
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Click to expand...
Click to collapse
Part 2 - Installing SDK and AVD Manager​
Make sure you have JAVA Installed.....otherwise NOTHING will work...
WINDOWS
1. Download the SDK setup from here > http://developer.android.com/sdk/index.html
2. Install the SDK and choose a short directory to install (C:\....).
3. After you have installed your SDK, Open It and Check Mark the following package :- Tools
4. Wait for it to Download...It will take some time...Be patient...
Click to expand...
Click to collapse
MAC
Go here to get a guide on HOW TO INSTALL SDK ON MAC
Click to expand...
Click to collapse
Here is a video Guide too
Click to expand...
Click to collapse
LINUX
Go here to get a guide on HOW TO INSTALL SDK ON LINUX
Click to expand...
Click to collapse
Part 3 - Creating and Managing AVDs​
1. Go to your android-sdk directory and start/run "SDK Manager.exe"
2. Select the platform that you want to download.
3. Click on "Install X Packages" where "X" is the no. of packages you have selected to download.
4. After downloading has finished which will take around 30 minutes on a descent speed internet select "Tools" from the Main Menu bar
at the top of the window and select Manage AVDs..........
5. A New window will open which is the AVD MANAGER.
6. In the Android Virtual Devices tab SELECT "New" to create a new AVD.
7. Enter the following things:
AVD NAME: Type the desired name that you want for your AVD
Device: Select the AVD resolution as per the device options
Target: Select the Android version you downloaded
CPU/ABI: Select Intel Atom (x86) for 32-bit and ARM (armeabi-v7) for 64-bit.
Keyboard: Check this box if you want to use your keyboard in the AVD
Skin: Check this box if you want to get the hardware buttons
Front Camera: Use this option if you have a webcam and want to use it in the AVD
Back Camera: Use this option if you have a webcam and want to use it in the AVD
Memory Options
RAM: Set this to 768 (maximum for Windows user) or 1024 (maximum for Ubuntu users
VM Heap: Set this to 100
Internel Storage: Set this to 4 and Select "GiB" from this drop down list from side by.
SD Card: Select "Size" and Enter 4 and Select "GiB" from this drop down list from side by.
Emulation Options
Snapshot: Just check mark this option. (Not really neccessary)
Use Host GPU: Check mark this option if you want to use the computers graphics.
*****NOTE: REMEMBER THESE TWO OPTIONS ("SNAPSHOT" and "USE HOST GPU") CANNOT BE USED SIMULTANEOUSLY. IT WILL GIVE YOU AN ERROR.*****
7. Now click OK and wait for few seconds. It will come up with a dialog box which will show you the details of the AVD you created and a message that your AVD has been created.
8. Running the AVD
Highlight the AVD you have created and click "Start..." on the left of the window.
and ENJOYYYY......
Click to expand...
Click to collapse
Part 4 - Configuring ADB on your Computer​
Configuring ADB (Android Debug Bridge) on your Windows allows you to run adb from anywhere. Hence you always do not have to "cd" to the android-sdk directory.
1. Right click on "My Computer" and select "Properties".
2. Go to "Advanced system settings" and open "Environment Variables".
3. Now under System Variables, click "New"
and enter the following details:-
Variable name: Type in ADB.....
Variable Value: Type here the path of your ADB preceeded by a ";" (SEMI-COLON)
FOR EG: If the path to your ADB is (by default) "C:\Program Files\Android\android-sdk\platform-tools\adb.exe"
THEN YOUR variable path would be :" ;C:\Program Files\Android\android-sdk\platform-tools\adb.exe "
AND CLICK "OK".....
4. After having done with this Search for "Path" in System Variables.
5. Double click on it to edit "Variable Value" and add these lines at the end of it:-
;<PATH_TO_YOUR_ADB> where "<PATH_TO_YOUR_ADB>" is the directory where your ADB is located.
6. Save all these changes by clicking "OK".... and you are done .........
NOW YOU CAN TYPE "adb" ANYWHERE IN CMD AND IT WILL RECOGNIZE IT AS A PROGRAM....
Click to expand...
Click to collapse
Part 5 - Root Your Android Emulator​
Want to get more fun on your Android Emulator.....
GET IT ROOTED....
NOTE: YOU MUST HAVE ADB CONFIGURED....... I HAVE TESTED THIS ROOTING METHOD ON API LEVEL 16 ( JELLY BEAN 4.1.2) AND IT WORKS ABSOLUTELY FINE NOT SURE ABOUT OTHERS.....
1. Download the ROOT package from here.
2. Extract the package to somewhere like desktop.
3. Browse to your android-sdk/tools directory and Hold Shift and then right click to get an Advanced Menu. Click on "Open Command Window Here" and type the following command:-
Code:
emulator -avd <YOUR_AVD_NAME> -partition-size 512
NOTE:- DO NOT CLOSE THE COMMAND PROMPT WINDOW OTHERWISE THE EMULATOR WILL CLOSE
4. Now go to Desktop and again hold Shift and right click and Select "Open Command Window Here" and type the following commands one by one:-
Code:
adb connect 127.0.0.1:5554
adb root
adb remount
adb push Superuser.apk /system/app/
adb push su /system/bin/su
adb push su /system/sbin/su
adb push su /system/xbin/su
adb shell chmod 6755 /system/bin/su
adb shell chmod 6755 /system/sbin/su
adb shell chmod 6755 /system/xbin/su
adb kill-server
adb start-server
YOHO............... We are now rooted haha
Click to expand...
Click to collapse
Want to know anything more....Just post it here.....and I'll help you back.... ​
Have I missed something....Please remind me....
Hi
Thanks for this, exactly what i was looking for.
But I find that after I have expanded the /system partition when i restart the AVD it starts with a 211M sized partition. unless i start it from the command line.
Is there any way to change the ini file or the avd manager to start it with 512M /system ?
Also the SU didn't work, I had to grab one of my working phone.. (there was a hex error code)
/system/bin/sh: /system/xbin/su: not executable: magic 7F45
actually spoke way to early no I find the /system partition doesn't save a cross reboots
last edit.
found http://www.ehalm.at/avd-4.3-gapps.php?l=en
has a pre built 4.3 system img with all the goodies installed
Hello and thanks for your OP.
Do you have the binaries for Intel? Intel emulators being way faster, I'd rather root an intel AVD than use ARM.
Also, is there a way to make SU survive reboots? It's very annoying to have to repeat those steps each time.
error: device not found
Thanks for this guide. Had me thinking of how to connect a AVD to adb since there is no USB to physically plug in.
I did try the loopback address, with the right port, but that is as far as I have got:
Code:
[email protected]:~/Build/android-sdk-linux/tools$ sudo adb connect 127.0.0.1:5554
[sudo] password for joel:
connected to 127.0.0.1:5554
[email protected]:~/Build/android-sdk-linux/tools$ sudo adb root
error: device not found
[email protected]:~/Build/android-sdk-linux/tools$ sudo adb devices
List of devices attached
[email protected]:~/Build/android-sdk-linux/tools$
Is there anything I am doing wrong? I know your guide (mostly) is for windows, but it would seem strange for me to emulate Android in an emulated Windows environment (running Debian GNU/Linux v7).
UPDATE: Figured it out, once I used the ./adb command in platform-tools.

[APP][2.2+] Remote ADB Shell

Overview
Remote ADB Shell is a simple terminal app that allows you to connect to the ADB shell service of another Android device over the network. This works in the exact same way that the "adb shell" command works on a computer. Because this app uses a native implementation of the ADB protocol in Java, it does not require root on either device or any 3rd party apps on the target device. The devices simply speak the same protocol to each other that they would to a computer running the ADB client from the Android SDK.
Features
Command history (accessible by long pressing the command box)
Send Ctrl+C (accessible by long pressing the terminal view)
Auto-scroll (with toggle accessible by long pressing the terminal view)
Screenshots
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Instructions
IMPORTANT: Android 4.2.2+ devices use RSA keys to authenticate the ADB connection. These devices will need to be plugged in to a computer the first time you connect to them (from each device with this app installed). This allows them to display the public key acceptance dialog, which you must accept (and check "Always allow from this computer").
To configure a stock un-rooted target, plug the target device into a computer and run "adb tcpip 5555". This will start ADB listening on port 5555 on the target device. The device can then be unplugged and will remain configured properly until reboot.
For devices that are rooted (although it's not required), you can install one of the several "ADB WiFi" apps to enable the ADB server to listen over the network. Devices with a custom ROM may have an option to enable ADB over the network in the Developer Options pane of Settings. Using either of these methods will properly configure ADB for network access with this app. The extra step for 4.2.2+ is still required for the initial connection.
To connect to your remote Android device, type in the IP address of the device and the port number (5555 from the example above) in Remote ADB Shell. Tap Connect and it will attempt to connect to the device and start up the terminal.
Notes
This app is unique because it runs a custom ADB implementation that I wrote from scratch in Java. I plan to open-source my ADB implementation on GitHub or Google Code once I give it a bit of cleanup and documentation. Using this custom ADB implementation means that I don't require an ADB binary or root on the device running the app. Because it speaks standard ADB, it doesn't require anything special on the target either.
Please post feature requests or suggestions here and I'll do my best to work on them.
Download
The app is available on Google Play for free. https://play.google.com/store/apps/details?id=com.cgutman.androidremotedebugger
Hi, cgutman - I actually have a feature request.
But first, let me say thank you for providing this featureset in an app I already have gotten a fair amount of use out of it.
Backstory:
I use adb shell commands to automate repetitive processes on a Fire TV (Android Settop Box, connected to a TV, runs apps), like launching certain apps, performing certain actions - and so on.
I actually have about 20 actions across multiple Applescript apps on the Mac that allow me to remote controll apps like Spotify or Pandora - and your app allows me to do that from an Android device (smartphone) as well.
That said - I run into two major speedbumps.
Without a "Bookmarks" feature (store a certain shell script, give it a name, be able to edit it, execute it on click), so far I can only effectively cycle through two scripts (using the "recent history" feature in your app) - and I'd like to be able to use 20+ scripts eventually. A bookmark list (sorted by name) would be great for my purpose.
Second - to really be able to speed up the use of those items a launcher shortcut feature would be great. It could look up and reference the bookmark entries from the suggestion above - or let you set an IP and enter a command in the shortcut dialogue (Terminal Emulator does it that way). Maybe even with an auto exit option (although "&& exit" works just as well right now (*yay*) - but people would have to know to use it). Also it should allow you to name the shortcut, before creating it.
The reason why this would be great is to reduce steps. Right now I have to open the app, connect to the remote Android device, longpress on the command line entry field, select a history item, press enter - press OK once the app has finished the script, then exit the app.
It would be great to be able to automate all of this down to one launcher shortcut click.
To give you an Idea - what I am using the app for currently - here is one of the scripts I wrote today:
Code:
monkey -p com.netease.cloudmusic 1 && sleep 5 && input tap 960 978 && sleep 0.8 && input keyevent 19 && input keyevent 19 && input keyevent 19 && sleep 0.3 && input keyevent 20 && input keyevent 20 && input keyevent 20 && sleep 0.3 && input tap 50 960 && sleep 0.8 && exit
This opens the netease app and starts the "daily recommended" playlist.
Code:
input tap 60 100 && sleep 0.8 && input tap 60 100 && sleep 0.8 && input tap 60 100 && sleep 0.8 && input tap 1444 1030 && sleep 0.8 && exit
This exits the app cleanly - and so on...
Again - I've set up dozens of scripts like that on my Mac to be able to navigate Pandora, and spotify - to pull files, make screenshots, and so on and so forth. If you could implement said features (again - Terminal Emulator has them.. ) - your app would allow me to realize the same functionality on my smartphone.
Thank you for reading through my posting and contemplating the idea -
so long
h.
edit: Also thank you for already exiting the session cleanly (adb disconnect) once you type in exit. The Fire TV only allows one adb session at a time, so this is great.
Found a way to make the app a little more usable "as is" for my purposes in the meantime. Part of my problem was, that the shell scripts turned out quite complex - so I couldnt run several of them - because they weren't instantly recognizable on the run history level.
The temporary workaround for me was to move the commands as shell scripts to a folder (I named "shell") in /system on the target device and make them executable. That way the history in Remote ADB Shell stays cleaner and is better parseable by humans.
This is what it looks like now:
http://i.imgur.com/AuGFZ0a.png
Just right. Thank you.
Love this app! However I would like to ask if it were possible to send adb commands from outside the app using apps like Tasker. This could already simply be done by sending your app and intent with the ip, port and command.
I just created a Tasker Plugin myself using the AdbLib library! Have a look if you like https://play.google.com/store/apps/details?id=com.ADBPlugin
Trying to connect to my phone but I am not getting device authorization messages.
Great application, thank you.
My task:
- - the device has no Root
- in the directory / tmp there is a binary file su and SuperSU.apк for this device
- How to launch an "adb root shell tcpip:5555" using your application on the this device?
may be:?
1) adb tcpip:5555
2) adb root
3) adb tcpip:5555
4) adb remount
5) "adb shell"
6) or without "adb shell" -> adb pull ... adb pushh... adb reboot...
This is possible?
Or is this impossible in principle?
I'm having trouble installing apk's with this. The normal command that I use on Windows doesn't seem to work...
Could it be having trouble finding the file on my phone while trying to send it to my fire stick?
Kranium31 said:
I'm having trouble installing apk's with this. The normal command that I use on Windows doesn't seem to work...
Could it be having trouble finding the file on my phone while trying to send it to my fire stick?
Click to expand...
Click to collapse
You can't, it's just "adb shell" commands (where you leave out the adb shell part), not "adb install" for instance.
---------- Post added at 12:23 AM ---------- Previous post was at 12:20 AM ----------
AS2107 said:
Great application, thank you.
My task:
- - the device has no Root
- in the directory / tmp there is a binary file su and SuperSU.apк for this device
- How to launch an "adb root shell tcpip:5555" using your application on the this device?
may be:?
1) adb tcpip:5555
2) adb root
3) adb tcpip:5555
4) adb remount
5) "adb shell"
6) or without "adb shell" -> adb pull ... adb pushh... adb reboot...
This is possible?
Or is this impossible in principle?
Click to expand...
Click to collapse
The app only connects via "adb shell", so only those commands are possible, so no "adb install", "adb tcpip" or whatever. It's like typing "adb shell" on a PC and then you're able to give direct commands to the phone like moving a file with "mv /sdcard/Download/file /sdcard"
Hello I am having an issue
I want to use the adb on my own device (meaning only one device is being used)
I am able to connect the adb shell but whenever I try to type the following command it gives the error adb not found
adb shell sh /sdcard/.chaozhuo.gameassistan2/inject.sh
If anyone knows what the issue is Plz help
Thanks in advance
I just bought a 2019 Nvidia Pro. I installed your Wolf Launch and was attempting to install a widget. A prompt appears and states my device doesn't support a widget and have to run an ADB shell. Troypoint has an app for a remote adb shell as so do others, but I cannot find one for a nvidia.
In the widget binding failure the code it is telling me to type is, appwidget grantbind --package com.wolf.firelauncher --user 0
I was all set to do this but the firelauncher gave me pause. The device I am attempting this on isa 2019 Nvidia Pro v.9.0.1 + hotfix 1
need confirmation this is the correct code for my device.
Thanks,

[TOOL] [LINUX/MAC/WINDOWS] Nexus Tools 5 (Featured by XDA)

Nexus Tools
Nexus Tools is a simple installer for the Android SDK Platform Tools package, which includes ADB, Fastboot, Systrace, and other applications. Nexus Tools is written in Dart, and can run on Linux, macOS, Windows, Windows Subsystem for Linux, and Chrome OS.
Nexus Tools downloads the latest Platform tools package directly from Google's servers (so you're always getting the latest version), saves them to ~/.nexustools, and adds the directory to your system's path. On Windows, Nexus Tools can optionally install Koush's Universal ADB Driver.
Once Nexus Tools is finished, you can run adb, fastboot, and other commands with no problems. You need to open a new terminal/command line window after installation for changes to take effect. The SDK Platform Tools can be updated by running nexustools -i, or you can uninstall everything by running nexustools -r.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
How to use on Linux, macOS, and Chrome OS
Paste this command into the Terminal app:
Code:
bash <(curl -s https://raw.githubusercontent.com/corbindavenport/nexus-tools/main/install.sh)
You can also download the Mac and Linux versions from the latest release page, un-zip the file, and run it from the Terminal.
Once Nexus Tools is finished, you can run adb, fastboot, and other commands straight from the terminal. You may need to open a new terminal window for changes to take effect. To update, just run the installer again.
How to use on Windows
Open Windows PowerShell from the Start Menu and paste this command:
Code:
iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/corbindavenport/nexus-tools/main/install.ps1'))
You can also download the Windows version from the latest release page, un-zip the file, and run it from Windows PowerShell or the Command Prompt.
New in Nexus Tools 3.0:
Cleaned up script code
Fixed udev list being installed on Mac OS X, even though OS X doesn't need it
Less output spam during installation
New logo
corbin052198 said:
New in Nexus Tools 3.0:
Cleaned up script code
Fixed udev list being installed on Mac OS X, even though OS X doesn't need it
Less output spam during installation
New logo
Click to expand...
Click to collapse
Hey, I appreciate your work mate. Nexus Tools has worked well on my Mac. Thanks for creating this tool set. Keep it up!
syintiphic said:
Hey, I appreciate your work mate. Nexus Tools has worked well on my Mac. Thanks for creating this tool set. Keep it up!
Click to expand...
Click to collapse
Glad it worked for you!
New in Nexus Tools 3.1:
Added smart remove (on Ubuntu and Debian linux, Nexus Tools will automatically check if the distro's ADB/Fastboot packages are present and allow you to uninstall them)
Changed udev rules list to automatically overwrite existing list
No longer installs udev list on Mac OS X (because it doesn't use it)
sorry to bother, but will this very useful tool be updated to the latest adb and fastboot versions ? afaik the last adb version is 1.0.35 and the current installed is 1.0.32.
thanks a lot in advance !
I've installed it but the terminal still says -bash: adb: command not found
where can i find 1.0.32? The adb version i have now is 1.0.31...
Any chance you can update the script to install ADB 1.0.36?
UPDATED: I downloaded the latest SDK Tools and moved the adb and fastboot binaries into the .nexustools folder and made the binaries executable using chmod +x on both binaries so now I have adb 1.0.36 and the latest fastboot
1619415 said:
Any chance you can update the script to install ADB 1.0.36?
UPDATED: I downloaded the latest SDK Tools and moved the adb and fastboot binaries into the .nexustools folder and made the binaries executable using chmod +x on both binaries so now I have adb 1.0.36 and the latest fastboot
Click to expand...
Click to collapse
Hey, would you be able to send me the adb and fastboot files? I don't have Android Studio installed on my Mac and so I can't use sdk tools to update my adb to 1.0.36. Thanks.
corbin052198 said:
Nexus Tools is an installer for the Android debug/development command-line tools ADB (Android Device Bridge) and Fastboot for Mac OS X and Linux. The script does not need to be downloaded, simply copy and paste this command into the terminal and run it to install ADB/Fastboot:
Code:
bash <(curl -s https://raw.githubusercontent.com/corbindavenport/nexus-tools/master/install.sh)
and this command to un-install Nexus Tools:
Code:
bash <(curl -s https://raw.githubusercontent.com/corbindavenport/nexus-tools/master/uninstall.sh)
Nexus Tools requires sudo privileges to install/uninstall the adb and fastboot tools to /usr/local/bin, so they can be run without typing the full directory. Nexus Tools is licensed under the GPLv3 license, and the source code is at the GitHub project below.
If you have a problem with Nexus Tools, leave a reply below or as an issue on the GitHub project!
GitHub Project
XDA News Article
Click to expand...
Click to collapse
Thank You so much. You are a life saver. This is amazing. Looked all over for this. It was hard to find.
Thank You.
1619415 said:
Any chance you can update the script to install ADB 1.0.36?
UPDATED: I downloaded the latest SDK Tools and moved the adb and fastboot binaries into the .nexustools folder and made the binaries executable using chmod +x on both binaries so now I have adb 1.0.36 and the latest fastboot
Click to expand...
Click to collapse
Also anyone that's on Linux another way to make adb/fastboot or any binary for that matter executable is to just put a " dot followed by a forward slash in front of your adb or fastboot command " like so...
./adb devices
./fastboot devices
Work like charm on el capitan, thanks for this quick an amazing script
1619415 said:
Any chance you can update the script to install ADB 1.0.36?
UPDATED: I downloaded the latest SDK Tools and moved the adb and fastboot binaries into the .nexustools folder and made the binaries executable using chmod +x on both binaries so now I have adb 1.0.36 and the latest fastboot
Click to expand...
Click to collapse
I ran your script today and ADB is showing 1.0.32 for me. Any way I can get it to 1.0.36?
Google Releases Separate ADB and Fastboot Binary Downloads
could some one tell me where to place the files i want to flash.. i'm not a pro thanks in advance
hjjiang said:
Google Releases Separate ADB and Fastboot Binary Downloads
Click to expand...
Click to collapse
thanks a ton you saved me a lot of time. thanks a lot
I just updated Nexus Tools to version 3.3, which updates the ADB/Fastboot binaries to the latest versions. Enjoy!
i try this but got a message
"Illegal instruction"
i also try
"PATH=~/.nexustools:$PATH"
but there is nothing happen
my computer is mac osx 10.6
how could i fix it
thank you
I can install and working well without any doubt till today.. using the copy of script directed to my terminal.. thanks alot

Making a simple ADB shell script.

So i am trying to make a simple shell script which will execute multiple ADB commands, here's what i have come up with.
#bin/sh
echo -------------------------------
echo Removing lockscreen ads...
echo -------------------------------
adb shell pm disable-user --user 0 com.amazon.kindle.kso
when i try to do, bash file.sh it just says bash is a unknown command, so what am i doing wrong?
ADB is a commandline tool to be run either on Windows OS, preferredly wrapped into a Windows CMD script, or in Android OS, preferredly wrapped into an Android shell script.
If you intend to run ADB commands in Android's terminal then a shell script would look like this
Code:
#!sbin/sh
ADB=/usr/bin/adb
"$ADB" shell "<COMMAND-HERE>"
jwoegerbauer said:
ADB is a commandline tool to be run either on Windows OS, preferredly wrapped into a Windows CMD script, or in Android OS, preferredly wrapped into an Android shell script.
If you intend to run ADB commands in Android's terminal then a shell script would look like this
Code:
#!sbin/sh
ADB=/usr/bin/adb
"$ADB" shell "<COMMAND-HERE>"
Click to expand...
Click to collapse
Okay, thank you. will try that right away
i could also use this in a windows batch file?(sorry bit of a noob about this )
ComputerTech312 said:
i could also use this in a windows batch file?(sorry bit of a noob about this )
Click to expand...
Click to collapse
If you'ld carefully read posts then you'll notice this question already get answered.
jwoegerbauer said:
If you'ld carefully read posts then you'll notice this question already get answered.
Click to expand...
Click to collapse
Apologies, i misread your post
What would the changes be to your code if it's a Windows CMD script? would changes to the path be required and such?
It really depends on what you're trying to do.
I wrote the following as a simple .bat file and ran it from my platform-tools directory on my Windows laptop:
@Echo Off
echo Checking for Devices.
adb devices
echo Is device present?
echo (Press Enter if yes, Ctrl+C or close Script if not)
pause
echo Rebooting to recovery.
adb reboot recovery
echo Waiting 30 seconds for reboot.
timeout /t 30
echo Checking for Devices.
adb devices
echo Is device present?
echo (Press Enter if yes, Ctrl+C or close Script if not)
pause
echo Decrypting Data in TWRP.
adb shell twrp decrypt ******
pause
Click to expand...
Click to collapse
And it does the following:
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
ComputerTech312 said:
What would the changes be to your code if it's a Windows CMD script? would changes to the path be required and such?
Click to expand...
Click to collapse
An Android shell script and a Windows bash script ( including a Powerpoint script ) are in all aspects different with regards to coding, this because Android shell scripts are coded using Linux synthax.
BTW:
To not have to dance on 2 weddings I create my scripts mainly as pure Android shell scripts, which I copy from PC to Android device, and then start executing it from PC by means of ADB using a Windows bash script.
Example Windows bash script:
Code:
@echo off
adb devices
adb push <ANDROID-SCRIPT-PATH-ON-PC-HERE> /tmp
adb shell "chmod 0755 /tmp/<ANDROID-SCRIPT-NAME-HERE>"
adb shell "cd /tmp; $(<ANDROID-SCRIPT-NAME-HERE>);"
adb shell "rm -f /tmp/<ANDROID-SCRIPT-NAME-HERE>"
Deleted member 1890170 said:
An Android shell script and a Windows bash script ( including a Powerpoint script ) are in all aspects different with regards to coding, this because Android shell scripts are coded using Linux synthax.
BTW:
To not have to dance on 2 weddings I create my scripts mainly as pure Android shell scripts, which I copy from PC to Android device, and then start executing it from PC by means of ADB using a Windows bash script.
Example Windows bash script:
Code:
@echo off
adb devices
adb push <ANDROID-SCRIPT-PATH-ON-PC-HERE> /tmp
adb shell "chmod 0755 /tmp/<ANDROID-SCRIPT-NAME-HERE>"
adb shell "cd /tmp; $(<ANDROID-SCRIPT-NAME-HERE>);"
adb shell "rm -f /tmp/<ANDROID-SCRIPT-NAME-HERE>"
Click to expand...
Click to collapse
I am doing similar adb commands but from a bash script on a PC connected only via wifi to android box.
FYI, unlike a phone these Android 11 devices are not recognized by Windows11 when connected via a USB cable.
Commands I issue are things like
$ADB_CMD shell pm uninstall org.courville.nova
Before I can use these varous ADB commands I have to
(1) manually add the box to my wifi (via a mini-keyboard attached to android box)
(2) figure out which IP it was assigned by my router
(3) update my script with the correct IP to it can issue all the $ADB_CMD = eg. "../ADB -s 192.168.123:5555"
(4) run the script
I would like to skip steps 1..3, so the idea of running a similar script on the android box is very attractive.
(1) prepare a usb thumbdrive with a script, aps, ... and plug it into the android device
(2) use the filemanager on the device to execute the script
(3) done (ie. never have to connect to wifi).
What do you suggest doing?
I assumed by the nature of it's name "bridge" that ADB is meant to be run over a connection?
Ideally I would like to install nothing on the android device but I would not mind if a script installed some apk from the thumbdrive and then de-installed it.
The device is rooted.
Can you actually get some shell prompt on Android? or does it require an app to be installed.
I saw references to /usr/bin/sh I have no idea how to start one
Thank you for helping out.
Short answer: use
SH Script Runner for Android - APK Download
Download SH Script Runner apk 1.10 for Android. Bash script runner and shell command executor with superuser functionality.
apkpure.com
app to run scripts on Android device without the need of ADB
.
xXx yYy said:
.
xXx yYy said:
Short answer: use
SH Script Runner for Android - APK Download
Download SH Script Runner apk 1.10 for Android. Bash script runner and shell command executor with superuser functionality.
apkpure.com
app to run scripts on Android device without the need of ADB
Click to expand...
Click to collapse
Click to expand...
Click to collapse
So I downloaded SH Script Runner_v1.10_apkpure.com.apk onto a thumbdrive
I insert it into the android device I have to install it manually?
can you provide a sample script.sh that would run the equivalent of I can take it from there
$ADB_CMD shell pm uninstall org.courville.nova
...
I went ahead and installed the SH Script Runner it looks like it's designed to create/manage several scripts. I am not sure I understand yet it's flow.
When accessing the upper-right menu ... "open local script" It does not appear to let me browse other than internal /sdcard IOW, it does not seem to list my connected thumbdrive like this simple FileManager or X-plore would.
Once I understand the syntax of this script.sh I will convert my current make.sh and take it over the android device.
I do all my script editing on a PC with VScode editor.
Thank you for your guidance.
SH Script Runner is both a script editor and script executor, means write your code into this editor and run the script.
Example:
Code:
pm uninstall org.courville.nova

Question Resolve "adbd cannot run as root in production builds"

Hi!
I'm running Android 13. I've used Magisk to root the device but the command
Code:
adb root
results in
Code:
adbd cannot run as root in production builds
I already tried "adbd Insecure v2.00.apk" but it fails with the message
Code:
Could not patch adbd !
Is there a way to fix this?
you can overlay /system/bin/adbd with magisk module. create new directory in /data/adb/modules and place your files
Code:
/data/adb/modules/my_module/system/bin/adbd
/data/adb/modules/my_module/module.prop
https://topjohnwu.github.io/Magisk/guides.html#magisk-modules
or escalate to privileged shell and stream file content over stdin/stdout (linux only)
Code:
adb shell "su -c 'dd bs=1m if=/dev/block/bootdevice/by-name/boot 2> /dev/null'" > boot.img
adb shell "su -c 'dd bs=1m of=/dev/block/bootdevice/by-name/boot'" < path/to/boot.img
alecxs said:
you can overlay /system/bin/adbd with magisk module. create new directory in /data/adb/modules and place your files
Code:
/data/adb/modules/my_module/system/bin/adbd
/data/adb/modules/my_module/module.prop
https://topjohnwu.github.io/Magisk/guides.html#magisk-modules
or escalate to privileged shell and stream file content over stdin/stdout (linux only)
Code:
adb shell "su -c 'dd bs=1m if=/dev/block/bootdevice/by-name/boot 2> /dev/null'" > boot.img
adb shell "su -c 'dd bs=1m of=/dev/block/bootdevice/by-name/boot'" < path/to/boot.img
Click to expand...
Click to collapse
Thank you very much for your reply.
How would method 1 work? I find a different binary of adbd that has the root feature enabled and overlay the original with it through a Magisk module?
mattdeox said:
I already tried "adbd Insecure v2.00.apk" but it fails with the message
Click to expand...
Click to collapse
you found already, just unzip the assets/adbd.21.png from apk
alecxs said:
you found already, just unzip the assets/adbd.21.png from apk
Click to expand...
Click to collapse
I checked the file you mentioned and it has those contents:
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
What should I do with them?
mattdeox said:
. I've used Magisk to root the device but the command
Code:
adb root
results in
Code:
adbd cannot run as root in production builds
Click to expand...
Click to collapse
Why do you need this?
WoKoschekk said:
Why do you need this?
Click to expand...
Click to collapse
I would like to do some automated testing on my device using Appium to check if my website works correctly.
As I understood, adb root is needed to do it properly.
just rename the file > adbd
/data/data/eu.chainfire.adbd/files/adbd.21.png: ELF executable, 32-bit LSB arm, static, stripped
mattdeox said:
I would like to do some automated testing on my device using Appium to check if my website works correctly.
As I understood, adb root is needed to do it properly.
Click to expand...
Click to collapse
Basically: ADB is a commandline tool which acts as a client-server programm. You send ADB commands (usually from a desktop PC, but also possible from a rooted mobile) as a client to the adbd (daemon) on another device. The adbd executes those commands on the other device as user:shell. If you want the adbd acts as user:root then you have to execute adb root. BUT it's not possible to grant the adbd root permissions on a stock ROM (production builds). Even if the other device is rooted with Magisk it's still a production build!
The only way to execute commands as root via ADB on another device is
Code:
adb shell
su
alecxs said:
just rename the file > adbd
/data/data/eu.chainfire.adbd/files/adbd.21.png: ELF executable, 32-bit LSB arm, static, stripped
Click to expand...
Click to collapse
I created the structure you recommended
Code:
/data/adb/modules/adbRoot/module.prop
/data/adb/modules/adbRoot/system/bin/adbd
I opened Magisk and could see the module enabled.
Then restarted adbd
Code:
setprop ctl.restart adbd
But there was still the error
adbd cannot run as root in production builds
Click to expand...
Click to collapse
Then I found out on this page https://source.android.com/docs/core/ota/modular-system/adbd
that adbd moved on Android 13, supposedly to this location:
Code:
/apex/com.android.adbd/bin/adbd
Then I also created this file for the Magisk module
Code:
/data/adb/modules/adbRoot/system/apex/com.android.adbd/bin/adbd
Again, I restarted adb
Code:
setprop ctl.restart adbd
But the result still is the same
adbd cannot run as root in production builds
Click to expand...
Click to collapse
Anything else I could do/something that is wrong?
WoKoschekk said:
Basically: ADB is a commandline tool which acts as a client-server programm. You send ADB commands (usually from a desktop PC, but also possible from a rooted mobile) as a client to the adbd (daemon) on another device. The adbd executes those commands on the other device as user:shell. If you want the adbd acts as user:root then you have to execute adb root. BUT it's not possible to grant the adbd root permissions on a stock ROM (production builds). Even if the other device is rooted with Magisk it's still a production build!
The only way to execute commands as root via ADB on another device is
Code:
adb shell
su
Click to expand...
Click to collapse
Thank you very much for your input.
Are you saying there is nothing that can be done by replacing the adbd file or the config?
Do you think the solution by alecxs to replace the binary is not working?
mattdeox said:
Thank you very much for your input.
Are you saying there is nothing that can be done by replacing the adbd file or the config?
Do you think the solution by alecxs to replace the binary is not working?
Click to expand...
Click to collapse
Still do not understand the reason. Assume the command adb root is successful. how to proceed then?
Here's what you need for adb root:
daemon/main.cpp - platform/system/adb - Git at Google
These criterias have to be met to execute adb root.
In case the adbd gets root permissions, then you keep the privileges to run:
Code:
adb disable-verity
enable-verity
sideload OTAPACKAGE
remount [-R]
unroot
(For further information see 'adb help')
All the other ADB commands don't require the adbd to be rooted.
the insecure adbd by @Chainfire according to this logcat requires some additional sepolicy rules and probably therefore does not work with magisk out of the box.
found some magisk modules, maybe one of these binaries work for android 13 if you place it system/apex
[MODULE] Insecure adbd for Pixel devices
Hi everyone, I made a simple module for my own needs and I figured I'd share it here as well. This module enables "insecure adbd" on Pixel devices, which allows you to restart adbd in root mode via "adb root" and push/pull to/from the /data...
forum.xda-developers.com
[MODULE] Debugging modules: ADB Root, SELinux Permissive, Enable Eng
These modules are not meant for everyday use. They are intended for debugging and modification of a firmware. They significantly lower security of your device while active and even could softbrick it. You've been warned. ADB Root Magisk Module...
forum.xda-developers.com
Do I understand correctly:
To use/install the patched adbd I need a device with root permissions. Otherwise it wouldn't be possible to copy the adbd to /system/bin and make it executable. Having that patched adbd in /system/bin, I'm able to use the command adb root which let's me execute ADB commands with root permissions.
Why not using
Code:
adb shell
su
? Why I need a adbd with root permissions on a rooted device?
@WoKoschekk most likely he don't need it. we don't know. but there are cases where it can be useful, for example
Code:
adb pull /dev/block/bootdevice/by-name/userdata
alecxs said:
@WoKoschekk most likely he don't need it. we don't know. but there are cases where it can be useful, for example
Code:
adb pull /dev/block/bootdevice/by-name/userdata
Click to expand...
Click to collapse
Apart from the fact that it's not possible to restore such an image (e.g. corrupted encryption) you have to copy 128GB (minus the system) or more via USB. There is a reason why TWRP saves the data as a TAR archive and splits it into 1GB chunks.
I know there are more examples for a rooted adbd. But it could all be done in a root shell, too.
TWRP is useful for backup only if encryption is supported, which is not the case for Samsung encryption. But for forensic and recovery of deleted files full partition image is required. on FBE that /dev/block/bootdevice/by-name/userdata is already decrypted during runtime. for FDE one must adb pull /dev/block/dm-0 or whatever is mounted /data of course. Restoring works fine btw. just some encryption related files (like locksettings.db) must deleted.
I have posted workaround for streaming partitions with su (refer to 2. method in post #2) but it does not work on windows (not even with dos2unix)
TWRP was only an example for how /data could be backed up. In the most cases you restore /data after a wipe or when /data gets formatted. Then you will have a conflict with the already established encryption. After /data gets formatted the system generates a new master key during the next boot. You can't decrypt an old encryption with that master key.
The partition mirrors ~/dm-0 and so on are based on AVB and the device-mapper layer.
alecxs said:
I have posted workaround for streaming partitions with su
Click to expand...
Click to collapse
Yes, I know the 'netcat' method. Of course it's better to have a desktop PC and its storage for large images like /data. Better than an external sd. But you could also use the device's shell to create tar files.
WoKoschekk said:
Then you will have a conflict with the already established encryption.
Click to expand...
Click to collapse
Nope. works fine, as the partition image does not contain any encryption at all. consider it's already decrypted in AFU state.
WoKoschekk said:
After /data gets formatted the system generates a new master key during the next boot. You can't decrypt an old encryption with that master key.
Click to expand...
Click to collapse
Yes. only for FBE, for FDE it's static key. But encryption type doesn't matter, it contains plain files - same as TWRP backup.

Categories

Resources