Code cleanup

This commit is contained in:
Gustave Monce
2019-12-22 12:25:48 +01:00
parent 0e6f905809
commit a2a1c2302b
149 changed files with 3980 additions and 4088 deletions
+1 -1
View File
@@ -365,7 +365,7 @@ namespace WPinternals
uint crc = (uint)(((uint)0) ^ (-1));
for (var i = Offset; i < (Offset + Length); i++)
{
crc = (crc >> 8) ^ CRC32Table[ (crc ^ Input[i]) & 0xFF ];
crc = (crc >> 8) ^ CRC32Table[(crc ^ Input[i]) & 0xFF];
}
crc = (uint)(crc ^ (-1));
+1 -1
View File
@@ -442,7 +442,7 @@ namespace WPinternals
byte[] mobilestartup = msms.ToArray();
Version OSVersion = PE.GetProductVersion(mobilestartup);
s.Close();
return OSVersion.ToString();
}
}
+1 -1
View File
@@ -39,7 +39,7 @@ namespace WPinternals
Buffer.BlockCopy(Input, (int)Offset, Properties, 0, 5);
UInt64 OutputSize = ByteOperations.ReadUInt64(Input, Offset + 5);
SevenZip.Compression.LZMA.Decoder Coder = new SevenZip.Compression.LZMA.Decoder();
Coder.SetDecoderProperties(Properties);
+14 -14
View File
@@ -20,15 +20,15 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
@@ -202,13 +202,13 @@ namespace WPinternals
if (SoftwarePackages != null)
{
foreach (SoftwarePackage pkg in SoftwarePackages.softwarePackages)
Package = SoftwarePackages.softwarePackages.FirstOrDefault<SoftwarePackage>();
Package = SoftwarePackages.softwarePackages.FirstOrDefault<SoftwarePackage>();
}
}
if (Package == null)
throw new WPinternalsException("ENOSW package not found");
SoftwareFile FileInfo = Package.files.Where(f => f.fileName.EndsWith(".secwim", StringComparison.OrdinalIgnoreCase)).First();
SoftwareFile DPLF = Package.files.Where(f => f.fileName.EndsWith(".dpl", StringComparison.OrdinalIgnoreCase)).First();
@@ -231,11 +231,11 @@ namespace WPinternals
if (DPLUrl == "")
throw new WPinternalsException("DPL not found");
Task<string> GetDPLStrTask = HttpClient.GetStringAsync(DPLUrl);
GetDPLStrTask.Wait();
string DPLStrString = GetDPLStrTask.Result;
DPL.Package dpl;
XmlSerializer serializer = new XmlSerializer(typeof(DPL.Package));
using (StringReader reader = new StringReader(DPLStrString.Replace("ft:", "").Replace("dpl:", "").Replace("typedes:", "")))
@@ -246,9 +246,9 @@ namespace WPinternals
foreach (DPL.File file in dpl.Content.Files.File)
{
string name = file.Name;
DPL.Range range = file.Extensions.MmosWimFile.UseCaseCompatibilities.Compatibility.FirstOrDefault().Range;
if (IsFirmwareBetween(PhoneFirmwareRevision, range.From, range.To))
FileInfo = Package.files.Where(f => f.fileName.EndsWith(name, StringComparison.OrdinalIgnoreCase)).First();
}
@@ -363,7 +363,7 @@ namespace WPinternals
}
}
#pragma warning disable 0649
#pragma warning disable 0649
[DataContract]
internal class FileUrlResult
{
@@ -379,7 +379,7 @@ namespace WPinternals
[DataMember]
internal List<SoftwareFileChecksum> checksum;
}
#pragma warning restore 0649
#pragma warning restore 0649
[DataContract]
public class DiscoveryQueryParameters
@@ -454,7 +454,7 @@ namespace WPinternals
[DataMember]
public List<string> response;
public DiscoveryParameters(): this(DiscoveryCondition.Default)
public DiscoveryParameters() : this(DiscoveryCondition.Default)
{
}
+8 -8
View File
@@ -26,7 +26,7 @@ using System.Runtime.InteropServices;
namespace WPinternals
{
internal class MassStorage: NokiaPhoneModel
internal class MassStorage : NokiaPhoneModel
{
internal string Drive = null;
internal string PhysicalDrive = null;
@@ -36,8 +36,8 @@ namespace WPinternals
private bool OpenWithWriteAccess;
private QualcommSerial Serial;
internal MassStorage(string DevicePath): base(DevicePath)
internal MassStorage(string DevicePath) : base(DevicePath)
{
try
{
@@ -288,7 +288,7 @@ namespace WPinternals
ProgressUpdater Progress = UpdaterPerSector;
if ((Progress == null) && (ProgressUpdateCallback != null))
Progress = new ProgressUpdater(SectorCount, ProgressUpdateCallback);
byte[] Buffer;
if (SectorCount >= 0x80)
Buffer = new byte[0x10000];
@@ -425,13 +425,13 @@ namespace WPinternals
OpenVolume(true);
SetSectorPosition(StartSector);
byte[] Buffer;
using (BinaryReader Reader = new BinaryReader(File.Open(Path, FileMode.Open)))
{
ProgressUpdater Progress = UpdaterPerSector;
if ((Progress == null) && (ProgressUpdateCallback != null))
if ((Progress == null) && (ProgressUpdateCallback != null))
Progress = new ProgressUpdater((UInt64)(Reader.BaseStream.Length / 0x200), ProgressUpdateCallback);
if (Reader.BaseStream.Length >= 0x10000)
@@ -443,9 +443,9 @@ namespace WPinternals
for (UInt64 i = 0; i < (UInt64)(Reader.BaseStream.Length / 0x200); i += 0x80)
{
Count = Reader.Read(Buffer, 0, Buffer.Length);
WriteSectors(Buffer, (uint)Count);
if (Progress != null)
Progress.IncreaseProgress((ulong)Count / 0x200);
}
+3 -3
View File
@@ -18,10 +18,10 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Runtime.InteropServices;
using System.Runtime.ConstrainedExecution;
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security;
namespace WPinternals
+12 -12
View File
@@ -100,7 +100,7 @@ namespace WPinternals
uint? flags = ReadSecurityFlags();
if (!flags.HasValue)
return null;
var finalconfig = (Fuse)flags.Value;
return finalconfig.HasFlag(fuse);
}
@@ -186,7 +186,7 @@ namespace WPinternals
public void SendFfuHeaderV1(byte[] FfuHeader, byte Options = 0)
{
byte[] Request = new byte[FfuHeader.Length + 0x20];
string Header = "NOKXFS";
System.Buffer.BlockCopy(System.Text.Encoding.ASCII.GetBytes(Header), 0, Request, 0, Header.Length);
System.Buffer.BlockCopy(BigEndian.GetBytes(0x0001, 2), 0, Request, 0x06, 2); // Protocol version = 0x0001
@@ -279,7 +279,7 @@ namespace WPinternals
System.Buffer.BlockCopy(BigEndian.GetBytes(0x0000001B, 4), 0, Request, 0x0C, 4); // Subblock type for Payload v2 = 0x1B
System.Buffer.BlockCopy(BigEndian.GetBytes(FfuChunk.Length + 0x0C, 4), 0, Request, 0x10, 4); // Subblock length = length of chunk + 0x08
System.Buffer.BlockCopy(BigEndian.GetBytes(FfuChunk.Length, 4), 0, Request, 0x14, 4); // Payload length = length of chunk
Request[0x18] = Options; // Data options = 0 (1 = verify)
@@ -368,18 +368,18 @@ namespace WPinternals
if (ResultCode != 0)
ThrowFlashError(ResultCode);
}
internal void SwitchToMmosContext()
{
byte[] Request = new byte[7];
ByteOperations.WriteAsciiString(Request, 0, "NOKXCBA");
ExecuteRawVoidMethod(Request);
ResetDevice();
Dispose(true);
}
private void ThrowFlashError(int ErrorCode)
{
string SubMessage;
@@ -549,11 +549,11 @@ namespace WPinternals
MMOSFile.Read(data, 0, (int)(length - offset));
LoadMmosBinary(length, (uint)offset, false, data);
}
SwitchToMmosContext();
ResetPhone();
}
LogFile.EndAction("FlashMMOS");
}
@@ -613,9 +613,9 @@ namespace WPinternals
// If this function is used with a locked BootMgr v1,
// then the mode-switching should be done outside this function,
// because the context-switches that are used here are not supported on BootMgr v1.
// Only works in BootLoader-mode or on unlocked bootloaders in Flash-mode!!
PhoneInfo Info = ReadPhoneInfo(ExtendedInfo: false);
FlashAppType OriginalAppType = Info.App;
bool Switch = ((Info.App != FlashAppType.BootManager) && Info.SecureFfuEnabled && !Info.Authenticated && !Info.RdcPresent);
@@ -1112,7 +1112,7 @@ namespace WPinternals
ExecuteRawMethod(Request);
}
internal enum SecureBootKeyType: byte
internal enum SecureBootKeyType : byte
{
Retail = 0,
Engineering = 1
@@ -1154,7 +1154,7 @@ namespace WPinternals
public string Imei; // Extended info
public string Firmware; // Extended info
public byte[] RKH; // Extended info
public FlashAppType App;
public byte FlashAppVersionMajor;
+1 -1
View File
@@ -27,7 +27,7 @@ using System.Linq;
namespace WPinternals
{
internal class NokiaPhoneModel: IDisposable
internal class NokiaPhoneModel : IDisposable
{
protected bool Disposed = false;
private USBDevice Device = null;
+2 -2
View File
@@ -21,15 +21,15 @@
using System;
using System.Collections.Specialized;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Threading;
namespace WPinternals
{
using Luid = NativeMethods.LUID;
using Win32Exception = System.ComponentModel.Win32Exception;
using PrivilegeNotHeldException = System.Security.AccessControl.PrivilegeNotHeldException;
using Win32Exception = System.ComponentModel.Win32Exception;
internal delegate void PrivilegedCallback(object state);
+1 -1
View File
@@ -47,7 +47,7 @@ namespace WPinternals
internal uint CertificatesOffset;
internal byte[] RootKeyHash = null;
internal QualcommPartition(string Path): this(File.ReadAllBytes(Path)) { }
internal QualcommPartition(string Path) : this(File.ReadAllBytes(Path)) { }
internal QualcommPartition(byte[] Binary, uint Offset = 0)
{
+3 -3
View File
@@ -23,7 +23,7 @@ using System.Threading.Tasks;
namespace WPinternals
{
internal enum SaharaMode: uint
internal enum SaharaMode : uint
{
ImageTransferPending = 0x00,
ImagetransferComplete = 0x01,
@@ -154,7 +154,7 @@ namespace WPinternals
LogFile.Log("MaxLength: 0x" + ByteOperations.ReadUInt32(Hello, 0x10).ToString("X8"), LogType.FileOnly);
LogFile.Log("Mode: 0x" + ByteOperations.ReadUInt32(Hello, 0x14).ToString("X8"), LogType.FileOnly);
byte[] HelloResponse = new byte[] {
byte[] HelloResponse = new byte[] {
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
@@ -233,7 +233,7 @@ namespace WPinternals
Incoming = System.Text.Encoding.ASCII.GetString(Serial.GetResponse(null));
LogFile.Log("In: " + Incoming, LogType.FileOnly);
};
LogFile.Log("Incoming Hello-response received", LogType.FileOnly);
HandshakeCompleted = true;
}
+4 -4
View File
@@ -24,7 +24,7 @@ using System.IO.Ports;
namespace WPinternals
{
internal class QualcommSerial: IDisposable
internal class QualcommSerial : IDisposable
{
private bool Disposed = false;
private SerialPort Port = null;
@@ -37,7 +37,7 @@ namespace WPinternals
public QualcommSerial(string DevicePath)
{
CRC16 = new CRC16(0x1189, 0xFFFF, 0xFFFF);
string[] DevicePathElements = DevicePath.Split(new char[] { '#' });
if (string.Compare(DevicePathElements[3], "{86E0D1E0-8089-11D0-9CE4-08003E301F73}", true) == 0)
{
@@ -132,7 +132,7 @@ namespace WPinternals
for (int i = 0; i < ResponsePattern.Length; i++)
if (DecodedResponse[i] != ResponsePattern[i])
{
byte[] LogResponse = new byte[DecodedResponse.Length < 0x10 ? DecodedResponse.Length: 0x10];
byte[] LogResponse = new byte[DecodedResponse.Length < 0x10 ? DecodedResponse.Length : 0x10];
LogFile.Log("Qualcomm serial response: " + Converter.ConvertHexToString(LogResponse, ""), LogType.FileOnly);
LogFile.Log("Expected: " + Converter.ConvertHexToString(ResponsePattern, ""), LogType.FileOnly);
throw new BadMessageException();
@@ -292,7 +292,7 @@ namespace WPinternals
public class CRC16
{
private UInt16[] ChecksumTable =
private UInt16[] ChecksumTable =
new UInt16[] {
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
+4 -4
View File
@@ -22,14 +22,14 @@ using System;
namespace WPinternals
{
internal class SBL1: QualcommPartition
internal class SBL1 : QualcommPartition
{
internal SBL1(byte[] Binary): base(Binary, 0x2800) { }
internal SBL1(byte[] Binary) : base(Binary, 0x2800) { }
internal byte[] GenerateExtraSector(byte[] PartitionHeader)
{
UInt32? Offset = ByteOperations.FindPattern(Binary,
new byte[] {
new byte[] {
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,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
@@ -56,7 +56,7 @@ namespace WPinternals
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
},
new byte[] {
+1 -1
View File
@@ -42,7 +42,7 @@ namespace WPinternals
0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
null);
if (PatchOffset == null)
throw new BadImageFormatException();
+2 -2
View File
@@ -35,7 +35,7 @@ namespace WPinternals
internal SBL3(string FileName)
{
Binary = null;
// First try to parse as FFU
try
{
@@ -52,7 +52,7 @@ namespace WPinternals
{
byte[] SBL3Header;
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[] 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 = new byte[] { 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 SBL3Header);
+7 -7
View File
@@ -324,7 +324,7 @@ namespace WPinternals
Buffer.BlockCopy(
DecompressedImage,
(int)(File.BinaryOffset + OldBinarySize + OldSectionPadding),
NewImage,
NewImage,
(int)(File.BinaryOffset + NewBinarySize + NewSectionPadding),
(int)(File.FileOffset + OldFileSize - File.BinaryOffset - OldBinarySize - OldSectionPadding));
@@ -334,8 +334,8 @@ namespace WPinternals
// Copy volume-tail
Buffer.BlockCopy(
DecompressedImage,
(int)(File.FileOffset + OldFileSize + OldFilePadding),
DecompressedImage,
(int)(File.FileOffset + OldFileSize + OldFilePadding),
NewImage,
(int)(File.FileOffset + NewFileSize + NewFilePadding),
(int)(DecompressedImage.Length - File.FileOffset - OldFileSize - OldFilePadding));
@@ -386,7 +386,7 @@ namespace WPinternals
// The new binary will include the Qualcomm header, but not the signature and certificates, because they won't match anyway.
byte[] NewBinary = new byte[Binary.Length];
Buffer.BlockCopy(Binary, 0, NewBinary, 0, (int)CompressedSubImageOffset);
ByteOperations.WriteUInt32(NewBinary, 0x10, ByteOperations.ReadUInt32(NewBinary, 0x14)); // Complete image size - does not include signature and certs anymore
ByteOperations.WriteUInt32(NewBinary, 0x18, 0x00000000); // Address of signature
ByteOperations.WriteUInt32(NewBinary, 0x1C, 0x00000000); // Signature length
@@ -433,7 +433,7 @@ namespace WPinternals
if (NewCompressedImage.Length > CompressedSubImageSize)
{
Buffer.BlockCopy(Binary, (int)(FileHeaderOffset + OldFileSize + OldFilePadding), NewBinary, (int)(FileHeaderOffset + NewFileSize + NewFilePadding),
Buffer.BlockCopy(Binary, (int)(FileHeaderOffset + OldFileSize + OldFilePadding), NewBinary, (int)(FileHeaderOffset + NewFileSize + NewFilePadding),
(int)(VolumeHeaderOffset + VolumeSize - FileHeaderOffset - NewFileSize - NewFilePadding));
}
else
@@ -548,8 +548,8 @@ namespace WPinternals
byte[] SecurityDxe = GetFile("SecurityDxe");
ClearEfiChecksum(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 },
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 },
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 },
null);