From 222e05dba058bd9faa30376397e795cc50992c59 Mon Sep 17 00:00:00 2001 From: Strong Recommend Date: Wed, 3 Jan 2024 01:34:53 +0700 Subject: [PATCH] 24f --- HuaweiUnlock/DIAGNOS/Bootloader.cs | 159 +++++++++++ HuaweiUnlock/DIAGNOS/DIAG.cs | 2 + HuaweiUnlock/FlashTool/FlashToolQClegacy.cs | 2 +- HuaweiUnlock/HuaweiUnlock.csproj | 13 +- HuaweiUnlock/TOOLS/Fastboot.cs | 2 +- HuaweiUnlock/TOOLS/HISI.cs | 280 +++++++++++++------- HuaweiUnlock/TOOLS/ImageFlasher.cs | 35 ++- HuaweiUnlock/TOOLS/ResourcesMNG.cs | 31 +++ HuaweiUnlock/TOOLS/UpdateApp.cs | 4 +- HuaweiUnlock/Window.Designer.cs | 114 +++++--- HuaweiUnlock/Window.cs | 41 ++- 11 files changed, 507 insertions(+), 176 deletions(-) create mode 100644 HuaweiUnlock/DIAGNOS/Bootloader.cs create mode 100644 HuaweiUnlock/TOOLS/ResourcesMNG.cs diff --git a/HuaweiUnlock/DIAGNOS/Bootloader.cs b/HuaweiUnlock/DIAGNOS/Bootloader.cs new file mode 100644 index 0000000..93b0bf6 --- /dev/null +++ b/HuaweiUnlock/DIAGNOS/Bootloader.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Security.Cryptography; +using System.Xml; +using static HuaweiUnlocker.LangProc; + +namespace HuaweiUnlocker.DIAGNOS +{ + public class Bootloader + { + public class Image + { + private bool? valid = null; + private int? size = null; + + public string Path { get; } + public string Role { get; } + public uint Address { get; } + private string Hash { get; } + public bool IsValid { get => valid ?? Validate(); } + public int Size { get => size ?? GetSize(); } + + private bool Validate() + { + if (Hash == null) + { + return true; + } + + using (var stream = File.OpenRead(Path)) { + using (var sha1 = SHA1.Create()) + { + stream.Position = 0; + byte[] hash = sha1.ComputeHash(stream); + stream.Close(); + valid = BitConverter.ToString(hash).Replace("-", "").ToLower() == Hash; + } + } + + return valid.Value; + } + + private int GetSize() + { + size = (int)new FileInfo(Path).Length; + + return size.Value; + } + + public Image(string path, string role, uint address, string hash = null) + { + Path = path; + Role = role; + Address = address; + Hash = hash; + } + } + + public Image[] Images { get; } + public string Title { get; } + public string Name { get; } + + public Bootloader(string name, string title, Image[] images) + { + Title = title; + Name = name; + Images = images; + } + + private static uint ParseAddress(string str) => Convert.ToUInt32(str, str.StartsWith("0x") ? 16 : 10); + + private static XmlElement GetRootFromFile(string filename) + { + var xml = new XmlDocument(); + xml.Load(filename); + + var root = xml.DocumentElement; + + if (root.Name != "bootloader") + { + throw new Exception("XML root name is invalid."); + } + + return root; + } + + private readonly static string[] requiredStrings = new[] { "path", "role", "hash", "address" }; + + public static Bootloader ParseBootloader(string filename) + { + var root = GetRootFromFile(filename); + var dir = Path.GetDirectoryName(filename); + + var title = root.GetAttribute("name"); + + if (string.IsNullOrEmpty(title)) + { + LOG(2, "Name attribute is invalid!"); + title = "Unknown bootloader"; + } + + var images = new List(); + + foreach (XmlNode node in root) + { + bool isBad = node.Name != "image"; + + foreach (var key in requiredStrings) + { + var item = node.Attributes.GetNamedItem(key); + isBad |= item == null || string.IsNullOrWhiteSpace(item.Value); + } + + if (isBad) + { + throw new Exception("Failed to parse image"); + } + + images.Add(new Image( + Path.Combine(dir, node.Attributes.GetNamedItem("path").Value), + node.Attributes.GetNamedItem("role").Value, + ParseAddress(node.Attributes.GetNamedItem("address").Value), + node.Attributes.GetNamedItem("hash").Value + )); + } + + return new Bootloader(Path.GetFileName(dir), title, images.ToArray()); + } + + public static Bootloader[] GetBootloaders() + { + var bootloaders = new List(); + var root = Path.Combine(Environment.CurrentDirectory, "bootloaders"); + + if (!Directory.Exists(root)) + { + return new Bootloader[] { }; + } + + var dirs = Directory.GetDirectories(root); + + foreach (var dir in dirs) + { + var manifest = Path.Combine(dir, "manifest.xml"); + + if (!File.Exists(manifest)) + { + LOG(2, $"{Path.GetFileName(dir)}: Manifest not found"); + continue; + } + + bootloaders.Add(ParseBootloader(manifest)); + } + + return bootloaders.ToArray(); + } + } +} diff --git a/HuaweiUnlock/DIAGNOS/DIAG.cs b/HuaweiUnlock/DIAGNOS/DIAG.cs index 39973cd..e625b82 100644 --- a/HuaweiUnlock/DIAGNOS/DIAG.cs +++ b/HuaweiUnlock/DIAGNOS/DIAG.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.ServiceProcess; +using System.Threading; namespace HuaweiUnlocker.DIAGNOS { @@ -332,6 +333,7 @@ public static byte[] READ_SECRET_KEY() byte[] status = DIAG_SEND(pkt, true, true); if (DataS.GetStatus(status)) return status.Skip(4).Take(status.Length - 11).ToArray(); + Thread.Sleep(100); return Encoding.ASCII.GetBytes("Please Auth"); } public static byte[] AUTH_PHONE(byte[] hexdata) diff --git a/HuaweiUnlock/FlashTool/FlashToolQClegacy.cs b/HuaweiUnlock/FlashTool/FlashToolQClegacy.cs index b7c9764..d52c522 100644 --- a/HuaweiUnlock/FlashTool/FlashToolQClegacy.cs +++ b/HuaweiUnlock/FlashTool/FlashToolQClegacy.cs @@ -213,7 +213,7 @@ public static async void FlashPartsXml(string rawxml, string patchxml, string lo { Progress(2); string command = "Tools\\fh_loader.exe"; - string subcommand = "--port=\\\\.\\" + DeviceInfo.Port.ComName + " --showpercentagecomplete --sendxml=" + '"' + rawxml + '"' + " --search_path=" + '"' + path + '"'; + string subcommand = "--port=\\\\.\\" + DeviceInfo.Port.ComName + " --sendxml=" + '"' + rawxml + '"' + " --search_path=" + '"' + path + '"'; string subcommandp = "--port=\\\\.\\" + DeviceInfo.Port.ComName + " --sendxml=" + '"' + patchxml + '"' + " --search_path=" + '"' + path + '"'; if (debug) LOG(-1, "===Flash Partitions XML===" + newline + newline); if (!LoadLoader(loader)) { DeviceInfo.loadedhose = false; LOG(2, "Fail"); CurTask.Dispose(); } diff --git a/HuaweiUnlock/HuaweiUnlock.csproj b/HuaweiUnlock/HuaweiUnlock.csproj index 16f1616..aebf264 100644 --- a/HuaweiUnlock/HuaweiUnlock.csproj +++ b/HuaweiUnlock/HuaweiUnlock.csproj @@ -77,13 +77,10 @@ - C:\Users\werasik2aa\Desktop\QC.QMSLPhone.dll + ..\packages\add\QC.QMSLPhone.dll - C:\Users\werasik2aa\Desktop\QMSL_Library.dll - - - C:\Users\werasik2aa\Desktop\SwDownloadDLL.dll + ..\packages\add\QMSL_Library.dll @@ -105,12 +102,11 @@ - + - - + @@ -155,7 +151,6 @@ Resources.resx True - diff --git a/HuaweiUnlock/TOOLS/Fastboot.cs b/HuaweiUnlock/TOOLS/Fastboot.cs index 7663311..97604f6 100644 --- a/HuaweiUnlock/TOOLS/Fastboot.cs +++ b/HuaweiUnlock/TOOLS/Fastboot.cs @@ -17,7 +17,7 @@ public class Fastboot private const int BLOCK_SIZE = 512 * 1024; // 512 KB public int Timeout = 3000; - public int TimeoutWait = 50; + public int TimeoutWait = 1000; private UsbDevice device; public enum FastbootStatus diff --git a/HuaweiUnlock/TOOLS/HISI.cs b/HuaweiUnlock/TOOLS/HISI.cs index 37b08b0..8e2e2f6 100644 --- a/HuaweiUnlock/TOOLS/HISI.cs +++ b/HuaweiUnlock/TOOLS/HISI.cs @@ -1,63 +1,77 @@ -using System.Collections.Generic; -using System.Security.Cryptography; -using System; -using static HuaweiUnlocker.LangProc; -using System.Text.RegularExpressions; -using System.Text; - -namespace HuaweiUnlocker.TOOLS -{ - public class HISI - { - private Fastboot fb = new Fastboot(); - public bool DisableFBLOCK; +using HuaweiUnlocker.DIAGNOS; +using Microsoft.VisualBasic.Logging; +using System; +using System.Collections.Generic; +using System.Security.Cryptography; +using System.Text; +using System.Text.RegularExpressions; +using static HuaweiUnlocker.LangProc; +namespace HuaweiUnlocker.TOOLS +{ + public class HISI + { + public delegate void RunWorkerCompletedHandler(); + public event RunWorkerCompletedHandler RunWorkerCompleted; + + private Fastboot fb; public string BSN = "NaN"; public string BNUM = "NaN"; public string AVER = "NaN"; public string MODEL = "NaN"; public string BLKEY = "NaN"; - public string FBLOCKSTATE = "NaN"; - public bool SetHWDogState(byte state) - { - foreach (var command in new[] { "hwdog certify set", "backdoor set" }) - { - LOG(0, "Trying: " + command); - Fastboot.Response res = fb.Command("oem " + command + " " + state); - if (debug) LOG(0, Encoding.UTF8.GetString(res.RawData)); - if (res.Status == Fastboot.FastbootStatus.Ok || res.Payload.Contains("equal")) - { - LOG(0, command + " success"); - return true; - } - } - - LOG(2, "Failed to set FBLOCK state!"); - return false; - } - public void UnlockFRP() - { - LOG(0, "Unlocker", "FRP (BETA)"); - string command = "Tools\\fastboot.exe"; - string subcommand = "flash devinfo Tools\\frpUnlocked.img"; - string subcommand2 = "flash frp Tools\\frpPartition.img"; - fb.Command("oem erase frp"); - fb.Command("oem unlock-frp"); - fb.Command("oem frp-unlock"); - LOG(1, "THIS IS BETA!"); - SyncRUN(command, subcommand); - SyncRUN(command, subcommand2); - LOG(1, "THIS IS BETA AND MAY NOT WORK!"); - LOG(1, "Recomended to open the fastboot and flash devinfo(frpunlocked.img) or frp(frpPartition.img) (frp from program Tools folder!"); - } + public string FBLOCKSTATE = "NaN"; + + public void FlashBootloader(Bootloader bootloader, string port) + { + var flasher = new ImageFlasher(); + + LOG(0, "Verifying images..."); + + int asize = 0, dsize = 0; + + foreach (var image in bootloader.Images) + { + if (!image.IsValid) + { + throw new Exception($"Image `{image.Role}` is not valid!"); + } + + asize += image.Size; + } + + if(debug) LOG(0, ($"Opening {port}...")); + + flasher.Open(port); + + LOG(0, $"Uploading {bootloader.Name}..."); + + foreach (var image in bootloader.Images) + { + var size = image.Size; + + LOG(0, $"- {image.Role}"); + + flasher.Write(image.Path, (int)image.Address, x => { + Progress(dsize + (int)(size / 100f * x)); + }); + + dsize += size; + } + + flasher.Close(); + } + public bool ReadInfo() { - if (fb.Connect()) { + if (fb.Connect()) + { string serial = fb.GetSerialNumber(); LOG(0, "SerialnTag", serial); AVER = serial; Fastboot.Response bsn = fb.Command("oem read_bsn"); - if (bsn.Status == Fastboot.FastbootStatus.Ok) { + if (bsn.Status == Fastboot.FastbootStatus.Ok) + { LOG(0, "BSNTag", bsn.Payload); BSN = bsn.Payload; } @@ -98,54 +112,128 @@ public bool ReadInfo() } return false; } - public void SetProp(string prop, byte[] value) - { - LOG(0, "WritingPropTAG", prop); - var cmd = new List(); - - cmd.AddRange(Encoding.ASCII.GetBytes($"getvar:nve:{prop}@")); - cmd.AddRange(value); - - var res = fb.Command(cmd.ToArray()); - - if(debug) LOG(1, Encoding.UTF8.GetString(res.RawData)); - - if (!res.Payload.Contains("set nv ok")) - throw new Exception("Failed to set: "+ res.Payload); - } - public string ReadFactoryKey() - { - var res = fb.Command("getvar:nve:WVLOCK"); - var match = Regex.Match(res.Payload, @"[\w\d]{16}"); - - return match.Success ? match.Value : null; - } - public void SetFBLOCK(int state) + public void UnlockFRP() { - try - { - SetProp("FBLOCK", new[] { (byte) state }); - } - catch (Exception ex) + LOG(0, "Unlocker", "FRP (BETA)"); + string command = "Tools\\fastboot.exe"; + string subcommand = "flash devinfo Tools\\frpUnlocked.img"; + string subcommand2 = "flash frp Tools\\frpPartition.img"; + fb.Command("oem erase frp"); + fb.Command("oem unlock-frp"); + fb.Command("oem frp-unlock"); + LOG(1, "THIS IS BETA!"); + SyncRUN(command, subcommand); + SyncRUN(command, subcommand2); + LOG(1, "THIS IS BETA AND MAY NOT WORK!"); + LOG(1, "Recomended to open the fastboot and flash devinfo(frpunlocked.img) or frp(frpPartition.img) (frp from program Tools folder!"); + } + public void SetNVMEProp(string prop, byte[] value) + { + LOG(0, $"Writing {prop}..."); + + var cmd = new List(); + + cmd.AddRange(Encoding.ASCII.GetBytes($"getvar:nve:{prop}@")); + cmd.AddRange(value); + + var res = fb.Command(cmd.ToArray()); + + LOG(0, "", res.ToString()); + + if (!res.Payload.Contains("set nv ok")) + { + throw new Exception($"Failed to set: {res.Payload}"); + } + } + + public static byte[] GetSHA256(string str) + { + using (var sha256 = SHA256.Create()) + { + return sha256.ComputeHash(Encoding.ASCII.GetBytes(str)); + } + } + + public void SetHWDogState(byte state) + { + foreach (var command in new[] { "hwdog certify set", "backdoor set" }) + { + LOG(0, $"Trying {command}..."); + var res = fb.Command($"oem {command} {state}"); + LOG(0, "", res.ToString()); + if (res.Status == Fastboot.FastbootStatus.Ok || res.Payload.Contains("equal")) + { + LOG(0, $"{command}: success"); + return; + } + } + + LOG(2, "Failed to set FBLOCK state!"); + } + + public string ReadFactoryKey() + { + var res = fb.Command("getvar:nve:WVLOCK"); + var match = Regex.Match(res.Payload, @"[\w\d]{16}"); + + return match.Success ? match.Value : null; + } + + public void WriteBOOTLOADERKEY(string key) + { + var fblockState = (byte)1; + + try + { + SetNVMEProp("FBLOCK", new[] { fblockState }); + } + catch (Exception ex) + { + LOG(2, "Failed to set the FBLOCK, using the alternative method..."); + if(debug) LOG(0, ex.Message); + SetHWDogState(fblockState); + } + + try + { + SetNVMEProp("WVLOCK", Encoding.ASCII.GetBytes(key)); + SetNVMEProp("USRKEY", GetSHA256(key)); + } + catch (Exception ex) + { + LOG(2, "Failed to set the key."); + if(debug) LOG(2, ex.Message); + } + } + + public void StartUnlockPRCS(bool frp, string key, Bootloader d, string port) + { + fb = new Fastboot(); + + try { - LOG(1, "FBLOCKSetTag"); - LOG(2, ex.Message); - SetHWDogState((byte)state); - } - } - public void WriteBOOTLOADERKEY(string KEY) - { - SetFBLOCK(1); + FlashBootloader(d, port); - try - { - SetProp("WVLOCK", Encoding.ASCII.GetBytes(KEY)); - SetProp("USRKEY", SHA256.Create().ComputeHash(Encoding.ASCII.GetBytes(KEY))); - } - catch (Exception ex) - { - LOG(2, "Failed to set the key.", ex.Message); - } - } - } -} + if (frp) + { + LOG(1, "Unlocking frp only"); + if (ReadInfo()) + UnlockFRP(); + return; + } + LOG(0, "[Fastboot] ", "CheckCon"); + if (ReadInfo()) + { + WriteBOOTLOADERKEY(key); + LOG(0, $"New unlock code:"); + fb.Disconnect(); + } + } + catch (Exception ex) + { + LOG(2, ex.Message); + if (debug) LOG(2, ex.StackTrace); + } + } + } +} diff --git a/HuaweiUnlock/TOOLS/ImageFlasher.cs b/HuaweiUnlock/TOOLS/ImageFlasher.cs index 4c480e4..3b41263 100644 --- a/HuaweiUnlock/TOOLS/ImageFlasher.cs +++ b/HuaweiUnlock/TOOLS/ImageFlasher.cs @@ -15,6 +15,29 @@ public class ImageFlasher private readonly static byte[] dataframe = new byte[] { 0xDA }; private readonly static byte[] tailframe = new byte[] { 0xED }; + private SerialPort port; + + public void Open(string portName) + { + port = new SerialPort + { + PortName = portName, + BaudRate = BAUDRATE, + DtrEnable = true, + RtsEnable = true, + ReadTimeout = 1000, + WriteTimeout = 1000 + }; + port.Open(); + } + + public void Close() + { + port.Close(); + port.Dispose(); + port = null; + } + public void Write(string path, int address, Action reportProgress = null) { var stream = new FileStream(path, FileMode.Open, FileAccess.Read); @@ -34,7 +57,9 @@ public void Write(string path, int address, Action reportProgress = null) length -= MAX_DATA_LEN; if (n % (nframes > 250 ? 10 : 3) == 0) + { reportProgress?.Invoke((int)(100f * n / nframes)); + } } if (length > 0) @@ -95,15 +120,17 @@ private void SendFrame(byte[] data) var count = frameList.Count(); var frame = frameList.ToArray(); - SerialManager.Port.Write(frame, 0, count); + port.Write(frame, 0, count); - byte _ack = (byte)SerialManager.Port.ReadByte(); + byte _ack = (byte)port.ReadByte(); - SerialManager.Port.DiscardInBuffer(); - SerialManager.Port.DiscardOutBuffer(); + port.DiscardInBuffer(); + port.DiscardOutBuffer(); if (_ack != 0xAA) + { throw new Exception(string.Format("ACK is invalid! ACK={0:X2}; Excepted={1:X2}", _ack, 0xAA)); + } } } } \ No newline at end of file diff --git a/HuaweiUnlock/TOOLS/ResourcesMNG.cs b/HuaweiUnlock/TOOLS/ResourcesMNG.cs new file mode 100644 index 0000000..9823811 --- /dev/null +++ b/HuaweiUnlock/TOOLS/ResourcesMNG.cs @@ -0,0 +1,31 @@ +using System; +using System.IO; +using System.Reflection; + +namespace HuaweiUnlocker +{ + public class ResourcesMNG + { + public static byte[] GetResource(string ResourceName) + { + Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(ResourceName); + byte[] data = new byte[stream.Length]; + stream.Read(data, 0, (int)stream.Length); + return data; + } + public static Stream GetResourceStream(string ResourceName) + { + return Assembly.GetExecutingAssembly().GetManifestResourceStream(ResourceName); + } + public static void SaveResources(string ResourceName, string SavePath, string SaveName = "") + { + if (!Directory.Exists(SavePath)) Directory.CreateDirectory(SavePath); + string myspace = typeof(ResourcesMNG).Namespace; + Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(myspace + "." + ResourceName); + FileStream filewritter = new FileStream(SavePath + "\\" + (string.IsNullOrEmpty(SaveName) ? ResourceName : SaveName), FileMode.CreateNew); + for (int i = 0; i < stream.Length; i++) filewritter.WriteByte((byte)stream.ReadByte()); + filewritter.Close(); + filewritter.Dispose(); + } + } +} diff --git a/HuaweiUnlock/TOOLS/UpdateApp.cs b/HuaweiUnlock/TOOLS/UpdateApp.cs index 6f5d063..cf0a43b 100644 --- a/HuaweiUnlock/TOOLS/UpdateApp.cs +++ b/HuaweiUnlock/TOOLS/UpdateApp.cs @@ -65,7 +65,9 @@ public static async void Unpack(string path, int state, string loader = "") if (gpttable.ContainsKey(a.FileType.ToLower())) { FlashToolQClegacy.CurPartLenght = (int)a.FileSize; - FlashToolQClegacy.Write(a.FileType.ToLower(), loader, "UnlockFiles/UpdateAPP/" + a.FileType.ToLower() + ".img"); + string command = "Tools\\emmcdl.exe"; + string subcommand = "-p " + DeviceInfo.Port.ComName + " -f " + '"' + loader + '"' + " -b " + a.FileType.ToLower() + " " + '"' + "UnlockFiles/UpdateAPP/" + a.FileType.ToLower() + ".img" + '"'; + SyncRUN(command, subcommand); i++; } Progress(i / gpttable.Count * 100); diff --git a/HuaweiUnlock/Window.Designer.cs b/HuaweiUnlock/Window.Designer.cs index 36f1cc4..279ee79 100644 --- a/HuaweiUnlock/Window.Designer.cs +++ b/HuaweiUnlock/Window.Designer.cs @@ -18,9 +18,9 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle9 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle13 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle14 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle15 = new System.Windows.Forms.DataGridViewCellStyle(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Window)); this.pather = new System.Windows.Forms.TextBox(); this.DETECTED = new System.Windows.Forms.Label(); @@ -93,6 +93,8 @@ private void InitializeComponent() this.CMDbox = new System.Windows.Forms.TextBox(); this.NC = new System.Windows.Forms.TabPage(); this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.FRPchk = new System.Windows.Forms.CheckBox(); + this.FrpHISIUnlock = new HuaweiUnlocker.UI.NButton(); this.UNLOCKHISI = new HuaweiUnlocker.UI.NButton(); this.HISI_board_FB = new HuaweiUnlocker.UI.NButton(); this.EnDisFBLOCK = new System.Windows.Forms.CheckBox(); @@ -153,7 +155,6 @@ private void InitializeComponent() this.PortFindUpd = new System.Windows.Forms.Timer(this.components); this.IdentifyBTN = new System.Windows.Forms.Button(); this.PGG = new HuaweiUnlocker.UI.NProgressBar(); - this.FRPchk = new System.Windows.Forms.CheckBox(); this.panel1.SuspendLayout(); this.Tab.SuspendLayout(); this.MA.SuspendLayout(); @@ -246,6 +247,8 @@ private void InitializeComponent() // AutoXml // this.AutoXml.AutoSize = true; + this.AutoXml.Checked = true; + this.AutoXml.CheckState = System.Windows.Forms.CheckState.Checked; this.AutoXml.Font = new System.Drawing.Font("Arial", 10.2F, System.Drawing.FontStyle.Bold); this.AutoXml.ForeColor = System.Drawing.Color.AntiqueWhite; this.AutoXml.ImeMode = System.Windows.Forms.ImeMode.NoControl; @@ -1337,40 +1340,40 @@ private void InitializeComponent() this.PARTLIST.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders; this.PARTLIST.BackgroundColor = System.Drawing.Color.FromArgb(((int)(((byte)(27)))), ((int)(((byte)(38)))), ((int)(((byte)(49))))); this.PARTLIST.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Sunken; - dataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.TopCenter; - dataGridViewCellStyle7.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(42)))), ((int)(((byte)(80))))); - dataGridViewCellStyle7.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Bold); - dataGridViewCellStyle7.ForeColor = System.Drawing.SystemColors.Menu; - dataGridViewCellStyle7.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle7.SelectionForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(5)))), ((int)(((byte)(42)))), ((int)(((byte)(80))))); - dataGridViewCellStyle7.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.PARTLIST.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle7; + dataGridViewCellStyle13.Alignment = System.Windows.Forms.DataGridViewContentAlignment.TopCenter; + dataGridViewCellStyle13.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(3)))), ((int)(((byte)(42)))), ((int)(((byte)(80))))); + dataGridViewCellStyle13.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Bold); + dataGridViewCellStyle13.ForeColor = System.Drawing.SystemColors.Menu; + dataGridViewCellStyle13.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle13.SelectionForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(5)))), ((int)(((byte)(42)))), ((int)(((byte)(80))))); + dataGridViewCellStyle13.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.PARTLIST.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle13; this.PARTLIST.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.PARTLIST.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.P, this.O, this.L}); - dataGridViewCellStyle8.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle8.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(44)))), ((int)(((byte)(62)))), ((int)(((byte)(80))))); - dataGridViewCellStyle8.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Bold); - dataGridViewCellStyle8.ForeColor = System.Drawing.Color.Snow; - dataGridViewCellStyle8.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle8.SelectionForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(5)))), ((int)(((byte)(47)))), ((int)(((byte)(60))))); - dataGridViewCellStyle8.WrapMode = System.Windows.Forms.DataGridViewTriState.False; - this.PARTLIST.DefaultCellStyle = dataGridViewCellStyle8; + dataGridViewCellStyle14.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle14.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(44)))), ((int)(((byte)(62)))), ((int)(((byte)(80))))); + dataGridViewCellStyle14.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Bold); + dataGridViewCellStyle14.ForeColor = System.Drawing.Color.Snow; + dataGridViewCellStyle14.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle14.SelectionForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(5)))), ((int)(((byte)(47)))), ((int)(((byte)(60))))); + dataGridViewCellStyle14.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this.PARTLIST.DefaultCellStyle = dataGridViewCellStyle14; this.PARTLIST.GridColor = System.Drawing.Color.FromArgb(((int)(((byte)(27)))), ((int)(((byte)(38)))), ((int)(((byte)(49))))); this.PARTLIST.ImeMode = System.Windows.Forms.ImeMode.Close; this.PARTLIST.Location = new System.Drawing.Point(-2, -2); this.PARTLIST.Name = "PARTLIST"; this.PARTLIST.ReadOnly = true; - dataGridViewCellStyle9.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle9.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(33)))), ((int)(((byte)(47)))), ((int)(((byte)(60))))); - dataGridViewCellStyle9.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Bold); - dataGridViewCellStyle9.ForeColor = System.Drawing.SystemColors.Info; - dataGridViewCellStyle9.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle9.SelectionForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(33)))), ((int)(((byte)(47)))), ((int)(((byte)(60))))); - dataGridViewCellStyle9.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.PARTLIST.RowHeadersDefaultCellStyle = dataGridViewCellStyle9; + dataGridViewCellStyle15.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle15.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(33)))), ((int)(((byte)(47)))), ((int)(((byte)(60))))); + dataGridViewCellStyle15.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Bold); + dataGridViewCellStyle15.ForeColor = System.Drawing.SystemColors.Info; + dataGridViewCellStyle15.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle15.SelectionForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(33)))), ((int)(((byte)(47)))), ((int)(((byte)(60))))); + dataGridViewCellStyle15.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.PARTLIST.RowHeadersDefaultCellStyle = dataGridViewCellStyle15; this.PARTLIST.RowHeadersVisible = false; this.PARTLIST.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders; this.PARTLIST.RowTemplate.ReadOnly = true; @@ -1486,6 +1489,7 @@ private void InitializeComponent() // groupBox3 // this.groupBox3.Controls.Add(this.FRPchk); + this.groupBox3.Controls.Add(this.FrpHISIUnlock); this.groupBox3.Controls.Add(this.UNLOCKHISI); this.groupBox3.Controls.Add(this.HISI_board_FB); this.groupBox3.Controls.Add(this.EnDisFBLOCK); @@ -1500,6 +1504,43 @@ private void InitializeComponent() this.groupBox3.TabStop = false; this.groupBox3.Text = "Fastboot"; // + // FRPchk + // + this.FRPchk.AutoSize = true; + this.FRPchk.Location = new System.Drawing.Point(129, 336); + this.FRPchk.Name = "FRPchk"; + this.FRPchk.Size = new System.Drawing.Size(132, 20); + this.FRPchk.TabIndex = 25; + this.FRPchk.Text = "FRP Unlock Only"; + this.FRPchk.UseVisualStyleBackColor = true; + // + // FrpHISIUnlock + // + this.FrpHISIUnlock.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(35)))), ((int)(((byte)(37)))), ((int)(((byte)(90))))); + this.FrpHISIUnlock.BackColorAdditional = System.Drawing.Color.Gray; + this.FrpHISIUnlock.BackColorGradientEnabled = false; + this.FrpHISIUnlock.BackColorGradientMode = System.Drawing.Drawing2D.LinearGradientMode.Horizontal; + this.FrpHISIUnlock.BorderColor = System.Drawing.Color.Tomato; + this.FrpHISIUnlock.BorderColorEnabled = false; + this.FrpHISIUnlock.BorderColorOnHover = System.Drawing.Color.Tomato; + this.FrpHISIUnlock.BorderColorOnHoverEnabled = false; + this.FrpHISIUnlock.Cursor = System.Windows.Forms.Cursors.Hand; + this.FrpHISIUnlock.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.FrpHISIUnlock.ForeColor = System.Drawing.Color.White; + this.FrpHISIUnlock.Location = new System.Drawing.Point(6, 364); + this.FrpHISIUnlock.Name = "FrpHISIUnlock"; + this.FrpHISIUnlock.RippleColor = System.Drawing.Color.Black; + this.FrpHISIUnlock.RoundingEnable = false; + this.FrpHISIUnlock.Size = new System.Drawing.Size(405, 28); + this.FrpHISIUnlock.TabIndex = 24; + this.FrpHISIUnlock.Text = "FRP Unlock"; + this.FrpHISIUnlock.TextHover = null; + this.FrpHISIUnlock.UseDownPressEffectOnClick = false; + this.FrpHISIUnlock.UseRippleEffect = true; + this.FrpHISIUnlock.UseVisualStyleBackColor = false; + this.FrpHISIUnlock.UseZoomEffectOnHover = false; + this.FrpHISIUnlock.Click += new System.EventHandler(this.FrpHISIUnlock_Click); + // // UNLOCKHISI // this.UNLOCKHISI.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(35)))), ((int)(((byte)(37)))), ((int)(((byte)(90))))); @@ -1557,9 +1598,7 @@ private void InitializeComponent() // EnDisFBLOCK // this.EnDisFBLOCK.AutoSize = true; - this.EnDisFBLOCK.Checked = true; - this.EnDisFBLOCK.CheckState = System.Windows.Forms.CheckState.Checked; - this.EnDisFBLOCK.Location = new System.Drawing.Point(6, 365); + this.EnDisFBLOCK.Location = new System.Drawing.Point(6, 338); this.EnDisFBLOCK.Name = "EnDisFBLOCK"; this.EnDisFBLOCK.Size = new System.Drawing.Size(79, 20); this.EnDisFBLOCK.TabIndex = 20; @@ -1625,7 +1664,7 @@ private void InitializeComponent() this.isVCOM.AutoSize = true; this.isVCOM.Checked = true; this.isVCOM.CheckState = System.Windows.Forms.CheckState.Checked; - this.isVCOM.Location = new System.Drawing.Point(306, 365); + this.isVCOM.Location = new System.Drawing.Point(306, 336); this.isVCOM.Name = "isVCOM"; this.isVCOM.Size = new System.Drawing.Size(105, 20); this.isVCOM.TabIndex = 14; @@ -2423,16 +2462,6 @@ private void InitializeComponent() this.PGG.ValueMaximum = 100; this.PGG.ValueMinimum = 0; // - // FRPchk - // - this.FRPchk.AutoSize = true; - this.FRPchk.Location = new System.Drawing.Point(152, 365); - this.FRPchk.Name = "FRPchk"; - this.FRPchk.Size = new System.Drawing.Size(99, 20); - this.FRPchk.TabIndex = 25; - this.FRPchk.Text = "FRP-Unlock"; - this.FRPchk.UseVisualStyleBackColor = true; - // // Window // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -2638,6 +2667,7 @@ private void InitializeComponent() public System.Windows.Forms.ComboBox LoaderBox; private System.Windows.Forms.Label TUTR2; public System.Windows.Forms.ComboBox IndexiesOEMdata; + private UI.NButton FrpHISIUnlock; private System.Windows.Forms.CheckBox FRPchk; } } \ No newline at end of file diff --git a/HuaweiUnlock/Window.cs b/HuaweiUnlock/Window.cs index 4bdc8c3..d90615f 100644 --- a/HuaweiUnlock/Window.cs +++ b/HuaweiUnlock/Window.cs @@ -232,7 +232,7 @@ private void Flash_Click(object sender, EventArgs e) if (!RAW.Checked) { LOG(0, "EemmcXML_WPS", pather.Text); - FlashPartsXml(Xm.Text, PatXm.Text, AutoLdr.Checked ? "" : LoaderBox.Text, pather.Text); + FlashPartsXml(Xm.Text, PatXm.Text, AutoLdr.Checked ? GuessMbn() : LoaderBox.Text, pather.Text); } else { @@ -247,13 +247,16 @@ private void PATHTOFIRMWARE_Clck(object sender, EventArgs e) { if (!RAW.Checked) { - FolderBrowserDialog openFileDialog = new FolderBrowserDialog(); + OpenFileDialog openFileDialog = new OpenFileDialog() + { + Filter = "XML Files (*.xml)|*.xml", + }; if (openFileDialog.ShowDialog() == DialogResult.OK) { - pather.Text = openFileDialog.SelectedPath; + pather.Text = System.IO.Path.GetDirectoryName(openFileDialog.FileName); if (AutoXml.Checked) { - foreach (var a in Directory.GetFiles(openFileDialog.SelectedPath)) + foreach (var a in Directory.GetFiles(pather.Text)) { if (AutoXml.Checked && a.EndsWith(".xml")) { @@ -638,7 +641,7 @@ private void RdHISIinfo_Click(object sender, EventArgs e) private void FBLstHISI_Click(object sender, EventArgs e) { LOG(-1, "=============WRITE FBLOCK (FASTBOOT)============="); - LOG(-1, "=============> VALUE: " + (EnDisFBLOCK.Checked ? 1 : 0) + " <============="); + LOG(-1, "=============> VALUE: " + (EnDisFBLOCK.Checked ? 0 : 1) + " <============="); try { if (HISI.ReadInfo()) @@ -649,7 +652,7 @@ private void FBLstHISI_Click(object sender, EventArgs e) FblockStateTxt.Text = HISI.FBLOCKSTATE; BLKEYTXT.Text = HISI.BLKEY; VersionIdTxt.Text = HISI.AVER; - HISI.SetFBLOCK(EnDisFBLOCK.Checked ? 1 : 0); + HISI.SetNVMEProp("FBLOCK", new[] { (byte)(EnDisFBLOCK.Checked ? 0 : 1) }); } } catch (Exception se) @@ -688,8 +691,7 @@ private void HISI_board_FB_Click(object sender, EventArgs e) LOG(2, se.Message); } } - - private void UNLOCKHISI_Click(object sender, EventArgs e) + private async void UNLOCKHISI_Click(object sender, EventArgs e) { LOG(-1, "-->HISI UNL LOGS<--"); try @@ -728,21 +730,16 @@ private void UNLOCKHISI_Click(object sender, EventArgs e) LangProc.DeviceInfo.Port = GETPORT("huawei usb com", PORTBOX.Text); if (LangProc.DeviceInfo.Port.ComName != "NaN") { - FlashToolHisi.FlashBootloader(Bootloader.ParseBootloader(Path)); - LOG(0, "[FastBoot] ", "CheckCon"); - if (HISI.ReadInfo()) + CurTask = Task.Run(() => { - BuildIdTxt.Text = HISI.AVER; - ModelIdTxt.Text = HISI.MODEL; - VersionIdTxt.Text = HISI.BNUM; - FblockStateTxt.Text = HISI.FBLOCKSTATE; - BLKEYTXT.Text = HISI.BLKEY; - if (!FRPchk.Checked) - HISI.WriteBOOTLOADERKEY(BLkeyHI.Text); - else - HISI.UnlockFRP(); - } - else LOG(2, "DeviceNotCon", "[FastBoot] TIMED OUT"); + HISI.StartUnlockPRCS(FRPchk.Checked, BLkeyHI.Text, Bootloader.ParseBootloader(Path), LangProc.DeviceInfo.Port.ComName); + }); + await CurTask; + BuildIdTxt.Text = HISI.AVER; + ModelIdTxt.Text = HISI.MODEL; + VersionIdTxt.Text = HISI.BNUM; + FblockStateTxt.Text = HISI.FBLOCKSTATE; + BLKEYTXT.Text = HISI.BLKEY; } else { Tab.Enabled = true; LOG(2, "DeviceNotCon"); } }