C# NUnrar library (extracting password protected rar files without password)

早过忘川 提交于 2019-12-02 02:01:35

I'm the author of nunrar and https://sharpcompress.codeplex.com/

I am making decryption of password protected rar archives my next item to do as I thought I had already done it (zip files blurred my memory).

As another comment said, I am always looking for help but hopefully I'll get this done soon.

Игорь Орлов

(End of Year 2018.) Solution for unpacking RAR (4 or 5 format) archive with Password: Install Nuget Packages 7z.Libs (https://www.nuget.org/packages/7z.Libs/) and Squid-Box.SevenZipSharp (https://www.nuget.org/packages/Squid-Box.SevenZipSharp/). Using this code: (edit: error correction)

        public void Unpack()
        {
            var rawBytes = File.ReadAllBytes(".\\Some.rar");

            using (var stream = new MemoryStream(rawBytes, true))
            {
                // Toggle between the x86 and x64 bit dll
                var path = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Environment.Is64BitProcess ? "x64" : "x86", "7z.dll");
                SevenZip.SevenZipBase.SetLibraryPath(path);

                using (var outMemStream = File.Create(".\\SomeSingleFile.txt"))
                {
                    var extractor = new SevenZipExtractor(stream, "passwordXXX");
                    var entry = extractor.ArchiveFileData.Single(info => false == info.IsDirectory);    
                    extractor.ExtractFile(entry.Index, outMemStream);                        
                }
            }
        }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!