Adopt new C# syntax for array init

This commit is contained in:
Gustave Monce
2023-11-26 14:03:46 +01:00
parent 742c89b9bf
commit 96c42a29b5
27 changed files with 129 additions and 133 deletions
@@ -1518,10 +1518,10 @@ namespace SevenZip.Compression.LZMA
} }
private static readonly string[] kMatchFinderIDs = private static readonly string[] kMatchFinderIDs =
{ [
"BT2", "BT2",
"BT4", "BT4",
}; ];
private static int FindMatchFinder(string s) private static int FindMatchFinder(string s)
{ {
+1 -1
View File
@@ -114,7 +114,7 @@ namespace WPinternals
return; return;
} }
switch (args[1].ToLower().TrimStart(new char[] { '-', '/' })) switch (args[1].ToLower().TrimStart(['-', '/']))
{ {
#if DEBUG #if DEBUG
case "test": case "test":
@@ -31,15 +31,15 @@ namespace DiscUtils.Fat
private const byte SpaceByte = 0x20; private const byte SpaceByte = 0x20;
public static readonly FileName SelfEntryName = public static readonly FileName SelfEntryName =
new(new byte[] { 0x2E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, 0); new([0x2E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20], 0);
public static readonly FileName ParentEntryName = public static readonly FileName ParentEntryName =
new(new byte[] { 0x2E, 0x2E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, 0); new([0x2E, 0x2E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20], 0);
public static readonly FileName Null = public static readonly FileName Null =
new(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0); new([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], 0);
private static readonly byte[] InvalidBytes = { 0x22, 0x2A, 0x2B, 0x2C, 0x2E, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x5B, 0x5C, 0x5D, 0x7C }; private static readonly byte[] InvalidBytes = [0x22, 0x2A, 0x2B, 0x2C, 0x2E, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x5B, 0x5C, 0x5D, 0x7C];
private readonly byte[] _raw; private readonly byte[] _raw;
@@ -33,7 +33,7 @@ namespace DiscUtils.Fat
{ {
if (FatFileSystem.Detect(stream)) if (FatFileSystem.Detect(stream))
{ {
return new FileSystemInfo[] { new VfsFileSystemInfo("FAT", "Microsoft FAT", Open) }; return [new VfsFileSystemInfo("FAT", "Microsoft FAT", Open)];
} }
return System.Array.Empty<FileSystemInfo>(); return System.Array.Empty<FileSystemInfo>();
@@ -80,22 +80,22 @@ namespace DiscUtils.Fat
{ {
// see http://home.teleport.com/~brainy/lfn.htm // see http://home.teleport.com/~brainy/lfn.htm
// NOTE: we assume ordinals are ok here. // NOTE: we assume ordinals are ok here.
char[] chars = new char[13]; char[] chars =
chars[0] = (char)((256 * buffer[2]) + buffer[1]); [
chars[1] = (char)((256 * buffer[4]) + buffer[3]); (char)((256 * buffer[2]) + buffer[1]),
chars[2] = (char)((256 * buffer[6]) + buffer[5]); (char)((256 * buffer[4]) + buffer[3]),
chars[3] = (char)((256 * buffer[8]) + buffer[7]); (char)((256 * buffer[6]) + buffer[5]),
chars[4] = (char)((256 * buffer[10]) + buffer[9]); (char)((256 * buffer[8]) + buffer[7]),
(char)((256 * buffer[10]) + buffer[9]),
chars[5] = (char)((256 * buffer[15]) + buffer[14]); (char)((256 * buffer[15]) + buffer[14]),
chars[6] = (char)((256 * buffer[17]) + buffer[16]); (char)((256 * buffer[17]) + buffer[16]),
chars[7] = (char)((256 * buffer[19]) + buffer[18]); (char)((256 * buffer[19]) + buffer[18]),
chars[8] = (char)((256 * buffer[21]) + buffer[20]); (char)((256 * buffer[21]) + buffer[20]),
chars[9] = (char)((256 * buffer[23]) + buffer[22]); (char)((256 * buffer[23]) + buffer[22]),
chars[10] = (char)((256 * buffer[25]) + buffer[24]); (char)((256 * buffer[25]) + buffer[24]),
(char)((256 * buffer[29]) + buffer[28]),
chars[11] = (char)((256 * buffer[29]) + buffer[28]); (char)((256 * buffer[31]) + buffer[30]),
chars[12] = (char)((256 * buffer[31]) + buffer[30]); ];
string chunk = new(chars); string chunk = new(chars);
int zero = chunk.IndexOf('\0'); int zero = chunk.IndexOf('\0');
return zero >= 0 ? chunk.Substring(0, zero) : chunk; return zero >= 0 ? chunk.Substring(0, zero) : chunk;
+3 -3
View File
@@ -924,7 +924,7 @@ namespace WPinternals
{ {
if (proxy?.CheckAccess() == false) if (proxy?.CheckAccess() == false)
{ {
proxy.BeginInvoke(new Action<object, EventHandler>(CallHandler), new object[] { sender, eventHandler }); proxy.BeginInvoke(new Action<object, EventHandler>(CallHandler), [sender, eventHandler]);
} }
else else
{ {
@@ -1890,7 +1890,7 @@ namespace WPinternals
internal static Version GetFileVersion(byte[] PEfile) internal static Version GetFileVersion(byte[] PEfile)
{ {
byte[] version = GetResource(PEfile, new int[] { (int)ResourceType.RT_VERSION, 1, 1033 }); byte[] version = GetResource(PEfile, [(int)ResourceType.RT_VERSION, 1, 1033]);
// RT_VERSION format: // RT_VERSION format:
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms647001(v=vs.85).aspx // https://msdn.microsoft.com/en-us/library/windows/desktop/ms647001(v=vs.85).aspx
@@ -1906,7 +1906,7 @@ namespace WPinternals
internal static Version GetProductVersion(byte[] PEfile) internal static Version GetProductVersion(byte[] PEfile)
{ {
byte[] version = GetResource(PEfile, new int[] { (int)ResourceType.RT_VERSION, 1, 1033 }); byte[] version = GetResource(PEfile, [(int)ResourceType.RT_VERSION, 1, 1033]);
// RT_VERSION format: // RT_VERSION format:
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms647001(v=vs.85).aspx // https://msdn.microsoft.com/en-us/library/windows/desktop/ms647001(v=vs.85).aspx
+2 -2
View File
@@ -332,7 +332,7 @@ namespace WPinternals
return (UInt16)(0x10000 - Checksum); return (UInt16)(0x10000 - Checksum);
} }
private static readonly UInt32[] CRC32Table = new UInt32[] { private static readonly UInt32[] CRC32Table = [
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,
0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2,
@@ -376,7 +376,7 @@ namespace WPinternals
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693,
0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
}; ];
internal static UInt32 CRC32(byte[] Input, UInt32 Offset, UInt32 Length) internal static UInt32 CRC32(byte[] Input, UInt32 Offset, UInt32 Length)
{ {
+3 -3
View File
@@ -84,7 +84,7 @@ namespace WPinternals
// Read Store Header // Read Store Header
byte[] ShortStoreHeader = new byte[248]; byte[] ShortStoreHeader = new byte[248];
FFUFile.Read(ShortStoreHeader, 0, 248); FFUFile.Read(ShortStoreHeader, 0, 248);
PlatformID = ByteOperations.ReadAsciiString(ShortStoreHeader, 0x0C, 192).TrimEnd(new char[] { (char)0, ' ' }); PlatformID = ByteOperations.ReadAsciiString(ShortStoreHeader, 0x0C, 192).TrimEnd([(char)0, ' ']);
int WriteDescriptorCount = ByteOperations.ReadInt32(ShortStoreHeader, 208); int WriteDescriptorCount = ByteOperations.ReadInt32(ShortStoreHeader, 208);
UInt32 WriteDescriptorLength = ByteOperations.ReadUInt32(ShortStoreHeader, 212); UInt32 WriteDescriptorLength = ByteOperations.ReadUInt32(ShortStoreHeader, 212);
UInt32 ValidateDescriptorLength = ByteOperations.ReadUInt32(ShortStoreHeader, 220); UInt32 ValidateDescriptorLength = ByteOperations.ReadUInt32(ShortStoreHeader, 220);
@@ -455,8 +455,8 @@ namespace WPinternals
if (Offset != null) if (Offset != null)
{ {
uint Start = (uint)Offset + 10; uint Start = (uint)Offset + 10;
uint Length = (uint)ByteOperations.FindPattern(Data, Start, 0x100, new byte[] { 0x00 }, null, null) - Start; uint Length = (uint)ByteOperations.FindPattern(Data, Start, 0x100, [0x00], null, null) - Start;
uint? Offset0D = ByteOperations.FindPattern(Data, Start, 0x100, new byte[] { 0x0D }, null, null); uint? Offset0D = ByteOperations.FindPattern(Data, Start, 0x100, [0x0D], null, null);
if ((Offset0D != null) && (Offset0D < (Start + Length))) if ((Offset0D != null) && (Offset0D < (Start + Length)))
{ {
Length = (uint)Offset0D - Start; Length = (uint)Offset0D - Start;
+1 -1
View File
@@ -74,7 +74,7 @@ namespace WPinternals
while (PartitionOffset < (TableOffset + TableSize)) while (PartitionOffset < (TableOffset + TableSize))
{ {
string Name = ByteOperations.ReadUnicodeString(GPTBuffer, PartitionOffset + 0x38, 0x48).TrimEnd(new char[] { (char)0, ' ' }); string Name = ByteOperations.ReadUnicodeString(GPTBuffer, PartitionOffset + 0x38, 0x48).TrimEnd([(char)0, ' ']);
if (Name.Length == 0) if (Name.Length == 0)
{ {
break; break;
+3 -3
View File
@@ -110,9 +110,9 @@ namespace WPinternals
if (DictionarySize != 0) if (DictionarySize != 0)
{ {
Encoder.SetCoderProperties( Encoder.SetCoderProperties(
new CoderPropID[8] {CoderPropID.DictionarySize, CoderPropID.PosStateBits, CoderPropID.LitContextBits, [CoderPropID.DictionarySize, CoderPropID.PosStateBits, CoderPropID.LitContextBits,
CoderPropID.LitPosBits, CoderPropID.Algorithm, CoderPropID.NumFastBytes, CoderPropID.MatchFinder, CoderPropID.EndMarker}, CoderPropID.LitPosBits, CoderPropID.Algorithm, CoderPropID.NumFastBytes, CoderPropID.MatchFinder, CoderPropID.EndMarker],
new object[8] { DictionarySize, PosStateBits, LitContextBits, LitPosBits, Algorithm, NumFastBytes, MatchFinder, EndMarker }); [DictionarySize, PosStateBits, LitContextBits, LitPosBits, Algorithm, NumFastBytes, MatchFinder, EndMarker]);
} }
Encoder.WriteCoderProperties(stream); Encoder.WriteCoderProperties(stream);
+2 -2
View File
@@ -111,10 +111,10 @@ namespace WPinternals
SerialDevice.EncodeCommands = false; SerialDevice.EncodeCommands = false;
// This will succeed on new models // This will succeed on new models
SerialDevice.SendData(new byte[] { 0x7, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0 }); SerialDevice.SendData([0x7, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0]);
// This will succeed on old models // This will succeed on old models
SerialDevice.SendData(new byte[] { 0x7E, 0xA, 0x0, 0x0, 0xB6, 0xB5, 0x7E }); SerialDevice.SendData([0x7E, 0xA, 0x0, 0x0, 0xB6, 0xB5, 0x7E]);
SerialDevice.Close(); SerialDevice.Close();
SerialDevice.Dispose(); SerialDevice.Dispose();
+4 -4
View File
@@ -80,7 +80,7 @@ namespace WPinternals
return null; return null;
} }
return System.Text.Encoding.ASCII.GetString(Bytes).Trim(new char[] { '\0' }); return System.Text.Encoding.ASCII.GetString(Bytes).Trim(['\0']);
} }
[Flags] [Flags]
@@ -193,7 +193,7 @@ namespace WPinternals
public TerminalResponse GetTerminalResponse() public TerminalResponse GetTerminalResponse()
{ {
byte[] AsskMask = new byte[0x10] { 1, 0, 16, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64 }; byte[] AsskMask = [1, 0, 16, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64];
byte[] Request = new byte[0xAC]; byte[] Request = new byte[0xAC];
const string Header = "NOKXFT"; const string Header = "NOKXFT";
Buffer.BlockCopy(System.Text.Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length); Buffer.BlockCopy(System.Text.Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length);
@@ -972,7 +972,7 @@ namespace WPinternals
Result.EmmcSizeInSectors = BigEndian.ToUInt32(Response, SubblockPayloadOffset); Result.EmmcSizeInSectors = BigEndian.ToUInt32(Response, SubblockPayloadOffset);
break; break;
case 0x05: case 0x05:
Result.PlatformID = ByteOperations.ReadAsciiString(Response, (uint)SubblockPayloadOffset, SubblockLength).Trim(new char[] { ' ', '\0' }); Result.PlatformID = ByteOperations.ReadAsciiString(Response, (uint)SubblockPayloadOffset, SubblockLength).Trim([' ', '\0']);
break; break;
case 0x0D: case 0x0D:
Result.AsyncSupport = Response[SubblockPayloadOffset + 1] == 1; Result.AsyncSupport = Response[SubblockPayloadOffset + 1] == 1;
@@ -1215,7 +1215,7 @@ namespace WPinternals
ByteOperations.WriteAsciiString(Request, 0, "NOKXPH" + VariableName + "\0"); // BTR or CTR, CTR is public ProductCode ByteOperations.WriteAsciiString(Request, 0, "NOKXPH" + VariableName + "\0"); // BTR or CTR, CTR is public ProductCode
byte[] Response = ExecuteRawMethod(Request); byte[] Response = ExecuteRawMethod(Request);
UInt16 Length = BigEndian.ToUInt16(Response, 6); UInt16 Length = BigEndian.ToUInt16(Response, 6);
return ByteOperations.ReadAsciiString(Response, 8, Length).Trim(new char[] { ' ', '\0' }); return ByteOperations.ReadAsciiString(Response, 8, Length).Trim([' ', '\0']);
} }
internal string ReadProductCode() internal string ReadProductCode()
+4 -4
View File
@@ -94,7 +94,7 @@ namespace WPinternals
} }
set set
{ {
_TargetPath = value.TrimEnd(new char[] { '\\' }); _TargetPath = value.TrimEnd(['\\']);
} }
} }
@@ -365,7 +365,7 @@ namespace WPinternals
} }
set set
{ {
_RelativePath = value.TrimStart(new char[] { '\\' }).TrimEnd(new char[] { '\\' }); _RelativePath = value.TrimStart(['\\']).TrimEnd(['\\']);
} }
} }
@@ -377,7 +377,7 @@ namespace WPinternals
} }
set set
{ {
_TargetPath = value.TrimEnd(new char[] { '\\' }); _TargetPath = value.TrimEnd(['\\']);
} }
} }
} }
@@ -515,7 +515,7 @@ namespace WPinternals
} }
set set
{ {
_Path = value.TrimStart(new char[] { '\\' }); _Path = value.TrimStart(['\\']);
} }
} }
+7 -7
View File
@@ -37,7 +37,7 @@ namespace WPinternals
{ {
try try
{ {
Serial.SendCommand(new byte[] { 0x06 }, new byte[] { 0x02 }); Serial.SendCommand([0x06], [0x02]);
return true; return true;
} }
catch catch
@@ -61,7 +61,7 @@ namespace WPinternals
CurrentLength = Remaining >= 0x100 ? 0x100 : (UInt32)Remaining; CurrentLength = Remaining >= 0x100 ? 0x100 : (UInt32)Remaining;
CurrentLength = (UInt32)Data.Read(Buffer, 7, (int)CurrentLength); CurrentLength = (UInt32)Data.Read(Buffer, 7, (int)CurrentLength);
Serial.SendCommand(Buffer, new byte[] { 0x02 }); Serial.SendCommand(Buffer, [0x02]);
CurrentAddress += CurrentLength; CurrentAddress += CurrentLength;
Remaining -= CurrentLength; Remaining -= CurrentLength;
@@ -100,7 +100,7 @@ namespace WPinternals
System.Buffer.BlockCopy(BitConverter.GetBytes((UInt16)CurrentLength).Reverse().ToArray(), 0, CurrentBytes, 5, 2); // Length is in Big Endian System.Buffer.BlockCopy(BitConverter.GetBytes((UInt16)CurrentLength).Reverse().ToArray(), 0, CurrentBytes, 5, 2); // Length is in Big Endian
System.Buffer.BlockCopy(Data, (int)CurrentOffset, CurrentBytes, 7, (int)CurrentLength); System.Buffer.BlockCopy(Data, (int)CurrentOffset, CurrentBytes, 7, (int)CurrentLength);
Serial.SendCommand(CurrentBytes, new byte[] { 0x02 }); Serial.SendCommand(CurrentBytes, [0x02]);
CurrentAddress += CurrentLength; CurrentAddress += CurrentLength;
CurrentOffset += CurrentLength; CurrentOffset += CurrentLength;
@@ -113,25 +113,25 @@ namespace WPinternals
byte[] Buffer = new byte[5]; byte[] Buffer = new byte[5];
Buffer[0] = 0x05; Buffer[0] = 0x05;
System.Buffer.BlockCopy(BitConverter.GetBytes(Address).Reverse().ToArray(), 0, Buffer, 1, 4); // Address is in Big Endian System.Buffer.BlockCopy(BitConverter.GetBytes(Address).Reverse().ToArray(), 0, Buffer, 1, 4); // Address is in Big Endian
Serial.SendCommand(Buffer, new byte[] { 0x02 }); Serial.SendCommand(Buffer, [0x02]);
} }
// Reset interface. Interface becomes unresponsive. // Reset interface. Interface becomes unresponsive.
public void Reset() public void Reset()
{ {
Serial.SendCommand(new byte[] { 0x0A }, new byte[] { 0x02 }); Serial.SendCommand([0x0A], [0x02]);
} }
// This also resets interface. This does not actually reboot the phone. The interface becomes unresponsive. // This also resets interface. This does not actually reboot the phone. The interface becomes unresponsive.
public void Shutdown() public void Shutdown()
{ {
Serial.SendCommand(new byte[] { 0x0E }, new byte[] { 0x02 }); Serial.SendCommand([0x0E], [0x02]);
} }
// This command only works on 9008 interface. // This command only works on 9008 interface.
public byte[] GetRKH() public byte[] GetRKH()
{ {
byte[] Response = Serial.SendCommand(new byte[] { 0x18 }, new byte[] { 0x18, 0x01, 0x00 }); byte[] Response = Serial.SendCommand([0x18], [0x18, 0x01, 0x00]);
byte[] Result = new byte[0x20]; byte[] Result = new byte[0x20];
Buffer.BlockCopy(Response, 3, Result, 0, 0x20); Buffer.BlockCopy(Response, 3, Result, 0, 0x20);
return Result; return Result;
+10 -14
View File
@@ -45,41 +45,37 @@ namespace WPinternals
public void Hello() public void Hello()
{ {
byte[] Command = new byte[] byte[] Command =
{ [
0x01, // Hello command 0x01, // Hello command
0x51, 0x43, 0x4F, 0x4D, 0x20, 0x66, 0x61, 0x73, 0x74, 0x20, 0x64, 0x6F, 0x77, 0x6E, 0x6C, 0x6F, // "QCOM fast download protocol host" 0x51, 0x43, 0x4F, 0x4D, 0x20, 0x66, 0x61, 0x73, 0x74, 0x20, 0x64, 0x6F, 0x77, 0x6E, 0x6C, 0x6F, // "QCOM fast download protocol host"
0x61, 0x64, 0x20, 0x70, 0x72, 0x6F, 0x74, 0x6F, 0x63, 0x6F, 0x6C, 0x20, 0x68, 0x6F, 0x73, 0x74, 0x61, 0x64, 0x20, 0x70, 0x72, 0x6F, 0x74, 0x6F, 0x63, 0x6F, 0x6C, 0x20, 0x68, 0x6F, 0x73, 0x74,
0x02, 0x02,
0x02, // Protocol version - Must be at least 0x02 0x02, // Protocol version - Must be at least 0x02
0x01 0x01
}; ];
Serial.SendCommand(Command, new byte[] { 0x02 }); Serial.SendCommand(Command, [0x02]);
} }
public void SetSecurityMode(byte Mode) public void SetSecurityMode(byte Mode)
{ {
byte[] Command = new byte[2]; byte[] Command = [0x17, Mode];
Command[0] = 0x17;
Command[1] = Mode;
Serial.SendCommand(Command, new byte[] { 0x18 }); Serial.SendCommand(Command, [0x18]);
} }
// Use PartitionID 0x21 // Use PartitionID 0x21
public void OpenPartition(byte PartitionID) public void OpenPartition(byte PartitionID)
{ {
byte[] Command = new byte[2]; byte[] Command = [0x1B, PartitionID];
Command[0] = 0x1B;
Command[1] = PartitionID;
Serial.SendCommand(Command, new byte[] { 0x1C }); Serial.SendCommand(Command, [0x1C]);
} }
public void ClosePartition() public void ClosePartition()
{ {
Serial.SendCommand(new byte[] { 0x15 }, new byte[] { 0x16 }); Serial.SendCommand([0x15], [0x16]);
} }
public void Flash(UInt32 StartInBytes, Stream Data, UInt32 LengthInBytes = UInt32.MaxValue) public void Flash(UInt32 StartInBytes, Stream Data, UInt32 LengthInBytes = UInt32.MaxValue)
@@ -222,7 +218,7 @@ namespace WPinternals
public void Reboot() public void Reboot()
{ {
Serial.SendCommand(new byte[] { 0x0B }, new byte[] { 0x0C }); Serial.SendCommand([0x0B], [0x0C]);
} }
} }
} }
+3 -3
View File
@@ -57,10 +57,10 @@ namespace WPinternals
this.Binary = Binary; this.Binary = Binary;
byte[] LongHeaderPattern = new byte[] { 0xD1, 0xDC, 0x4B, 0x84, 0x34, 0x10, 0xD7, 0x73, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; byte[] LongHeaderPattern = [0xD1, 0xDC, 0x4B, 0x84, 0x34, 0x10, 0xD7, 0x73, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF];
byte[] LongHeaderMask = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; byte[] LongHeaderMask = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
if (ByteOperations.FindPattern(Binary, Offset, 4, new byte[] { 0x7F, 0x45, 0x4C, 0x46 }, new byte[] { 0x00, 0x00, 0x00, 0x00 }, null) == 0) if (ByteOperations.FindPattern(Binary, Offset, 4, [0x7F, 0x45, 0x4C, 0x46], [0x00, 0x00, 0x00, 0x00], null) == 0)
{ {
// This is an ELF image // This is an ELF image
// First program header is a reference to the elf-header // First program header is a reference to the elf-header
+15 -15
View File
@@ -63,7 +63,7 @@ namespace WPinternals
try try
{ {
Step = 1; Step = 1;
byte[] Hello = Serial.GetResponse(new byte[] { 0x01, 0x00, 0x00, 0x00 }); byte[] Hello = Serial.GetResponse([0x01, 0x00, 0x00, 0x00]);
// Incoming Hello packet: // Incoming Hello packet:
// 00000001 = Hello command id // 00000001 = Hello command id
@@ -87,11 +87,11 @@ namespace WPinternals
// 00000000 = Mode // 00000000 = Mode
// rest is reserved space // rest is reserved space
Step = 2; Step = 2;
byte[] HelloResponse = new byte[] { byte[] HelloResponse = [
0x02, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}; ];
Serial.SendData(HelloResponse); Serial.SendData(HelloResponse);
Step = 3; Step = 3;
@@ -151,7 +151,7 @@ namespace WPinternals
try try
{ {
byte[] Hello = Serial.GetResponse(new byte[] { 0x01, 0x00, 0x00, 0x00 }); byte[] Hello = Serial.GetResponse([0x01, 0x00, 0x00, 0x00]);
// Incoming Hello packet: // Incoming Hello packet:
// 00000001 = Hello command id // 00000001 = Hello command id
@@ -166,13 +166,13 @@ namespace WPinternals
LogFile.Log("MaxLength: 0x" + ByteOperations.ReadUInt32(Hello, 0x10).ToString("X8"), LogType.FileOnly); LogFile.Log("MaxLength: 0x" + ByteOperations.ReadUInt32(Hello, 0x10).ToString("X8"), LogType.FileOnly);
LogFile.Log("Mode: 0x" + ByteOperations.ReadUInt32(Hello, 0x14).ToString("X8"), LogType.FileOnly); LogFile.Log("Mode: 0x" + ByteOperations.ReadUInt32(Hello, 0x14).ToString("X8"), LogType.FileOnly);
byte[] HelloResponse = new byte[] { byte[] HelloResponse = [
0x02, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}; ];
byte[] Ready = Serial.SendCommand(HelloResponse, new byte[] { 0x03, 0x00, 0x00, 0x00 }); byte[] Ready = Serial.SendCommand(HelloResponse, [0x03, 0x00, 0x00, 0x00]);
} }
catch catch
{ {
@@ -184,7 +184,7 @@ namespace WPinternals
public void ResetSahara() public void ResetSahara()
{ {
Serial.SendCommand(new byte[] { 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00 }, new byte[] { 0x08, 0x00, 0x00, 0x00 }); Serial.SendCommand([0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00], [0x08, 0x00, 0x00, 0x00]);
} }
public bool ConnectToProgrammer(byte[] PacketFromPcToProgrammer) public bool ConnectToProgrammer(byte[] PacketFromPcToProgrammer)
@@ -319,19 +319,19 @@ namespace WPinternals
public void SwitchMode(SaharaMode Mode) public void SwitchMode(SaharaMode Mode)
{ {
byte[] SwitchModeCommand = new byte[] { 0x0C, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; byte[] SwitchModeCommand = [0x0C, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
ByteOperations.WriteUInt32(SwitchModeCommand, 8, (UInt32)Mode); ByteOperations.WriteUInt32(SwitchModeCommand, 8, (UInt32)Mode);
byte[] ResponsePattern = null; byte[] ResponsePattern = null;
switch (Mode) switch (Mode)
{ {
case SaharaMode.ImageTransferPending: case SaharaMode.ImageTransferPending:
ResponsePattern = new byte[] { 0x04, 0x00, 0x00, 0x00 }; ResponsePattern = [0x04, 0x00, 0x00, 0x00];
break; break;
case SaharaMode.MemoryDebug: case SaharaMode.MemoryDebug:
ResponsePattern = new byte[] { 0x09, 0x00, 0x00, 0x00 }; ResponsePattern = [0x09, 0x00, 0x00, 0x00];
break; break;
case SaharaMode.Command: case SaharaMode.Command:
ResponsePattern = new byte[] { 0x0B, 0x00, 0x00, 0x00 }; ResponsePattern = [0x0B, 0x00, 0x00, 0x00];
break; break;
} }
Serial.SendCommand(SwitchModeCommand, ResponsePattern); Serial.SendCommand(SwitchModeCommand, ResponsePattern);
@@ -340,7 +340,7 @@ namespace WPinternals
public void StartProgrammer() public void StartProgrammer()
{ {
LogFile.Log("Starting programmer", LogType.FileAndConsole); LogFile.Log("Starting programmer", LogType.FileAndConsole);
byte[] DoneCommand = new byte[] { 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00 }; byte[] DoneCommand = [0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00];
bool Started = false; bool Started = false;
int count = 0; int count = 0;
do do
@@ -348,7 +348,7 @@ namespace WPinternals
count++; count++;
try try
{ {
byte[] DoneResponse = Serial.SendCommand(DoneCommand, new byte[] { 0x06, 0x00, 0x00, 0x00 }); byte[] DoneResponse = Serial.SendCommand(DoneCommand, [0x06, 0x00, 0x00, 0x00]);
Started = true; Started = true;
} }
catch (BadConnectionException) catch (BadConnectionException)
@@ -369,7 +369,7 @@ namespace WPinternals
// First, let's read the Emergency Download payload header and verify its validity // First, let's read the Emergency Download payload header and verify its validity
FileStream PayloadStream = File.OpenRead(PayloadPath); FileStream PayloadStream = File.OpenRead(PayloadPath);
byte[] ValidReferencePayloadHeader = new byte[] { 0x45, 0x6D, 0x65, 0x72, 0x67, 0x65, 0x6E, 0x63, 0x79, 0x20, 0x50, 0x61, 0x79, 0x6C, 0x6F, 0x61, 0x64 }; byte[] ValidReferencePayloadHeader = [0x45, 0x6D, 0x65, 0x72, 0x67, 0x65, 0x6E, 0x63, 0x79, 0x20, 0x50, 0x61, 0x79, 0x6C, 0x6F, 0x61, 0x64];
byte[] PayloadHeader = new byte[17]; byte[] PayloadHeader = new byte[17];
PayloadStream.Read(PayloadHeader, 0, 17); PayloadStream.Read(PayloadHeader, 0, 17);
+3 -3
View File
@@ -38,7 +38,7 @@ namespace WPinternals
{ {
CRC16 = new CRC16(0x1189, 0xFFFF, 0xFFFF); CRC16 = new CRC16(0x1189, 0xFFFF, 0xFFFF);
string[] DevicePathElements = DevicePath.Split(new char[] { '#' }); string[] DevicePathElements = DevicePath.Split(['#']);
if (string.Equals(DevicePathElements[3], "{86E0D1E0-8089-11D0-9CE4-08003E301F73}", StringComparison.CurrentCultureIgnoreCase)) if (string.Equals(DevicePathElements[3], "{86E0D1E0-8089-11D0-9CE4-08003E301F73}", StringComparison.CurrentCultureIgnoreCase))
{ {
string PortName = (string)Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\" + DevicePathElements[1] + @"\" + DevicePathElements[2] + @"\Device Parameters", "PortName", null); string PortName = (string)Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\" + DevicePathElements[1] + @"\" + DevicePathElements[2] + @"\Device Parameters", "PortName", null);
@@ -323,7 +323,7 @@ namespace WPinternals
public class CRC16 public class CRC16
{ {
private readonly UInt16[] ChecksumTable = private readonly UInt16[] ChecksumTable =
new UInt16[] { [
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
@@ -356,7 +356,7 @@ namespace WPinternals
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
}; ];
private readonly UInt16 Seed, FinalXor; private readonly UInt16 Seed, FinalXor;
+14 -14
View File
@@ -29,11 +29,11 @@ namespace WPinternals
internal byte[] GenerateExtraSector(byte[] PartitionHeader) internal byte[] GenerateExtraSector(byte[] PartitionHeader)
{ {
UInt32? Offset = ByteOperations.FindPattern(Binary, UInt32? Offset = ByteOperations.FindPattern(Binary,
new byte[] { [
0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}, null, null); ], null, null);
if (Offset == null) if (Offset == null)
{ {
throw new BadImageFormatException(); throw new BadImageFormatException();
@@ -43,12 +43,12 @@ namespace WPinternals
byte[] FoundPattern = new byte[0x10]; byte[] FoundPattern = new byte[0x10];
Offset = ByteOperations.FindPattern(Binary, Offset = ByteOperations.FindPattern(Binary,
new byte[] { [
0x04, 0x00, 0x9F, 0xE5, 0x28, 0x00, 0xD0, 0xE5, 0x1E, 0xFF, 0x2F, 0xE1, 0xFF, 0xFF, 0xFF, 0xFF 0x04, 0x00, 0x9F, 0xE5, 0x28, 0x00, 0xD0, 0xE5, 0x1E, 0xFF, 0x2F, 0xE1, 0xFF, 0xFF, 0xFF, 0xFF
}, ],
new byte[] { [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF
}, ],
FoundPattern); FoundPattern);
if (Offset == null) if (Offset == null)
{ {
@@ -59,14 +59,14 @@ namespace WPinternals
UInt32 GlobalIsSecurityEnabledAddress = SharedMemoryAddress + 0x28; UInt32 GlobalIsSecurityEnabledAddress = SharedMemoryAddress + 0x28;
Offset = ByteOperations.FindPattern(Binary, Offset = ByteOperations.FindPattern(Binary,
new byte[] { [
0x01, 0xFF, 0xA0, 0xE3, 0xFF, 0xFF, 0xA0, 0xE1, 0x1C, 0xD0, 0x8D, 0xE2, 0xF0, 0x4F, 0xBD, 0xE8, 0x01, 0xFF, 0xA0, 0xE3, 0xFF, 0xFF, 0xA0, 0xE1, 0x1C, 0xD0, 0x8D, 0xE2, 0xF0, 0x4F, 0xBD, 0xE8,
0x1E, 0xFF, 0x2F, 0xE1 0x1E, 0xFF, 0x2F, 0xE1
}, ],
new byte[] { [
0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x00
}, ],
null); null);
if (Offset == null) if (Offset == null)
{ {
@@ -78,7 +78,7 @@ namespace WPinternals
byte[] Sector = new byte[0x200]; byte[] Sector = new byte[0x200];
Array.Clear(Sector, 0, 0x200); Array.Clear(Sector, 0, 0x200);
byte[] Content = new byte[] { byte[] Content = [
0x16, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x28, 0xBD, 0x02, 0x00, 0x16, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x28, 0xBD, 0x02, 0x00,
0xD8, 0x01, 0x00, 0x00, 0xD8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD8, 0x01, 0x00, 0x00, 0xD8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0xE3, 0x3C, 0x10, 0x9F, 0xE5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0xE3, 0x3C, 0x10, 0x9F, 0xE5,
@@ -88,11 +88,11 @@ namespace WPinternals
0x04, 0x10, 0x81, 0xE2, 0x03, 0x00, 0x50, 0xE1, 0xF9, 0xFF, 0xFF, 0xBA, 0x14, 0xF0, 0x9F, 0xE5, 0x04, 0x10, 0x81, 0xE2, 0x03, 0x00, 0x50, 0xE1, 0xF9, 0xFF, 0xFF, 0xBA, 0x14, 0xF0, 0x9F, 0xE5,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0x90, 0xBF, 0x02, 0x00, 0xD0, 0xBF, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0x90, 0xBF, 0x02, 0x00, 0xD0, 0xBF, 0x02, 0x00,
0xA0, 0xBD, 0x02, 0x00, 0xA0, 0xBE, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 0xA0, 0xBD, 0x02, 0x00, 0xA0, 0xBE, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00
}; ];
byte[] PartitionTypeGuid = new byte[] { byte[] PartitionTypeGuid = [
0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74
}; ];
Buffer.BlockCopy(Content, 0, Sector, 0, Content.Length); Buffer.BlockCopy(Content, 0, Sector, 0, Content.Length);
+4 -4
View File
@@ -35,12 +35,12 @@ namespace WPinternals
internal byte[] Patch() internal byte[] Patch()
{ {
UInt32? PatchOffset = ByteOperations.FindPattern(Binary, UInt32? PatchOffset = ByteOperations.FindPattern(Binary,
new byte[] { [
0xFF, 0xFF, 0xFF, 0xE3, 0x01, 0x0E, 0x42, 0xE3, 0x28, 0x00, 0xD0, 0xE5, 0x1E, 0xFF, 0x2F, 0xE1 0xFF, 0xFF, 0xFF, 0xE3, 0x01, 0x0E, 0x42, 0xE3, 0x28, 0x00, 0xD0, 0xE5, 0x1E, 0xFF, 0x2F, 0xE1
}, ],
new byte[] { [
0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}, ],
null); null);
if (PatchOffset == null) if (PatchOffset == null)
+3 -3
View File
@@ -50,8 +50,8 @@ namespace WPinternals
// If not succeeded, then try to parse it as raw image // If not succeeded, then try to parse it as raw image
if (Binary == null) if (Binary == null)
{ {
byte[] SBL3Pattern = new byte[] { 0x18, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x8F, 0xFF, 0xFF, 0xFF, 0xFF }; byte[] SBL3Pattern = [0x18, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x8F, 0xFF, 0xFF, 0xFF, 0xFF];
byte[] SBL3Mask = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF }; byte[] SBL3Mask = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF];
UInt32? Offset = ByteOperations.FindPatternInFile(FileName, SBL3Pattern, SBL3Mask, out byte[] SBL3Header); UInt32? Offset = ByteOperations.FindPatternInFile(FileName, SBL3Pattern, SBL3Mask, out byte[] SBL3Header);
@@ -72,7 +72,7 @@ namespace WPinternals
internal byte[] Patch() internal byte[] Patch()
{ {
UInt32? PatchOffset = ByteOperations.FindPattern(Binary, UInt32? PatchOffset = ByteOperations.FindPattern(Binary,
new byte[] { 0x04, 0x00, 0x9F, 0xE5, 0x28, 0x00, 0xD0, 0xE5, 0x1E, 0xFF, 0x2F, 0xE1 }, [0x04, 0x00, 0x9F, 0xE5, 0x28, 0x00, 0xD0, 0xE5, 0x1E, 0xFF, 0x2F, 0xE1],
null, null); null, null);
if (PatchOffset == null) if (PatchOffset == null)
+7 -7
View File
@@ -256,7 +256,7 @@ namespace WPinternals
// but the sections that are used in Windows Phone EFI's all have a header of 4 bytes. // but the sections that are used in Windows Phone EFI's all have a header of 4 bytes.
if (SectionType == 0x15) if (SectionType == 0x15)
{ {
CurrentEFI.Name = ByteOperations.ReadUnicodeString(DecompressedImage, DecompressedSectionHeaderOffset + 0x04, SectionSize - 0x04).TrimEnd(new char[] { (char)0, ' ' }); CurrentEFI.Name = ByteOperations.ReadUnicodeString(DecompressedImage, DecompressedSectionHeaderOffset + 0x04, SectionSize - 0x04).TrimEnd([(char)0, ' ']);
} }
else if ((SectionType == 0x10) || (SectionType == 0x19)) else if ((SectionType == 0x10) || (SectionType == 0x19))
{ {
@@ -599,8 +599,8 @@ namespace WPinternals
ClearEfiChecksum(SecurityDxe); ClearEfiChecksum(SecurityDxe);
UInt32? PatchOffset = ByteOperations.FindPattern(SecurityDxe, UInt32? PatchOffset = ByteOperations.FindPattern(SecurityDxe,
new byte[] { 0xF0, 0x41, 0x2D, 0xE9, 0xFF, 0xFF, 0xB0, 0xE1, 0x28, 0xD0, 0x4D, 0xE2, 0xFF, 0xFF, 0xA0, 0xE1, 0x00, 0x00, 0xFF, 0x13, 0x20, 0xFF, 0xA0, 0xE3 }, [0xF0, 0x41, 0x2D, 0xE9, 0xFF, 0xFF, 0xB0, 0xE1, 0x28, 0xD0, 0x4D, 0xE2, 0xFF, 0xFF, 0xA0, 0xE1, 0x00, 0x00, 0xFF, 0x13, 0x20, 0xFF, 0xA0, 0xE3],
new byte[] { 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00 }, [0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00],
null); null);
if (PatchOffset == null) if (PatchOffset == null)
@@ -616,8 +616,8 @@ namespace WPinternals
ClearEfiChecksum(SecurityServicesDxe); ClearEfiChecksum(SecurityServicesDxe);
PatchOffset = ByteOperations.FindPattern(SecurityServicesDxe, PatchOffset = ByteOperations.FindPattern(SecurityServicesDxe,
new byte[] { 0x10, 0xFF, 0xFF, 0xE5, 0x80, 0xFF, 0x10, 0xE3, 0xFF, 0xFF, 0xFF, 0x0A }, [0x10, 0xFF, 0xFF, 0xE5, 0x80, 0xFF, 0x10, 0xE3, 0xFF, 0xFF, 0xFF, 0x0A],
new byte[] { 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00 }, [0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00],
null); null);
if (PatchOffset == null) if (PatchOffset == null)
@@ -628,8 +628,8 @@ namespace WPinternals
ByteOperations.WriteUInt8(SecurityServicesDxe, (UInt32)PatchOffset + 0x0B, 0xEA); ByteOperations.WriteUInt8(SecurityServicesDxe, (UInt32)PatchOffset + 0x0B, 0xEA);
PatchOffset = ByteOperations.FindPattern(SecurityServicesDxe, PatchOffset = ByteOperations.FindPattern(SecurityServicesDxe,
new byte[] { 0x11, 0xFF, 0xFF, 0xE5, 0x40, 0xFF, 0x10, 0xE3, 0xFF, 0xFF, 0xFF, 0x0A }, [0x11, 0xFF, 0xFF, 0xE5, 0x40, 0xFF, 0x10, 0xE3, 0xFF, 0xFF, 0xFF, 0x0A],
new byte[] { 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00 }, [0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00],
null); null);
if (PatchOffset == null) if (PatchOffset == null)
@@ -51,7 +51,7 @@ namespace WPinternals
FlashModel.SendFfuPayloadV1(EmptyChunk); FlashModel.SendFfuPayloadV1(EmptyChunk);
// Reboot to Qualcomm Emergency mode // Reboot to Qualcomm Emergency mode
byte[] RebootCommand = new byte[] { 0x4E, 0x4F, 0x4B, 0x52 }; // NOKR byte[] RebootCommand = [0x4E, 0x4F, 0x4B, 0x52]; // NOKR
FlashModel.ExecuteRawVoidMethod(RebootCommand); FlashModel.ExecuteRawVoidMethod(RebootCommand);
} }
@@ -1848,7 +1848,7 @@ namespace WPinternals
byte[] buffer = new byte[chunkSize]; byte[] buffer = new byte[chunkSize];
Int64 position = flashPart.Stream.Position; Int64 position = flashPart.Stream.Position;
flashPart.Stream.Read(buffer, 0, chunkSize); flashPart.Stream.Read(buffer, 0, chunkSize);
flashingPayloads.Add(new FlashingPayload(1, new byte[][] { crypto.ComputeHash(buffer) }, new UInt32[] { (flashPart.StartSector * 0x200 / (UInt32)chunkSize) + i }, new UInt32[] { j }, new Int64[] { position })); flashingPayloads.Add(new FlashingPayload(1, [crypto.ComputeHash(buffer)], [(flashPart.StartSector * 0x200 / (UInt32)chunkSize) + i], [j], [position]));
CurrentProcess1++; CurrentProcess1++;
} }
} }
@@ -1902,7 +1902,7 @@ namespace WPinternals
} }
else else
{ {
flashingPayloads.Add(new FlashingPayload(1, new byte[][] { hash }, new UInt32[] { (flashPart.StartSector * 0x200 / (UInt32)chunkSize) + i }, new UInt32[] { j }, new Int64[] { position })); flashingPayloads.Add(new FlashingPayload(1, [hash], [(flashPart.StartSector * 0x200 / (UInt32)chunkSize) + i], [j], [position]));
} }
CurrentProcess1++; CurrentProcess1++;
@@ -123,8 +123,8 @@ namespace WPinternals
// //
private static byte[] GenerateCatalogFile(byte[] hashData) private static byte[] GenerateCatalogFile(byte[] hashData)
{ {
byte[] catalog_first_part = new byte[] { 0x30, 0x82, 0x01, 0x44, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x02, 0xA0, 0x82, 0x01, 0x35, 0x30, 0x82, 0x01, 0x31, 0x02, 0x01, 0x01, 0x31, 0x00, 0x30, 0x82, 0x01, 0x26, 0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0A, 0x01, 0xA0, 0x82, 0x01, 0x17, 0x30, 0x82, 0x01, 0x13, 0x30, 0x0C, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0C, 0x01, 0x01, 0x04, 0x10, 0xA8, 0xCA, 0xD9, 0x7D, 0xBF, 0x6D, 0x67, 0x4D, 0xB1, 0x4D, 0x62, 0xFB, 0xE6, 0x26, 0x22, 0xD4, 0x17, 0x0D, 0x32, 0x30, 0x30, 0x31, 0x31, 0x30, 0x31, 0x32, 0x31, 0x32, 0x32, 0x37, 0x5A, 0x30, 0x0E, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0C, 0x01, 0x02, 0x05, 0x00, 0x30, 0x81, 0xD1, 0x30, 0x81, 0xCE, 0x04, 0x1E, 0x48, 0x00, 0x61, 0x00, 0x73, 0x00, 0x68, 0x00, 0x54, 0x00, 0x61, 0x00, 0x62, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x2E, 0x00, 0x62, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x62, 0x00, 0x00, 0x00, 0x31, 0x81, 0xAB, 0x30, 0x45, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x04, 0x31, 0x37, 0x30, 0x35, 0x30, 0x10, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x19, 0xA2, 0x02, 0x80, 0x00, 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14 }; byte[] catalog_first_part = [0x30, 0x82, 0x01, 0x44, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x02, 0xA0, 0x82, 0x01, 0x35, 0x30, 0x82, 0x01, 0x31, 0x02, 0x01, 0x01, 0x31, 0x00, 0x30, 0x82, 0x01, 0x26, 0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0A, 0x01, 0xA0, 0x82, 0x01, 0x17, 0x30, 0x82, 0x01, 0x13, 0x30, 0x0C, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0C, 0x01, 0x01, 0x04, 0x10, 0xA8, 0xCA, 0xD9, 0x7D, 0xBF, 0x6D, 0x67, 0x4D, 0xB1, 0x4D, 0x62, 0xFB, 0xE6, 0x26, 0x22, 0xD4, 0x17, 0x0D, 0x32, 0x30, 0x30, 0x31, 0x31, 0x30, 0x31, 0x32, 0x31, 0x32, 0x32, 0x37, 0x5A, 0x30, 0x0E, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0C, 0x01, 0x02, 0x05, 0x00, 0x30, 0x81, 0xD1, 0x30, 0x81, 0xCE, 0x04, 0x1E, 0x48, 0x00, 0x61, 0x00, 0x73, 0x00, 0x68, 0x00, 0x54, 0x00, 0x61, 0x00, 0x62, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x2E, 0x00, 0x62, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x62, 0x00, 0x00, 0x00, 0x31, 0x81, 0xAB, 0x30, 0x45, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x04, 0x31, 0x37, 0x30, 0x35, 0x30, 0x10, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x19, 0xA2, 0x02, 0x80, 0x00, 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14];
byte[] catalog_second_part = new byte[] { 0x30, 0x62, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0C, 0x02, 0x02, 0x31, 0x54, 0x30, 0x52, 0x1E, 0x4C, 0x00, 0x7B, 0x00, 0x44, 0x00, 0x45, 0x00, 0x33, 0x00, 0x35, 0x00, 0x31, 0x00, 0x41, 0x00, 0x34, 0x00, 0x32, 0x00, 0x2D, 0x00, 0x38, 0x00, 0x45, 0x00, 0x35, 0x00, 0x39, 0x00, 0x2D, 0x00, 0x31, 0x00, 0x31, 0x00, 0x44, 0x00, 0x30, 0x00, 0x2D, 0x00, 0x38, 0x00, 0x43, 0x00, 0x34, 0x00, 0x37, 0x00, 0x2D, 0x00, 0x30, 0x00, 0x30, 0x00, 0x43, 0x00, 0x30, 0x00, 0x34, 0x00, 0x46, 0x00, 0x43, 0x00, 0x32, 0x00, 0x39, 0x00, 0x35, 0x00, 0x45, 0x00, 0x45, 0x00, 0x7D, 0x02, 0x02, 0x02, 0x00, 0x31, 0x00 }; byte[] catalog_second_part = [0x30, 0x62, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0C, 0x02, 0x02, 0x31, 0x54, 0x30, 0x52, 0x1E, 0x4C, 0x00, 0x7B, 0x00, 0x44, 0x00, 0x45, 0x00, 0x33, 0x00, 0x35, 0x00, 0x31, 0x00, 0x41, 0x00, 0x34, 0x00, 0x32, 0x00, 0x2D, 0x00, 0x38, 0x00, 0x45, 0x00, 0x35, 0x00, 0x39, 0x00, 0x2D, 0x00, 0x31, 0x00, 0x31, 0x00, 0x44, 0x00, 0x30, 0x00, 0x2D, 0x00, 0x38, 0x00, 0x43, 0x00, 0x34, 0x00, 0x37, 0x00, 0x2D, 0x00, 0x30, 0x00, 0x30, 0x00, 0x43, 0x00, 0x30, 0x00, 0x34, 0x00, 0x46, 0x00, 0x43, 0x00, 0x32, 0x00, 0x39, 0x00, 0x35, 0x00, 0x45, 0x00, 0x45, 0x00, 0x7D, 0x02, 0x02, 0x02, 0x00, 0x31, 0x00];
byte[] hash = new SHA1Managed().ComputeHash(hashData); byte[] hash = new SHA1Managed().ComputeHash(hashData);
@@ -72,7 +72,7 @@ namespace WPinternals
//byte[] Meid = CurrentModel.ExecuteJsonMethodAsBytes("ReadMeid", "Meid"); // error //byte[] Meid = CurrentModel.ExecuteJsonMethodAsBytes("ReadMeid", "Meid"); // error
//string Test = CurrentModel.ExecuteJsonMethodAsString("ReadManufacturingData", ""); -> This method is only possible in Label-mode. //string Test = CurrentModel.ExecuteJsonMethodAsString("ReadManufacturingData", ""); -> This method is only possible in Label-mode.
byte[] AsskMask = new byte[0x10] { 1, 0, 16, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64 }; byte[] AsskMask = [1, 0, 16, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64];
byte[] Challenge = new byte[0x88]; byte[] Challenge = new byte[0x88];
Dictionary<string, object> Params = new(); Dictionary<string, object> Params = new();
Params.Add("AsskMask", AsskMask); Params.Add("AsskMask", AsskMask);
+11 -11
View File
@@ -296,8 +296,8 @@ namespace WPinternals
break; break;
case PhoneInterfaces.Lumia_Flash: case PhoneInterfaces.Lumia_Flash:
case PhoneInterfaces.Lumia_Bootloader: case PhoneInterfaces.Lumia_Bootloader:
byte[] BootModeFlagCommand = new byte[] { 0x4E, 0x4F, 0x4B, 0x58, 0x46, 0x57, 0x00, 0x55, 0x42, 0x46, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 }; // NOKFW UBF byte[] BootModeFlagCommand = [0x4E, 0x4F, 0x4B, 0x58, 0x46, 0x57, 0x00, 0x55, 0x42, 0x46, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00]; // NOKFW UBF
byte[] RebootCommand = new byte[] { 0x4E, 0x4F, 0x4B, 0x52 }; // NOKR byte[] RebootCommand = [0x4E, 0x4F, 0x4B, 0x52]; // NOKR
byte[] RebootCommandResult; byte[] RebootCommandResult;
IsSwitchingInterface = true; IsSwitchingInterface = true;
switch (TargetMode) switch (TargetMode)
@@ -328,7 +328,7 @@ namespace WPinternals
SwitchFromFlashToLabelMode(); SwitchFromFlashToLabelMode();
break; break;
case PhoneInterfaces.Lumia_Flash: // attempt to boot from limited flash to full flash case PhoneInterfaces.Lumia_Flash: // attempt to boot from limited flash to full flash
byte[] RebootToFlashCommand = new byte[] { 0x4E, 0x4F, 0x4B, 0x53 }; // NOKS byte[] RebootToFlashCommand = [0x4E, 0x4F, 0x4B, 0x53]; // NOKS
((NokiaPhoneModel)CurrentModel).ExecuteRawVoidMethod(RebootToFlashCommand); ((NokiaPhoneModel)CurrentModel).ExecuteRawVoidMethod(RebootToFlashCommand);
PhoneNotifier.NewDeviceArrived += NewDeviceArrived; PhoneNotifier.NewDeviceArrived += NewDeviceArrived;
ModeSwitchProgressWrapper("Rebooting phone to Flash mode...", null); ModeSwitchProgressWrapper("Rebooting phone to Flash mode...", null);
@@ -338,7 +338,7 @@ namespace WPinternals
SwitchFromFlashToMassStorageMode(); SwitchFromFlashToMassStorageMode();
break; break;
case PhoneInterfaces.Qualcomm_Download: case PhoneInterfaces.Qualcomm_Download:
byte[] RebootToQualcommDownloadCommand = new byte[] { 0x4E, 0x4F, 0x4B, 0x58, 0x43, 0x42, 0x45 }; // NOKXCBE byte[] RebootToQualcommDownloadCommand = [0x4E, 0x4F, 0x4B, 0x58, 0x43, 0x42, 0x45]; // NOKXCBE
RebootCommandResult = ((NokiaPhoneModel)CurrentModel).ExecuteRawMethod(RebootToQualcommDownloadCommand); RebootCommandResult = ((NokiaPhoneModel)CurrentModel).ExecuteRawMethod(RebootToQualcommDownloadCommand);
if (RebootCommandResult?.Length == 4) // This means fail: NOKU (unknow command) if (RebootCommandResult?.Length == 4) // This means fail: NOKU (unknow command)
{ {
@@ -504,8 +504,8 @@ namespace WPinternals
} }
else if ((CurrentMode == PhoneInterfaces.Lumia_Flash) && (TargetMode == PhoneInterfaces.Qualcomm_Download)) else if ((CurrentMode == PhoneInterfaces.Lumia_Flash) && (TargetMode == PhoneInterfaces.Qualcomm_Download))
{ {
byte[] RebootCommand = new byte[] { 0x4E, 0x4F, 0x4B, 0x52 }; byte[] RebootCommand = [0x4E, 0x4F, 0x4B, 0x52];
byte[] RebootToQualcommDownloadCommand = new byte[] { 0x4E, 0x4F, 0x4B, 0x58, 0x43, 0x42, 0x45 }; // NOKXCBE byte[] RebootToQualcommDownloadCommand = [0x4E, 0x4F, 0x4B, 0x58, 0x43, 0x42, 0x45]; // NOKXCBE
IsSwitchingInterface = true; IsSwitchingInterface = true;
LogFile.Log("Sending command for rebooting to Emergency Download mode"); LogFile.Log("Sending command for rebooting to Emergency Download mode");
byte[] RebootCommandResult = ((NokiaPhoneModel)CurrentModel).ExecuteRawMethod(RebootToQualcommDownloadCommand); byte[] RebootCommandResult = ((NokiaPhoneModel)CurrentModel).ExecuteRawMethod(RebootToQualcommDownloadCommand);
@@ -619,8 +619,8 @@ namespace WPinternals
} }
else else
{ {
byte[] BootModeFlagCommand = new byte[] { 0x4E, 0x4F, 0x4B, 0x58, 0x46, 0x57, 0x00, 0x55, 0x42, 0x46, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 }; // NOKFW UBF byte[] BootModeFlagCommand = [0x4E, 0x4F, 0x4B, 0x58, 0x46, 0x57, 0x00, 0x55, 0x42, 0x46, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00]; // NOKFW UBF
byte[] RebootCommand = new byte[] { 0x4E, 0x4F, 0x4B, 0x52 }; // NOKR byte[] RebootCommand = [0x4E, 0x4F, 0x4B, 0x52]; // NOKR
BootModeFlagCommand[0x0F] = 0x59; BootModeFlagCommand[0x0F] = 0x59;
((NokiaPhoneModel)CurrentModel).ExecuteRawMethod(BootModeFlagCommand); ((NokiaPhoneModel)CurrentModel).ExecuteRawMethod(BootModeFlagCommand);
@@ -671,9 +671,9 @@ namespace WPinternals
if (IsOldLumia || IsOriginalEngineeringLumia) if (IsOldLumia || IsOriginalEngineeringLumia)
{ {
byte[] BootModeFlagCommand = new byte[] { 0x4E, 0x4F, 0x4B, 0x58, 0x46, 0x57, 0x00, 0x55, 0x42, 0x46, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 }; // NOKFW UBF byte[] BootModeFlagCommand = [0x4E, 0x4F, 0x4B, 0x58, 0x46, 0x57, 0x00, 0x55, 0x42, 0x46, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00]; // NOKFW UBF
byte[] RebootCommand = new byte[] { 0x4E, 0x4F, 0x4B, 0x52 }; byte[] RebootCommand = [0x4E, 0x4F, 0x4B, 0x52];
byte[] RebootToMassStorageCommand = new byte[] { 0x4E, 0x4F, 0x4B, 0x4D }; // NOKM byte[] RebootToMassStorageCommand = [0x4E, 0x4F, 0x4B, 0x4D]; // NOKM
IsSwitchingInterface = true; IsSwitchingInterface = true;
byte[] RebootCommandResult = ((NokiaPhoneModel)CurrentModel).ExecuteRawMethod(RebootToMassStorageCommand); byte[] RebootCommandResult = ((NokiaPhoneModel)CurrentModel).ExecuteRawMethod(RebootToMassStorageCommand);
if (RebootCommandResult?.Length == 4) // This means fail: NOKU (unknown command) if (RebootCommandResult?.Length == 4) // This means fail: NOKU (unknown command)