├── lib └── codecs │ ├── core │ ├── Windows │ │ ├── Menu.h │ │ ├── initguid.cpp │ │ ├── Synchronization-win.cpp │ │ ├── System.h │ │ ├── Shell.h │ │ ├── CommonDialog.h │ │ ├── StdAfx.h │ │ ├── Defs.h │ │ ├── PropVariantConversions.h │ │ ├── Clipboard.h │ │ ├── Time.h │ │ ├── ResourceString.h │ │ ├── FileName.h │ │ ├── Handle.h │ │ ├── Error.h │ │ ├── DLL.h │ │ ├── COM.cpp │ │ ├── Window.h │ │ ├── NtCheck.h │ │ ├── PropVariantUtils.h │ │ ├── FileName.cpp │ │ ├── Thread.h │ │ ├── COM.h │ │ └── System-win.cpp │ ├── myWindows │ │ ├── initguid.h │ │ ├── myGetTickCount.cpp │ │ ├── myAddExeFlag.cpp │ │ ├── myPrivate.h │ │ └── config.h │ ├── Codecs │ │ ├── Archive │ │ │ ├── 7z │ │ │ │ ├── 7zCompressionMode.cpp │ │ │ │ ├── 7zHeader.cpp │ │ │ │ ├── 7zProperties.h │ │ │ │ ├── 7zRegister.cpp │ │ │ │ ├── 7zSpecStream.cpp │ │ │ │ ├── 7zSpecStream.h │ │ │ │ ├── 7zCompressionMode.h │ │ │ │ ├── 7zEncode.h │ │ │ │ ├── 7zFolderInStream.h │ │ │ │ ├── 7zFolderOutStream.h │ │ │ │ ├── 7zDecode.h │ │ │ │ └── 7zHeader.h │ │ │ ├── Common │ │ │ │ ├── FindSignature.h │ │ │ │ ├── CrossThreadProgress.cpp │ │ │ │ ├── OutStreamWithCRC.cpp │ │ │ │ ├── OutStreamWithSha1.cpp │ │ │ │ ├── DummyOutStream.cpp │ │ │ │ ├── ItemNameUtils.h │ │ │ │ ├── DummyOutStream.h │ │ │ │ ├── ParseProperties.h │ │ │ │ ├── CrossThreadProgress.h │ │ │ │ ├── OutStreamWithCRC.h │ │ │ │ ├── OutStreamWithSha1.h │ │ │ │ ├── InStreamWithCRC.cpp │ │ │ │ ├── ItemNameUtils.cpp │ │ │ │ └── InStreamWithCRC.h │ │ │ ├── Chm │ │ │ │ ├── ChmRegister.cpp │ │ │ │ ├── ChmHeader.cpp │ │ │ │ ├── ChmHandler.h │ │ │ │ └── ChmHeader.h │ │ │ ├── Cab │ │ │ │ ├── CabRegister.cpp │ │ │ │ ├── CabHeader.cpp │ │ │ │ ├── CabHandler.h │ │ │ │ ├── CabHeader.h │ │ │ │ ├── CabBlockInStream.h │ │ │ │ └── CabItem.h │ │ │ ├── Tar │ │ │ │ ├── TarIn.h │ │ │ │ ├── TarRegister.cpp │ │ │ │ ├── TarOut.h │ │ │ │ ├── TarUpdate.h │ │ │ │ ├── TarHeader.cpp │ │ │ │ ├── TarHandler.h │ │ │ │ └── TarItem.h │ │ │ ├── Rar │ │ │ │ ├── RarRegister.cpp │ │ │ │ ├── RarHeader.cpp │ │ │ │ ├── RarVolumeInStream.h │ │ │ │ ├── RarItem.cpp │ │ │ │ └── RarHandler.h │ │ │ ├── Nsis │ │ │ │ ├── NsisRegister.cpp │ │ │ │ ├── NsisHandler.h │ │ │ │ └── NsisDecode.h │ │ │ ├── Zip │ │ │ │ ├── ZipRegister.cpp │ │ │ │ ├── ZipHeader.cpp │ │ │ │ ├── ZipCompressionMode.h │ │ │ │ ├── ZipItemEx.h │ │ │ │ ├── ZipUpdate.h │ │ │ │ ├── ZipAddCommon.h │ │ │ │ └── ZipOut.h │ │ │ └── DeflateProps.h │ │ ├── Common │ │ │ ├── MethodId.h │ │ │ ├── FilePathAutoRename.h │ │ │ ├── StreamUtils.h │ │ │ ├── VirtThread.h │ │ │ ├── MethodId.cpp │ │ │ ├── OffsetStream.h │ │ │ ├── LockedStream.cpp │ │ │ ├── ProgressUtils.h │ │ │ ├── RegisterArc.h │ │ │ ├── MethodProps.h │ │ │ ├── LockedStream.h │ │ │ ├── VirtThread.cpp │ │ │ ├── OffsetStream.cpp │ │ │ ├── RegisterCodec.h │ │ │ ├── ProgressUtils.cpp │ │ │ ├── InOutTempBuffer.h │ │ │ ├── ProgressMt.h │ │ │ ├── ProgressMt.cpp │ │ │ ├── FilePathAutoRename.cpp │ │ │ ├── OutBuffer.h │ │ │ ├── StreamUtils.cpp │ │ │ └── InBuffer.cpp │ │ ├── Compress │ │ │ ├── LzOutWindow.cpp │ │ │ ├── BranchMisc.h │ │ │ ├── CopyRegister.cpp │ │ │ ├── BcjCoder.h │ │ │ ├── BcjCoder.cpp │ │ │ ├── BranchCoder.cpp │ │ │ ├── BcjRegister.cpp │ │ │ ├── BitlDecoder.cpp │ │ │ ├── Bcj2Register.cpp │ │ │ ├── LzmaRegister.cpp │ │ │ ├── Lzma2Register.cpp │ │ │ ├── BZip2Crc.cpp │ │ │ ├── BZip2Register.cpp │ │ │ ├── PpmdRegister.cpp │ │ │ ├── RarCodecsRegister.cpp │ │ │ ├── DeflateRegister.cpp │ │ │ ├── Deflate64Register.cpp │ │ │ ├── BZip2Crc.h │ │ │ ├── CopyCoder.h │ │ │ ├── BranchRegister.cpp │ │ │ ├── LzmaEncoder.h │ │ │ ├── ImplodeHuffmanDecoder.h │ │ │ ├── Lzma2Encoder.h │ │ │ ├── ShrinkDecoder.h │ │ │ ├── ZDecoder.h │ │ │ ├── Lzx86Converter.h │ │ │ ├── PpmdEncoder.h │ │ │ ├── BZip2Const.h │ │ │ ├── BitmEncoder.h │ │ │ ├── ZlibDecoder.h │ │ │ ├── ZlibEncoder.h │ │ │ ├── BranchMisc.cpp │ │ │ ├── ArjDecoder2.h │ │ │ ├── BranchCoder.h │ │ │ ├── LzOutWindow.h │ │ │ ├── BitlEncoder.h │ │ │ ├── CopyCoder.cpp │ │ │ ├── ImplodeDecoder.h │ │ │ ├── BitmDecoder.h │ │ │ ├── ZlibEncoder.cpp │ │ │ ├── PpmdZip.h │ │ │ └── ByteSwap.cpp │ │ ├── MyVersion.h │ │ ├── IDecl.h │ │ ├── Crypto │ │ │ ├── RandGen.h │ │ │ ├── 7zAesRegister.cpp │ │ │ ├── Pbkdf2HmacSha1.h │ │ │ ├── MyAes.h │ │ │ ├── ZipStrong.h │ │ │ ├── HmacSha1.h │ │ │ ├── RarAes.h │ │ │ ├── ZipCrypto.h │ │ │ ├── MyAes.cpp │ │ │ ├── Rar20Crypto.h │ │ │ └── Sha1.h │ │ ├── IPassword.h │ │ ├── IProgress.h │ │ ├── PropID.h │ │ └── IStream.h │ ├── Common │ │ ├── CRC.cpp │ │ ├── Types.h │ │ ├── MyUnknown.h │ │ ├── NewHandler.h │ │ ├── ListFileUtils.h │ │ ├── MyException.h │ │ ├── UTFConvert.h │ │ ├── ComTry.h │ │ ├── Defs.h │ │ ├── StringToInt.h │ │ ├── Lang.h │ │ ├── TextConfig.h │ │ ├── MyMap.h │ │ ├── MyInitGuid.h │ │ ├── IntToString.h │ │ ├── AutoPtr.h │ │ ├── MyXml.h │ │ ├── C_FileIO.h │ │ ├── MyGuidDef.h │ │ ├── DynamicBuffer.h │ │ ├── CommandLineParser.h │ │ ├── IntToString.cpp │ │ ├── ListFileUtils.cpp │ │ └── StringToInt.cpp │ └── include_windows │ │ └── basetyps.h │ └── rtl │ ├── 7zVersion.h │ ├── Sort.h │ ├── RotateDefs.h │ ├── Delta.h │ ├── XzEnc.h │ ├── Alloc.h │ ├── Sha256.h │ ├── HuffEnc.h │ ├── 7zCrc.h │ ├── XzCrc64.h │ ├── BwtSort.h │ ├── 7zBuf.h │ ├── XzCrc64.c │ ├── 7zBuf2.c │ ├── 7zCrcOpt.c │ ├── 7zCrcT8.c │ ├── LzmaUtil │ ├── Lzma86Dec.h │ └── Lzma86Dec.c │ ├── Aes.h │ └── Delta.c ├── .gitignore ├── README ├── src └── libxsse │ └── codecs │ └── res │ └── resource.h └── libcodecs.sln /lib/codecs/core/Windows/Menu.h: -------------------------------------------------------------------------------- 1 | 2 | /* TODO */ 3 | 4 | 5 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/initguid.cpp: -------------------------------------------------------------------------------- 1 | #define INITGUID 2 | #include 3 | -------------------------------------------------------------------------------- /lib/codecs/core/myWindows/initguid.h: -------------------------------------------------------------------------------- 1 | // initguid.h 2 | 3 | #include "Common/MyInitGuid.h" 4 | 5 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/7z/7zCompressionMode.cpp: -------------------------------------------------------------------------------- 1 | // CompressionMethod.cpp 2 | 3 | #include "StdAfx.h" 4 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/CRC.cpp: -------------------------------------------------------------------------------- 1 | // Common/CRC.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include 6 | 7 | struct CCRCTableInit { CCRCTableInit() { CrcGenerateTable(); } } g_CRCTableInit; 8 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/Types.h: -------------------------------------------------------------------------------- 1 | // Common/Types.h 2 | 3 | #ifndef __COMMON_TYPES_H 4 | #define __COMMON_TYPES_H 5 | 6 | #include 7 | 8 | typedef int HRes; 9 | 10 | #endif 11 | 12 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/MethodId.h: -------------------------------------------------------------------------------- 1 | // MethodId.h 2 | 3 | #ifndef __7Z_METHOD_ID_H 4 | #define __7Z_METHOD_ID_H 5 | 6 | #include "../../Common/Types.h" 7 | 8 | typedef UInt64 CMethodId; 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/Synchronization-win.cpp: -------------------------------------------------------------------------------- 1 | // Windows/Synchronization.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "Synchronization.h" 6 | 7 | namespace NWindows { 8 | namespace NSynchronization { 9 | 10 | }} 11 | -------------------------------------------------------------------------------- /lib/codecs/core/myWindows/myGetTickCount.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | 3 | #include 4 | 5 | DWORD WINAPI GetTickCount(VOID) { 6 | return (DWORD)time(0); // FIXME : but only for the seed of the random generator 7 | } 8 | 9 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/MyUnknown.h: -------------------------------------------------------------------------------- 1 | // MyUnknown.h 2 | 3 | #ifndef __MY_UNKNOWN_H 4 | #define __MY_UNKNOWN_H 5 | 6 | #ifdef _WIN32 7 | #include 8 | #include 9 | #else 10 | #include "MyWindows.h" 11 | #endif 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/FilePathAutoRename.h: -------------------------------------------------------------------------------- 1 | // Util/FilePathAutoRename.h 2 | 3 | #ifndef __FILEPATHAUTORENAME_H 4 | #define __FILEPATHAUTORENAME_H 5 | 6 | #include "Common/MyString.h" 7 | 8 | bool AutoRenamePath(UString &fullProcessedPath); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /lib/codecs/rtl/7zVersion.h: -------------------------------------------------------------------------------- 1 | #define MY_VER_MAJOR 9 2 | #define MY_VER_MINOR 20 3 | #define MY_VER_BUILD 0 4 | #define MY_VERSION "9.20" 5 | #define MY_DATE "2010-11-18" 6 | #define MY_COPYRIGHT ": Igor Pavlov : Public domain" 7 | #define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " : " MY_DATE 8 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/LzOutWindow.cpp: -------------------------------------------------------------------------------- 1 | // LzOutWindow.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "LzOutWindow.h" 6 | 7 | void CLzOutWindow::Init(bool solid) 8 | { 9 | if (!solid) 10 | COutBuffer::Init(); 11 | #ifdef _NO_EXCEPTIONS 12 | ErrorCode = S_OK; 13 | #endif 14 | } 15 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/NewHandler.h: -------------------------------------------------------------------------------- 1 | // Common/NewHandler.h 2 | 3 | #ifndef __COMMON_NEWHANDLER_H 4 | #define __COMMON_NEWHANDLER_H 5 | 6 | class CNewException {}; 7 | 8 | #ifdef _WIN32 9 | void 10 | #ifdef _MSC_VER 11 | __cdecl 12 | #endif 13 | operator delete(void *p) throw(); 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/System.h: -------------------------------------------------------------------------------- 1 | // Windows/System.h 2 | 3 | #ifndef __WINDOWS_SYSTEM_H 4 | #define __WINDOWS_SYSTEM_H 5 | 6 | #include "../Common/Types.h" 7 | 8 | namespace NWindows { 9 | namespace NSystem { 10 | 11 | UInt32 GetNumberOfProcessors(); 12 | UInt64 GetRamSize(); 13 | 14 | }} 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/ListFileUtils.h: -------------------------------------------------------------------------------- 1 | // Common/ListFileUtils.h 2 | 3 | #ifndef __COMMON_LISTFILEUTILS_H 4 | #define __COMMON_LISTFILEUTILS_H 5 | 6 | #include "MyString.h" 7 | #include "Types.h" 8 | 9 | bool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/MyException.h: -------------------------------------------------------------------------------- 1 | // Common/Exception.h 2 | 3 | #ifndef __COMMON_EXCEPTION_H 4 | #define __COMMON_EXCEPTION_H 5 | 6 | #include "MyWindows.h" 7 | 8 | struct CSystemException 9 | { 10 | HRESULT ErrorCode; 11 | CSystemException(HRESULT errorCode): ErrorCode(errorCode) {} 12 | }; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/UTFConvert.h: -------------------------------------------------------------------------------- 1 | // Common/UTFConvert.h 2 | 3 | #ifndef __COMMON_UTFCONVERT_H 4 | #define __COMMON_UTFCONVERT_H 5 | 6 | #include "MyString.h" 7 | 8 | bool ConvertUTF8ToUnicode(const AString &utfString, UString &resultString); 9 | bool ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/BranchMisc.h: -------------------------------------------------------------------------------- 1 | // BranchMisc.h 2 | 3 | #ifndef __COMPRESS_BRANCH_MISC_H 4 | #define __COMPRESS_BRANCH_MISC_H 5 | 6 | #include "BranchCoder.h" 7 | 8 | MyClassA(BC_ARM, 0x05, 1) 9 | MyClassA(BC_ARMT, 0x07, 1) 10 | MyClassA(BC_PPC, 0x02, 5) 11 | MyClassA(BC_SPARC, 0x08, 5) 12 | MyClassA(BC_IA64, 0x04, 1) 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Common/FindSignature.h: -------------------------------------------------------------------------------- 1 | // FindSignature.h 2 | 3 | #ifndef __FINDSIGNATURE_H 4 | #define __FINDSIGNATURE_H 5 | 6 | #include "../../IStream.h" 7 | 8 | HRESULT FindSignatureInStream(ISequentialInStream *stream, 9 | const Byte *signature, unsigned signatureSize, 10 | const UInt64 *limit, UInt64 &resPos); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.in 3 | build/ 4 | aclocal.m4 5 | autom4te.cache/ 6 | m4/ 7 | *.o 8 | *.a 9 | *.lo 10 | *.la 11 | *.dll 12 | *.map 13 | config.log 14 | config.status 15 | libtool 16 | .deps/ 17 | .libs/ 18 | Makefile 19 | *.suo 20 | *.ncb 21 | *.user 22 | Debug/ 23 | Release/ 24 | x64/ 25 | GPATH 26 | GRTAGS 27 | GTAGS 28 | GSYMS 29 | .DS_Store 30 | *.aps 31 | bin/ 32 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/7z/7zHeader.cpp: -------------------------------------------------------------------------------- 1 | // 7zHeader.cpp 2 | 3 | #include "StdAfx.h" 4 | #include "7zHeader.h" 5 | 6 | namespace NArchive { 7 | namespace N7z { 8 | 9 | Byte kSignature[kSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; 10 | #ifdef _7Z_VOL 11 | Byte kFinishSignature[kSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C + 1}; 12 | #endif 13 | 14 | }} 15 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Chm/ChmRegister.cpp: -------------------------------------------------------------------------------- 1 | // ChmRegister.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../../Common/RegisterArc.h" 6 | 7 | #include "ChmHandler.h" 8 | static IInArchive *CreateArc() { return new NArchive::NChm::CHandler; } 9 | 10 | static CArcInfo g_ArcInfo = 11 | { ".chm", { 'I', 'T', 'S', 'F' }, 4, CreateArc, 0 }; 12 | 13 | REGISTER_ARC(chm) 14 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Cab/CabRegister.cpp: -------------------------------------------------------------------------------- 1 | // CabRegister.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../../Common/RegisterArc.h" 6 | 7 | #include "CabHandler.h" 8 | static IInArchive *CreateArc() { return new NArchive::NCab::CHandler; } 9 | 10 | static CArcInfo g_ArcInfo = 11 | { ".cab", { 0x4D, 0x53, 0x43, 0x46 }, 4, CreateArc, 0 }; 12 | 13 | REGISTER_ARC(cab) 14 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Tar/TarIn.h: -------------------------------------------------------------------------------- 1 | // TarIn.h 2 | 3 | #ifndef __ARCHIVE_TAR_IN_H 4 | #define __ARCHIVE_TAR_IN_H 5 | 6 | #include "../../IStream.h" 7 | 8 | #include "TarItem.h" 9 | 10 | namespace NArchive { 11 | namespace NTar { 12 | 13 | HRESULT ReadItem(ISequentialInStream *stream, bool &filled, CItemEx &itemInfo, AString &error); 14 | 15 | }} 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Cab/CabHeader.cpp: -------------------------------------------------------------------------------- 1 | // CabHeader.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "CabHeader.h" 6 | 7 | namespace NArchive { 8 | namespace NCab { 9 | namespace NHeader { 10 | 11 | Byte kMarker[kMarkerSize] = {'M', 'S', 'C', 'F', 0, 0, 0, 0 }; 12 | 13 | // struct CSignatureInitializer { CSignatureInitializer() { kMarker[0]--; }; } g_SignatureInitializer; 14 | 15 | }}} 16 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Common/CrossThreadProgress.cpp: -------------------------------------------------------------------------------- 1 | // CrossThreadProgress.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "CrossThreadProgress.h" 6 | 7 | STDMETHODIMP CCrossThreadProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) 8 | { 9 | InSize = inSize; 10 | OutSize = outSize; 11 | ProgressEvent.Set(); 12 | WaitEvent.Lock(); 13 | return Result; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Rar/RarRegister.cpp: -------------------------------------------------------------------------------- 1 | // RarRegister.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../../Common/RegisterArc.h" 6 | 7 | #include "RarHandler.h" 8 | static IInArchive *CreateArc() { return new NArchive::NRar::CHandler; } 9 | 10 | static CArcInfo g_ArcInfo = 11 | { ".rar", {0x52 , 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00}, 7, CreateArc, 0, }; 12 | 13 | REGISTER_ARC(rar) 14 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/MyVersion.h: -------------------------------------------------------------------------------- 1 | #define MY_VER_MAJOR 9 2 | #define MY_VER_MINOR 20 3 | #define MY_VER_BUILD 0 4 | #define MY_VERSION "9.20" 5 | #define MY_7ZIP_VERSION "7-Zip 9.20" 6 | #define MY_DATE "2010-11-18" 7 | #define MY_COPYRIGHT "Copyright (c) 1999-2010 Igor Pavlov" 8 | #define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " " MY_DATE 9 | 10 | #define P7ZIP_VERSION "9.20" 11 | 12 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Nsis/NsisRegister.cpp: -------------------------------------------------------------------------------- 1 | // NsisRegister.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../../Common/RegisterArc.h" 6 | 7 | #include "NsisHandler.h" 8 | static IInArchive *CreateArc() { return new NArchive::NNsis::CHandler; } 9 | 10 | static CArcInfo g_ArcInfo = 11 | { ".nsis", NSIS_SIGNATURE, NArchive::NNsis::kSignatureSize, CreateArc, 0 }; 12 | 13 | REGISTER_ARC(nsis) 14 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/CopyRegister.cpp: -------------------------------------------------------------------------------- 1 | // CopyRegister.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../Common/RegisterCodec.h" 6 | 7 | #include "CopyCoder.h" 8 | 9 | static void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::CCopyCoder); } 10 | 11 | static CCodecInfo g_CodecInfo = 12 | { CreateCodec, CreateCodec, 0x00, L"Copy", 1, false }; 13 | 14 | REGISTER_CODEC(Copy) 15 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/7z/7zProperties.h: -------------------------------------------------------------------------------- 1 | // 7zProperties.h 2 | 3 | #ifndef __7Z_PROPERTIES_H 4 | #define __7Z_PROPERTIES_H 5 | 6 | #include "../../PropID.h" 7 | 8 | namespace NArchive { 9 | namespace N7z { 10 | 11 | enum 12 | { 13 | kpidPackedSize0 = kpidUserDefined, 14 | kpidPackedSize1, 15 | kpidPackedSize2, 16 | kpidPackedSize3, 17 | kpidPackedSize4 18 | }; 19 | 20 | }} 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /lib/codecs/rtl/Sort.h: -------------------------------------------------------------------------------- 1 | /* Sort.h -- Sort functions 2 | 2009-02-07 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_SORT_H 5 | #define __7Z_SORT_H 6 | 7 | #include "Types.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | void HeapSort(UInt32 *p, UInt32 size); 14 | /* void HeapSortRef(UInt32 *p, UInt32 *vals, UInt32 size); */ 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/BcjCoder.h: -------------------------------------------------------------------------------- 1 | // BcjCoder.h 2 | 3 | #ifndef __COMPRESS_BCJ_CODER_H 4 | #define __COMPRESS_BCJ_CODER_H 5 | 6 | #include 7 | 8 | #include "BranchCoder.h" 9 | 10 | struct CBranch86 11 | { 12 | UInt32 _prevMask; 13 | void x86Init() { x86_Convert_Init(_prevMask); } 14 | }; 15 | 16 | MyClassB(BCJ_x86, 0x01, 3, CBranch86 , 17 | virtual void SubInit() { x86Init(); }) 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/BcjCoder.cpp: -------------------------------------------------------------------------------- 1 | // BcjCoder.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "BcjCoder.h" 6 | 7 | UInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size) 8 | { 9 | return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 1); 10 | } 11 | 12 | UInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size) 13 | { 14 | return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 0); 15 | } 16 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/IDecl.h: -------------------------------------------------------------------------------- 1 | // IDecl.h 2 | 3 | #ifndef __IDECL_H 4 | #define __IDECL_H 5 | 6 | #include "../Common/MyUnknown.h" 7 | 8 | #define DECL_INTERFACE_SUB(i, base, groupId, subId) \ 9 | DEFINE_GUID(IID_ ## i, \ 10 | 0x23170F69, 0x40C1, 0x278A, 0, 0, 0, (groupId), 0, (subId), 0, 0); \ 11 | struct i: public base 12 | 13 | #define DECL_INTERFACE(i, groupId, subId) DECL_INTERFACE_SUB(i, IUnknown, groupId, subId) 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/Shell.h: -------------------------------------------------------------------------------- 1 | // Windows/Shell.h 2 | 3 | #ifndef __WINDOWS_SHELL_H 4 | #define __WINDOWS_SHELL_H 5 | 6 | #include 7 | // #include 8 | 9 | #include "Common/MyString.h" 10 | #include "Windows/Defs.h" 11 | 12 | 13 | namespace NWindows{ 14 | namespace NShell{ 15 | 16 | bool BrowseForFolder(HWND owner, LPCWSTR title, LPCWSTR initialFolder, UString &resultPath); 17 | 18 | }} 19 | 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/CommonDialog.h: -------------------------------------------------------------------------------- 1 | // Windows/CommonDialog.h 2 | 3 | #ifndef __WINDOWS_COMMON_DIALOG_H 4 | #define __WINDOWS_COMMON_DIALOG_H 5 | 6 | #include "Common/MyString.h" 7 | 8 | namespace NWindows{ 9 | 10 | bool MyGetOpenFileName(HWND hwnd, LPCWSTR title, LPCWSTR fullFileName, 11 | LPCWSTR s, UString &resPath 12 | #ifdef UNDER_CE 13 | , bool openFolder = false 14 | #endif 15 | ); 16 | 17 | } 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/BranchCoder.cpp: -------------------------------------------------------------------------------- 1 | // BranchCoder.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "BranchCoder.h" 6 | 7 | STDMETHODIMP CBranchConverter::Init() 8 | { 9 | _bufferPos = 0; 10 | SubInit(); 11 | return S_OK; 12 | } 13 | 14 | STDMETHODIMP_(UInt32) CBranchConverter::Filter(Byte *data, UInt32 size) 15 | { 16 | UInt32 processedSize = SubFilter(data, size); 17 | _bufferPos += processedSize; 18 | return processedSize; 19 | } 20 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Crypto/RandGen.h: -------------------------------------------------------------------------------- 1 | // RandGen.h 2 | 3 | #ifndef __CRYPTO_RAND_GEN_H 4 | #define __CRYPTO_RAND_GEN_H 5 | 6 | #include "Sha1.h" 7 | 8 | class CRandomGenerator 9 | { 10 | Byte _buff[NCrypto::NSha1::kDigestSize]; 11 | bool _needInit; 12 | 13 | void Init(); 14 | public: 15 | CRandomGenerator(): _needInit(true) {}; 16 | void Generate(Byte *data, unsigned size); 17 | }; 18 | 19 | extern CRandomGenerator g_RandomGenerator; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Rar/RarHeader.cpp: -------------------------------------------------------------------------------- 1 | // Archive/Rar/Headers.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "RarHeader.h" 6 | 7 | namespace NArchive{ 8 | namespace NRar{ 9 | namespace NHeader{ 10 | 11 | Byte kMarker[kMarkerSize] = {0x52 + 1, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00}; 12 | 13 | class CMarkerInitializer 14 | { 15 | public: 16 | CMarkerInitializer() { kMarker[0]--; }; 17 | }; 18 | 19 | static CMarkerInitializer markerInitializer; 20 | 21 | }}} 22 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | libcodecs Copyright (C) Huorong Borui (Beijing) Technology Co., Ltd. 2 | ==================================================================== 3 | 4 | libcodecs is part of the "Huorong eXtendible Stream Scan Engine" project copyright by Huorong Borui (Beijing) Technology Co., Ltd. 5 | libcodecs is released under the terms of the GNU Lesser General Public License (LGPL). 6 | 7 | More details about "Huorong eXtendible Stream Scan Engine" project is available at: http://huorong.cn 8 | -------------------------------------------------------------------------------- /lib/codecs/core/include_windows/basetyps.h: -------------------------------------------------------------------------------- 1 | #ifndef _BASETYPS_H 2 | #define _BASETYPS_H 3 | 4 | #ifdef ENV_HAVE_GCCVISIBILITYPATCH 5 | #define DLLEXPORT __attribute__ ((visibility("default"))) 6 | #else 7 | #define DLLEXPORT 8 | #endif 9 | 10 | #ifdef __cplusplus 11 | #define STDAPI extern "C" DLLEXPORT HRESULT 12 | #else 13 | #define STDAPI extern DLLEXPORT HRESULT 14 | #endif /* __cplusplus */ 15 | 16 | typedef GUID IID; 17 | typedef GUID CLSID; 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /src/libxsse/codecs/res/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by libcodecs.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /lib/codecs/rtl/RotateDefs.h: -------------------------------------------------------------------------------- 1 | /* RotateDefs.h -- Rotate functions 2 | 2009-02-07 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __ROTATE_DEFS_H 5 | #define __ROTATE_DEFS_H 6 | 7 | #ifdef _MSC_VER 8 | 9 | #include 10 | #define rotlFixed(x, n) _rotl((x), (n)) 11 | #define rotrFixed(x, n) _rotr((x), (n)) 12 | 13 | #else 14 | 15 | #define rotlFixed(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) 16 | #define rotrFixed(x, n) (((x) >> (n)) | ((x) << (32 - (n)))) 17 | 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/StreamUtils.h: -------------------------------------------------------------------------------- 1 | // StreamUtils.h 2 | 3 | #ifndef __STREAMUTILS_H 4 | #define __STREAMUTILS_H 5 | 6 | #include "../IStream.h" 7 | 8 | HRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *size); 9 | HRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size); 10 | HRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size); 11 | HRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Chm/ChmHeader.cpp: -------------------------------------------------------------------------------- 1 | // Archive/Chm/Header.h 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "ChmHeader.h" 6 | 7 | namespace NArchive{ 8 | namespace NChm{ 9 | namespace NHeader{ 10 | 11 | UInt32 kItsfSignature = 0x46535449 + 1; 12 | UInt32 kItolSignature = 0x4C4F5449 + 1; 13 | static class CSignatureInitializer 14 | { 15 | public: 16 | CSignatureInitializer() 17 | { 18 | kItsfSignature--; 19 | kItolSignature--; 20 | } 21 | }g_SignatureInitializer; 22 | 23 | 24 | }}} 25 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Cab/CabHandler.h: -------------------------------------------------------------------------------- 1 | // CabHandler.h 2 | 3 | #ifndef __CAB_HANDLER_H 4 | #define __CAB_HANDLER_H 5 | 6 | #include "Common/MyCom.h" 7 | #include "../IArchive.h" 8 | #include "CabIn.h" 9 | 10 | namespace NArchive { 11 | namespace NCab { 12 | 13 | class CHandler: 14 | public IInArchive, 15 | public CMyUnknownImp 16 | { 17 | public: 18 | MY_UNKNOWN_IMP1(IInArchive) 19 | 20 | INTERFACE_IInArchive(;) 21 | 22 | private: 23 | CMvDatabaseEx m_Database; 24 | }; 25 | 26 | }} 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/ComTry.h: -------------------------------------------------------------------------------- 1 | // ComTry.h 2 | 3 | #ifndef __COM_TRY_H 4 | #define __COM_TRY_H 5 | 6 | #include "MyWindows.h" 7 | // #include "Exception.h" 8 | // #include "NewHandler.h" 9 | 10 | #define COM_TRY_BEGIN try { 11 | #define COM_TRY_END } catch(const char * s) { throw s ; } \ 12 | catch(...) { return E_OUTOFMEMORY; } 13 | 14 | // catch(const CNewException &) { return E_OUTOFMEMORY; } 15 | // catch(const CSystemException &e) { return e.ErrorCode; } 16 | // catch(...) { return E_FAIL; } 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /lib/codecs/core/myWindows/myAddExeFlag.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #define NEED_NAME_WINDOWS_TO_UNIX 9 | #include "myPrivate.h" 10 | 11 | #include "Common/StringConvert.h" 12 | 13 | void myAddExeFlag(const UString &u_name) 14 | { 15 | AString filename = UnicodeStringToMultiByte(u_name, CP_ACP); // FIXME 16 | const char * name = nameWindowToUnix(filename); 17 | // printf("myAddExeFlag(%s)\n",name); 18 | chmod(name,0700); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /lib/codecs/core/myWindows/myPrivate.h: -------------------------------------------------------------------------------- 1 | 2 | void WINAPI RtlSecondsSince1970ToFileTime( DWORD Seconds, FILETIME * ft ); 3 | 4 | extern "C" int global_use_utf16_conversion; 5 | #ifdef ENV_HAVE_LSTAT 6 | extern "C" int global_use_lstat; 7 | #endif 8 | 9 | const char *my_getlocale(void); 10 | 11 | #ifdef NEED_NAME_WINDOWS_TO_UNIX 12 | static inline const char * nameWindowToUnix(const char * lpFileName) { 13 | if ((lpFileName[0] == 'c') && (lpFileName[1] == ':')) return lpFileName+2; 14 | return lpFileName; 15 | } 16 | #endif 17 | 18 | -------------------------------------------------------------------------------- /lib/codecs/rtl/Delta.h: -------------------------------------------------------------------------------- 1 | /* Delta.h -- Delta converter 2 | 2009-04-15 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __DELTA_H 5 | #define __DELTA_H 6 | 7 | #include "Types.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #define DELTA_STATE_SIZE 256 14 | 15 | void Delta_Init(Byte *state); 16 | void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size); 17 | void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Common/OutStreamWithCRC.cpp: -------------------------------------------------------------------------------- 1 | // OutStreamWithCRC.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "OutStreamWithCRC.h" 6 | 7 | STDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *processedSize) 8 | { 9 | HRESULT result = S_OK; 10 | if (_stream) 11 | result = _stream->Write(data, size, &size); 12 | if (_calculate) 13 | _crc = CrcUpdate(_crc, data, size); 14 | _size += size; 15 | if (processedSize != NULL) 16 | *processedSize = size; 17 | return result; 18 | } 19 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/7z/7zRegister.cpp: -------------------------------------------------------------------------------- 1 | // 7zRegister.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../../Common/RegisterArc.h" 6 | 7 | #include "7zHandler.h" 8 | static IInArchive *CreateArc() { return new NArchive::N7z::CHandler; } 9 | #ifndef EXTRACT_ONLY 10 | static IOutArchive *CreateArcOut() { return new NArchive::N7z::CHandler; } 11 | #else 12 | #define CreateArcOut 0 13 | #endif 14 | 15 | static CArcInfo g_ArcInfo = 16 | { ".7z", {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}, 6, CreateArc, CreateArcOut }; 17 | 18 | REGISTER_ARC(7z) 19 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Common/OutStreamWithSha1.cpp: -------------------------------------------------------------------------------- 1 | // OutStreamWithSha1.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "OutStreamWithSha1.h" 6 | 7 | STDMETHODIMP COutStreamWithSha1::Write(const void *data, UInt32 size, UInt32 *processedSize) 8 | { 9 | HRESULT result = S_OK; 10 | if (_stream) 11 | result = _stream->Write(data, size, &size); 12 | if (_calculate) 13 | _sha.Update((const Byte *)data, size); 14 | _size += size; 15 | if (processedSize != NULL) 16 | *processedSize = size; 17 | return result; 18 | } 19 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Tar/TarRegister.cpp: -------------------------------------------------------------------------------- 1 | // TarRegister.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../../Common/RegisterArc.h" 6 | 7 | #include "TarHandler.h" 8 | static IInArchive *CreateArc() { return new NArchive::NTar::CHandler; } 9 | #ifndef EXTRACT_ONLY 10 | static IOutArchive *CreateArcOut() { return new NArchive::NTar::CHandler; } 11 | #else 12 | #define CreateArcOut 0 13 | #endif 14 | 15 | static CArcInfo g_ArcInfo = 16 | { ".tar", { 'u', 's', 't', 'a', 'r' }, 5, CreateArc, CreateArcOut }; 17 | 18 | REGISTER_ARC(tar) 19 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Zip/ZipRegister.cpp: -------------------------------------------------------------------------------- 1 | // ZipRegister.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../../Common/RegisterArc.h" 6 | 7 | #include "ZipHandler.h" 8 | static IInArchive *CreateArc() { return new NArchive::NZip::CHandler; } 9 | #ifndef EXTRACT_ONLY 10 | static IOutArchive *CreateArcOut() { return new NArchive::NZip::CHandler; } 11 | #else 12 | #define CreateArcOut 0 13 | #endif 14 | 15 | static CArcInfo g_ArcInfo = 16 | { ".zip", { 0x50, 0x4B, 0x03, 0x04 }, 4, CreateArc, CreateArcOut }; 17 | 18 | REGISTER_ARC(zip) 19 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/Defs.h: -------------------------------------------------------------------------------- 1 | // Common/Defs.h 2 | 3 | #ifndef __COMMON_DEFS_H 4 | #define __COMMON_DEFS_H 5 | 6 | template inline T MyMin(T a, T b) 7 | { return a < b ? a : b; } 8 | template inline T MyMax(T a, T b) 9 | { return a > b ? a : b; } 10 | 11 | template inline int MyCompare(T a, T b) 12 | { return a < b ? -1 : (a == b ? 0 : 1); } 13 | 14 | inline int BoolToInt(bool value) 15 | { return (value ? 1: 0); } 16 | 17 | inline bool IntToBool(int value) 18 | { return (value != 0); } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /lib/codecs/rtl/XzEnc.h: -------------------------------------------------------------------------------- 1 | /* XzEnc.h -- Xz Encode 2 | 2009-04-15 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __XZ_ENC_H 5 | #define __XZ_ENC_H 6 | 7 | #include "Lzma2Enc.h" 8 | 9 | #include "Xz.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | SRes Xz_Encode(ISeqOutStream *outStream, ISeqInStream *inStream, 16 | const CLzma2EncProps *lzma2Props, Bool useSubblock, 17 | ICompressProgress *progress); 18 | 19 | SRes Xz_EncodeEmpty(ISeqOutStream *outStream); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/StringToInt.h: -------------------------------------------------------------------------------- 1 | // Common/StringToInt.h 2 | 3 | #ifndef __COMMON_STRINGTOINT_H 4 | #define __COMMON_STRINGTOINT_H 5 | 6 | #include 7 | #include "Types.h" 8 | 9 | UInt64 ConvertStringToUInt64(const char *s, const char **end); 10 | UInt64 ConvertOctStringToUInt64(const char *s, const char **end); 11 | UInt64 ConvertHexStringToUInt64(const char *s, const char **end); 12 | UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end); 13 | 14 | Int64 ConvertStringToInt64(const char *s, const char **end); 15 | 16 | #endif 17 | 18 | 19 | -------------------------------------------------------------------------------- /lib/codecs/rtl/Alloc.h: -------------------------------------------------------------------------------- 1 | /* Alloc.h -- Memory allocation functions 2 | 2009-02-07 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __COMMON_ALLOC_H 5 | #define __COMMON_ALLOC_H 6 | 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | void *MyAlloc(size_t size); 14 | void MyFree(void *address); 15 | 16 | void SetLargePageSize(); 17 | 18 | void *MidAlloc(size_t size); 19 | void MidFree(void *address); 20 | void *BigAlloc(size_t size); 21 | void BigFree(void *address); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /lib/codecs/rtl/Sha256.h: -------------------------------------------------------------------------------- 1 | /* Sha256.h -- SHA-256 Hash 2 | 2010-06-11 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __CRYPTO_SHA256_H 5 | #define __CRYPTO_SHA256_H 6 | 7 | #include "Types.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define SHA256_DIGEST_SIZE 32 12 | 13 | typedef struct 14 | { 15 | UInt32 state[8]; 16 | UInt64 count; 17 | Byte buffer[64]; 18 | } CSha256; 19 | 20 | void Sha256_Init(CSha256 *p); 21 | void Sha256_Update(CSha256 *p, const Byte *data, size_t size); 22 | void Sha256_Final(CSha256 *p, Byte *digest); 23 | 24 | EXTERN_C_END 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/Lang.h: -------------------------------------------------------------------------------- 1 | // Common/Lang.h 2 | 3 | #ifndef __COMMON_LANG_H 4 | #define __COMMON_LANG_H 5 | 6 | #include "MyVector.h" 7 | #include "MyString.h" 8 | #include "Types.h" 9 | 10 | struct CLangPair 11 | { 12 | UInt32 Value; 13 | UString String; 14 | }; 15 | 16 | class CLang 17 | { 18 | CObjectVector _langPairs; 19 | public: 20 | bool Open(LPCWSTR fileName); 21 | void Clear() { _langPairs.Clear(); } 22 | int FindItem(UInt32 value) const; 23 | bool GetMessage(UInt32 value, UString &message) const; 24 | }; 25 | 26 | #endif 27 | 28 | 29 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/StdAfx.h: -------------------------------------------------------------------------------- 1 | // StdAfx.h 2 | 3 | #ifndef __STDAFX_H 4 | #define __STDAFX_H 5 | 6 | #ifdef _WIN32 7 | # include "../Common/MyWindows.h" 8 | # include "../Common/NewHandler.h" 9 | # ifndef ENV_HAVE_WCTYPE_H 10 | # define ENV_HAVE_WCTYPE_H 11 | # endif 12 | # ifndef ENV_HAVE_WCHAR__H 13 | # define ENV_HAVE_WCHAR__H 14 | # endif 15 | # ifndef ENV_HAVE_MBRTOWC 16 | # define ENV_HAVE_MBRTOWC 17 | # endif 18 | # ifndef ENV_HAVE_WCSTOMBS 19 | # define ENV_HAVE_WCSTOMBS 20 | # endif 21 | #else 22 | # include "../myWindows/StdAfx.h" 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Chm/ChmHandler.h: -------------------------------------------------------------------------------- 1 | // ChmHandler.h 2 | 3 | #ifndef __ARCHIVE_CHM_HANDLER_H 4 | #define __ARCHIVE_CHM_HANDLER_H 5 | 6 | #include "Common/MyCom.h" 7 | #include "../IArchive.h" 8 | #include "ChmIn.h" 9 | 10 | namespace NArchive { 11 | namespace NChm { 12 | 13 | class CHandler: 14 | public IInArchive, 15 | public CMyUnknownImp 16 | { 17 | public: 18 | MY_UNKNOWN_IMP1(IInArchive) 19 | 20 | INTERFACE_IInArchive(;) 21 | 22 | private: 23 | CFilesDatabase m_Database; 24 | CMyComPtr m_Stream; 25 | }; 26 | 27 | }} 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/BcjRegister.cpp: -------------------------------------------------------------------------------- 1 | // BcjRegister.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../Common/RegisterCodec.h" 6 | 7 | #include "BcjCoder.h" 8 | 9 | static void *CreateCodec() { return (void *)(ICompressFilter *)(new CBCJ_x86_Decoder()); } 10 | #ifndef EXTRACT_ONLY 11 | static void *CreateCodecOut() { return (void *)(ICompressFilter *)(new CBCJ_x86_Encoder()); } 12 | #else 13 | #define CreateCodecOut 0 14 | #endif 15 | 16 | static CCodecInfo g_CodecInfo = 17 | { CreateCodec, CreateCodecOut, 0x03030103, L"BCJ", 1, true }; 18 | 19 | REGISTER_CODEC(BCJ) 20 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/BitlDecoder.cpp: -------------------------------------------------------------------------------- 1 | // BitlDecoder.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "BitlDecoder.h" 6 | 7 | namespace NBitl { 8 | 9 | Byte kInvertTable[256]; 10 | 11 | struct CInverterTableInitializer 12 | { 13 | CInverterTableInitializer() 14 | { 15 | for (int i = 0; i < 256; i++) 16 | { 17 | int x = ((i & 0x55) << 1) | ((i & 0xAA) >> 1); 18 | x = ((x & 0x33) << 2) | ((x & 0xCC) >> 2); 19 | kInvertTable[i] = (Byte)(((x & 0x0F) << 4) | ((x & 0xF0) >> 4)); 20 | } 21 | } 22 | } g_InverterTableInitializer; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/TextConfig.h: -------------------------------------------------------------------------------- 1 | // Common/TextConfig.h 2 | 3 | #ifndef __COMMON_TEXTCONFIG_H 4 | #define __COMMON_TEXTCONFIG_H 5 | 6 | #include "MyVector.h" 7 | #include "MyString.h" 8 | 9 | struct CTextConfigPair 10 | { 11 | UString ID; 12 | UString String; 13 | }; 14 | 15 | bool GetTextConfig(const AString &text, CObjectVector &pairs); 16 | 17 | int FindTextConfigItem(const CObjectVector &pairs, const UString &id); 18 | UString GetTextConfigValue(const CObjectVector &pairs, const UString &id); 19 | 20 | #endif 21 | 22 | 23 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/Defs.h: -------------------------------------------------------------------------------- 1 | // Windows/Defs.h 2 | 3 | #ifndef __WINDOWS_DEFS_H 4 | #define __WINDOWS_DEFS_H 5 | 6 | #include "../Common/MyWindows.h" 7 | 8 | // #ifdef _WIN32 9 | inline bool LRESULTToBool(LRESULT v) { return (v != FALSE); } 10 | inline bool BOOLToBool(BOOL v) { return (v != FALSE); } 11 | inline BOOL BoolToBOOL(bool v) { return (v ? TRUE: FALSE); } 12 | // #endif 13 | 14 | inline VARIANT_BOOL BoolToVARIANT_BOOL(bool v) { return (v ? VARIANT_TRUE: VARIANT_FALSE); } 15 | inline bool VARIANT_BOOLToBool(VARIANT_BOOL v) { return (v != VARIANT_FALSE); } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/IPassword.h: -------------------------------------------------------------------------------- 1 | // IPassword.h 2 | 3 | #ifndef __IPASSWORD_H 4 | #define __IPASSWORD_H 5 | 6 | #include "../Common/MyUnknown.h" 7 | #include "../Common/Types.h" 8 | 9 | #include "IDecl.h" 10 | 11 | #define PASSWORD_INTERFACE(i, x) DECL_INTERFACE(i, 5, x) 12 | 13 | PASSWORD_INTERFACE(ICryptoGetTextPassword, 0x10) 14 | { 15 | STDMETHOD(CryptoGetTextPassword)(BSTR *password) PURE; 16 | }; 17 | 18 | PASSWORD_INTERFACE(ICryptoGetTextPassword2, 0x11) 19 | { 20 | STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password) PURE; 21 | }; 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/VirtThread.h: -------------------------------------------------------------------------------- 1 | // VirtThread.h 2 | 3 | #ifndef __VIRTTHREAD_H 4 | #define __VIRTTHREAD_H 5 | 6 | #include "../../Windows/Synchronization.h" 7 | #include "../../Windows/Thread.h" 8 | 9 | struct CVirtThread 10 | { 11 | NWindows::NSynchronization::CAutoResetEvent StartEvent; 12 | NWindows::NSynchronization::CAutoResetEvent FinishedEvent; 13 | NWindows::CThread Thread; 14 | bool ExitEvent; 15 | 16 | ~CVirtThread(); 17 | WRes Create(); 18 | void Start(); 19 | void WaitFinish() { FinishedEvent.Lock(); } 20 | virtual void Execute() = 0; 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Crypto/7zAesRegister.cpp: -------------------------------------------------------------------------------- 1 | // 7zAesRegister.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../Common/RegisterCodec.h" 6 | #include "7zAes.h" 7 | 8 | static void *CreateCodec() { return (void *)(ICompressFilter *)(new NCrypto::NSevenZ::CDecoder()); } 9 | #ifndef EXTRACT_ONLY 10 | static void *CreateCodecOut() { return (void *)(ICompressFilter *)(new NCrypto::NSevenZ::CEncoder()); } 11 | #else 12 | #define CreateCodecOut 0 13 | #endif 14 | 15 | static CCodecInfo g_CodecInfo = 16 | { CreateCodec, CreateCodecOut, 0x06F10701, L"7zAES", 1, true }; 17 | 18 | REGISTER_CODEC(7zAES) 19 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/MyMap.h: -------------------------------------------------------------------------------- 1 | // MyMap.h 2 | 3 | #ifndef __COMMON_MYMAP_H 4 | #define __COMMON_MYMAP_H 5 | 6 | #include "MyVector.h" 7 | #include "Types.h" 8 | 9 | class CMap32 10 | { 11 | struct CNode 12 | { 13 | UInt32 Key; 14 | UInt32 Keys[2]; 15 | UInt32 Values[2]; 16 | UInt16 Len; 17 | Byte IsLeaf[2]; 18 | }; 19 | CRecordVector Nodes; 20 | 21 | public: 22 | 23 | void Clear() { Nodes.Clear(); } 24 | bool Find(UInt32 key, UInt32 &valueRes) const; 25 | bool Set(UInt32 key, UInt32 value); // returns true, if there is such key already 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /lib/codecs/rtl/HuffEnc.h: -------------------------------------------------------------------------------- 1 | /* HuffEnc.h -- Huffman encoding 2 | 2009-02-07 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __HUFF_ENC_H 5 | #define __HUFF_ENC_H 6 | 7 | #include "Types.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /* 14 | Conditions: 15 | num <= 1024 = 2 ^ NUM_BITS 16 | Sum(freqs) < 4M = 2 ^ (32 - NUM_BITS) 17 | maxLen <= 16 = kMaxLen 18 | Num_Items(p) >= HUFFMAN_TEMP_SIZE(num) 19 | */ 20 | 21 | void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 num, UInt32 maxLen); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Common/DummyOutStream.cpp: -------------------------------------------------------------------------------- 1 | // DummyOutStream.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "DummyOutStream.h" 6 | 7 | STDMETHODIMP CDummyOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize) 8 | { 9 | UInt32 realProcessedSize; 10 | HRESULT result; 11 | if(!_stream) 12 | { 13 | realProcessedSize = size; 14 | result = S_OK; 15 | } 16 | else 17 | result = _stream->Write(data, size, &realProcessedSize); 18 | _size += realProcessedSize; 19 | if(processedSize != NULL) 20 | *processedSize = realProcessedSize; 21 | return result; 22 | } 23 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/Bcj2Register.cpp: -------------------------------------------------------------------------------- 1 | // Bcj2Register.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../Common/RegisterCodec.h" 6 | 7 | #include "Bcj2Coder.h" 8 | 9 | static void *CreateCodec() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CDecoder()); } 10 | #ifndef EXTRACT_ONLY 11 | static void *CreateCodecOut() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CEncoder()); } 12 | #else 13 | #define CreateCodecOut 0 14 | #endif 15 | 16 | static CCodecInfo g_CodecInfo = 17 | { CreateCodec, CreateCodecOut, 0x0303011B, L"BCJ2", 4, false }; 18 | 19 | REGISTER_CODEC(BCJ2) 20 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/MyInitGuid.h: -------------------------------------------------------------------------------- 1 | // Common/MyInitGuid.h 2 | 3 | #ifndef __COMMON_MY_INITGUID_H 4 | #define __COMMON_MY_INITGUID_H 5 | 6 | #ifdef _WIN32 7 | #ifdef UNDER_CE 8 | #include 9 | #endif 10 | #include 11 | #if defined(UNDER_CE) || defined(__MINGW32__) 12 | DEFINE_GUID(IID_IUnknown, 13 | 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); 14 | #endif 15 | #else 16 | #define INITGUID 17 | #include "MyGuidDef.h" 18 | DEFINE_GUID(IID_IUnknown, 19 | 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/PropVariantConversions.h: -------------------------------------------------------------------------------- 1 | // Windows/PropVariantConversions.h 2 | 3 | #ifndef __PROP_VARIANT_CONVERSIONS_H 4 | #define __PROP_VARIANT_CONVERSIONS_H 5 | 6 | #include "Common/MyString.h" 7 | #include "Common/Types.h" 8 | 9 | bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime = true, bool includeSeconds = true); 10 | UString ConvertFileTimeToString(const FILETIME &ft, bool includeTime = true, bool includeSeconds = true); 11 | UString ConvertPropVariantToString(const PROPVARIANT &prop); 12 | UInt64 ConvertPropVariantToUInt64(const PROPVARIANT &prop); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/Clipboard.h: -------------------------------------------------------------------------------- 1 | // Windows/Clipboard.h 2 | 3 | #ifndef __CLIPBOARD_H 4 | #define __CLIPBOARD_H 5 | 6 | #include "Common/MyString.h" 7 | 8 | namespace NWindows { 9 | 10 | class CClipboard 11 | { 12 | bool m_Open; 13 | public: 14 | CClipboard(): m_Open(false) {}; 15 | ~CClipboard(); 16 | bool Open(HWND wndNewOwner); 17 | bool Close(); 18 | }; 19 | 20 | bool ClipboardIsFormatAvailableHDROP(); 21 | 22 | // bool ClipboardGetFileNames(UStringVector &names); 23 | // bool ClipboardGetTextString(AString &s); 24 | bool ClipboardSetText(HWND owner, const UString &s); 25 | 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/MethodId.cpp: -------------------------------------------------------------------------------- 1 | // MethodId.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "MethodId.h" 6 | #include "../../Common/MyString.h" 7 | 8 | static inline wchar_t GetHex(Byte value) 9 | { 10 | return (wchar_t)((value < 10) ? ('0' + value) : ('A' + (value - 10))); 11 | } 12 | 13 | UString ConvertMethodIdToString(UInt64 id) 14 | { 15 | wchar_t s[32]; 16 | int len = 32; 17 | s[--len] = 0; 18 | do 19 | { 20 | s[--len] = GetHex((Byte)id & 0xF); 21 | id >>= 4; 22 | s[--len] = GetHex((Byte)id & 0xF); 23 | id >>= 4; 24 | } 25 | while (id != 0); 26 | return s + len; 27 | } 28 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/LzmaRegister.cpp: -------------------------------------------------------------------------------- 1 | // LzmaRegister.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../Common/RegisterCodec.h" 6 | 7 | #include "LzmaDecoder.h" 8 | 9 | static void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NLzma::CDecoder); } 10 | #ifndef EXTRACT_ONLY 11 | #include "LzmaEncoder.h" 12 | static void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NLzma::CEncoder); } 13 | #else 14 | #define CreateCodecOut 0 15 | #endif 16 | 17 | static CCodecInfo g_CodecInfo = 18 | { CreateCodec, CreateCodecOut, 0x030101, L"LZMA", 1, false }; 19 | 20 | REGISTER_CODEC(LZMA) 21 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/Lzma2Register.cpp: -------------------------------------------------------------------------------- 1 | // Lzma2Register.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../Common/RegisterCodec.h" 6 | 7 | #include "Lzma2Decoder.h" 8 | 9 | static void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NLzma2::CDecoder); } 10 | #ifndef EXTRACT_ONLY 11 | #include "Lzma2Encoder.h" 12 | static void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NLzma2::CEncoder); } 13 | #else 14 | #define CreateCodecOut 0 15 | #endif 16 | 17 | static CCodecInfo g_CodecInfo = 18 | { CreateCodec, CreateCodecOut, 0x21, L"LZMA2", 1, false }; 19 | 20 | REGISTER_CODEC(LZMA2) 21 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/IntToString.h: -------------------------------------------------------------------------------- 1 | // Common/IntToString.h 2 | 3 | #ifndef __COMMON_INT_TO_STRING_H 4 | #define __COMMON_INT_TO_STRING_H 5 | 6 | #include 7 | #include "Types.h" 8 | 9 | void ConvertUInt64ToString(UInt64 value, char *s, UInt32 base = 10); 10 | void ConvertUInt64ToString(UInt64 value, wchar_t *s); 11 | void ConvertInt64ToString(Int64 value, char *s); 12 | void ConvertInt64ToString(Int64 value, wchar_t *s); 13 | 14 | void ConvertUInt32ToString(UInt32 value, char *s); 15 | void ConvertUInt32ToString(UInt32 value, wchar_t *s); 16 | 17 | void ConvertUInt32ToHexWithZeros(UInt32 value, char *s); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/BZip2Crc.cpp: -------------------------------------------------------------------------------- 1 | // BZip2Crc.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "BZip2Crc.h" 6 | 7 | UInt32 CBZip2Crc::Table[256]; 8 | 9 | static const UInt32 kBZip2CrcPoly = 0x04c11db7; /* AUTODIN II, Ethernet, & FDDI */ 10 | 11 | void CBZip2Crc::InitTable() 12 | { 13 | for (UInt32 i = 0; i < 256; i++) 14 | { 15 | UInt32 r = (i << 24); 16 | for (int j = 8; j > 0; j--) 17 | r = (r & 0x80000000) ? ((r << 1) ^ kBZip2CrcPoly) : (r << 1); 18 | Table[i] = r; 19 | } 20 | } 21 | 22 | class CBZip2CrcTableInit 23 | { 24 | public: 25 | CBZip2CrcTableInit() { CBZip2Crc::InitTable(); } 26 | } g_BZip2CrcTableInit; 27 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/OffsetStream.h: -------------------------------------------------------------------------------- 1 | // OffsetStream.h 2 | 3 | #ifndef __OFFSETSTREAM_H 4 | #define __OFFSETSTREAM_H 5 | 6 | #include "Common/MyCom.h" 7 | #include "../IStream.h" 8 | 9 | class COffsetOutStream: 10 | public IOutStream, 11 | public CMyUnknownImp 12 | { 13 | UInt64 _offset; 14 | CMyComPtr _stream; 15 | public: 16 | HRESULT Init(IOutStream *stream, UInt64 offset); 17 | 18 | MY_UNKNOWN_IMP 19 | 20 | STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); 21 | STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition); 22 | STDMETHOD(SetSize)(UInt64 newSize); 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/BZip2Register.cpp: -------------------------------------------------------------------------------- 1 | // BZip2Register.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../Common/RegisterCodec.h" 6 | 7 | #include "BZip2Decoder.h" 8 | 9 | static void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NBZip2::CDecoder); } 10 | #if !defined(EXTRACT_ONLY) && !defined(BZIP2_EXTRACT_ONLY) 11 | #include "BZip2Encoder.h" 12 | static void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NBZip2::CEncoder); } 13 | #else 14 | #define CreateCodecOut 0 15 | #endif 16 | 17 | static CCodecInfo g_CodecInfo = 18 | { CreateCodec, CreateCodecOut, 0x040202, L"BZip2", 1, false }; 19 | 20 | REGISTER_CODEC(BZip2) 21 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/PpmdRegister.cpp: -------------------------------------------------------------------------------- 1 | // PpmdRegister.cpp 2 | // 2009-05-30 : Igor Pavlov : Public domain 3 | 4 | #include "StdAfx.h" 5 | 6 | #include "../Common/RegisterCodec.h" 7 | 8 | #include "PpmdDecoder.h" 9 | 10 | static void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NPpmd::CDecoder); } 11 | #ifndef EXTRACT_ONLY 12 | #include "PpmdEncoder.h" 13 | static void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NPpmd::CEncoder); } 14 | #else 15 | #define CreateCodecOut 0 16 | #endif 17 | 18 | static CCodecInfo g_CodecInfo = 19 | { CreateCodec, CreateCodecOut, 0x030401, L"PPMD", 1, false }; 20 | 21 | REGISTER_CODEC(PPMD) 22 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Common/ItemNameUtils.h: -------------------------------------------------------------------------------- 1 | // Archive/Common/ItemNameUtils.h 2 | 3 | #ifndef __ARCHIVE_ITEMNAMEUTILS_H 4 | #define __ARCHIVE_ITEMNAMEUTILS_H 5 | 6 | #include "../../../Common/MyString.h" 7 | 8 | namespace NArchive { 9 | namespace NItemName { 10 | 11 | UString MakeLegalName(const UString &name); 12 | UString GetOSName(const UString &name); 13 | UString GetOSName2(const UString &name); 14 | bool HasTailSlash(const AString &name, UINT codePage); 15 | 16 | #ifdef _WIN32 17 | inline UString WinNameToOSName(const UString &name) { return name; } 18 | #else 19 | UString WinNameToOSName(const UString &name); 20 | #endif 21 | 22 | }} 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Crypto/Pbkdf2HmacSha1.h: -------------------------------------------------------------------------------- 1 | // Pbkdf2HmacSha1.h 2 | // Password-Based Key Derivation Function (RFC 2898, PKCS #5) based on HMAC-SHA-1 3 | 4 | #ifndef __CRYPTO_PBKDF2_HMAC_SHA1_H 5 | #define __CRYPTO_PBKDF2_HMAC_SHA1_H 6 | 7 | #include 8 | #include "../../Common/Types.h" 9 | 10 | namespace NCrypto { 11 | namespace NSha1 { 12 | 13 | void Pbkdf2Hmac(const Byte *pwd, size_t pwdSize, const Byte *salt, size_t saltSize, 14 | UInt32 numIterations, Byte *key, size_t keySize); 15 | 16 | void Pbkdf2Hmac32(const Byte *pwd, size_t pwdSize, const UInt32 *salt, size_t saltSize, 17 | UInt32 numIterations, UInt32 *key, size_t keySize); 18 | 19 | }} 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/Time.h: -------------------------------------------------------------------------------- 1 | // Windows/Time.h 2 | 3 | #ifndef __WINDOWS_TIME_H 4 | #define __WINDOWS_TIME_H 5 | 6 | #include "Common/Types.h" 7 | 8 | namespace NWindows { 9 | namespace NTime { 10 | 11 | bool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime); 12 | bool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime); 13 | void UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime); 14 | bool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime); 15 | bool GetSecondsSince1601(unsigned year, unsigned month, unsigned day, 16 | unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds); 17 | void GetCurUtcFileTime(FILETIME &ft); 18 | 19 | }} 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Tar/TarOut.h: -------------------------------------------------------------------------------- 1 | // Archive/TarOut.h 2 | 3 | #ifndef __ARCHIVE_TAR_OUT_H 4 | #define __ARCHIVE_TAR_OUT_H 5 | 6 | #include "TarItem.h" 7 | 8 | #include "Common/MyCom.h" 9 | #include "../../IStream.h" 10 | 11 | namespace NArchive { 12 | namespace NTar { 13 | 14 | class COutArchive 15 | { 16 | CMyComPtr m_Stream; 17 | HRESULT WriteBytes(const void *buffer, UInt32 size); 18 | public: 19 | void Create(ISequentialOutStream *outStream); 20 | HRESULT WriteHeaderReal(const CItem &item); 21 | HRESULT WriteHeader(const CItem &item); 22 | HRESULT FillDataResidual(UInt64 dataSize); 23 | HRESULT WriteFinishHeader(); 24 | }; 25 | 26 | }} 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/RarCodecsRegister.cpp: -------------------------------------------------------------------------------- 1 | // RarCodecsRegister.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../Common/RegisterCodec.h" 6 | 7 | #include "Rar1Decoder.h" 8 | #include "Rar2Decoder.h" 9 | #include "Rar3Decoder.h" 10 | 11 | #define CREATE_CODEC(x) static void *CreateCodec ## x() { return (void *)(ICompressCoder *)(new NCompress::NRar ## x::CDecoder); } 12 | 13 | CREATE_CODEC(1) 14 | CREATE_CODEC(2) 15 | CREATE_CODEC(3) 16 | 17 | #define RAR_CODEC(x, name) { CreateCodec ## x, 0, 0x040300 + x, L"Rar" name, 1, false } 18 | 19 | static CCodecInfo g_CodecsInfo[] = 20 | { 21 | RAR_CODEC(1, L"1"), 22 | RAR_CODEC(2, L"2"), 23 | RAR_CODEC(3, L"3"), 24 | }; 25 | 26 | REGISTER_CODECS(Rar) 27 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/ResourceString.h: -------------------------------------------------------------------------------- 1 | // Windows/ResourceString.h 2 | 3 | #ifndef __WINDOWS_RESOURCESTRING_H 4 | #define __WINDOWS_RESOURCESTRING_H 5 | 6 | #include "Common/MyString.h" 7 | 8 | namespace NWindows { 9 | 10 | CSysString MyLoadString(HINSTANCE hInstance, UINT resourceID); 11 | CSysString MyLoadString(UINT resourceID); 12 | #ifdef _UNICODE 13 | inline UString MyLoadStringW(HINSTANCE hInstance, UINT resourceID) { return MyLoadString(hInstance, resourceID); } 14 | inline UString MyLoadStringW(UINT resourceID) { return MyLoadString(resourceID); } 15 | #else 16 | UString MyLoadStringW(HINSTANCE hInstance, UINT resourceID); 17 | UString MyLoadStringW(UINT resourceID); 18 | #endif 19 | 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /lib/codecs/rtl/7zCrc.h: -------------------------------------------------------------------------------- 1 | /* 7zCrc.h -- CRC32 calculation 2 | 2009-11-21 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_CRC_H 5 | #define __7Z_CRC_H 6 | 7 | #include "Types.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | extern UInt32 g_CrcTable[]; 12 | 13 | /* Call CrcGenerateTable one time before other CRC functions */ 14 | void MY_FAST_CALL CrcGenerateTable(void); 15 | 16 | #define CRC_INIT_VAL 0xFFFFFFFF 17 | #define CRC_GET_DIGEST(crc) ((crc) ^ CRC_INIT_VAL) 18 | #define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) 19 | 20 | UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size); 21 | UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size); 22 | 23 | EXTERN_C_END 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Common/DummyOutStream.h: -------------------------------------------------------------------------------- 1 | // DummyOutStream.h 2 | 3 | #ifndef __DUMMYOUTSTREAM_H 4 | #define __DUMMYOUTSTREAM_H 5 | 6 | #include "../../IStream.h" 7 | #include "Common/MyCom.h" 8 | 9 | class CDummyOutStream: 10 | public ISequentialOutStream, 11 | public CMyUnknownImp 12 | { 13 | public: 14 | CMyComPtr _stream; 15 | UInt64 _size; 16 | public: 17 | void SetStream(ISequentialOutStream *outStream) { _stream = outStream; } 18 | void ReleaseStream() { _stream.Release(); } 19 | void Init() { _size = 0; } 20 | MY_UNKNOWN_IMP 21 | STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); 22 | UInt64 GetSize() const { return _size; } 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/codecs/rtl/XzCrc64.h: -------------------------------------------------------------------------------- 1 | /* XzCrc64.h -- CRC64 calculation 2 | 2010-04-16 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __XZ_CRC64_H 5 | #define __XZ_CRC64_H 6 | 7 | #include 8 | 9 | #include "Types.h" 10 | 11 | EXTERN_C_BEGIN 12 | 13 | extern UInt64 g_Crc64Table[]; 14 | 15 | void MY_FAST_CALL Crc64GenerateTable(void); 16 | 17 | #define CRC64_INIT_VAL UINT64_CONST(0xFFFFFFFFFFFFFFFF) 18 | #define CRC64_GET_DIGEST(crc) ((crc) ^ CRC64_INIT_VAL) 19 | #define CRC64_UPDATE_BYTE(crc, b) (g_Crc64Table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) 20 | 21 | UInt64 MY_FAST_CALL Crc64Update(UInt64 crc, const void *data, size_t size); 22 | UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size); 23 | 24 | EXTERN_C_END 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/7z/7zSpecStream.cpp: -------------------------------------------------------------------------------- 1 | // 7zSpecStream.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "7zSpecStream.h" 6 | 7 | STDMETHODIMP CSequentialInStreamSizeCount2::Read(void *data, UInt32 size, UInt32 *processedSize) 8 | { 9 | UInt32 realProcessedSize; 10 | HRESULT result = _stream->Read(data, size, &realProcessedSize); 11 | _size += realProcessedSize; 12 | if (processedSize != 0) 13 | *processedSize = realProcessedSize; 14 | return result; 15 | } 16 | 17 | STDMETHODIMP CSequentialInStreamSizeCount2::GetSubStreamSize( 18 | UInt64 subStream, UInt64 *value) 19 | { 20 | if (_getSubStreamSize == NULL) 21 | return E_NOTIMPL; 22 | return _getSubStreamSize->GetSubStreamSize(subStream, value); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/DeflateRegister.cpp: -------------------------------------------------------------------------------- 1 | // DeflateRegister.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../Common/RegisterCodec.h" 6 | 7 | #include "DeflateDecoder.h" 8 | 9 | static void *CreateCodecDeflate() { return (void *)(ICompressCoder *)(new NCompress::NDeflate::NDecoder::CCOMCoder); } 10 | 11 | #if !defined(EXTRACT_ONLY) && !defined(DEFLATE_EXTRACT_ONLY) 12 | #include "DeflateEncoder.h" 13 | static void *CreateCodecOutDeflate() { return (void *)(ICompressCoder *)(new NCompress::NDeflate::NEncoder::CCOMCoder); } 14 | #else 15 | #define CreateCodecOutDeflate 0 16 | #endif 17 | 18 | static CCodecInfo g_CodecInfo = 19 | { CreateCodecDeflate, CreateCodecOutDeflate, 0x040108, L"Deflate", 1, false }; 20 | 21 | REGISTER_CODEC(Deflate) 22 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/FileName.h: -------------------------------------------------------------------------------- 1 | // Windows/FileName.h 2 | 3 | #ifndef __WINDOWS_FILENAME_H 4 | #define __WINDOWS_FILENAME_H 5 | 6 | #include 7 | 8 | #include "../Common/MyString.h" 9 | 10 | namespace NWindows { 11 | namespace NFile { 12 | namespace NName { 13 | 14 | const TCHAR kDirDelimiter = CHAR_PATH_SEPARATOR; 15 | const TCHAR kAnyStringWildcard = '*'; 16 | 17 | void NormalizeDirPathPrefix(CSysString &dirPath); // ensures that it ended with '\\' 18 | #ifndef _UNICODE 19 | void NormalizeDirPathPrefix(UString &dirPath); // ensures that it ended with '\\' 20 | #endif 21 | 22 | void SplitNameToPureNameAndExtension(const UString &fullName, 23 | UString &pureName, UString &extensionDelimiter, UString &extension); 24 | 25 | }}} 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/Deflate64Register.cpp: -------------------------------------------------------------------------------- 1 | // Deflate64Register.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../Common/RegisterCodec.h" 6 | 7 | #include "DeflateDecoder.h" 8 | 9 | static void *CreateCodecDeflate64() { return (void *)(ICompressCoder *)(new NCompress::NDeflate::NDecoder::CCOMCoder64); } 10 | #if !defined(EXTRACT_ONLY) && !defined(DEFLATE_EXTRACT_ONLY) 11 | #include "DeflateEncoder.h" 12 | static void *CreateCodecOutDeflate64() { return (void *)(ICompressCoder *)(new NCompress::NDeflate::NEncoder::CCOMCoder64); } 13 | #else 14 | #define CreateCodecOutDeflate64 0 15 | #endif 16 | 17 | static CCodecInfo g_CodecInfo = 18 | { CreateCodecDeflate64, CreateCodecOutDeflate64, 0x040109, L"Deflate64", 1, false }; 19 | 20 | REGISTER_CODEC(Deflate64) 21 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Tar/TarUpdate.h: -------------------------------------------------------------------------------- 1 | // TarUpdate.h 2 | 3 | #ifndef __TAR_UPDATE_H 4 | #define __TAR_UPDATE_H 5 | 6 | #include "../IArchive.h" 7 | #include "TarItem.h" 8 | 9 | namespace NArchive { 10 | namespace NTar { 11 | 12 | struct CUpdateItem 13 | { 14 | int IndexInArchive; 15 | int IndexInClient; 16 | UInt32 Time; 17 | UInt32 Mode; 18 | UInt64 Size; 19 | AString Name; 20 | AString User; 21 | AString Group; 22 | bool NewData; 23 | bool NewProps; 24 | bool IsDir; 25 | }; 26 | 27 | HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream, 28 | const CObjectVector &inputItems, 29 | const CObjectVector &updateItems, 30 | IArchiveUpdateCallback *updateCallback); 31 | 32 | }} 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Tar/TarHeader.cpp: -------------------------------------------------------------------------------- 1 | // Archive/Tar/Header.h 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "TarHeader.h" 6 | 7 | namespace NArchive { 8 | namespace NTar { 9 | namespace NFileHeader { 10 | 11 | // The checksum field is filled with this while the checksum is computed. 12 | const char *kCheckSumBlanks = " "; // 8 blanks, no null 13 | 14 | const char *kLongLink = "././@LongLink"; 15 | const char *kLongLink2 = "@LongLink"; 16 | 17 | // The magic field is filled with this if uname and gname are valid. 18 | namespace NMagic 19 | { 20 | const char *kUsTar = "ustar"; // 5 chars 21 | const char *kGNUTar = "GNUtar "; // 7 chars and a null 22 | const char *kEmpty = "\0\0\0\0\0\0\0\0"; // 7 chars and a null 23 | } 24 | 25 | }}} 26 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Chm/ChmHeader.h: -------------------------------------------------------------------------------- 1 | // Archive/Chm/Header.h 2 | 3 | #ifndef __ARCHIVE_CHM_HEADER_H 4 | #define __ARCHIVE_CHM_HEADER_H 5 | 6 | #include "Common/Types.h" 7 | 8 | namespace NArchive { 9 | namespace NChm { 10 | namespace NHeader{ 11 | 12 | const UInt32 kItspSignature = 0x50535449; 13 | const UInt32 kPmglSignature = 0x4C474D50; 14 | const UInt32 kLzxcSignature = 0x43585A4C; 15 | 16 | const UInt32 kIfcmSignature = 0x4D434649; 17 | const UInt32 kAollSignature = 0x4C4C4F41; 18 | const UInt32 kCaolSignature = 0x4C4F4143; 19 | 20 | extern UInt32 kItsfSignature; 21 | 22 | extern UInt32 kItolSignature; 23 | const UInt32 kItlsSignature = 0x534C5449; 24 | UInt64 inline GetHxsSignature() { return ((UInt64)kItlsSignature << 32) | kItolSignature; } 25 | 26 | }}} 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/AutoPtr.h: -------------------------------------------------------------------------------- 1 | // Common/AutoPtr.h 2 | 3 | #ifndef __COMMON_AUTOPTR_H 4 | #define __COMMON_AUTOPTR_H 5 | 6 | template class CMyAutoPtr 7 | { 8 | T *_p; 9 | public: 10 | CMyAutoPtr(T *p = 0) : _p(p) {} 11 | CMyAutoPtr(CMyAutoPtr& p): _p(p.release()) {} 12 | CMyAutoPtr& operator=(CMyAutoPtr& p) 13 | { 14 | reset(p.release()); 15 | return (*this); 16 | } 17 | ~CMyAutoPtr() { delete _p; } 18 | T& operator*() const { return *_p; } 19 | // T* operator->() const { return (&**this); } 20 | T* get() const { return _p; } 21 | T* release() 22 | { 23 | T *tmp = _p; 24 | _p = 0; 25 | return tmp; 26 | } 27 | void reset(T* p = 0) 28 | { 29 | if (p != _p) 30 | delete _p; 31 | _p = p; 32 | } 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/Handle.h: -------------------------------------------------------------------------------- 1 | // Windows/Handle.h 2 | 3 | #ifndef __WINDOWS_HANDLE_H 4 | #define __WINDOWS_HANDLE_H 5 | 6 | namespace NWindows { 7 | 8 | class CHandle 9 | { 10 | protected: 11 | HANDLE _handle; 12 | public: 13 | operator HANDLE() { return _handle; } 14 | CHandle(): _handle(NULL) {} 15 | ~CHandle() { Close(); } 16 | bool IsCreated() const { return (_handle != NULL); } 17 | bool Close() 18 | { 19 | if (_handle == NULL) 20 | return true; 21 | if (!::CloseHandle(_handle)) 22 | return false; 23 | _handle = NULL; 24 | return true; 25 | } 26 | void Attach(HANDLE handle) { _handle = handle; } 27 | HANDLE Detach() 28 | { 29 | HANDLE handle = _handle; 30 | _handle = NULL; 31 | return handle; 32 | } 33 | }; 34 | 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/LockedStream.cpp: -------------------------------------------------------------------------------- 1 | // LockedStream.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "LockedStream.h" 6 | 7 | HRESULT CLockedInStream::Read(UInt64 startPos, void *data, UInt32 size, 8 | UInt32 *processedSize) 9 | { 10 | NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); 11 | RINOK(_stream->Seek(startPos, STREAM_SEEK_SET, NULL)); 12 | return _stream->Read(data, size, processedSize); 13 | } 14 | 15 | STDMETHODIMP CLockedSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize) 16 | { 17 | UInt32 realProcessedSize = 0; 18 | HRESULT result = _lockedInStream->Read(_pos, data, size, &realProcessedSize); 19 | _pos += realProcessedSize; 20 | if (processedSize != NULL) 21 | *processedSize = realProcessedSize; 22 | return result; 23 | } 24 | -------------------------------------------------------------------------------- /lib/codecs/rtl/BwtSort.h: -------------------------------------------------------------------------------- 1 | /* BwtSort.h -- BWT block sorting 2 | 2009-02-07 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __BWT_SORT_H 5 | #define __BWT_SORT_H 6 | 7 | #include "Types.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /* use BLOCK_SORT_EXTERNAL_FLAGS if blockSize can be > 1M */ 14 | /* #define BLOCK_SORT_EXTERNAL_FLAGS */ 15 | 16 | #ifdef BLOCK_SORT_EXTERNAL_FLAGS 17 | #define BLOCK_SORT_EXTERNAL_SIZE(blockSize) ((((blockSize) + 31) >> 5)) 18 | #else 19 | #define BLOCK_SORT_EXTERNAL_SIZE(blockSize) 0 20 | #endif 21 | 22 | #define BLOCK_SORT_BUF_SIZE(blockSize) ((blockSize) * 2 + BLOCK_SORT_EXTERNAL_SIZE(blockSize) + (1 << 16)) 23 | 24 | UInt32 BlockSort(UInt32 *indices, const Byte *data, UInt32 blockSize); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Common/ParseProperties.h: -------------------------------------------------------------------------------- 1 | // ParseProperties.h 2 | 3 | #ifndef __PARSEPROPERTIES_H 4 | #define __PARSEPROPERTIES_H 5 | 6 | #include "Common/MyString.h" 7 | #include "Common/Types.h" 8 | 9 | HRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue); 10 | HRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize); 11 | HRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue); 12 | 13 | bool StringToBool(const UString &s, bool &res); 14 | HRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value); 15 | int ParseStringToUInt32(const UString &srcString, UInt32 &number); 16 | HRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/DeflateProps.h: -------------------------------------------------------------------------------- 1 | // DeflateProps.h 2 | 3 | #ifndef __DEFLATE_PROPS_H 4 | #define __DEFLATE_PROPS_H 5 | 6 | #include "../ICoder.h" 7 | 8 | namespace NArchive { 9 | 10 | class CDeflateProps 11 | { 12 | UInt32 Level; 13 | UInt32 NumPasses; 14 | UInt32 Fb; 15 | UInt32 Algo; 16 | UInt32 Mc; 17 | bool McDefined; 18 | 19 | void Init() 20 | { 21 | Level = NumPasses = Fb = Algo = Mc = 0xFFFFFFFF; 22 | McDefined = false; 23 | } 24 | void Normalize(); 25 | public: 26 | CDeflateProps() { Init(); } 27 | bool IsMaximum() const { return Algo > 0; } 28 | 29 | HRESULT SetCoderProperties(ICompressSetCoderProperties *setCoderProperties); 30 | HRESULT SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProps); 31 | }; 32 | 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/Error.h: -------------------------------------------------------------------------------- 1 | // Windows/Error.h 2 | 3 | #ifndef __WINDOWS_ERROR_H 4 | #define __WINDOWS_ERROR_H 5 | 6 | #include "Common/MyString.h" 7 | 8 | namespace NWindows { 9 | namespace NError { 10 | 11 | bool MyFormatMessage(DWORD messageID, CSysString &message); 12 | inline CSysString MyFormatMessage(DWORD messageID) 13 | { 14 | CSysString message; 15 | MyFormatMessage(messageID, message); 16 | return message; 17 | } 18 | #ifdef _UNICODE 19 | inline UString MyFormatMessageW(DWORD messageID) 20 | { return MyFormatMessage(messageID); } 21 | #else 22 | bool MyFormatMessage(DWORD messageID, UString &message); 23 | inline UString MyFormatMessageW(DWORD messageID) 24 | { 25 | UString message; 26 | MyFormatMessage(messageID, message); 27 | return message; 28 | } 29 | #endif 30 | 31 | }} 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/ProgressUtils.h: -------------------------------------------------------------------------------- 1 | // ProgressUtils.h 2 | 3 | #ifndef __PROGRESSUTILS_H 4 | #define __PROGRESSUTILS_H 5 | 6 | #include "../../Common/MyCom.h" 7 | 8 | #include "../ICoder.h" 9 | #include "../IProgress.h" 10 | 11 | class CLocalProgress: 12 | public ICompressProgressInfo, 13 | public CMyUnknownImp 14 | { 15 | CMyComPtr _progress; 16 | CMyComPtr _ratioProgress; 17 | bool _inSizeIsMain; 18 | public: 19 | UInt64 ProgressOffset; 20 | UInt64 InSize; 21 | UInt64 OutSize; 22 | bool SendRatio; 23 | bool SendProgress; 24 | 25 | CLocalProgress(); 26 | void Init(IProgress *progress, bool inSizeIsMain); 27 | HRESULT SetCur(); 28 | 29 | MY_UNKNOWN_IMP 30 | 31 | STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize); 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /lib/codecs/rtl/7zBuf.h: -------------------------------------------------------------------------------- 1 | /* 7zBuf.h -- Byte Buffer 2 | 2009-02-07 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_BUF_H 5 | #define __7Z_BUF_H 6 | 7 | #include "Types.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | typedef struct 14 | { 15 | Byte *data; 16 | size_t size; 17 | } CBuf; 18 | 19 | void Buf_Init(CBuf *p); 20 | int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc); 21 | void Buf_Free(CBuf *p, ISzAlloc *alloc); 22 | 23 | typedef struct 24 | { 25 | Byte *data; 26 | size_t size; 27 | size_t pos; 28 | } CDynBuf; 29 | 30 | void DynBuf_Construct(CDynBuf *p); 31 | void DynBuf_SeekToBeg(CDynBuf *p); 32 | int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc); 33 | void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/RegisterArc.h: -------------------------------------------------------------------------------- 1 | // RegisterArc.h 2 | 3 | #ifndef __REGISTER_ARC_H 4 | #define __REGISTER_ARC_H 5 | 6 | #include "../Archive/IArchive.h" 7 | 8 | typedef IInArchive * (*CreateInArchiveP)(); 9 | typedef IOutArchive * (*CreateOutArchiveP)(); 10 | 11 | struct CArcInfo 12 | { 13 | const char *Name; 14 | Byte Signature[28]; // FIXME Byte Signature[16]; adding 22 bytes to insure kSignature[0x1A]!= 0 and kSignature[0x1B] != 0 15 | int SignatureSize; 16 | CreateInArchiveP CreateInArchive; 17 | CreateOutArchiveP CreateOutArchive; 18 | }; 19 | 20 | void RegisterArc(const CArcInfo *arcInfo); 21 | 22 | #define REGISTER_ARC_NAME(x) CRegister ## x 23 | 24 | #define REGISTER_ARC(x) struct REGISTER_ARC_NAME(x) { \ 25 | REGISTER_ARC_NAME(x)() { RegisterArc(&g_ArcInfo); }}; \ 26 | static REGISTER_ARC_NAME(x) g_RegisterArc; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/MethodProps.h: -------------------------------------------------------------------------------- 1 | // MethodProps.h 2 | 3 | #ifndef __7Z_METHOD_PROPS_H 4 | #define __7Z_METHOD_PROPS_H 5 | 6 | #include "../../Common/MyVector.h" 7 | 8 | #include "../../Windows/PropVariant.h" 9 | 10 | #include "MethodId.h" 11 | 12 | struct CProp 13 | { 14 | PROPID Id; 15 | NWindows::NCOM::CPropVariant Value; 16 | }; 17 | 18 | struct CMethod 19 | { 20 | CMethodId Id; 21 | CObjectVector Props; 22 | }; 23 | 24 | struct CMethodsMode 25 | { 26 | CObjectVector Methods; 27 | #ifndef _7ZIP_ST 28 | UInt32 NumThreads; 29 | #endif 30 | 31 | CMethodsMode() 32 | #ifndef _7ZIP_ST 33 | : NumThreads(1) 34 | #endif 35 | {} 36 | bool IsEmpty() const { return Methods.IsEmpty() ; } 37 | }; 38 | 39 | HRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/IProgress.h: -------------------------------------------------------------------------------- 1 | // Interface/IProgress.h 2 | 3 | #ifndef __IPROGRESS_H 4 | #define __IPROGRESS_H 5 | 6 | #include "../Common/MyUnknown.h" 7 | #include "../Common/Types.h" 8 | 9 | #include "IDecl.h" 10 | 11 | #define INTERFACE_IProgress(x) \ 12 | STDMETHOD(SetTotal)(UInt64 total) x; \ 13 | STDMETHOD(SetCompleted)(const UInt64 *completeValue) x; \ 14 | 15 | DECL_INTERFACE(IProgress, 0, 5) 16 | { 17 | INTERFACE_IProgress(PURE) 18 | }; 19 | 20 | /* 21 | // {23170F69-40C1-278A-0000-000000050002} 22 | DEFINE_GUID(IID_IProgress2, 23 | 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x02); 24 | MIDL_INTERFACE("23170F69-40C1-278A-0000-000000050002") 25 | IProgress2: public IUnknown 26 | { 27 | public: 28 | STDMETHOD(SetTotal)(const UInt64 *total) PURE; 29 | STDMETHOD(SetCompleted)(const UInt64 *completeValue) PURE; 30 | }; 31 | */ 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /lib/codecs/rtl/XzCrc64.c: -------------------------------------------------------------------------------- 1 | /* XzCrc64.c -- CRC64 calculation 2 | 2010-04-16 : Igor Pavlov : Public domain */ 3 | 4 | #include "XzCrc64.h" 5 | 6 | #define kCrc64Poly UINT64_CONST(0xC96C5795D7870F42) 7 | UInt64 g_Crc64Table[256]; 8 | 9 | void MY_FAST_CALL Crc64GenerateTable(void) 10 | { 11 | UInt32 i; 12 | for (i = 0; i < 256; i++) 13 | { 14 | UInt64 r = i; 15 | int j; 16 | for (j = 0; j < 8; j++) 17 | r = (r >> 1) ^ ((UInt64)kCrc64Poly & ~((r & 1) - 1)); 18 | g_Crc64Table[i] = r; 19 | } 20 | } 21 | 22 | UInt64 MY_FAST_CALL Crc64Update(UInt64 v, const void *data, size_t size) 23 | { 24 | const Byte *p = (const Byte *)data; 25 | for (; size > 0 ; size--, p++) 26 | v = CRC64_UPDATE_BYTE(v, *p); 27 | return v; 28 | } 29 | 30 | UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size) 31 | { 32 | return CRC64_GET_DIGEST(Crc64Update(CRC64_INIT_VAL, data, size)); 33 | } 34 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/DLL.h: -------------------------------------------------------------------------------- 1 | // Windows/DLL.h 2 | 3 | #ifndef __WINDOWS_DLL_H 4 | #define __WINDOWS_DLL_H 5 | 6 | #include "../Common/MyString.h" 7 | 8 | typedef void * HMODULE; 9 | 10 | typedef int (*FARPROC)(); 11 | 12 | namespace NWindows { 13 | namespace NDLL { 14 | 15 | class CLibrary 16 | { 17 | bool LoadOperations(HMODULE newModule); 18 | HMODULE _module; 19 | public: 20 | operator HMODULE() const { return _module; } 21 | HMODULE* operator&() { return &_module; } 22 | 23 | 24 | CLibrary():_module(NULL) {}; 25 | ~CLibrary(); 26 | 27 | bool Free(); 28 | 29 | void Attach(HMODULE m) 30 | { 31 | Free(); 32 | _module = m; 33 | } 34 | HMODULE Detach() 35 | { 36 | HMODULE m = _module; 37 | _module = NULL; 38 | return m; 39 | } 40 | 41 | 42 | bool Load(LPCTSTR fileName); 43 | FARPROC GetProc(LPCSTR procName) const; 44 | }; 45 | 46 | }} 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/BZip2Crc.h: -------------------------------------------------------------------------------- 1 | // BZip2Crc.h 2 | 3 | #ifndef __BZIP2_CRC_H 4 | #define __BZIP2_CRC_H 5 | 6 | #include "Common/Types.h" 7 | 8 | class CBZip2Crc 9 | { 10 | UInt32 _value; 11 | static UInt32 Table[256]; 12 | public: 13 | static void InitTable(); 14 | CBZip2Crc(): _value(0xFFFFFFFF) {}; 15 | void Init() { _value = 0xFFFFFFFF; } 16 | void UpdateByte(Byte b) { _value = Table[(_value >> 24) ^ b] ^ (_value << 8); } 17 | void UpdateByte(unsigned int b) { _value = Table[(_value >> 24) ^ b] ^ (_value << 8); } 18 | UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; } 19 | }; 20 | 21 | class CBZip2CombinedCrc 22 | { 23 | UInt32 _value; 24 | public: 25 | CBZip2CombinedCrc(): _value(0){}; 26 | void Init() { _value = 0; } 27 | void Update(UInt32 v) { _value = ((_value << 1) | (_value >> 31)) ^ v; } 28 | UInt32 GetDigest() const { return _value ; } 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/COM.cpp: -------------------------------------------------------------------------------- 1 | // Windows/COM.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "Windows/COM.h" 6 | #include "Common/StringConvert.h" 7 | 8 | namespace NWindows { 9 | namespace NCOM { 10 | 11 | // CoInitialize (NULL); must be called! 12 | 13 | UString GUIDToStringW(REFGUID guid) 14 | { 15 | UString string; 16 | const int kStringSize = 48; 17 | StringFromGUID2(guid, string.GetBuffer(kStringSize), kStringSize); 18 | string.ReleaseBuffer(); 19 | return string; 20 | } 21 | 22 | AString GUIDToStringA(REFGUID guid) 23 | { 24 | return UnicodeStringToMultiByte(GUIDToStringW(guid)); 25 | } 26 | 27 | HRESULT StringToGUIDW(const wchar_t *string, GUID &classID) 28 | { 29 | return CLSIDFromString((wchar_t *)string, &classID); 30 | } 31 | 32 | HRESULT StringToGUIDA(const char *string, GUID &classID) 33 | { 34 | return StringToGUIDW(MultiByteToUnicodeString(string), classID); 35 | } 36 | 37 | }} 38 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Zip/ZipHeader.cpp: -------------------------------------------------------------------------------- 1 | // Archive/Zip/Header.h 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "ZipHeader.h" 6 | 7 | namespace NArchive { 8 | namespace NZip { 9 | 10 | namespace NSignature 11 | { 12 | UInt32 kLocalFileHeader = 0x04034B50 + 1; 13 | UInt32 kDataDescriptor = 0x08074B50 + 1; 14 | UInt32 kCentralFileHeader = 0x02014B50 + 1; 15 | UInt32 kEndOfCentralDir = 0x06054B50 + 1; 16 | UInt32 kZip64EndOfCentralDir = 0x06064B50 + 1; 17 | UInt32 kZip64EndOfCentralDirLocator = 0x07064B50 + 1; 18 | 19 | class CMarkersInitializer 20 | { 21 | public: 22 | CMarkersInitializer() 23 | { 24 | kLocalFileHeader--; 25 | kDataDescriptor--; 26 | kCentralFileHeader--; 27 | kEndOfCentralDir--; 28 | kZip64EndOfCentralDir--; 29 | kZip64EndOfCentralDirLocator--; 30 | } 31 | }; 32 | static CMarkersInitializer g_MarkerInitializer; 33 | } 34 | 35 | }} 36 | 37 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/MyXml.h: -------------------------------------------------------------------------------- 1 | // MyXml.h 2 | 3 | #ifndef __MYXML_H 4 | #define __MYXML_H 5 | 6 | #include "MyString.h" 7 | 8 | struct CXmlProp 9 | { 10 | AString Name; 11 | AString Value; 12 | }; 13 | 14 | class CXmlItem 15 | { 16 | bool ParseItems(const AString &s, int &pos, int numAllowedLevels); 17 | 18 | public: 19 | AString Name; 20 | bool IsTag; 21 | CObjectVector Props; 22 | CObjectVector SubItems; 23 | 24 | bool ParseItem(const AString &s, int &pos, int numAllowedLevels); 25 | 26 | bool IsTagged(const AString &tag) const; 27 | int FindProperty(const AString &propName) const; 28 | AString GetPropertyValue(const AString &propName) const; 29 | AString GetSubString() const; 30 | int FindSubTag(const AString &tag) const; 31 | AString GetSubStringForTag(const AString &tag) const; 32 | }; 33 | 34 | struct CXml 35 | { 36 | CXmlItem Root; 37 | bool Parse(const AString &s); 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Zip/ZipCompressionMode.h: -------------------------------------------------------------------------------- 1 | // CompressionMode.h 2 | 3 | #ifndef __ZIP_COMPRESSION_MODE_H 4 | #define __ZIP_COMPRESSION_MODE_H 5 | 6 | #include "Common/MyString.h" 7 | 8 | namespace NArchive { 9 | namespace NZip { 10 | 11 | struct CCompressionMethodMode 12 | { 13 | CRecordVector MethodSequence; 14 | UString MatchFinder; 15 | UInt32 Algo; 16 | UInt32 NumPasses; 17 | UInt32 NumFastBytes; 18 | bool NumMatchFinderCyclesDefined; 19 | UInt32 NumMatchFinderCycles; 20 | UInt32 DicSize; 21 | UInt32 MemSize; 22 | UInt32 Order; 23 | 24 | #ifndef _7ZIP_ST 25 | UInt32 NumThreads; 26 | #endif 27 | bool PasswordIsDefined; 28 | AString Password; 29 | bool IsAesMode; 30 | Byte AesKeyMode; 31 | 32 | CCompressionMethodMode(): 33 | NumMatchFinderCyclesDefined(false), 34 | PasswordIsDefined(false), 35 | IsAesMode(false), 36 | AesKeyMode(3) 37 | {} 38 | }; 39 | 40 | }} 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Common/CrossThreadProgress.h: -------------------------------------------------------------------------------- 1 | // CrossThreadProgress.h 2 | 3 | #ifndef __CROSSTHREADPROGRESS_H 4 | #define __CROSSTHREADPROGRESS_H 5 | 6 | #include "../../ICoder.h" 7 | #include "../../../Windows/Synchronization.h" 8 | #include "../../../Common/MyCom.h" 9 | 10 | class CCrossThreadProgress: 11 | public ICompressProgressInfo, 12 | public CMyUnknownImp 13 | { 14 | public: 15 | const UInt64 *InSize; 16 | const UInt64 *OutSize; 17 | HRESULT Result; 18 | NWindows::NSynchronization::CAutoResetEvent ProgressEvent; 19 | NWindows::NSynchronization::CAutoResetEvent WaitEvent; 20 | 21 | HRes Create() 22 | { 23 | RINOK(ProgressEvent.CreateIfNotCreated()); 24 | return WaitEvent.CreateIfNotCreated(); 25 | } 26 | void Init() 27 | { 28 | ProgressEvent.Reset(); 29 | WaitEvent.Reset(); 30 | } 31 | 32 | MY_UNKNOWN_IMP 33 | 34 | STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize); 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/CopyCoder.h: -------------------------------------------------------------------------------- 1 | // Compress/CopyCoder.h 2 | 3 | #ifndef __COMPRESS_COPY_CODER_H 4 | #define __COMPRESS_COPY_CODER_H 5 | 6 | #include "../../Common/MyCom.h" 7 | 8 | #include "../ICoder.h" 9 | 10 | namespace NCompress { 11 | 12 | class CCopyCoder: 13 | public ICompressCoder, 14 | public ICompressGetInStreamProcessedSize, 15 | public CMyUnknownImp 16 | { 17 | Byte *_buffer; 18 | public: 19 | UInt64 TotalSize; 20 | CCopyCoder(): TotalSize(0), _buffer(0) {}; 21 | ~CCopyCoder(); 22 | 23 | MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize) 24 | 25 | STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, 26 | const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 27 | STDMETHOD(GetInStreamProcessedSize)(UInt64 *value); 28 | }; 29 | 30 | HRESULT CopyStream(ISequentialInStream *inStream, ISequentialOutStream *outStream, ICompressProgressInfo *progress); 31 | 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /libcodecs.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcodecs", "src\libxsse\codecs\libcodecs.vcproj", "{4024553C-39B5-4E44-B480-68FE56E5BA05}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {4024553C-39B5-4E44-B480-68FE56E5BA05}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {4024553C-39B5-4E44-B480-68FE56E5BA05}.Debug|Win32.Build.0 = Debug|Win32 14 | {4024553C-39B5-4E44-B480-68FE56E5BA05}.Release|Win32.ActiveCfg = Release|Win32 15 | {4024553C-39B5-4E44-B480-68FE56E5BA05}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Crypto/MyAes.h: -------------------------------------------------------------------------------- 1 | // Crypto/MyAes.h 2 | 3 | #ifndef __CRYPTO_MY_AES_H 4 | #define __CRYPTO_MY_AES_H 5 | 6 | #include 7 | 8 | #include "../../Common/MyCom.h" 9 | 10 | #include "../ICoder.h" 11 | 12 | namespace NCrypto { 13 | 14 | class CAesCbcCoder: 15 | public ICompressFilter, 16 | public ICryptoProperties, 17 | public CMyUnknownImp 18 | { 19 | protected: 20 | AES_CODE_FUNC _codeFunc; 21 | AES_SET_KEY_FUNC _setKeyFunc; 22 | unsigned _offset; 23 | UInt32 _aes[AES_NUM_IVMRK_WORDS + 3]; 24 | public: 25 | CAesCbcCoder(); 26 | MY_UNKNOWN_IMP1(ICryptoProperties) 27 | STDMETHOD(Init)(); 28 | STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size); 29 | STDMETHOD(SetKey)(const Byte *data, UInt32 size); 30 | STDMETHOD(SetInitVector)(const Byte *data, UInt32 size); 31 | }; 32 | 33 | struct CAesCbcEncoder: public CAesCbcCoder { CAesCbcEncoder(); }; 34 | struct CAesCbcDecoder: public CAesCbcCoder { CAesCbcDecoder(); }; 35 | 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Cab/CabHeader.h: -------------------------------------------------------------------------------- 1 | // Archive/Cab/Header.h 2 | 3 | #ifndef __ARCHIVE_CAB_HEADER_H 4 | #define __ARCHIVE_CAB_HEADER_H 5 | 6 | #include "Common/Types.h" 7 | 8 | namespace NArchive { 9 | namespace NCab { 10 | namespace NHeader { 11 | 12 | const unsigned kMarkerSize = 8; 13 | extern Byte kMarker[kMarkerSize]; 14 | 15 | namespace NArchive 16 | { 17 | namespace NFlags 18 | { 19 | const int kPrevCabinet = 0x0001; 20 | const int kNextCabinet = 0x0002; 21 | const int kReservePresent = 0x0004; 22 | } 23 | } 24 | 25 | namespace NCompressionMethodMajor 26 | { 27 | const Byte kNone = 0; 28 | const Byte kMSZip = 1; 29 | const Byte kQuantum = 2; 30 | const Byte kLZX = 3; 31 | } 32 | 33 | const int kFileNameIsUTFAttributeMask = 0x80; 34 | 35 | namespace NFolderIndex 36 | { 37 | const int kContinuedFromPrev = 0xFFFD; 38 | const int kContinuedToNext = 0xFFFE; 39 | const int kContinuedPrevAndNext = 0xFFFF; 40 | } 41 | 42 | }}} 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Nsis/NsisHandler.h: -------------------------------------------------------------------------------- 1 | // NSisHandler.h 2 | 3 | #ifndef __NSIS_HANDLER_H 4 | #define __NSIS_HANDLER_H 5 | 6 | #include "Common/MyCom.h" 7 | #include "../IArchive.h" 8 | 9 | #include "NsisIn.h" 10 | 11 | #include "../../Common/CreateCoder.h" 12 | 13 | namespace NArchive { 14 | namespace NNsis { 15 | 16 | class CHandler: 17 | public IInArchive, 18 | PUBLIC_ISetCompressCodecsInfo 19 | public CMyUnknownImp 20 | { 21 | CMyComPtr _inStream; 22 | CInArchive _archive; 23 | 24 | DECL_EXTERNAL_CODECS_VARS 25 | 26 | bool GetUncompressedSize(int index, UInt32 &size); 27 | bool GetCompressedSize(int index, UInt32 &size); 28 | 29 | AString GetMethod(bool useItemFilter, UInt32 dictionary) const; 30 | public: 31 | MY_QUERYINTERFACE_BEGIN2(IInArchive) 32 | QUERY_ENTRY_ISetCompressCodecsInfo 33 | MY_QUERYINTERFACE_END 34 | MY_ADDREF_RELEASE 35 | 36 | INTERFACE_IInArchive(;) 37 | 38 | DECL_ISetCompressCodecsInfo 39 | }; 40 | 41 | }} 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/LockedStream.h: -------------------------------------------------------------------------------- 1 | // LockedStream.h 2 | 3 | #ifndef __LOCKEDSTREAM_H 4 | #define __LOCKEDSTREAM_H 5 | 6 | #include "../../Windows/Synchronization.h" 7 | #include "../../Common/MyCom.h" 8 | #include "../IStream.h" 9 | 10 | class CLockedInStream 11 | { 12 | CMyComPtr _stream; 13 | NWindows::NSynchronization::CCriticalSection _criticalSection; 14 | public: 15 | void Init(IInStream *stream) 16 | { _stream = stream; } 17 | HRESULT Read(UInt64 startPos, void *data, UInt32 size, UInt32 *processedSize); 18 | }; 19 | 20 | class CLockedSequentialInStreamImp: 21 | public ISequentialInStream, 22 | public CMyUnknownImp 23 | { 24 | CLockedInStream *_lockedInStream; 25 | UInt64 _pos; 26 | public: 27 | void Init(CLockedInStream *lockedInStream, UInt64 startPos) 28 | { 29 | _lockedInStream = lockedInStream; 30 | _pos = startPos; 31 | } 32 | 33 | MY_UNKNOWN_IMP 34 | 35 | STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/VirtThread.cpp: -------------------------------------------------------------------------------- 1 | // VirtThread.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "VirtThread.h" 6 | 7 | static THREAD_FUNC_DECL CoderThread(void *p) 8 | { 9 | for (;;) 10 | { 11 | CVirtThread *t = (CVirtThread *)p; 12 | t->StartEvent.Lock(); 13 | if (t->ExitEvent) 14 | return 0; 15 | t->Execute(); 16 | t->FinishedEvent.Set(); 17 | } 18 | } 19 | 20 | WRes CVirtThread::Create() 21 | { 22 | RINOK(StartEvent.CreateIfNotCreated()); 23 | RINOK(FinishedEvent.CreateIfNotCreated()); 24 | StartEvent.Reset(); 25 | FinishedEvent.Reset(); 26 | ExitEvent = false; 27 | if (Thread.IsCreated()) 28 | return S_OK; 29 | return Thread.Create(CoderThread, this); 30 | } 31 | 32 | void CVirtThread::Start() 33 | { 34 | ExitEvent = false; 35 | StartEvent.Set(); 36 | } 37 | 38 | CVirtThread::~CVirtThread() 39 | { 40 | ExitEvent = true; 41 | if (StartEvent.IsCreated()) 42 | StartEvent.Set(); 43 | if (Thread.IsCreated()) 44 | Thread.Wait(); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/7z/7zSpecStream.h: -------------------------------------------------------------------------------- 1 | // 7zSpecStream.h 2 | 3 | #ifndef __7Z_SPEC_STREAM_H 4 | #define __7Z_SPEC_STREAM_H 5 | 6 | #include "../../IStream.h" 7 | #include "../../ICoder.h" 8 | #include "../../../Common/MyCom.h" 9 | 10 | class CSequentialInStreamSizeCount2: 11 | public ISequentialInStream, 12 | public ICompressGetSubStreamSize, 13 | public CMyUnknownImp 14 | { 15 | CMyComPtr _stream; 16 | CMyComPtr _getSubStreamSize; 17 | UInt64 _size; 18 | public: 19 | void Init(ISequentialInStream *stream) 20 | { 21 | _stream = stream; 22 | _getSubStreamSize = 0; 23 | _stream.QueryInterface(IID_ICompressGetSubStreamSize, &_getSubStreamSize); 24 | _size = 0; 25 | } 26 | UInt64 GetSize() const { return _size; } 27 | 28 | MY_UNKNOWN_IMP1(ICompressGetSubStreamSize) 29 | 30 | STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); 31 | 32 | STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value); 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/BranchRegister.cpp: -------------------------------------------------------------------------------- 1 | // BranchRegister.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../Common/RegisterCodec.h" 6 | 7 | #include "BranchMisc.h" 8 | 9 | #define CREATE_CODEC(x) \ 10 | static void *CreateCodec ## x() { return (void *)(ICompressFilter *)(new C ## x ## _Decoder); } \ 11 | static void *CreateCodec ## x ## Out() { return (void *)(ICompressFilter *)(new C ## x ## _Encoder); } 12 | 13 | CREATE_CODEC(BC_PPC) 14 | CREATE_CODEC(BC_IA64) 15 | CREATE_CODEC(BC_ARM) 16 | CREATE_CODEC(BC_ARMT) 17 | CREATE_CODEC(BC_SPARC) 18 | 19 | #define METHOD_ITEM(x, id1, id2, name) { CreateCodec ## x, CreateCodec ## x ## Out, 0x03030000 + (id1 * 256) + id2, name, 1, true } 20 | 21 | static CCodecInfo g_CodecsInfo[] = 22 | { 23 | METHOD_ITEM(BC_PPC, 0x02, 0x05, L"PPC"), 24 | METHOD_ITEM(BC_IA64, 0x04, 1, L"IA64"), 25 | METHOD_ITEM(BC_ARM, 0x05, 1, L"ARM"), 26 | METHOD_ITEM(BC_ARMT, 0x07, 1, L"ARMT"), 27 | METHOD_ITEM(BC_SPARC, 0x08, 0x05, L"SPARC") 28 | }; 29 | 30 | REGISTER_CODECS(Branch) 31 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/LzmaEncoder.h: -------------------------------------------------------------------------------- 1 | // LzmaEncoder.h 2 | 3 | #ifndef __LZMA_ENCODER_H 4 | #define __LZMA_ENCODER_H 5 | 6 | #include 7 | 8 | #include "../../Common/MyCom.h" 9 | 10 | #include "../ICoder.h" 11 | 12 | namespace NCompress { 13 | namespace NLzma { 14 | 15 | class CEncoder: 16 | public ICompressCoder, 17 | public ICompressSetCoderProperties, 18 | public ICompressWriteCoderProperties, 19 | public CMyUnknownImp 20 | { 21 | CLzmaEncHandle _encoder; 22 | public: 23 | MY_UNKNOWN_IMP2(ICompressSetCoderProperties, ICompressWriteCoderProperties) 24 | 25 | STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, 26 | const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 27 | STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps); 28 | STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream); 29 | 30 | CEncoder(); 31 | virtual ~CEncoder(); 32 | }; 33 | 34 | }} 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/ImplodeHuffmanDecoder.h: -------------------------------------------------------------------------------- 1 | // ImplodeHuffmanDecoder.h 2 | 3 | #ifndef __IMPLODE_HUFFMAN_DECODER_H 4 | #define __IMPLODE_HUFFMAN_DECODER_H 5 | 6 | #include "../Common/InBuffer.h" 7 | 8 | #include "BitlDecoder.h" 9 | 10 | namespace NCompress { 11 | namespace NImplode { 12 | namespace NHuffman { 13 | 14 | const int kNumBitsInLongestCode = 16; 15 | 16 | typedef NBitl::CDecoder CInBit; 17 | 18 | class CDecoder 19 | { 20 | UInt32 m_Limitits[kNumBitsInLongestCode + 2]; // m_Limitits[i] = value limit for symbols with length = i 21 | UInt32 m_Positions[kNumBitsInLongestCode + 2]; // m_Positions[i] = index in m_Symbols[] of first symbol with length = i 22 | UInt32 m_NumSymbols; // number of symbols in m_Symbols 23 | UInt32 *m_Symbols; // symbols: at first with len=1 then 2, ... 15. 24 | public: 25 | CDecoder(UInt32 numSymbols); 26 | ~CDecoder(); 27 | 28 | bool SetCodeLengths(const Byte *codeLengths); 29 | UInt32 DecodeSymbol(CInBit *inStream); 30 | }; 31 | 32 | }}} 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/Lzma2Encoder.h: -------------------------------------------------------------------------------- 1 | // Lzma2Encoder.h 2 | 3 | #ifndef __LZMA2_ENCODER_H 4 | #define __LZMA2_ENCODER_H 5 | 6 | #include 7 | 8 | #include "../../Common/MyCom.h" 9 | 10 | #include "../ICoder.h" 11 | 12 | namespace NCompress { 13 | namespace NLzma2 { 14 | 15 | class CEncoder: 16 | public ICompressCoder, 17 | public ICompressSetCoderProperties, 18 | public ICompressWriteCoderProperties, 19 | public CMyUnknownImp 20 | { 21 | CLzma2EncHandle _encoder; 22 | public: 23 | MY_UNKNOWN_IMP2(ICompressSetCoderProperties, ICompressWriteCoderProperties) 24 | 25 | STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, 26 | const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 27 | STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps); 28 | STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream); 29 | 30 | CEncoder(); 31 | virtual ~CEncoder(); 32 | }; 33 | 34 | }} 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Common/OutStreamWithCRC.h: -------------------------------------------------------------------------------- 1 | // OutStreamWithCRC.h 2 | 3 | #ifndef __OUT_STREAM_WITH_CRC_H 4 | #define __OUT_STREAM_WITH_CRC_H 5 | 6 | #include 7 | 8 | #include "../../../Common/MyCom.h" 9 | 10 | #include "../../IStream.h" 11 | 12 | class COutStreamWithCRC: 13 | public ISequentialOutStream, 14 | public CMyUnknownImp 15 | { 16 | public: 17 | CMyComPtr _stream; 18 | UInt64 _size; 19 | UInt32 _crc; 20 | bool _calculate; 21 | public: 22 | MY_UNKNOWN_IMP 23 | STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); 24 | void SetStream(ISequentialOutStream *stream) { _stream = stream; } 25 | void ReleaseStream() { _stream.Release(); } 26 | void Init(bool calculate = true) 27 | { 28 | _size = 0; 29 | _calculate = calculate; 30 | _crc = CRC_INIT_VAL; 31 | } 32 | void InitCRC() { _crc = CRC_INIT_VAL; } 33 | UInt64 GetSize() const { return _size; } 34 | UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); } 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Common/OutStreamWithSha1.h: -------------------------------------------------------------------------------- 1 | // OutStreamWithSha1.h 2 | 3 | #ifndef __OUT_STREAM_WITH_SHA1_H 4 | #define __OUT_STREAM_WITH_SHA1_H 5 | 6 | #include "../../Crypto/Sha1.h" 7 | 8 | #include "../../../Common/MyCom.h" 9 | 10 | #include "../../IStream.h" 11 | 12 | class COutStreamWithSha1: 13 | public ISequentialOutStream, 14 | public CMyUnknownImp 15 | { 16 | public: 17 | CMyComPtr _stream; 18 | UInt64 _size; 19 | NCrypto::NSha1::CContext _sha; 20 | bool _calculate; 21 | public: 22 | MY_UNKNOWN_IMP 23 | STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); 24 | void SetStream(ISequentialOutStream *stream) { _stream = stream; } 25 | void ReleaseStream() { _stream.Release(); } 26 | void Init(bool calculate = true) 27 | { 28 | _size = 0; 29 | _calculate = calculate; 30 | _sha.Init(); 31 | } 32 | void InitSha1() { _sha.Init(); } 33 | UInt64 GetSize() const { return _size; } 34 | void Final(Byte *digest) { _sha.Final(digest); } 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Crypto/ZipStrong.h: -------------------------------------------------------------------------------- 1 | // Crypto/ZipStrong.h 2 | 3 | #ifndef __CRYPTO_ZIP_STRONG_H 4 | #define __CRYPTO_ZIP_STRONG_H 5 | 6 | #include "Common/Buffer.h" 7 | 8 | #include "../IPassword.h" 9 | 10 | #include "MyAes.h" 11 | 12 | namespace NCrypto { 13 | namespace NZipStrong { 14 | 15 | struct CKeyInfo 16 | { 17 | Byte MasterKey[32]; 18 | UInt32 KeySize; 19 | void SetPassword(const Byte *data, UInt32 size); 20 | }; 21 | 22 | class CBaseCoder: 23 | public CAesCbcDecoder, 24 | public ICryptoSetPassword 25 | { 26 | protected: 27 | CKeyInfo _key; 28 | CByteBuffer _buf; 29 | Byte *_bufAligned; 30 | public: 31 | STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size); 32 | }; 33 | 34 | class CDecoder: public CBaseCoder 35 | { 36 | UInt32 _ivSize; 37 | Byte _iv[16]; 38 | UInt32 _remSize; 39 | public: 40 | MY_UNKNOWN_IMP1(ICryptoSetPassword) 41 | HRESULT ReadHeader(ISequentialInStream *inStream, UInt32 crc, UInt64 unpackSize); 42 | HRESULT CheckPassword(bool &passwOK); 43 | }; 44 | 45 | }} 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /lib/codecs/rtl/7zBuf2.c: -------------------------------------------------------------------------------- 1 | /* 7zBuf2.c -- Byte Buffer 2 | 2008-10-04 : Igor Pavlov : Public domain */ 3 | 4 | #include 5 | #include "7zBuf.h" 6 | 7 | void DynBuf_Construct(CDynBuf *p) 8 | { 9 | p->data = 0; 10 | p->size = 0; 11 | p->pos = 0; 12 | } 13 | 14 | void DynBuf_SeekToBeg(CDynBuf *p) 15 | { 16 | p->pos = 0; 17 | } 18 | 19 | int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc) 20 | { 21 | if (size > p->size - p->pos) 22 | { 23 | size_t newSize = p->pos + size; 24 | Byte *data; 25 | newSize += newSize / 4; 26 | data = (Byte *)alloc->Alloc(alloc, newSize); 27 | if (data == 0) 28 | return 0; 29 | p->size = newSize; 30 | memcpy(data, p->data, p->pos); 31 | alloc->Free(alloc, p->data); 32 | p->data = data; 33 | } 34 | memcpy(p->data + p->pos, buf, size); 35 | p->pos += size; 36 | return 1; 37 | } 38 | 39 | void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc) 40 | { 41 | alloc->Free(alloc, p->data); 42 | p->data = 0; 43 | p->size = 0; 44 | p->pos = 0; 45 | } 46 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Nsis/NsisDecode.h: -------------------------------------------------------------------------------- 1 | // NsisDecode.h 2 | 3 | #ifndef __NSIS_DECODE_H 4 | #define __NSIS_DECODE_H 5 | 6 | #include "../../IStream.h" 7 | 8 | #include "../../Common/CreateCoder.h" 9 | 10 | namespace NArchive { 11 | namespace NNsis { 12 | 13 | namespace NMethodType 14 | { 15 | enum EEnum 16 | { 17 | kCopy, 18 | kDeflate, 19 | kBZip2, 20 | kLZMA 21 | }; 22 | } 23 | 24 | class CDecoder 25 | { 26 | NMethodType::EEnum _method; 27 | 28 | CMyComPtr _filterInStream; 29 | CMyComPtr _codecInStream; 30 | CMyComPtr _decoderInStream; 31 | 32 | public: 33 | void Release() 34 | { 35 | _filterInStream.Release(); 36 | _codecInStream.Release(); 37 | _decoderInStream.Release(); 38 | } 39 | HRESULT Init( 40 | DECL_EXTERNAL_CODECS_LOC_VARS 41 | IInStream *inStream, NMethodType::EEnum method, bool thereIsFilterFlag, bool &useFilter); 42 | HRESULT Read(void *data, size_t *processedSize); 43 | }; 44 | 45 | }} 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/ShrinkDecoder.h: -------------------------------------------------------------------------------- 1 | // ShrinkDecoder.h 2 | 3 | #ifndef __COMPRESS_SHRINK_DECODER_H 4 | #define __COMPRESS_SHRINK_DECODER_H 5 | 6 | #include "../../Common/MyCom.h" 7 | 8 | #include "../ICoder.h" 9 | 10 | namespace NCompress { 11 | namespace NShrink { 12 | 13 | const int kNumMaxBits = 13; 14 | const UInt32 kNumItems = 1 << kNumMaxBits; 15 | 16 | class CDecoder : 17 | public ICompressCoder, 18 | public CMyUnknownImp 19 | { 20 | UInt16 _parents[kNumItems]; 21 | Byte _suffixes[kNumItems]; 22 | Byte _stack[kNumItems]; 23 | bool _isFree[kNumItems]; 24 | bool _isParent[kNumItems]; 25 | 26 | public: 27 | MY_UNKNOWN_IMP 28 | 29 | HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream, 30 | const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 31 | 32 | STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, 33 | const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 34 | }; 35 | 36 | }} 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/OffsetStream.cpp: -------------------------------------------------------------------------------- 1 | // OffsetStream.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "Common/Defs.h" 6 | #include "OffsetStream.h" 7 | 8 | HRESULT COffsetOutStream::Init(IOutStream *stream, UInt64 offset) 9 | { 10 | _offset = offset; 11 | _stream = stream; 12 | return _stream->Seek(offset, STREAM_SEEK_SET, NULL); 13 | } 14 | 15 | STDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize) 16 | { 17 | return _stream->Write(data, size, processedSize); 18 | } 19 | 20 | STDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin, 21 | UInt64 *newPosition) 22 | { 23 | UInt64 absoluteNewPosition; 24 | if (seekOrigin == STREAM_SEEK_SET) 25 | offset += _offset; 26 | HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition); 27 | if (newPosition != NULL) 28 | *newPosition = absoluteNewPosition - _offset; 29 | return result; 30 | } 31 | 32 | STDMETHODIMP COffsetOutStream::SetSize(UInt64 newSize) 33 | { 34 | return _stream->SetSize(_offset + newSize); 35 | } 36 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Zip/ZipItemEx.h: -------------------------------------------------------------------------------- 1 | // Archive/ZipItemEx.h 2 | 3 | #ifndef __ARCHIVE_ZIP_ITEMEX_H 4 | #define __ARCHIVE_ZIP_ITEMEX_H 5 | 6 | #include "ZipHeader.h" 7 | #include "ZipItem.h" 8 | 9 | namespace NArchive { 10 | namespace NZip { 11 | 12 | class CItemEx: public CItem 13 | { 14 | public: 15 | UInt32 FileHeaderWithNameSize; 16 | UInt16 LocalExtraSize; 17 | 18 | UInt64 GetLocalFullSize() const 19 | { return FileHeaderWithNameSize + LocalExtraSize + PackSize + 20 | (HasDescriptor() ? NFileHeader::kDataDescriptorSize : 0); }; 21 | /* 22 | UInt64 GetLocalFullSize(bool isZip64) const 23 | { return FileHeaderWithNameSize + LocalExtraSize + PackSize + 24 | (HasDescriptor() ? (isZip64 ? NFileHeader::kDataDescriptor64Size : NFileHeader::kDataDescriptorSize) : 0); }; 25 | */ 26 | UInt64 GetLocalExtraPosition() const 27 | { return LocalHeaderPosition + FileHeaderWithNameSize; }; 28 | UInt64 GetDataPosition() const 29 | { return GetLocalExtraPosition() + LocalExtraSize; }; 30 | }; 31 | 32 | }} 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/Window.h: -------------------------------------------------------------------------------- 1 | // Windows/Window.h 2 | 3 | #ifndef __WINDOWS_WINDOW_H 4 | #define __WINDOWS_WINDOW_H 5 | 6 | #include "Windows/Defs.h" 7 | #include "Common/MyString.h" 8 | 9 | namespace NWindows { 10 | 11 | HWND GetDlgItem(HWND dialogWindow, int ControlID); 12 | void MySetWindowText(HWND wnd, LPCWSTR s); 13 | 14 | class CWindow 15 | { 16 | private: 17 | // bool ModifyStyleBase(int styleOffset, DWORD remove, DWORD add, UINT flags); 18 | protected: 19 | HWND _window; 20 | public: 21 | CWindow(HWND newWindow = NULL): _window(newWindow){}; 22 | CWindow& operator=(HWND newWindow) 23 | { 24 | _window = newWindow; 25 | return *this; 26 | } 27 | operator HWND() const { return _window; } 28 | void Attach(HWND newWindow) { _window = newWindow; } 29 | HWND Detach() 30 | { 31 | HWND window = _window; 32 | _window = NULL; 33 | return window; 34 | } 35 | virtual void SetText(LPCWSTR s) { MySetWindowText(_window, s); } 36 | virtual bool GetText(CSysString &s); 37 | bool IsEnabled(); 38 | }; 39 | 40 | } 41 | 42 | #endif 43 | 44 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/RegisterCodec.h: -------------------------------------------------------------------------------- 1 | // RegisterCodec.h 2 | 3 | #ifndef __REGISTERCODEC_H 4 | #define __REGISTERCODEC_H 5 | 6 | #include "../Common/MethodId.h" 7 | 8 | typedef void * (*CreateCodecP)(); 9 | struct CCodecInfo 10 | { 11 | CreateCodecP CreateDecoder; 12 | CreateCodecP CreateEncoder; 13 | CMethodId Id; 14 | const wchar_t *Name; 15 | UInt32 NumInStreams; 16 | bool IsFilter; 17 | }; 18 | 19 | void RegisterCodec(const CCodecInfo *codecInfo); 20 | 21 | #define REGISTER_CODEC_NAME(x) CRegisterCodec ## x 22 | 23 | #define REGISTER_CODEC(x) struct REGISTER_CODEC_NAME(x) { \ 24 | REGISTER_CODEC_NAME(x)() { RegisterCodec(&g_CodecInfo); }}; \ 25 | static REGISTER_CODEC_NAME(x) g_RegisterCodec; 26 | 27 | #define REGISTER_CODECS_NAME(x) CRegisterCodecs ## x 28 | #define REGISTER_CODECS(x) struct REGISTER_CODECS_NAME(x) { \ 29 | REGISTER_CODECS_NAME(x)() { for (int i = 0; i < sizeof(g_CodecsInfo) / sizeof(g_CodecsInfo[0]); i++) \ 30 | RegisterCodec(&g_CodecsInfo[i]); }}; \ 31 | static REGISTER_CODECS_NAME(x) g_RegisterCodecs; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /lib/codecs/rtl/7zCrcOpt.c: -------------------------------------------------------------------------------- 1 | /* 7zCrcOpt.c -- CRC32 calculation : optimized version 2 | 2009-11-23 : Igor Pavlov : Public domain */ 3 | 4 | #include "CpuArch.h" 5 | 6 | #ifdef MY_CPU_LE 7 | 8 | #define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) 9 | 10 | UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table) 11 | { 12 | const Byte *p = (const Byte *)data; 13 | for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++) 14 | v = CRC_UPDATE_BYTE_2(v, *p); 15 | for (; size >= 4; size -= 4, p += 4) 16 | { 17 | v ^= *(const UInt32 *)p; 18 | v = 19 | table[0x300 + (v & 0xFF)] ^ 20 | table[0x200 + ((v >> 8) & 0xFF)] ^ 21 | table[0x100 + ((v >> 16) & 0xFF)] ^ 22 | table[0x000 + ((v >> 24))]; 23 | } 24 | for (; size > 0; size--, p++) 25 | v = CRC_UPDATE_BYTE_2(v, *p); 26 | return v; 27 | } 28 | 29 | UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table) 30 | { 31 | return CrcUpdateT4(v, data, size, table); 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Crypto/HmacSha1.h: -------------------------------------------------------------------------------- 1 | // HmacSha1.h 2 | // Implements HMAC-SHA-1 (RFC2104, FIPS-198) 3 | 4 | #ifndef __CRYPTO_HMAC_SHA1_H 5 | #define __CRYPTO_HMAC_SHA1_H 6 | 7 | #include "Sha1.h" 8 | 9 | namespace NCrypto { 10 | namespace NSha1 { 11 | 12 | // Use: SetKey(key, keySize); for () Update(data, size); Final(mac, macSize); 13 | 14 | class CHmac 15 | { 16 | CContext _sha; 17 | CContext _sha2; 18 | public: 19 | void SetKey(const Byte *key, size_t keySize); 20 | void Update(const Byte *data, size_t dataSize) { _sha.Update(data, dataSize); } 21 | void Final(Byte *mac, size_t macSize = kDigestSize); 22 | }; 23 | 24 | class CHmac32 25 | { 26 | CContext32 _sha; 27 | CContext32 _sha2; 28 | public: 29 | void SetKey(const Byte *key, size_t keySize); 30 | void Update(const UInt32 *data, size_t dataSize) { _sha.Update(data, dataSize); } 31 | void Final(UInt32 *mac, size_t macSize = kDigestSizeInWords); 32 | 33 | // It'sa for hmac function. in,out: mac[kDigestSizeInWords]. 34 | void GetLoopXorDigest(UInt32 *mac, UInt32 numIteration); 35 | }; 36 | 37 | }} 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/NtCheck.h: -------------------------------------------------------------------------------- 1 | // Windows/NtCheck.h 2 | 3 | #ifndef __WINDOWS_NT_CHECK_H 4 | #define __WINDOWS_NT_CHECK_H 5 | 6 | #ifdef _WIN32 7 | 8 | #if !defined(_WIN64) && !defined(UNDER_CE) 9 | static inline bool IsItWindowsNT() 10 | { 11 | OSVERSIONINFO vi; 12 | vi.dwOSVersionInfoSize = sizeof(vi); 13 | return (::GetVersionEx(&vi) && vi.dwPlatformId == VER_PLATFORM_WIN32_NT); 14 | } 15 | #endif 16 | 17 | #ifndef _UNICODE 18 | #if defined(_WIN64) || defined(UNDER_CE) 19 | bool g_IsNT = true; 20 | #define SET_IS_NT 21 | #else 22 | bool g_IsNT = false; 23 | #define SET_IS_NT g_IsNT = IsItWindowsNT(); 24 | #endif 25 | #define NT_CHECK_ACTION 26 | // #define NT_CHECK_ACTION { NT_CHECK_FAIL_ACTION } 27 | #else 28 | #if !defined(_WIN64) && !defined(UNDER_CE) 29 | #define NT_CHECK_ACTION if (!IsItWindowsNT()) { NT_CHECK_FAIL_ACTION } 30 | #else 31 | #define NT_CHECK_ACTION 32 | #endif 33 | #define SET_IS_NT 34 | #endif 35 | 36 | #define NT_CHECK NT_CHECK_ACTION SET_IS_NT 37 | 38 | #else 39 | 40 | #define NT_CHECK 41 | 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/C_FileIO.h: -------------------------------------------------------------------------------- 1 | // Common/C_FileIO.h 2 | 3 | #ifndef __COMMON_C_FILEIO_H 4 | #define __COMMON_C_FILEIO_H 5 | 6 | #include 7 | #include 8 | 9 | #include "Types.h" 10 | #include "MyWindows.h" 11 | 12 | namespace NC { 13 | namespace NFile { 14 | namespace NIO { 15 | 16 | class CFileBase 17 | { 18 | protected: 19 | int _handle; 20 | bool OpenBinary(const char *name, int flags); 21 | public: 22 | CFileBase(): _handle(-1) {}; 23 | ~CFileBase() { Close(); } 24 | bool Close(); 25 | bool GetLength(UInt64 &length) const; 26 | off_t Seek(off_t distanceToMove, int moveMethod) const; 27 | }; 28 | 29 | class CInFile: public CFileBase 30 | { 31 | public: 32 | bool Open(const char *name); 33 | bool OpenShared(const char *name, bool shareForWrite); 34 | ssize_t Read(void *data, size_t size); 35 | }; 36 | 37 | class COutFile: public CFileBase 38 | { 39 | public: 40 | bool Create(const char *name, bool createAlways); 41 | bool Open(const char *name, DWORD creationDisposition); 42 | ssize_t Write(const void *data, size_t size); 43 | }; 44 | 45 | }}} 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Rar/RarVolumeInStream.h: -------------------------------------------------------------------------------- 1 | // RarVolumeInStream.h 2 | 3 | #ifndef __RAR_VOLUME_IN_STREAM_H 4 | #define __RAR_VOLUME_IN_STREAM_H 5 | 6 | #include "../../IStream.h" 7 | #include "RarIn.h" 8 | 9 | namespace NArchive { 10 | namespace NRar { 11 | 12 | struct CRefItem 13 | { 14 | int VolumeIndex; 15 | int ItemIndex; 16 | int NumItems; 17 | }; 18 | 19 | class CFolderInStream: 20 | public ISequentialInStream, 21 | public CMyUnknownImp 22 | { 23 | public: 24 | MY_UNKNOWN_IMP 25 | 26 | STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); 27 | 28 | private: 29 | CObjectVector *_archives; 30 | const CObjectVector *_items; 31 | CRefItem _refItem; 32 | int _curIndex; 33 | UInt32 _crc; 34 | bool _fileIsOpen; 35 | CMyComPtr _stream; 36 | 37 | HRESULT OpenStream(); 38 | HRESULT CloseStream(); 39 | public: 40 | void Init(CObjectVector *archives, 41 | const CObjectVector *items, 42 | const CRefItem &refItem); 43 | 44 | CRecordVector CRCs; 45 | }; 46 | 47 | }} 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Crypto/RarAes.h: -------------------------------------------------------------------------------- 1 | // Crypto/RarAes.h 2 | 3 | #ifndef __CRYPTO_RAR_AES_H 4 | #define __CRYPTO_RAR_AES_H 5 | 6 | #include 7 | 8 | #include "Common/Buffer.h" 9 | 10 | #include "../IPassword.h" 11 | 12 | #include "MyAes.h" 13 | 14 | namespace NCrypto { 15 | namespace NRar29 { 16 | 17 | const UInt32 kRarAesKeySize = 16; 18 | 19 | class CDecoder: 20 | public CAesCbcDecoder, 21 | public ICompressSetDecoderProperties2, 22 | public ICryptoSetPassword 23 | { 24 | Byte _salt[8]; 25 | bool _thereIsSalt; 26 | CByteBuffer buffer; 27 | Byte aesKey[kRarAesKeySize]; 28 | Byte _aesInit[AES_BLOCK_SIZE]; 29 | bool _needCalculate; 30 | bool _rar350Mode; 31 | 32 | void Calculate(); 33 | public: 34 | MY_UNKNOWN_IMP2( 35 | ICryptoSetPassword, 36 | ICompressSetDecoderProperties2) 37 | STDMETHOD(Init)(); 38 | STDMETHOD(CryptoSetPassword)(const Byte *aData, UInt32 aSize); 39 | STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size); 40 | 41 | CDecoder(); 42 | void SetRar350Mode(bool rar350Mode) { _rar350Mode = rar350Mode; } 43 | }; 44 | 45 | }} 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Cab/CabBlockInStream.h: -------------------------------------------------------------------------------- 1 | // CabBlockInStream.cpp 2 | 3 | #ifndef __CABBLOCKINSTREAM_H 4 | #define __CABBLOCKINSTREAM_H 5 | 6 | #include "Common/MyCom.h" 7 | #include "../../IStream.h" 8 | 9 | namespace NArchive { 10 | namespace NCab { 11 | 12 | class CCabBlockInStream: 13 | public ISequentialInStream, 14 | public CMyUnknownImp 15 | { 16 | CMyComPtr _stream; 17 | Byte *_buffer; 18 | UInt32 _pos; 19 | UInt32 _size; 20 | 21 | public: 22 | UInt32 TotalPackSize; 23 | UInt32 ReservedSize; 24 | bool DataError; 25 | bool MsZip; 26 | 27 | CCabBlockInStream(): _buffer(0), ReservedSize(0), MsZip(false), DataError(false), TotalPackSize(0) {} 28 | ~CCabBlockInStream(); 29 | bool Create(); 30 | void SetStream(ISequentialInStream *stream) { _stream = stream; } 31 | 32 | void InitForNewFolder() { TotalPackSize = 0; } 33 | void InitForNewBlock() { _size = 0; } 34 | 35 | MY_UNKNOWN_IMP 36 | 37 | STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); 38 | 39 | HRESULT PreRead(UInt32 &packSize, UInt32 &unpackSize); 40 | }; 41 | 42 | }} 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /lib/codecs/rtl/7zCrcT8.c: -------------------------------------------------------------------------------- 1 | /* 7zCrcT8.c -- CRC32 calculation with 8 tables 2 | 2008-03-19 3 | Igor Pavlov 4 | Public domain */ 5 | 6 | #include "7zCrc.h" 7 | 8 | #define kCrcPoly 0xEDB88320 9 | #define CRC_NUM_TABLES 8 10 | 11 | UInt32 g_CrcTable[256 * CRC_NUM_TABLES]; 12 | 13 | void MY_FAST_CALL CrcGenerateTable() 14 | { 15 | UInt32 i; 16 | for (i = 0; i < 256; i++) 17 | { 18 | UInt32 r = i; 19 | int j; 20 | for (j = 0; j < 8; j++) 21 | r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1)); 22 | g_CrcTable[i] = r; 23 | } 24 | #if CRC_NUM_TABLES > 1 25 | for (; i < 256 * CRC_NUM_TABLES; i++) 26 | { 27 | UInt32 r = g_CrcTable[i - 256]; 28 | g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8); 29 | } 30 | #endif 31 | } 32 | 33 | UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table); 34 | 35 | UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size) 36 | { 37 | return CrcUpdateT8(v, data, size, g_CrcTable); 38 | } 39 | 40 | UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size) 41 | { 42 | return CrcUpdateT8(CRC_INIT_VAL, data, size, g_CrcTable) ^ 0xFFFFFFFF; 43 | } 44 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/7z/7zCompressionMode.h: -------------------------------------------------------------------------------- 1 | // 7zCompressionMode.h 2 | 3 | #ifndef __7Z_COMPRESSION_MODE_H 4 | #define __7Z_COMPRESSION_MODE_H 5 | 6 | #include "../../../Common/MyString.h" 7 | 8 | #include "../../../Windows/PropVariant.h" 9 | 10 | #include "../../Common/MethodProps.h" 11 | 12 | namespace NArchive { 13 | namespace N7z { 14 | 15 | struct CMethodFull: public CMethod 16 | { 17 | UInt32 NumInStreams; 18 | UInt32 NumOutStreams; 19 | bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); } 20 | }; 21 | 22 | struct CBind 23 | { 24 | UInt32 InCoder; 25 | UInt32 InStream; 26 | UInt32 OutCoder; 27 | UInt32 OutStream; 28 | }; 29 | 30 | struct CCompressionMethodMode 31 | { 32 | CObjectVector Methods; 33 | CRecordVector Binds; 34 | #ifndef _7ZIP_ST 35 | UInt32 NumThreads; 36 | #endif 37 | bool PasswordIsDefined; 38 | UString Password; 39 | 40 | bool IsEmpty() const { return (Methods.IsEmpty() && !PasswordIsDefined); } 41 | CCompressionMethodMode(): PasswordIsDefined(false) 42 | #ifndef _7ZIP_ST 43 | , NumThreads(1) 44 | #endif 45 | {} 46 | }; 47 | 48 | }} 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/ZDecoder.h: -------------------------------------------------------------------------------- 1 | // ZDecoder.h 2 | 3 | #ifndef __COMPRESS_Z_DECODER_H 4 | #define __COMPRESS_Z_DECODER_H 5 | 6 | #include "../../Common/MyCom.h" 7 | 8 | #include "../ICoder.h" 9 | 10 | namespace NCompress { 11 | namespace NZ { 12 | 13 | class CDecoder: 14 | public ICompressCoder, 15 | public ICompressSetDecoderProperties2, 16 | public CMyUnknownImp 17 | { 18 | UInt16 *_parents; 19 | Byte *_suffixes; 20 | Byte *_stack; 21 | Byte _properties; 22 | int _numMaxBits; 23 | 24 | public: 25 | CDecoder(): _parents(0), _suffixes(0), _stack(0), _properties(0), _numMaxBits(0) {}; 26 | ~CDecoder(); 27 | void Free(); 28 | 29 | MY_UNKNOWN_IMP1(ICompressSetDecoderProperties2) 30 | 31 | HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream, 32 | const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 33 | 34 | STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, 35 | const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 36 | 37 | STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size); 38 | }; 39 | 40 | }} 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/Lzx86Converter.h: -------------------------------------------------------------------------------- 1 | // Lzx86Converter.h 2 | 3 | #ifndef __LZX_86_CONVERTER_H 4 | #define __LZX_86_CONVERTER_H 5 | 6 | #include "../../Common/MyCom.h" 7 | 8 | #include "../IStream.h" 9 | 10 | namespace NCompress { 11 | namespace NLzx { 12 | 13 | const int kUncompressedBlockSize = 1 << 15; 14 | 15 | class Cx86ConvertOutStream: 16 | public ISequentialOutStream, 17 | public CMyUnknownImp 18 | { 19 | CMyComPtr m_Stream; 20 | UInt32 m_ProcessedSize; 21 | UInt32 m_Pos; 22 | UInt32 m_TranslationSize; 23 | bool m_TranslationMode; 24 | Byte m_Buffer[kUncompressedBlockSize]; 25 | 26 | void MakeTranslation(); 27 | public: 28 | void SetStream(ISequentialOutStream *outStream) { m_Stream = outStream; } 29 | void ReleaseStream() { m_Stream.Release(); } 30 | void Init(bool translationMode, UInt32 translationSize) 31 | { 32 | m_TranslationMode = translationMode; 33 | m_TranslationSize = translationSize; 34 | m_ProcessedSize = 0; 35 | m_Pos = 0; 36 | } 37 | HRESULT Flush(); 38 | 39 | MY_UNKNOWN_IMP 40 | 41 | STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); 42 | }; 43 | 44 | }} 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/ProgressUtils.cpp: -------------------------------------------------------------------------------- 1 | // ProgressUtils.h 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "ProgressUtils.h" 6 | 7 | CLocalProgress::CLocalProgress() 8 | { 9 | ProgressOffset = InSize = OutSize = 0; 10 | SendRatio = SendProgress = true; 11 | } 12 | 13 | void CLocalProgress::Init(IProgress *progress, bool inSizeIsMain) 14 | { 15 | _ratioProgress.Release(); 16 | _progress = progress; 17 | _progress.QueryInterface(IID_ICompressProgressInfo, &_ratioProgress); 18 | _inSizeIsMain = inSizeIsMain; 19 | } 20 | 21 | STDMETHODIMP CLocalProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) 22 | { 23 | UInt64 inSizeNew = InSize, outSizeNew = OutSize; 24 | if (inSize) 25 | inSizeNew += (*inSize); 26 | if (outSize) 27 | outSizeNew += (*outSize); 28 | if (SendRatio && _ratioProgress) 29 | { 30 | RINOK(_ratioProgress->SetRatioInfo(&inSizeNew, &outSizeNew)); 31 | } 32 | inSizeNew += ProgressOffset; 33 | outSizeNew += ProgressOffset; 34 | if (SendProgress) 35 | return _progress->SetCompleted(_inSizeIsMain ? &inSizeNew : &outSizeNew); 36 | return S_OK; 37 | } 38 | 39 | HRESULT CLocalProgress::SetCur() 40 | { 41 | return SetRatioInfo(NULL, NULL); 42 | } 43 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/PropVariantUtils.h: -------------------------------------------------------------------------------- 1 | // Windows/PropVariantUtils.h 2 | 3 | #ifndef __PROP_VARIANT_UTILS_H 4 | #define __PROP_VARIANT_UTILS_H 5 | 6 | #include "Common/MyString.h" 7 | #include "PropVariant.h" 8 | 9 | struct CUInt32PCharPair 10 | { 11 | UInt32 Value; 12 | const char *Name; 13 | }; 14 | 15 | void StringToProp(const AString &s, NWindows::NCOM::CPropVariant &prop); 16 | void PairToProp(const CUInt32PCharPair *pairs, unsigned num, UInt32 value, NWindows::NCOM::CPropVariant &prop); 17 | 18 | AString FlagsToString(const CUInt32PCharPair *pairs, unsigned num, UInt32 flags); 19 | void FlagsToProp(const CUInt32PCharPair *pairs, unsigned num, UInt32 flags, NWindows::NCOM::CPropVariant &prop); 20 | 21 | AString TypeToString(const char *table[], unsigned num, UInt32 value); 22 | void TypeToProp(const char *table[], unsigned num, UInt32 value, NWindows::NCOM::CPropVariant &prop); 23 | 24 | #define PAIR_TO_PROP(pairs, value, prop) PairToProp(pairs, sizeof(pairs) / sizeof(pairs[0]), value, prop) 25 | #define FLAGS_TO_PROP(pairs, value, prop) FlagsToProp(pairs, sizeof(pairs) / sizeof(pairs[0]), value, prop) 26 | #define TYPE_TO_PROP(table, value, prop) TypeToProp(table, sizeof(table) / sizeof(table[0]), value, prop) 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/InOutTempBuffer.h: -------------------------------------------------------------------------------- 1 | // InOutTempBuffer.h 2 | 3 | #ifndef __IN_OUT_TEMP_BUFFER_H 4 | #define __IN_OUT_TEMP_BUFFER_H 5 | 6 | #include "../../Common/MyCom.h" 7 | #include "../../Windows/FileDir.h" 8 | #include "../../Windows/FileIO.h" 9 | 10 | #include "../IStream.h" 11 | 12 | class CInOutTempBuffer 13 | { 14 | NWindows::NFile::NDirectory::CTempFile _tempFile; 15 | NWindows::NFile::NIO::COutFile _outFile; 16 | Byte *_buf; 17 | UInt32 _bufPos; 18 | CSysString _tempFileName; 19 | bool _tempFileCreated; 20 | UInt64 _size; 21 | UInt32 _crc; 22 | 23 | bool WriteToFile(const void *data, UInt32 size); 24 | public: 25 | CInOutTempBuffer(); 26 | ~CInOutTempBuffer(); 27 | void Create(); 28 | 29 | void InitWriting(); 30 | bool Write(const void *data, UInt32 size); 31 | 32 | HRESULT WriteToStream(ISequentialOutStream *stream); 33 | UInt64 GetDataSize() const { return _size; } 34 | }; 35 | 36 | class CSequentialOutTempBufferImp: 37 | public ISequentialOutStream, 38 | public CMyUnknownImp 39 | { 40 | CInOutTempBuffer *_buf; 41 | public: 42 | void Init(CInOutTempBuffer *buffer) { _buf = buffer; } 43 | MY_UNKNOWN_IMP 44 | 45 | STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/PpmdEncoder.h: -------------------------------------------------------------------------------- 1 | // PpmdEncoder.h 2 | // 2009-03-11 : Igor Pavlov : Public domain 3 | 4 | #ifndef __COMPRESS_PPMD_ENCODER_H 5 | #define __COMPRESS_PPMD_ENCODER_H 6 | 7 | #include 8 | 9 | #include "../../Common/MyCom.h" 10 | 11 | #include "../ICoder.h" 12 | 13 | #include "../Common/CWrappers.h" 14 | 15 | namespace NCompress { 16 | namespace NPpmd { 17 | 18 | class CEncoder : 19 | public ICompressCoder, 20 | public ICompressSetCoderProperties, 21 | public ICompressWriteCoderProperties, 22 | public CMyUnknownImp 23 | { 24 | Byte *_inBuf; 25 | CByteOutBufWrap _outStream; 26 | CPpmd7z_RangeEnc _rangeEnc; 27 | CPpmd7 _ppmd; 28 | 29 | UInt32 _usedMemSize; 30 | Byte _order; 31 | 32 | public: 33 | MY_UNKNOWN_IMP2( 34 | ICompressSetCoderProperties, 35 | ICompressWriteCoderProperties) 36 | 37 | STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, 38 | const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 39 | STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps); 40 | STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream); 41 | 42 | CEncoder(); 43 | ~CEncoder(); 44 | }; 45 | 46 | }} 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/ProgressMt.h: -------------------------------------------------------------------------------- 1 | // ProgressMt.h 2 | 3 | #ifndef __PROGRESSMT_H 4 | #define __PROGRESSMT_H 5 | 6 | #include "../../Common/MyCom.h" 7 | #include "../../Common/MyVector.h" 8 | #include "../../Windows/Synchronization.h" 9 | 10 | #include "../ICoder.h" 11 | #include "../IProgress.h" 12 | 13 | class CMtCompressProgressMixer 14 | { 15 | CMyComPtr _progress; 16 | CRecordVector InSizes; 17 | CRecordVector OutSizes; 18 | UInt64 TotalInSize; 19 | UInt64 TotalOutSize; 20 | public: 21 | NWindows::NSynchronization::CCriticalSection CriticalSection; 22 | void Init(int numItems, ICompressProgressInfo *progress); 23 | void Reinit(int index); 24 | HRESULT SetRatioInfo(int index, const UInt64 *inSize, const UInt64 *outSize); 25 | }; 26 | 27 | class CMtCompressProgress: 28 | public ICompressProgressInfo, 29 | public CMyUnknownImp 30 | { 31 | CMtCompressProgressMixer *_progress; 32 | int _index; 33 | public: 34 | void Init(CMtCompressProgressMixer *progress, int index) 35 | { 36 | _progress = progress; 37 | _index = index; 38 | } 39 | void Reinit() { _progress->Reinit(_index); } 40 | 41 | MY_UNKNOWN_IMP 42 | 43 | STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize); 44 | }; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Crypto/ZipCrypto.h: -------------------------------------------------------------------------------- 1 | // Crypto/ZipCrypto.h 2 | 3 | #ifndef __CRYPTO_ZIP_CRYPTO_H 4 | #define __CRYPTO_ZIP_CRYPTO_H 5 | 6 | #include "Common/MyCom.h" 7 | 8 | #include "../ICoder.h" 9 | #include "../IPassword.h" 10 | 11 | namespace NCrypto { 12 | namespace NZip { 13 | 14 | const unsigned kHeaderSize = 12; 15 | 16 | class CCipher: 17 | public ICompressFilter, 18 | public ICryptoSetPassword, 19 | public CMyUnknownImp 20 | { 21 | UInt32 Keys[3]; 22 | UInt32 Keys2[3]; 23 | 24 | protected: 25 | void UpdateKeys(Byte b); 26 | Byte DecryptByteSpec(); 27 | void RestoreKeys() 28 | { 29 | for (int i = 0; i < 3; i++) 30 | Keys[i] = Keys2[i]; 31 | } 32 | 33 | public: 34 | STDMETHOD(Init)(); 35 | STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size); 36 | }; 37 | 38 | class CEncoder: public CCipher 39 | { 40 | public: 41 | MY_UNKNOWN_IMP1(ICryptoSetPassword) 42 | STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size); 43 | HRESULT WriteHeader(ISequentialOutStream *outStream, UInt32 crc); 44 | }; 45 | 46 | class CDecoder: public CCipher 47 | { 48 | public: 49 | MY_UNKNOWN_IMP1(ICryptoSetPassword) 50 | STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size); 51 | HRESULT ReadHeader(ISequentialInStream *inStream); 52 | }; 53 | 54 | }} 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/FileName.cpp: -------------------------------------------------------------------------------- 1 | // Windows/FileName.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "Windows/FileName.h" 6 | #include "Common/Wildcard.h" 7 | 8 | namespace NWindows { 9 | namespace NFile { 10 | namespace NName { 11 | 12 | void NormalizeDirPathPrefix(CSysString &dirPath) 13 | { 14 | if (dirPath.IsEmpty()) 15 | return; 16 | if (dirPath.ReverseFind(kDirDelimiter) != dirPath.Length() - 1) 17 | dirPath += kDirDelimiter; 18 | } 19 | 20 | #ifndef _UNICODE 21 | void NormalizeDirPathPrefix(UString &dirPath) 22 | { 23 | if (dirPath.IsEmpty()) 24 | return; 25 | if (dirPath.ReverseFind(wchar_t(kDirDelimiter)) != dirPath.Length() - 1) 26 | dirPath += wchar_t(kDirDelimiter); 27 | } 28 | #endif 29 | 30 | const wchar_t kExtensionDelimiter = L'.'; 31 | 32 | void SplitNameToPureNameAndExtension(const UString &fullName, 33 | UString &pureName, UString &extensionDelimiter, UString &extension) 34 | { 35 | int index = fullName.ReverseFind(kExtensionDelimiter); 36 | if (index < 0) 37 | { 38 | pureName = fullName; 39 | extensionDelimiter.Empty(); 40 | extension.Empty(); 41 | } 42 | else 43 | { 44 | pureName = fullName.Left(index); 45 | extensionDelimiter = kExtensionDelimiter; 46 | extension = fullName.Mid(index + 1); 47 | } 48 | } 49 | 50 | }}} 51 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/MyGuidDef.h: -------------------------------------------------------------------------------- 1 | // Common/MyGuidDef.h 2 | 3 | #ifndef GUID_DEFINED 4 | #define GUID_DEFINED 5 | 6 | #include "Types.h" 7 | 8 | typedef struct { 9 | UInt32 Data1; 10 | UInt16 Data2; 11 | UInt16 Data3; 12 | unsigned char Data4[8]; 13 | } GUID; 14 | 15 | #ifdef __cplusplus 16 | #define REFGUID const GUID & 17 | #else 18 | #define REFGUID const GUID * 19 | #endif 20 | 21 | #define REFCLSID REFGUID 22 | #define REFIID REFGUID 23 | 24 | #ifdef __cplusplus 25 | inline int operator==(REFGUID g1, REFGUID g2) 26 | { 27 | for (int i = 0; i < (int)sizeof(g1); i++) 28 | if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i]) 29 | return 0; 30 | return 1; 31 | } 32 | inline int operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); } 33 | #endif 34 | 35 | #ifdef __cplusplus 36 | #define MY_EXTERN_C extern "C" 37 | #else 38 | #define MY_EXTERN_C extern 39 | #endif 40 | 41 | #endif 42 | 43 | 44 | #ifdef DEFINE_GUID 45 | #undef DEFINE_GUID 46 | #endif 47 | 48 | #ifdef INITGUID 49 | #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ 50 | MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } 51 | #else 52 | #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ 53 | MY_EXTERN_C const GUID name 54 | #endif 55 | -------------------------------------------------------------------------------- /lib/codecs/rtl/LzmaUtil/Lzma86Dec.h: -------------------------------------------------------------------------------- 1 | /* Lzma86Dec.h -- LZMA + x86 (BCJ) Filter Decoder 2 | 2009-02-07 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZMA86_DEC_H 5 | #define __LZMA86_DEC_H 6 | 7 | #include "../Types.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /* 14 | Lzma86_GetUnpackSize: 15 | In: 16 | src - input data 17 | srcLen - input data size 18 | Out: 19 | unpackSize - size of uncompressed stream 20 | Return code: 21 | SZ_OK - OK 22 | SZ_ERROR_INPUT_EOF - Error in headers 23 | */ 24 | 25 | SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize); 26 | 27 | /* 28 | Lzma86_Decode: 29 | In: 30 | dest - output data 31 | destLen - output data size 32 | src - input data 33 | srcLen - input data size 34 | Out: 35 | destLen - processed output size 36 | srcLen - processed input size 37 | Return code: 38 | SZ_OK - OK 39 | SZ_ERROR_DATA - Data error 40 | SZ_ERROR_MEM - Memory allocation error 41 | SZ_ERROR_UNSUPPORTED - unsupported file 42 | SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer 43 | */ 44 | 45 | SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/Thread.h: -------------------------------------------------------------------------------- 1 | // Windows/Thread.h 2 | 3 | #ifndef __WINDOWS_THREAD_H 4 | #define __WINDOWS_THREAD_H 5 | 6 | #include "Defs.h" 7 | 8 | extern "C" 9 | { 10 | #include 11 | } 12 | 13 | namespace NWindows { 14 | 15 | class CThread 16 | { 17 | ::CThread thread; 18 | public: 19 | CThread() { Thread_Construct(&thread); } 20 | ~CThread() { Close(); } 21 | bool IsCreated() { return Thread_WasCreated(&thread) != 0; } 22 | WRes Close() { return Thread_Close(&thread); } 23 | WRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter) 24 | { return Thread_Create(&thread, startAddress, parameter); } 25 | WRes Wait() { return Thread_Wait(&thread); } 26 | 27 | #ifdef _WIN32 28 | operator HANDLE() { return thread; } 29 | void Attach(HANDLE handle) { thread = handle; } 30 | HANDLE Detach() { HANDLE h = thread; thread = NULL; return h; } 31 | DWORD Resume() { return ::ResumeThread(thread); } 32 | DWORD Suspend() { return ::SuspendThread(thread); } 33 | bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread, exitCode)); } 34 | int GetPriority() { return ::GetThreadPriority(thread); } 35 | bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread, priority)); } 36 | #endif 37 | }; 38 | 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Crypto/MyAes.cpp: -------------------------------------------------------------------------------- 1 | // Crypto/MyAes.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "MyAes.h" 6 | 7 | namespace NCrypto { 8 | 9 | struct CAesTabInit { CAesTabInit() { AesGenTables();} } g_AesTabInit; 10 | 11 | CAesCbcCoder::CAesCbcCoder() 12 | { 13 | _offset = ((0 - (unsigned)(ptrdiff_t)_aes) & 0xF) / sizeof(UInt32); 14 | } 15 | 16 | STDMETHODIMP CAesCbcCoder::Init() { return S_OK; } 17 | 18 | STDMETHODIMP_(UInt32) CAesCbcCoder::Filter(Byte *data, UInt32 size) 19 | { 20 | if (size == 0) 21 | return 0; 22 | if (size < AES_BLOCK_SIZE) 23 | return AES_BLOCK_SIZE; 24 | size >>= 4; 25 | _codeFunc(_aes + _offset, data, size); 26 | return size << 4; 27 | } 28 | 29 | STDMETHODIMP CAesCbcCoder::SetKey(const Byte *data, UInt32 size) 30 | { 31 | if ((size & 0x7) != 0 || size < 16 || size > 32) 32 | return E_INVALIDARG; 33 | _setKeyFunc(_aes + _offset + 4, data, size); 34 | return S_OK; 35 | } 36 | 37 | STDMETHODIMP CAesCbcCoder::SetInitVector(const Byte *data, UInt32 size) 38 | { 39 | if (size != AES_BLOCK_SIZE) 40 | return E_INVALIDARG; 41 | AesCbc_Init(_aes + _offset, data); 42 | return S_OK; 43 | } 44 | 45 | CAesCbcEncoder::CAesCbcEncoder() { _codeFunc = g_AesCbc_Encode; _setKeyFunc = Aes_SetKey_Enc; } 46 | CAesCbcDecoder::CAesCbcDecoder() { _codeFunc = g_AesCbc_Decode; _setKeyFunc = Aes_SetKey_Dec; } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Crypto/Rar20Crypto.h: -------------------------------------------------------------------------------- 1 | // Crypto/Rar20Crypto.h 2 | 3 | #ifndef __CRYPTO_RAR20_CRYPTO_H 4 | #define __CRYPTO_RAR20_CRYPTO_H 5 | 6 | #include "Common/MyCom.h" 7 | 8 | #include "../ICoder.h" 9 | #include "../IPassword.h" 10 | 11 | namespace NCrypto { 12 | namespace NRar20 { 13 | 14 | class CData 15 | { 16 | Byte SubstTable[256]; 17 | UInt32 Keys[4]; 18 | 19 | UInt32 SubstLong(UInt32 t) 20 | { 21 | return (UInt32)SubstTable[(int)t & 255] | 22 | ((UInt32)SubstTable[(int)(t >> 8) & 255] << 8) | 23 | ((UInt32)SubstTable[(int)(t >> 16) & 255] << 16) | 24 | ((UInt32)SubstTable[(int)(t >> 24) & 255] << 24); 25 | } 26 | void UpdateKeys(const Byte *data); 27 | void CryptBlock(Byte *buf, bool encrypt); 28 | public: 29 | void EncryptBlock(Byte *buf) { CryptBlock(buf, true); } 30 | void DecryptBlock(Byte *buf) { CryptBlock(buf, false); } 31 | void SetPassword(const Byte *password, UInt32 passwordLen); 32 | }; 33 | 34 | class CDecoder: 35 | public ICompressFilter, 36 | public ICryptoSetPassword, 37 | public CMyUnknownImp 38 | { 39 | CData _cipher; 40 | public: 41 | MY_UNKNOWN_IMP1(ICryptoSetPassword) 42 | 43 | STDMETHOD(Init)(); 44 | STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size); 45 | STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size); 46 | }; 47 | 48 | }} 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Rar/RarItem.cpp: -------------------------------------------------------------------------------- 1 | // RarItem.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "RarItem.h" 6 | 7 | namespace NArchive{ 8 | namespace NRar{ 9 | 10 | bool CItem::IgnoreItem() const 11 | { 12 | switch(HostOS) 13 | { 14 | case NHeader::NFile::kHostMSDOS: 15 | case NHeader::NFile::kHostOS2: 16 | case NHeader::NFile::kHostWin32: 17 | return ((Attrib & NHeader::NFile::kLabelFileAttribute) != 0); 18 | } 19 | return false; 20 | } 21 | 22 | bool CItem::IsDir() const 23 | { 24 | if (GetDictSize() == NHeader::NFile::kDictDirectoryValue) 25 | return true; 26 | switch(HostOS) 27 | { 28 | case NHeader::NFile::kHostMSDOS: 29 | case NHeader::NFile::kHostOS2: 30 | case NHeader::NFile::kHostWin32: 31 | if ((Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0) 32 | return true; 33 | } 34 | return false; 35 | } 36 | 37 | UInt32 CItem::GetWinAttributes() const 38 | { 39 | UInt32 winAttributes; 40 | switch(HostOS) 41 | { 42 | case NHeader::NFile::kHostMSDOS: 43 | case NHeader::NFile::kHostOS2: 44 | case NHeader::NFile::kHostWin32: 45 | winAttributes = Attrib; 46 | break; 47 | default: 48 | winAttributes = 0; // must be converted from unix value; 49 | } 50 | if (IsDir()) 51 | winAttributes |= NHeader::NFile::kWinFileDirectoryAttributeMask; 52 | return winAttributes; 53 | } 54 | 55 | }} 56 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Common/InStreamWithCRC.cpp: -------------------------------------------------------------------------------- 1 | // InStreamWithCRC.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "InStreamWithCRC.h" 6 | 7 | STDMETHODIMP CSequentialInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize) 8 | { 9 | UInt32 realProcessedSize; 10 | HRESULT result = _stream->Read(data, size, &realProcessedSize); 11 | _size += realProcessedSize; 12 | if (size > 0 && realProcessedSize == 0) 13 | _wasFinished = true; 14 | _crc = CrcUpdate(_crc, data, realProcessedSize); 15 | if(processedSize != NULL) 16 | *processedSize = realProcessedSize; 17 | return result; 18 | } 19 | 20 | STDMETHODIMP CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize) 21 | { 22 | UInt32 realProcessedSize; 23 | HRESULT result = _stream->Read(data, size, &realProcessedSize); 24 | /* 25 | if (size > 0 && realProcessedSize == 0) 26 | _wasFinished = true; 27 | */ 28 | _size += realProcessedSize; 29 | _crc = CrcUpdate(_crc, data, realProcessedSize); 30 | if(processedSize != NULL) 31 | *processedSize = realProcessedSize; 32 | return result; 33 | } 34 | 35 | STDMETHODIMP CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) 36 | { 37 | if (seekOrigin != STREAM_SEEK_SET || offset != 0) 38 | return E_FAIL; 39 | _size = 0; 40 | _crc = CRC_INIT_VAL; 41 | return _stream->Seek(offset, seekOrigin, newPosition); 42 | } 43 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/BZip2Const.h: -------------------------------------------------------------------------------- 1 | // Compress/BZip2Const.h 2 | 3 | #ifndef __COMPRESS_BZIP2_CONST_H 4 | #define __COMPRESS_BZIP2_CONST_H 5 | 6 | namespace NCompress { 7 | namespace NBZip2 { 8 | 9 | const Byte kArSig0 = 'B'; 10 | const Byte kArSig1 = 'Z'; 11 | const Byte kArSig2 = 'h'; 12 | const Byte kArSig3 = '0'; 13 | 14 | const Byte kFinSig0 = 0x17; 15 | const Byte kFinSig1 = 0x72; 16 | const Byte kFinSig2 = 0x45; 17 | const Byte kFinSig3 = 0x38; 18 | const Byte kFinSig4 = 0x50; 19 | const Byte kFinSig5 = 0x90; 20 | 21 | const Byte kBlockSig0 = 0x31; 22 | const Byte kBlockSig1 = 0x41; 23 | const Byte kBlockSig2 = 0x59; 24 | const Byte kBlockSig3 = 0x26; 25 | const Byte kBlockSig4 = 0x53; 26 | const Byte kBlockSig5 = 0x59; 27 | 28 | const int kNumOrigBits = 24; 29 | 30 | const int kNumTablesBits = 3; 31 | const int kNumTablesMin = 2; 32 | const int kNumTablesMax = 6; 33 | 34 | const int kNumLevelsBits = 5; 35 | 36 | const int kMaxHuffmanLen = 20; // Check it 37 | 38 | const int kMaxAlphaSize = 258; 39 | 40 | const int kGroupSize = 50; 41 | 42 | const int kBlockSizeMultMin = 1; 43 | const int kBlockSizeMultMax = 9; 44 | const UInt32 kBlockSizeStep = 100000; 45 | const UInt32 kBlockSizeMax = kBlockSizeMultMax * kBlockSizeStep; 46 | 47 | const int kNumSelectorsBits = 15; 48 | const UInt32 kNumSelectorsMax = (2 + (kBlockSizeMax / kGroupSize)); 49 | 50 | const int kRleModeRepSize = 4; 51 | 52 | }} 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/BitmEncoder.h: -------------------------------------------------------------------------------- 1 | // BitmEncoder.h -- the Most Significant Bit of byte is First 2 | 3 | #ifndef __BITM_ENCODER_H 4 | #define __BITM_ENCODER_H 5 | 6 | #include "../IStream.h" 7 | 8 | template 9 | class CBitmEncoder 10 | { 11 | TOutByte m_Stream; 12 | unsigned m_BitPos; 13 | Byte m_CurByte; 14 | public: 15 | bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); } 16 | void SetStream(ISequentialOutStream *outStream) { m_Stream.SetStream(outStream);} 17 | void ReleaseStream() { m_Stream.ReleaseStream(); } 18 | UInt64 GetProcessedSize() const { return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) / 8; } 19 | void Init() 20 | { 21 | m_Stream.Init(); 22 | m_BitPos = 8; 23 | m_CurByte = 0; 24 | } 25 | HRESULT Flush() 26 | { 27 | if (m_BitPos < 8) 28 | WriteBits(0, m_BitPos); 29 | return m_Stream.Flush(); 30 | } 31 | void WriteBits(UInt32 value, unsigned numBits) 32 | { 33 | while (numBits > 0) 34 | { 35 | if (numBits < m_BitPos) 36 | { 37 | m_CurByte |= ((Byte)value << (m_BitPos -= numBits)); 38 | return; 39 | } 40 | numBits -= m_BitPos; 41 | UInt32 newBits = (value >> numBits); 42 | value -= (newBits << numBits); 43 | m_Stream.WriteByte((Byte)(m_CurByte | newBits)); 44 | m_BitPos = 8; 45 | m_CurByte = 0; 46 | } 47 | } 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/ZlibDecoder.h: -------------------------------------------------------------------------------- 1 | // ZlibDecoder.h 2 | 3 | #ifndef __ZLIB_DECODER_H 4 | #define __ZLIB_DECODER_H 5 | 6 | #include "DeflateDecoder.h" 7 | 8 | namespace NCompress { 9 | namespace NZlib { 10 | 11 | const UInt32 ADLER_INIT_VAL = 1; 12 | 13 | class COutStreamWithAdler: 14 | public ISequentialOutStream, 15 | public CMyUnknownImp 16 | { 17 | CMyComPtr _stream; 18 | UInt32 _adler; 19 | public: 20 | MY_UNKNOWN_IMP 21 | STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); 22 | void SetStream(ISequentialOutStream *stream) { _stream = stream; } 23 | void ReleaseStream() { _stream.Release(); } 24 | void Init() { _adler = ADLER_INIT_VAL; } 25 | UInt32 GetAdler() const { return _adler; } 26 | }; 27 | 28 | class CDecoder: 29 | public ICompressCoder, 30 | public CMyUnknownImp 31 | { 32 | COutStreamWithAdler *AdlerSpec; 33 | CMyComPtr AdlerStream; 34 | 35 | NCompress::NDeflate::NDecoder::CCOMCoder *DeflateDecoderSpec; 36 | CMyComPtr DeflateDecoder; 37 | public: 38 | STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, 39 | const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 40 | 41 | UInt64 GetInputProcessedSize() const { return DeflateDecoderSpec->GetInputProcessedSize() + 2; } 42 | 43 | MY_UNKNOWN_IMP 44 | }; 45 | 46 | }} 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Zip/ZipUpdate.h: -------------------------------------------------------------------------------- 1 | // Zip/Update.h 2 | 3 | #ifndef __ZIP_UPDATE_H 4 | #define __ZIP_UPDATE_H 5 | 6 | #include "../../ICoder.h" 7 | #include "../IArchive.h" 8 | 9 | #include "../../Common/CreateCoder.h" 10 | 11 | #include "ZipCompressionMode.h" 12 | #include "ZipIn.h" 13 | 14 | namespace NArchive { 15 | namespace NZip { 16 | 17 | struct CUpdateRange 18 | { 19 | UInt64 Position; 20 | UInt64 Size; 21 | CUpdateRange() {}; 22 | CUpdateRange(UInt64 position, UInt64 size): Position(position), Size(size) {}; 23 | }; 24 | 25 | struct CUpdateItem 26 | { 27 | bool NewData; 28 | bool NewProperties; 29 | bool IsDir; 30 | bool NtfsTimeIsDefined; 31 | bool IsUtf8; 32 | int IndexInArchive; 33 | int IndexInClient; 34 | UInt32 Attributes; 35 | UInt32 Time; 36 | UInt64 Size; 37 | AString Name; 38 | // bool Commented; 39 | // CUpdateRange CommentRange; 40 | FILETIME NtfsMTime; 41 | FILETIME NtfsATime; 42 | FILETIME NtfsCTime; 43 | 44 | CUpdateItem(): NtfsTimeIsDefined(false), IsUtf8(false), Size(0) {} 45 | }; 46 | 47 | HRESULT Update( 48 | DECL_EXTERNAL_CODECS_LOC_VARS 49 | const CObjectVector &inputItems, 50 | const CObjectVector &updateItems, 51 | ISequentialOutStream *seqOutStream, 52 | CInArchive *inArchive, 53 | CCompressionMethodMode *compressionMethodMode, 54 | IArchiveUpdateCallback *updateCallback); 55 | 56 | }} 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/ZlibEncoder.h: -------------------------------------------------------------------------------- 1 | // ZlibEncoder.h 2 | 3 | #ifndef __ZLIB_ENCODER_H 4 | #define __ZLIB_ENCODER_H 5 | 6 | #include "DeflateEncoder.h" 7 | 8 | namespace NCompress { 9 | namespace NZlib { 10 | 11 | class CInStreamWithAdler: 12 | public ISequentialInStream, 13 | public CMyUnknownImp 14 | { 15 | CMyComPtr _stream; 16 | UInt32 _adler; 17 | UInt64 _size; 18 | public: 19 | MY_UNKNOWN_IMP 20 | STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); 21 | void SetStream(ISequentialInStream *stream) { _stream = stream; } 22 | void ReleaseStream() { _stream.Release(); } 23 | void Init() { _adler = 1; _size = 0; } // ADLER_INIT_VAL 24 | UInt32 GetAdler() const { return _adler; } 25 | UInt64 GetSize() const { return _size; } 26 | }; 27 | 28 | class CEncoder: 29 | public ICompressCoder, 30 | public CMyUnknownImp 31 | { 32 | CInStreamWithAdler *AdlerSpec; 33 | CMyComPtr AdlerStream; 34 | CMyComPtr DeflateEncoder; 35 | public: 36 | NCompress::NDeflate::NEncoder::CCOMCoder *DeflateEncoderSpec; 37 | 38 | void Create(); 39 | STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, 40 | const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 41 | UInt64 GetInputProcessedSize() const { return AdlerSpec->GetSize(); } 42 | 43 | MY_UNKNOWN_IMP 44 | }; 45 | 46 | }} 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Zip/ZipAddCommon.h: -------------------------------------------------------------------------------- 1 | // ZipAddCommon.h 2 | 3 | #ifndef __ZIP_ADD_COMMON_H 4 | #define __ZIP_ADD_COMMON_H 5 | 6 | #include "../../ICoder.h" 7 | #include "../../IProgress.h" 8 | 9 | #include "../../Common/CreateCoder.h" 10 | #include "../../Common/FilterCoder.h" 11 | 12 | #include "../../Compress/CopyCoder.h" 13 | 14 | #include "../../Crypto/ZipCrypto.h" 15 | #include "../../Crypto/WzAes.h" 16 | 17 | #include "ZipCompressionMode.h" 18 | 19 | namespace NArchive { 20 | namespace NZip { 21 | 22 | struct CCompressingResult 23 | { 24 | UInt64 UnpackSize; 25 | UInt64 PackSize; 26 | UInt32 CRC; 27 | UInt16 Method; 28 | Byte ExtractVersion; 29 | }; 30 | 31 | class CAddCommon 32 | { 33 | CCompressionMethodMode _options; 34 | NCompress::CCopyCoder *_copyCoderSpec; 35 | CMyComPtr _copyCoder; 36 | 37 | CMyComPtr _compressEncoder; 38 | Byte _compressExtractVersion; 39 | 40 | CFilterCoder *_cryptoStreamSpec; 41 | CMyComPtr _cryptoStream; 42 | 43 | NCrypto::NZip::CEncoder *_filterSpec; 44 | NCrypto::NWzAes::CEncoder *_filterAesSpec; 45 | 46 | public: 47 | CAddCommon(const CCompressionMethodMode &options); 48 | HRESULT Compress( 49 | DECL_EXTERNAL_CODECS_LOC_VARS 50 | ISequentialInStream *inStream, IOutStream *outStream, 51 | ICompressProgressInfo *progress, CCompressingResult &operationResult); 52 | }; 53 | 54 | }} 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /lib/codecs/core/myWindows/config.h: -------------------------------------------------------------------------------- 1 | 2 | #if !defined(__DJGPP__) 3 | 4 | #ifndef __CYGWIN__ 5 | #define FILESYSTEM_IS_CASE_SENSITIVE 1 6 | #endif 7 | 8 | #if !defined(ENV_MACOSX) && !defined(ENV_BEOS) 9 | 10 | /* */ 11 | /* ENV_HAVE_WCHAR__H and not ENV_HAVE_WCHAR_H to avoid warning with wxWidgets */ 12 | #define ENV_HAVE_WCHAR__H 13 | 14 | /* */ 15 | #define ENV_HAVE_WCTYPE_H 16 | 17 | /* mbrtowc */ 18 | /* #ifndef __hpux */ 19 | /* #define ENV_HAVE_MBRTOWC */ 20 | /* #endif */ 21 | 22 | /* towupper */ 23 | #define ENV_HAVE_TOWUPPER 24 | 25 | #endif /* !ENV_MACOSX && !ENV_BEOS */ 26 | 27 | #if !defined(ENV_BEOS) 28 | #define ENV_HAVE_GETPASS 29 | 30 | #if !defined(sun) 31 | #define ENV_HAVE_TIMEGM 32 | #endif 33 | 34 | 35 | #endif 36 | 37 | /* lstat, readlink and S_ISLNK */ 38 | #define ENV_HAVE_LSTAT 39 | 40 | /* */ 41 | #define ENV_HAVE_LOCALE 42 | 43 | /* mbstowcs */ 44 | #define ENV_HAVE_MBSTOWCS 45 | 46 | /* wcstombs */ 47 | #define ENV_HAVE_WCSTOMBS 48 | 49 | #endif /* !__DJGPP__ */ 50 | 51 | #ifndef ENV_BEOS 52 | #define ENV_HAVE_PTHREAD 53 | #endif 54 | 55 | #if defined(ENV_MACOSX) 56 | #define LOCALE_IS_UTF8 57 | #endif 58 | 59 | #ifdef LOCALE_IS_UTF8 60 | #undef ENV_HAVE_LOCALE 61 | #undef ENV_HAVE_MBSTOWCS 62 | #undef ENV_HAVE_WCSTOMBS 63 | /* #undef ENV_HAVE_MBRTOWC */ 64 | #endif 65 | 66 | #define MAX_PATHNAME_LEN 1024 67 | 68 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/PropID.h: -------------------------------------------------------------------------------- 1 | // PropID.h 2 | 3 | #ifndef __7ZIP_PROPID_H 4 | #define __7ZIP_PROPID_H 5 | 6 | enum 7 | { 8 | kpidNoProperty = 0, 9 | kpidMainSubfile = 1, 10 | kpidHandlerItemIndex = 2, 11 | kpidPath, 12 | kpidName, 13 | kpidExtension, 14 | kpidIsDir, 15 | kpidSize, 16 | kpidPackSize, 17 | kpidAttrib, 18 | kpidCTime, 19 | kpidATime, 20 | kpidMTime, 21 | kpidSolid, 22 | kpidCommented, 23 | kpidEncrypted, 24 | kpidSplitBefore, 25 | kpidSplitAfter, 26 | kpidDictionarySize, 27 | kpidCRC, 28 | kpidType, 29 | kpidIsAnti, 30 | kpidMethod, 31 | kpidHostOS, 32 | kpidFileSystem, 33 | kpidUser, 34 | kpidGroup, 35 | kpidBlock, 36 | kpidComment, 37 | kpidPosition, 38 | kpidPrefix, 39 | kpidNumSubDirs, 40 | kpidNumSubFiles, 41 | kpidUnpackVer, 42 | kpidVolume, 43 | kpidIsVolume, 44 | kpidOffset, 45 | kpidLinks, 46 | kpidNumBlocks, 47 | kpidNumVolumes, 48 | kpidTimeType, 49 | kpidBit64, 50 | kpidBigEndian, 51 | kpidCpu, 52 | kpidPhySize, 53 | kpidHeadersSize, 54 | kpidChecksum, 55 | kpidCharacts, 56 | kpidVa, 57 | kpidId, 58 | kpidShortName, 59 | kpidCreatorApp, 60 | kpidSectorSize, 61 | kpidPosixAttrib, 62 | kpidLink, 63 | kpidError, 64 | 65 | kpidTotalSize = 0x1100, 66 | kpidFreeSpace, 67 | kpidClusterSize, 68 | kpidVolumeName, 69 | 70 | kpidLocalName = 0x1200, 71 | kpidProvider, 72 | 73 | kpidUserDefined = 0x10000 74 | }; 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /lib/codecs/rtl/Aes.h: -------------------------------------------------------------------------------- 1 | /* Aes.h -- AES encryption / decryption 2 | 2009-11-23 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __AES_H 5 | #define __AES_H 6 | 7 | #include "Types.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define AES_BLOCK_SIZE 16 12 | 13 | /* Call AesGenTables one time before other AES functions */ 14 | void AesGenTables(void); 15 | 16 | /* UInt32 pointers must be 16-byte aligned */ 17 | 18 | /* 16-byte (4 * 32-bit words) blocks: 1 (IV) + 1 (keyMode) + 15 (AES-256 roundKeys) */ 19 | #define AES_NUM_IVMRK_WORDS ((1 + 1 + 15) * 4) 20 | 21 | /* aes - 16-byte aligned pointer to keyMode+roundKeys sequence */ 22 | /* keySize = 16 or 24 or 32 (bytes) */ 23 | typedef void (MY_FAST_CALL *AES_SET_KEY_FUNC)(UInt32 *aes, const Byte *key, unsigned keySize); 24 | void MY_FAST_CALL Aes_SetKey_Enc(UInt32 *aes, const Byte *key, unsigned keySize); 25 | void MY_FAST_CALL Aes_SetKey_Dec(UInt32 *aes, const Byte *key, unsigned keySize); 26 | 27 | /* ivAes - 16-byte aligned pointer to iv+keyMode+roundKeys sequence: UInt32[AES_NUM_IVMRK_WORDS] */ 28 | void AesCbc_Init(UInt32 *ivAes, const Byte *iv); /* iv size is AES_BLOCK_SIZE */ 29 | /* data - 16-byte aligned pointer to data */ 30 | /* numBlocks - the number of 16-byte blocks in data array */ 31 | typedef void (MY_FAST_CALL *AES_CODE_FUNC)(UInt32 *ivAes, Byte *data, size_t numBlocks); 32 | extern AES_CODE_FUNC g_AesCbc_Encode; 33 | extern AES_CODE_FUNC g_AesCbc_Decode; 34 | extern AES_CODE_FUNC g_AesCtr_Code; 35 | 36 | EXTERN_C_END 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Tar/TarHandler.h: -------------------------------------------------------------------------------- 1 | // TarHandler.h 2 | 3 | #ifndef __TAR_HANDLER_H 4 | #define __TAR_HANDLER_H 5 | 6 | #include "Common/MyCom.h" 7 | #include "../IArchive.h" 8 | 9 | #include "../../Compress/CopyCoder.h" 10 | 11 | #include "TarItem.h" 12 | 13 | namespace NArchive { 14 | namespace NTar { 15 | 16 | class CHandler: 17 | public IInArchive, 18 | public IArchiveOpenSeq, 19 | public IInArchiveGetStream, 20 | public IOutArchive, 21 | public CMyUnknownImp 22 | { 23 | CObjectVector _items; 24 | CMyComPtr _stream; 25 | CMyComPtr _seqStream; 26 | 27 | UInt32 _curIndex; 28 | bool _latestIsRead; 29 | CItemEx _latestItem; 30 | 31 | UInt64 _phySize; 32 | UInt64 _headersSize; 33 | bool _phySizeDefined; 34 | AString _errorMessage; 35 | 36 | NCompress::CCopyCoder *copyCoderSpec; 37 | CMyComPtr copyCoder; 38 | 39 | HRESULT ReadItem2(ISequentialInStream *stream, bool &filled, CItemEx &itemInfo); 40 | HRESULT Open2(IInStream *stream, IArchiveOpenCallback *callback); 41 | HRESULT SkipTo(UInt32 index); 42 | 43 | public: 44 | MY_UNKNOWN_IMP4( 45 | IInArchive, 46 | IArchiveOpenSeq, 47 | IInArchiveGetStream, 48 | IOutArchive 49 | ) 50 | 51 | INTERFACE_IInArchive(;) 52 | INTERFACE_IOutArchive(;) 53 | STDMETHOD(OpenSeq)(ISequentialInStream *stream); 54 | STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream); 55 | 56 | CHandler(); 57 | }; 58 | 59 | }} 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/DynamicBuffer.h: -------------------------------------------------------------------------------- 1 | // Common/DynamicBuffer.h 2 | 3 | #ifndef __COMMON_DYNAMIC_BUFFER_H 4 | #define __COMMON_DYNAMIC_BUFFER_H 5 | 6 | #include "Buffer.h" 7 | 8 | template class CDynamicBuffer: public CBuffer 9 | { 10 | void GrowLength(size_t size) 11 | { 12 | size_t delta; 13 | if (this->_capacity > 64) 14 | delta = this->_capacity / 4; 15 | else if (this->_capacity > 8) 16 | delta = 16; 17 | else 18 | delta = 4; 19 | delta = MyMax(delta, size); 20 | size_t newCap = this->_capacity + delta; 21 | if (newCap < delta) 22 | newCap = this->_capacity + size; 23 | this->SetCapacity(newCap); 24 | } 25 | public: 26 | CDynamicBuffer(): CBuffer() {}; 27 | CDynamicBuffer(const CDynamicBuffer &buffer): CBuffer(buffer) {}; 28 | CDynamicBuffer(size_t size): CBuffer(size) {}; 29 | CDynamicBuffer& operator=(const CDynamicBuffer &buffer) 30 | { 31 | this->Free(); 32 | if (buffer._capacity > 0) 33 | { 34 | SetCapacity(buffer._capacity); 35 | memmove(this->_items, buffer._items, buffer._capacity * sizeof(T)); 36 | } 37 | return *this; 38 | } 39 | void EnsureCapacity(size_t capacity) 40 | { 41 | if (this->_capacity < capacity) 42 | GrowLength(capacity - this->_capacity); 43 | } 44 | }; 45 | 46 | typedef CDynamicBuffer CCharDynamicBuffer; 47 | typedef CDynamicBuffer CWCharDynamicBuffer; 48 | typedef CDynamicBuffer CByteDynamicBuffer; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/BranchMisc.cpp: -------------------------------------------------------------------------------- 1 | // BranchMisc.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include 6 | 7 | #include "BranchMisc.h" 8 | 9 | UInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size) 10 | { return (UInt32)::ARM_Convert(data, size, _bufferPos, 1); } 11 | 12 | UInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size) 13 | { return (UInt32)::ARM_Convert(data, size, _bufferPos, 0); } 14 | 15 | UInt32 CBC_ARMT_Encoder::SubFilter(Byte *data, UInt32 size) 16 | { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 1); } 17 | 18 | UInt32 CBC_ARMT_Decoder::SubFilter(Byte *data, UInt32 size) 19 | { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 0); } 20 | 21 | UInt32 CBC_PPC_Encoder::SubFilter(Byte *data, UInt32 size) 22 | { return (UInt32)::PPC_Convert(data, size, _bufferPos, 1); } 23 | 24 | UInt32 CBC_PPC_Decoder::SubFilter(Byte *data, UInt32 size) 25 | { return (UInt32)::PPC_Convert(data, size, _bufferPos, 0); } 26 | 27 | UInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size) 28 | { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 1); } 29 | 30 | UInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size) 31 | { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 0); } 32 | 33 | UInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size) 34 | { return (UInt32)::IA64_Convert(data, size, _bufferPos, 1); } 35 | 36 | UInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size) 37 | { return (UInt32)::IA64_Convert(data, size, _bufferPos, 0); } 38 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/ArjDecoder2.h: -------------------------------------------------------------------------------- 1 | // ArjDecoder2.h 2 | 3 | #ifndef __COMPRESS_ARJ_DECODER2_H 4 | #define __COMPRESS_ARJ_DECODER2_H 5 | 6 | #include "../../Common/MyCom.h" 7 | 8 | #include "../ICoder.h" 9 | 10 | #include "../Common/InBuffer.h" 11 | 12 | #include "BitmDecoder.h" 13 | #include "LzOutWindow.h" 14 | 15 | namespace NCompress { 16 | namespace NArj { 17 | namespace NDecoder2 { 18 | 19 | class CCoder : 20 | public ICompressCoder, 21 | public CMyUnknownImp 22 | { 23 | CLzOutWindow m_OutWindowStream; 24 | NBitm::CDecoder m_InBitStream; 25 | 26 | void ReleaseStreams() 27 | { 28 | m_OutWindowStream.ReleaseStream(); 29 | m_InBitStream.ReleaseStream(); 30 | } 31 | 32 | class CCoderReleaser 33 | { 34 | CCoder *m_Coder; 35 | public: 36 | bool NeedFlush; 37 | CCoderReleaser(CCoder *coder): m_Coder(coder), NeedFlush(true) {} 38 | ~CCoderReleaser() 39 | { 40 | if (NeedFlush) 41 | m_Coder->m_OutWindowStream.Flush(); 42 | m_Coder->ReleaseStreams(); 43 | } 44 | }; 45 | friend class CCoderReleaser; 46 | 47 | HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream, 48 | const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 49 | public: 50 | MY_UNKNOWN_IMP 51 | 52 | STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, 53 | const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 54 | 55 | }; 56 | 57 | }}} 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /lib/codecs/rtl/Delta.c: -------------------------------------------------------------------------------- 1 | /* Delta.c -- Delta converter 2 | 2009-05-26 : Igor Pavlov : Public domain */ 3 | 4 | #include "Delta.h" 5 | 6 | void Delta_Init(Byte *state) 7 | { 8 | unsigned i; 9 | for (i = 0; i < DELTA_STATE_SIZE; i++) 10 | state[i] = 0; 11 | } 12 | 13 | static void MyMemCpy(Byte *dest, const Byte *src, unsigned size) 14 | { 15 | unsigned i; 16 | for (i = 0; i < size; i++) 17 | dest[i] = src[i]; 18 | } 19 | 20 | void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size) 21 | { 22 | Byte buf[DELTA_STATE_SIZE]; 23 | unsigned j = 0; 24 | MyMemCpy(buf, state, delta); 25 | { 26 | SizeT i; 27 | for (i = 0; i < size;) 28 | { 29 | for (j = 0; j < delta && i < size; i++, j++) 30 | { 31 | Byte b = data[i]; 32 | data[i] = (Byte)(b - buf[j]); 33 | buf[j] = b; 34 | } 35 | } 36 | } 37 | if (j == delta) 38 | j = 0; 39 | MyMemCpy(state, buf + j, delta - j); 40 | MyMemCpy(state + delta - j, buf, j); 41 | } 42 | 43 | void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size) 44 | { 45 | Byte buf[DELTA_STATE_SIZE]; 46 | unsigned j = 0; 47 | MyMemCpy(buf, state, delta); 48 | { 49 | SizeT i; 50 | for (i = 0; i < size;) 51 | { 52 | for (j = 0; j < delta && i < size; i++, j++) 53 | { 54 | buf[j] = data[i] = (Byte)(buf[j] + data[i]); 55 | } 56 | } 57 | } 58 | if (j == delta) 59 | j = 0; 60 | MyMemCpy(state, buf + j, delta - j); 61 | MyMemCpy(state + delta - j, buf, j); 62 | } 63 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/ProgressMt.cpp: -------------------------------------------------------------------------------- 1 | // ProgressMt.h 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "ProgressMt.h" 6 | 7 | void CMtCompressProgressMixer::Init(int numItems, ICompressProgressInfo *progress) 8 | { 9 | NWindows::NSynchronization::CCriticalSectionLock lock(CriticalSection); 10 | InSizes.Clear(); 11 | OutSizes.Clear(); 12 | for (int i = 0; i < numItems; i++) 13 | { 14 | InSizes.Add(0); 15 | OutSizes.Add(0); 16 | } 17 | TotalInSize = 0; 18 | TotalOutSize = 0; 19 | _progress = progress; 20 | } 21 | 22 | void CMtCompressProgressMixer::Reinit(int index) 23 | { 24 | NWindows::NSynchronization::CCriticalSectionLock lock(CriticalSection); 25 | InSizes[index] = 0; 26 | OutSizes[index] = 0; 27 | } 28 | 29 | HRESULT CMtCompressProgressMixer::SetRatioInfo(int index, const UInt64 *inSize, const UInt64 *outSize) 30 | { 31 | NWindows::NSynchronization::CCriticalSectionLock lock(CriticalSection); 32 | if (inSize != 0) 33 | { 34 | UInt64 diff = *inSize - InSizes[index]; 35 | InSizes[index] = *inSize; 36 | TotalInSize += diff; 37 | } 38 | if (outSize != 0) 39 | { 40 | UInt64 diff = *outSize - OutSizes[index]; 41 | OutSizes[index] = *outSize; 42 | TotalOutSize += diff; 43 | } 44 | if (_progress) 45 | return _progress->SetRatioInfo(&TotalInSize, &TotalOutSize); 46 | return S_OK; 47 | } 48 | 49 | 50 | STDMETHODIMP CMtCompressProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) 51 | { 52 | return _progress->SetRatioInfo(_index, inSize, outSize); 53 | } 54 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/FilePathAutoRename.cpp: -------------------------------------------------------------------------------- 1 | // FilePathAutoRename.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "Common/Defs.h" 6 | #include "Common/IntToString.h" 7 | 8 | #include "Windows/FileFind.h" 9 | 10 | #include "FilePathAutoRename.h" 11 | 12 | using namespace NWindows; 13 | 14 | static bool MakeAutoName(const UString &name, 15 | const UString &extension, unsigned value, UString &path) 16 | { 17 | wchar_t number[16]; 18 | ConvertUInt32ToString(value, number); 19 | path = name; 20 | path += number; 21 | path += extension; 22 | return NFile::NFind::DoesFileOrDirExist(path); 23 | } 24 | 25 | bool AutoRenamePath(UString &fullProcessedPath) 26 | { 27 | UString path; 28 | int dotPos = fullProcessedPath.ReverseFind(L'.'); 29 | 30 | int slashPos = fullProcessedPath.ReverseFind(L'/'); 31 | #ifdef _WIN32 32 | int slash1Pos = fullProcessedPath.ReverseFind(L'\\'); 33 | slashPos = MyMax(slashPos, slash1Pos); 34 | #endif 35 | 36 | UString name, extension; 37 | if (dotPos > slashPos && dotPos > 0) 38 | { 39 | name = fullProcessedPath.Left(dotPos); 40 | extension = fullProcessedPath.Mid(dotPos); 41 | } 42 | else 43 | name = fullProcessedPath; 44 | name += L'_'; 45 | unsigned left = 1, right = (1 << 30); 46 | while (left != right) 47 | { 48 | unsigned mid = (left + right) / 2; 49 | if (MakeAutoName(name, extension, mid, path)) 50 | left = mid + 1; 51 | else 52 | right = mid; 53 | } 54 | return !MakeAutoName(name, extension, right, fullProcessedPath); 55 | } 56 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/7z/7zEncode.h: -------------------------------------------------------------------------------- 1 | // 7zEncode.h 2 | 3 | #ifndef __7Z_ENCODE_H 4 | #define __7Z_ENCODE_H 5 | 6 | // #include "../../Common/StreamObjects.h" 7 | 8 | #include "7zCompressionMode.h" 9 | 10 | #include "../Common/CoderMixer2.h" 11 | #include "../Common/CoderMixer2MT.h" 12 | #ifdef _ST_MODE 13 | #include "../Common/CoderMixer2ST.h" 14 | #endif 15 | #include "7zItem.h" 16 | 17 | #include "../../Common/CreateCoder.h" 18 | 19 | namespace NArchive { 20 | namespace N7z { 21 | 22 | class CEncoder 23 | { 24 | NCoderMixer::CCoderMixer2MT *_mixerCoderSpec; 25 | CMyComPtr _mixerCoder; 26 | 27 | CObjectVector _codersInfo; 28 | 29 | CCompressionMethodMode _options; 30 | NCoderMixer::CBindInfo _bindInfo; 31 | NCoderMixer::CBindInfo _decompressBindInfo; 32 | NCoderMixer::CBindReverseConverter *_bindReverseConverter; 33 | CRecordVector _decompressionMethods; 34 | 35 | HRESULT CreateMixerCoder(DECL_EXTERNAL_CODECS_LOC_VARS 36 | const UInt64 *inSizeForReduce); 37 | 38 | bool _constructed; 39 | public: 40 | CEncoder(const CCompressionMethodMode &options); 41 | ~CEncoder(); 42 | HRESULT EncoderConstr(); 43 | HRESULT Encode( 44 | DECL_EXTERNAL_CODECS_LOC_VARS 45 | ISequentialInStream *inStream, 46 | const UInt64 *inStreamSize, const UInt64 *inSizeForReduce, 47 | CFolder &folderItem, 48 | ISequentialOutStream *outStream, 49 | CRecordVector &packSizes, 50 | ICompressProgressInfo *compressProgress); 51 | }; 52 | 53 | }} 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Common/ItemNameUtils.cpp: -------------------------------------------------------------------------------- 1 | // Archive/Common/ItemNameUtils.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include 6 | 7 | #include "ItemNameUtils.h" 8 | 9 | namespace NArchive { 10 | namespace NItemName { 11 | 12 | static const wchar_t kOSDirDelimiter = WCHAR_PATH_SEPARATOR; 13 | static const wchar_t kDirDelimiter = L'/'; 14 | 15 | UString MakeLegalName(const UString &name) 16 | { 17 | UString zipName = name; 18 | zipName.Replace(kOSDirDelimiter, kDirDelimiter); 19 | return zipName; 20 | } 21 | 22 | UString GetOSName(const UString &name) 23 | { 24 | UString newName = name; 25 | newName.Replace(kDirDelimiter, kOSDirDelimiter); 26 | return newName; 27 | } 28 | 29 | UString GetOSName2(const UString &name) 30 | { 31 | if (name.IsEmpty()) 32 | return UString(); 33 | UString newName = GetOSName(name); 34 | if (newName[newName.Length() - 1] == kOSDirDelimiter) 35 | newName.Delete(newName.Length() - 1); 36 | return newName; 37 | } 38 | 39 | bool HasTailSlash(const AString &name, UINT codePage) 40 | { 41 | if (name.IsEmpty()) 42 | return false; 43 | LPCSTR prev = 44 | #if defined(_WIN32) && !defined(UNDER_CE) 45 | CharPrevExA((WORD)codePage, name, &name[name.Length()], 0); 46 | #else 47 | (LPCSTR)(name) + (name.Length() - 1); 48 | #endif 49 | return (*prev == '/'); 50 | } 51 | 52 | #ifndef _WIN32 53 | UString WinNameToOSName(const UString &name) 54 | { 55 | UString newName = name; 56 | newName.Replace(L'\\', kOSDirDelimiter); 57 | return newName; 58 | } 59 | #endif 60 | 61 | }} 62 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/BranchCoder.h: -------------------------------------------------------------------------------- 1 | // BranchCoder.h 2 | 3 | #ifndef __COMPRESS_BRANCH_CODER_H 4 | #define __COMPRESS_BRANCH_CODER_H 5 | 6 | #include "../../Common/MyCom.h" 7 | 8 | #include "../ICoder.h" 9 | 10 | class CBranchConverter: 11 | public ICompressFilter, 12 | public CMyUnknownImp 13 | { 14 | protected: 15 | UInt32 _bufferPos; 16 | virtual void SubInit() {} 17 | virtual UInt32 SubFilter(Byte *data, UInt32 size) = 0; 18 | public: 19 | MY_UNKNOWN_IMP; 20 | STDMETHOD(Init)(); 21 | STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size); 22 | }; 23 | 24 | #define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \ 25 | { public: UInt32 SubFilter(Byte *data, UInt32 size); }; 26 | 27 | #define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \ 28 | { public: UInt32 SubFilter(Byte *data, UInt32 size); }; 29 | 30 | #define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \ 31 | { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; 32 | 33 | #define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \ 34 | { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; 35 | 36 | #define MyClassA(Name, id, subId) \ 37 | MyClassEncoderA(Name ## _Encoder) \ 38 | MyClassDecoderA(Name ## _Decoder) 39 | 40 | #define MyClassB(Name, id, subId, ADD_ITEMS, ADD_INIT) \ 41 | MyClassEncoderB(Name ## _Encoder, ADD_ITEMS, ADD_INIT) \ 42 | MyClassDecoderB(Name ## _Decoder, ADD_ITEMS, ADD_INIT) 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/7z/7zFolderInStream.h: -------------------------------------------------------------------------------- 1 | // 7zFolderInStream.h 2 | 3 | #ifndef __7Z_FOLDER_IN_STREAM_H 4 | #define __7Z_FOLDER_IN_STREAM_H 5 | 6 | #include "../../ICoder.h" 7 | #include "../IArchive.h" 8 | #include "../Common/InStreamWithCRC.h" 9 | 10 | #include "7zItem.h" 11 | 12 | namespace NArchive { 13 | namespace N7z { 14 | 15 | class CFolderInStream: 16 | public ISequentialInStream, 17 | public ICompressGetSubStreamSize, 18 | public CMyUnknownImp 19 | { 20 | CSequentialInStreamWithCRC *_inStreamWithHashSpec; 21 | CMyComPtr _inStreamWithHash; 22 | CMyComPtr _updateCallback; 23 | 24 | bool _currentSizeIsDefined; 25 | bool _fileIsOpen; 26 | UInt64 _currentSize; 27 | UInt64 _filePos; 28 | const UInt32 *_fileIndices; 29 | UInt32 _numFiles; 30 | UInt32 _fileIndex; 31 | 32 | HRESULT OpenStream(); 33 | HRESULT CloseStream(); 34 | void AddDigest(); 35 | 36 | public: 37 | CRecordVector Processed; 38 | CRecordVector CRCs; 39 | CRecordVector Sizes; 40 | 41 | MY_UNKNOWN_IMP1(ICompressGetSubStreamSize) 42 | STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); 43 | STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value); 44 | 45 | CFolderInStream(); 46 | void Init(IArchiveUpdateCallback *updateCallback, const UInt32 *fileIndices, UInt32 numFiles); 47 | UInt64 GetFullSize() const 48 | { 49 | UInt64 size = 0; 50 | for (int i = 0; i < Sizes.Size(); i++) 51 | size += Sizes[i]; 52 | return size; 53 | } 54 | }; 55 | 56 | }} 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/OutBuffer.h: -------------------------------------------------------------------------------- 1 | // OutBuffer.h 2 | 3 | #ifndef __OUTBUFFER_H 4 | #define __OUTBUFFER_H 5 | 6 | #include "../IStream.h" 7 | #include "../../Common/MyCom.h" 8 | #include "../../Common/MyException.h" 9 | 10 | #ifndef _NO_EXCEPTIONS 11 | struct COutBufferException: public CSystemException 12 | { 13 | COutBufferException(HRESULT errorCode): CSystemException(errorCode) {} 14 | }; 15 | #endif 16 | 17 | class COutBuffer 18 | { 19 | protected: 20 | Byte *_buffer; 21 | UInt32 _pos; 22 | UInt32 _limitPos; 23 | UInt32 _streamPos; 24 | UInt32 _bufferSize; 25 | CMyComPtr _stream; 26 | UInt64 _processedSize; 27 | Byte *_buffer2; 28 | bool _overDict; 29 | 30 | HRESULT FlushPart(); 31 | public: 32 | #ifdef _NO_EXCEPTIONS 33 | HRESULT ErrorCode; 34 | #endif 35 | 36 | COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {} 37 | ~COutBuffer() { Free(); } 38 | 39 | bool Create(UInt32 bufferSize); 40 | void Free(); 41 | 42 | void SetMemStream(Byte *buffer) { _buffer2 = buffer; } 43 | void SetStream(ISequentialOutStream *stream); 44 | void Init(); 45 | HRESULT Flush(); 46 | void FlushWithCheck(); 47 | void ReleaseStream() { _stream.Release(); } 48 | 49 | void WriteByte(Byte b) 50 | { 51 | _buffer[_pos++] = b; 52 | if(_pos == _limitPos) 53 | FlushWithCheck(); 54 | } 55 | void WriteBytes(const void *data, size_t size) 56 | { 57 | for (size_t i = 0; i < size; i++) 58 | WriteByte(((const Byte *)data)[i]); 59 | } 60 | 61 | UInt64 GetProcessedSize() const; 62 | }; 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/LzOutWindow.h: -------------------------------------------------------------------------------- 1 | // LzOutWindow.h 2 | 3 | #ifndef __LZ_OUT_WINDOW_H 4 | #define __LZ_OUT_WINDOW_H 5 | 6 | #include "../IStream.h" 7 | 8 | #include "../Common/OutBuffer.h" 9 | 10 | #ifndef _NO_EXCEPTIONS 11 | typedef COutBufferException CLzOutWindowException; 12 | #endif 13 | 14 | class CLzOutWindow: public COutBuffer 15 | { 16 | public: 17 | void Init(bool solid = false); 18 | 19 | // distance >= 0, len > 0, 20 | bool CopyBlock(UInt32 distance, UInt32 len) 21 | { 22 | UInt32 pos = _pos - distance - 1; 23 | if (distance >= _pos) 24 | { 25 | if (!_overDict || distance >= _bufferSize) 26 | return false; 27 | pos += _bufferSize; 28 | } 29 | if (_limitPos - _pos > len && _bufferSize - pos > len) 30 | { 31 | const Byte *src = _buffer + pos; 32 | Byte *dest = _buffer + _pos; 33 | _pos += len; 34 | do 35 | *dest++ = *src++; 36 | while(--len != 0); 37 | } 38 | else do 39 | { 40 | if (pos == _bufferSize) 41 | pos = 0; 42 | _buffer[_pos++] = _buffer[pos++]; 43 | if (_pos == _limitPos) 44 | FlushWithCheck(); 45 | } 46 | while(--len != 0); 47 | return true; 48 | } 49 | 50 | void PutByte(Byte b) 51 | { 52 | _buffer[_pos++] = b; 53 | if (_pos == _limitPos) 54 | FlushWithCheck(); 55 | } 56 | 57 | Byte GetByte(UInt32 distance) const 58 | { 59 | UInt32 pos = _pos - distance - 1; 60 | if (pos >= _bufferSize) 61 | pos += _bufferSize; 62 | return _buffer[pos]; 63 | } 64 | }; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Rar/RarHandler.h: -------------------------------------------------------------------------------- 1 | // Rar/Handler.h 2 | 3 | #ifndef __RAR_HANDLER_H 4 | #define __RAR_HANDLER_H 5 | 6 | #include "../IArchive.h" 7 | 8 | #include "../../Common/CreateCoder.h" 9 | 10 | #include "RarIn.h" 11 | #include "RarVolumeInStream.h" 12 | 13 | namespace NArchive { 14 | namespace NRar { 15 | 16 | class CHandler: 17 | public IInArchive, 18 | PUBLIC_ISetCompressCodecsInfo 19 | public CMyUnknownImp 20 | { 21 | CRecordVector _refItems; 22 | CObjectVector _items; 23 | CObjectVector _archives; 24 | NArchive::NRar::CInArchiveInfo _archiveInfo; 25 | AString _errorMessage; 26 | 27 | DECL_EXTERNAL_CODECS_VARS 28 | 29 | UInt64 GetPackSize(int refIndex) const; 30 | 31 | bool IsSolid(int refIndex) 32 | { 33 | const CItemEx &item = _items[_refItems[refIndex].ItemIndex]; 34 | if (item.UnPackVersion < 20) 35 | { 36 | if (_archiveInfo.IsSolid()) 37 | return (refIndex > 0); 38 | return false; 39 | } 40 | return item.IsSolid(); 41 | } 42 | void AddErrorMessage(const AString &s) 43 | { 44 | if (!_errorMessage.IsEmpty()) 45 | _errorMessage += '\n'; 46 | _errorMessage += s; 47 | } 48 | 49 | HRESULT Open2(IInStream *stream, 50 | const UInt64 *maxCheckStartPosition, 51 | IArchiveOpenCallback *openCallback); 52 | 53 | public: 54 | MY_QUERYINTERFACE_BEGIN2(IInArchive) 55 | QUERY_ENTRY_ISetCompressCodecsInfo 56 | MY_QUERYINTERFACE_END 57 | MY_ADDREF_RELEASE 58 | 59 | INTERFACE_IInArchive(;) 60 | 61 | DECL_ISetCompressCodecsInfo 62 | }; 63 | 64 | }} 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/BitlEncoder.h: -------------------------------------------------------------------------------- 1 | // BitlEncoder.h -- the Least Significant Bit of byte is First 2 | 3 | #ifndef __BITL_ENCODER_H 4 | #define __BITL_ENCODER_H 5 | 6 | #include "../Common/OutBuffer.h" 7 | 8 | class CBitlEncoder 9 | { 10 | COutBuffer m_Stream; 11 | unsigned m_BitPos; 12 | Byte m_CurByte; 13 | public: 14 | bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); } 15 | void SetStream(ISequentialOutStream *outStream) { m_Stream.SetStream(outStream); } 16 | void ReleaseStream() { m_Stream.ReleaseStream(); } 17 | UInt32 GetBitPosition() const { return (8 - m_BitPos); } 18 | UInt64 GetProcessedSize() const { return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) /8; } 19 | void Init() 20 | { 21 | m_Stream.Init(); 22 | m_BitPos = 8; 23 | m_CurByte = 0; 24 | } 25 | HRESULT Flush() 26 | { 27 | FlushByte(); 28 | return m_Stream.Flush(); 29 | } 30 | void FlushByte() 31 | { 32 | if (m_BitPos < 8) 33 | m_Stream.WriteByte(m_CurByte); 34 | m_BitPos = 8; 35 | m_CurByte = 0; 36 | } 37 | void WriteBits(UInt32 value, unsigned numBits) 38 | { 39 | while (numBits > 0) 40 | { 41 | if (numBits < m_BitPos) 42 | { 43 | m_CurByte |= (value & ((1 << numBits) - 1)) << (8 - m_BitPos); 44 | m_BitPos -= numBits; 45 | return; 46 | } 47 | numBits -= m_BitPos; 48 | m_Stream.WriteByte((Byte)(m_CurByte | (value << (8 - m_BitPos)))); 49 | value >>= m_BitPos; 50 | m_BitPos = 8; 51 | m_CurByte = 0; 52 | } 53 | } 54 | void WriteByte(Byte b) { m_Stream.WriteByte(b);} 55 | }; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/COM.h: -------------------------------------------------------------------------------- 1 | // Windows/COM.h 2 | 3 | #ifndef __WINDOWS_COM_H 4 | #define __WINDOWS_COM_H 5 | 6 | #include "Common/MyString.h" 7 | 8 | namespace NWindows { 9 | namespace NCOM { 10 | 11 | #ifdef _WIN32 12 | 13 | class CComInitializer 14 | { 15 | public: 16 | CComInitializer() 17 | { 18 | #ifdef UNDER_CE 19 | CoInitializeEx(NULL, COINIT_MULTITHREADED); 20 | #else 21 | // it's single thread. Do we need multithread? 22 | CoInitialize(NULL); 23 | #endif 24 | }; 25 | ~CComInitializer() { CoUninitialize(); }; 26 | }; 27 | 28 | class CStgMedium 29 | { 30 | STGMEDIUM _object; 31 | public: 32 | bool _mustBeReleased; 33 | CStgMedium(): _mustBeReleased(false) {} 34 | ~CStgMedium() { Free(); } 35 | void Free() 36 | { 37 | if (_mustBeReleased) 38 | ReleaseStgMedium(&_object); 39 | _mustBeReleased = false; 40 | } 41 | const STGMEDIUM* operator->() const { return &_object;} 42 | STGMEDIUM* operator->() { return &_object;} 43 | STGMEDIUM* operator&() { return &_object; } 44 | }; 45 | 46 | #endif 47 | 48 | ////////////////////////////////// 49 | // GUID <--> String Conversions 50 | UString GUIDToStringW(REFGUID guid); 51 | AString GUIDToStringA(REFGUID guid); 52 | #ifdef UNICODE 53 | #define GUIDToString GUIDToStringW 54 | #else 55 | #define GUIDToString GUIDToStringA 56 | #endif 57 | 58 | HRESULT StringToGUIDW(const wchar_t *string, GUID &classID); 59 | HRESULT StringToGUIDA(const char *string, GUID &classID); 60 | #ifdef UNICODE 61 | #define StringToGUID StringToGUIDW 62 | #else 63 | #define StringToGUID StringToGUIDA 64 | #endif 65 | 66 | 67 | }} 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/CopyCoder.cpp: -------------------------------------------------------------------------------- 1 | // Compress/CopyCoder.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include 6 | 7 | #include "../Common/StreamUtils.h" 8 | 9 | #include "CopyCoder.h" 10 | 11 | namespace NCompress { 12 | 13 | static const UInt32 kBufferSize = 1 << 17; 14 | 15 | CCopyCoder::~CCopyCoder() 16 | { 17 | ::MidFree(_buffer); 18 | } 19 | 20 | STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream, 21 | ISequentialOutStream *outStream, 22 | const UInt64 * /* inSize */, const UInt64 *outSize, 23 | ICompressProgressInfo *progress) 24 | { 25 | if (_buffer == 0) 26 | { 27 | _buffer = (Byte *)::MidAlloc(kBufferSize); 28 | if (_buffer == 0) 29 | return E_OUTOFMEMORY; 30 | } 31 | 32 | TotalSize = 0; 33 | for (;;) 34 | { 35 | UInt32 size = kBufferSize; 36 | if (outSize != 0) 37 | if (size > *outSize - TotalSize) 38 | size = (UInt32)(*outSize - TotalSize); 39 | RINOK(inStream->Read(_buffer, size, &size)); 40 | if (size == 0) 41 | break; 42 | if (outStream) 43 | { 44 | RINOK(WriteStream(outStream, _buffer, size)); 45 | } 46 | TotalSize += size; 47 | if (progress != NULL) 48 | { 49 | RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize)); 50 | } 51 | } 52 | return S_OK; 53 | } 54 | 55 | STDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value) 56 | { 57 | *value = TotalSize; 58 | return S_OK; 59 | } 60 | 61 | HRESULT CopyStream(ISequentialInStream *inStream, ISequentialOutStream *outStream, ICompressProgressInfo *progress) 62 | { 63 | CMyComPtr copyCoder = new NCompress::CCopyCoder; 64 | return copyCoder->Code(inStream, outStream, NULL, NULL, progress); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/ImplodeDecoder.h: -------------------------------------------------------------------------------- 1 | // ImplodeDecoder.h 2 | 3 | #ifndef __COMPRESS_IMPLODE_DECODER_H 4 | #define __COMPRESS_IMPLODE_DECODER_H 5 | 6 | #include "../../Common/MyCom.h" 7 | 8 | #include "../ICoder.h" 9 | 10 | #include "ImplodeHuffmanDecoder.h" 11 | #include "LzOutWindow.h" 12 | 13 | namespace NCompress { 14 | namespace NImplode { 15 | namespace NDecoder { 16 | 17 | class CCoder: 18 | public ICompressCoder, 19 | public ICompressSetDecoderProperties2, 20 | public CMyUnknownImp 21 | { 22 | CLzOutWindow m_OutWindowStream; 23 | NBitl::CDecoder m_InBitStream; 24 | 25 | NImplode::NHuffman::CDecoder m_LiteralDecoder; 26 | NImplode::NHuffman::CDecoder m_LengthDecoder; 27 | NImplode::NHuffman::CDecoder m_DistanceDecoder; 28 | 29 | bool m_BigDictionaryOn; 30 | bool m_LiteralsOn; 31 | 32 | int m_NumDistanceLowDirectBits; 33 | UInt32 m_MinMatchLength; 34 | 35 | bool ReadLevelItems(NImplode::NHuffman::CDecoder &table, Byte *levels, int numLevelItems); 36 | bool ReadTables(); 37 | void DeCodeLevelTable(Byte *newLevels, int numLevels); 38 | public: 39 | CCoder(); 40 | 41 | MY_UNKNOWN_IMP1(ICompressSetDecoderProperties2) 42 | 43 | void ReleaseStreams(); 44 | HRESULT Flush() { return m_OutWindowStream.Flush(); } 45 | 46 | HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream, 47 | const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 48 | 49 | STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, 50 | const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 51 | 52 | STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size); 53 | }; 54 | 55 | }}} 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/7z/7zFolderOutStream.h: -------------------------------------------------------------------------------- 1 | // 7zFolderOutStream.h 2 | 3 | #ifndef __7Z_FOLDER_OUT_STREAM_H 4 | #define __7Z_FOLDER_OUT_STREAM_H 5 | 6 | #include "../../IStream.h" 7 | #include "../IArchive.h" 8 | #include "../Common/OutStreamWithCRC.h" 9 | 10 | #include "7zIn.h" 11 | 12 | namespace NArchive { 13 | namespace N7z { 14 | 15 | class CFolderOutStream: 16 | public ISequentialOutStream, 17 | public ICompressGetSubStreamSize, 18 | public CMyUnknownImp 19 | { 20 | COutStreamWithCRC *_crcStreamSpec; 21 | CMyComPtr _crcStream; 22 | const CArchiveDatabaseEx *_db; 23 | const CBoolVector *_extractStatuses; 24 | CMyComPtr _extractCallback; 25 | UInt32 _ref2Offset; 26 | UInt32 _startIndex; 27 | int _currentIndex; 28 | bool _testMode; 29 | bool _checkCrc; 30 | bool _fileIsOpen; 31 | UInt64 _rem; 32 | 33 | HRESULT OpenFile(); 34 | HRESULT CloseFileAndSetResult(Int32 res); 35 | HRESULT CloseFileAndSetResult(); 36 | HRESULT ProcessEmptyFiles(); 37 | public: 38 | MY_UNKNOWN_IMP1(ICompressGetSubStreamSize) 39 | 40 | CFolderOutStream(); 41 | 42 | STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); 43 | STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value); 44 | 45 | HRESULT Init( 46 | const CArchiveDatabaseEx *db, 47 | UInt32 ref2Offset, UInt32 startIndex, 48 | const CBoolVector *extractStatuses, 49 | IArchiveExtractCallback *extractCallback, 50 | bool testMode, bool checkCrc); 51 | HRESULT FlushCorrupted(Int32 resultEOperationResult); 52 | HRESULT WasWritingFinished() const 53 | { return (_currentIndex == _extractStatuses->Size()) ? S_OK: E_FAIL; } 54 | }; 55 | 56 | }} 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/BitmDecoder.h: -------------------------------------------------------------------------------- 1 | // BitmDecoder.h -- the Most Significant Bit of byte is First 2 | 3 | #ifndef __BITM_DECODER_H 4 | #define __BITM_DECODER_H 5 | 6 | #include "../IStream.h" 7 | 8 | namespace NBitm { 9 | 10 | const unsigned kNumBigValueBits = 8 * 4; 11 | const unsigned kNumValueBytes = 3; 12 | const unsigned kNumValueBits = 8 * kNumValueBytes; 13 | 14 | const UInt32 kMask = (1 << kNumValueBits) - 1; 15 | 16 | template 17 | class CDecoder 18 | { 19 | unsigned m_BitPos; 20 | UInt32 m_Value; 21 | public: 22 | TInByte m_Stream; 23 | bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); } 24 | void SetStream(ISequentialInStream *inStream) { m_Stream.SetStream(inStream);} 25 | void ReleaseStream() { m_Stream.ReleaseStream();} 26 | 27 | void Init() 28 | { 29 | m_Stream.Init(); 30 | m_BitPos = kNumBigValueBits; 31 | Normalize(); 32 | } 33 | 34 | UInt64 GetProcessedSize() const { return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; } 35 | 36 | void Normalize() 37 | { 38 | for (;m_BitPos >= 8; m_BitPos -= 8) 39 | m_Value = (m_Value << 8) | m_Stream.ReadByte(); 40 | } 41 | 42 | UInt32 GetValue(unsigned numBits) const 43 | { 44 | // return (m_Value << m_BitPos) >> (kNumBigValueBits - numBits); 45 | return ((m_Value >> (8 - m_BitPos)) & kMask) >> (kNumValueBits - numBits); 46 | } 47 | 48 | void MovePos(unsigned numBits) 49 | { 50 | m_BitPos += numBits; 51 | Normalize(); 52 | } 53 | 54 | UInt32 ReadBits(unsigned numBits) 55 | { 56 | UInt32 res = GetValue(numBits); 57 | MovePos(numBits); 58 | return res; 59 | } 60 | 61 | void AlignToByte() { MovePos((32 - m_BitPos) & 7); } 62 | }; 63 | 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/ZlibEncoder.cpp: -------------------------------------------------------------------------------- 1 | // ZlibEncoder.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../Common/StreamUtils.h" 6 | 7 | #include "ZlibEncoder.h" 8 | 9 | namespace NCompress { 10 | namespace NZlib { 11 | 12 | #define DEFLATE_TRY_BEGIN try { 13 | #define DEFLATE_TRY_END } catch(...) { return S_FALSE; } 14 | 15 | UInt32 Adler32_Update(UInt32 adler, const Byte *buf, size_t size); 16 | 17 | STDMETHODIMP CInStreamWithAdler::Read(void *data, UInt32 size, UInt32 *processedSize) 18 | { 19 | HRESULT result = _stream->Read(data, size, &size); 20 | _adler = Adler32_Update(_adler, (const Byte *)data, size); 21 | _size += size; 22 | if (processedSize != NULL) 23 | *processedSize = size; 24 | return result; 25 | } 26 | 27 | void CEncoder::Create() 28 | { 29 | if (!DeflateEncoder) 30 | DeflateEncoder = DeflateEncoderSpec = new NDeflate::NEncoder::CCOMCoder; 31 | } 32 | 33 | STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream, 34 | const UInt64 *inSize, const UInt64 * /* outSize */, ICompressProgressInfo *progress) 35 | { 36 | DEFLATE_TRY_BEGIN 37 | if (!AdlerStream) 38 | AdlerStream = AdlerSpec = new CInStreamWithAdler; 39 | Create(); 40 | 41 | { 42 | Byte buf[2] = { 0x78, 0xDA }; 43 | RINOK(WriteStream(outStream, buf, 2)); 44 | } 45 | 46 | AdlerSpec->SetStream(inStream); 47 | AdlerSpec->Init(); 48 | HRESULT res = DeflateEncoder->Code(AdlerStream, outStream, inSize, NULL, progress); 49 | AdlerSpec->ReleaseStream(); 50 | 51 | RINOK(res); 52 | 53 | { 54 | UInt32 a = AdlerSpec->GetAdler(); 55 | Byte buf[4] = { (Byte)(a >> 24), (Byte)(a >> 16), (Byte)(a >> 8), (Byte)(a) }; 56 | return WriteStream(outStream, buf, 4); 57 | } 58 | DEFLATE_TRY_END 59 | } 60 | 61 | }} 62 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Tar/TarItem.h: -------------------------------------------------------------------------------- 1 | // TarItem.h 2 | 3 | #ifndef __ARCHIVE_TAR_ITEM_H 4 | #define __ARCHIVE_TAR_ITEM_H 5 | 6 | #include "../Common/ItemNameUtils.h" 7 | 8 | #include "TarHeader.h" 9 | 10 | namespace NArchive { 11 | namespace NTar { 12 | 13 | struct CItem 14 | { 15 | AString Name; 16 | UInt64 Size; 17 | 18 | UInt32 Mode; 19 | UInt32 UID; 20 | UInt32 GID; 21 | UInt32 MTime; 22 | UInt32 DeviceMajor; 23 | UInt32 DeviceMinor; 24 | 25 | AString LinkName; 26 | AString User; 27 | AString Group; 28 | 29 | char Magic[8]; 30 | char LinkFlag; 31 | bool DeviceMajorDefined; 32 | bool DeviceMinorDefined; 33 | 34 | bool IsLink() const { return LinkFlag == NFileHeader::NLinkFlag::kSymbolicLink && (Size == 0); } 35 | UInt64 GetUnpackSize() const { return IsLink() ? LinkName.Length() : Size; } 36 | 37 | bool IsDir() const 38 | { 39 | switch(LinkFlag) 40 | { 41 | case NFileHeader::NLinkFlag::kDirectory: 42 | case NFileHeader::NLinkFlag::kDumpDir: 43 | return true; 44 | case NFileHeader::NLinkFlag::kOldNormal: 45 | case NFileHeader::NLinkFlag::kNormal: 46 | return NItemName::HasTailSlash(Name, CP_OEMCP); 47 | } 48 | return false; 49 | } 50 | 51 | bool IsMagic() const 52 | { 53 | for (int i = 0; i < 5; i++) 54 | if (Magic[i] != NFileHeader::NMagic::kUsTar[i]) 55 | return false; 56 | return true; 57 | } 58 | 59 | UInt64 GetPackSize() const { return (Size + 0x1FF) & (~((UInt64)0x1FF)); } 60 | }; 61 | 62 | struct CItemEx: public CItem 63 | { 64 | UInt64 HeaderPos; 65 | unsigned HeaderSize; 66 | UInt64 GetDataPosition() const { return HeaderPos + HeaderSize; } 67 | UInt64 GetFullSize() const { return HeaderSize + Size; } 68 | }; 69 | 70 | }} 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/PpmdZip.h: -------------------------------------------------------------------------------- 1 | // PpmdZip.h 2 | // 2010-03-11 : Igor Pavlov : Public domain 3 | 4 | #ifndef __COMPRESS_PPMD_ZIP_H 5 | #define __COMPRESS_PPMD_ZIP_H 6 | 7 | #include 8 | #include 9 | 10 | #include "../../Common/MyCom.h" 11 | 12 | #include "../Common/CWrappers.h" 13 | 14 | #include "../ICoder.h" 15 | 16 | namespace NCompress { 17 | namespace NPpmdZip { 18 | 19 | static const UInt32 kBufSize = (1 << 20); 20 | 21 | struct CBuf 22 | { 23 | Byte *Buf; 24 | 25 | CBuf(): Buf(0) {} 26 | ~CBuf() { ::MidFree(Buf); } 27 | bool Alloc() 28 | { 29 | if (!Buf) 30 | Buf = (Byte *)::MidAlloc(kBufSize); 31 | return (Buf != 0); 32 | } 33 | }; 34 | 35 | class CDecoder : 36 | public ICompressCoder, 37 | public CMyUnknownImp 38 | { 39 | CByteInBufWrap _inStream; 40 | CBuf _outStream; 41 | CPpmd8 _ppmd; 42 | bool _fullFileMode; 43 | public: 44 | MY_UNKNOWN_IMP 45 | STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, 46 | const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 47 | CDecoder(bool fullFileMode); 48 | ~CDecoder(); 49 | }; 50 | 51 | class CEncoder : 52 | public ICompressCoder, 53 | public CMyUnknownImp 54 | { 55 | CByteOutBufWrap _outStream; 56 | CBuf _inStream; 57 | CPpmd8 _ppmd; 58 | UInt32 _usedMemInMB; 59 | unsigned _order; 60 | unsigned _restor; 61 | public: 62 | MY_UNKNOWN_IMP 63 | STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, 64 | const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 65 | HRESULT SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps); 66 | CEncoder(); 67 | ~CEncoder(); 68 | }; 69 | 70 | }} 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/7z/7zDecode.h: -------------------------------------------------------------------------------- 1 | // 7zDecode.h 2 | 3 | #ifndef __7Z_DECODE_H 4 | #define __7Z_DECODE_H 5 | 6 | #include "../../IStream.h" 7 | #include "../../IPassword.h" 8 | 9 | #include "../Common/CoderMixer2.h" 10 | #include "../Common/CoderMixer2MT.h" 11 | #ifdef _ST_MODE 12 | #include "../Common/CoderMixer2ST.h" 13 | #endif 14 | 15 | #include "../../Common/CreateCoder.h" 16 | 17 | #include "7zItem.h" 18 | 19 | namespace NArchive { 20 | namespace N7z { 21 | 22 | struct CBindInfoEx: public NCoderMixer::CBindInfo 23 | { 24 | CRecordVector CoderMethodIDs; 25 | void Clear() 26 | { 27 | CBindInfo::Clear(); 28 | CoderMethodIDs.Clear(); 29 | } 30 | }; 31 | 32 | class CDecoder 33 | { 34 | bool _bindInfoExPrevIsDefined; 35 | CBindInfoEx _bindInfoExPrev; 36 | 37 | bool _multiThread; 38 | #ifdef _ST_MODE 39 | NCoderMixer::CCoderMixer2ST *_mixerCoderSTSpec; 40 | #endif 41 | NCoderMixer::CCoderMixer2MT *_mixerCoderMTSpec; 42 | NCoderMixer::CCoderMixer2 *_mixerCoderCommon; 43 | 44 | CMyComPtr _mixerCoder; 45 | CObjectVector > _decoders; 46 | // CObjectVector > _decoders2; 47 | public: 48 | CDecoder(bool multiThread); 49 | HRESULT Decode( 50 | DECL_EXTERNAL_CODECS_LOC_VARS 51 | IInStream *inStream, 52 | UInt64 startPos, 53 | const UInt64 *packSizes, 54 | const CFolder &folder, 55 | ISequentialOutStream *outStream, 56 | ICompressProgressInfo *compressProgress 57 | #ifndef _NO_CRYPTO 58 | , ICryptoGetTextPassword *getTextPasswordSpec, bool &passwordIsDefined 59 | #endif 60 | #if !defined(_7ZIP_ST) && !defined(_SFX) 61 | , bool mtMode, UInt32 numThreads 62 | #endif 63 | ); 64 | }; 65 | 66 | }} 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/CommandLineParser.h: -------------------------------------------------------------------------------- 1 | // Common/CommandLineParser.h 2 | 3 | #ifndef __COMMON_COMMAND_LINE_PARSER_H 4 | #define __COMMON_COMMAND_LINE_PARSER_H 5 | 6 | #include "MyString.h" 7 | 8 | namespace NCommandLineParser { 9 | 10 | bool SplitCommandLine(const UString &src, UString &dest1, UString &dest2); 11 | void SplitCommandLine(const UString &s, UStringVector &parts); 12 | 13 | namespace NSwitchType { 14 | enum EEnum 15 | { 16 | kSimple, 17 | kPostMinus, 18 | kLimitedPostString, 19 | kUnLimitedPostString, 20 | kPostChar 21 | }; 22 | } 23 | 24 | struct CSwitchForm 25 | { 26 | const wchar_t *IDString; 27 | NSwitchType::EEnum Type; 28 | bool Multi; 29 | int MinLen; 30 | int MaxLen; 31 | const wchar_t *PostCharSet; 32 | }; 33 | 34 | struct CSwitchResult 35 | { 36 | bool ThereIs; 37 | bool WithMinus; 38 | UStringVector PostStrings; 39 | int PostCharIndex; 40 | CSwitchResult(): ThereIs(false) {}; 41 | }; 42 | 43 | class CParser 44 | { 45 | int _numSwitches; 46 | CSwitchResult *_switches; 47 | bool ParseString(const UString &s, const CSwitchForm *switchForms); 48 | public: 49 | UStringVector NonSwitchStrings; 50 | CParser(int numSwitches); 51 | ~CParser(); 52 | void ParseStrings(const CSwitchForm *switchForms, 53 | const UStringVector &commandStrings); 54 | const CSwitchResult& operator[](size_t index) const; 55 | }; 56 | 57 | ///////////////////////////////// 58 | // Command parsing procedures 59 | 60 | struct CCommandForm 61 | { 62 | const wchar_t *IDString; 63 | bool PostStringMode; 64 | }; 65 | 66 | // Returns: Index of form and postString; -1, if there is no match 67 | int ParseCommand(int numCommandForms, const CCommandForm *commandForms, 68 | const UString &commandString, UString &postString); 69 | 70 | } 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /lib/codecs/rtl/LzmaUtil/Lzma86Dec.c: -------------------------------------------------------------------------------- 1 | /* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder 2 | 2008-04-07 3 | Igor Pavlov 4 | Public domain */ 5 | 6 | #include "Lzma86Dec.h" 7 | 8 | #include "../Alloc.h" 9 | #include "../Bra.h" 10 | #include "../LzmaDec.h" 11 | 12 | #define LZMA86_SIZE_OFFSET (1 + LZMA_PROPS_SIZE) 13 | #define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8) 14 | 15 | static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); } 16 | static void SzFree(void *p, void *address) { p = p; MyFree(address); } 17 | static ISzAlloc g_Alloc = { SzAlloc, SzFree }; 18 | 19 | SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize) 20 | { 21 | unsigned i; 22 | if (srcLen < LZMA86_HEADER_SIZE) 23 | return SZ_ERROR_INPUT_EOF; 24 | *unpackSize = 0; 25 | for (i = 0; i < sizeof(UInt64); i++) 26 | *unpackSize += ((UInt64)src[LZMA86_SIZE_OFFSET + i]) << (8 * i); 27 | return SZ_OK; 28 | } 29 | 30 | SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen) 31 | { 32 | SRes res; 33 | int useFilter; 34 | SizeT inSizePure; 35 | ELzmaStatus status; 36 | 37 | if (*srcLen < LZMA86_HEADER_SIZE) 38 | return SZ_ERROR_INPUT_EOF; 39 | 40 | useFilter = src[0]; 41 | 42 | if (useFilter > 1) 43 | { 44 | *destLen = 0; 45 | return SZ_ERROR_UNSUPPORTED; 46 | } 47 | 48 | inSizePure = *srcLen - LZMA86_HEADER_SIZE; 49 | res = LzmaDecode(dest, destLen, src + LZMA86_HEADER_SIZE, &inSizePure, 50 | src + 1, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc); 51 | *srcLen = inSizePure + LZMA86_HEADER_SIZE; 52 | if (res != SZ_OK) 53 | return res; 54 | if (useFilter == 1) 55 | { 56 | UInt32 x86State; 57 | x86_Convert_Init(x86State); 58 | x86_Convert(dest, *destLen, 0, &x86State, 0); 59 | } 60 | return SZ_OK; 61 | } 62 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/StreamUtils.cpp: -------------------------------------------------------------------------------- 1 | // StreamUtils.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "StreamUtils.h" 6 | 7 | static const UInt32 kBlockSize = ((UInt32)1 << 31); 8 | 9 | HRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *processedSize) 10 | { 11 | size_t size = *processedSize; 12 | *processedSize = 0; 13 | while (size != 0) 14 | { 15 | UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize; 16 | UInt32 processedSizeLoc; 17 | HRESULT res = stream->Read(data, curSize, &processedSizeLoc); 18 | *processedSize += processedSizeLoc; 19 | data = (void *)((Byte *)data + processedSizeLoc); 20 | size -= processedSizeLoc; 21 | RINOK(res); 22 | if (processedSizeLoc == 0) 23 | return S_OK; 24 | } 25 | return S_OK; 26 | } 27 | 28 | HRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size) 29 | { 30 | size_t processedSize = size; 31 | RINOK(ReadStream(stream, data, &processedSize)); 32 | return (size == processedSize) ? S_OK : S_FALSE; 33 | } 34 | 35 | HRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size) 36 | { 37 | size_t processedSize = size; 38 | RINOK(ReadStream(stream, data, &processedSize)); 39 | return (size == processedSize) ? S_OK : E_FAIL; 40 | } 41 | 42 | HRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size) 43 | { 44 | while (size != 0) 45 | { 46 | UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize; 47 | UInt32 processedSizeLoc; 48 | HRESULT res = stream->Write(data, curSize, &processedSizeLoc); 49 | data = (const void *)((const Byte *)data + processedSizeLoc); 50 | size -= processedSizeLoc; 51 | RINOK(res); 52 | if (processedSizeLoc == 0) 53 | return E_FAIL; 54 | } 55 | return S_OK; 56 | } 57 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Zip/ZipOut.h: -------------------------------------------------------------------------------- 1 | // ZipOut.h 2 | 3 | #ifndef __ZIP_OUT_H 4 | #define __ZIP_OUT_H 5 | 6 | #include "Common/MyCom.h" 7 | 8 | #include "../../IStream.h" 9 | #include "../../Common/OutBuffer.h" 10 | 11 | #include "ZipItem.h" 12 | 13 | namespace NArchive { 14 | namespace NZip { 15 | 16 | // can throw CSystemException and COutBufferException 17 | 18 | class COutArchive 19 | { 20 | CMyComPtr m_Stream; 21 | COutBuffer m_OutBuffer; 22 | 23 | UInt64 m_BasePosition; 24 | UInt32 m_LocalFileHeaderSize; 25 | UInt32 m_ExtraSize; 26 | bool m_IsZip64; 27 | 28 | void WriteBytes(const void *buffer, UInt32 size); 29 | void WriteByte(Byte b); 30 | void WriteUInt16(UInt16 value); 31 | void WriteUInt32(UInt32 value); 32 | void WriteUInt64(UInt64 value); 33 | 34 | void WriteExtraHeader(const CItem &item); 35 | void WriteCentralHeader(const CItem &item); 36 | void WriteExtra(const CExtraBlock &extra); 37 | void SeekTo(UInt64 offset); 38 | public: 39 | void Create(IOutStream *outStream); 40 | void MoveBasePosition(UInt64 distanceToMove); 41 | UInt64 GetCurrentPosition() const { return m_BasePosition; }; 42 | void PrepareWriteCompressedDataZip64(UInt16 fileNameLength, bool isZip64, bool aesEncryption); 43 | void PrepareWriteCompressedData(UInt16 fileNameLength, UInt64 unPackSize, bool aesEncryption); 44 | void PrepareWriteCompressedData2(UInt16 fileNameLength, UInt64 unPackSize, UInt64 packSize, bool aesEncryption); 45 | void WriteLocalHeader(const CLocalItem &item); 46 | 47 | void WriteCentralDir(const CObjectVector &items, const CByteBuffer *comment); 48 | 49 | void CreateStreamForCompressing(IOutStream **outStream); 50 | void CreateStreamForCopying(ISequentialOutStream **outStream); 51 | void SeekToPackedDataPosition(); 52 | }; 53 | 54 | }} 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Cab/CabItem.h: -------------------------------------------------------------------------------- 1 | // Archive/CabItem.h 2 | 3 | #ifndef __ARCHIVE_CAB_ITEM_H 4 | #define __ARCHIVE_CAB_ITEM_H 5 | 6 | #include "Common/Types.h" 7 | #include "Common/MyString.h" 8 | #include "CabHeader.h" 9 | 10 | namespace NArchive { 11 | namespace NCab { 12 | 13 | struct CFolder 14 | { 15 | UInt32 DataStart; // offset of the first CFDATA block in this folder 16 | UInt16 NumDataBlocks; // number of CFDATA blocks in this folder 17 | Byte CompressionTypeMajor; 18 | Byte CompressionTypeMinor; 19 | Byte GetCompressionMethod() const { return (Byte)(CompressionTypeMajor & 0xF); } 20 | }; 21 | 22 | struct CItem 23 | { 24 | AString Name; 25 | UInt32 Offset; 26 | UInt32 Size; 27 | UInt32 Time; 28 | UInt16 FolderIndex; 29 | UInt16 Flags; 30 | UInt16 Attributes; 31 | 32 | UInt64 GetEndOffset() const { return (UInt64)Offset + Size; } 33 | UInt32 GetWinAttributes() const { return (Attributes & ~NHeader::kFileNameIsUTFAttributeMask); } 34 | bool IsNameUTF() const { return (Attributes & NHeader::kFileNameIsUTFAttributeMask) != 0; } 35 | bool IsDir() const { return (Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0; } 36 | 37 | bool ContinuedFromPrev() const 38 | { 39 | return 40 | (FolderIndex == NHeader::NFolderIndex::kContinuedFromPrev) || 41 | (FolderIndex == NHeader::NFolderIndex::kContinuedPrevAndNext); 42 | } 43 | 44 | bool ContinuedToNext() const 45 | { 46 | return 47 | (FolderIndex == NHeader::NFolderIndex::kContinuedToNext) || 48 | (FolderIndex == NHeader::NFolderIndex::kContinuedPrevAndNext); 49 | } 50 | 51 | int GetFolderIndex(int numFolders) const 52 | { 53 | if (ContinuedFromPrev()) 54 | return 0; 55 | if (ContinuedToNext()) 56 | return (numFolders - 1); 57 | return FolderIndex; 58 | } 59 | }; 60 | 61 | }} 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Compress/ByteSwap.cpp: -------------------------------------------------------------------------------- 1 | // ByteSwap.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../../Common/MyCom.h" 6 | 7 | #include "../ICoder.h" 8 | 9 | #include "../Common/RegisterCodec.h" 10 | 11 | class CByteSwap2: 12 | public ICompressFilter, 13 | public CMyUnknownImp 14 | { 15 | public: 16 | MY_UNKNOWN_IMP 17 | STDMETHOD(Init)(); 18 | STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size); 19 | }; 20 | 21 | class CByteSwap4: 22 | public ICompressFilter, 23 | public CMyUnknownImp 24 | { 25 | public: 26 | MY_UNKNOWN_IMP 27 | STDMETHOD(Init)(); 28 | STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size); 29 | }; 30 | 31 | STDMETHODIMP CByteSwap2::Init() { return S_OK; } 32 | 33 | STDMETHODIMP_(UInt32) CByteSwap2::Filter(Byte *data, UInt32 size) 34 | { 35 | const UInt32 kStep = 2; 36 | UInt32 i; 37 | for (i = 0; i + kStep <= size; i += kStep) 38 | { 39 | Byte b = data[i]; 40 | data[i] = data[i + 1]; 41 | data[i + 1] = b; 42 | } 43 | return i; 44 | } 45 | 46 | STDMETHODIMP CByteSwap4::Init() { return S_OK; } 47 | 48 | STDMETHODIMP_(UInt32) CByteSwap4::Filter(Byte *data, UInt32 size) 49 | { 50 | const UInt32 kStep = 4; 51 | UInt32 i; 52 | for (i = 0; i + kStep <= size; i += kStep) 53 | { 54 | Byte b0 = data[i]; 55 | Byte b1 = data[i + 1]; 56 | data[i] = data[i + 3]; 57 | data[i + 1] = data[i + 2]; 58 | data[i + 2] = b1; 59 | data[i + 3] = b0; 60 | } 61 | return i; 62 | } 63 | 64 | static void *CreateCodec2() { return (void *)(ICompressFilter *)(new CByteSwap2); } 65 | static void *CreateCodec4() { return (void *)(ICompressFilter *)(new CByteSwap4); } 66 | 67 | static CCodecInfo g_CodecsInfo[] = 68 | { 69 | { CreateCodec2, CreateCodec2, 0x020302, L"Swap2", 1, true }, 70 | { CreateCodec4, CreateCodec4, 0x020304, L"Swap4", 1, true } 71 | }; 72 | 73 | REGISTER_CODECS(ByteSwap) 74 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/IStream.h: -------------------------------------------------------------------------------- 1 | // IStream.h 2 | 3 | #ifndef __ISTREAM_H 4 | #define __ISTREAM_H 5 | 6 | #include "../Common/MyUnknown.h" 7 | #include "../Common/Types.h" 8 | 9 | #include "IDecl.h" 10 | 11 | #define STREAM_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 3, x) 12 | #define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x) 13 | 14 | STREAM_INTERFACE(ISequentialInStream, 0x01) 15 | { 16 | STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE; 17 | /* 18 | Out: if size != 0, return_value = S_OK and (*processedSize == 0), 19 | then there are no more bytes in stream. 20 | if (size > 0) && there are bytes in stream, 21 | this function must read at least 1 byte. 22 | This function is allowed to read less than number of remaining bytes in stream. 23 | You must call Read function in loop, if you need exact amount of data 24 | */ 25 | }; 26 | 27 | STREAM_INTERFACE(ISequentialOutStream, 0x02) 28 | { 29 | STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE; 30 | /* 31 | if (size > 0) this function must write at least 1 byte. 32 | This function is allowed to write less than "size". 33 | You must call Write function in loop, if you need to write exact amount of data 34 | */ 35 | }; 36 | 37 | STREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03) 38 | { 39 | STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE; 40 | }; 41 | 42 | STREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04) 43 | { 44 | STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE; 45 | STDMETHOD(SetSize)(UInt64 newSize) PURE; 46 | }; 47 | 48 | STREAM_INTERFACE(IStreamGetSize, 0x06) 49 | { 50 | STDMETHOD(GetSize)(UInt64 *size) PURE; 51 | }; 52 | 53 | STREAM_INTERFACE(IOutStreamFlush, 0x07) 54 | { 55 | STDMETHOD(Flush)() PURE; 56 | }; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/Common/InStreamWithCRC.h: -------------------------------------------------------------------------------- 1 | // InStreamWithCRC.h 2 | 3 | #ifndef __IN_STREAM_WITH_CRC_H 4 | #define __IN_STREAM_WITH_CRC_H 5 | 6 | #include 7 | 8 | #include "../../../Common/MyCom.h" 9 | 10 | #include "../../IStream.h" 11 | 12 | class CSequentialInStreamWithCRC: 13 | public ISequentialInStream, 14 | public CMyUnknownImp 15 | { 16 | public: 17 | MY_UNKNOWN_IMP 18 | 19 | STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); 20 | private: 21 | CMyComPtr _stream; 22 | UInt64 _size; 23 | UInt32 _crc; 24 | bool _wasFinished; 25 | public: 26 | void SetStream(ISequentialInStream *stream) { _stream = stream; } 27 | void Init() 28 | { 29 | _size = 0; 30 | _wasFinished = false; 31 | _crc = CRC_INIT_VAL; 32 | } 33 | void ReleaseStream() { _stream.Release(); } 34 | UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); } 35 | UInt64 GetSize() const { return _size; } 36 | bool WasFinished() const { return _wasFinished; } 37 | }; 38 | 39 | class CInStreamWithCRC: 40 | public IInStream, 41 | public CMyUnknownImp 42 | { 43 | public: 44 | MY_UNKNOWN_IMP1(IInStream) 45 | 46 | STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); 47 | STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition); 48 | private: 49 | CMyComPtr _stream; 50 | UInt64 _size; 51 | UInt32 _crc; 52 | // bool _wasFinished; 53 | public: 54 | void SetStream(IInStream *stream) { _stream = stream; } 55 | void Init() 56 | { 57 | _size = 0; 58 | // _wasFinished = false; 59 | _crc = CRC_INIT_VAL; 60 | } 61 | void ReleaseStream() { _stream.Release(); } 62 | UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); } 63 | UInt64 GetSize() const { return _size; } 64 | // bool WasFinished() const { return _wasFinished; } 65 | }; 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/IntToString.cpp: -------------------------------------------------------------------------------- 1 | // Common/IntToString.cpp 2 | 3 | #ifndef _WIN32 4 | #include "StdAfx.h" 5 | #else 6 | #include "Windows/StdAfx.h" 7 | #endif 8 | 9 | #include "IntToString.h" 10 | 11 | void ConvertUInt64ToString(UInt64 value, char *s, UInt32 base) 12 | { 13 | if (base < 2 || base > 36) 14 | { 15 | *s = '\0'; 16 | return; 17 | } 18 | char temp[72]; 19 | int pos = 0; 20 | do 21 | { 22 | int delta = (int)(value % base); 23 | temp[pos++] = (char)((delta < 10) ? ('0' + delta) : ('a' + (delta - 10))); 24 | value /= base; 25 | } 26 | while (value != 0); 27 | do 28 | *s++ = temp[--pos]; 29 | while (pos > 0); 30 | *s = '\0'; 31 | } 32 | 33 | void ConvertUInt64ToString(UInt64 value, wchar_t *s) 34 | { 35 | wchar_t temp[32]; 36 | int pos = 0; 37 | do 38 | { 39 | temp[pos++] = (wchar_t)(L'0' + (int)(value % 10)); 40 | value /= 10; 41 | } 42 | while (value != 0); 43 | do 44 | *s++ = temp[--pos]; 45 | while (pos > 0); 46 | *s = L'\0'; 47 | } 48 | 49 | void ConvertUInt32ToString(UInt32 value, char *s) { ConvertUInt64ToString(value, s); } 50 | void ConvertUInt32ToString(UInt32 value, wchar_t *s) { ConvertUInt64ToString(value, s); } 51 | 52 | void ConvertInt64ToString(Int64 value, char *s) 53 | { 54 | if (value < 0) 55 | { 56 | *s++ = '-'; 57 | value = -value; 58 | } 59 | ConvertUInt64ToString(value, s); 60 | } 61 | 62 | void ConvertInt64ToString(Int64 value, wchar_t *s) 63 | { 64 | if (value < 0) 65 | { 66 | *s++ = L'-'; 67 | value = -value; 68 | } 69 | ConvertUInt64ToString(value, s); 70 | } 71 | 72 | void ConvertUInt32ToHexWithZeros(UInt32 value, char *s) 73 | { 74 | for (int i = 0; i < 8; i++) 75 | { 76 | int t = value & 0xF; 77 | value >>= 4; 78 | s[7 - i] = (char)((t < 10) ? ('0' + t) : ('A' + (t - 10))); 79 | } 80 | s[8] = '\0'; 81 | } 82 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/ListFileUtils.cpp: -------------------------------------------------------------------------------- 1 | // Common/ListFileUtils.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "MyWindows.h" 6 | #include "../Windows/FileIO.h" 7 | 8 | #include "ListFileUtils.h" 9 | #include "StringConvert.h" 10 | #include "UTFConvert.h" 11 | 12 | static const char kQuoteChar = '\"'; 13 | static void RemoveQuote(UString &s) 14 | { 15 | if (s.Length() >= 2) 16 | if (s[0] == kQuoteChar && s[s.Length() - 1] == kQuoteChar) 17 | s = s.Mid(1, s.Length() - 2); 18 | } 19 | 20 | bool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &resultStrings, UINT codePage) 21 | { 22 | NWindows::NFile::NIO::CInFile file; 23 | if (!file.Open(fileName,true)) /* follow the symbolic link */ 24 | return false; 25 | UInt64 length; 26 | if (!file.GetLength(length)) 27 | return false; 28 | if (length > ((UInt32)1 << 31)) 29 | return false; 30 | AString s; 31 | char *p = s.GetBuffer((int)length + 1); 32 | UInt32 processed; 33 | if (!file.Read(p, (UInt32)length, processed)) 34 | return false; 35 | p[(UInt32)length] = 0; 36 | s.ReleaseBuffer(); 37 | file.Close(); 38 | 39 | UString u; 40 | #ifdef CP_UTF8 41 | if (codePage == CP_UTF8) 42 | { 43 | if (!ConvertUTF8ToUnicode(s, u)) 44 | return false; 45 | } 46 | else 47 | #endif 48 | u = MultiByteToUnicodeString(s, codePage); 49 | if (!u.IsEmpty()) 50 | { 51 | if (u[0] == 0xFEFF) 52 | u.Delete(0); 53 | } 54 | 55 | UString t; 56 | for (int i = 0; i < u.Length(); i++) 57 | { 58 | wchar_t c = u[i]; 59 | if (c == L'\n' || c == 0xD) 60 | { 61 | t.Trim(); 62 | RemoveQuote(t); 63 | if (!t.IsEmpty()) 64 | resultStrings.Add(t); 65 | t.Empty(); 66 | } 67 | else 68 | t += c; 69 | } 70 | t.Trim(); 71 | RemoveQuote(t); 72 | if (!t.IsEmpty()) 73 | resultStrings.Add(t); 74 | return true; 75 | } 76 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Crypto/Sha1.h: -------------------------------------------------------------------------------- 1 | // Crypto/Sha1.h 2 | // This file is based on public domain 3 | // Steve Reid and Wei Dai's code from Crypto++ 4 | 5 | #ifndef __CRYPTO_SHA1_H 6 | #define __CRYPTO_SHA1_H 7 | 8 | #include 9 | #include "../../Common/Types.h" 10 | 11 | // Sha1 implementation in RAR before version 3.60 has bug: 12 | // it changes data bytes in some cases. 13 | // So this class supports both versions: normal_SHA and rar3Mode 14 | 15 | namespace NCrypto { 16 | namespace NSha1 { 17 | 18 | const unsigned kBlockSize = 64; 19 | const unsigned kDigestSize = 20; 20 | 21 | const unsigned kBlockSizeInWords = (kBlockSize >> 2); 22 | const unsigned kDigestSizeInWords = (kDigestSize >> 2); 23 | 24 | class CContextBase 25 | { 26 | protected: 27 | UInt32 _state[5]; 28 | UInt64 _count; 29 | void UpdateBlock(UInt32 *data, bool returnRes = false) 30 | { 31 | GetBlockDigest(data, _state, returnRes); 32 | _count++; 33 | } 34 | public: 35 | void Init(); 36 | void GetBlockDigest(UInt32 *blockData, UInt32 *destDigest, bool returnRes = false); 37 | // PrepareBlock can be used only when size <= 13. size in Words 38 | void PrepareBlock(UInt32 *block, unsigned int size) const; 39 | }; 40 | 41 | class CContextBase2: public CContextBase 42 | { 43 | protected: 44 | unsigned _count2; 45 | UInt32 _buffer[kBlockSizeInWords]; 46 | void UpdateBlock() { CContextBase::UpdateBlock(_buffer); } 47 | public: 48 | void Init() { CContextBase::Init(); _count2 = 0; } 49 | }; 50 | 51 | class CContext: public CContextBase2 52 | { 53 | public: 54 | void Update(const Byte *data, size_t size); 55 | void UpdateRar(Byte *data, size_t size, bool rar350Mode); 56 | void Final(Byte *digest); 57 | }; 58 | 59 | class CContext32: public CContextBase2 60 | { 61 | public: 62 | void Update(const UInt32 *data, size_t size); 63 | void Final(UInt32 *digest); 64 | }; 65 | 66 | }} 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /lib/codecs/core/Windows/System-win.cpp: -------------------------------------------------------------------------------- 1 | // Windows/System.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "../Common/Defs.h" 6 | 7 | #include "System.h" 8 | 9 | namespace NWindows { 10 | namespace NSystem { 11 | 12 | UInt32 GetNumberOfProcessors() 13 | { 14 | SYSTEM_INFO systemInfo; 15 | GetSystemInfo(&systemInfo); 16 | return (UInt32)systemInfo.dwNumberOfProcessors; 17 | } 18 | 19 | #ifndef UNDER_CE 20 | 21 | #if !defined(_WIN64) && defined(__GNUC__) 22 | 23 | typedef struct _MY_MEMORYSTATUSEX { 24 | DWORD dwLength; 25 | DWORD dwMemoryLoad; 26 | DWORDLONG ullTotalPhys; 27 | DWORDLONG ullAvailPhys; 28 | DWORDLONG ullTotalPageFile; 29 | DWORDLONG ullAvailPageFile; 30 | DWORDLONG ullTotalVirtual; 31 | DWORDLONG ullAvailVirtual; 32 | DWORDLONG ullAvailExtendedVirtual; 33 | } MY_MEMORYSTATUSEX, *MY_LPMEMORYSTATUSEX; 34 | 35 | #else 36 | 37 | #define MY_MEMORYSTATUSEX MEMORYSTATUSEX 38 | #define MY_LPMEMORYSTATUSEX LPMEMORYSTATUSEX 39 | 40 | #endif 41 | 42 | typedef BOOL (WINAPI *GlobalMemoryStatusExP)(MY_LPMEMORYSTATUSEX lpBuffer); 43 | 44 | #endif 45 | 46 | UInt64 GetRamSize() 47 | { 48 | #ifndef UNDER_CE 49 | MY_MEMORYSTATUSEX stat; 50 | stat.dwLength = sizeof(stat); 51 | #endif 52 | #ifdef _WIN64 53 | if (!::GlobalMemoryStatusEx(&stat)) 54 | return 0; 55 | return MyMin(stat.ullTotalVirtual, stat.ullTotalPhys); 56 | #else 57 | #ifndef UNDER_CE 58 | GlobalMemoryStatusExP globalMemoryStatusEx = (GlobalMemoryStatusExP) 59 | ::GetProcAddress(::GetModuleHandle(TEXT("kernel32.dll")), "GlobalMemoryStatusEx"); 60 | if (globalMemoryStatusEx != 0 && globalMemoryStatusEx(&stat)) 61 | return MyMin(stat.ullTotalVirtual, stat.ullTotalPhys); 62 | #endif 63 | { 64 | MEMORYSTATUS stat; 65 | stat.dwLength = sizeof(stat); 66 | ::GlobalMemoryStatus(&stat); 67 | return MyMin(stat.dwTotalVirtual, stat.dwTotalPhys); 68 | } 69 | #endif 70 | } 71 | 72 | }} 73 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Archive/7z/7zHeader.h: -------------------------------------------------------------------------------- 1 | // 7z/7zHeader.h 2 | 3 | #ifndef __7Z_HEADER_H 4 | #define __7Z_HEADER_H 5 | 6 | #include "../../../Common/Types.h" 7 | 8 | namespace NArchive { 9 | namespace N7z { 10 | 11 | const int kSignatureSize = 6; 12 | extern Byte kSignature[kSignatureSize]; 13 | 14 | // #define _7Z_VOL 15 | // 7z-MultiVolume is not finished yet. 16 | // It can work already, but I still do not like some 17 | // things of that new multivolume format. 18 | // So please keep it commented. 19 | 20 | #ifdef _7Z_VOL 21 | extern Byte kFinishSignature[kSignatureSize]; 22 | #endif 23 | 24 | struct CArchiveVersion 25 | { 26 | Byte Major; 27 | Byte Minor; 28 | }; 29 | 30 | const Byte kMajorVersion = 0; 31 | 32 | struct CStartHeader 33 | { 34 | UInt64 NextHeaderOffset; 35 | UInt64 NextHeaderSize; 36 | UInt32 NextHeaderCRC; 37 | }; 38 | 39 | const UInt32 kStartHeaderSize = 20; 40 | 41 | #ifdef _7Z_VOL 42 | struct CFinishHeader: public CStartHeader 43 | { 44 | UInt64 ArchiveStartOffset; // data offset from end if that struct 45 | UInt64 AdditionalStartBlockSize; // start signature & start header size 46 | }; 47 | 48 | const UInt32 kFinishHeaderSize = kStartHeaderSize + 16; 49 | #endif 50 | 51 | namespace NID 52 | { 53 | enum EEnum 54 | { 55 | kEnd, 56 | 57 | kHeader, 58 | 59 | kArchiveProperties, 60 | 61 | kAdditionalStreamsInfo, 62 | kMainStreamsInfo, 63 | kFilesInfo, 64 | 65 | kPackInfo, 66 | kUnpackInfo, 67 | kSubStreamsInfo, 68 | 69 | kSize, 70 | kCRC, 71 | 72 | kFolder, 73 | 74 | kCodersUnpackSize, 75 | kNumUnpackStream, 76 | 77 | kEmptyStream, 78 | kEmptyFile, 79 | kAnti, 80 | 81 | kName, 82 | kCTime, 83 | kATime, 84 | kMTime, 85 | kWinAttributes, 86 | kComment, 87 | 88 | kEncodedHeader, 89 | 90 | kStartPos, 91 | kDummy 92 | }; 93 | } 94 | 95 | }} 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /lib/codecs/core/Codecs/Common/InBuffer.cpp: -------------------------------------------------------------------------------- 1 | // InBuffer.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include 6 | 7 | #include "InBuffer.h" 8 | 9 | CInBuffer::CInBuffer(): 10 | _buffer(0), 11 | _bufferLimit(0), 12 | _bufferBase(0), 13 | _stream(0), 14 | _bufferSize(0) 15 | {} 16 | 17 | bool CInBuffer::Create(UInt32 bufferSize) 18 | { 19 | const UInt32 kMinBlockSize = 1; 20 | if (bufferSize < kMinBlockSize) 21 | bufferSize = kMinBlockSize; 22 | if (_bufferBase != 0 && _bufferSize == bufferSize) 23 | return true; 24 | Free(); 25 | _bufferSize = bufferSize; 26 | _bufferBase = (Byte *)::MidAlloc(bufferSize); 27 | return (_bufferBase != 0); 28 | } 29 | 30 | void CInBuffer::Free() 31 | { 32 | ::MidFree(_bufferBase); 33 | _bufferBase = 0; 34 | } 35 | 36 | void CInBuffer::SetStream(ISequentialInStream *stream) 37 | { 38 | _stream = stream; 39 | } 40 | 41 | void CInBuffer::Init() 42 | { 43 | _processedSize = 0; 44 | _buffer = _bufferBase; 45 | _bufferLimit = _buffer; 46 | _wasFinished = false; 47 | #ifdef _NO_EXCEPTIONS 48 | ErrorCode = S_OK; 49 | #endif 50 | } 51 | 52 | bool CInBuffer::ReadBlock() 53 | { 54 | #ifdef _NO_EXCEPTIONS 55 | if (ErrorCode != S_OK) 56 | return false; 57 | #endif 58 | if (_wasFinished) 59 | return false; 60 | _processedSize += (_buffer - _bufferBase); 61 | UInt32 numProcessedBytes; 62 | HRESULT result = _stream->Read(_bufferBase, _bufferSize, &numProcessedBytes); 63 | #ifdef _NO_EXCEPTIONS 64 | ErrorCode = result; 65 | #else 66 | if (result != S_OK) 67 | throw CInBufferException(result); 68 | #endif 69 | _buffer = _bufferBase; 70 | _bufferLimit = _buffer + numProcessedBytes; 71 | _wasFinished = (numProcessedBytes == 0); 72 | return (!_wasFinished); 73 | } 74 | 75 | Byte CInBuffer::ReadBlock2() 76 | { 77 | if (!ReadBlock()) 78 | { 79 | _processedSize++; 80 | return 0xFF; 81 | } 82 | return *_buffer++; 83 | } 84 | -------------------------------------------------------------------------------- /lib/codecs/core/Common/StringToInt.cpp: -------------------------------------------------------------------------------- 1 | // Common/StringToInt.cpp 2 | 3 | #include "StdAfx.h" 4 | 5 | #include "StringToInt.h" 6 | 7 | UInt64 ConvertStringToUInt64(const char *s, const char **end) 8 | { 9 | UInt64 result = 0; 10 | for (;;) 11 | { 12 | char c = *s; 13 | if (c < '0' || c > '9') 14 | { 15 | if (end != NULL) 16 | *end = s; 17 | return result; 18 | } 19 | result *= 10; 20 | result += (c - '0'); 21 | s++; 22 | } 23 | } 24 | 25 | UInt64 ConvertOctStringToUInt64(const char *s, const char **end) 26 | { 27 | UInt64 result = 0; 28 | for (;;) 29 | { 30 | char c = *s; 31 | if (c < '0' || c > '7') 32 | { 33 | if (end != NULL) 34 | *end = s; 35 | return result; 36 | } 37 | result <<= 3; 38 | result += (c - '0'); 39 | s++; 40 | } 41 | } 42 | 43 | UInt64 ConvertHexStringToUInt64(const char *s, const char **end) 44 | { 45 | UInt64 result = 0; 46 | for (;;) 47 | { 48 | char c = *s; 49 | UInt32 v; 50 | if (c >= '0' && c <= '9') v = (c - '0'); 51 | else if (c >= 'A' && c <= 'F') v = 10 + (c - 'A'); 52 | else if (c >= 'a' && c <= 'f') v = 10 + (c - 'a'); 53 | else 54 | { 55 | if (end != NULL) 56 | *end = s; 57 | return result; 58 | } 59 | result <<= 4; 60 | result |= v; 61 | s++; 62 | } 63 | } 64 | 65 | 66 | UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end) 67 | { 68 | UInt64 result = 0; 69 | for (;;) 70 | { 71 | wchar_t c = *s; 72 | if (c < '0' || c > '9') 73 | { 74 | if (end != NULL) 75 | *end = s; 76 | return result; 77 | } 78 | result *= 10; 79 | result += (c - '0'); 80 | s++; 81 | } 82 | } 83 | 84 | 85 | Int64 ConvertStringToInt64(const char *s, const char **end) 86 | { 87 | if (*s == '-') 88 | return -(Int64)ConvertStringToUInt64(s + 1, end); 89 | return ConvertStringToUInt64(s, end); 90 | } 91 | --------------------------------------------------------------------------------