# 🔧 RR3 APK DECOMPILATION METHOD

**For Discord User Asking About APK Decompilation**

---

## 📋 QUESTIONS ANSWERED

### A) "jadx to convert it to what?"
**Answer:** JADX converts DEX bytecode → **Java source code (.java files)**

### B) "How did you circumvent apktool corrupting textures?"
**Answer:** **I didn't use apktool for textures. I used JADX only, which doesn't reprocess resources.**

---

## 🛠️ THE METHOD I USED

### Tool: JADX (NOT apktool)
- **Download:** https://github.com/skylot/jadx/releases
- **Version:** Latest release (jadx-1.5.0 or newer)
- **Type:** GUI or CLI

### What JADX Does:
```
Input:  realracing3.apk (100 MB)
        └── classes.dex (DEX bytecode)

Output: decompiled/
        ├── sources/           (Java .java files)
        │   └── com/ea/...     (Readable source code)
        └── resources/         (Extracted AS-IS)
            ├── AndroidManifest.xml
            ├── res/           (Resources)
            └── assets/        (Game assets)
```

### Why JADX Doesn't Corrupt Textures:
1. **JADX only decompiles CODE** (DEX → Java)
2. **Resources are extracted, not converted**
3. **No reprocessing/recompression** of images
4. **Files stay in original format**

---

## ⚠️ WHY APKTOOL CORRUPTS TEXTURES

### The Problem with apktool:
```
apktool tries to:
├── Decode resources.arsc
├── Decompile XML files
├── Extract PNG/9-patch images
└── Reprocess drawable resources ❌

Result: Textures get corrupted during:
├── PNG recompression
├── 9-patch processing
└── Resource table rebuilding
```

### When apktool is useful:
- Modifying AndroidManifest.xml
- Changing app resources (icons, strings)
- Rebuilding APK after modifications
- **NOT for preserving original assets!**

---

## ✅ RECOMMENDED APPROACH FOR RR3

### For Source Code Analysis:
```bash
# Use JADX (GUI or CLI)
jadx realracing3.apk -d decompiled/

# Result: Clean Java source code
# No corruption, just decompiled code
```

### For Asset Extraction:
```bash
# Option 1: Unzip APK directly (APK = ZIP file)
unzip realracing3.apk -d extracted/

# Option 2: Use JADX to extract resources
jadx realracing3.apk --export-gradle

# Option 3: Manual extraction from phone (what we did!)
adb pull /sdcard/Android/data/com.ea.games.r3_row/files/
```

### For Texture Preservation:
**DON'T USE:** apktool (corrupts textures)  
**DO USE:** 
- Direct APK extraction (unzip)
- JADX resource extraction
- ADB pull from phone (gets runtime assets)

---

## 📦 COMPLETE WORKFLOW

### Step 1: Get the APK
```bash
# From phone
adb pull /system/app/RealRacing3/base.apk

# Or from installed apps
adb shell pm path com.ea.games.r3_row
adb pull /data/app/com.ea.games.r3_row-[hash]/base.apk

# Or download from APKMirror/APKPure
```

### Step 2: Decompile Code with JADX
```bash
# GUI method (recommended for beginners)
1. Download JADX from: https://github.com/skylot/jadx/releases
2. Run jadx-gui.exe (Windows) or jadx-gui.sh (Linux)
3. File → Open → Select realracing3.apk
4. Wait for decompilation (2-5 minutes)
5. Browse source code in GUI
6. File → Save All → Choose output folder

# CLI method (for automation)
jadx realracing3.apk -d decompiled/
```

### Step 3: Extract Resources WITHOUT Corruption
```bash
# Method A: JADX extraction (safe)
jadx realracing3.apk --export-gradle -d output/

# Method B: Direct unzip (safest for textures)
unzip realracing3.apk -d apk-contents/

# Method C: 7-Zip (Windows)
7z x realracing3.apk -oapk-contents/
```

### Step 4: Get Runtime Assets from Phone
```bash
# This gets assets downloaded from EA CDN
adb pull /sdcard/Android/data/com.ea.games.r3_row/files/ phone-assets/

# Also check OBB files
adb pull /sdcard/Android/obb/com.ea.games.r3_row/ obb-assets/
```

---

## 🎯 WHAT YOU GET FROM EACH METHOD

### JADX Output:
```
decompiled/
├── sources/
│   └── com/ea/nimble/          (Network code)
│   └── com/firemonkeys/        (Game logic)
│   └── com/ea/games/r3/        (RR3 specific)
└── resources/
    ├── AndroidManifest.xml     (App config)
    ├── res/                    (App resources)
    │   ├── drawable/           (Icons, UI)
    │   ├── layout/             (UI layouts)
    │   └── values/             (Strings, configs)
    └── assets/                 (Base game assets)
```

### APK Direct Extraction (unzip):
```
apk-contents/
├── AndroidManifest.xml         (Binary XML)
├── classes.dex                 (Bytecode)
├── res/                        (Resources - intact!)
│   ├── drawable/               (PNG files - NOT corrupted)
│   └── layout/                 (Binary XML)
├── assets/                     (Game base assets)
│   └── (whatever APK contains)
├── lib/                        (Native libraries)
│   ├── armeabi-v7a/
│   └── arm64-v8a/
└── META-INF/                   (Signatures)
```

### Phone Asset Pull (ADB):
```
phone-assets/
├── pak files                   (3D models)
├── pka files                   (Archives)
├── z files                     (Compressed textures)
├── audio/                      (Sound files)
└── data/                       (Game data)

Size: 1.44 GB (full game content)
```

---

## 💡 TELL YOUR DISCORD FRIEND

### Quick Answer:
```
Q: How did you decompile without corruption?

A: I used JADX, not apktool.

JADX = Decompiles code only, extracts resources AS-IS
apktool = Tries to decode/rebuild everything (corrupts textures)

For RR3:
1. Use JADX for source code
2. Use unzip/7-zip for APK resources
3. Use ADB to pull runtime assets from phone (best quality)

DO NOT use apktool if you want intact textures!
```

### Detailed Answer:
```
The "res.zip" I extracted came from:
1. Install RR3 on phone
2. Let it download assets from EA CDN (1.44 GB)
3. ADB pull from phone storage
4. These are the ACTUAL game assets, not APK resources

For source code analysis:
1. Use JADX to decompile DEX → Java
2. No corruption, clean code output
3. Resources extracted as-is (no reprocessing)

apktool is NOT needed for RR3 preservation!
```

---

## 🔗 TOOLS & LINKS

### JADX (Recommended)
- **GitHub:** https://github.com/skylot/jadx
- **Releases:** https://github.com/skylot/jadx/releases/latest
- **Download:** jadx-1.5.0.zip (Windows/Linux/Mac)
- **GUI:** jadx-gui.exe / jadx-gui.sh
- **CLI:** jadx.bat / jadx.sh

### Alternative Tools
- **APKTool:** https://apktool.org/ (use only for rebuilding, NOT preservation)
- **7-Zip:** https://www.7-zip.org/ (for direct APK extraction)
- **ADB:** https://developer.android.com/tools/adb (for phone asset pull)

### APK Sources
- **APKMirror:** https://www.apkmirror.com/
- **APKPure:** https://apkpure.com/
- **Your own device:** `adb pull` from phone

---

## 📊 COMPARISON TABLE

| Method | Source Code | Resources | Texture Quality | Use Case |
|--------|-------------|-----------|-----------------|----------|
| **JADX** | ✅ Clean Java | ✅ Intact | ✅ Perfect | Analysis |
| **apktool** | ❌ Smali only | ⚠️ Decoded | ❌ Corrupted | Modding |
| **unzip/7-zip** | ❌ Bytecode | ✅ Binary | ✅ Perfect | Extraction |
| **ADB pull** | ❌ N/A | ✅ Runtime | ✅ Perfect | Preservation |

---

## ✅ MY FINAL WORKFLOW FOR RR3

```
1. Decompile with JADX:
   jadx realracing3.apk -d E:\rr3\decompiled\
   
2. Extract APK resources:
   unzip realracing3.apk -d E:\rr3\apk-contents\
   
3. Pull runtime assets from phone:
   adb pull /sdcard/Android/data/com.ea.games.r3_row/files/ E:\rr3\phone-assets-full\
   
4. Analyze source code:
   - Read decompiled Java in E:\rr3\decompiled\sources\
   - Find network endpoints in com/ea/nimble/
   - Map API calls to server implementation
   
5. Preserve assets:
   - Use phone-pulled assets (best quality)
   - Extract .z files with custom tools
   - Archive everything for preservation
```

**Result: No corruption, complete preservation, full source access** ✅

---

## 🚨 TL;DR FOR DISCORD

**Tell them:**

> "I used **JADX** (not apktool) to decompile the APK. JADX only decompiles the code (DEX → Java) and extracts resources without reprocessing them, so nothing gets corrupted.
> 
> For the actual game assets (textures, models, audio), I pulled them directly from my phone using ADB after letting the game download everything from EA's CDN. That's 1.44 GB of pristine assets.
> 
> **Don't use apktool for RR3** - it tries to decode and rebuild resources, which corrupts textures. Use JADX for code analysis and ADB for asset preservation.
> 
> Tools:
> - JADX: https://github.com/skylot/jadx/releases
> - ADB: Part of Android SDK platform-tools
> 
> Method: `jadx realracing3.apk -d output/` - done!"

---

**This is the RIGHT way to preserve RR3 without corruption.** 🏁✨
