Fix: detect Java version, use jadx 1.2.0 for Java 8 or 1.5.0 for Java 11+
This commit is contained in:
+73
-27
@@ -2,6 +2,10 @@
|
||||
#
|
||||
# Run from D:\HereMyHope\hh-bt-controller:
|
||||
# powershell -ExecutionPolicy Bypass -File sniffer/decompile_kaiyu.ps1
|
||||
#
|
||||
# Automatically picks jadx version based on your Java:
|
||||
# Java 8 -> jadx 1.2.0 (last version supporting Java 8)
|
||||
# Java 11+ -> jadx 1.5.0
|
||||
|
||||
$BaseDir = "D:\Claude\HH-BT-Controller\decompile"
|
||||
$JadxDir = "$BaseDir\jadx"
|
||||
@@ -17,39 +21,78 @@ Write-Host "============================================" -ForegroundColor Cyan
|
||||
Write-Host " KAIYU APK Decompiler" -ForegroundColor Cyan
|
||||
Write-Host "============================================" -ForegroundColor Cyan
|
||||
|
||||
# 1. Download jadx
|
||||
if (-not (Test-Path "$JadxDir\bin\jadx.bat")) {
|
||||
Write-Host "`n[1/4] Downloading jadx 1.5.0..." -ForegroundColor Yellow
|
||||
$url = "https://github.com/skylot/jadx/releases/download/v1.5.0/jadx-1.5.0.zip"
|
||||
# ── Detect Java version ───────────────────────────────────────────────────────
|
||||
Write-Host "`nDetecting Java version..." -ForegroundColor Gray
|
||||
$javaVer = 8
|
||||
try {
|
||||
$javaOut = & java -version 2>&1 | Select-Object -First 1
|
||||
Write-Host " $javaOut" -ForegroundColor Gray
|
||||
if ($javaOut -match '"(\d+)[\._]') {
|
||||
$major = [int]$Matches[1]
|
||||
# Java 8 reports as "1.8.x", Java 11+ reports as "11.x"
|
||||
$javaVer = if ($major -eq 1) {
|
||||
[int]($javaOut -replace '.*"1\.(\d+).*','$1')
|
||||
} else { $major }
|
||||
}
|
||||
} catch { Write-Host " Could not detect Java version, assuming Java 8" -ForegroundColor Yellow }
|
||||
|
||||
Write-Host " Java major version: $javaVer" -ForegroundColor Gray
|
||||
|
||||
# Pick jadx version accordingly
|
||||
if ($javaVer -ge 11) {
|
||||
$jadxVersion = "1.5.0"
|
||||
$jadxUrl = "https://github.com/skylot/jadx/releases/download/v1.5.0/jadx-1.5.0.zip"
|
||||
Write-Host " Using jadx 1.5.0 (Java 11+ detected)" -ForegroundColor Gray
|
||||
} else {
|
||||
$jadxVersion = "1.2.0"
|
||||
$jadxUrl = "https://github.com/skylot/jadx/releases/download/v1.2.0/jadx-1.2.0.zip"
|
||||
Write-Host " Using jadx 1.2.0 (Java 8 detected - last version supporting Java 8)" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# ── 1. Download jadx ──────────────────────────────────────────────────────────
|
||||
$jadxBat = Get-ChildItem -Path $JadxDir -Recurse -Filter "jadx.bat" -ErrorAction SilentlyContinue |
|
||||
Select-Object -First 1 -ExpandProperty FullName
|
||||
|
||||
if (-not $jadxBat) {
|
||||
Write-Host "`n[1/4] Downloading jadx $jadxVersion..." -ForegroundColor Yellow
|
||||
try {
|
||||
Invoke-WebRequest -Uri $url -OutFile $JadxZip -UseBasicParsing
|
||||
Write-Host " Downloaded ($([math]::Round((Get-Item $JadxZip).Length/1MB,1)) MB)"
|
||||
Invoke-WebRequest -Uri $jadxUrl -OutFile $JadxZip -UseBasicParsing
|
||||
$sizeMB = [math]::Round((Get-Item $JadxZip).Length / 1MB, 1)
|
||||
Write-Host " Downloaded ($sizeMB MB)"
|
||||
Write-Host " Extracting..."
|
||||
Expand-Archive -Path $JadxZip -DestinationPath $JadxDir -Force
|
||||
Remove-Item $JadxZip -Force
|
||||
Write-Host " jadx ready." -ForegroundColor Green
|
||||
$jadxBat = Get-ChildItem -Path $JadxDir -Recurse -Filter "jadx.bat" |
|
||||
Select-Object -First 1 -ExpandProperty FullName
|
||||
Write-Host " jadx ready: $jadxBat" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "[ERROR] Download failed: $_" -ForegroundColor Red
|
||||
Write-Host " Download manually: $url"
|
||||
Write-Host " Extract to: $JadxDir then re-run."
|
||||
Write-Host " Download manually: $jadxUrl"
|
||||
Write-Host " Extract to: $JadxDir"
|
||||
Read-Host; exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Host "`n[1/4] jadx already present." -ForegroundColor Green
|
||||
Write-Host "`n[1/4] jadx already present: $jadxBat" -ForegroundColor Green
|
||||
}
|
||||
|
||||
# 2. Pull APK
|
||||
if (-not $jadxBat) {
|
||||
Write-Host "[ERROR] jadx.bat not found after extraction." -ForegroundColor Red
|
||||
Read-Host; exit 1
|
||||
}
|
||||
|
||||
# ── 2. Pull APK ───────────────────────────────────────────────────────────────
|
||||
if (-not (Test-Path $ApkPath) -or (Get-Item $ApkPath).Length -lt 1MB) {
|
||||
Write-Host "`n[2/4] Pulling APK from phone..." -ForegroundColor Yellow
|
||||
$pmOut = & $Adb shell "pm path $Pkg" 2>&1
|
||||
if ($pmOut -notmatch "package:") {
|
||||
Write-Host "[ERROR] KAIYU not found on device. Is phone connected?" -ForegroundColor Red
|
||||
Write-Host "[ERROR] KAIYU not found on device." -ForegroundColor Red
|
||||
& $Adb devices; Read-Host; exit 1
|
||||
}
|
||||
$apkOnDevice = ($pmOut -split "`n" | Where-Object { $_ -match "package:" } |
|
||||
Select-Object -First 1).Replace("package:","").Trim()
|
||||
Select-Object -First 1).Replace("package:", "").Trim()
|
||||
Write-Host " Device path: $apkOnDevice"
|
||||
& $Adb pull $apkOnDevice $ApkPath
|
||||
if (-not (Test-Path $ApkPath)) {
|
||||
if (-not (Test-Path $ApkPath) -or (Get-Item $ApkPath).Length -lt 1MB) {
|
||||
& $Adb shell "cp '$apkOnDevice' /sdcard/kaiyu_tmp.apk"
|
||||
& $Adb pull /sdcard/kaiyu_tmp.apk $ApkPath
|
||||
& $Adb shell "rm /sdcard/kaiyu_tmp.apk" 2>&1 | Out-Null
|
||||
@@ -59,25 +102,28 @@ if (-not (Test-Path $ApkPath) -or (Get-Item $ApkPath).Length -lt 1MB) {
|
||||
}
|
||||
Write-Host " APK: $([math]::Round((Get-Item $ApkPath).Length/1MB,1)) MB" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "`n[2/4] APK already pulled ($([math]::Round((Get-Item $ApkPath).Length/1MB,1)) MB)." -ForegroundColor Green
|
||||
Write-Host "`n[2/4] APK already pulled ($([math]::Round((Get-Item $ApkPath).Length/1MB,1)) MB) -- skipping." -ForegroundColor Green
|
||||
}
|
||||
|
||||
# 3. Decompile
|
||||
Write-Host "`n[3/4] Decompiling with jadx (1-3 min)..." -ForegroundColor Yellow
|
||||
$jadxBat = Get-ChildItem -Path $JadxDir -Recurse -Filter "jadx.bat" |
|
||||
Select-Object -First 1 -ExpandProperty FullName
|
||||
if (-not $jadxBat) {
|
||||
Write-Host "[ERROR] jadx.bat not found in $JadxDir" -ForegroundColor Red; Read-Host; exit 1
|
||||
# ── 3. Decompile ──────────────────────────────────────────────────────────────
|
||||
Write-Host "`n[3/4] Decompiling with jadx $jadxVersion (1-3 min)..." -ForegroundColor Yellow
|
||||
if (Test-Path $OutputDir) {
|
||||
Write-Host " Removing previous output..."
|
||||
Remove-Item -Recurse -Force $OutputDir
|
||||
}
|
||||
if (Test-Path $OutputDir) { Remove-Item -Recurse -Force $OutputDir }
|
||||
|
||||
& $jadxBat --deobf --show-bad-code -d $OutputDir $ApkPath
|
||||
|
||||
$count = (Get-ChildItem -Recurse -Filter "*.java" -Path $OutputDir -ErrorAction SilentlyContinue).Count
|
||||
if ($count -eq 0) {
|
||||
Write-Host "[ERROR] No Java files produced. Check jadx output above." -ForegroundColor Red
|
||||
Read-Host; exit 1
|
||||
}
|
||||
Write-Host " $count Java files decompiled." -ForegroundColor Green
|
||||
|
||||
# 4. Analyse
|
||||
# ── 4. Analyse ────────────────────────────────────────────────────────────────
|
||||
Write-Host "`n[4/4] Analysing for BLE protocol..." -ForegroundColor Yellow
|
||||
|
||||
$analysePy = @(
|
||||
"sniffer\analyse_jadx.py",
|
||||
"D:\Claude\HH-BT-Controller\sniffer\analyse_jadx.py"
|
||||
@@ -86,12 +132,12 @@ $analysePy = @(
|
||||
if ($analysePy) {
|
||||
python $analysePy --src $OutputDir
|
||||
} else {
|
||||
Write-Host "analyse_jadx.py not found - run it manually:"
|
||||
Write-Host " python sniffer\analyse_jadx.py --src $OutputDir"
|
||||
Write-Host " analyse_jadx.py not found, run manually:"
|
||||
Write-Host " python sniffer\analyse_jadx.py --src `"$OutputDir`""
|
||||
}
|
||||
|
||||
Write-Host "`n============================================" -ForegroundColor Green
|
||||
Write-Host " Source at: $OutputDir" -ForegroundColor Green
|
||||
Write-Host " Browse: code $OutputDir" -ForegroundColor Green
|
||||
Write-Host " Done! Source at: $OutputDir" -ForegroundColor Green
|
||||
Write-Host " Open in VS Code: code `"$OutputDir`"" -ForegroundColor Green
|
||||
Write-Host "============================================" -ForegroundColor Green
|
||||
Read-Host "`nPress Enter to exit"
|
||||
|
||||
Reference in New Issue
Block a user