Skip to content

Instantly share code, notes, and snippets.

@teebow1e
Last active September 7, 2024 09:24
Show Gist options
  • Select an option

  • Save teebow1e/544c70a25ced4e4dedf9257efa807cf1 to your computer and use it in GitHub Desktop.

Select an option

Save teebow1e/544c70a25ced4e4dedf9257efa807cf1 to your computer and use it in GitHub Desktop.
[Android] Script to download frida-server
function Download-FileWithProgress {
param (
[string]$url,
[string]$destination
)
$request = [System.Net.HttpWebRequest]::Create($url)
$request.Method = "GET"
$response = $request.GetResponse()
$totalBytes = $response.ContentLength
$fileStream = [System.IO.File]::Create($destination)
$responseStream = $response.GetResponseStream()
$buffer = New-Object byte[] 8192
$bytesRead = 0
$totalRead = 0
while (($bytesRead = $responseStream.Read($buffer, 0, $buffer.Length)) -gt 0) {
$fileStream.Write($buffer, 0, $bytesRead)
$totalRead += $bytesRead
$percentComplete = [math]::Round(($totalRead / $totalBytes) * 100, 2)
Write-Progress -Activity "Downloading" -Status "$percentComplete% Complete" -PercentComplete $percentComplete
}
$fileStream.Close()
$responseStream.Close()
}
try {
$version = frida --version 2>&1
if ($version -match "(\d+\.\d+\.\d+)") {
$fridaVersion = $matches[0]
Write-Host "[+] Frida version: $fridaVersion"
} else {
throw "[-] Frida not found"
}
} catch {
Write-Host "[-] Frida is not installed or there was an error. You need to install frida-tools using pip."
$installFrida = Read-Host "[?] Do you want to install frida-tools now? (y/n)"
if ($installFrida -eq 'y') {
try {
python -m pip install frida-tools
Write-Host "[+] frida-tools installed successfully."
$version = frida --version 2>&1
if ($version -match "(\d+\.\d+\.\d+)") {
$fridaVersion = $matches[0]
Write-Host "[+] Frida version: $fridaVersion"
}
} catch {
Write-Host "[-] Error installing frida-tools. Please install it manually."
exit
}
} else {
Write-Host "[-] frida-tools installation aborted."
exit
}
}
$architectureOptions = @("arm", "arm64", "x86", "x86_64")
$architecture = Read-Host "[?] Choose architecture (arm, arm64, x86, x86_64)"
if ($architectureOptions -notcontains $architecture) {
Write-Host "[-] Invalid architecture choice. Exiting."
exit
}
$downloadUrl = "https://github.com/frida/frida/releases/download/$fridaVersion/frida-server-$fridaVersion-android-$architecture.xz"
$destinationPath = "$PWD\frida-server-$fridaVersion-android-$architecture.xz"
Write-Host "[!] Downloading frida-server version $version for $architecture architecture from $downloadUrl..."
try {
Download-FileWithProgress -url $downloadUrl -destination $destinationPath
Write-Host "[+] Download completed: $destinationPath"
} catch {
Write-Host "[-] Failed to download frida-server."
exit
}
$openFolder = Read-Host "[?] Do you want to open the folder where the file has been downloaded? (y/n)"
if ($openFolder -eq 'y') {
Start-Process explorer.exe $PWD
}
#!/bin/bash
download_file_with_progress() {
local url="$1"
local destination="$2"
echo "[!] Downloading from $url..."
curl -L -o "$destination" "$url" --progress-bar
}
get_frida_version() {
if command -v frida &> /dev/null; then
version=$(frida --version 2>&1)
if [[ $version =~ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then
echo "${BASH_REMATCH[1]}"
else
echo "Frida version not found"
return 1
fi
else
echo "Frida not installed"
return 1
fi
}
install_frida_tools() {
echo "[!] Installing frida-tools..."
python -m pip install frida-tools
if [[ $? -eq 0 ]]; then
echo "[+] frida-tools installed successfully."
frida_version=$(get_frida_version)
if [[ $? -eq 0 ]]; then
echo "[+] Frida version: $frida_version"
else
echo "[-] Error retrieving Frida version after installation."
exit 1
fi
else
echo "[-] Error installing frida-tools. Please install it manually."
exit 1
fi
}
frida_version=$(get_frida_version)
if [[ $? -ne 0 ]]; then
echo "[-] Frida is not installed or there was an error. You need to install frida-tools using pip."
read -p "[?] Do you want to install frida-tools now? (y/n) " install_frida
if [[ "$install_frida" == "y" ]]; then
install_frida_tools
else
echo "[-] frida-tools installation aborted."
exit 1
fi
fi
architecture_options=("arm" "arm64" "x86" "x86_64")
read -p "[?] Choose architecture (arm, arm64, x86, x86_64): " architecture
if [[ ! " ${architecture_options[@]} " =~ " ${architecture} " ]]; then
echo "[-] Invalid architecture choice. Exiting."
exit 1
fi
download_url="https://github.com/frida/frida/releases/download/$frida_version/frida-server-$frida_version-android-$architecture.xz"
destination_path="./frida-server-$frida_version-android-$architecture.xz"
echo "[!] Downloading frida-server version $frida_version for $architecture architecture from $download_url..."
download_file_with_progress "$download_url" "$destination_path"
if [[ $? -eq 0 ]]; then
echo "[+] Download completed: $destination_path"
else
echo "[-] Failed to download frida-server."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment