Skip to content

Commit

Permalink
Fixed extraction failure of some installers with data files
Browse files Browse the repository at this point in the history
  • Loading branch information
Bioruebe committed Jan 4, 2021
1 parent 117e661 commit 1edecbe
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 28 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
@@ -1,3 +1,6 @@
2.1.2
Fixed extraction failure of some installers with data files

2.1.1
Fixed version detection for some installers
Updated BioLib to 2.0.0
Expand Down
44 changes: 24 additions & 20 deletions cicdec/Program.cs
Expand Up @@ -11,7 +11,7 @@

namespace cicdec {
class Program {
private const string VERSION = "2.1.1";
private const string VERSION = "2.1.2";
private const string PROMPT_ID = "cicdec_overwrite";

private const int SEARCH_BUFFER_SIZE = 1024 * 1024;
Expand Down Expand Up @@ -94,26 +94,28 @@ class Program {

if (fileListStream == null) Bio.Error("File list could not be read. Please send a bug report if you want the file to be supported in a future version.", Bio.EXITCODE.NOT_SUPPORTED);

if (dataBlockStartPosition > -1) {
ParseFileList(fileListStream, inputStreamLength);
ExtractFiles(inputStream, binaryReader);
}
else {
// Install Creator supports external data files, instead of integrating
// the files into the executable. This actually means the data block is
// saved as a separate file, which we just need to read.
var dataFilePath = Path.Combine(Path.GetDirectoryName(inputFile), Path.GetFileNameWithoutExtension(inputFile) + ".D01");
if (!File.Exists(dataFilePath)) Bio.Error("Could not find data block in installer and there is no external data file.", Bio.EXITCODE.RUNTIME_ERROR);

// Install Creator supports external data files, instead of integrating
// the files into the executable. This actually means the data block is
// saved as a separate file, which we just need to read.
var dataFilePath = Path.Combine(Path.GetDirectoryName(inputFile), Path.GetFileNameWithoutExtension(inputFile) + ".D01");
if (File.Exists(dataFilePath)) {
Bio.Debug("External data file found");
using (var dataFileStream = File.OpenRead(dataFilePath)) {
ParseFileList(fileListStream, dataFileStream.Length);
using (var dataFileBinaryReader = new BinaryReader(dataFileStream)) {
dataBlockStartPosition = 0;
ExtractFiles(dataFileStream, dataFileBinaryReader);
using (var dataFileStream = File.OpenRead(dataFilePath))
using (var offsetStream = new OffsetStream(dataFileStream, 4)) // Data files seem to have a 4 byte header
using (var concatenatedStream = inputStream.Concatenate(offsetStream)) {
ParseFileList(fileListStream, concatenatedStream.Length);
using (var concatenatedStreamBinaryReader = new BinaryReader(concatenatedStream)) {
ExtractFiles(concatenatedStream, concatenatedStreamBinaryReader);
}
}
}
else if (dataBlockStartPosition < 0) {
Bio.Error("Could not find data block in installer and there is no external data file. The installer is likely corrupt.", Bio.EXITCODE.RUNTIME_ERROR);
}
else {
ParseFileList(fileListStream, inputStreamLength);
ExtractFiles(inputStream, binaryReader);
}

if (failedExtractions > 0) {
if (failedExtractions == filesInfos.Count) Bio.Error("Extraction failed. The installer is either encrypted or a version, which is currently not supported.", Bio.EXITCODE.NOT_SUPPORTED);
Expand Down Expand Up @@ -283,16 +285,16 @@ class Program {
}

static bool SaveToFile(Stream stream, string fileName, FileInfo fileInfo = null) {
if (simulate) return true;

if (stream == null) {
Bio.Warn("Failed to save stream to file. Stream is null");
return false;
}

if (simulate) return true;

stream.MoveToStart();
var filePath = Path.Combine(outputDirectory, fileName);
//Bio.Cout("Saving decompressed block to " + outputFilePath);
//Bio.Cout("Saving decompressed block to " + filePath);

try {
if (!stream.WriteToFile(filePath, PROMPT_ID)) return true;
Expand Down Expand Up @@ -448,9 +450,11 @@ class Program {

for (var i = 0; i < filesInfos.Count; i++) {
var fileInfo = filesInfos[i];
//Bio.Tout(fileInfo, Bio.LOG_SEVERITY.DEBUG);
Bio.Debug(fileInfo);
inputStream.Position = dataBlockStartPosition + fileInfo.offset + 4;
Bio.Cout(string.Format("{0}/{1}\t{2}", i + 1, filesInfos.Count, fileInfo.path));
//Bio.Cout(inputStream);

// Empty files
if (fileInfo.uncompressedSize == 0) {
Expand Down
4 changes: 2 additions & 2 deletions cicdec/Properties/AssemblyInfo.cs
Expand Up @@ -33,6 +33,6 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.1.0.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: AssemblyVersion("2.1.2.0")]
[assembly: AssemblyFileVersion("2.1.2.0")]
[assembly: NeutralResourcesLanguage("en")]
8 changes: 4 additions & 4 deletions cicdec/cicdec.csproj
Expand Up @@ -36,11 +36,11 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Bio.cs, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Bioruebe.BioLib.2.0.0\lib\net40\Bio.cs.dll</HintPath>
<Reference Include="Bio.cs, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Bioruebe.BioLib.2.1.0\lib\net45\Bio.cs.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.SharpZipLib, Version=1.2.0.246, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<HintPath>..\packages\SharpZipLib.1.2.0\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath>
<Reference Include="ICSharpCode.SharpZipLib, Version=1.3.1.9, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<HintPath>..\packages\SharpZipLib.1.3.1\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
4 changes: 2 additions & 2 deletions cicdec/packages.config
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Bioruebe.BioLib" version="2.0.0" targetFramework="net40" />
<package id="SharpZipLib" version="1.2.0" targetFramework="net45" />
<package id="Bioruebe.BioLib" version="2.1.0" targetFramework="net45" />
<package id="SharpZipLib" version="1.3.1" targetFramework="net45" />
</packages>

0 comments on commit 1edecbe

Please sign in to comment.