官术网_书友最值得收藏!

Using the Android Debug Bridge (ADB) to interact with the AVDs

Interacting with the emulated Android device is one of the most important skills for both a developer and an Android security engineer/auditor. The Android Debug Bridge (ADB) provides the functionality needed to interact with the native-level components of an Android device. It allows the developers and security engineers to read the contents of the filesystem and interact with the package manager, application manager, kernel driver interfaces, and initialization scripts to mention a few.

How to do it...

Interacting with a virtual device using the ADB works as follows:

  1. You'll need to start an AVD first or, if you like, simply plug in your own Android device via a USB to whatever machine you'd like to use—given that this machine has the SDK installed. You can start the AVD using the following command:
    emulator –avd [name]
    
  2. We can list all the connected Android Devices by using the following command for a Windows machine:
    C;\\[path-to-sdk-install]\platform-tools\adb devices
    

    Or, if you're using a Linux machine, use the following command:

    [path-to-sdk-install]/platform-tools/adb devices
    

    This command should give you a list of the connected devices, which is basically all the devices that you will be able to connect to using ADB. You need to pay attention to the device names in the list. You will need to identify the devices when you launch a connection to them using ADB.

  3. You can launch a shell connection to your Android device using the following command:
    /sdk/platform-tools/abd shell –s [specific device]
    

    Or, if you happen to know that the Android device you want to connect to is the only emulated device, you can use the following command:

    /sdk/platform-tools/adb shell –e
    

    Or, if the device is the only USB-connected device, you can use the following command:

    /sdk/platform-tools/adb shell –d
    

    The switches –d, -e, and -p apply to the other ADB commands and not just the shell. If this works well, you should see a prompt string—the string displayed to identify the command shell being used—similar to the following command:

    root@android$
    

You should now have a full-fledged shell with some of the traditional Unix/Linux commands and utilities at your finger tips. Try searching around on the filesystem and getting to know where everything is kept.

There's more…

Now that you have a connected device, you'll need to know a little bit about navigating the Android filesystem and making use of the commands. Here's a small list to get you started:

  • ls {path}: This will list the contents of the directory at the path
  • cat {file}: This will print the contents of a text file on the screen
  • cd {path}: This will change the working directory to the one pointed to by the path
  • cd ../: This changes the working directory to the one that's exactly one level higher
  • pwd: This prints the current working directory
  • id: This checks your user ID
主站蜘蛛池模板: 德令哈市| 泸溪县| 宣恩县| 尉氏县| 宜春市| 乌海市| 永昌县| 临汾市| 庆安县| 镇宁| 贵德县| 自贡市| 海伦市| 清远市| 阿拉善左旗| 东台市| 南和县| 香格里拉县| 钟山县| 彰武县| 湘潭县| 红桥区| 新乡市| 昭苏县| 清水河县| 深圳市| 万山特区| 牙克石市| 来安县| 会东县| 连江县| 宁明县| 白朗县| 巴青县| 无锡市| 桃江县| 辽阳县| 东光县| 五常市| 彭泽县| 福清市|