Tuesday, 26 November 2013

Android Debug Bridge - An introduction

Posted by srini0x00 on 09:32

What is ADB?

Android Debug Bridge (adb) is a command line tool which acts as a bridge between you and your Android device. It allows the users to control the mobile device right from your computer/laptop.Using ADB, We can do many operations on the Connected Device or Emulator such as, 

  • Checking what are the devices/emulators connected to the computer.
  • Installing an application.
  • Copying files from to/from a phone onto your computer.
  • Executing shell commands.
  • Exploring the directories on a device/emulator.
  • Analyzing the installed app directories for vulnerabilities.

What do we need to work with adb?

  • A Laptop/Computer with adb installed
  • An Android mobile phone/ Emulator(USB Debugging should be enabled on mobile)
  • A USB Cable(If you are using a mobile phone)

How does adb work?

ADB has three important components.
  1. A Client
  2. A Server 
  3. A Daemon
Client resides on the computer we are working on. We can explicitly execute it by navigating to android installation path and then moving to platform tools. The adb client looks as shown in figure 1.1
Syntax: <Your installation path>\platform-tools

In my case, I have it in the following path.

figure 1.1

It is a background process running on the computer we are working on, it is used to manage the communication between the client running on the computer and daemon running on the device.

It is a background process by default running on each android device or emulator.

When we start adb client on the computer, it checks whether the server is running or not, if it is not running, it will start it on port 5037 as shown in figure 1.2

Figure 1.2 adb command looking for attached devices.

Since, my emulator is still switching on, the above figure shows the emulator's status as offline. Once, if it is started it shows the status device as shown in the figure 1.2.1.

figure 1.2.1

Checking the adb connections with netstat

Lets recheck whether this 5037 port is listening for any connections or not using netstat command line utility.

netstat  -a | findstr 5037

-a is to display all connections and ports
| is to pipe the results
findstr is to find the specific string rather than displaying all the output on the screen.
The output is as shown in figure 1.3
figure 1.3

As we can clearly see, a process is listening for a connection on port number 5037. Once if we connect to a device/emulator the status becomes “ESTABLISHED”
Lets run the command “adb shell” as shown in figure 1.4, it gives us a shell on the emulator/device where we can execute the commands.
figure 1.4

If we now check the same nestat command, status says “ESTABLISHED”.

Running Commands

We can now start using adb for different purposes. For instance, let us do a quick “ls” to see all the files and folders in the current directory as shown in the figure 1.5
figure 1.5

We keep using adb throughout this series wherever it is needed. So, its always a good idea to get your hands dirty with adb. 

Hope this information helps you. Please post your comments for any queries or suggestions.

Kindly Bookmark and Share it:


Post a Comment


Recent posts

Recent Comments

Bookmark & Share