From 8be6f336914cc0cef701471ce37e8094cbaf8df4 Mon Sep 17 00:00:00 2001 From: Gustave Monce Date: Sun, 23 Jun 2024 10:55:30 +0200 Subject: [PATCH] Cleanup --- UnifiedFlashingPlatformTransport.Commands.cs | 58 +++++++++---------- UnifiedFlashingPlatformTransport.ReadParam.cs | 14 ++--- UnifiedFlashingPlatformTransport.WPI.cs | 16 ++--- UnifiedFlashingPlatformTransport.cs | 26 ++++----- 4 files changed, 57 insertions(+), 57 deletions(-) diff --git a/UnifiedFlashingPlatformTransport.Commands.cs b/UnifiedFlashingPlatformTransport.Commands.cs index f6b5ee3..4831e80 100644 --- a/UnifiedFlashingPlatformTransport.Commands.cs +++ b/UnifiedFlashingPlatformTransport.Commands.cs @@ -6,74 +6,74 @@ // Not valid commands // /* NOK */ - private static string Signature => "NOK"; + private const string Signature = "NOK"; /* NOKX */ - private static string ExtendedMessageSignature => $"{Signature}X"; + private const string ExtendedMessageSignature = $"{Signature}X"; /* NOKXC */ - private static string CommonExtendedMessageSignature => $"{ExtendedMessageSignature}C"; + private const string CommonExtendedMessageSignature = $"{ExtendedMessageSignature}C"; /* NOKXF */ - private static string UFPExtendedMessageSignature => $"{ExtendedMessageSignature}F"; + private const string UFPExtendedMessageSignature = $"{ExtendedMessageSignature}F"; // // Normal commands // /* NOKF */ - private static string FlashSignature => $"{Signature}F"; + private const string FlashSignature = $"{Signature}F"; /* NOKI */ - private static string HelloSignature => $"{Signature}I"; + private const string HelloSignature = $"{Signature}I"; /* NOKM */ - private static string MassStorageSignature => $"{Signature}M"; + private const string MassStorageSignature = $"{Signature}M"; /* NOKN */ - private static string TelemetryEndSignature => $"{Signature}N"; + private const string TelemetryEndSignature = $"{Signature}N"; /* NOKR */ - private static string RebootSignature => $"{Signature}R"; + private const string RebootSignature = $"{Signature}R"; /* NOKS */ - private static string TelemetryStartSignature => $"{Signature}S"; + private const string TelemetryStartSignature = $"{Signature}S"; /* NOKT */ - private static string GetGPTSignature => $"{Signature}T"; + private const string GetGPTSignature = $"{Signature}T"; /* NOKV */ - private static string InfoQuerySignature => $"{Signature}V"; + private const string InfoQuerySignature = $"{Signature}V"; /* NOKZ */ - private static string ShutdownSignature => $"{Signature}Z"; + private const string ShutdownSignature = $"{Signature}Z"; // // Common extended commands // /* NOKXCB */ - private static string SwitchModeSignature => $"{CommonExtendedMessageSignature}B"; + private const string SwitchModeSignature = $"{CommonExtendedMessageSignature}B"; /* NOKXCC */ - private static string ClearScreenSignature => $"{CommonExtendedMessageSignature}C"; + private const string ClearScreenSignature = $"{CommonExtendedMessageSignature}C"; /* NOKXCD */ - private static string GetDirectoryEntriesSignature => $"{CommonExtendedMessageSignature}D"; + private const string GetDirectoryEntriesSignature = $"{CommonExtendedMessageSignature}D"; /* NOKXCE */ - private static string EchoSignature => $"{CommonExtendedMessageSignature}E"; + private const string EchoSignature = $"{CommonExtendedMessageSignature}E"; /* NOKXCF */ - private static string GetFileSignature => $"{CommonExtendedMessageSignature}F"; + private const string GetFileSignature = $"{CommonExtendedMessageSignature}F"; /* NOKXCM */ - private static string DisplayCustomMessageSignature => $"{CommonExtendedMessageSignature}M"; + private const string DisplayCustomMessageSignature = $"{CommonExtendedMessageSignature}M"; /* NOKXCP */ - private static string PutFileSignature => $"{CommonExtendedMessageSignature}P"; + private const string PutFileSignature = $"{CommonExtendedMessageSignature}P"; /* NOKXCT */ - private static string BenchmarkTestsSignature => $"{CommonExtendedMessageSignature}T"; + private const string BenchmarkTestsSignature = $"{CommonExtendedMessageSignature}T"; // // UFP extended commands // /* NOKXFF */ - private static string AsyncFlashModeSignature => $"{UFPExtendedMessageSignature}F"; + private const string AsyncFlashModeSignature = $"{UFPExtendedMessageSignature}F"; /* NOKXFI */ - private static string UnlockSignature => $"{UFPExtendedMessageSignature}I"; + private const string UnlockSignature = $"{UFPExtendedMessageSignature}I"; /* NOKXFO */ - private static string RelockSignature => $"{UFPExtendedMessageSignature}O"; + private const string RelockSignature = $"{UFPExtendedMessageSignature}O"; /* NOKXFR */ - private static string ReadParamSignature => $"{UFPExtendedMessageSignature}R"; + private const string ReadParamSignature = $"{UFPExtendedMessageSignature}R"; /* NOKXFS */ - private static string SecureFlashSignature => $"{UFPExtendedMessageSignature}S"; + private const string SecureFlashSignature = $"{UFPExtendedMessageSignature}S"; /* NOKXFT */ - private static string TelemetryReadSignature => $"{UFPExtendedMessageSignature}T"; + private const string TelemetryReadSignature = $"{UFPExtendedMessageSignature}T"; /* NOKXFW */ - private static string WriteParamSignature => $"{UFPExtendedMessageSignature}W"; + private const string WriteParamSignature = $"{UFPExtendedMessageSignature}W"; /* NOKXFX */ - private static string GetLogsSignature => $"{UFPExtendedMessageSignature}X"; + private const string GetLogsSignature = $"{UFPExtendedMessageSignature}X"; } } diff --git a/UnifiedFlashingPlatformTransport.ReadParam.cs b/UnifiedFlashingPlatformTransport.ReadParam.cs index 6a54846..a32a633 100644 --- a/UnifiedFlashingPlatformTransport.ReadParam.cs +++ b/UnifiedFlashingPlatformTransport.ReadParam.cs @@ -9,7 +9,7 @@ namespace UnifiedFlashingPlatform public byte[]? ReadParam(string Param) { byte[] Request = new byte[0x0B]; - string Header = ReadParamSignature; // NOKXFR + const string Header = ReadParamSignature; // NOKXFR Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); Buffer.BlockCopy(Encoding.ASCII.GetBytes(Param), 0, Request, 7, Param.Length); @@ -84,7 +84,7 @@ namespace UnifiedFlashingPlatform byte[] DirectoryNameBuffer = Encoding.Unicode.GetBytes(DirectoryName); byte[] Request = new byte[87 + DirectoryNameBuffer.Length + 2]; - string Header = ReadParamSignature; // NOKXFR + const string Header = ReadParamSignature; // NOKXFR const string Param = "DES\0"; Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); @@ -247,7 +247,7 @@ namespace UnifiedFlashingPlatform byte[] FileNameBuffer = Encoding.Unicode.GetBytes(FileName); byte[] Request = new byte[87 + FileNameBuffer.Length + 2]; - string Header = ReadParamSignature; // NOKXFR + const string Header = ReadParamSignature; // NOKXFR const string Param = "FZ\0\0"; Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); @@ -277,7 +277,7 @@ namespace UnifiedFlashingPlatform public UefiVariable? ReadUEFIVariable(Guid Guid, string Name, uint Size) { byte[] Request = new byte[39 + ((Name.Length + 1) * 2)]; - string Header = ReadParamSignature; // NOKXFR + const string Header = ReadParamSignature; // NOKXFR string Param = "GUFV"; byte[] VariableNameBuffer = Encoding.Unicode.GetBytes(Name); @@ -310,7 +310,7 @@ namespace UnifiedFlashingPlatform public uint? ReadUEFIVariableSize(Guid Guid, string Name) { byte[] Request = new byte[39 + ((Name.Length + 1) * 2)]; - string Header = "NOKXFR"; // NOKXFR + const string Header = "NOKXFR"; // NOKXFR string Param = "GUVS"; byte[] VariableNameBuffer = Encoding.Unicode.GetBytes(Name); @@ -346,7 +346,7 @@ namespace UnifiedFlashingPlatform public ulong? ReadLogSize(DeviceLogType LogType) { byte[] Request = new byte[0x10]; - string Header = ReadParamSignature; // NOKXFR + const string Header = ReadParamSignature; // NOKXFR const string Param = "LZ\0\0"; Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); @@ -377,7 +377,7 @@ namespace UnifiedFlashingPlatform public uint? ReadModeData(Mode Mode) { byte[] Request = new byte[0x10]; - string Header = ReadParamSignature; // NOKXFR + const string Header = ReadParamSignature; // NOKXFR string Param = "MODE"; Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); diff --git a/UnifiedFlashingPlatformTransport.WPI.cs b/UnifiedFlashingPlatformTransport.WPI.cs index e21c0b1..1bef174 100644 --- a/UnifiedFlashingPlatformTransport.WPI.cs +++ b/UnifiedFlashingPlatformTransport.WPI.cs @@ -18,7 +18,7 @@ namespace UnifiedFlashingPlatform byte[] Request = new byte[Data.Length + 0x40]; - string Header = FlashSignature; // NOKF + const string Header = FlashSignature; // NOKF Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); Request[0x05] = TargetDevice; // Target device: 0: eMMC, 1: SDIO, 2: Other ???, 3: ??? Buffer.BlockCopy(BigEndian.GetBytes(StartSector, 4), 0, Request, 0x0B, 4); // Start sector @@ -77,7 +77,7 @@ namespace UnifiedFlashingPlatform }*/ byte[] Request = new byte[0x04]; - string Header = GetGPTSignature; + const string Header = GetGPTSignature; System.Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); @@ -177,7 +177,7 @@ namespace UnifiedFlashingPlatform { byte[] Request = new byte[FfuHeader.Length + 0x20]; - string Header = SecureFlashSignature; + const string Header = SecureFlashSignature; Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); Buffer.BlockCopy(BigEndian.GetBytes(0x0001, 2), 0, Request, 0x06, 2); // Protocol version = 0x0001 Request[0x08] = (byte)Progress; // Progress = 0% (0 - 100) @@ -203,7 +203,7 @@ namespace UnifiedFlashingPlatform { byte[] Request = new byte[FfuHeader.Length + 0x3C]; - string Header = SecureFlashSignature; + const string Header = SecureFlashSignature; Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); Buffer.BlockCopy(BigEndian.GetBytes(0x0002, 2), 0, Request, 0x06, 2); // Protocol version = 0x0002 Request[0x08] = (byte)Progress; // Progress = 0% (0 - 100) @@ -240,7 +240,7 @@ namespace UnifiedFlashingPlatform { byte[] Request = new byte[FfuChunk.Length + 0x1C]; - string Header = SecureFlashSignature; + const string Header = SecureFlashSignature; Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); Buffer.BlockCopy(BigEndian.GetBytes((int)FfuProtocol.ProtocolSyncV1, 2), 0, Request, 0x06, 2); // Protocol version = 0x0001 Request[0x08] = (byte)Progress; // Progress = 0% (0 - 100) @@ -267,7 +267,7 @@ namespace UnifiedFlashingPlatform { byte[] Request = new byte[FfuChunk.Length + 0x20]; - string Header = SecureFlashSignature; + const string Header = SecureFlashSignature; Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); Buffer.BlockCopy(BigEndian.GetBytes((int)FfuProtocol.ProtocolSyncV2, 2), 0, Request, 0x06, 2); // Protocol Request[0x08] = (byte)Progress; // Progress = 0% (0 - 100) @@ -294,7 +294,7 @@ namespace UnifiedFlashingPlatform { byte[] Request = new byte[FfuChunk.Length + 0x20]; - string Header = SecureFlashSignature; + const string Header = SecureFlashSignature; Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); Buffer.BlockCopy(BigEndian.GetBytes((int)FfuProtocol.ProtocolAsyncV3, 2), 0, Request, 0x06, 2); // Protocol Request[0x08] = (byte)Progress; // Progress = 0% (0 - 100) @@ -640,7 +640,7 @@ namespace UnifiedFlashingPlatform public void Shutdown() { byte[] Request = new byte[4]; - string Header = ShutdownSignature; + const string Header = ShutdownSignature; Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); ExecuteRawVoidMethod(Request); } diff --git a/UnifiedFlashingPlatformTransport.cs b/UnifiedFlashingPlatformTransport.cs index a5e7448..90741f3 100644 --- a/UnifiedFlashingPlatformTransport.cs +++ b/UnifiedFlashingPlatformTransport.cs @@ -98,7 +98,7 @@ namespace UnifiedFlashingPlatform public void Relock() { byte[] Request = new byte[7]; - string Header = RelockSignature; // NOKXFO + const string Header = RelockSignature; // NOKXFO Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); _ = ExecuteRawMethod(Request); } @@ -106,7 +106,7 @@ namespace UnifiedFlashingPlatform public void MassStorage() { byte[] Request = new byte[7]; - string Header = MassStorageSignature; // NOKM + const string Header = MassStorageSignature; // NOKM Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); _ = ExecuteRawMethod(Request); } @@ -114,7 +114,7 @@ namespace UnifiedFlashingPlatform public void RebootPhone() { byte[] Request = new byte[7]; - string Header = $"{SwitchModeSignature}R"; // NOKXCBR + const string Header = $"{SwitchModeSignature}R"; // NOKXCBR Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); _ = ExecuteRawMethod(Request); } @@ -122,7 +122,7 @@ namespace UnifiedFlashingPlatform public void SwitchToUFP() { byte[] Request = new byte[7]; - string Header = $"{SwitchModeSignature}U"; // NOKXCBU + const string Header = $"{SwitchModeSignature}U"; // NOKXCBU Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); _ = ExecuteRawMethod(Request); } @@ -130,7 +130,7 @@ namespace UnifiedFlashingPlatform public void ContinueBoot() { byte[] Request = new byte[7]; - string Header = $"{SwitchModeSignature}W"; // NOKXCBW + const string Header = $"{SwitchModeSignature}W"; // NOKXCBW Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); _ = ExecuteRawMethod(Request); } @@ -138,7 +138,7 @@ namespace UnifiedFlashingPlatform public void PowerOff() { byte[] Request = new byte[7]; - string Header = $"{SwitchModeSignature}Z"; // NOKXCBZ + const string Header = $"{SwitchModeSignature}Z"; // NOKXCBZ Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); ExecuteRawVoidMethod(Request); } @@ -146,7 +146,7 @@ namespace UnifiedFlashingPlatform public void TransitionToUFPBootApp() { byte[] Request = new byte[7]; - string Header = $"{SwitchModeSignature}T"; // NOKXCBT + const string Header = $"{SwitchModeSignature}T"; // NOKXCBT Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); ExecuteRawVoidMethod(Request); } @@ -155,7 +155,7 @@ namespace UnifiedFlashingPlatform { byte[] MessageBuffer = Encoding.Unicode.GetBytes(Message); byte[] Request = new byte[8 + MessageBuffer.Length]; - string Header = DisplayCustomMessageSignature; // NOKXCM + const string Header = DisplayCustomMessageSignature; // NOKXCM Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); Buffer.BlockCopy(BitConverter.GetBytes(Row).Reverse().ToArray(), 0, Request, 6, 2); @@ -167,7 +167,7 @@ namespace UnifiedFlashingPlatform public void ClearScreen() { byte[] Request = new byte[6]; - string Header = ClearScreenSignature; // NOKXCC + const string Header = ClearScreenSignature; // NOKXCC Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); _ = ExecuteRawMethod(Request); } @@ -175,7 +175,7 @@ namespace UnifiedFlashingPlatform public byte[]? Echo(byte[] DataPayload) { byte[] Request = new byte[10 + DataPayload.Length]; - string Header = EchoSignature; // NOKXCE + const string Header = EchoSignature; // NOKXCE Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); Buffer.BlockCopy(BitConverter.GetBytes(DataPayload.Length).Reverse().ToArray(), 0, Request, 6, 4); @@ -195,7 +195,7 @@ namespace UnifiedFlashingPlatform public void TelemetryStart() { byte[] Request = new byte[4]; - string Header = TelemetryStartSignature; // NOKS + const string Header = TelemetryStartSignature; // NOKS Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); ExecuteRawVoidMethod(Request); } @@ -203,7 +203,7 @@ namespace UnifiedFlashingPlatform public void TelemetryEnd() { byte[] Request = new byte[4]; - string Header = TelemetryEndSignature; // NOKN + const string Header = TelemetryEndSignature; // NOKN Buffer.BlockCopy(Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); ExecuteRawVoidMethod(Request); } @@ -214,7 +214,7 @@ namespace UnifiedFlashingPlatform PhoneInfo Info = ReadPhoneInfo(); byte[] Request = new byte[0x13]; - string Header = GetLogsSignature; + const string Header = GetLogsSignature; ulong BufferSize = 0xE000 - 0xC; ulong Length = ReadLogSize(DeviceLogType.Flashing)!.Value;