Skip to content

Commit 4e2165c

Browse files
committed
Added ability to decode embedded files.
1 parent 825f269 commit 4e2165c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

labtech_decode_scriptxml/Program.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,42 @@ static int Main(string[] args)
170170
scriptDataParent.ReplaceChild(scriptDecodedNode, scriptData[0]);
171171
licenseDataParent.ReplaceChild(licenseDecodedNode, licenseData[0]);
172172

173+
/* Find the File nodes */
174+
XmlNodeList filesNodes = inputXMLdoc.SelectNodes("LabTech_Expansion/PackedScript/File");
175+
176+
/* Loop through the File nodes */
177+
foreach (XmlNode fileNode in filesNodes)
178+
{
179+
/* Don't touch invalid or empty File nodes */
180+
if (!string.IsNullOrEmpty(fileNode.Attributes["Bytes"].Value) && !string.IsNullOrEmpty(fileNode.Attributes["Name"].Value))
181+
{
182+
/* Convert the Base 64 string to bytes */
183+
byte[] filebytes = Convert.FromBase64String(fileNode.Attributes["Bytes"].Value);
184+
185+
/* Create the directory path if it doesn't exist */
186+
if (!Directory.Exists(Path.GetDirectoryName(fileNode.Attributes["Name"].Value.Replace(@"L:\", @"C:\"))))
187+
{
188+
Directory.CreateDirectory(Path.GetDirectoryName(fileNode.Attributes["Name"].Value.Replace(@"L:\", @"C:\")));
189+
}
190+
191+
/* If we're overwriting, then overwrite the existing files in the path */
192+
if (argOverwrite && File.Exists(fileNode.Attributes["Name"].Value.Replace(@"L:\", @"C:\")))
193+
{
194+
File.Delete(fileNode.Attributes["Name"].Value.Replace(@"L:\", @"C:\"));
195+
}
196+
197+
/* Create a filestream */
198+
FileStream fs = new FileStream(fileNode.Attributes["Name"].Value.Replace(@"L:\",@"C:\"),
199+
FileMode.CreateNew,
200+
FileAccess.Write,
201+
FileShare.None);
202+
203+
/* Write the bytes to disk and close the file */
204+
fs.Write(filebytes, 0, filebytes.Length);
205+
fs.Close();
206+
}
207+
}
208+
173209
/* Create a new XMLdoc for output by copying the modified inputXML */
174210
XmlDocument outputXMLdoc = new XmlDocument();
175211
outputXMLdoc = inputXMLdoc;

0 commit comments

Comments
 (0)