MSI was really CFB all along

This commit is contained in:
Matt Nadareski
2023-01-10 10:51:36 -08:00
parent 661808826a
commit 5ea89eefe8
7 changed files with 119 additions and 103 deletions

View File

@@ -189,6 +189,58 @@ namespace Test
}
}
// CFB
else if (ft == SupportedFileType.CFB)
{
// Build the installer information
Console.WriteLine("Extracting CFB contents");
Console.WriteLine();
// If the CFB file itself fails
try
{
using (CompoundFile cf = new CompoundFile(stream, CFSUpdateMode.ReadOnly, CFSConfiguration.Default))
{
cf.RootStorage.VisitEntries((e) =>
{
if (!e.IsStream)
return;
var str = cf.RootStorage.GetStream(e.Name);
if (str == null)
return;
byte[] strData = str.GetData();
if (strData == null)
return;
string decoded = BurnOutSharp.FileType.CFB.DecodeStreamName(e.Name).TrimEnd('\0');
byte[] nameBytes = Encoding.UTF8.GetBytes(e.Name);
// UTF-8 encoding of 0x4840.
if (nameBytes[0] == 0xe4 && nameBytes[1] == 0xa1 && nameBytes[2] == 0x80)
decoded = decoded.Substring(3);
foreach (char c in Path.GetInvalidFileNameChars())
{
decoded = decoded.Replace(c, '_');
}
string filename = Path.Combine(outputDirectory, decoded);
using (Stream fs = File.OpenWrite(filename))
{
fs.Write(strData, 0, strData.Length);
}
}, recursive: true);
}
}
catch (Exception ex)
{
Console.WriteLine($"Something went wrong extracting CFB: {ex}");
Console.WriteLine();
}
}
// GCF
else if (ft == SupportedFileType.GCF)
{
@@ -458,58 +510,6 @@ namespace Test
}
#endif
// MSI
else if (ft == SupportedFileType.MSI)
{
// Build the installer information
Console.WriteLine("Extracting MSI contents");
Console.WriteLine();
// If the MSI file itself fails
try
{
using (CompoundFile msi = new CompoundFile(stream, CFSUpdateMode.ReadOnly, CFSConfiguration.Default))
{
msi.RootStorage.VisitEntries((e) =>
{
if (!e.IsStream)
return;
var str = msi.RootStorage.GetStream(e.Name);
if (str == null)
return;
byte[] strData = str.GetData();
if (strData == null)
return;
string decoded = BurnOutSharp.FileType.MSI.DecodeStreamName(e.Name).TrimEnd('\0');
byte[] nameBytes = Encoding.UTF8.GetBytes(e.Name);
// UTF-8 encoding of 0x4840.
if (nameBytes[0] == 0xe4 && nameBytes[1] == 0xa1 && nameBytes[2] == 0x80)
decoded = decoded.Substring(3);
foreach (char c in Path.GetInvalidFileNameChars())
{
decoded = decoded.Replace(c, '_');
}
string filename = Path.Combine(outputDirectory, decoded);
using (Stream fs = File.OpenWrite(filename))
{
fs.Write(strData, 0, strData.Length);
}
}, recursive: true);
}
}
catch (Exception ex)
{
Console.WriteLine($"Something went wrong extracting MSI: {ex}");
Console.WriteLine();
}
}
// PAK
else if (ft == SupportedFileType.PAK)
{

View File

@@ -174,6 +174,25 @@ namespace Test
bsp.Print();
}
// CFB
else if (ft == SupportedFileType.CFB)
{
// Build the CFB information
Console.WriteLine("Creating Compact File Binary deserializer");
Console.WriteLine();
var cfb = CFB.Create(stream);
if (cfb == null)
{
Console.WriteLine("Something went wrong parsing Compact File Binary");
Console.WriteLine();
return;
}
// Print the CFB to screen
cfb.Print();
}
// CIA
else if (ft == SupportedFileType.CIA)
{
@@ -257,25 +276,6 @@ namespace Test
cabinet.Print();
}
// MSI -- TODO: Technically CFB
else if (ft == SupportedFileType.MSI)
{
// Build the CFB information
Console.WriteLine("Creating Compact File Binary deserializer");
Console.WriteLine();
var cfb = CFB.Create(stream);
if (cfb == null)
{
Console.WriteLine("Something went wrong parsing Compact File Binary");
Console.WriteLine();
return;
}
// Print the CFB to screen
cfb.Print();
}
// N3DS
else if (ft == SupportedFileType.N3DS)
{