# Complete Android Studio ARM64 Emulator Setup + Root + Frida
# One-click setup for Canada Post app analysis

## Quick Start (Automated)

Just run this script after creating the AVD!

```powershell
.\SETUP_ANDROID_STUDIO_COMPLETE.bat
```

---

## Manual Setup (Step by Step)

### Step 1: Install Android Studio

1. Download: https://developer.android.com/studio
2. Install Android Studio
3. Open Android Studio → More Actions → SDK Manager
4. SDK Tools tab → Check "Android SDK Platform-Tools" → Apply

### Step 2: Create ARM64 AVD

1. Android Studio → More Actions → Device Manager
2. Click "Create Device"
3. **Hardware**: Select "Pixel 5" (or any modern phone)
4. **System Image**: 
   - Click "Download" next to an ARM64 image
   - **IMPORTANT**: Choose "arm64-v8a" NOT "x86_64"
   - Recommended: API 33 (Android 13) with Google APIs
5. **AVD Name**: "Pixel5_ARM64_API33" (or your choice)
6. **Advanced Settings**:
   - RAM: 4096 MB (4GB)
   - Internal Storage: 8192 MB (8GB)
7. Click "Finish"

### Step 3: Start the AVD

```powershell
# Set environment
$env:ANDROID_HOME = "$env:LOCALAPPDATA\Android\Sdk"
$env:PATH += ";$env:ANDROID_HOME\emulator;$env:ANDROID_HOME\platform-tools"

# List AVDs
emulator -list-avds

# Start your AVD
emulator -avd Pixel5_ARM64_API33 -writable-system
```

### Step 4: Root the AVD (rootAVD)

**Option A: Automated (Recommended)**
```powershell
.\SETUP_ANDROID_STUDIO_COMPLETE.bat
# It will download rootAVD and root your AVD automatically
```

**Option B: Manual**
```powershell
# Download rootAVD
git clone https://gitlab.com/newbit/rootAVD.git
cd rootAVD

# Root the AVD (make sure AVD is running first!)
.\rootAVD.bat system-images\android-33\google_apis\arm64-v8a\ramdisk.img

# Wait for the script to complete
# It will install Magisk automatically
```

### Step 5: Install Frida-Server (ARM64)

```powershell
cd C:\Users\Roose\Downloads\8c7481c52661c4933b707a14e6cd22ba-java

# Download frida-server ARM64
Invoke-WebRequest -Uri "https://github.com/frida/frida/releases/download/17.5.1/frida-server-17.5.1-android-arm64.xz" -OutFile "frida-server-arm64.xz"

# Extract
python -c "import lzma, shutil; f_in = lzma.open('frida-server-arm64.xz', 'rb'); f_out = open('frida-server-arm64', 'wb'); shutil.copyfileobj(f_in, f_out); f_in.close(); f_out.close()"

# Push to device
adb push frida-server-arm64 /data/local/tmp/frida-server
adb shell "chmod 755 /data/local/tmp/frida-server"

# Start frida-server
adb root
adb shell "/data/local/tmp/frida-server &"

# Verify
frida-ps -U
```

### Step 6: Install Canada Post App

```powershell
cd C:\Users\Roose\Downloads\8c7481c52661c4933b707a14e6cd22ba-java

# Install all APK splits
adb install-multiple cpc_extracted\base.apk cpc_extracted\split_config.arm64_v8a.apk cpc_extracted\split_config.xxhdpi.apk

# Verify installation
adb shell pm list packages | Select-String "canada"
```

### Step 7: Run Frida with Ultimate Bypass

```powershell
cd C:\Users\Roose\Downloads\8c7481c52661c4933b707a14e6cd22ba-java

# Run the ultimate bypass
frida -U -f com.canadapost.android -l frida_ultimate_bypass.js
```

---

## Troubleshooting

### AVD won't start
- Make sure you have enough RAM (4GB+)
- Enable Hyper-V in Windows (Settings → Windows Features)
- Close other emulators/VMs

### rootAVD fails
- Make sure AVD is running
- Check `adb devices` shows the device
- Try with elevated permissions (Run as Administrator)

### Frida connection fails
- Kill existing frida-server: `adb shell "killall frida-server"`
- Restart: `adb shell "/data/local/tmp/frida-server &"`
- Check: `frida-ps -U`

### App crashes on launch
- Wrong architecture: Make sure you created ARM64 AVD
- Check logs: `adb logcat | Select-String "canadapost"`

---

## Key Files

- `SETUP_ANDROID_STUDIO_COMPLETE.bat` - Automated setup
- `rootAVD\rootAVD.bat` - Root script
- `frida-server-arm64` - Frida server for ARM64
- `frida_ultimate_bypass.js` - Ultimate bypass (SSL+Root+Emulator)
- `RUN_FRIDA_HOOKS.bat` - Quick launch menu

---

## Resources

- rootAVD: https://gitlab.com/newbit/rootAVD
- Android Studio: https://developer.android.com/studio
- Frida: https://frida.re/docs/android/
- Magisk: https://github.com/topjohnwu/Magisk
