From 330f2257a800825bd691b9e57e6ff1e9d15b34e6 Mon Sep 17 00:00:00 2001 From: Tom60chat Date: Sun, 11 Jul 2021 17:12:34 +0200 Subject: [PATCH 1/3] Add support for container type 14 and sub container Add support for container type 14 (0xe) Add support to read sub container file (Tested on We Happy Few save file) --- ContainerReader/Program.cs | 108 +++++++++++++++++++++++++++++++------ 1 file changed, 93 insertions(+), 15 deletions(-) diff --git a/ContainerReader/Program.cs b/ContainerReader/Program.cs index 2c0c55e..013b241 100644 --- a/ContainerReader/Program.cs +++ b/ContainerReader/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -16,6 +16,7 @@ static void Main(string[] args) Console.WriteLine("ContainerReader\nA program that prints infomation about Windows Containers.index files, used to store metadata (such as the package family name, guid, and filename) about configuration/save game files for UWP apps and games.\nContainer \"filenames\" are actually directories, as they can have more than one file inside of them.\nUsage: ContainerReader containers.index\nNOTE: Doesn't, at the current time, handle all forms of containers.index. Will add support, but most are supported."); return; } + try { // Open a filestream with the user selected file @@ -28,15 +29,20 @@ static void Main(string[] args) int type = reader.ReadInt32(); // Throw generic exception - if(type != 0xd) + if (type != 0xd && type != 0xe) { throw new Exception(); } + // Could be something other than int32, but very unlikely int numFiles = reader.ReadInt32(); - Console.WriteLine("Friendly Name: "+BinaryReaderHelper.ReadUnicodeString(reader, reader.ReadInt32())); - Console.WriteLine("Package Family Name: " + BinaryReaderHelper.ReadUnicodeString(reader, reader.ReadInt32())); + Console.WriteLine("Friendly Name: " + BinaryReaderHelper.ReadUnicodeString(reader, reader.ReadInt32())); + + string[] name = BinaryReaderHelper.ReadUnicodeString(reader, reader.ReadInt32()).Split('!'); + + Console.WriteLine("Package Full Name: " + name[0]); + Console.WriteLine("Id: " + name[1]); // Not awfully sure what this is, so I'll just skip past it until I can figure out what it is. Possibly title ID or other internal data reader.ReadBytes(0xc); @@ -44,8 +50,14 @@ static void Main(string[] args) // Not sure what this is either, but I'll print it Console.WriteLine("Unknown GUID: " + BinaryReaderHelper.ReadUnicodeString(reader, reader.ReadInt32())); + if (type == 0xe) + { + // 8 padding bytes + reader.ReadBytes(8); + } + // Loop through every file in the index, and print info about it - for (int i = 0; i < numFiles;i++) + for (int i = 0; i < numFiles; i++) { string fileName = BinaryReaderHelper.ReadUnicodeString(reader, reader.ReadInt32()); @@ -55,8 +67,10 @@ static void Main(string[] args) // Unknown value, surrounded by quotes for some reason string UnknownValue = BinaryReaderHelper.ReadUnicodeString(reader, reader.ReadInt32()); + byte containerNum = reader.ReadByte(); + // Unknown, will add later if it is important - reader.ReadBytes(5); + reader.ReadBytes(4); // The guid folder that the files reside in byte[] guid1 = reader.ReadBytes(4); @@ -73,29 +87,93 @@ static void Main(string[] args) // holy unwieldy code batman...gotta condense this sometime // TODO: condense this - Console.WriteLine(fileName+" | "+UnknownValue+" | "+BitConverter.ToString(guid1).Replace("-", string.Empty) + "-"+ BitConverter.ToString(guid2).Replace("-", string.Empty) + "-"+ BitConverter.ToString(guid3).Replace("-", string.Empty) + "-"+ BitConverter.ToString(guid4).Replace("-", string.Empty) + "-"+ BitConverter.ToString(guid5).Replace("-", string.Empty)); - + string guid = BitConverter.ToString(guid1).Replace("-", string.Empty) + "-" + BitConverter.ToString(guid2).Replace("-", string.Empty) + "-" + BitConverter.ToString(guid3).Replace("-", string.Empty) + "-" + BitConverter.ToString(guid4).Replace("-", string.Empty) + "-" + BitConverter.ToString(guid5).Replace("-", string.Empty); + + Console.WriteLine(fileName + " | " + UnknownValue + " | " + containerNum + " | " + guid); + + // Go through every sub files + try + { + if (type == 0xe) // (1 file = a block lenght 160) + { + string subContainerName = Path.Combine(guid.Replace("-", string.Empty).ToUpper(), "container." + containerNum); + + // Open a filestream with the user selected file + FileStream subFile = new FileStream(Path.Combine(Path.GetDirectoryName(args[0]), subContainerName), FileMode.Open); + + // Create a binary reader that will be used to read the file + BinaryReader subReader = new BinaryReader(subFile); + + // Grab the type, currently the only supported type is 0xD + int subType = subReader.ReadInt32(); + + // Throw generic exception + if (subType != 0x04) + { + throw new Exception(); + } + + int subNumFiles = subReader.ReadInt32(); + + for (int y = 0; y < subNumFiles; y++) + { + string subfileName = BinaryReaderHelper.ReadUnicodeString(subReader); + + // Ignore all the white space of the block + while (subReader.ReadByte() == 0x0) { } + + // Go back to a position after reading a non-empty byte + subReader.BaseStream.Position--; + + // The sub guid folder that the files reside in + byte[] subGuid1 = subReader.ReadBytes(4); + Array.Reverse(subGuid1); + byte[] subGuid2 = subReader.ReadBytes(2); + Array.Reverse(subGuid2); + byte[] subGuid3 = subReader.ReadBytes(2); + Array.Reverse(subGuid3); + byte[] subGuid4 = subReader.ReadBytes(2); + byte[] subGuid5 = subReader.ReadBytes(6); + + // The second sub guid folder that the files reside in + byte[] subGuid6 = subReader.ReadBytes(4); + Array.Reverse(subGuid6); + byte[] subGuid7 = subReader.ReadBytes(2); + Array.Reverse(subGuid7); + byte[] subGuid8 = subReader.ReadBytes(2); + Array.Reverse(subGuid8); + byte[] subGuid9 = subReader.ReadBytes(2); + byte[] subGuid10 = subReader.ReadBytes(6); + + string subGuid = BitConverter.ToString(subGuid1).Replace("-", string.Empty) + "-" + BitConverter.ToString(subGuid2).Replace("-", string.Empty) + "-" + BitConverter.ToString(subGuid3).Replace("-", string.Empty) + "-" + BitConverter.ToString(subGuid4).Replace("-", string.Empty) + "-" + BitConverter.ToString(subGuid5).Replace("-", string.Empty); + // The second guid is the same + string subSecondGuid = BitConverter.ToString(subGuid6).Replace("-", string.Empty) + "-" + BitConverter.ToString(subGuid7).Replace("-", string.Empty) + "-" + BitConverter.ToString(subGuid8).Replace("-", string.Empty) + "-" + BitConverter.ToString(subGuid9).Replace("-", string.Empty) + "-" + BitConverter.ToString(subGuid10).Replace("-", string.Empty); + + Console.WriteLine("\t" + subfileName + " | " + subGuid); + } + + subReader.Dispose(); + subFile.Dispose(); + } + } + catch + { + Console.WriteLine("This sub type is not supported yet."); + } } - return; - - } catch (FileNotFoundException) { Console.WriteLine("File not found!"); - return; } catch (UnauthorizedAccessException) { Console.WriteLine("File could not be accessed!"); - return; } catch (Exception) { Console.WriteLine("This type is not supported yet."); - return; } - return; } } } From c696e2cc8bcfcd572a129c0e30a7954c4f135964 Mon Sep 17 00:00:00 2001 From: Tom60chat Date: Mon, 12 Jul 2021 00:15:35 +0200 Subject: [PATCH 2/3] Update Program.cs --- ContainerReader/Program.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ContainerReader/Program.cs b/ContainerReader/Program.cs index 013b241..f3ceb02 100644 --- a/ContainerReader/Program.cs +++ b/ContainerReader/Program.cs @@ -61,8 +61,7 @@ static void Main(string[] args) { string fileName = BinaryReaderHelper.ReadUnicodeString(reader, reader.ReadInt32()); - // 4 padding bytes - reader.ReadBytes(4); + string secondName = BinaryReaderHelper.ReadUnicodeString(reader, reader.ReadInt32()); // Unknown value, surrounded by quotes for some reason string UnknownValue = BinaryReaderHelper.ReadUnicodeString(reader, reader.ReadInt32()); From 7e87c8cf55e47fd4dbb827a46fa92b0b3f10796f Mon Sep 17 00:00:00 2001 From: David Date: Sat, 17 Jul 2021 15:07:57 -0700 Subject: [PATCH 3/3] Adjustment to type 14 sub container --- ContainerReader/Program.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/ContainerReader/Program.cs b/ContainerReader/Program.cs index f3ceb02..4902c12 100644 --- a/ContainerReader/Program.cs +++ b/ContainerReader/Program.cs @@ -11,7 +11,7 @@ class Program { static void Main(string[] args) { - if(args.Length != 1) + if (args.Length != 1) { Console.WriteLine("ContainerReader\nA program that prints infomation about Windows Containers.index files, used to store metadata (such as the package family name, guid, and filename) about configuration/save game files for UWP apps and games.\nContainer \"filenames\" are actually directories, as they can have more than one file inside of them.\nUsage: ContainerReader containers.index\nNOTE: Doesn't, at the current time, handle all forms of containers.index. Will add support, but most are supported."); return; @@ -116,13 +116,8 @@ static void Main(string[] args) for (int y = 0; y < subNumFiles; y++) { - string subfileName = BinaryReaderHelper.ReadUnicodeString(subReader); - - // Ignore all the white space of the block - while (subReader.ReadByte() == 0x0) { } - - // Go back to a position after reading a non-empty byte - subReader.BaseStream.Position--; + // subFileName has a fixed length + string subfileName = BinaryReaderHelper.ReadUnicodeString(subReader, 0x40); // The sub guid folder that the files reside in byte[] subGuid1 = subReader.ReadBytes(4); @@ -175,4 +170,4 @@ static void Main(string[] args) } } } -} +} \ No newline at end of file