Last active
August 11, 2025 16:17
-
-
Save ElectroHeavenVN/50d9040a7254177e89cb0115bb1756cc to your computer and use it in GitHub Desktop.
Extract all necessary information from your ZaloPC client to interact with Zalo's API (token, IMEI, user agent, computer name, API type and client version).
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 -c "irm https://gist.githubusercontent.com/ElectroHeavenVN/50d9040a7254177e89cb0115bb1756cc/raw/ZaloPCDataExtractor.ps1 | iex" |
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
| $zaloPCLauncherPath = $env:LOCALAPPDATA + "\Programs\Zalo\Zalo.exe" | |
| $debugPort = 8315 | |
| Write-Host "Closing ZaloPC..." | |
| Stop-Process -Name Zalo | |
| Write-Host "Opening ZaloPC..." | |
| Start-Process -FilePath $zaloPCLauncherPath -ArgumentList "--remote-debugging-port=$debugPort --remote-allow-origins=*" -PassThru | |
| write-Host "Waiting 30 seconds..." | |
| Start-Sleep -Seconds 30 | |
| $debuggerInfo = Invoke-RestMethod -Uri "http://localhost:$debugPort/json" | |
| $wsUrl = $debuggerInfo[0].webSocketDebuggerUrl | |
| Add-Type -TypeDefinition @" | |
| using System; | |
| using System.Net.WebSockets; | |
| using System.Text; | |
| using System.Threading; | |
| using System.Threading.Tasks; | |
| public class ZaloPCData | |
| { | |
| public int api_type { get; set; } | |
| public int client_version { get; set; } | |
| public string computer_name { get; set; } | |
| public string imei { get; set; } | |
| public string token { get; set; } | |
| } | |
| public class ZaloPCDataExtractor | |
| { | |
| public static async Task<ZaloPCData> ExtractDataAsync(string wsUrl) | |
| { | |
| ZaloPCData data = new ZaloPCData(); | |
| using (var client = new ClientWebSocket()) | |
| { | |
| await client.ConnectAsync(new Uri(wsUrl), CancellationToken.None); | |
| Console.WriteLine("Connected to " + wsUrl); | |
| string getAllCookies = @"{""id"":0,""method"":""Network.getAllCookies""}"; | |
| await SendMessage(client, getAllCookies); | |
| await Task.Delay(500); | |
| var receiveBuffer = new byte[4096]; | |
| var result = await client.ReceiveAsync(new ArraySegment<byte>(receiveBuffer), CancellationToken.None); | |
| string message = Encoding.UTF8.GetString(receiveBuffer, 0, result.Count); | |
| string token = message.Substring(message.IndexOf("\"zpw_sek\",") + 10); | |
| token = token.Substring(0, token.IndexOf("\"domain\"")); | |
| token = token.Substring(token.IndexOf("\"value\":") + 8); | |
| token = token.Trim().Trim(',', '"').Trim(); | |
| data.token = token; | |
| string enableNetwork = @"{""id"":1,""method"":""Network.enable""}"; | |
| await SendMessage(client, enableNetwork); | |
| await Task.Delay(500); | |
| string reloadPage = @"{""id"":2,""method"":""Page.reload""}"; | |
| await SendMessage(client, reloadPage); | |
| while (true) | |
| { | |
| result = await client.ReceiveAsync(new ArraySegment<byte>(receiveBuffer), CancellationToken.None); | |
| message = Encoding.UTF8.GetString(receiveBuffer, 0, result.Count); | |
| if (message.Contains("Network.requestWillBeSent") && message.Contains("api/login/getServerInfo")) | |
| { | |
| string url = message.Substring(message.IndexOf("\"url\":") + 6); | |
| url = url.Substring(0, url.IndexOf("signkey")); | |
| url = url.Trim().Trim('"'); | |
| string[] urlParams = url.Split('?', '&'); | |
| foreach (string param in urlParams) | |
| { | |
| if (param.StartsWith("type=")) | |
| data.api_type = int.Parse(param.Split('=')[1]); | |
| else if (param.StartsWith("client_version=")) | |
| data.client_version = int.Parse(param.Split('=')[1]); | |
| else if (param.StartsWith("computer_name=")) | |
| data.computer_name = param.Split('=')[1]; | |
| else if (param.StartsWith("imei=")) | |
| data.imei = param.Split('=')[1]; | |
| } | |
| break; | |
| } | |
| } | |
| } | |
| return data; | |
| } | |
| static async Task SendMessage(ClientWebSocket client, string message) | |
| { | |
| byte[] buffer = Encoding.UTF8.GetBytes(message); | |
| await client.SendAsync(new ArraySegment<byte>(buffer), WebSocketMessageType.Text, true, CancellationToken.None); | |
| } | |
| } | |
| "@ -Language CSharp | |
| $data = [ZaloPCDataExtractor]::ExtractDataAsync($wsUrl).GetAwaiter().GetResult() | |
| Clear-Host | |
| Write-Host | |
| Write-Host "------------------------------------" | |
| Write-Host | |
| Write-Host "Info:" | |
| Write-Host | |
| $data | ConvertTo-Json -Depth 10 | |
| Write-Host | |
| Write-Host "------------------------------------" | |
| Write-Host | |
| Write-Host "Press Enter key to close ZaloPC and exit..." | |
| Read-Host | |
| Stop-Process -Name Zalo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment