Skip to content

Commit 46dd7b6

Browse files
fixed error while checking root on newer adb versions
1 parent 39b8781 commit 46dd7b6

File tree

1 file changed

+56
-10
lines changed

1 file changed

+56
-10
lines changed

Steam Desktop Authenticator/PhoneBridge.cs

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
using Newtonsoft.Json;
2-
using SteamAuth;
3-
using System;
1+
using System;
42
using System.Collections.Generic;
53
using System.Diagnostics;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading;
9-
using System.Threading.Tasks;
104
using System.IO;
5+
using System.Linq;
116
using System.Text.RegularExpressions;
7+
using System.Threading;
8+
using Newtonsoft.Json;
9+
using SteamAuth;
1210

1311
namespace Steam_Desktop_Authenticator
1412
{
@@ -20,6 +18,8 @@ public class PhoneBridge
2018
private Process console;
2119
private ManualResetEvent mreOutput = new ManualResetEvent(false);
2220

21+
private int adbVersion;
22+
2323
public delegate void BridgeOutput(string msg);
2424
public event BridgeOutput PhoneBridgeError;
2525
public event BridgeOutput OutputLog;
@@ -76,6 +76,8 @@ public SteamGuardAccount ExtractSteamGuardAccount(string id = "*", bool skipChec
7676
if (!skipChecks) AppendToLog("");
7777
InitConsole(); // Init the console
7878

79+
GetAdbVersion();
80+
7981
if (!skipChecks)
8082
{
8183
OnOutputLog("Checking requirements...");
@@ -154,7 +156,7 @@ private string GetDeviceID(bool root)
154156
console.OutputDataReceived += f1;
155157

156158
if (root)
157-
ExecuteCommand($"adb shell su -c 'sed -n 3p /data/data/$STEAMAPP/shared_prefs/steam.uuid.xml' & echo Done");
159+
ExecuteCommand("adb shell su -c 'sed -n 3p /data/data/$STEAMAPP/shared_prefs/steam.uuid.xml' & echo Done");
158160
else
159161
ExecuteCommand("adb shell \"cat /sdcard/steamauth/apps/$STEAMAPP/sp/steam.uuid.xml\" & echo Done");
160162
mre.Wait();
@@ -366,7 +368,12 @@ private bool SteamAppInstalled()
366368

367369
console.OutputDataReceived += f1;
368370

369-
ExecuteCommand("adb shell \"su -c 'cd /data/data/com.valvesoftware.android.steam.community && echo Yes'\"");
371+
if (UseLegacyAdbMethod()) {
372+
ExecuteCommand("adb shell \"su -c 'cd /data/data/com.valvesoftware.android.steam.community && echo Yes'\"");
373+
}
374+
else {
375+
ExecuteCommand("adb shell -n \"su -c 'cd /data/data/com.valvesoftware.android.steam.community && echo Yes'\"");
376+
}
370377
mre.Wait();
371378

372379
console.OutputDataReceived -= f1;
@@ -389,13 +396,52 @@ private bool IsRooted()
389396

390397
console.OutputDataReceived += f1;
391398

392-
ExecuteCommand("adb shell su -c 'echo Yes'");
399+
if (UseLegacyAdbMethod()) {
400+
ExecuteCommand("adb shell su -c 'echo Yes'");
401+
}
402+
else {
403+
ExecuteCommand("adb shell -n su -c 'echo Yes'");
404+
}
405+
393406
mre.Wait();
394407

395408
console.OutputDataReceived -= f1;
396409

397410
return root;
398411
}
412+
413+
private void GetAdbVersion()
414+
{
415+
OnOutputLog("Checking ADB version");
416+
string versionString = "";
417+
ManualResetEventSlim mre = new ManualResetEventSlim();
418+
DataReceivedEventHandler f1 = (sender, e) =>
419+
{
420+
if (e.Data.Contains(">@") || e.Data == "" || e.Data.Contains("Revision")) return;
421+
422+
versionString = new string(e.Data.ToCharArray().Where(char.IsDigit).ToArray());
423+
mre.Set();
424+
};
425+
426+
console.OutputDataReceived += f1;
427+
428+
ExecuteCommand("adb version");
429+
mre.Wait();
430+
431+
console.OutputDataReceived -= f1;
432+
433+
try {
434+
adbVersion = int.Parse(versionString);
435+
OnOutputLog("ADB version: " + adbVersion);
436+
}
437+
catch (Exception exception) {
438+
OnOutputLog("Error getting ADB version");
439+
}
440+
}
441+
442+
private bool UseLegacyAdbMethod() {
443+
return adbVersion < 1036;
444+
}
399445

400446

401447
public delegate void AccountsDelegate(List<string> accounts);

0 commit comments

Comments
 (0)