Last active
October 14, 2024 00:31
-
-
Save Mirai0009/e2408c1bed22869848b37828ef83bc8f to your computer and use it in GitHub Desktop.
PowerShell script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PowerShell script for retrieving Gacha URL | |
# Base script by jogerj | |
# Rewrite by Miraiwangy | |
function Expand-ZIPFile($file, $destination) { | |
$shell = New-Object -ComObject Shell.Application | |
$zip = $shell.NameSpace($file) | |
if ($zip -eq $null) { | |
Write-Host "Could not open ZIP file: $file" -ForegroundColor Red | |
return | |
} | |
foreach ($item in $zip.Items()) { | |
$shell.Namespace($destination).CopyHere($item) | |
} | |
} | |
$tmps = Join-Path $env:TEMP 'pma' | |
if (!(Test-Path $tmps)) { | |
New-Item -Path $tmps -ItemType Directory | Out-Null | |
} | |
Write-Host "Please connect your phone via USB and turn on USB Debugging in Developer options." -ForegroundColor Cyan | |
Pause | |
$adb = Join-Path $tmps 'platform-tools\adb.exe' | |
if (!(Test-Path $adb)) { | |
Write-Host "Fetching ADB..." -ForegroundColor Cyan | |
Invoke-WebRequest "https://dl.google.com/android/repository/platform-tools-latest-windows.zip" -OutFile "$tmps\adb.zip" | |
Expand-ZIPFile "$tmps\adb.zip" -destination $tmps | |
} | |
$output = & "$adb" "devices" | |
$output | |
$unauthorized = $output -match "unauthorized" | |
if ($unauthorized) { | |
Write-Host "USB Debugging is not authorized!" -ForegroundColor Red | |
return | |
} | |
Write-Host "Open Games and open Wish history." -ForegroundColor Cyan | |
$output = & $adb "logcat" '-c' | |
$output = & $adb "logcat" '-m' '1' '-e' "OnGetWebViewPageFinish" | |
$link = $output | Select-String -Pattern "https://(webstatic|hk4e-api|webstatic-sea|hk4e-api-os|api-takumi|api-os-takumi|gs|public-operation-hk4e).(mihoyo\.com|hoyoverse\.com).*authkey=.*\s*.*game_biz.*(plat_type|#/log|global#/info)" | |
if (-Not $link) { | |
Write-Host "Error when parsing link, please try again." -ForegroundColor Red | |
return | |
} | |
$s = $link -match "(https://(webstatic|hk4e-api|webstatic-sea|hk4e-api-os|api-takumi|api-os-takumi|gs|public-operation-hk4e).(mihoyo\.com|hoyoverse\.com).*authkey=.*\s*.*game_biz.*(plat_type|#/log|global#/info))" | |
if (!$s) { | |
Write-Host "Error when parsing link, please try again." -ForegroundColor Red | |
return | |
} | |
$f = $matches[0] -replace '&', "\&" | |
Write-Host "Opening link on your phone..." -ForegroundColor Cyan | |
$o = & "$adb" 'shell' 'am' 'start' '-a' 'android.intent.action.VIEW' '-d' $f | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment