# Reversing

In this part we will extract the legitimate apk from emulator or the device and get the source code.

## Tool

**Android Debug Bridge (ADB)** is a development tool that facilitates communication between an Android device and a personal computer.

[How to Install ADB on Windows, macOS, and Linux](https://www.xda-developers.com/install-adb-windows-macos-linux/)

> Note: You need debug usb enable in your emulator or device.

### How view devices?

`adb devices`

<figure><img src="https://2641436320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZkW2HTL8VBVaNWfTE6Ra%2Fuploads%2FmbzIArH5uCsGw1z9GZHC%2Fde.png?alt=media&#x26;token=1e32fab5-68fa-40a6-9071-6325ffb1d2fb" alt=""><figcaption></figcaption></figure>

### How extract apk?

For this you need have installed the application in your device and know package name.

`adb shell pm path package_name`&#x20;

This command print the path to the APK of the given

<figure><img src="https://2641436320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZkW2HTL8VBVaNWfTE6Ra%2Fuploads%2FbiuoC1gGiMkZ0kWTjo9e%2F2019-10-28%2015_07_17-Select%20Command%20Prompt.png?alt=media&#x26;token=a8290ee1-30a7-4fef-a1aa-ad281b18a6da" alt=""><figcaption></figcaption></figure>

`adb pull <remote> [<localDestination>]`&#x20;

This command pulls the file **remote** to **local**. If **local** isn’t specified, it will pull to the current folder.

<figure><img src="https://2641436320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZkW2HTL8VBVaNWfTE6Ra%2Fuploads%2FBoZCXTUhAoCf5z8YAWhz%2F2019-10-28%2015_12_48-Select%20Command%20Prompt.png?alt=media&#x26;token=f501aa6a-4166-4e7a-8b0d-62993decab9a" alt=""><figcaption></figcaption></figure>

## Now, how to get to the source code?

[**jadx**](https://github.com/skylot/jadx/releases/)**:** The **jadx** suite allows you to simply load an APK and look at its Java source code. What’s happening under the hood is that jADX is decompiling the APK to smali and then converting the smali back to Java.

### Usage

`jadx -d [path-output-folder] [path-apk-or-dex-file]`

<figure><img src="https://2641436320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZkW2HTL8VBVaNWfTE6Ra%2Fuploads%2FmRI2HaGXtEZBUQxU5EGQ%2F2.png?alt=media&#x26;token=0c4b8706-e786-4d48-b4dc-42652da32057" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2641436320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZkW2HTL8VBVaNWfTE6Ra%2Fuploads%2F0L5VyR5mHn9M7WkyieUU%2F3.png?alt=media&#x26;token=9373952c-3968-4a64-90ab-b3cf5561ee51" alt=""><figcaption></figcaption></figure>

[**Dex2Jar**](https://sourceforge.net/projects/dex2jar/)**:** use dex2jar to convert an APK to a JAR file.

`d2j-dex2jar.sh or .bat /path/application.apk`&#x20;

<figure><img src="https://2641436320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZkW2HTL8VBVaNWfTE6Ra%2Fuploads%2FRPZU4rmQOM5iUqBTchyH%2F4.png?alt=media&#x26;token=4e3a903d-2355-4853-b2b5-49a54c70f9de" alt=""><figcaption></figcaption></figure>

Once you have the JAR file, simply open it with [JD-GUI](http://java-decompiler.github.io/) and you’ll see its Java code.

<figure><img src="https://2641436320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZkW2HTL8VBVaNWfTE6Ra%2Fuploads%2Fx65WkIiqGvd2toH3dNyh%2F5.png?alt=media&#x26;token=e4001f65-da0b-43b4-910f-2dcaf2a64760" alt=""><figcaption></figcaption></figure>

[**apktool**](https://ibotpeaches.github.io/Apktool/install/)**:** This tool get a source code in smali.

`apktool d file.apk`&#x20;

<figure><img src="https://2641436320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZkW2HTL8VBVaNWfTE6Ra%2Fuploads%2FVHQDEC5GPfuBMwasUacs%2F6.png?alt=media&#x26;token=41109b89-70c0-4eec-ba30-5376a612886d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2641436320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZkW2HTL8VBVaNWfTE6Ra%2Fuploads%2F5JPsNnFZPnjCLDxlcEjp%2F7.png?alt=media&#x26;token=d00635e9-3d54-4691-89a6-c8c3d3505419" alt=""><figcaption></figcaption></figure>

**jadx-gui:**  UI version of jadx

`jadx\bin\jadx-gui`&#x20;

<figure><img src="https://2641436320-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZkW2HTL8VBVaNWfTE6Ra%2Fuploads%2FGpNeVxSKy0oVDO154ANq%2F8.png?alt=media&#x26;token=057596d4-ea7c-40e2-8f76-e053829219da" alt=""><figcaption></figcaption></figure>
