Add new feature to generate a GPT xml file from a binary or backup

This commit is contained in:
Gustave Monce
2023-11-26 13:08:33 +01:00
parent 8d35be447a
commit dbd303fd07
3 changed files with 41 additions and 26 deletions
+40 -2
View File
@@ -223,7 +223,11 @@ namespace WPinternals
UIContext.Send(s => Notifier.Start(), null);
FlashModel = (NokiaFlashModel)await SwitchModeViewModel.SwitchTo(Notifier, PhoneInterfaces.Lumia_Flash);
GPT GPT = FlashModel.ReadGPT(); // May throw NotSupportedException
Directory.CreateDirectory(Path.GetDirectoryName(args[2]));
string DirPath = Path.GetDirectoryName(args[2]);
if (!string.IsNullOrEmpty(DirPath) && !Directory.Exists(DirPath))
{
Directory.CreateDirectory(DirPath);
}
GPT.WritePartitions(args[2]);
FlashModel.SwitchToFlashAppContext();
Notifier.Stop();
@@ -237,6 +241,35 @@ namespace WPinternals
LogFile.EndAction("BackupGPT");
}
break;
case "convertgpt":
if (args.Length < 4)
{
throw new ArgumentException("Wrong number of arguments. Usage: WPinternals.exe -ConvertGPT <Path to GPT-file> <Path to xml-file>");
}
LogFile.BeginAction("ConvertGPT");
try
{
using var stream = File.OpenRead(args[2]);
byte[] GPTBuffer = new byte[34 * 0x200];
stream.Read(GPTBuffer, 0, 34 * 0x200);
GPT GPT = new(GPTBuffer);// May throw NotSupportedException
string DirPath = Path.GetDirectoryName(args[3]);
if (!string.IsNullOrEmpty(DirPath) && !Directory.Exists(DirPath))
{
Directory.CreateDirectory(DirPath);
}
GPT.WritePartitions(args[3]);
}
catch (Exception Ex)
{
LogFile.LogException(Ex);
}
finally
{
LogFile.EndAction("ConvertGPT");
}
break;
case "restoregpt":
if (args.Length < 3)
{
@@ -393,7 +426,11 @@ namespace WPinternals
};
}
string EfiPath = Path.Combine(args[3], Name);
Directory.CreateDirectory(Path.GetDirectoryName(EfiPath));
string DirPath = Path.GetDirectoryName(EfiPath);
if (!string.IsNullOrEmpty(DirPath) && !Directory.Exists(DirPath))
{
Directory.CreateDirectory(DirPath);
}
File.WriteAllBytes(EfiPath, EfiBinary);
}
break;
@@ -1968,6 +2005,7 @@ namespace WPinternals
LogFile.Log("WPinternals -ClearNV", LogType.ConsoleOnly);
LogFile.Log("WPinternals -ReadGPT", LogType.ConsoleOnly);
LogFile.Log("WPinternals -BackupGPT <Path to xml-file>", LogType.ConsoleOnly);
LogFile.Log("WPinternals -ConvertGPT <Path to GPT-file> <Path to xml-file>", LogType.ConsoleOnly);
LogFile.Log("WPinternals -RestoreGPT <Path to xml-file>", LogType.ConsoleOnly);
LogFile.Log("WPinternals -MergeGPT <Path to input-xml-file> <Path to input-xml-file>", LogType.ConsoleOnly);
LogFile.Log(" <Optional: Path to output-xml-file>", LogType.ConsoleOnly);
+1 -1
View File
@@ -545,7 +545,7 @@ namespace WPinternals
internal void WritePartitions(string Path)
{
string DirPath = System.IO.Path.GetDirectoryName(Path);
if (!Directory.Exists(DirPath))
if (!string.IsNullOrEmpty(DirPath) && !Directory.Exists(DirPath))
{
Directory.CreateDirectory(DirPath);
}
-23
View File
@@ -29,8 +29,6 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>Heathcliff74.snk</AssemblyOriginatorKeyFile>
<NoWarn>1701;1702;CA1416;RCS1090;RCS1163</NoWarn>
</PropertyGroup>
<PropertyGroup>
@@ -302,14 +300,10 @@
<PlatformTarget>x64</PlatformTarget>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>Heathcliff74.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<None Update="app.manifest">
<SubType>Designer</SubType>
</None>
<None Include="Heathcliff74.snk" />
<AppDesigner Include="Properties\" />
<EmbeddedResource Include="SB" />
<EmbeddedResource Include="SBA" />
@@ -321,23 +315,6 @@
<ItemGroup>
<Resource Include="WPinternals.ico" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Resource Include="aerobusy.gif" />
</ItemGroup>