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); UIContext.Send(s => Notifier.Start(), null);
FlashModel = (NokiaFlashModel)await SwitchModeViewModel.SwitchTo(Notifier, PhoneInterfaces.Lumia_Flash); FlashModel = (NokiaFlashModel)await SwitchModeViewModel.SwitchTo(Notifier, PhoneInterfaces.Lumia_Flash);
GPT GPT = FlashModel.ReadGPT(); // May throw NotSupportedException 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]); GPT.WritePartitions(args[2]);
FlashModel.SwitchToFlashAppContext(); FlashModel.SwitchToFlashAppContext();
Notifier.Stop(); Notifier.Stop();
@@ -237,6 +241,35 @@ namespace WPinternals
LogFile.EndAction("BackupGPT"); LogFile.EndAction("BackupGPT");
} }
break; 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": case "restoregpt":
if (args.Length < 3) if (args.Length < 3)
{ {
@@ -393,7 +426,11 @@ namespace WPinternals
}; };
} }
string EfiPath = Path.Combine(args[3], Name); 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); File.WriteAllBytes(EfiPath, EfiBinary);
} }
break; break;
@@ -1968,6 +2005,7 @@ namespace WPinternals
LogFile.Log("WPinternals -ClearNV", LogType.ConsoleOnly); LogFile.Log("WPinternals -ClearNV", LogType.ConsoleOnly);
LogFile.Log("WPinternals -ReadGPT", LogType.ConsoleOnly); LogFile.Log("WPinternals -ReadGPT", LogType.ConsoleOnly);
LogFile.Log("WPinternals -BackupGPT <Path to xml-file>", 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 -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("WPinternals -MergeGPT <Path to input-xml-file> <Path to input-xml-file>", LogType.ConsoleOnly);
LogFile.Log(" <Optional: Path to output-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) internal void WritePartitions(string Path)
{ {
string DirPath = System.IO.Path.GetDirectoryName(Path); string DirPath = System.IO.Path.GetDirectoryName(Path);
if (!Directory.Exists(DirPath)) if (!string.IsNullOrEmpty(DirPath) && !Directory.Exists(DirPath))
{ {
Directory.CreateDirectory(DirPath); Directory.CreateDirectory(DirPath);
} }
-23
View File
@@ -29,8 +29,6 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>Heathcliff74.snk</AssemblyOriginatorKeyFile>
<NoWarn>1701;1702;CA1416;RCS1090;RCS1163</NoWarn> <NoWarn>1701;1702;CA1416;RCS1090;RCS1163</NoWarn>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
@@ -302,14 +300,10 @@
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>Heathcliff74.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<None Update="app.manifest"> <None Update="app.manifest">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</None> </None>
<None Include="Heathcliff74.snk" />
<AppDesigner Include="Properties\" /> <AppDesigner Include="Properties\" />
<EmbeddedResource Include="SB" /> <EmbeddedResource Include="SB" />
<EmbeddedResource Include="SBA" /> <EmbeddedResource Include="SBA" />
@@ -321,23 +315,6 @@
<ItemGroup> <ItemGroup>
<Resource Include="WPinternals.ico" /> <Resource Include="WPinternals.ico" />
</ItemGroup> </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> <ItemGroup>
<Resource Include="aerobusy.gif" /> <Resource Include="aerobusy.gif" />
</ItemGroup> </ItemGroup>