SevenZipSharp
SevenZipSharp copied to clipboard
Unable to extract a 7z SFX exe archive from memory
I have been working with this for an updater for my mod manager and have noticed a few things.
- The SFX signature detection size is too small at just 256KB. While this will work for some apps, in mine for example, I install an icon, which makes my SFX header larger than 256KB. I set mine to 1MB and I can find a 7zip SFX. This is at the top of File Checker.
- If I download an exe to memory for this SFX, and then try to extract it from a memorystream (using new SevenZipExtractor(memorystream)), the Check() method is executed because it thinks it's an executable. This method seems to be designed for file-based extraction as it closes the archive stream, which is my memory stream. Thus, when I try to actually extract the files, it dies because the memory stream was closed. This is part of SevenZipExtractor.cs's Check() method. I am not sure how to work around this unless I check if it's a memory based stream (vs a filestream).
finally
{
if (_archive != null)
{
_archive.Close();
}
((InStreamWrapper)_archiveStream).Dispose(); <-- This disposes the input stream.
_archiveStream = null;
_opened = false;
}
return true;
In my app (I have SevenZipSharp source) I changed the GetArchiveStream call in Check() to see if it's an emulationstreamproxy, and then checked if that source is a memorystream - if it is, don't close the stream. I will test this implementation to see if it's an working solution for other archive types. I try to get the test framework up and running and also add cases to test against memory-loading and extraction.