From 79552c20971d4a18f0420a6d5cf535f6f55790b5 Mon Sep 17 00:00:00 2001
From: Andrey Smirnoff <37037851+mashed-potatoes@users.noreply.github.com>
Date: Sun, 25 Apr 2021 22:28:39 +0500
Subject: [PATCH] v2.2.0
---
PotatoNV-next/Controls/AboutTab.xaml.cs | 19 ++++----
PotatoNV-next/Controls/LogBox.xaml | 11 ++---
PotatoNV-next/Controls/LogBox.xaml.cs | 4 ++
PotatoNV-next/Controls/NVForm.xaml | 9 ++--
PotatoNV-next/Controls/NVForm.xaml.cs | 13 ++----
PotatoNV-next/Core.cs | 57 ++++++++++++------------
PotatoNV-next/MainWindow.xaml | 47 +++++++++++--------
PotatoNV-next/MainWindow.xaml.cs | 7 ++-
PotatoNV-next/PotatoNV-next.csproj | 1 +
PotatoNV-next/Properties/AssemblyInfo.cs | 4 +-
PotatoNV-next/Utils/Common.cs | 30 +++++++++++++
11 files changed, 119 insertions(+), 83 deletions(-)
create mode 100644 PotatoNV-next/Utils/Common.cs
diff --git a/PotatoNV-next/Controls/AboutTab.xaml.cs b/PotatoNV-next/Controls/AboutTab.xaml.cs
index 989d65e..8d808f1 100644
--- a/PotatoNV-next/Controls/AboutTab.xaml.cs
+++ b/PotatoNV-next/Controls/AboutTab.xaml.cs
@@ -11,17 +11,16 @@ namespace PotatoNV_next.Controls
public AboutTab()
{
InitializeComponent();
- version.Text = string.Format(version.Text, GetVersion(3));
- fireLogo.Source = MediaConverter.ImageSourceFromBitmap(Properties.Resources.Fire.ToBitmap());
- }
+ var versionTag = $"v{Common.GetAssemblyVersion(typeof(MainWindow).Assembly)}\n[" +
+ string.Join(", ", new (string AssemblyName, string Tag)[] {
+ ("Potato.Fastboot", "FB"),
+ ("Potato.ImageFlasher", "IF"),
+ ("LibUsbDotNet.LibUsbDotNet", "LD"),
+ ("libusb-1.0", "LU"),
+ }.Select(x => $"{x.Tag} v{Common.GetAssemblyVersion($"{x.AssemblyName}.dll") ?? "??"}").ToArray()) + "]";
- public static string GetVersion(int depth = 3)
- {
- return string.Join(".",
- typeof(MainWindow).Assembly.GetName().Version
- .ToString()
- .Split('.')
- .Take(depth));
+ version.Text = versionTag;
+ fireLogo.Source = MediaConverter.ImageSourceFromBitmap(Properties.Resources.Fire.ToBitmap());
}
private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
diff --git a/PotatoNV-next/Controls/LogBox.xaml b/PotatoNV-next/Controls/LogBox.xaml
index 0d96a1b..92ed7ab 100644
--- a/PotatoNV-next/Controls/LogBox.xaml
+++ b/PotatoNV-next/Controls/LogBox.xaml
@@ -1,10 +1,6 @@
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
@@ -13,9 +9,10 @@
+ IsReadOnly="True"
+ ScrollViewer.VerticalScrollBarVisibility="Visible" />
diff --git a/PotatoNV-next/Controls/LogBox.xaml.cs b/PotatoNV-next/Controls/LogBox.xaml.cs
index efb6f47..c60250a 100644
--- a/PotatoNV-next/Controls/LogBox.xaml.cs
+++ b/PotatoNV-next/Controls/LogBox.xaml.cs
@@ -37,7 +37,11 @@ namespace PotatoNV_next.Controls
Dispatcher.Invoke(() => logBox.AppendText(e.Message));
return;
}
+
logBox.AppendText(e.Message);
+ logBox.Focus();
+ logBox.CaretIndex = logBox.Text.Length;
+ logBox.ScrollToEnd();
}
private void OnProgress(Log.ProgressEventArgs progressEventArgs)
diff --git a/PotatoNV-next/Controls/NVForm.xaml b/PotatoNV-next/Controls/NVForm.xaml
index 2c65940..d33700e 100644
--- a/PotatoNV-next/Controls/NVForm.xaml
+++ b/PotatoNV-next/Controls/NVForm.xaml
@@ -4,7 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
- d:DesignHeight="450" d:DesignWidth="800" IsEnabledChanged="NVForm_IsEnabledChanged">
+ IsEnabledChanged="NVForm_IsEnabledChanged">
@@ -15,11 +15,8 @@
-
-
-
-
-
+
+
diff --git a/PotatoNV-next/Controls/NVForm.xaml.cs b/PotatoNV-next/Controls/NVForm.xaml.cs
index 610f84f..93f7659 100644
--- a/PotatoNV-next/Controls/NVForm.xaml.cs
+++ b/PotatoNV-next/Controls/NVForm.xaml.cs
@@ -37,11 +37,6 @@ namespace PotatoNV_next.Controls
{
deviceBootloader.SelectedIndex = 0;
}
-
- var random = new Random(Guid.NewGuid().GetHashCode());
-
- nvUnlockCode.Text = new string(Enumerable.Repeat("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 16)
- .Select(s => s[random.Next(s.Length)]).ToArray());
}
public class FormEventArgs : EventArgs
@@ -50,6 +45,7 @@ namespace PotatoNV_next.Controls
public string Target { get; set; }
public string UnlockCode { get; set; }
public bool DisableFBLOCK { get; set; }
+ public bool Reboot { get; set; }
public Bootloader Bootloader { get; set; } = null;
}
@@ -110,8 +106,6 @@ namespace PotatoNV_next.Controls
"Check connection and required drivers.");
Assert(deviceBootloader.SelectedIndex != -1, "Couldn't find any valid bootloader!");
-
- Assert(VerifyNVValue(nvUnlockCode.Text, true), "Unlock code is not valid.");
}
catch
{
@@ -126,8 +120,8 @@ namespace PotatoNV_next.Controls
? UsbController.Device.DMode.Fastboot
: UsbController.Device.DMode.DownloadVCOM,
Target = deviceList.SelectedItem.ToString(),
- UnlockCode = nvUnlockCode.Text,
- DisableFBLOCK = disableFBLOCK.IsChecked.Value
+ DisableFBLOCK = disableFBLOCK.IsChecked.Value,
+ Reboot = reboot.IsChecked.Value
};
if (!IsSelectedDeviceInFastbootMode)
@@ -142,7 +136,6 @@ namespace PotatoNV_next.Controls
{
deviceList.IsEnabled = IsEnabled;
deviceBootloader.IsEnabled = IsEnabled;
- nvUnlockCode.IsEnabled = IsEnabled;
disableFBLOCK.IsEnabled = IsEnabled;
startButton.IsEnabled = IsEnabled;
}
diff --git a/PotatoNV-next/Core.cs b/PotatoNV-next/Core.cs
index b040af6..5d7dc37 100644
--- a/PotatoNV-next/Core.cs
+++ b/PotatoNV-next/Core.cs
@@ -4,6 +4,7 @@ using PotatoNV_next.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
@@ -82,17 +83,28 @@ namespace PotatoNV_next
var build = fb.Command("oem get-build-number");
Log.Info($"Build number: {build.Payload.Replace(":", "")}");
- var regex = new Regex(@"FB[\w: ]{1,}UNLOCKED");
var fblock = fb.Command("oem lock-state info");
- var state = regex.IsMatch(fblock.Payload);
+ var state = Regex.IsMatch(fblock.Payload, @"FB[\w: ]{1,}UNLOCKED");
Log.Info($"FBLOCK state: {(state ? "unlocked" : "locked")}");
LogResponse(fblock);
if (!state)
{
- Log.Error("*** FBLOCK is locked! ***");
+ throw new Exception("*** FBLOCK is locked! ***");
}
+
+ var factoryKey = ReadFactoryKey();
+
+ if (factoryKey != null)
+ {
+ Log.Info($"Unlock key: {factoryKey}");
+ }
+
+ var random = new Random(Guid.NewGuid().GetHashCode());
+
+ args.UnlockCode = factoryKey ?? new string(Enumerable.Repeat("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 16)
+ .Select(s => s[random.Next(s.Length)]).ToArray());
}
private void SetNVMEProp(string prop, byte[] value)
@@ -122,7 +134,7 @@ namespace PotatoNV_next
}
}
- private void SetHWDogCertify(byte state)
+ private void SetHWDogState(byte state)
{
foreach (var command in new[] { "hwdog certify set", "backdoor set" })
{
@@ -139,24 +151,12 @@ namespace PotatoNV_next
Log.Error("Failed to set FBLOCK state!");
}
- private void WidevineLock()
+ private string ReadFactoryKey()
{
- Log.Debug("WV Lock");
var res = fb.Command("getvar:nve:WVLOCK");
- LogResponse(res);
- if (res.Status != Fastboot.Status.Fail && res.Payload.Replace("\n", "").Trim() != "UUUUUUUUUUUUUUUU")
- {
- Log.Info($"Read factory key: {res.Payload}");
- }
+ var match = Regex.Match(res.Payload, @"\w{16}");
- try
- {
- SetNVMEProp("WVLOCK", Encoding.ASCII.GetBytes(args.UnlockCode));
- }
- catch
- {
- Log.Error("Failed to set the WVLOCK.");
- }
+ return match.Success ? match.Value : null;
}
private void WriteNVME()
@@ -171,13 +171,13 @@ namespace PotatoNV_next
{
Log.Error("Failed to set the FBLOCK, using the alternative method...");
Log.Debug(ex.Message);
- SetHWDogCertify(fblockState);
+ SetHWDogState(fblockState);
}
try
{
+ SetNVMEProp("WVLOCK", Encoding.ASCII.GetBytes(args.UnlockCode));
SetNVMEProp("USRKEY", GetSHA256(args.UnlockCode));
- WidevineLock();
}
catch (Exception ex)
{
@@ -207,11 +207,16 @@ namespace PotatoNV_next
ReadInfo();
WriteNVME();
- Log.Info("Rebooting...");
+ Log.Info("Finalizing...");
+ LogResponse(fb.Command($"oem unlock {args.UnlockCode}"));
- fb.Command("reboot");
+ if (args.Reboot)
+ {
+ Log.Info("Rebooting...");
+ fb.Command("reboot");
+ }
- Log.Info($"New bootloader unlock code: {args.UnlockCode}");
+ Log.Info($"Bootloader unlock code: {args.UnlockCode}");
fb.Disconnect();
}
@@ -220,10 +225,6 @@ namespace PotatoNV_next
Log.Error(ex.Message);
Log.Debug(ex.StackTrace);
}
- finally
- {
- fb.Disconnect();
- }
}
public void StartProcess(Controls.NVForm.FormEventArgs args)
diff --git a/PotatoNV-next/MainWindow.xaml b/PotatoNV-next/MainWindow.xaml
index e80522f..90cb9c7 100644
--- a/PotatoNV-next/MainWindow.xaml
+++ b/PotatoNV-next/MainWindow.xaml
@@ -6,36 +6,47 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="PotatoNV"
- Width="720"
- Height="416"
+ Width="450"
+ Height="500"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
diff --git a/PotatoNV-next/MainWindow.xaml.cs b/PotatoNV-next/MainWindow.xaml.cs
index 3583d7c..6a32466 100644
--- a/PotatoNV-next/MainWindow.xaml.cs
+++ b/PotatoNV-next/MainWindow.xaml.cs
@@ -1,8 +1,11 @@
using Microsoft.Win32;
using PotatoNV_next.Utils;
using System;
+using System.Collections.Generic;
using System.Globalization;
using System.IO;
+using System.Linq;
+using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
@@ -96,11 +99,11 @@ namespace PotatoNV_next
SetupLog();
core.StartProcess(formEventArgs);
}
-
+
public void SetupLog()
{
logBox.Clear();
- Log.Info($"PotatoNV v{Controls.AboutTab.GetVersion()}");
+ Log.Info($"PotatoNV v{Common.GetAssemblyVersion(typeof(MainWindow).Assembly)}");
Log.Info("User manual: https://kutt.it/pnv-"
+ (CultureInfo.InstalledUICulture.TwoLetterISOLanguageName == "ru"
? "ru"
diff --git a/PotatoNV-next/PotatoNV-next.csproj b/PotatoNV-next/PotatoNV-next.csproj
index 4fb9480..a38fba1 100644
--- a/PotatoNV-next/PotatoNV-next.csproj
+++ b/PotatoNV-next/PotatoNV-next.csproj
@@ -116,6 +116,7 @@
+
diff --git a/PotatoNV-next/Properties/AssemblyInfo.cs b/PotatoNV-next/Properties/AssemblyInfo.cs
index 8f04256..1c1c679 100644
--- a/PotatoNV-next/Properties/AssemblyInfo.cs
+++ b/PotatoNV-next/Properties/AssemblyInfo.cs
@@ -20,5 +20,5 @@ using System.Windows;
ResourceDictionaryLocation.SourceAssembly
)]
-[assembly: AssemblyVersion("2.1.0.0")]
-[assembly: AssemblyFileVersion("2.1.0.0")]
+[assembly: AssemblyVersion("2.2.0.0")]
+[assembly: AssemblyFileVersion("2.2.0.0")]
diff --git a/PotatoNV-next/Utils/Common.cs b/PotatoNV-next/Utils/Common.cs
new file mode 100644
index 0000000..15fdcb0
--- /dev/null
+++ b/PotatoNV-next/Utils/Common.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PotatoNV_next.Utils
+{
+ class Common
+ {
+ public static string GetAssemblyVersion(Assembly assembly)
+ {
+ return assembly.GetName().Version.ToString(3);
+ }
+
+ public static string GetAssemblyVersion(string name)
+ {
+ try
+ {
+ return FileVersionInfo.GetVersionInfo(name).FileVersion;
+ }
+ catch
+ {
+ return null;
+ }
+ }
+ }
+}