├── .gitignore ├── Extra ├── lsar.1 ├── lsar.bash_completion ├── unar.1 └── unar.bash_completion ├── License.txt ├── README.md ├── UniversalDetector ├── DetectorTest.m ├── English.lproj │ └── InfoPlist.strings ├── Info.plist ├── Makefile.common ├── Makefile.freebsd ├── Makefile.legacy ├── Makefile.linux ├── Makefile.windows ├── UniversalDetector.h ├── UniversalDetector.m ├── UniversalDetector.xcodeproj │ └── project.pbxproj ├── UniversalDetector_Prefix.pch ├── WrappedUniversalDetector.cpp ├── WrappedUniversalDetector.h ├── scan.pl └── universalchardet │ ├── .cvsignore │ ├── Big5Freq.tab │ ├── CharDistribution.cpp │ ├── CharDistribution.h │ ├── EUCKRFreq.tab │ ├── EUCTWFreq.tab │ ├── GB2312Freq.tab │ ├── JISFreq.tab │ ├── JpCntx.cpp │ ├── JpCntx.h │ ├── LangBulgarianModel.cpp │ ├── LangCyrillicModel.cpp │ ├── LangGreekModel.cpp │ ├── LangHebrewModel.cpp │ ├── LangHungarianModel.cpp │ ├── LangThaiModel.cpp │ ├── kludge.c │ ├── nsBig5Prober.cpp │ ├── nsBig5Prober.h │ ├── nsCharSetProber.cpp │ ├── nsCharSetProber.h │ ├── nsCodingStateMachine.h │ ├── nsEUCJPProber.cpp │ ├── nsEUCJPProber.h │ ├── nsEUCKRProber.cpp │ ├── nsEUCKRProber.h │ ├── nsEUCTWProber.cpp │ ├── nsEUCTWProber.h │ ├── nsError.h │ ├── nsEscCharsetProber.cpp │ ├── nsEscCharsetProber.h │ ├── nsEscSM.cpp │ ├── nsGB2312Prober.cpp │ ├── nsGB2312Prober.h │ ├── nsHebrewProber.cpp │ ├── nsHebrewProber.h │ ├── nsLatin1Prober.cpp │ ├── nsLatin1Prober.h │ ├── nsMBCSGroupProber.cpp │ ├── nsMBCSGroupProber.h │ ├── nsMBCSSM.cpp │ ├── nsPkgInt.h │ ├── nsSBCSGroupProber.cpp │ ├── nsSBCSGroupProber.h │ ├── nsSBCharSetProber.cpp │ ├── nsSBCharSetProber.h │ ├── nsSJISProber.cpp │ ├── nsSJISProber.h │ ├── nsUTF8Prober.cpp │ ├── nsUTF8Prober.h │ ├── nsUniversalDetector.cpp │ ├── nsUniversalDetector.h │ ├── nscore.h │ ├── prcpucfg.h │ ├── prmem.h │ ├── protypes.h │ └── prtypes.h └── XADMaster ├── BWT.c ├── BWT.h ├── CRC.h ├── CRC.m ├── CSBlockStreamHandle.h ├── CSBlockStreamHandle.m ├── CSByteStreamHandle.h ├── CSByteStreamHandle.m ├── CSBzip2Handle.h ├── CSBzip2Handle.m ├── CSCommandLineParser.h ├── CSCommandLineParser.m ├── CSFileHandle.h ├── CSFileHandle.m ├── CSHandle.h ├── CSHandle.m ├── CSHexDump.m ├── CSInputBuffer.h ├── CSInputBuffer.m ├── CSJSONPrinter.h ├── CSJSONPrinter.m ├── CSMemoryHandle.h ├── CSMemoryHandle.m ├── CSMultiFileHandle.h ├── CSMultiFileHandle.m ├── CSMultiHandle.h ├── CSMultiHandle.m ├── CSSegmentedHandle.h ├── CSSegmentedHandle.m ├── CSStreamHandle.h ├── CSStreamHandle.m ├── CSSubHandle.h ├── CSSubHandle.m ├── CSZlibHandle.h ├── CSZlibHandle.m ├── CarrylessRangeCoder.h ├── CarrylessRangeCoder.m ├── Checksums.h ├── Checksums.m ├── ClangAnalyser.h ├── CommandLineCommon.h ├── CommandLineCommon.m ├── Crypto ├── aes.h ├── aes_modes.c ├── aescrypt.c ├── aeskey.c ├── aesopt.h ├── aestab.c ├── aestab.h ├── brg_endian.h ├── des.c ├── des.h ├── hmac_sha1.c ├── hmac_sha1.h ├── hmac_sha256.c ├── hmac_sha256.h ├── md5.c ├── md5.h ├── pbkdf2_hmac_sha256.c ├── pbkdf2_hmac_sha256.h ├── sha.c └── sha.h ├── English.lproj └── InfoPlist.strings ├── Info.plist ├── LZSS.c ├── LZSS.h ├── LZW.c ├── LZW.h ├── Makefile.common ├── Makefile.freebsd ├── Makefile.legacy ├── Makefile.linux ├── Makefile.windows ├── NSDateXAD.h ├── NSDateXAD.m ├── NSStringPrinting.h ├── NSStringPrinting.m ├── NumberParsing.h ├── NumberParsing.m ├── PDF ├── CCITTHandle.h ├── CCITTHandle.m ├── LZWHandle.h ├── LZWHandle.m ├── NSDictionaryNumberExtension.h ├── NSDictionaryNumberExtension.m ├── PDFEncryptionHandler.h ├── PDFEncryptionHandler.m ├── PDFEncryptionUtils.h ├── PDFEncryptionUtils.m ├── PDFParser.h ├── PDFParser.m ├── PDFStream.h └── PDFStream.m ├── PPMd ├── Context.c ├── Context.h ├── Dependencies ├── Fuzzer.c ├── Makefile ├── PPMd.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── RangeCoder.c ├── RangeCoder.h ├── SimpleDecompressor.c ├── SubAllocator.h ├── SubAllocatorBrimstone.c ├── SubAllocatorBrimstone.h ├── SubAllocatorVariantG.c ├── SubAllocatorVariantG.h ├── SubAllocatorVariantH.c ├── SubAllocatorVariantH.h ├── SubAllocatorVariantI.c ├── SubAllocatorVariantI.h ├── VariantG.c ├── VariantG.h ├── VariantH.c ├── VariantH.h ├── VariantI.c └── VariantI.h ├── Progress.h ├── Progress.m ├── RARAudioDecoder.c ├── RARAudioDecoder.h ├── RARBug.c ├── RARBug.h ├── RARVirtualMachine.c ├── RARVirtualMachine.h ├── Realloc.h ├── Scanning.h ├── Scanning.m ├── StuffItXEnglishDictionary.c ├── StuffItXUtilities.h ├── StuffItXUtilities.m ├── WinZipJPEG ├── ArithmeticDecoder.c ├── ArithmeticDecoder.h ├── Decompressor.c ├── Decompressor.h ├── Dependencies ├── InputStream.h ├── JPEG.c ├── JPEG.h ├── LZMA.h ├── Makefile ├── RawDecoder.c └── Test.c ├── Windows ├── Foundation.1.0.dll ├── bin │ └── libtoolstub.pl ├── include │ ├── bzlib.h │ ├── regex.h │ ├── zconf.h │ └── zlib.h ├── lib │ ├── libbz2.a │ └── libz.a └── regex.c ├── XAD7ZipAESHandle.h ├── XAD7ZipAESHandle.m ├── XAD7ZipBCJ2Handle.h ├── XAD7ZipBCJ2Handle.m ├── XAD7ZipBranchHandles.h ├── XAD7ZipBranchHandles.m ├── XAD7ZipParser.h ├── XAD7ZipParser.m ├── XADALZipParser.h ├── XADALZipParser.m ├── XADARCCrunchHandle.h ├── XADARCCrunchHandle.m ├── XADARCCrushHandle.h ├── XADARCCrushHandle.m ├── XADARCDistillHandle.h ├── XADARCDistillHandle.m ├── XADARCParser.h ├── XADARCParser.m ├── XADARJFastestHandle.h ├── XADARJFastestHandle.m ├── XADARJParser.h ├── XADARJParser.m ├── XADAppleDouble.h ├── XADAppleDouble.m ├── XADAppleSingleParser.h ├── XADAppleSingleParser.m ├── XADArParser.h ├── XADArParser.m ├── XADArchive.h ├── XADArchive.m ├── XADArchiveParser.h ├── XADArchiveParser.m ├── XADArchiveParserDescriptions.h ├── XADArchiveParserDescriptions.m ├── XADBinHexParser.h ├── XADBinHexParser.m ├── XADBlockHandle.h ├── XADBlockHandle.m ├── XADBzip2Parser.h ├── XADBzip2Parser.m ├── XADCABBlockHandle.h ├── XADCABBlockHandle.m ├── XADCABBlockReader.h ├── XADCABBlockReader.m ├── XADCABParser.h ├── XADCABParser.m ├── XADCFBFParser.h ├── XADCFBFParser.m ├── XADCRCHandle.h ├── XADCRCHandle.m ├── XADCRCSuffixHandle.h ├── XADCRCSuffixHandle.m ├── XADChecksumHandle.h ├── XADChecksumHandle.m ├── XADCompactProLZHHandle.h ├── XADCompactProLZHHandle.m ├── XADCompactProParser.h ├── XADCompactProParser.m ├── XADCompactProRLEHandle.h ├── XADCompactProRLEHandle.m ├── XADCompressHandle.h ├── XADCompressHandle.m ├── XADCompressParser.h ├── XADCompressParser.m ├── XADCpioParser.h ├── XADCpioParser.m ├── XADCrunchHandles.h ├── XADCrunchHandles.m ├── XADCrunchParser.h ├── XADCrunchParser.m ├── XADDeflateHandle.h ├── XADDeflateHandle.m ├── XADDeltaHandle.h ├── XADDeltaHandle.m ├── XADDiskDoublerADnHandle.h ├── XADDiskDoublerADnHandle.m ├── XADDiskDoublerDDnHandle.h ├── XADDiskDoublerDDnHandle.m ├── XADDiskDoublerMethod2Handle.h ├── XADDiskDoublerMethod2Handle.m ├── XADDiskDoublerParser.h ├── XADDiskDoublerParser.m ├── XADException.h ├── XADException.m ├── XADFastLZSSHandle.h ├── XADFastLZSSHandle.m ├── XADGzipParser.h ├── XADGzipParser.m ├── XADISO9660Parser.h ├── XADISO9660Parser.m ├── XADLArcHandles.h ├── XADLArcHandles.m ├── XADLBRParser.h ├── XADLBRParser.m ├── XADLZHDynamicHandle.h ├── XADLZHDynamicHandle.m ├── XADLZHOldHandles.h ├── XADLZHOldHandles.m ├── XADLZHParser.h ├── XADLZHParser.m ├── XADLZHSFXParsers.h ├── XADLZHSFXParsers.m ├── XADLZHStaticHandle.h ├── XADLZHStaticHandle.m ├── XADLZMA2Handle.h ├── XADLZMA2Handle.m ├── XADLZMAAloneParser.h ├── XADLZMAAloneParser.m ├── XADLZMAHandle.h ├── XADLZMAHandle.m ├── XADLZSSHandle.h ├── XADLZSSHandle.m ├── XADLZXHandle.h ├── XADLZXHandle.m ├── XADLZXParser.h ├── XADLZXParser.m ├── XADLibXADIOHandle.h ├── XADLibXADIOHandle.m ├── XADLibXADParser.h ├── XADLibXADParser.m ├── XADMD5Handle.h ├── XADMD5Handle.m ├── XADMSLZXHandle.h ├── XADMSLZXHandle.m ├── XADMSZipHandle.h ├── XADMSZipHandle.m ├── XADMacArchiveParser.h ├── XADMacArchiveParser.m ├── XADMacBinaryParser.h ├── XADMacBinaryParser.m ├── XADMaster.xcodeproj └── project.pbxproj ├── XADMaster_Prefix.pch ├── XADNDSParser.h ├── XADNDSParser.m ├── XADNSAParser.h ├── XADNSAParser.m ├── XADNSISBzip2Handle.h ├── XADNSISBzip2Handle.m ├── XADNSISParser.h ├── XADNSISParser.m ├── XADNowCompressHandle.h ├── XADNowCompressHandle.m ├── XADNowCompressParser.h ├── XADNowCompressParser.m ├── XADPDFParser.h ├── XADPDFParser.m ├── XADPMArc1Handle.h ├── XADPMArc1Handle.m ├── XADPNGWriter.h ├── XADPNGWriter.m ├── XADPPMdHandles.h ├── XADPPMdHandles.m ├── XADPPMdParser.h ├── XADPPMdParser.m ├── XADPackItParser.h ├── XADPackItParser.m ├── XADPaddedBlockHandle.h ├── XADPaddedBlockHandle.m ├── XADPath.h ├── XADPath.m ├── XADPlatform.h ├── XADPlatformLinux.m ├── XADPlatformMacOSX.m ├── XADPlatformWindows.m ├── XADPlatformiOS.m ├── XADPowerPackerParser.h ├── XADPowerPackerParser.m ├── XADPrefixCode.h ├── XADPrefixCode.m ├── XADQuantumHandle.h ├── XADQuantumHandle.m ├── XADRAR13CryptHandle.h ├── XADRAR13CryptHandle.m ├── XADRAR15CryptHandle.h ├── XADRAR15CryptHandle.m ├── XADRAR15Handle.h ├── XADRAR15Handle.m ├── XADRAR20CryptHandle.h ├── XADRAR20CryptHandle.m ├── XADRAR20Handle.h ├── XADRAR20Handle.m ├── XADRAR30Handle.h ├── XADRAR30Handle.m ├── XADRAR50Handle.h ├── XADRAR50Handle.m ├── XADRAR5Parser.h ├── XADRAR5Parser.m ├── XADRARAESHandle.h ├── XADRARAESHandle.m ├── XADRARFilters.h ├── XADRARFilters.m ├── XADRARInputHandle.h ├── XADRARInputHandle.m ├── XADRARParser.h ├── XADRARParser.m ├── XADRARVirtualMachine.h ├── XADRARVirtualMachine.m ├── XADRC4Handle.h ├── XADRC4Handle.m ├── XADRLE90Handle.h ├── XADRLE90Handle.m ├── XADRPMParser.h ├── XADRPMParser.m ├── XADRegex.h ├── XADRegex.m ├── XADResourceFork.h ├── XADResourceFork.m ├── XADSARParser.h ├── XADSARParser.m ├── XADSHA1Handle.h ├── XADSHA1Handle.m ├── XADSWFGeometry.h ├── XADSWFGeometry.m ├── XADSWFParser.h ├── XADSWFParser.m ├── XADSWFTagParser.h ├── XADSWFTagParser.m ├── XADSimpleUnarchiver.h ├── XADSimpleUnarchiver.m ├── XADSkipHandle.h ├── XADSkipHandle.m ├── XADSplitFileParser.h ├── XADSplitFileParser.m ├── XADSqueezeHandle.h ├── XADSqueezeHandle.m ├── XADSqueezeParser.h ├── XADSqueezeParser.m ├── XADStacLZSHandle.h ├── XADStacLZSHandle.m ├── XADString.h ├── XADString.m ├── XADStringCFString.m ├── XADStringICU.m ├── XADStringIconv.m ├── XADStringWindows.m ├── XADStuffIt13Handle.h ├── XADStuffIt13Handle.m ├── XADStuffIt5Parser.h ├── XADStuffIt5Parser.m ├── XADStuffItArsenicHandle.h ├── XADStuffItArsenicHandle.m ├── XADStuffItDESHandle.h ├── XADStuffItDESHandle.m ├── XADStuffItHuffmanHandle.h ├── XADStuffItHuffmanHandle.m ├── XADStuffItOldHandles.h ├── XADStuffItOldHandles.m ├── XADStuffItParser.h ├── XADStuffItParser.m ├── XADStuffItSplitParser.h ├── XADStuffItSplitParser.m ├── XADStuffItXBlendHandle.h ├── XADStuffItXBlendHandle.m ├── XADStuffItXBlockHandle.h ├── XADStuffItXBlockHandle.m ├── XADStuffItXCyanideHandle.h ├── XADStuffItXCyanideHandle.m ├── XADStuffItXDarkhorseHandle.h ├── XADStuffItXDarkhorseHandle.m ├── XADStuffItXEnglishHandle.h ├── XADStuffItXEnglishHandle.m ├── XADStuffItXIronHandle.h ├── XADStuffItXIronHandle.m ├── XADStuffItXParser.h ├── XADStuffItXParser.m ├── XADStuffItXX86Handle.h ├── XADStuffItXX86Handle.m ├── XADTarParser.h ├── XADTarParser.m ├── XADTarSparseHandle.h ├── XADTarSparseHandle.m ├── XADTest.m ├── XADTest2.m ├── XADTest3.m ├── XADTest4.m ├── XADTest5.m ├── XADTest6.m ├── XADUnarchiver.h ├── XADUnarchiver.m ├── XADUnarchiverOldMacOSX.m ├── XADWARCParser.h ├── XADWARCParser.m ├── XADWinZipAESHandle.h ├── XADWinZipAESHandle.m ├── XADWinZipJPEGHandle.h ├── XADWinZipJPEGHandle.m ├── XADWinZipWavPackHandle.h ├── XADWinZipWavPackHandle.m ├── XADXARParser.h ├── XADXARParser.m ├── XADXORHandle.h ├── XADXORHandle.m ├── XADXORSumHandle.h ├── XADXORSumHandle.m ├── XADXZHandle.h ├── XADXZHandle.m ├── XADXZParser.h ├── XADXZParser.m ├── XADZipCryptHandle.h ├── XADZipCryptHandle.m ├── XADZipImplodeHandle.h ├── XADZipImplodeHandle.m ├── XADZipParser.h ├── XADZipParser.m ├── XADZipSFXParsers.h ├── XADZipSFXParsers.m ├── XADZipShrinkHandle.h ├── XADZipShrinkHandle.m ├── XADZooParser.h ├── XADZooParser.m ├── libxad ├── all.c ├── clientfunc.c ├── clients.c ├── clients │ ├── AMPK.c │ ├── Ace.c │ ├── CrunchDisk.c │ ├── DCS.c │ ├── DMS.c │ ├── FS_Amiga.c │ ├── FS_FAT.c │ ├── FS_SOS.c │ ├── IFF-CDAF.c │ ├── LhA.c │ ├── LhF.c │ ├── MDC.c │ ├── MXM-SimpleArc.c │ ├── PackDev.c │ ├── PackDisk.c │ ├── SuperDuper3.c │ ├── Tar.c │ ├── Zoom.c │ ├── xDisk.c │ ├── xMash.c │ ├── xadCRC_1021.c │ ├── xadIO.c │ ├── xadIO.h │ ├── xadIO_Compress.c │ └── xadIO_XPK.c ├── config.h ├── copymem.c ├── crc.c ├── dates.c ├── debug.c ├── diskfile.c ├── diskunarc.c ├── error.c ├── filename.c ├── fileunarc.c ├── gpl.txt ├── hook.c ├── hook_diskarc.c ├── hook_mem.c ├── hook_splitted.c ├── hook_stream.c ├── include │ ├── ConvertE.c │ ├── SDI_compiler.h │ ├── functions.h │ ├── privdefs.h │ ├── version.h │ └── xadmaster.h ├── info.c ├── lgpl.txt ├── objects.c ├── protection.c └── unix │ ├── emulation.c │ ├── emulation.h │ ├── hook_fh.c │ ├── init.c │ └── xadClient.h ├── lsar.m ├── lzma ├── Bra.c ├── Bra.h ├── Bra86.c ├── BraIA64.c ├── Lzma2Dec.c ├── Lzma2Dec.h ├── LzmaDec.c ├── LzmaDec.h └── Types.h ├── unar.m └── wavpack ├── bits.c ├── float.c ├── metadata.c ├── unpack.c ├── wavpack.h ├── wavpack_local.h ├── wavpack_version.h ├── words.c └── wputils.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | Build/ 3 | UniversalDetector/DetectorTest 4 | XADTest? 5 | XADMaster/lsar 6 | XADMaster/unar 7 | -------------------------------------------------------------------------------- /Extra/lsar.bash_completion: -------------------------------------------------------------------------------- 1 | __lsar() 2 | { 3 | local cur prev opts 4 | COMPREPLY=() 5 | cur="${COMP_WORDS[COMP_CWORD]}" 6 | opts="--long --verylong --test --password ---encoding --password-encoding \ 7 | --print-encoding --indexes --json --json-ascii --no-recursion --help \ 8 | --version" 9 | if [[ ${cur} == -* ]] ; then 10 | COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) 11 | return 0 12 | fi 13 | } 14 | 15 | complete -o bashdefault -A file -F __lsar lsar 16 | 17 | -------------------------------------------------------------------------------- /Extra/unar.bash_completion: -------------------------------------------------------------------------------- 1 | __unar() 2 | { 3 | local cur prev opts 4 | COMPREPLY=() 5 | cur="${COMP_WORDS[COMP_CWORD]}" 6 | prev="${COMP_WORDS[COMP_CWORD-1]}" 7 | opts="--output-directory --force-overwrite --force-rename --force-skip \ 8 | --force-directory --no-directory --password --encoding \ 9 | --password-encoding --indexes --no-recursion --copy-time \ 10 | --no-quarantine --forks --quiet --help --version" 11 | if [[ ${prev} == "--forks" ]] ; then 12 | local forksopts 13 | forksopts="fork visible hidden skip" 14 | COMPREPLY=( $(compgen -W "${forksopts}" -- ${cur}) ) 15 | return 0 16 | elif [[ ${cur} == -* ]] ; then 17 | COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) 18 | return 0 19 | fi 20 | } 21 | 22 | complete -o bashdefault -A file -F __unar unar 23 | 24 | -------------------------------------------------------------------------------- /UniversalDetector/DetectorTest.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "UniversalDetector.h" 3 | 4 | int main(int argc,char **argv) 5 | { 6 | NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init]; 7 | 8 | UniversalDetector *detector=[UniversalDetector detector]; 9 | 10 | for(int i=1;i 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | FMWK 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.1 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /UniversalDetector/Makefile.common: -------------------------------------------------------------------------------- 1 | # Source files 2 | 3 | LIBRARY_OBJC_FILES = UniversalDetector.m 4 | 5 | LIBRARY_C_FILES = universalchardet/kludge.c 6 | 7 | LIBRARY_CXX_FILES = WrappedUniversalDetector.cpp \ 8 | universalchardet/CharDistribution.cpp \ 9 | universalchardet/JpCntx.cpp \ 10 | universalchardet/LangBulgarianModel.cpp \ 11 | universalchardet/LangCyrillicModel.cpp \ 12 | universalchardet/LangGreekModel.cpp \ 13 | universalchardet/LangHebrewModel.cpp \ 14 | universalchardet/LangHungarianModel.cpp \ 15 | universalchardet/LangThaiModel.cpp \ 16 | universalchardet/nsBig5Prober.cpp \ 17 | universalchardet/nsCharSetProber.cpp \ 18 | universalchardet/nsEscCharsetProber.cpp \ 19 | universalchardet/nsEscSM.cpp \ 20 | universalchardet/nsEUCJPProber.cpp \ 21 | universalchardet/nsEUCKRProber.cpp \ 22 | universalchardet/nsEUCTWProber.cpp \ 23 | universalchardet/nsGB2312Prober.cpp \ 24 | universalchardet/nsHebrewProber.cpp \ 25 | universalchardet/nsLatin1Prober.cpp \ 26 | universalchardet/nsMBCSGroupProber.cpp \ 27 | universalchardet/nsMBCSSM.cpp \ 28 | universalchardet/nsSBCharSetProber.cpp \ 29 | universalchardet/nsSBCSGroupProber.cpp \ 30 | universalchardet/nsSJISProber.cpp \ 31 | universalchardet/nsUniversalDetector.cpp \ 32 | universalchardet/nsUTF8Prober.cpp 33 | 34 | DETECTORTEST_OBJC_FILES = DetectorTest.m 35 | 36 | # Object files 37 | 38 | LIBRARY_OBJS = $(LIBRARY_OBJC_FILES:%.m=$(BUILD_DIR)/%.o) \ 39 | $(LIBRARY_C_FILES:%.c=$(BUILD_DIR)/%.o) \ 40 | $(LIBRARY_CXX_FILES:%.cpp=$(BUILD_DIR)/%.o) 41 | 42 | DETECTORTEST_OBJS = $(DETECTORTEST_OBJC_FILES:%.m=$(BUILD_DIR)/%.o) 43 | 44 | OBJS = $(LIBRARY_OBJS) \ 45 | $(DETECTORTEST_OBJS) 46 | 47 | # Other files 48 | 49 | EXECUTABLE_FILES = DetectorTest 50 | 51 | LIBRARY_FILES = libUniversalDetector.a 52 | -------------------------------------------------------------------------------- /UniversalDetector/UniversalDetector.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface UniversalDetector:NSObject 4 | { 5 | void *detector; 6 | NSString *charset; 7 | float confidence; 8 | const char *lastcstring; 9 | } 10 | 11 | +(UniversalDetector *)detector; 12 | +(NSArray *)possibleMIMECharsets; 13 | 14 | -(id)init; 15 | -(void)dealloc; 16 | 17 | -(void)analyzeData:(NSData *)data; 18 | -(void)analyzeBytes:(const char *)data length:(int)len; 19 | -(void)reset; 20 | 21 | -(BOOL)done; 22 | -(NSString *)MIMECharset; 23 | -(float)confidence; 24 | 25 | #ifdef __APPLE__ 26 | -(NSStringEncoding)encoding; 27 | #endif 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /UniversalDetector/UniversalDetector_Prefix.pch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/UniversalDetector/UniversalDetector_Prefix.pch -------------------------------------------------------------------------------- /UniversalDetector/WrappedUniversalDetector.h: -------------------------------------------------------------------------------- 1 | #ifndef __WrappedUniversalDetector_h__ 2 | #define __WrappedUniversalDetector_h__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | void *AllocUniversalDetector(); 9 | void FreeUniversalDetector(void *detectorptr); 10 | void UniversalDetectorHandleData(void *detectorptr,const char *data,int length); 11 | void UniversalDetectorReset(void *detectorptr); 12 | int UniversalDetectorDone(void *detectorptr); 13 | const char *UniversalDetectorCharset(void *detectorptr,float *confidence); 14 | 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /UniversalDetector/scan.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use strict; 4 | 5 | my %charsets; 6 | 7 | for(@ARGV) 8 | { 9 | open FILE,$_ or die; 10 | $_=do {local $/; }; 11 | 12 | # $charsets{$1}=1 while(/SequenceModel.*?=.*?\{[^}"]+"([^"]*)"[^}]+\}/gs); 13 | $charsets{$1}=1 while(/"([A-Za-z0-9_\-]+)"/g); 14 | } 15 | 16 | print join "\n",sort keys %charsets; 17 | print "\n"; -------------------------------------------------------------------------------- /UniversalDetector/universalchardet/.cvsignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | -------------------------------------------------------------------------------- /UniversalDetector/universalchardet/kludge.c: -------------------------------------------------------------------------------- 1 | #include "prmem.h" // nose core nose core nose core nose core 2 | 3 | PR_IMPLEMENT(void *) PR_Malloc(PRUint32 size) 4 | { 5 | return malloc(size); 6 | } 7 | 8 | PR_IMPLEMENT(void *) PR_Calloc(PRUint32 nelem, PRUint32 elsize) 9 | { 10 | return calloc(nelem, elsize); 11 | } 12 | 13 | PR_IMPLEMENT(void *) PR_Realloc(void *ptr, PRUint32 size) 14 | { 15 | return realloc(ptr, size); 16 | } 17 | 18 | PR_IMPLEMENT(void) PR_Free(void *ptr) 19 | { 20 | free(ptr); 21 | } 22 | -------------------------------------------------------------------------------- /UniversalDetector/universalchardet/nscore.h: -------------------------------------------------------------------------------- 1 | #include "prtypes.h" 2 | 3 | typedef PRUint32 nsresult; 4 | 5 | #define nsnull 0 6 | #define NS_COM 7 | 8 | #include "nsError.h" 9 | -------------------------------------------------------------------------------- /XADMaster/BWT.h: -------------------------------------------------------------------------------- 1 | #ifndef __BWT_H__ 2 | #define __BWT_H__ 3 | 4 | #include 5 | 6 | void CalculateInverseBWT(uint32_t *transform,uint8_t *block,int blocklen); 7 | void UnsortBWT(uint8_t *dest,uint8_t *src,int blocklen,int firstindex,uint32_t *transformbuf); 8 | 9 | void UnsortST4(uint8_t *dest,uint8_t *src,int blocklen,int firstindex,uint32_t *transformbuf); 10 | 11 | typedef struct MTFState 12 | { 13 | int table[256]; 14 | } MTFState; 15 | 16 | void ResetMTFDecoder(MTFState *self); 17 | int DecodeMTF(MTFState *self,int symbol); 18 | void DecodeMTFBlock(uint8_t *block,int blocklen); 19 | void DecodeM1FFNBlock(uint8_t *block,int blocklen,int order); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /XADMaster/CRC.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | uint32_t XADCRC(uint32_t prevcrc,uint8_t byte,const uint32_t *table); 4 | uint32_t XADCalculateCRC(uint32_t prevcrc,const uint8_t *buffer,int length,const uint32_t *table); 5 | 6 | uint64_t XADCRC64(uint64_t prevcrc,uint8_t byte,const uint64_t *table); 7 | uint64_t XADCalculateCRC64(uint64_t prevcrc,const uint8_t *buffer,int length,const uint64_t *table); 8 | 9 | int XADUnReverseCRC16(int val); 10 | 11 | extern const uint32_t XADCRCTable_a001[256]; 12 | extern const uint32_t XADCRCReverseTable_1021[256]; 13 | extern const uint32_t XADCRCTable_edb88320[256]; 14 | extern const uint64_t XADCRCTable_c96c5795d7870f42[256]; 15 | -------------------------------------------------------------------------------- /XADMaster/CSBlockStreamHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSStreamHandle.h" 2 | 3 | #define CSBlockStreamHandle XADBlockStreamHandle 4 | 5 | @interface CSBlockStreamHandle:CSStreamHandle 6 | { 7 | uint8_t *_currblock; 8 | off_t _blockstartpos; 9 | int _blocklength; 10 | BOOL _endofblocks; 11 | } 12 | 13 | // Intializers 14 | //-(id)initWithName:(NSString *)descname length:(off_t)length; 15 | -(id)initWithInputBufferForHandle:(CSHandle *)handle length:(off_t)length bufferSize:(int)buffersize; 16 | -(id)initAsCopyOf:(CSBlockStreamHandle *)other; 17 | 18 | // Implemented by this class 19 | -(void)seekToFileOffset:(off_t)offs; 20 | -(void)resetStream; 21 | -(int)streamAtMost:(int)num toBuffer:(void *)buffer; 22 | 23 | // Internal methods 24 | -(void)_readNextBlock; 25 | 26 | // Implemented by subclasses 27 | -(void)resetBlockStream; 28 | -(int)produceBlockAtOffset:(off_t)pos; 29 | 30 | // Called by subclasses 31 | -(void)setBlockPointer:(uint8_t *)blockpointer; 32 | -(void)endBlockStream; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /XADMaster/CSByteStreamHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSStreamHandle.h" 2 | 3 | #import 4 | 5 | #define CSByteStreamHandle XADByteStreamHandle 6 | 7 | @interface CSByteStreamHandle:CSStreamHandle 8 | { 9 | uint8_t (*bytestreamproducebyte_ptr)(id,SEL,off_t); 10 | int bytesproduced; 11 | @public 12 | jmp_buf eofenv; 13 | } 14 | 15 | // Intializers 16 | //-(id)initWithName:(NSString *)descname length:(off_t)length; 17 | -(id)initWithInputBufferForHandle:(CSHandle *)handle length:(off_t)length bufferSize:(int)buffersize; 18 | -(id)initAsCopyOf:(CSByteStreamHandle *)other; 19 | 20 | // Implemented by this class 21 | -(int)streamAtMost:(int)num toBuffer:(void *)buffer; 22 | -(void)resetStream; 23 | 24 | // Implemented by subclasses 25 | -(void)resetByteStream; 26 | -(uint8_t)produceByteAtOffset:(off_t)pos; 27 | 28 | // Called by subclasses 29 | -(void)endByteStream; 30 | 31 | @end 32 | 33 | 34 | 35 | extern NSString *CSByteStreamEOFReachedException; 36 | 37 | static inline void CSByteStreamEOF(CSByteStreamHandle *self) __attribute__((noreturn)); 38 | static inline void CSByteStreamEOF(CSByteStreamHandle *self) { longjmp(self->eofenv,1); } 39 | -------------------------------------------------------------------------------- /XADMaster/CSByteStreamHandle.m: -------------------------------------------------------------------------------- 1 | #import "CSByteStreamHandle.h" 2 | 3 | NSString *CSByteStreamEOFReachedException=@"CSByteStreamEOFReachedException"; 4 | 5 | @implementation CSByteStreamHandle 6 | 7 | /*-(id)initWithName:(NSString *)descname length:(off_t)length 8 | { 9 | if(self=[super initWithName:descname length:length]) 10 | { 11 | bytestreamproducebyte_ptr=(uint8_t (*)(id,SEL,off_t))[self methodForSelector:@selector(produceByteAtOffset:)]; 12 | } 13 | return self; 14 | }*/ 15 | 16 | -(id)initWithInputBufferForHandle:(CSHandle *)handle length:(off_t)length bufferSize:(int)buffersize; 17 | { 18 | if(self=[super initWithInputBufferForHandle:handle length:length bufferSize:buffersize]) 19 | { 20 | bytestreamproducebyte_ptr=(uint8_t (*)(id,SEL,off_t))[self methodForSelector:@selector(produceByteAtOffset:)]; 21 | } 22 | return self; 23 | } 24 | 25 | -(id)initAsCopyOf:(CSByteStreamHandle *)other 26 | { 27 | [self _raiseNotSupported:_cmd]; 28 | return nil; 29 | } 30 | 31 | 32 | 33 | -(int)streamAtMost:(int)num toBuffer:(void *)buffer 34 | { 35 | bytesproduced=0; 36 | 37 | if(setjmp(eofenv)==0) 38 | { 39 | while(bytesproduced 4 | 5 | #define CSBzip2Handle XADBzip2Handle 6 | 7 | extern NSString *CSBzip2Exception; 8 | 9 | @interface CSBzip2Handle:CSStreamHandle 10 | { 11 | off_t startoffs; 12 | bz_stream bzs; 13 | BOOL inited,checksumcorrect; 14 | 15 | uint8_t inbuffer[16*1024]; 16 | } 17 | 18 | +(CSBzip2Handle *)bzip2HandleWithHandle:(CSHandle *)handle; 19 | +(CSBzip2Handle *)bzip2HandleWithHandle:(CSHandle *)handle length:(off_t)length; 20 | 21 | // Initializers. 22 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 23 | -(void)dealloc; 24 | 25 | // Implemented by this class. 26 | -(void)resetStream; 27 | -(int)streamAtMost:(int)num toBuffer:(void *)buffer; 28 | 29 | // Checksum functions for XADMaster. 30 | -(BOOL)hasChecksum; 31 | -(BOOL)isChecksumCorrect; 32 | 33 | // Internal methods. 34 | -(void)_raiseBzip2:(int)error; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /XADMaster/CSFileHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSHandle.h" 2 | 3 | #import 4 | 5 | #define CSFileHandle XADFileHandle 6 | 7 | extern NSString *CSCannotOpenFileException; 8 | extern NSString *CSFileErrorException; 9 | 10 | @interface CSFileHandle:CSHandle 11 | { 12 | FILE *fh; 13 | NSString *path; 14 | BOOL close; 15 | 16 | NSLock *multilock; 17 | CSFileHandle *fhowner; 18 | off_t pos; 19 | } 20 | 21 | +(CSFileHandle *)fileHandleForReadingAtPath:(NSString *)path; 22 | +(CSFileHandle *)fileHandleForWritingAtPath:(NSString *)path; 23 | +(CSFileHandle *)fileHandleForPath:(NSString *)path modes:(NSString *)modes; 24 | +(CSFileHandle *)fileHandleForStandardInput; 25 | +(CSFileHandle *)fileHandleForStandardOutput; 26 | +(CSFileHandle *)fileHandleForStandardError; 27 | 28 | // Initializers 29 | -(id)initWithFilePointer:(FILE *)file closeOnDealloc:(BOOL)closeondealloc path:(NSString *)filepath; 30 | -(id)initAsCopyOf:(CSFileHandle *)other; 31 | -(void)dealloc; 32 | -(void)close; 33 | 34 | // Public methods 35 | -(FILE *)filePointer; 36 | 37 | // Implemented by this class 38 | -(off_t)fileSize; 39 | -(off_t)offsetInFile; 40 | -(BOOL)atEndOfFile; 41 | 42 | -(void)seekToFileOffset:(off_t)offs; 43 | -(void)seekToEndOfFile; 44 | -(void)pushBackByte:(int)byte; 45 | -(int)readAtMost:(int)num toBuffer:(void *)buffer; 46 | -(void)writeBytes:(int)num fromBuffer:(const void *)buffer; 47 | 48 | -(NSString *)name; 49 | 50 | // Internal methods 51 | -(void)_raiseError; 52 | -(void)_setMultiMode; 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /XADMaster/CSHexDump.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | static NSString *HexDump(const uint8_t *bytes,size_t len,int cols,int indent); 4 | 5 | @implementation NSData (CSHexDump) 6 | 7 | -(NSString *)description 8 | { 9 | return [NSString stringWithFormat:@"<\n%@\n>",HexDump([self bytes],[self length],16,0)]; 10 | } 11 | 12 | @end 13 | 14 | @implementation NSValue (CSHexDump) 15 | 16 | /*-(NSString *)description 17 | { 18 | NSUInteger size; 19 | NSGetSizeAndAlignment([self objCType],&size,NULL); 20 | if(size>0x40000) return [NSString stringWithFormat:@"",[self class]]; 21 | 22 | uint8_t buf[size]; 23 | [self getValue:buf]; 24 | 25 | return [NSString stringWithFormat:@"",HexDump(buf,size,16)]; 26 | }*/ 27 | 28 | @end 29 | 30 | static NSString *HexDump(const uint8_t *bytes,size_t len,int cols,int indent) 31 | { 32 | NSMutableString *str=[NSMutableString string]; 33 | int lines=(len+cols-1)/cols; 34 | 35 | for(int i=0;i=len) [str appendString:@" "]; 45 | else [str appendFormat:@"%02x",bytes[i*cols+j]]; 46 | if(j%4==3&&j!=cols-1) [str appendString:@" "]; 47 | } 48 | [str appendString:@" "]; 49 | 50 | for(int j=0;j=len) [str appendString:@" "]; 54 | else 55 | { 56 | int c=bytes[i*cols+j]; 57 | if(c<0x20||(c>=0x80&&c<0xa0)) c='.'; 58 | [str appendFormat:@"%C",(unichar)c]; 59 | } 60 | } 61 | 62 | if(i!=lines-1) [str appendString:@"\n"]; 63 | } 64 | return str; 65 | } 66 | -------------------------------------------------------------------------------- /XADMaster/CSJSONPrinter.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | 4 | @interface CSJSONPrinter:NSObject 5 | { 6 | int indentlevel; 7 | NSString *indentstring; 8 | BOOL asciimode; 9 | 10 | BOOL needseparator; 11 | } 12 | 13 | -(id)init; 14 | -(void)dealloc; 15 | 16 | -(void)setIndentString:(NSString *)string; 17 | -(void)setASCIIMode:(BOOL)ascii; 18 | 19 | -(void)printObject:(id)object; 20 | 21 | -(void)printNull; 22 | -(void)printNumber:(NSNumber *)number; 23 | -(void)printString:(NSString *)string; 24 | -(void)printData:(NSData *)data; 25 | -(void)printValue:(NSValue *)value; 26 | -(void)printArray:(NSArray *)array; 27 | -(void)printDictionary:(NSDictionary *)dictionary; 28 | 29 | -(void)startPrintingArray; 30 | -(void)startPrintingArrayObject; 31 | -(void)printArrayObject:(id)object; 32 | -(void)endPrintingArray; 33 | -(void)printArrayObjects:(NSArray *)array; 34 | 35 | -(void)startPrintingDictionary; 36 | -(void)startPrintingDictionaryObjectForKey:(id)key; 37 | -(void)printDictionaryObject:(id)object forKey:(id)key; 38 | -(void)endPrintingDictionary; 39 | -(void)printDictionaryKeysAndObjects:(NSDictionary *)dictionary; 40 | 41 | -(void)startNewLine; 42 | -(void)printSeparatorIfNeeded; 43 | 44 | -(NSString *)stringByEscapingString:(NSString *)string; 45 | -(NSString *)stringByEncodingBytes:(const uint8_t *)bytes length:(int)length; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /XADMaster/CSMemoryHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSHandle.h" 2 | 3 | #define CSMemoryHandle XADMemoryHandle 4 | 5 | @interface CSMemoryHandle:CSHandle 6 | { 7 | NSData *backingdata; 8 | off_t memorypos; 9 | } 10 | 11 | +(CSMemoryHandle *)memoryHandleForReadingData:(NSData *)data; 12 | +(CSMemoryHandle *)memoryHandleForReadingBuffer:(const void *)buf length:(unsigned)len; 13 | +(CSMemoryHandle *)memoryHandleForReadingMappedFile:(NSString *)filename; 14 | +(CSMemoryHandle *)memoryHandleForWriting; 15 | 16 | // Initializers 17 | -(id)initWithData:(NSData *)dataobj; 18 | -(id)initAsCopyOf:(CSMemoryHandle *)other; 19 | -(void)dealloc; 20 | 21 | // Public methods 22 | -(NSData *)data; 23 | -(NSMutableData *)mutableData; 24 | 25 | // Implemented by this class 26 | -(off_t)fileSize; 27 | -(off_t)offsetInFile; 28 | -(BOOL)atEndOfFile; 29 | 30 | -(void)seekToFileOffset:(off_t)offs; 31 | -(void)seekToEndOfFile; 32 | //-(void)pushBackByte:(int)byte; 33 | -(int)readAtMost:(int)num toBuffer:(void *)buffer; 34 | -(void)writeBytes:(int)num fromBuffer:(const void *)buffer; 35 | 36 | -(NSData *)fileContents; 37 | -(NSData *)remainingFileContents; 38 | -(NSData *)readDataOfLength:(int)length; 39 | -(NSData *)readDataOfLengthAtMost:(int)length; 40 | -(NSData *)copyDataOfLength:(int)length; 41 | -(NSData *)copyDataOfLengthAtMost:(int)length; 42 | 43 | -(NSString *)name; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /XADMaster/CSMultiFileHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSSegmentedHandle.h" 2 | 3 | #define CSMultiFileHandle XADMultiFileHandle 4 | 5 | @interface CSMultiFileHandle:CSSegmentedHandle 6 | { 7 | NSArray *paths; 8 | } 9 | 10 | +(CSHandle *)handleWithPathArray:(NSArray *)patharray; 11 | +(CSHandle *)handleWithPaths:(CSHandle *)firstpath,...; 12 | 13 | // Initializers 14 | -(id)initWithPaths:(NSArray *)patharray; 15 | -(id)initAsCopyOf:(CSMultiFileHandle *)other; 16 | -(void)dealloc; 17 | 18 | // Public methods 19 | -(NSArray *)paths; 20 | 21 | // Implemented by this class 22 | -(NSInteger)numberOfSegments; 23 | -(off_t)segmentSizeAtIndex:(NSInteger)index; 24 | -(CSHandle *)handleAtIndex:(NSInteger)index; 25 | 26 | // Internal methods 27 | -(void)_raiseError; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /XADMaster/CSMultiHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSSegmentedHandle.h" 2 | 3 | #define CSMultiHandle XADMultiHandle 4 | 5 | @interface CSMultiHandle:CSSegmentedHandle 6 | { 7 | NSArray *handles; 8 | } 9 | 10 | +(CSHandle *)handleWithHandleArray:(NSArray *)handlearray; 11 | +(CSHandle *)handleWithHandles:(CSHandle *)firsthandle,...; 12 | 13 | // Initializers 14 | -(id)initWithHandles:(NSArray *)handlearray; 15 | -(id)initAsCopyOf:(CSMultiHandle *)other; 16 | -(void)dealloc; 17 | 18 | // Public methods 19 | -(NSArray *)handles; 20 | 21 | // Implemented by this class 22 | -(NSInteger)numberOfSegments; 23 | -(off_t)segmentSizeAtIndex:(NSInteger)index; 24 | -(CSHandle *)handleAtIndex:(NSInteger)index; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /XADMaster/CSSegmentedHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSHandle.h" 2 | 3 | #define CSSegmentedHandle XADSegmentedHandle 4 | 5 | extern NSString *CSNoSegmentsException; 6 | extern NSString *CSSizeOfSegmentUnknownException; 7 | 8 | @interface CSSegmentedHandle:CSHandle 9 | { 10 | NSInteger count; 11 | NSInteger currindex; 12 | CSHandle *currhandle; 13 | off_t *segmentends; 14 | NSArray *segmentsizes; 15 | } 16 | 17 | // Initializers 18 | -(id)init; 19 | -(id)initAsCopyOf:(CSSegmentedHandle *)other; 20 | -(void)dealloc; 21 | 22 | // Public methods 23 | -(CSHandle *)currentHandle; 24 | -(NSArray *)segmentSizes; 25 | 26 | // Implemented by this class 27 | -(off_t)fileSize; 28 | -(off_t)offsetInFile; 29 | -(BOOL)atEndOfFile; 30 | 31 | -(void)seekToFileOffset:(off_t)offs; 32 | -(void)seekToEndOfFile; 33 | -(int)readAtMost:(int)num toBuffer:(void *)buffer; 34 | 35 | -(NSString *)name; 36 | -(NSString *)description; 37 | 38 | // Implemented by subclasses 39 | -(NSInteger)numberOfSegments; 40 | -(off_t)segmentSizeAtIndex:(NSInteger)index; 41 | -(CSHandle *)handleAtIndex:(NSInteger)index; 42 | 43 | // Internal methods 44 | -(void)_open; 45 | -(void)_setCurrentIndex:(NSInteger)newindex; 46 | -(void)_raiseNoSegments; 47 | -(void)_raiseSizeUnknownForSegment:(NSInteger)i; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /XADMaster/CSStreamHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSHandle.h" 2 | #import "CSInputBuffer.h" 3 | 4 | #define CSStreamHandle XADStreamHandle 5 | 6 | @interface CSStreamHandle:CSHandle 7 | { 8 | off_t streampos,streamlength; 9 | BOOL needsreset,endofstream; 10 | int nextstreambyte; 11 | 12 | @public 13 | CSInputBuffer *input; 14 | } 15 | 16 | // Initializers 17 | //-(id)initWithName:(NSString *)descname; 18 | //-(id)initWithName:(NSString *)descname length:(off_t)length; 19 | -(id)initWithParentHandle:(CSHandle *)handle; 20 | -(id)initWithParentHandle:(CSHandle *)handle length:(off_t)length; 21 | -(id)initWithInputBufferForHandle:(CSHandle *)handle; 22 | -(id)initWithInputBufferForHandle:(CSHandle *)handle length:(off_t)length; 23 | -(id)initWithInputBufferForHandle:(CSHandle *)handle bufferSize:(int)buffersize; 24 | -(id)initWithInputBufferForHandle:(CSHandle *)handle length:(off_t)length bufferSize:(int)buffersize; 25 | -(id)initAsCopyOf:(CSStreamHandle *)other; 26 | -(void)dealloc; 27 | 28 | // Implemented by this class 29 | -(off_t)fileSize; 30 | -(off_t)offsetInFile; 31 | -(BOOL)atEndOfFile; 32 | -(void)seekToFileOffset:(off_t)offs; 33 | -(void)seekToEndOfFile; 34 | -(int)readAtMost:(int)num toBuffer:(void *)buffer; 35 | 36 | // Implemented by subclasses 37 | -(void)resetStream; 38 | -(int)streamAtMost:(int)num toBuffer:(void *)buffer; 39 | 40 | // Called by subclasses 41 | -(void)endStream; 42 | -(BOOL)_prepareStreamSeekTo:(off_t)offs; 43 | -(void)setStreamLength:(off_t)length; 44 | -(void)setInputBuffer:(CSInputBuffer *)inputbuffer; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /XADMaster/CSSubHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSHandle.h" 2 | 3 | #define CSSubHandle XADSubHandle 4 | 5 | @interface CSSubHandle:CSHandle 6 | { 7 | off_t start,end; 8 | } 9 | 10 | // Initializers 11 | -(id)initWithHandle:(CSHandle *)handle from:(off_t)from length:(off_t)length; 12 | -(id)initAsCopyOf:(CSSubHandle *)other; 13 | -(void)dealloc; 14 | 15 | // Public methods 16 | -(off_t)startOffsetInParent; 17 | 18 | // Implemented by this class 19 | -(off_t)fileSize; 20 | -(off_t)offsetInFile; 21 | -(BOOL)atEndOfFile; 22 | 23 | -(void)seekToFileOffset:(off_t)offs; 24 | -(void)seekToEndOfFile; 25 | -(int)readAtMost:(int)num toBuffer:(void *)buffer; 26 | 27 | -(NSString *)description; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /XADMaster/CSZlibHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSStreamHandle.h" 2 | 3 | #ifndef __MACTYPES__ 4 | #define Byte zlibByte 5 | #include 6 | #undef Byte 7 | #else 8 | #include 9 | #endif 10 | 11 | #define CSZlibHandle XADZlibHandle 12 | 13 | extern NSString *CSZlibException; 14 | 15 | @interface CSZlibHandle:CSStreamHandle 16 | { 17 | off_t startoffs; 18 | z_stream zs; 19 | BOOL inited,seekback,endstreamateof; 20 | 21 | uint8_t inbuffer[0x4000]; 22 | } 23 | 24 | +(CSZlibHandle *)zlibHandleWithHandle:(CSHandle *)handle; 25 | +(CSZlibHandle *)zlibHandleWithHandle:(CSHandle *)handle length:(off_t)length; 26 | +(CSZlibHandle *)deflateHandleWithHandle:(CSHandle *)handle; 27 | +(CSZlibHandle *)deflateHandleWithHandle:(CSHandle *)handle length:(off_t)length; 28 | 29 | // Intializers 30 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length header:(BOOL)header ; 31 | -(id)initAsCopyOf:(CSZlibHandle *)other; 32 | -(void)dealloc; 33 | 34 | // Public methods 35 | -(void)setSeekBackAtEOF:(BOOL)seekateof; 36 | -(void)setEndStreamAtInputEOF:(BOOL)endateof; 37 | 38 | // Implemented by this class 39 | -(void)resetStream; 40 | -(int)streamAtMost:(int)num toBuffer:(void *)buffer; 41 | 42 | // Internal methods 43 | -(void)_raiseZlib; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /XADMaster/CarrylessRangeCoder.h: -------------------------------------------------------------------------------- 1 | #import "CSInputBuffer.h" 2 | 3 | typedef struct CarrylessRangeCoder 4 | { 5 | CSInputBuffer *input; 6 | uint32_t low,code,range,bottom; 7 | BOOL uselow; 8 | } CarrylessRangeCoder; 9 | 10 | void InitializeRangeCoder(CarrylessRangeCoder *self,CSInputBuffer *input,BOOL uselow,int bottom); 11 | 12 | uint32_t RangeCoderCurrentCount(CarrylessRangeCoder *self,uint32_t scale); 13 | void RemoveRangeCoderSubRange(CarrylessRangeCoder *self,uint32_t lowcount,uint32_t highcount); 14 | 15 | int NextSymbolFromRangeCoder(CarrylessRangeCoder *self,uint32_t *freqtable,int numfreq); 16 | int NextBitFromRangeCoder(CarrylessRangeCoder *self); 17 | int NextWeightedBitFromRangeCoder(CarrylessRangeCoder *self,int weight,int size); 18 | 19 | int NextWeightedBitFromRangeCoder2(CarrylessRangeCoder *self,int weight,int shift); 20 | 21 | void NormalizeRangeCoder(CarrylessRangeCoder *self); 22 | -------------------------------------------------------------------------------- /XADMaster/Checksums.h: -------------------------------------------------------------------------------- 1 | #import "CSHandle.h" 2 | #import "CSSubHandle.h" 3 | #import "CSStreamHandle.h" 4 | 5 | @interface CSHandle (Checksums) 6 | 7 | -(BOOL)hasChecksum; 8 | -(BOOL)isChecksumCorrect; 9 | 10 | @end 11 | 12 | @interface CSSubHandle (Checksums) 13 | 14 | -(BOOL)hasChecksum; 15 | -(BOOL)isChecksumCorrect; 16 | 17 | @end 18 | 19 | @interface CSStreamHandle (Checksums) 20 | 21 | -(BOOL)hasChecksum; 22 | -(BOOL)isChecksumCorrect; 23 | 24 | @end 25 | 26 | #define CSChecksumWrapperHandle XADChecksumWrapperHandle 27 | 28 | @interface CSChecksumWrapperHandle:CSHandle 29 | { 30 | CSHandle *checksum; 31 | } 32 | 33 | -(id)initWithHandle:(CSHandle *)handle checksumHandle:(CSHandle *)checksumhandle; 34 | -(void)dealloc; 35 | 36 | -(off_t)fileSize; 37 | -(off_t)offsetInFile; 38 | -(BOOL)atEndOfFile; 39 | -(void)seekToFileOffset:(off_t)offs; 40 | -(void)seekToEndOfFile; 41 | -(void)pushBackByte:(int)byte; 42 | -(int)readAtMost:(int)num toBuffer:(void *)buffer; 43 | -(void)writeBytes:(int)num fromBuffer:(const void *)buffer; 44 | 45 | -(BOOL)hasChecksum; 46 | -(BOOL)isChecksumCorrect; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /XADMaster/ClangAnalyser.h: -------------------------------------------------------------------------------- 1 | #ifndef __CLANG_ANALYSER_H__ 2 | #define __CLANG_ANALYSER_H__ 3 | 4 | #ifdef __clang_analyzer__ 5 | 6 | #include 7 | 8 | #define analyser_assert(x) assert(x) 9 | 10 | #if __has_feature(attribute_analyzer_noreturn) 11 | #define CLANG_ANALYZER_NORETURN __attribute__((analyzer_noreturn)) 12 | #else 13 | #define CLANG_ANALYZER_NORETURN 14 | #endif 15 | 16 | #else 17 | 18 | #define analyser_assert(x) 19 | #define CLANG_ANALYZER_NORETURN 20 | 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /XADMaster/CommandLineCommon.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "XADArchiveParser.h" 4 | 5 | BOOL IsListRequest(NSString *encoding); 6 | void PrintEncodingList(); 7 | 8 | NSString *ShortInfoLineForEntryWithDictionary(NSDictionary *dict); 9 | NSString *MediumInfoLineForEntryWithDictionary(NSDictionary *dict); 10 | NSString *LongInfoLineForEntryWithDictionary(NSDictionary *dict,XADArchiveParser *parser); 11 | NSString *CompressionNameExplanationForLongInfo(); 12 | 13 | BOOL IsInteractive(); 14 | int GetPromptCharacter(); 15 | NSString *AskForPassword(NSString *prompt); 16 | -------------------------------------------------------------------------------- /XADMaster/Crypto/des.h: -------------------------------------------------------------------------------- 1 | #ifndef __DES_H__ 2 | #define __DES_H__ 3 | 4 | #include 5 | 6 | typedef struct DES_key_schedule 7 | { 8 | struct DES_key_stage 9 | { 10 | uint32_t h, l; 11 | } KS[16]; 12 | } DES_key_schedule; 13 | 14 | void DES_set_key(const uint8_t key[8],DES_key_schedule *ks); 15 | void DES_encrypt(uint8_t block[8],int decrypt,DES_key_schedule *ks); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /XADMaster/Crypto/md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. 3 | * MD5 Message-Digest Algorithm (RFC 1321). 4 | * 5 | * Homepage: 6 | * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 7 | * 8 | * Author: 9 | * Alexander Peslyak, better known as Solar Designer 10 | * 11 | * This software was written by Alexander Peslyak in 2001. No copyright is 12 | * claimed, and the software is hereby placed in the public domain. 13 | * In case this attempt to disclaim copyright and place the software in the 14 | * public domain is deemed null and void, then the software is 15 | * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the 16 | * general public under the following terms: 17 | * 18 | * Redistribution and use in source and binary forms, with or without 19 | * modification, are permitted. 20 | * 21 | * There's ABSOLUTELY NO WARRANTY, express or implied. 22 | * 23 | * See md5.c for more information. 24 | */ 25 | 26 | #ifdef HAVE_OPENSSL 27 | #include 28 | #elif !defined(_MD5_H) 29 | #define _MD5_H 30 | 31 | /* Any 32-bit or wider unsigned integer data type will do */ 32 | typedef unsigned int MD5_u32plus; 33 | 34 | typedef struct { 35 | MD5_u32plus lo, hi; 36 | MD5_u32plus a, b, c, d; 37 | unsigned char buffer[64]; 38 | MD5_u32plus block[16]; 39 | } MD5_CTX; 40 | 41 | extern void MD5_Init(MD5_CTX *ctx); 42 | extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size); 43 | extern void MD5_Final(unsigned char *result, MD5_CTX *ctx); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /XADMaster/Crypto/pbkdf2_hmac_sha256.h: -------------------------------------------------------------------------------- 1 | #ifndef __PBKDF2_HMAC_SHA256_H__ 2 | #define __PBKDF2_HMAC_SHA256_H__ 3 | 4 | #include 5 | #include 6 | 7 | void PBKDF2(const void *password,size_t passwordlength, 8 | const void *salt,size_t saltlength, 9 | uint8_t *DK,size_t DKlength,int count); 10 | 11 | void PBKDF2_3(const void *password,size_t passwordlength, 12 | const void *salt,size_t saltlength, 13 | uint8_t *DK1,uint8_t *DK2,uint8_t *DK3,size_t DKlength, 14 | int count1,int count2,int count3); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /XADMaster/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | NSHumanReadableCopyright = "LGPL"; 4 | -------------------------------------------------------------------------------- /XADMaster/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | XADMaster 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | XADMaster 17 | CFBundlePackageType 18 | FMWK 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 3.10 (libxad 13.0, modified) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /XADMaster/LZSS.c: -------------------------------------------------------------------------------- 1 | #include "LZSS.h" 2 | 3 | #include 4 | #include 5 | 6 | bool InitializeLZSS(LZSS *self,int windowsize) 7 | { 8 | self->window=malloc(windowsize); 9 | if(!self->window) return false; 10 | 11 | self->mask=windowsize-1; // Assume windows are power-of-two sized! 12 | 13 | RestartLZSS(self); 14 | 15 | return true; 16 | } 17 | 18 | void CleanupLZSS(LZSS *self) 19 | { 20 | free(self->window); 21 | } 22 | 23 | void RestartLZSS(LZSS *self) 24 | { 25 | memset(self->window,0,LZSSWindowSize(self)); 26 | self->position=0; 27 | } 28 | 29 | void CopyBytesFromLZSSWindow(LZSS *self,uint8_t *buffer,int64_t startpos,int length) 30 | { 31 | int windowoffs=LZSSWindowOffsetForPosition(self,startpos); 32 | 33 | if(windowoffs+length<=LZSSWindowSize(self)) // Request fits inside window 34 | { 35 | memcpy(buffer,&self->window[windowoffs],length); 36 | } 37 | else // Request wraps around window 38 | { 39 | int firstpart=LZSSWindowSize(self)-windowoffs; 40 | memcpy(&buffer[0],&self->window[windowoffs],firstpart); 41 | memcpy(&buffer[firstpart],&self->window[0],length-firstpart); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /XADMaster/LZW.h: -------------------------------------------------------------------------------- 1 | #ifndef __LZW_H__ 2 | #define __LZW_H__ 3 | 4 | #include 5 | #include 6 | 7 | #define LZWNoError 0 8 | #define LZWInvalidCodeError 1 9 | #define LZWTooManyCodesError 2 10 | 11 | typedef struct LZWTreeNode 12 | { 13 | uint8_t chr; 14 | int parent; 15 | } LZWTreeNode; 16 | 17 | typedef struct LZW 18 | { 19 | int numsymbols,maxsymbols,reservedsymbols; 20 | int prevsymbol; 21 | int symbolsize; 22 | 23 | uint8_t *buffer; 24 | int buffersize; 25 | 26 | LZWTreeNode nodes[0]; 27 | } LZW; 28 | 29 | LZW *AllocLZW(int maxsymbols,int reservedsymbols); 30 | void FreeLZW(LZW *self); 31 | void ClearLZWTable(LZW *self); 32 | 33 | int NextLZWSymbol(LZW *self,int symbol); 34 | int ReplaceLZWSymbol(LZW *self,int oldsymbol,int symbol); 35 | int LZWOutputLength(LZW *self); 36 | int LZWOutputToBuffer(LZW *self,uint8_t *buffer); 37 | int LZWReverseOutputToBuffer(LZW *self,uint8_t *buffer); 38 | int LZWOutputToInternalBuffer(LZW *self); 39 | 40 | static inline int LZWSuggestedSymbolSize(LZW *self) 41 | { 42 | return self->symbolsize; 43 | } 44 | 45 | static inline uint8_t *LZWInternalBuffer(LZW *self) 46 | { 47 | return self->buffer; 48 | } 49 | 50 | static inline int LZWSymbolCount(LZW *self) 51 | { 52 | return self->numsymbols; 53 | } 54 | 55 | static inline bool LZWSymbolListFull(LZW *self) 56 | { 57 | return self->numsymbols==self->maxsymbols; 58 | } 59 | 60 | static inline LZWTreeNode *LZWSymbols(LZW *self) 61 | { 62 | return self->nodes; 63 | } 64 | 65 | #endif 66 | 67 | -------------------------------------------------------------------------------- /XADMaster/NSDateXAD.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | #ifdef __MINGW32__ 5 | #include 6 | #endif 7 | 8 | @interface NSDate (XAD) 9 | 10 | +(NSDate *)XADDateWithYear:(int)year month:(int)month day:(int)day 11 | hour:(int)hour minute:(int)minute second:(int)second timeZone:(NSTimeZone *)timezone; 12 | +(NSDate *)XADDateWithTimeIntervalSince2000:(NSTimeInterval)interval; 13 | +(NSDate *)XADDateWithTimeIntervalSince1904:(NSTimeInterval)interval; 14 | +(NSDate *)XADDateWithTimeIntervalSince1601:(NSTimeInterval)interval; 15 | +(NSDate *)XADDateWithMSDOSDate:(uint16_t)date time:(uint16_t)time; 16 | +(NSDate *)XADDateWithMSDOSDate:(uint16_t)date time:(uint16_t)time timeZone:(NSTimeZone *)tz; 17 | +(NSDate *)XADDateWithMSDOSDateTime:(uint32_t)msdos; 18 | +(NSDate *)XADDateWithMSDOSDateTime:(uint32_t)msdos timeZone:(NSTimeZone *)tz; 19 | +(NSDate *)XADDateWithWindowsFileTime:(uint64_t)filetime; 20 | +(NSDate *)XADDateWithWindowsFileTimeLow:(uint32_t)low high:(uint32_t)high; 21 | +(NSDate *)XADDateWithCPMDate:(uint16_t)date time:(uint16_t)time; 22 | 23 | #ifndef __MINGW32__ 24 | -(struct timeval)timevalStruct; 25 | -(struct timespec)timespecStruct; 26 | #endif 27 | 28 | #ifdef __APPLE__ 29 | #ifdef __UTCUTILS__ 30 | -(UTCDateTime)UTCDateTime; 31 | #endif 32 | #endif 33 | 34 | #ifdef __MINGW32__ 35 | -(FILETIME)FILETIME; 36 | #endif 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /XADMaster/NSStringPrinting.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface NSString (Printing) 4 | 5 | +(int)terminalWidth; 6 | 7 | -(void)print; 8 | -(void)printToFile:(FILE *)fh; 9 | 10 | -(NSString *)stringByEscapingControlCharacters; 11 | 12 | -(NSArray *)linesWrappedToWidth:(int)width; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /XADMaster/NumberParsing.h: -------------------------------------------------------------------------------- 1 | #import "CSHandle.h" 2 | 3 | int64_t ParseNumberWithBase(const char *num,int length,int base); 4 | int64_t ParseDecimalNumber(const char *num,int length); 5 | int64_t ParseHexadecimalNumber(const char *num,int length); 6 | int64_t ParseOctalNumber(const char *num,int length); 7 | 8 | @interface CSHandle (NumberParsing) 9 | 10 | -(int64_t)readDecimalNumberWithDigits:(int)numdigits; 11 | -(int64_t)readHexadecimalNumberWithDigits:(int)numdigits; 12 | -(int64_t)readOctalNumberWithDigits:(int)numdigits; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /XADMaster/NumberParsing.m: -------------------------------------------------------------------------------- 1 | #import "NumberParsing.h" 2 | 3 | int64_t ParseNumberWithBase(const char *num,int length,int base) 4 | { 5 | char cstr[length+1]; 6 | memcpy(cstr,num,length); 7 | cstr[length]=0; 8 | return strtoll(cstr,NULL,base); 9 | } 10 | 11 | int64_t ParseDecimalNumber(const char *num,int length) 12 | { 13 | return ParseNumberWithBase(num,length,10); 14 | } 15 | 16 | int64_t ParseHexadecimalNumber(const char *num,int length) 17 | { 18 | return ParseNumberWithBase(num,length,16); 19 | } 20 | 21 | int64_t ParseOctalNumber(const char *num,int length) 22 | { 23 | return ParseNumberWithBase(num,length,8); 24 | } 25 | 26 | @implementation CSHandle (NumberParsing) 27 | 28 | -(int64_t)readDecimalNumberWithDigits:(int)numdigits 29 | { 30 | char buf[numdigits]; 31 | [self readBytes:numdigits toBuffer:buf]; 32 | return ParseDecimalNumber(buf,numdigits); 33 | } 34 | 35 | -(int64_t)readHexadecimalNumberWithDigits:(int)numdigits 36 | { 37 | char buf[numdigits]; 38 | [self readBytes:numdigits toBuffer:buf]; 39 | return ParseHexadecimalNumber(buf,numdigits); 40 | } 41 | 42 | -(int64_t)readOctalNumberWithDigits:(int)numdigits 43 | { 44 | char buf[numdigits]; 45 | [self readBytes:numdigits toBuffer:buf]; 46 | return ParseOctalNumber(buf,numdigits); 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /XADMaster/PDF/CCITTHandle.h: -------------------------------------------------------------------------------- 1 | #import "../CSByteStreamHandle.h" 2 | #import "../XADPrefixCode.h" 3 | 4 | extern NSString *CCITTCodeException; 5 | 6 | @interface CCITTFaxHandle:CSByteStreamHandle 7 | { 8 | int columns,white; 9 | int column,colour,bitsleft; 10 | } 11 | 12 | -(id)initWithInputBufferForHandle:(CSHandle *)handle columns:(int)cols white:(int)whitevalue; 13 | 14 | -(void)resetByteStream; 15 | -(uint8_t)produceByteAtOffset:(off_t)pos; 16 | 17 | -(void)startNewLine; 18 | -(void)findNextSpanLength; 19 | 20 | @end 21 | 22 | @interface CCITTFaxT41DHandle:CCITTFaxHandle 23 | { 24 | XADPrefixCode *whitecode,*blackcode; 25 | } 26 | 27 | -(id)initWithHandle:(CSHandle *)handle columns:(int)cols white:(int)whitevalue; 28 | -(void)dealloc; 29 | 30 | -(void)startNewLine; 31 | -(void)findNextSpanLength; 32 | 33 | @end 34 | 35 | @interface CCITTFaxT6Handle:CCITTFaxHandle 36 | { 37 | int *prevchanges,numprevchanges; 38 | int *currchanges,numcurrchanges; 39 | int prevpos,previndex,currpos,currcol,nexthoriz; 40 | XADPrefixCode *maincode,*whitecode,*blackcode; 41 | } 42 | 43 | -(id)initWithHandle:(CSHandle *)handle columns:(int)columns white:(int)whitevalue; 44 | -(void)dealloc; 45 | 46 | -(void)resetByteStream; 47 | -(void)startNewLine; 48 | -(void)findNextSpanLength; 49 | 50 | @end 51 | 52 | -------------------------------------------------------------------------------- /XADMaster/PDF/LZWHandle.h: -------------------------------------------------------------------------------- 1 | #import "../CSByteStreamHandle.h" 2 | #import "../LZW.h" 3 | 4 | extern NSString *LZWInvalidCodeException; 5 | 6 | @interface LZWHandle:CSByteStreamHandle 7 | { 8 | BOOL early; 9 | 10 | LZW *lzw; 11 | int symbolsize; 12 | 13 | int currbyte; 14 | uint8_t buffer[4096]; 15 | } 16 | 17 | -(id)initWithHandle:(CSHandle *)handle earlyChange:(BOOL)earlychange; 18 | 19 | -(void)clearTable; 20 | 21 | -(void)resetByteStream; 22 | -(uint8_t)produceByteAtOffset:(off_t)pos; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /XADMaster/PDF/LZWHandle.m: -------------------------------------------------------------------------------- 1 | #import "LZWHandle.h" 2 | 3 | NSString *LZWInvalidCodeException=@"LZWInvalidCodeException"; 4 | 5 | 6 | @implementation LZWHandle 7 | 8 | -(id)initWithHandle:(CSHandle *)handle earlyChange:(BOOL)earlychange 9 | { 10 | if(self=[super initWithInputBufferForHandle:handle]) 11 | { 12 | early=earlychange; 13 | lzw=AllocLZW(4096+1,2); 14 | } 15 | return self; 16 | } 17 | 18 | -(void)dealloc 19 | { 20 | FreeLZW(lzw); 21 | [super dealloc]; 22 | } 23 | 24 | -(void)clearTable 25 | { 26 | ClearLZWTable(lzw); 27 | symbolsize=9; 28 | currbyte=0; 29 | } 30 | 31 | -(void)resetByteStream 32 | { 33 | [self clearTable]; 34 | } 35 | 36 | -(uint8_t)produceByteAtOffset:(off_t)pos 37 | { 38 | if(!currbyte) 39 | { 40 | int symbol; 41 | for(;;) 42 | { 43 | symbol=CSInputNextBitString(input,symbolsize); 44 | if(symbol==256) [self clearTable]; 45 | else break; 46 | } 47 | 48 | if(symbol==257) CSByteStreamEOF(self); 49 | 50 | int err=NextLZWSymbol(lzw,symbol); 51 | if(err!=LZWNoError) [NSException raise:LZWInvalidCodeException format:@"Invalid code in LZW stream (error code %d)",err]; 52 | currbyte=LZWReverseOutputToBuffer(lzw,buffer); 53 | 54 | int offs=early?1:0; 55 | int numsymbols=LZWSymbolCount(lzw); 56 | if(numsymbols==512-offs) symbolsize=10; 57 | else if(numsymbols==1024-offs) symbolsize=11; 58 | else if(numsymbols==2048-offs) symbolsize=12; 59 | } 60 | 61 | return buffer[--currbyte]; 62 | } 63 | 64 | @end 65 | 66 | -------------------------------------------------------------------------------- /XADMaster/PDF/NSDictionaryNumberExtension.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface NSDictionary (NumberExtension) 4 | 5 | -(int)intValueForKey:(NSString *)key default:(int)def; 6 | -(unsigned int)unsignedIntValueForKey:(NSString *)key default:(unsigned int)def; 7 | -(BOOL)boolValueForKey:(NSString *)key default:(BOOL)def; 8 | -(float)floatValueForKey:(NSString *)key default:(float)def; 9 | -(double)doubleValueForKey:(NSString *)key default:(double)def; 10 | 11 | -(NSString *)stringForKey:(NSString *)key default:(NSString *)def; 12 | -(NSArray *)arrayForKey:(NSString *)key; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /XADMaster/PDF/NSDictionaryNumberExtension.m: -------------------------------------------------------------------------------- 1 | #import "NSDictionaryNumberExtension.h" 2 | 3 | 4 | @implementation NSDictionary (NumberExtension) 5 | 6 | -(int)intValueForKey:(NSString *)key default:(int)def 7 | { 8 | id obj=[self objectForKey:key]; 9 | if(!obj||![obj isKindOfClass:[NSNumber class]]) return def; 10 | return [obj intValue]; 11 | } 12 | 13 | -(unsigned int)unsignedIntValueForKey:(NSString *)key default:(unsigned int)def 14 | { 15 | id obj=[self objectForKey:key]; 16 | if(!obj||![obj isKindOfClass:[NSNumber class]]) return def; 17 | return [obj unsignedIntValue]; 18 | } 19 | 20 | -(BOOL)boolValueForKey:(NSString *)key default:(BOOL)def 21 | { 22 | id obj=[self objectForKey:key]; 23 | if(!obj||![obj isKindOfClass:[NSNumber class]]) return def; 24 | return [obj boolValue]; 25 | } 26 | 27 | -(float)floatValueForKey:(NSString *)key default:(float)def 28 | { 29 | id obj=[self objectForKey:key]; 30 | if(!obj||![obj isKindOfClass:[NSNumber class]]) return def; 31 | return [obj floatValue]; 32 | } 33 | 34 | -(double)doubleValueForKey:(NSString *)key default:(double)def 35 | { 36 | id obj=[self objectForKey:key]; 37 | if(!obj||![obj isKindOfClass:[NSNumber class]]) return def; 38 | return [obj doubleValue]; 39 | } 40 | 41 | -(NSString *)stringForKey:(NSString *)key default:(NSString *)def 42 | { 43 | id obj=[self objectForKey:key]; 44 | if(!obj||![obj isKindOfClass:[NSString class]]) return def; 45 | return obj; 46 | } 47 | 48 | -(NSArray *)arrayForKey:(NSString *)key 49 | { 50 | id obj=[self objectForKey:key]; 51 | if(!obj) return nil; 52 | else if([obj isKindOfClass:[NSArray class]]) return obj; 53 | else return [NSArray arrayWithObject:obj]; 54 | } 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /XADMaster/PDF/PDFEncryptionUtils.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "../CSHandle.h" 3 | #import "../CSBlockStreamHandle.h" 4 | #import "../Crypto/md5.h" 5 | #import "../Crypto/aes.h" 6 | 7 | extern NSString *PDFMD5FinishedException; 8 | 9 | 10 | 11 | @interface PDFMD5Engine:NSObject 12 | { 13 | MD5_CTX md5; 14 | unsigned char digest_bytes[16]; 15 | BOOL done; 16 | } 17 | 18 | +(PDFMD5Engine *)engine; 19 | +(NSData *)digestForData:(NSData *)data; 20 | +(NSData *)digestForBytes:(const void *)bytes length:(int)length; 21 | 22 | -(id)init; 23 | 24 | -(void)updateWithData:(NSData *)data; 25 | -(void)updateWithBytes:(const void *)bytes length:(unsigned long)length; 26 | 27 | -(NSData *)digest; 28 | -(NSString *)hexDigest; 29 | 30 | -(NSString *)description; 31 | 32 | @end 33 | 34 | 35 | 36 | 37 | @interface PDFAESHandle:CSBlockStreamHandle 38 | { 39 | off_t startoffs; 40 | 41 | NSData *key,*iv; 42 | 43 | aes_decrypt_ctx aes; 44 | uint8_t ivbuffer[16],streambuffer[16]; 45 | } 46 | 47 | -(id)initWithHandle:(CSHandle *)handle key:(NSData *)keydata; 48 | -(void)dealloc; 49 | 50 | -(void)resetBlockStream; 51 | -(int)produceBlockAtOffset:(off_t)pos; 52 | 53 | @end 54 | 55 | -------------------------------------------------------------------------------- /XADMaster/PPMd/Dependencies: -------------------------------------------------------------------------------- 1 | Context.o: Context.c Context.h RangeCoder.h SubAllocator.h 2 | RangeCoder.o: RangeCoder.c RangeCoder.h 3 | SubAllocatorBrimstone.o: SubAllocatorBrimstone.c SubAllocatorBrimstone.h \ 4 | SubAllocator.h 5 | SubAllocatorVariantG.o: SubAllocatorVariantG.c SubAllocatorVariantG.h \ 6 | SubAllocator.h 7 | SubAllocatorVariantH.o: SubAllocatorVariantH.c SubAllocatorVariantH.h \ 8 | SubAllocator.h 9 | SubAllocatorVariantI.o: SubAllocatorVariantI.c SubAllocatorVariantI.h \ 10 | SubAllocator.h 11 | VariantG.o: VariantG.c VariantG.h Context.h RangeCoder.h SubAllocator.h 12 | VariantH.o: VariantH.c VariantH.h Context.h RangeCoder.h SubAllocator.h \ 13 | SubAllocatorVariantH.h 14 | VariantI.o: VariantI.c VariantI.h Context.h RangeCoder.h SubAllocator.h \ 15 | SubAllocatorVariantI.h 16 | SimpleDecompressor.o: SimpleDecompressor.c VariantG.h Context.h \ 17 | RangeCoder.h SubAllocator.h VariantH.h SubAllocatorVariantH.h \ 18 | VariantI.h SubAllocatorVariantI.h SubAllocatorVariantG.h \ 19 | SubAllocatorBrimstone.h 20 | Fuzzer.o: Fuzzer.c VariantG.h Context.h RangeCoder.h SubAllocator.h \ 21 | VariantH.h SubAllocatorVariantH.h VariantI.h SubAllocatorVariantI.h \ 22 | SubAllocatorVariantG.h SubAllocatorBrimstone.h 23 | -------------------------------------------------------------------------------- /XADMaster/PPMd/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-std=c99 -g 2 | 3 | LDFLAGS= 4 | LIBS= 5 | 6 | CC=gcc 7 | LD=gcc 8 | 9 | PPMD_C_FILES=Context.c \ 10 | RangeCoder.c \ 11 | SubAllocatorBrimstone.c \ 12 | SubAllocatorVariantG.c \ 13 | SubAllocatorVariantH.c \ 14 | SubAllocatorVariantI.c \ 15 | VariantG.c \ 16 | VariantH.c \ 17 | VariantI.c 18 | 19 | SIMPLEDECOMPRESSOR_C_FILES=SimpleDecompressor.c 20 | 21 | FUZZER_C_FILES=Fuzzer.c 22 | 23 | ALL_C_FILES=$(PPMD_C_FILES) $(SIMPLEDECOMPRESSOR_C_FILES) $(FUZZER_C_FILES) 24 | 25 | ALL_OBJS=$(ALL_C_FILES:.c=.o) 26 | SIMPLEDECOMPRESSOR_OBJS=$(SIMPLEDECOMPRESSOR_C_FILES:.c=.o) $(PPMD_C_FILES:.c=.o) 27 | FUZZER_OBJS=$(FUZZER_C_FILES:.c=.o) $(PPMD_C_FILES:.c=.o) 28 | 29 | all: SimpleDecompressor Fuzzer 30 | 31 | Fuzzer: $(FUZZER_OBJS) 32 | $(LD) $(LDFLAGS) -o $@ $^ $(LIBS) 33 | 34 | SimpleDecompressor: $(SIMPLEDECOMPRESSOR_OBJS) 35 | $(LD) $(LDFLAGS) -o $@ $^ $(LIBS) 36 | 37 | clean: 38 | rm -rf $(ALL_OBJS) SimpleDecompressor Fuzzer 39 | 40 | depend: 41 | $(CC) -MM $(CFLAGS) $(ALL_C_FILES) >Dependencies.tmp 42 | sed 's/.*: *\([^ ]*\)\.\([^ ]*\)/\1.o: \1.\2/g' Dependencies 43 | rm Dependencies.tmp 44 | 45 | include Dependencies 46 | -------------------------------------------------------------------------------- /XADMaster/PPMd/PPMd.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /XADMaster/PPMd/RangeCoder.h: -------------------------------------------------------------------------------- 1 | #ifndef __PPMD_RANGE_CODER_H__ 2 | #define __PPMD_RANGE_CODER_H__ 3 | 4 | #include 5 | #include 6 | 7 | typedef int PPMdReadFunction(void *context); 8 | 9 | typedef struct PPMdRangeCoder 10 | { 11 | PPMdReadFunction *readfunc; 12 | void *inputcontext; 13 | 14 | uint32_t low,code,range,bottom; 15 | bool uselow; 16 | } PPMdRangeCoder; 17 | 18 | void InitializePPMdRangeCoder(PPMdRangeCoder *self, 19 | PPMdReadFunction *readfunc,void *inputcontext, 20 | bool uselow,int bottom); 21 | 22 | uint32_t PPMdRangeCoderCurrentCount(PPMdRangeCoder *self,uint32_t scale); 23 | void RemovePPMdRangeCoderSubRange(PPMdRangeCoder *self,uint32_t lowcount,uint32_t highcount); 24 | 25 | int NextWeightedBitFromPPMdRangeCoder(PPMdRangeCoder *self,int weight,int size); 26 | 27 | int NextWeightedBitFromPPMdRangeCoder2(PPMdRangeCoder *self,int weight,int shift); 28 | 29 | void NormalizePPMdRangeCoder(PPMdRangeCoder *self); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /XADMaster/PPMd/SubAllocator.h: -------------------------------------------------------------------------------- 1 | #ifndef __PPMD_SUB_ALLOCATOR_H__ 2 | #define __PPMD_SUB_ALLOCATOR_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | typedef struct PPMdSubAllocator PPMdSubAllocator; 9 | 10 | struct PPMdSubAllocator 11 | { 12 | void (*Init)(PPMdSubAllocator *self); 13 | uint32_t (*AllocContext)(PPMdSubAllocator *self); 14 | uint32_t (*AllocUnits)(PPMdSubAllocator *self,int num); // 1 unit == 12 bytes, NU <= 128 15 | uint32_t (*ExpandUnits)(PPMdSubAllocator *self,uint32_t oldoffs,int oldnum); 16 | uint32_t (*ShrinkUnits)(PPMdSubAllocator *self,uint32_t oldoffs,int oldnum,int newnum); 17 | void (*FreeUnits)(PPMdSubAllocator *self,uint32_t offs,int num); 18 | }; 19 | 20 | static inline void InitSubAllocator(PPMdSubAllocator *self) { self->Init(self); }; 21 | static inline uint32_t AllocContext(PPMdSubAllocator *self) { return self->AllocContext(self); } 22 | static inline uint32_t AllocUnits(PPMdSubAllocator *self,int num) { return self->AllocUnits(self,num); } 23 | static inline uint32_t ExpandUnits(PPMdSubAllocator *self,uint32_t oldoffs,int oldnum) { return self->ExpandUnits(self,oldoffs,oldnum); } 24 | static inline uint32_t ShrinkUnits(PPMdSubAllocator *self,uint32_t oldoffs,int oldnum,int newnum) { return self->ShrinkUnits(self,oldoffs,oldnum,newnum); } 25 | static inline void FreeUnits(PPMdSubAllocator *self,uint32_t offs,int num) { return self->FreeUnits(self,offs,num); } 26 | 27 | // TODO: Keep pointers as pointers on 32 bit, and offsets on 64 bit. 28 | 29 | static inline void *OffsetToPointer(void *base,uint32_t offset) 30 | { 31 | if(!offset) return NULL; 32 | return ((uint8_t *)base)+offset; 33 | } 34 | 35 | static inline uint32_t PointerToOffset(void *base,void *pointer) 36 | { 37 | if(!pointer) return 0; 38 | return (uint32_t)(((uintptr_t)pointer)-(uintptr_t)base); 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /XADMaster/PPMd/SubAllocatorBrimstone.h: -------------------------------------------------------------------------------- 1 | #ifndef __PPMD_SUB_ALLOCATOR_BRIMSTONE_H__ 2 | #define __PPMD_SUB_ALLOCATOR_BRIMSTONE_H__ 3 | 4 | #include "SubAllocator.h" 5 | 6 | typedef struct PPMdSubAllocatorBrimstone 7 | { 8 | PPMdSubAllocator core; 9 | 10 | uint32_t SubAllocatorSize; 11 | uint8_t Index2Units[38],Units2Index[128]; 12 | uint8_t *LowUnit,*HighUnit; 13 | struct PPMAllocatorNodeBrimstone { struct PPMAllocatorNodeBrimstone *next; } FreeList[38]; 14 | uint8_t HeapStart[0]; 15 | } PPMdSubAllocatorBrimstone; 16 | 17 | PPMdSubAllocatorBrimstone *CreateSubAllocatorBrimstone(int size); 18 | void FreeSubAllocatorBrimstone(PPMdSubAllocatorBrimstone *self); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /XADMaster/PPMd/SubAllocatorVariantG.h: -------------------------------------------------------------------------------- 1 | #ifndef __PPMD_SUB_ALLOCATOR_VARIANT_G_H__ 2 | #define __PPMD_SUB_ALLOCATOR_VARIANT_G_H__ 3 | 4 | #include "SubAllocator.h" 5 | 6 | typedef struct PPMdSubAllocatorVariantG 7 | { 8 | PPMdSubAllocator core; 9 | 10 | uint32_t SubAllocatorSize; 11 | uint8_t Index2Units[38],Units2Index[128]; 12 | uint8_t *LowUnit,*HighUnit,*LastBreath; 13 | struct PPMAllocatorNodeVariantG { struct PPMAllocatorNodeVariantG *next; } FreeList[38]; 14 | uint8_t HeapStart[0]; 15 | } PPMdSubAllocatorVariantG; 16 | 17 | PPMdSubAllocatorVariantG *CreateSubAllocatorVariantG(int size); 18 | void FreeSubAllocatorVariantG(PPMdSubAllocatorVariantG *self); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /XADMaster/PPMd/SubAllocatorVariantH.h: -------------------------------------------------------------------------------- 1 | #ifndef __PPMD_SUB_ALLOCATOR_VARIANT_H_H__ 2 | #define __PPMD_SUB_ALLOCATOR_VARIANT_H_H__ 3 | 4 | #include "SubAllocator.h" 5 | 6 | struct PPMdMemoryBlockVariantH 7 | { 8 | uint16_t Stamp,NU; 9 | uint32_t next,prev; 10 | } __attribute__((packed)); 11 | 12 | typedef struct PPMdSubAllocatorVariantH 13 | { 14 | PPMdSubAllocator core; 15 | 16 | uint32_t SubAllocatorSize; 17 | uint8_t Index2Units[38],Units2Index[128],GlueCount; 18 | uint8_t *pText,*UnitsStart,*LowUnit,*HighUnit; 19 | struct PPMAllocatorNodeVariantH { struct PPMAllocatorNodeVariantH *next; } FreeList[38]; 20 | struct PPMdMemoryBlockVariantH sentinel; 21 | uint8_t HeapStart[0]; 22 | } PPMdSubAllocatorVariantH; 23 | 24 | PPMdSubAllocatorVariantH *CreateSubAllocatorVariantH(int size); 25 | void FreeSubAllocatorVariantH(PPMdSubAllocatorVariantH *self); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /XADMaster/PPMd/SubAllocatorVariantI.h: -------------------------------------------------------------------------------- 1 | #ifndef __PPMD_SUB_ALLOCATOR_VARIANT_I_H__ 2 | #define __PPMD_SUB_ALLOCATOR_VARIANT_I_H__ 3 | 4 | #include "SubAllocator.h" 5 | 6 | typedef struct PPMdMemoryBlockVariantI 7 | { 8 | uint32_t Stamp; 9 | uint32_t next; 10 | uint32_t NU; 11 | } __attribute__((packed)) PPMdMemoryBlockVariantI; 12 | 13 | typedef struct PPMdSubAllocatorVariantI 14 | { 15 | PPMdSubAllocator core; 16 | 17 | uint32_t GlueCount,SubAllocatorSize; 18 | uint8_t Index2Units[38],Units2Index[128]; // constants 19 | uint8_t *pText,*UnitsStart,*LowUnit,*HighUnit; 20 | PPMdMemoryBlockVariantI BList[38]; 21 | uint8_t HeapStart[0]; 22 | } PPMdSubAllocatorVariantI; 23 | 24 | PPMdSubAllocatorVariantI *CreateSubAllocatorVariantI(int size); 25 | void FreeSubAllocatorVariantI(PPMdSubAllocatorVariantI *self); 26 | 27 | uint32_t GetUsedMemoryVariantI(PPMdSubAllocatorVariantI *self); 28 | void SpecialFreeUnitVariantI(PPMdSubAllocatorVariantI *self,uint32_t offs); 29 | uint32_t MoveUnitsUpVariantI(PPMdSubAllocatorVariantI *self,uint32_t oldoffs,int num); 30 | void ExpandTextAreaVariantI(PPMdSubAllocatorVariantI *self); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /XADMaster/PPMd/VariantG.h: -------------------------------------------------------------------------------- 1 | #ifndef __PPMD_VARIANT_G_H__ 2 | #define __PPMD_VARIANT_G_H__ 3 | 4 | #include "Context.h" 5 | 6 | // PPMd Variant G. Used (slightly modified) by StuffIt X. 7 | 8 | typedef struct PPMdModelVariantG 9 | { 10 | PPMdCoreModel core; 11 | 12 | PPMdContext *MinContext,*MedContext,*MaxContext; 13 | int MaxOrder; 14 | bool Brimstone; 15 | SEE2Context SEE2Cont[43][8],DummySEE2Cont; 16 | uint8_t NS2BSIndx[256],NS2Indx[256]; 17 | uint16_t BinSumm[128][16]; // binary SEE-contexts 18 | } PPMdModelVariantG; 19 | 20 | void StartPPMdModelVariantG(PPMdModelVariantG *self, 21 | PPMdReadFunction *readfunc,void *inputcontext, 22 | PPMdSubAllocator *alloc,int maxorder,bool brimstone); 23 | int NextPPMdVariantGByte(PPMdModelVariantG *self); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /XADMaster/PPMd/VariantH.h: -------------------------------------------------------------------------------- 1 | #ifndef __PPMD_VARIANT_H_H__ 2 | #define __PPMD_VARIANT_H_H__ 3 | 4 | #include "Context.h" 5 | #include "SubAllocatorVariantH.h" 6 | 7 | // PPMd Variant H. Used by RAR and 7-Zip. 8 | 9 | typedef struct PPMdModelVariantH 10 | { 11 | PPMdCoreModel core; 12 | 13 | PPMdSubAllocatorVariantH *alloc; 14 | 15 | PPMdContext *MinContext,*MaxContext; 16 | int MaxOrder,HiBitsFlag; 17 | bool SevenZip; 18 | SEE2Context SEE2Cont[25][16],DummySEE2Cont; 19 | uint8_t NS2BSIndx[256],HB2Flag[256],NS2Indx[256]; 20 | uint16_t BinSumm[128][64]; // binary SEE-contexts 21 | } PPMdModelVariantH; 22 | 23 | void StartPPMdModelVariantH(PPMdModelVariantH *self, 24 | PPMdReadFunction *readfunc,void *inputcontext, 25 | PPMdSubAllocatorVariantH *alloc,int maxorder,bool sevenzip); 26 | void RestartPPMdVariantHRangeCoder(PPMdModelVariantH *self, 27 | PPMdReadFunction *readfunc,void *inputcontext, 28 | bool sevenzip); 29 | int NextPPMdVariantHByte(PPMdModelVariantH *self); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /XADMaster/PPMd/VariantI.h: -------------------------------------------------------------------------------- 1 | #ifndef __PPMD_VARIANT_I_H__ 2 | #define __PPMD_VARIANT_I_H__ 3 | 4 | #include "Context.h" 5 | #include "SubAllocatorVariantI.h" 6 | 7 | // PPMd Variant I. Used by WinZip. 8 | 9 | #define MRM_RESTART 0 10 | #define MRM_CUT_OFF 1 11 | #define MRM_FREEZE 2 12 | 13 | typedef struct PPMdModelVariantI 14 | { 15 | PPMdCoreModel core; 16 | 17 | PPMdSubAllocatorVariantI *alloc; 18 | 19 | uint8_t NS2BSIndx[256],QTable[260]; // constants 20 | 21 | PPMdContext *MaxContext; 22 | int MaxOrder,MRMethod; 23 | SEE2Context SEE2Cont[24][32],DummySEE2Cont; 24 | uint16_t BinSumm[25][64]; // binary SEE-contexts 25 | 26 | bool endofstream; 27 | } PPMdModelVariantI; 28 | 29 | void StartPPMdModelVariantI(PPMdModelVariantI *self, 30 | PPMdReadFunction *readfunc,void *inputcontext, 31 | PPMdSubAllocatorVariantI *alloc,int maxorder,int restoration); 32 | int NextPPMdVariantIByte(PPMdModelVariantI *self); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /XADMaster/Progress.h: -------------------------------------------------------------------------------- 1 | #import "CSHandle.h" 2 | #import "CSStreamHandle.h" 3 | #import "CSZlibHandle.h" 4 | #import "CSBzip2Handle.h" 5 | 6 | @interface CSHandle (Progress) 7 | 8 | -(double)estimatedProgress; 9 | 10 | @end 11 | 12 | @interface CSZlibHandle (Progress) 13 | 14 | -(double)estimatedProgress; 15 | 16 | @end 17 | 18 | @interface CSStreamHandle (progress) 19 | 20 | -(double)estimatedProgress; 21 | 22 | @end 23 | 24 | @interface CSBzip2Handle (progress) 25 | 26 | -(double)estimatedProgress; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /XADMaster/Progress.m: -------------------------------------------------------------------------------- 1 | #import "Progress.h" 2 | 3 | 4 | @implementation CSHandle (Progress) 5 | 6 | -(double)estimatedProgress 7 | { 8 | off_t size=[self fileSize]; 9 | if(size==CSHandleMaxLength) return 0; 10 | if(size==1) return 1; 11 | return (double)[self offsetInFile]/(double)size; 12 | } 13 | 14 | @end 15 | 16 | @implementation CSStreamHandle (progress) 17 | 18 | -(double)estimatedProgress 19 | { 20 | if(streamlength==CSHandleMaxLength) 21 | { 22 | if(input) return [input->parent estimatedProgress]; // TODO: better estimation 23 | else return 0; 24 | } 25 | else return (double)streampos/(double)streamlength; 26 | } 27 | 28 | @end 29 | 30 | @implementation CSZlibHandle (Progress) 31 | 32 | -(double)estimatedProgress { return [parent estimatedProgress]; } // TODO: better estimation using buffer? 33 | 34 | @end 35 | 36 | @implementation CSBzip2Handle (progress) 37 | 38 | -(double)estimatedProgress { return [parent estimatedProgress]; } // TODO: better estimation using buffer? 39 | 40 | @end 41 | 42 | // TODO: more handles like LZMA? 43 | -------------------------------------------------------------------------------- /XADMaster/RARAudioDecoder.h: -------------------------------------------------------------------------------- 1 | #ifndef __RARAUDIODECODER_H__ 2 | #define __RARAUDIODECODER_H__ 3 | 4 | typedef struct RAR20AudioState 5 | { 6 | int weight1,weight2,weight3,weight4,weight5; 7 | int delta1,delta2,delta3,delta4; 8 | int lastdelta; 9 | int error[11]; 10 | int count; 11 | int lastbyte; 12 | } RAR20AudioState; 13 | 14 | typedef struct RAR30AudioState 15 | { 16 | int weight1,weight2,weight3,weight4,weight5; 17 | int delta1,delta2,delta3,delta4; 18 | int lastdelta; 19 | int error[7]; 20 | int count; 21 | int lastbyte; 22 | } RAR30AudioState; 23 | 24 | int DecodeRAR20Audio(RAR20AudioState *state,int *channeldelta,int delta); 25 | int DecodeRAR30Audio(RAR30AudioState *state,int delta); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /XADMaster/RARBug.h: -------------------------------------------------------------------------------- 1 | #ifndef __RARBUG_H__ 2 | #define __RARBUG_H__ 3 | 4 | #include "Crypto/sha.h" 5 | 6 | void SHA1_Update_WithRARBug(SHA_CTX *ctx,void *bytes,unsigned long length,int bug); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /XADMaster/Realloc.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | static inline void *Realloc(void *ptr,size_t newsize) 4 | { 5 | void *newptr=realloc(ptr,newsize); 6 | if(!newptr) 7 | { 8 | free(ptr); 9 | [NSException raise:NSMallocException format:@"Realloc() failed"]; 10 | } 11 | return newptr; 12 | } 13 | -------------------------------------------------------------------------------- /XADMaster/Scanning.h: -------------------------------------------------------------------------------- 1 | #import "CSHandle.h" 2 | 3 | typedef int (*CSByteMatchingFunctionPointer)(const uint8_t *bytes,int available,off_t offset,void *state); 4 | 5 | @interface CSHandle (Scanning) 6 | 7 | -(BOOL)scanForByteString:(const void *)bytes length:(int)length; 8 | -(int)scanUsingMatchingFunction:(CSByteMatchingFunctionPointer)function 9 | maximumLength:(int)maximumlength; 10 | -(int)scanUsingMatchingFunction:(CSByteMatchingFunctionPointer)function 11 | maximumLength:(int)maximumlength context:(void *)contextptr; 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /XADMaster/Scanning.m: -------------------------------------------------------------------------------- 1 | #import "Scanning.h" 2 | 3 | typedef struct ByteString 4 | { 5 | const uint8_t *bytes; 6 | int length; 7 | } ByteString; 8 | 9 | static int MatchByteString(const uint8_t *bytes,int available,off_t offset,void *context) 10 | { 11 | ByteString *bs=context; 12 | if(availablelength) return NO; 13 | return memcmp(bytes,bs->bytes,bs->length)==0; 14 | } 15 | 16 | 17 | @implementation CSHandle (Scanning) 18 | 19 | -(BOOL)scanForByteString:(const void *)bytes length:(int)length 20 | { 21 | ByteString bs={ .bytes=bytes, .length=length }; 22 | return [self scanUsingMatchingFunction:MatchByteString maximumLength:length context:&bs]; 23 | } 24 | 25 | -(int)scanUsingMatchingFunction:(CSByteMatchingFunctionPointer)function 26 | maximumLength:(int)maximumlength 27 | { 28 | return [self scanUsingMatchingFunction:function maximumLength:maximumlength context:NULL]; 29 | } 30 | 31 | -(int)scanUsingMatchingFunction:(CSByteMatchingFunctionPointer)function 32 | maximumLength:(int)maximumlength context:(void *)contextptr 33 | { 34 | uint8_t buffer[65536]; 35 | 36 | off_t pos=0; 37 | int actual=[self readAtMost:sizeof(buffer) toBuffer:buffer]; 38 | 39 | while(actual>=maximumlength) 40 | { 41 | for(int i=0;i<=actual-maximumlength;i++) 42 | { 43 | int res=function(&buffer[i],actual-i,pos++,contextptr); 44 | if(res) 45 | { 46 | [self skipBytes:i-actual]; 47 | return res; 48 | } 49 | } 50 | 51 | memcpy(buffer,&buffer[actual-maximumlength+1],maximumlength-1); 52 | actual=[self readAtMost:sizeof(buffer)-maximumlength+1 toBuffer:&buffer[maximumlength-1]]+maximumlength-1; 53 | } 54 | 55 | for(int i=0;i 5 | #include 6 | 7 | typedef size_t WinZipJPEGReadFunction(void *context,uint8_t *buffer,size_t length); 8 | 9 | #endif 10 | 11 | -------------------------------------------------------------------------------- /XADMaster/WinZipJPEG/LZMA.h: -------------------------------------------------------------------------------- 1 | #ifndef __WINZIP_JPEG_LZMA_H__ 2 | #define __WINZIP_JPEG_LZMA_H__ 3 | 4 | #if !__LP64__ 5 | #define _LZMA_UINT32_IS_ULONG 6 | #endif 7 | 8 | #define Byte LzmaByte 9 | #include "../lzma/LzmaDec.h" 10 | #undef Byte 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /XADMaster/WinZipJPEG/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-std=c99 -g 2 | 3 | LDFLAGS= 4 | LIBS= 5 | 6 | CC=gcc 7 | LD=gcc 8 | 9 | ALL_C_FILES=ArithmeticDecoder.c \ 10 | Decompressor.c \ 11 | JPEG.c \ 12 | RawDecoder.c \ 13 | Test.c \ 14 | ../lzma/LzmaDec.c \ 15 | 16 | RAWDECODER_C_FILES=ArithmeticDecoder.c \ 17 | Decompressor.c \ 18 | JPEG.c \ 19 | RawDecoder.c \ 20 | ../lzma/LzmaDec.c \ 21 | 22 | TEST_C_FILES=ArithmeticDecoder.c \ 23 | Test.c 24 | 25 | ALL_OBJS=$(ALL_C_FILES:.c=.o) 26 | RAWDECODER_OBJS=$(RAWDECODER_C_FILES:.c=.o) 27 | TEST_OBJS=$(TEST_C_FILES:.c=.o) 28 | 29 | all: RawDecoder Test 30 | 31 | RawDecoder: $(RAWDECODER_OBJS) 32 | $(LD) $(LDFLAGS) -o $@ $^ $(LIBS) 33 | 34 | Test: $(TEST_OBJS) 35 | $(LD) $(LDFLAGS) -o $@ $^ $(LIBS) 36 | 37 | clean: 38 | rm -rf $(ALL_OBJS) RawDecoder Test 39 | 40 | depend: 41 | $(CC) -MM $(CFLAGS) $(ALL_C_FILES) >Dependencies.tmp 42 | sed 's/.*: *\([^ ]*\)\.\([^ ]*\)/\1.o: \1.\2/g' Dependencies 43 | rm Dependencies.tmp 44 | 45 | include Dependencies 46 | 47 | -------------------------------------------------------------------------------- /XADMaster/Windows/Foundation.1.0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/Windows/Foundation.1.0.dll -------------------------------------------------------------------------------- /XADMaster/Windows/bin/libtoolstub.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use strict; 4 | 5 | my $filelist; 6 | my $output; 7 | 8 | foreach my $i (0..$#ARGV) 9 | { 10 | $filelist=$ARGV[$i+1] if $ARGV[$i] eq "-filelist"; 11 | $output=$ARGV[$i+1] if $ARGV[$i] eq "-o"; 12 | } 13 | 14 | unlink $output; 15 | 16 | open LIST,$filelist or die; 17 | my @files=; 18 | close LIST; 19 | 20 | chomp @files; 21 | 22 | system( 23 | "/Developer/Cocotron/1.0/Windows/i386/gcc-4.3.1/bin/i386-mingw32msvc-ar", 24 | "rcs", 25 | $output, 26 | @files 27 | ); -------------------------------------------------------------------------------- /XADMaster/Windows/lib/libbz2.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/Windows/lib/libbz2.a -------------------------------------------------------------------------------- /XADMaster/Windows/lib/libz.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/Windows/lib/libz.a -------------------------------------------------------------------------------- /XADMaster/XAD7ZipAESHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSBlockStreamHandle.h" 2 | 3 | #import "Crypto/aes.h" 4 | 5 | @interface XAD7ZipAESHandle:CSBlockStreamHandle 6 | { 7 | off_t startoffs; 8 | 9 | aes_decrypt_ctx aes; 10 | uint8_t iv[16],block[16],buffer[65536]; 11 | } 12 | 13 | +(int)logRoundsForPropertyData:(NSData *)propertydata; 14 | +(NSData *)saltForPropertyData:(NSData *)propertydata; 15 | +(NSData *)IVForPropertyData:(NSData *)propertydata; 16 | +(NSData *)keyForPassword:(NSString *)password salt:(NSData *)salt logRounds:(int)logrounds; 17 | 18 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length key:(NSData *)keydata IV:(NSData *)ivdata; 19 | 20 | -(void)resetBlockStream; 21 | -(int)produceBlockAtOffset:(off_t)pos; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /XADMaster/XAD7ZipBCJ2Handle.h: -------------------------------------------------------------------------------- 1 | #import "CSByteStreamHandle.h" 2 | 3 | @interface XAD7ZipBCJ2Handle:CSByteStreamHandle 4 | { 5 | CSHandle *calls,*jumps,*ranges; 6 | off_t callstart,jumpstart,rangestart; 7 | 8 | uint16_t probabilities[258]; 9 | uint32_t range,code; 10 | 11 | int prevbyte; 12 | uint32_t val; 13 | int valbyte; 14 | } 15 | 16 | -(id)initWithHandle:(CSHandle *)handle callHandle:(CSHandle *)callhandle 17 | jumpHandle:(CSHandle *)jumphandle rangeHandle:(CSHandle *)rangehandle length:(off_t)length; 18 | -(void)dealloc; 19 | -(void)resetByteStream; 20 | -(uint8_t)produceByteAtOffset:(off_t)pos; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /XADMaster/XAD7ZipBranchHandles.h: -------------------------------------------------------------------------------- 1 | #import "CSBlockStreamHandle.h" 2 | 3 | @interface XAD7ZipBranchHandle:CSBlockStreamHandle 4 | { 5 | off_t startoffs; 6 | uint8_t inbuffer[4096]; 7 | int leftoverstart,leftoverlength; 8 | uint32_t baseoffset; 9 | } 10 | 11 | -(id)initWithHandle:(CSHandle *)handle; 12 | -(id)initWithHandle:(CSHandle *)handle propertyData:(NSData *)propertydata; 13 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 14 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length propertyData:(NSData *)propertydata; 15 | 16 | -(void)resetBlockStream; 17 | -(int)produceBlockAtOffset:(off_t)pos; 18 | 19 | -(int)decodeBlock:(uint8_t *)block length:(int)length offset:(off_t)pos; 20 | 21 | @end 22 | 23 | @interface XAD7ZipBCJHandle:XAD7ZipBranchHandle { uint32_t state; } 24 | @end 25 | 26 | @interface XAD7ZipPPCHandle:XAD7ZipBranchHandle {} 27 | @end 28 | 29 | @interface XAD7ZipIA64Handle:XAD7ZipBranchHandle {} 30 | @end 31 | 32 | @interface XAD7ZipARMHandle:XAD7ZipBranchHandle {} 33 | @end 34 | 35 | @interface XAD7ZipThumbHandle:XAD7ZipBranchHandle {} 36 | @end 37 | 38 | @interface XAD7ZipSPARCHandle:XAD7ZipBranchHandle {} 39 | @end 40 | -------------------------------------------------------------------------------- /XADMaster/XADALZipParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADALZipParser:XADArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 9 | +(NSArray *)volumesForHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 10 | 11 | -(void)parse; 12 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 13 | -(NSString *)formatName; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /XADMaster/XADARCCrunchHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSByteStreamHandle.h" 2 | 3 | typedef struct XADARCCrunchEntry 4 | { 5 | BOOL used; 6 | uint8_t byte; 7 | int next; 8 | int parent; 9 | } XADARCCrunchEntry; 10 | 11 | @interface XADARCCrunchHandle:CSByteStreamHandle 12 | { 13 | BOOL fast; 14 | 15 | int numfreecodes,sp,lastcode; 16 | uint8_t lastbyte; 17 | 18 | XADARCCrunchEntry table[4096]; 19 | uint8_t stack[4096]; 20 | } 21 | 22 | -(id)initWithHandle:(CSHandle *)handle useFastHash:(BOOL)usefast; 23 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length useFastHash:(BOOL)usefast; 24 | 25 | -(void)resetByteStream; 26 | -(uint8_t)produceByteAtOffset:(off_t)pos; 27 | -(void)updateTableWithParent:(int)parentcode byteValue:(int)byte; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /XADMaster/XADARCCrushHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSByteStreamHandle.h" 2 | #import "LZW.h" 3 | 4 | @interface XADARCCrushHandle:CSByteStreamHandle 5 | { 6 | LZW *lzw; 7 | int symbolsize,nextsizebump; 8 | BOOL useliteralbit; 9 | 10 | int numrecentstrings,ringindex; 11 | BOOL stringring[500]; 12 | 13 | int usageindex; 14 | 15 | int currbyte; 16 | uint8_t buffer[8192]; 17 | uint8_t usage[8192]; 18 | } 19 | 20 | -(id)initWithHandle:(CSHandle *)handle; 21 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 22 | -(void)dealloc; 23 | 24 | -(void)resetByteStream; 25 | -(uint8_t)produceByteAtOffset:(off_t)pos; 26 | 27 | @end 28 | 29 | -------------------------------------------------------------------------------- /XADMaster/XADARCDistillHandle.h: -------------------------------------------------------------------------------- 1 | #import "XADFastLZSSHandle.h" 2 | #import "XADPrefixCode.h" 3 | 4 | @interface XADARCDistillHandle:XADFastLZSSHandle 5 | { 6 | XADPrefixCode *maincode,*offsetcode; 7 | } 8 | 9 | -(id)initWithHandle:(CSHandle *)handle; 10 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 11 | -(void)dealloc; 12 | 13 | -(void)resetLZSSHandle; 14 | -(void)expandFromPosition:(off_t)pos; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /XADMaster/XADARCParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADARCParser:XADArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data 9 | name:(NSString *)name; 10 | 11 | -(void)parse; 12 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 13 | -(NSString *)formatName; 14 | 15 | @end 16 | 17 | 18 | @interface XADARCSFXParser:XADARCParser 19 | { 20 | } 21 | 22 | +(int)requiredHeaderSize; 23 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data 24 | name:(NSString *)name propertiesToAdd:(NSMutableDictionary *)props; 25 | 26 | -(void)parse; 27 | -(NSString *)formatName; 28 | 29 | @end 30 | 31 | -------------------------------------------------------------------------------- /XADMaster/XADARJFastestHandle.h: -------------------------------------------------------------------------------- 1 | #import "XADLZSSHandle.h" 2 | 3 | @interface XADARJFastestHandle:XADLZSSHandle 4 | { 5 | } 6 | 7 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 8 | -(void)resetLZSSHandle; 9 | -(int)nextLiteralOrOffset:(int *)offset andLength:(int *)length atPosition:(off_t)pos; 10 | 11 | @end 12 | -------------------------------------------------------------------------------- /XADMaster/XADARJParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADARJParser:XADArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 9 | 10 | -(void)parse; 11 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 12 | -(NSString *)formatName; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /XADMaster/XADAppleDouble.h: -------------------------------------------------------------------------------- 1 | #import "CSHandle.h" 2 | 3 | @interface XADAppleDouble:NSObject 4 | { 5 | } 6 | 7 | +(BOOL)parseAppleDoubleWithHandle:(CSHandle *)fh resourceForkOffset:(off_t *)resourceoffsetptr 8 | resourceForkLength:(off_t *)resourcelengthptr extendedAttributes:(NSDictionary **)extattrsptr; 9 | +(void)parseAppleDoubleExtendedAttributesWithHandle:(CSHandle *)fh intoDictionary:(NSMutableDictionary *)extattrs; 10 | 11 | +(void)writeAppleDoubleHeaderToHandle:(CSHandle *)fh resourceForkSize:(int)ressize 12 | extendedAttributes:(NSDictionary *)extattrs; 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /XADMaster/XADAppleSingleParser.h: -------------------------------------------------------------------------------- 1 | #import "XADMacArchiveParser.h" 2 | 3 | @interface XADAppleSingleParser:XADArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 9 | 10 | -(void)parse; 11 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 12 | -(NSString *)formatName; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /XADMaster/XADArParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADArParser:XADArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 9 | 10 | -(void)parse; 11 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 12 | -(NSString *)formatName; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /XADMaster/XADArchiveParserDescriptions.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADArchiveParser (Descriptions) 4 | 5 | -(NSString *)descriptionOfValueInDictionary:(NSDictionary *)dict key:(NSString *)key; 6 | -(NSString *)descriptionOfKey:(NSString *)key; 7 | -(NSArray *)descriptiveOrderingOfKeysInDictionary:(NSDictionary *)dict; 8 | 9 | @end 10 | 11 | NSString *XADHumanReadableFileSize(uint64_t size); 12 | NSString *XADShortHumanReadableFileSize(uint64_t size); 13 | NSString *XADHumanReadableBoolean(uint64_t boolean); 14 | NSString *XADHumanReadablePOSIXPermissions(uint64_t permissions); 15 | NSString *XADHumanReadableAmigaProtectionBits(uint64_t protection); 16 | NSString *XADHumanReadableDOSFileAttributes(uint64_t attributes); 17 | NSString *XADHumanReadableWindowsFileAttributes(uint64_t attributes); 18 | NSString *XADHumanReadableOSType(uint64_t ostype); 19 | NSString *XADHumanReadableEntryWithDictionary(NSDictionary *dict,XADArchiveParser *parser); 20 | 21 | NSString *XADHumanReadableObject(id object); 22 | NSString *XADHumanReadableDate(NSDate *date); 23 | NSString *XADHumanReadableData(NSData *data); 24 | NSString *XADHumanReadableArray(NSArray *array); 25 | NSString *XADHumanReadableDictionary(NSDictionary *dict); 26 | NSString *XADHumanReadableList(NSArray *labels,NSArray *values); 27 | NSString *XADIndentTextWithSpaces(NSString *text,int spaces); 28 | -------------------------------------------------------------------------------- /XADMaster/XADBinHexParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | #import "CSByteStreamHandle.h" 3 | 4 | @interface XADBinHexParser:XADArchiveParser 5 | { 6 | } 7 | 8 | +(int)requiredHeaderSize; 9 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 10 | 11 | -(void)parse; 12 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 13 | -(NSString *)formatName; 14 | 15 | @end 16 | 17 | 18 | 19 | @interface XADBinHexHandle:CSByteStreamHandle 20 | { 21 | uint32_t bytes; 22 | uint8_t prev_bits; 23 | int rle_byte,rle_num; 24 | } 25 | 26 | -(id)initWithHandle:(CSHandle *)handle; 27 | 28 | -(void)resetByteStream; 29 | -(uint8_t)produceByteAtOffset:(off_t)pos; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /XADMaster/XADBlockHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSHandle.h" 2 | 3 | @interface XADBlockHandle:CSHandle 4 | { 5 | off_t currpos,length; 6 | 7 | int numblocks,blocksize; 8 | off_t *blockoffsets; 9 | } 10 | 11 | -(id)initWithHandle:(CSHandle *)handle blockSize:(int)size; 12 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)maxlength blockSize:(int)size; 13 | -(void)dealloc; 14 | 15 | //-(void)addBlockAt:(off_t)start; 16 | -(void)setBlockChain:(uint32_t *)blocktable numberOfBlocks:(int)totalblocks 17 | firstBlock:(uint32_t)first headerSize:(off_t)headersize; 18 | 19 | -(off_t)fileSize; 20 | -(off_t)offsetInFile; 21 | -(BOOL)atEndOfFile; 22 | 23 | -(void)seekToFileOffset:(off_t)offs; 24 | -(void)seekToEndOfFile; 25 | -(int)readAtMost:(int)num toBuffer:(void *)buffer; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /XADMaster/XADBzip2Parser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADBzip2Parser:XADArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 9 | 10 | -(void)parse; 11 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 12 | -(NSString *)formatName; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /XADMaster/XADCABBlockHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSBlockStreamHandle.h" 2 | #import "XADCABBlockReader.h" 3 | 4 | 5 | @interface XADCABBlockHandle:CSBlockStreamHandle 6 | { 7 | XADCABBlockReader *blocks; 8 | uint8_t inbuffer[32768+6144]; 9 | } 10 | 11 | -(id)initWithBlockReader:(XADCABBlockReader *)blockreader; 12 | -(void)dealloc; 13 | 14 | -(void)resetBlockStream; 15 | -(int)produceBlockAtOffset:(off_t)pos; 16 | 17 | -(void)resetCABBlockHandle; 18 | -(int)produceCABBlockWithInputBuffer:(uint8_t *)buffer length:(int)length atOffset:(off_t)pos length:(int)uncomplength; 19 | 20 | @end 21 | 22 | @interface XADCABCopyHandle:XADCABBlockHandle 23 | 24 | -(int)produceCABBlockWithInputBuffer:(uint8_t *)buffer length:(int)length atOffset:(off_t)pos length:(int)uncomplength; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /XADMaster/XADCABBlockHandle.m: -------------------------------------------------------------------------------- 1 | #import "XADCABBlockHandle.h" 2 | #import "XADException.h" 3 | 4 | @implementation XADCABBlockHandle 5 | 6 | -(id)initWithBlockReader:(XADCABBlockReader *)blockreader 7 | { 8 | if((self=[super initWithParentHandle:[blockreader handle] length:[blockreader uncompressedLength]])) 9 | { 10 | blocks=[blockreader retain]; 11 | } 12 | return self; 13 | } 14 | 15 | -(void)dealloc 16 | { 17 | [blocks release]; 18 | [super dealloc]; 19 | } 20 | 21 | -(void)resetBlockStream 22 | { 23 | [blocks restart]; 24 | [self resetCABBlockHandle]; 25 | } 26 | 27 | -(int)produceBlockAtOffset:(off_t)pos 28 | { 29 | int complen,uncomplen; 30 | if([blocks readNextBlockToBuffer:inbuffer compressedLength:&complen 31 | uncompressedLength:&uncomplen]) [self endBlockStream]; 32 | 33 | return [self produceCABBlockWithInputBuffer:inbuffer length:complen atOffset:pos length:uncomplen]; 34 | } 35 | 36 | -(void)resetCABBlockHandle {} 37 | 38 | -(int)produceCABBlockWithInputBuffer:(uint8_t *)buffer length:(int)length atOffset:(off_t)pos length:(int)uncomplength { return 0; } 39 | 40 | @end 41 | 42 | 43 | 44 | @implementation XADCABCopyHandle 45 | 46 | -(int)produceCABBlockWithInputBuffer:(uint8_t *)buffer length:(int)length atOffset:(off_t)pos length:(int)uncomplength 47 | { 48 | [self setBlockPointer:buffer]; 49 | return length; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /XADMaster/XADCABBlockReader.h: -------------------------------------------------------------------------------- 1 | #import "CSHandle.h" 2 | 3 | @interface XADCABBlockReader:NSObject 4 | { 5 | CSHandle *parent; 6 | int extbytes; 7 | 8 | int numfolders; 9 | off_t offsets[100]; 10 | int numblocks[100]; 11 | 12 | int currentfolder,currentblock; 13 | 14 | off_t complen,uncomplen; 15 | } 16 | 17 | -(id)initWithHandle:(CSHandle *)handle reservedBytes:(int)reserved; 18 | -(void)dealloc; 19 | 20 | -(void)addFolderAtOffset:(off_t)startoffs numberOfBlocks:(int)numblocks; 21 | -(void)scanLengths; 22 | 23 | -(CSHandle *)handle; 24 | -(off_t)compressedLength; 25 | -(off_t)uncompressedLength; 26 | 27 | -(void)restart; 28 | -(BOOL)readNextBlockToBuffer:(uint8_t *)buffer compressedLength:(int *)compptr 29 | uncompressedLength:(int *)uncompptr; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /XADMaster/XADCABParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADCABParser:XADArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 9 | +(NSArray *)volumesForHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 10 | 11 | -(void)parse; 12 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 13 | -(CSHandle *)handleForSolidStreamWithObject:(id)obj wantChecksum:(BOOL)checksum; 14 | -(NSString *)formatName; 15 | 16 | @end 17 | 18 | @interface XADCABSFXParser:XADCABParser 19 | { 20 | } 21 | 22 | +(int)requiredHeaderSize; 23 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data 24 | name:(NSString *)name propertiesToAdd:(NSMutableDictionary *)props; 25 | +(NSArray *)volumesForHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 26 | 27 | -(void)parse; 28 | -(NSString *)formatName; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /XADMaster/XADCFBFParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADCFBFParser:XADArchiveParser 4 | { 5 | int minsize,secsize,minisecsize; 6 | 7 | uint32_t rootdirectorynode,firstminisector; 8 | 9 | int numsectors,numminisectors; 10 | uint32_t *sectable,*minisectable; 11 | } 12 | 13 | +(int)requiredHeaderSize; 14 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 15 | 16 | -(void)parse; 17 | -(XADString *)decodeFileNameWithBytes:(uint8_t *)bytes length:(int)length; 18 | -(void)processEntry:(uint32_t)n atPath:(XADPath *)path entries:(NSArray *)entries; 19 | -(void)seekToSector:(uint32_t)sector; 20 | -(uint32_t)nextSectorAfter:(uint32_t)sector; 21 | 22 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 23 | -(NSString *)formatName; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /XADMaster/XADCRCHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSStreamHandle.h" 2 | #import "Checksums.h" 3 | #import "Progress.h" 4 | #import "CRC.h" 5 | 6 | typedef uint32_t XADCRCTransformationFunction(uint32_t crc,id context); 7 | 8 | @interface XADCRCHandle:CSStreamHandle 9 | { 10 | uint32_t crc,initcrc,compcrc; 11 | const uint32_t *table; 12 | XADCRCTransformationFunction *transformationfunction; 13 | id transformationcontext; 14 | } 15 | 16 | +(XADCRCHandle *)IEEECRC32HandleWithHandle:(CSHandle *)handle 17 | correctCRC:(uint32_t)correctcrc conditioned:(BOOL)conditioned; 18 | +(XADCRCHandle *)IEEECRC32HandleWithHandle:(CSHandle *)handle length:(off_t)length 19 | correctCRC:(uint32_t)correctcrc conditioned:(BOOL)conditioned; 20 | +(XADCRCHandle *)IBMCRC16HandleWithHandle:(CSHandle *)handle length:(off_t)length 21 | correctCRC:(uint32_t)correctcrc conditioned:(BOOL)conditioned; 22 | +(XADCRCHandle *)CCITTCRC16HandleWithHandle:(CSHandle *)handle length:(off_t)length 23 | correctCRC:(uint32_t)correctcrc conditioned:(BOOL)conditioned; 24 | 25 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length initialCRC:(uint32_t)initialcrc 26 | correctCRC:(uint32_t)correctcrc CRCTable:(const uint32_t *)crctable; 27 | -(void)dealloc; 28 | 29 | -(void)setCRCTransformationFunction:(XADCRCTransformationFunction *)function context:(id)context; 30 | 31 | -(void)resetStream; 32 | -(int)streamAtMost:(int)num toBuffer:(void *)buffer; 33 | 34 | -(BOOL)hasChecksum; 35 | -(BOOL)isChecksumCorrect; 36 | 37 | @end 38 | 39 | 40 | -------------------------------------------------------------------------------- /XADMaster/XADCRCSuffixHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSStreamHandle.h" 2 | #import "Checksums.h" 3 | #import "Progress.h" 4 | #import "CRC.h" 5 | 6 | @interface XADCRCSuffixHandle:CSStreamHandle 7 | { 8 | CSHandle *crcparent; 9 | 10 | int crcsize; 11 | BOOL bigend; 12 | uint32_t crc,initcrc,compcrc; 13 | const uint32_t *table; 14 | 15 | BOOL didtest,wascorrect; 16 | } 17 | 18 | +(XADCRCSuffixHandle *)IEEECRC32SuffixHandleWithHandle:(CSHandle *)handle CRCHandle:(CSHandle *)crchandle 19 | bigEndianCRC:(BOOL)bigendian conditioned:(BOOL)conditioned; 20 | +(XADCRCSuffixHandle *)CCITTCRC16SuffixHandleWithHandle:(CSHandle *)handle CRCHandle:(CSHandle *)crchandle 21 | bigEndianCRC:(BOOL)bigendian conditioned:(BOOL)conditioned; 22 | 23 | -(id)initWithHandle:(CSHandle *)handle CRCHandle:(CSHandle *)crchandle initialCRC:(uint32_t)initialcrc 24 | CRCSize:(int)crcbytes bigEndianCRC:(BOOL)bigendian CRCTable:(const uint32_t *)crctable; 25 | -(void)dealloc; 26 | 27 | -(void)resetStream; 28 | -(int)streamAtMost:(int)num toBuffer:(void *)buffer; 29 | 30 | -(BOOL)hasChecksum; 31 | -(BOOL)isChecksumCorrect; 32 | 33 | @end 34 | 35 | -------------------------------------------------------------------------------- /XADMaster/XADChecksumHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSStreamHandle.h" 2 | #import "Checksums.h" 3 | #import "Progress.h" 4 | 5 | @interface XADChecksumHandle:CSStreamHandle 6 | { 7 | uint32_t correctchecksum,summask,checksum; 8 | } 9 | 10 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length correctChecksum:(int)correct mask:(int)mask; 11 | 12 | -(void)resetStream; 13 | -(int)streamAtMost:(int)num toBuffer:(void *)buffer; 14 | 15 | -(BOOL)hasChecksum; 16 | -(BOOL)isChecksumCorrect; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /XADMaster/XADChecksumHandle.m: -------------------------------------------------------------------------------- 1 | #import "XADChecksumHandle.h" 2 | 3 | @implementation XADChecksumHandle 4 | 5 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length correctChecksum:(int)correct mask:(int)mask 6 | { 7 | if((self=[super initWithParentHandle:handle length:length])) 8 | { 9 | correctchecksum=correct; 10 | summask=mask; 11 | } 12 | return self; 13 | } 14 | 15 | -(void)resetStream 16 | { 17 | [parent seekToFileOffset:0]; 18 | checksum=0; 19 | } 20 | 21 | -(int)streamAtMost:(int)num toBuffer:(void *)buffer 22 | { 23 | int actual=[parent readAtMost:num toBuffer:buffer]; 24 | 25 | uint8_t *bytes=buffer; 26 | for(int i=0;i=bufferend) 37 | { 38 | int symbol; 39 | for(;;) 40 | { 41 | if(CSInputAtEOF(input)) CSByteStreamEOF(self); 42 | 43 | symbol=CSInputNextBitStringLE(input,LZWSuggestedSymbolSize(lzw)); 44 | symbolcounter++; 45 | if(symbol==256&&blockmode) 46 | { 47 | // Skip garbage data after a clear. God damn, this is dumb. 48 | int symbolsize=LZWSuggestedSymbolSize(lzw); 49 | if(symbolcounter%8) CSInputSkipBitsLE(input,symbolsize*(8-symbolcounter%8)); 50 | ClearLZWTable(lzw); 51 | symbolcounter=0; 52 | } 53 | else break; 54 | } 55 | 56 | if(NextLZWSymbol(lzw,symbol)==LZWInvalidCodeError) [XADException raiseDecrunchException]; 57 | 58 | int n=LZWOutputToInternalBuffer(lzw); 59 | buffer=LZWInternalBuffer(lzw); 60 | bufferend=buffer+n; 61 | } 62 | 63 | return *buffer++; 64 | } 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /XADMaster/XADCompressParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADCompressParser:XADArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 9 | 10 | -(void)parse; 11 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 12 | -(NSString *)formatName; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /XADMaster/XADCompressParser.m: -------------------------------------------------------------------------------- 1 | #import "XADCompressParser.h" 2 | #import "XADCompressHandle.h" 3 | 4 | 5 | @implementation XADCompressParser 6 | 7 | +(int)requiredHeaderSize { return 3; } 8 | 9 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name 10 | { 11 | int length=[data length]; 12 | const uint8_t *bytes=[data bytes]; 13 | 14 | return length>=3&&bytes[0]==0x1f&&bytes[1]==0x9d; 15 | } 16 | 17 | -(void)parse 18 | { 19 | CSHandle *fh=[self handle]; 20 | 21 | [fh skipBytes:2]; 22 | int flags=[fh readUInt8]; 23 | 24 | NSString *contentname=[[self name] stringByDeletingPathExtension]; 25 | 26 | NSMutableDictionary *dict=[NSMutableDictionary dictionaryWithObjectsAndKeys: 27 | [self XADPathWithUnseparatedString:contentname],XADFileNameKey, 28 | [self XADStringWithString:@"Compress"],XADCompressionNameKey, 29 | [NSNumber numberWithLongLong:3],XADDataOffsetKey, 30 | [NSNumber numberWithInt:flags],@"CompressFlags", 31 | nil]; 32 | 33 | if([contentname matchedByPattern:@"\\.(tar|cpio|pax)$" options:REG_ICASE]) 34 | [dict setObject:[NSNumber numberWithBool:YES] forKey:XADIsArchiveKey]; 35 | 36 | off_t size=[[self handle] fileSize]; 37 | if(size!=CSHandleMaxLength) 38 | [dict setObject:[NSNumber numberWithLongLong:size-3] forKey:XADCompressedSizeKey]; 39 | 40 | [self addEntryWithDictionary:dict]; 41 | } 42 | 43 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum 44 | { 45 | return [[[XADCompressHandle alloc] initWithHandle:[self handleAtDataOffsetForDictionary:dict] 46 | flags:[[dict objectForKey:@"CompressFlags"] intValue]] autorelease]; 47 | } 48 | 49 | -(NSString *)formatName { return @"Compress"; } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /XADMaster/XADCpioParser.h: -------------------------------------------------------------------------------- 1 | #import "XADMacArchiveParser.h" 2 | 3 | @interface XADCpioParser:XADMacArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 9 | 10 | -(void)parseWithSeparateMacForks; 11 | -(CSHandle *)rawHandleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 12 | -(NSString *)formatName; 13 | 14 | @end 15 | 16 | 17 | -------------------------------------------------------------------------------- /XADMaster/XADCrunchHandles.h: -------------------------------------------------------------------------------- 1 | #import "XADLibXADIOHandle.h" 2 | 3 | // Implementation using the old xadIO code from libxad, emulated through XADLibXADIOHandle 4 | // TODO: Re-implement these as cleaner code. Problem: no test cases. 5 | 6 | @interface XADCrunchZHandle:XADLibXADIOHandle 7 | { 8 | BOOL oldversion,haschecksum,checksumcorrect; 9 | } 10 | 11 | -(id)initWithHandle:(CSHandle *)handle old:(BOOL)old hasChecksum:(BOOL)checksum; 12 | -(xadINT32)unpackData; 13 | 14 | @end 15 | 16 | @interface XADCrunchYHandle:XADLibXADIOHandle 17 | { 18 | BOOL oldversion,haschecksum,checksumcorrect; 19 | } 20 | 21 | -(id)initWithHandle:(CSHandle *)handle old:(BOOL)old hasChecksum:(BOOL)checksum; 22 | -(xadINT32)unpackData; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /XADMaster/XADCrunchParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADCrunchParser:XADArchiveParser 4 | { 5 | } 6 | 7 | +(NSMutableDictionary *)parseWithHandle:(CSHandle *)fh endOffset:(off_t)end parser:(XADArchiveParser *)parser; 8 | +(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum handle:(CSHandle *)handle; 9 | 10 | +(int)requiredHeaderSize; 11 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 12 | 13 | -(void)parse; 14 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 15 | -(NSString *)formatName; 16 | 17 | @end 18 | 19 | -------------------------------------------------------------------------------- /XADMaster/XADDeflateHandle.h: -------------------------------------------------------------------------------- 1 | #import "XADLZSSHandle.h" 2 | #import "XADPrefixCode.h" 3 | 4 | #define XADNormalDeflateVariant 0 5 | #define XADDeflate64DeflateVariant 1 6 | #define XADStuffItXDeflateVariant 2 7 | #define XADNSISDeflateVariant 3 8 | 9 | @interface XADDeflateHandle:XADLZSSHandle 10 | { 11 | int variant; 12 | 13 | XADPrefixCode *literalcode,*distancecode; 14 | XADPrefixCode *fixedliteralcode,*fixeddistancecode; 15 | BOOL storedblock,lastblock; 16 | int storedcount; 17 | 18 | int order[19]; 19 | } 20 | 21 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 22 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length variant:(int)deflatevariant; 23 | -(void)dealloc; 24 | 25 | -(void)setMetaTableOrder:(const int *)order; 26 | 27 | -(void)resetLZSSHandle; 28 | -(int)nextLiteralOrOffset:(int *)offset andLength:(int *)length atPosition:(off_t)pos; 29 | 30 | -(void)readBlockHeader; 31 | -(XADPrefixCode *)allocAndParseMetaCodeOfSize:(int)size; 32 | -(XADPrefixCode *)fixedLiteralCode; 33 | -(XADPrefixCode *)fixedDistanceCode; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /XADMaster/XADDeltaHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSByteStreamHandle.h" 2 | 3 | @interface XADDeltaHandle:CSByteStreamHandle 4 | { 5 | uint8_t deltabuffer[256]; 6 | int distance; 7 | } 8 | 9 | -(id)initWithHandle:(CSHandle *)handle; 10 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 11 | -(id)initWithHandle:(CSHandle *)handle deltaDistance:(int)deltadistance; 12 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length deltaDistance:(int)deltadistance; 13 | -(id)initWithHandle:(CSHandle *)handle propertyData:(NSData *)propertydata; 14 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length propertyData:(NSData *)propertydata; 15 | 16 | -(void)resetByteStream; 17 | -(uint8_t)produceByteAtOffset:(off_t)pos; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /XADMaster/XADDeltaHandle.m: -------------------------------------------------------------------------------- 1 | #import "XADDeltaHandle.h" 2 | 3 | @implementation XADDeltaHandle 4 | 5 | -(id)initWithHandle:(CSHandle *)handle 6 | { 7 | return [self initWithHandle:handle length:CSHandleMaxLength deltaDistance:1]; 8 | } 9 | 10 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length 11 | { 12 | return [self initWithHandle:handle length:length deltaDistance:1]; 13 | } 14 | 15 | -(id)initWithHandle:(CSHandle *)handle deltaDistance:(int)deltadistance 16 | { 17 | return [self initWithHandle:handle length:CSHandleMaxLength deltaDistance:deltadistance]; 18 | } 19 | 20 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length deltaDistance:(int)deltadistance 21 | { 22 | if((self=[super initWithInputBufferForHandle:handle length:length])) 23 | { 24 | distance=deltadistance; 25 | } 26 | return self; 27 | } 28 | 29 | -(id)initWithHandle:(CSHandle *)handle propertyData:(NSData *)propertydata 30 | { 31 | return [self initWithHandle:handle length:CSHandleMaxLength propertyData:propertydata]; 32 | } 33 | 34 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length propertyData:(NSData *)propertydata 35 | { 36 | int deltadistance=1; 37 | 38 | if(propertydata&&[propertydata length]>=1) 39 | deltadistance=((uint8_t *)[propertydata bytes])[0]+1; 40 | 41 | return [self initWithHandle:handle length:length deltaDistance:deltadistance]; 42 | } 43 | 44 | -(void)resetByteStream 45 | { 46 | memset(deltabuffer,0,sizeof(deltabuffer)); 47 | } 48 | 49 | -(uint8_t)produceByteAtOffset:(off_t)pos 50 | { 51 | if(CSInputAtEOF(input)) CSByteStreamEOF(self); 52 | 53 | uint8_t b=CSInputNextByte(input); 54 | uint8_t old=deltabuffer[(pos-distance+0x100)&0xff]; 55 | uint8_t new=b+old; 56 | 57 | deltabuffer[pos&0xff]=new; 58 | return new; 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /XADMaster/XADDiskDoublerADnHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSBlockStreamHandle.h" 2 | 3 | @interface XADDiskDoublerADnHandle:CSBlockStreamHandle 4 | { 5 | uint8_t outbuffer[8192]; 6 | } 7 | 8 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 9 | 10 | -(int)produceBlockAtOffset:(off_t)pos; 11 | 12 | @end 13 | -------------------------------------------------------------------------------- /XADMaster/XADDiskDoublerDDnHandle.h: -------------------------------------------------------------------------------- 1 | #import "XADLZSSHandle.h" 2 | #import "XADPrefixCode.h" 3 | 4 | @interface XADDiskDoublerDDnHandle:XADLZSSHandle 5 | { 6 | int blocksize; 7 | off_t blockend; 8 | int literalsleft; 9 | 10 | int correctxor; 11 | 12 | XADPrefixCode *lengthcode; 13 | 14 | uint8_t buffer[0x10000]; 15 | uint8_t *literalptr; 16 | uint16_t *offsetptr; 17 | off_t nextblock; 18 | 19 | BOOL checksumcorrect,uncompressed; 20 | } 21 | 22 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 23 | -(void)dealloc; 24 | 25 | -(void)resetLZSSHandle; 26 | -(int)nextLiteralOrOffset:(int *)offsetptr andLength:(int *)lengthptr atPosition:(off_t)pos; 27 | -(void)readBlockAtPosition:(off_t)pos; 28 | -(XADPrefixCode *)readCode; 29 | 30 | -(BOOL)hasChecksum; 31 | -(BOOL)isChecksumCorrect; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /XADMaster/XADDiskDoublerMethod2Handle.h: -------------------------------------------------------------------------------- 1 | #import "CSByteStreamHandle.h" 2 | 3 | @interface XADDiskDoublerMethod2Handle:CSByteStreamHandle 4 | { 5 | int numtrees,currtree; 6 | 7 | struct 8 | { 9 | uint8_t parents[512]; 10 | uint16_t leftchildren[256]; 11 | uint16_t rightchildren[256]; 12 | } trees[256]; 13 | } 14 | 15 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length numberOfTrees:(int)num; 16 | 17 | -(void)resetByteStream; 18 | -(uint8_t)produceByteAtOffset:(off_t)pos; 19 | 20 | -(void)updateStateForByte:(int)byte; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /XADMaster/XADDiskDoublerParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADDiskDoublerParser:XADArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 9 | 10 | -(void)parse; 11 | -(void)parseArchive; 12 | -(void)parseArchive2; 13 | -(uint32_t)parseFileHeaderWithHandle:(CSHandle *)fh name:(XADPath *)name; 14 | 15 | -(NSString *)nameForMethod:(int)method; 16 | 17 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 18 | -(NSString *)formatName; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /XADMaster/XADGzipParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | #import "CSStreamHandle.h" 3 | 4 | @interface XADGzipParser:XADArchiveParser 5 | { 6 | } 7 | 8 | +(int)requiredHeaderSize; 9 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 10 | 11 | -(void)parse; 12 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 13 | -(NSString *)formatName; 14 | 15 | @end 16 | 17 | @interface XADGzipSFXParser:XADGzipParser 18 | { 19 | } 20 | 21 | +(int)requiredHeaderSize; 22 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data 23 | name:(NSString *)name propertiesToAdd:(NSMutableDictionary *)props; 24 | 25 | -(void)parse; 26 | -(NSString *)formatName; 27 | 28 | @end 29 | 30 | @interface XADGzipHandle:CSStreamHandle 31 | { 32 | CSHandle *currhandle; 33 | off_t startoffs; 34 | int state; 35 | BOOL checksumscorrect; 36 | uint32_t crc; 37 | } 38 | 39 | -(id)initWithHandle:(CSHandle *)handle; 40 | -(void)dealloc; 41 | -(void)resetStream; 42 | -(int)streamAtMost:(int)num toBuffer:(void *)buffer; 43 | -(BOOL)hasChecksum; 44 | -(BOOL)isChecksumCorrect; 45 | -(double)estimatedProgress; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /XADMaster/XADISO9660Parser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADISO9660Parser:XADArchiveParser 4 | { 5 | int blocksize; 6 | BOOL isjoliet,ishighsierra; 7 | CSHandle *fh; 8 | } 9 | 10 | +(int)requiredHeaderSize; 11 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data 12 | name:(NSString *)name propertiesToAdd:(NSMutableDictionary *)props; 13 | 14 | -(id)init; 15 | -(void)dealloc; 16 | 17 | -(void)parse; 18 | -(void)parseVolumeDescriptorAtBlock:(uint32_t)block; 19 | -(void)parseDirectoryWithPath:(XADPath *)path atBlock:(uint32_t)block length:(uint32_t)length; 20 | 21 | -(XADString *)readStringOfLength:(int)length; 22 | -(NSDate *)readLongDateAndTime; 23 | -(NSDate *)readShortDateAndTime; 24 | -(NSDate *)parseDateAndTimeWithBytes:(const uint8_t *)buffer long:(BOOL)islong; 25 | -(NSDate *)parseLongDateAndTimeWithBytes:(const uint8_t *)buffer; 26 | -(NSDate *)parseShortDateAndTimeWithBytes:(const uint8_t *)buffer; 27 | 28 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 29 | -(NSString *)formatName; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /XADMaster/XADLArcHandles.h: -------------------------------------------------------------------------------- 1 | #import "XADLZSSHandle.h" 2 | 3 | @interface XADLArcLZSHandle:XADLZSSHandle 4 | { 5 | } 6 | 7 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 8 | -(int)nextLiteralOrOffset:(int *)offset andLength:(int *)length atPosition:(off_t)pos; 9 | 10 | @end 11 | 12 | @interface XADLArcLZ5Handle:XADLZSSHandle 13 | { 14 | int flags,flagbit; 15 | } 16 | 17 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 18 | -(void)resetLZSSHandle; 19 | -(int)nextLiteralOrOffset:(int *)offset andLength:(int *)length atPosition:(off_t)pos; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /XADMaster/XADLArcHandles.m: -------------------------------------------------------------------------------- 1 | #import "XADLArcHandles.h" 2 | 3 | @implementation XADLArcLZSHandle 4 | 5 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length 6 | { 7 | return [super initWithInputBufferForHandle:handle length:length windowSize:2048]; 8 | } 9 | 10 | -(int)nextLiteralOrOffset:(int *)offset andLength:(int *)length atPosition:(off_t)pos 11 | { 12 | if(CSInputNextBit(input)) return CSInputNextBitString(input,8); 13 | else 14 | { 15 | *offset=(int)pos-CSInputNextBitString(input,11)-17; 16 | *length=CSInputNextBitString(input,4)+2; // TODO: 3 or 2? 17 | 18 | return XADLZSSMatch; 19 | } 20 | } 21 | 22 | @end 23 | 24 | @implementation XADLArcLZ5Handle 25 | 26 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length 27 | { 28 | return [super initWithInputBufferForHandle:handle length:length windowSize:4096]; 29 | } 30 | 31 | -(void)resetLZSSHandle 32 | { 33 | flagbit=7; 34 | 35 | for(int i=0;i<256;i++) memset(&windowbuffer[i*13+18],i,13); 36 | for(int i=0;i<256;i++) windowbuffer[256*13+18+i]=i; 37 | for(int i=0;i<256;i++) windowbuffer[256*13+256+18+i]=255-i; 38 | memset(&windowbuffer[256*13+512+18],0,128); 39 | memset(&windowbuffer[256*13+512+128+18],' ',128-18); 40 | } 41 | 42 | -(int)nextLiteralOrOffset:(int *)offset andLength:(int *)length atPosition:(off_t)pos 43 | { 44 | flagbit++; 45 | if(flagbit>7) 46 | { 47 | flagbit=0; 48 | flags=CSInputNextByte(input); 49 | } 50 | 51 | int byte=CSInputNextByte(input); 52 | 53 | if(flags&(1<windowbuffer[absolutepos&self->windowmask]; 30 | } 31 | -------------------------------------------------------------------------------- /XADMaster/XADLZXHandle.h: -------------------------------------------------------------------------------- 1 | #import "XADLZSSHandle.h" 2 | #import "XADPrefixCode.h" 3 | 4 | @interface XADLZXHandle:XADLZSSHandle 5 | { 6 | XADPrefixCode *maincode,*offsetcode; 7 | 8 | int blocktype,lastoffs; 9 | off_t blockend; 10 | int mainlengths[768]; 11 | } 12 | 13 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 14 | -(void)dealloc; 15 | 16 | -(void)resetLZSSHandle; 17 | -(int)nextLiteralOrOffset:(int *)offset andLength:(int *)length atPosition:(off_t)pos; 18 | 19 | -(void)readBlockHeaderAtPosition:(off_t)pos; 20 | -(void)readDeltaLengths:(int *)lengths count:(int)count alternateMode:(BOOL)altmode; 21 | 22 | @end 23 | 24 | 25 | @interface XADLZXSwapHandle:CSByteStreamHandle 26 | { 27 | uint8_t otherbyte; 28 | } 29 | 30 | -(id)initWithHandle:(CSHandle *)handle; 31 | 32 | -(uint8_t)produceByteAtOffset:(off_t)pos; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /XADMaster/XADLZXParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADLZXParser:XADArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 9 | 10 | -(void)parse; 11 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 12 | -(CSHandle *)handleForSolidStreamWithObject:(id)obj wantChecksum:(BOOL)checksum; 13 | -(NSString *)formatName; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /XADMaster/XADLibXADParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | #import "CSMemoryHandle.h" 3 | #import "libxad/include/functions.h" 4 | 5 | @interface XADLibXADParser:XADArchiveParser 6 | { 7 | // XADArchivePipe *pipe; 8 | // XADError lasterror; 9 | 10 | struct xadArchiveInfoP *archive; 11 | struct Hook inhook,progresshook; 12 | 13 | struct XADInHookData 14 | { 15 | CSHandle *fh; 16 | const char *name; 17 | } indata; 18 | 19 | BOOL addonbuild; 20 | int numfilesadded,numdisksadded; 21 | 22 | NSMutableData *namedata; 23 | } 24 | 25 | +(int)requiredHeaderSize; 26 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data 27 | name:(NSString *)name propertiesToAdd:(NSMutableDictionary *)props; 28 | 29 | -(id)init; 30 | -(void)dealloc; 31 | 32 | -(void)parse; 33 | -(BOOL)newEntryCallback:(struct xadProgressInfo *)proginfo; 34 | -(NSMutableDictionary *)dictionaryForFileInfo:(struct xadFileInfo *)info; 35 | -(NSMutableDictionary *)dictionaryForDiskInfo:(struct xadDiskInfo *)info; 36 | 37 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 38 | 39 | -(NSString *)formatName; 40 | 41 | @end 42 | 43 | 44 | 45 | @interface XADLibXADMemoryHandle:CSMemoryHandle 46 | { 47 | BOOL success; 48 | } 49 | 50 | -(id)initWithData:(NSData *)data successfullyExtracted:(BOOL)wassuccess; 51 | -(BOOL)hasChecksum; 52 | -(BOOL)isChecksumCorrect; 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /XADMaster/XADMD5Handle.h: -------------------------------------------------------------------------------- 1 | #import "CSStreamHandle.h" 2 | #import "Checksums.h" 3 | #import "Progress.h" 4 | 5 | #include "Crypto/md5.h" 6 | 7 | @interface XADMD5Handle:CSStreamHandle 8 | { 9 | NSData *digest; 10 | 11 | MD5_CTX context; 12 | } 13 | 14 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length correctDigest:(NSData *)correctdigest; 15 | -(void)dealloc; 16 | 17 | -(void)resetStream; 18 | -(int)streamAtMost:(int)num toBuffer:(void *)buffer; 19 | 20 | -(BOOL)hasChecksum; 21 | -(BOOL)isChecksumCorrect; 22 | 23 | -(double)estimatedProgress; 24 | 25 | @end 26 | 27 | -------------------------------------------------------------------------------- /XADMaster/XADMD5Handle.m: -------------------------------------------------------------------------------- 1 | #import "XADMD5Handle.h" 2 | 3 | @implementation XADMD5Handle 4 | 5 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length correctDigest:(NSData *)correctdigest; 6 | { 7 | if((self=[super initWithParentHandle:handle length:length])) 8 | { 9 | digest=[correctdigest retain]; 10 | } 11 | return self; 12 | } 13 | 14 | -(void)dealloc 15 | { 16 | [digest release]; 17 | [super dealloc]; 18 | } 19 | 20 | -(void)resetStream 21 | { 22 | MD5_Init(&context); 23 | [parent seekToFileOffset:0]; 24 | } 25 | 26 | -(int)streamAtMost:(int)num toBuffer:(void *)buffer 27 | { 28 | int actual=[parent readAtMost:num toBuffer:buffer]; 29 | MD5_Update(&context,buffer,actual); 30 | return actual; 31 | } 32 | 33 | -(BOOL)hasChecksum { return YES; } 34 | 35 | -(BOOL)isChecksumCorrect 36 | { 37 | if([digest length]!=16) return NO; 38 | 39 | MD5_CTX copy; 40 | copy=context; 41 | 42 | uint8_t buf[16]; 43 | MD5_Final(buf,©); 44 | 45 | return memcmp([digest bytes],buf,16)==0; 46 | } 47 | 48 | -(double)estimatedProgress { return [parent estimatedProgress]; } 49 | 50 | @end 51 | 52 | 53 | -------------------------------------------------------------------------------- /XADMaster/XADMSLZXHandle.h: -------------------------------------------------------------------------------- 1 | #import "XADCABBlockHandle.h" 2 | #import "XADPrefixCode.h" 3 | #import "LZSS.h" 4 | 5 | @interface XADMSLZXHandle:XADCABBlockHandle 6 | { 7 | LZSS lzss; 8 | 9 | XADPrefixCode *maincode,*lengthcode,*offsetcode; 10 | 11 | int numslots; 12 | BOOL headerhasbeenread,ispreprocessed; 13 | int32_t preprocesssize; 14 | 15 | off_t inputpos; 16 | 17 | int blocktype; 18 | off_t blockend; 19 | int r0,r1,r2; 20 | int mainlengths[256+50*8],lengthlengths[249]; 21 | 22 | uint8_t outbuffer[32768]; 23 | } 24 | 25 | -(id)initWithBlockReader:(XADCABBlockReader *)blockreader windowBits:(int)windowbits; 26 | -(void)dealloc; 27 | 28 | -(void)resetCABBlockHandle; 29 | -(int)produceCABBlockWithInputBuffer:(uint8_t *)buffer length:(int)length atOffset:(off_t)pos length:(int)uncomplength; 30 | 31 | -(void)readBlockHeaderAtPosition:(off_t)pos; 32 | -(void)readDeltaLengths:(int *)lengths count:(int)count alternateMode:(BOOL)altmode; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /XADMaster/XADMSZipHandle.h: -------------------------------------------------------------------------------- 1 | #import "XADCABBlockHandle.h" 2 | 3 | @interface XADMSZipHandle:XADCABBlockHandle 4 | { 5 | uint8_t outbuffer[32768]; 6 | int lastlength; 7 | } 8 | 9 | -(int)produceCABBlockWithInputBuffer:(uint8_t *)buffer length:(int)length atOffset:(off_t)pos length:(int)uncomplength; 10 | 11 | @end 12 | -------------------------------------------------------------------------------- /XADMaster/XADMSZipHandle.m: -------------------------------------------------------------------------------- 1 | #import "XADMSZipHandle.h" 2 | 3 | #ifndef __MACTYPES__ 4 | #define Byte zlibByte 5 | #include 6 | #undef Byte 7 | #else 8 | #include 9 | #endif 10 | 11 | @implementation XADMSZipHandle 12 | 13 | -(int)produceCABBlockWithInputBuffer:(uint8_t *)buffer length:(int)length atOffset:(off_t)pos length:(int)uncomplength 14 | { 15 | z_stream zs; 16 | memset(&zs,0,sizeof(zs)); 17 | 18 | inflateInit2(&zs,-MAX_WBITS); 19 | if(pos!=0) inflateSetDictionary(&zs,outbuffer,lastlength); 20 | 21 | zs.avail_in=length-2; 22 | zs.next_in=buffer+2; 23 | 24 | zs.next_out=outbuffer; 25 | zs.avail_out=uncomplength; //sizeof(outbuffer); 26 | 27 | /*int err=*/inflate(&zs,0); 28 | inflateEnd(&zs); 29 | /*if(err==Z_STREAM_END) 30 | { 31 | if(seekback) [parent skipBytes:-(off_t)zs.avail_in]; 32 | [self endStream]; 33 | break; 34 | } 35 | else if(err!=Z_OK) [self _raiseZlib];*/ 36 | 37 | [self setBlockPointer:outbuffer]; 38 | 39 | lastlength=sizeof(outbuffer)-zs.avail_out; 40 | return lastlength; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /XADMaster/XADMacBinaryParser.h: -------------------------------------------------------------------------------- 1 | #import "XADMacArchiveParser.h" 2 | 3 | @interface XADMacBinaryParser:XADMacArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 9 | 10 | -(void)parseWithSeparateMacForks; 11 | -(CSHandle *)rawHandleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 12 | -(NSString *)formatName; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /XADMaster/XADMacBinaryParser.m: -------------------------------------------------------------------------------- 1 | #import "XADMacBinaryParser.h" 2 | 3 | @implementation XADMacBinaryParser 4 | 5 | +(int)requiredHeaderSize 6 | { 7 | return 128; 8 | } 9 | 10 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name 11 | { 12 | return [XADMacArchiveParser macBinaryVersionForHeader:data]>0; 13 | } 14 | 15 | -(void)parseWithSeparateMacForks 16 | { 17 | [self setIsMacArchive:YES]; 18 | 19 | [properties removeObjectForKey:XADDisableMacForkExpansionKey]; 20 | [self addEntryWithDictionary:[NSMutableDictionary dictionaryWithObjectsAndKeys: 21 | [NSNumber numberWithBool:YES],XADIsMacBinaryKey, 22 | nil]]; 23 | } 24 | 25 | -(CSHandle *)rawHandleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum 26 | { 27 | return [self handle]; 28 | } 29 | 30 | -(void)inspectEntryDictionary:(NSMutableDictionary *)dict 31 | { 32 | NSNumber *rsrc=[dict objectForKey:XADIsResourceForkKey]; 33 | if(rsrc&&[rsrc boolValue]) return; 34 | 35 | if([[self name] matchedByPattern:@"\\.sea(\\.|$)" options:REG_ICASE]|| 36 | [[[dict objectForKey:XADFileNameKey] string] matchedByPattern:@"\\.(sea|sit|cpt)$" options:REG_ICASE]) 37 | [dict setObject:[NSNumber numberWithBool:YES] forKey:XADIsArchiveKey]; 38 | 39 | // TODO: Better detection of embedded archives. Also applies to BinHex! 40 | // if([[dict objectForKey:XADFileTypeKey] unsignedIntValue]=='APPL')... 41 | } 42 | 43 | -(NSString *)formatName 44 | { 45 | return @"MacBinary"; 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /XADMaster/XADMaster_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'XADMaster' target in the 'XADMaster' project. 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | 9 | #if !NSINTEGER_DEFINED && !defined(__COCOTRON__) 10 | typedef int NSInteger; 11 | typedef unsigned int NSUInteger; 12 | #endif 13 | -------------------------------------------------------------------------------- /XADMaster/XADNDSParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADNDSParser:XADArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 9 | 10 | -(void)parse; 11 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 12 | -(NSString *)formatName; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /XADMaster/XADNSAParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | #import "XADLZSSHandle.h" 3 | 4 | @interface XADNSAParser:XADArchiveParser 5 | { 6 | } 7 | 8 | +(int)requiredHeaderSize; 9 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 10 | 11 | -(void)parse; 12 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 13 | -(NSString *)formatName; 14 | 15 | @end 16 | 17 | @interface XADNSALZSSHandle:XADLZSSHandle 18 | { 19 | } 20 | 21 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 22 | -(void)resetLZSSHandle; 23 | -(int)nextLiteralOrOffset:(int *)offset andLength:(int *)length atPosition:(off_t)pos; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /XADMaster/XADNowCompressHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSBlockStreamHandle.h" 2 | 3 | @interface XADNowCompressHandle:CSBlockStreamHandle 4 | { 5 | NSMutableArray *files; 6 | int nextfile; 7 | 8 | struct 9 | { 10 | uint32_t offset,length; 11 | int flags; 12 | } *blocks; 13 | int maxblocks,numblocks,nextblock; 14 | 15 | uint8_t inblock[0x8000],outblock[0x10000],dictionarycache[0x8000]; 16 | } 17 | 18 | -(id)initWithHandle:(CSHandle *)handle files:(NSMutableArray *)filesarray; 19 | 20 | -(void)resetBlockStream; 21 | 22 | -(BOOL)parseAndCheckFileHeaderWithHeaderOffset:(uint32_t)headeroffset 23 | firstOffset:(uint32_t)firstoffset delta:(int32_t)delta; 24 | -(int)findFileHeaderDeltaWithHeaderOffset:(uint32_t)headeroffset firstOffset:(uint32_t)firstoffset; 25 | -(BOOL)readNextFileHeader; 26 | -(int)produceBlockAtOffset:(off_t)pos; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /XADMaster/XADNowCompressParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADNowCompressParser:XADArchiveParser 4 | { 5 | int totalentries,currentries; 6 | NSMutableArray *entries,*filesarray; 7 | off_t solidoffset; 8 | } 9 | 10 | +(int)requiredHeaderSize; 11 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 12 | 13 | -(void)parse; 14 | -(void)parseDirectoryWithParent:(XADPath *)parent numberOfEntries:(int)numentries; 15 | 16 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 17 | -(NSString *)formatName; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /XADMaster/XADPDFParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | #import "PDF/PDFParser.h" 3 | 4 | @interface XADPDFParser:XADArchiveParser 5 | { 6 | PDFParser *parser; 7 | } 8 | 9 | +(int)requiredHeaderSize; 10 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 11 | 12 | -(id)init; 13 | -(void)dealloc; 14 | 15 | -(void)parse; 16 | -(NSString *)compressionNameForStream:(PDFStream *)stream excludingLast:(BOOL)excludelast; 17 | 18 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 19 | 20 | -(NSString *)formatName; 21 | 22 | @end 23 | 24 | @interface XAD8BitPaletteExpansionHandle:CSByteStreamHandle 25 | { 26 | NSData *palette; 27 | 28 | uint8_t bytebuffer[8]; 29 | int numchannels,currentchannel; 30 | } 31 | 32 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length 33 | numberOfChannels:(int)numberofchannels palette:(NSData *)palettedata; 34 | 35 | -(void)resetByteStream; 36 | -(uint8_t)produceByteAtOffset:(off_t)pos; 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /XADMaster/XADPMArc1Handle.h: -------------------------------------------------------------------------------- 1 | #import "XADLZSSHandle.h" 2 | 3 | typedef struct { 4 | uint8_t prev; 5 | uint8_t next; 6 | } XADPMA1HistoryNode; 7 | 8 | // History linked list. In the decode stream, codes representing 9 | // characters are not the character itself, but the number of 10 | // nodes to count back in time in the linked list. Every time 11 | // a character is output, it is moved to the front of the linked 12 | // list. The entry point index into the list is the last output 13 | // character, given by history_head; 14 | 15 | typedef struct { 16 | XADPMA1HistoryNode history[256]; 17 | uint8_t history_head; 18 | } XADPMA1HistoryLinkedList; 19 | 20 | @interface XADPMArc1Handle:XADLZSSHandle 21 | { 22 | int bytesleft; 23 | bool nextismatch; 24 | 25 | // Pointer to the entry in byte_decode_table used to decode 26 | // byte value indices. 27 | const uint8_t *byte_decode_tree; 28 | 29 | // History linked list, for adaptively encoding byte values. 30 | XADPMA1HistoryLinkedList history_list; 31 | } 32 | 33 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 34 | -(int)nextLiteralOrOffset:(int *)offset andLength:(int *)length atPosition:(off_t)pos; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /XADMaster/XADPNGWriter.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface XADPNGWriter:NSObject 5 | { 6 | NSMutableData *data; 7 | int bytesperrow; 8 | 9 | z_stream zs; 10 | BOOL streaminited; 11 | 12 | int idatstart; 13 | } 14 | 15 | +(XADPNGWriter *)PNGWriter; 16 | 17 | -(id)init; 18 | -(void)dealloc; 19 | 20 | -(NSData *)data; 21 | 22 | -(void)addIHDRWithWidth:(int)width height:(int)height bitDepth:(int)bitdepth 23 | colourType:(int)colourtype; 24 | -(void)addIEND; 25 | -(void)addChunk:(uint32_t)chunktype bytes:(uint8_t *)bytes length:(int)length; 26 | 27 | -(void)startIDAT; 28 | -(void)addIDATRow:(uint8_t *)bytes; 29 | -(void)endIDAT; 30 | 31 | @end 32 | 33 | -------------------------------------------------------------------------------- /XADMaster/XADPPMdParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADPPMdParser:XADArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 9 | 10 | -(void)parse; 11 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 12 | -(NSString *)formatName; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /XADMaster/XADPackItParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | #import "CSBlockStreamHandle.h" 3 | 4 | #import "Crypto/des.h" 5 | 6 | @interface XADPackItParser:XADArchiveParser 7 | { 8 | NSMutableDictionary *currdesc; 9 | CSHandle *currhandle; 10 | } 11 | 12 | +(int)requiredHeaderSize; 13 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 14 | 15 | -(void)parse; 16 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 17 | -(CSHandle *)handleForSolidStreamWithObject:(id)obj wantChecksum:(BOOL)checksum; 18 | -(NSString *)formatName; 19 | 20 | @end 21 | 22 | @interface XADPackItXORHandle:CSBlockStreamHandle 23 | { 24 | uint8_t key[8],block[8]; 25 | } 26 | 27 | -(id)initWithHandle:(CSHandle *)handle password:(NSData *)passdata; 28 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length password:(NSData *)passdata; 29 | 30 | -(int)produceBlockAtOffset:(off_t)pos; 31 | 32 | @end 33 | 34 | @interface XADPackItDESHandle:CSBlockStreamHandle 35 | { 36 | uint8_t block[8]; 37 | DES_key_schedule schedule; 38 | } 39 | 40 | -(id)initWithHandle:(CSHandle *)handle password:(NSData *)passdata; 41 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length password:(NSData *)passdata; 42 | 43 | -(int)produceBlockAtOffset:(off_t)pos; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /XADMaster/XADPaddedBlockHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSHandle.h" 2 | 3 | 4 | @interface XADPaddedBlockHandle:CSHandle 5 | { 6 | off_t startoffset; 7 | int logicalsize,physicalsize; 8 | } 9 | 10 | -(id)initWithHandle:(CSHandle *)handle startOffset:(off_t)start 11 | logicalBlockSize:(int)logical physicalBlockSize:(int)physical; 12 | 13 | -(off_t)fileSize; 14 | -(off_t)offsetInFile; 15 | -(BOOL)atEndOfFile; 16 | 17 | -(void)seekToFileOffset:(off_t)offs; 18 | -(void)seekToEndOfFile; 19 | -(int)readAtMost:(int)num toBuffer:(void *)buffer; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /XADMaster/XADPlatform.h: -------------------------------------------------------------------------------- 1 | #import "XADUnarchiver.h" 2 | #import "CSHandle.h" 3 | 4 | @interface XADPlatform:NSObject {} 5 | 6 | // Archive entry extraction. 7 | +(XADError)extractResourceForkEntryWithDictionary:(NSDictionary *)dict 8 | unarchiver:(XADUnarchiver *)unarchiver toPath:(NSString *)destpath; 9 | +(XADError)updateFileAttributesAtPath:(NSString *)path 10 | forEntryWithDictionary:(NSDictionary *)dict parser:(XADArchiveParser *)parser 11 | preservePermissions:(BOOL)preservepermissions; 12 | +(XADError)createLinkAtPath:(NSString *)path withDestinationPath:(NSString *)link; 13 | 14 | // Archive post-processing. 15 | +(id)readCloneableMetadataFromPath:(NSString *)path; 16 | +(void)writeCloneableMetadata:(id)metadata toPath:(NSString *)path; 17 | +(BOOL)copyDateFromPath:(NSString *)src toPath:(NSString *)dest; 18 | +(BOOL)resetDateAtPath:(NSString *)path; 19 | 20 | // Path functions. 21 | +(BOOL)fileExistsAtPath:(NSString *)path; 22 | +(BOOL)fileExistsAtPath:(NSString *)path isDirectory:(BOOL *)isdirptr; 23 | +(NSString *)uniqueDirectoryPathWithParentDirectory:(NSString *)parent; 24 | +(NSString *)sanitizedPathComponent:(NSString *)component; 25 | +(NSArray *)contentsOfDirectoryAtPath:(NSString *)path; 26 | +(BOOL)moveItemAtPath:(NSString *)src toPath:(NSString *)dest; 27 | +(BOOL)removeItemAtPath:(NSString *)path; 28 | 29 | // Resource forks 30 | +(CSHandle *)handleForReadingResourceForkAtPath:(NSString *)path; 31 | 32 | // Time functions. 33 | +(double)currentTimeInSeconds; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /XADMaster/XADPowerPackerParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADPowerPackerParser:XADArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 9 | 10 | -(void)parse; 11 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 12 | -(NSString *)formatName; 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /XADMaster/XADPrefixCode.h: -------------------------------------------------------------------------------- 1 | #import "CSInputBuffer.h" 2 | 3 | extern NSString *XADInvalidPrefixCodeException; 4 | 5 | typedef struct XADCodeTreeNode XADCodeTreeNode; 6 | typedef struct XADCodeTableEntry XADCodeTableEntry; 7 | 8 | @interface XADPrefixCode:NSObject 9 | { 10 | XADCodeTreeNode *tree; 11 | int numentries,minlength,maxlength; 12 | BOOL isstatic; 13 | 14 | int currnode; 15 | NSMutableArray *stack; 16 | 17 | int tablesize; 18 | XADCodeTableEntry *table1,*table2; 19 | } 20 | 21 | +(XADPrefixCode *)prefixCode; 22 | +(XADPrefixCode *)prefixCodeWithLengths:(const int *)lengths numberOfSymbols:(int)numsymbols 23 | maximumLength:(int)maxlength shortestCodeIsZeros:(BOOL)zeros; 24 | 25 | -(id)init; 26 | -(id)initWithStaticTable:(int (*)[2])statictable; 27 | -(id)initWithLengths:(const int *)lengths numberOfSymbols:(int)numsymbols 28 | maximumLength:(int)maxlength shortestCodeIsZeros:(BOOL)zeros; 29 | -(void)dealloc; 30 | 31 | -(void)addValue:(int)value forCodeWithHighBitFirst:(uint32_t)code length:(int)length; 32 | -(void)addValue:(int)value forCodeWithHighBitFirst:(uint32_t)code length:(int)length repeatAt:(int)repeatpos; 33 | -(void)addValue:(int)value forCodeWithLowBitFirst:(uint32_t)code length:(int)length; 34 | -(void)addValue:(int)value forCodeWithLowBitFirst:(uint32_t)code length:(int)length repeatAt:(int)repeatpos; 35 | 36 | -(void)startBuildingTree; 37 | -(void)startZeroBranch; 38 | -(void)startOneBranch; 39 | -(void)finishBranches; 40 | -(void)makeLeafWithValue:(int)value; 41 | -(void)_pushNode; 42 | -(void)_popNode; 43 | 44 | -(void)_makeTable; 45 | -(void)_makeTableLE; 46 | 47 | @end 48 | 49 | int CSInputNextSymbolUsingCode(CSInputBuffer *buf,XADPrefixCode *code); 50 | int CSInputNextSymbolUsingCodeLE(CSInputBuffer *buf,XADPrefixCode *code); 51 | -------------------------------------------------------------------------------- /XADMaster/XADQuantumHandle.h: -------------------------------------------------------------------------------- 1 | #import "XADCABBlockHandle.h" 2 | #import "LZSS.h" 3 | 4 | typedef struct QuantumCoder 5 | { 6 | uint16_t CS_L,CS_H,CS_C; 7 | CSInputBuffer *input; 8 | } QuantumCoder; 9 | 10 | typedef struct QuantumModelSymbol 11 | { 12 | uint16_t symbol; 13 | uint16_t cumfreq; 14 | } QuantumModelSymbol; 15 | 16 | typedef struct QuantumModel 17 | { 18 | int numsymbols,shiftsleft; 19 | QuantumModelSymbol symbols[65]; 20 | } QuantumModel; 21 | 22 | @interface XADQuantumHandle:XADCABBlockHandle 23 | { 24 | LZSS lzss; 25 | 26 | int numslots4,numslots5,numslots6; 27 | 28 | QuantumCoder coder; 29 | QuantumModel selectormodel; 30 | QuantumModel literalmodel[4]; 31 | QuantumModel offsetmodel4,offsetmodel5,offsetmodel6; 32 | QuantumModel lengthmodel6; 33 | } 34 | 35 | -(id)initWithBlockReader:(XADCABBlockReader *)blockreader windowBits:(int)windowbits; 36 | 37 | -(void)resetCABBlockHandle; 38 | -(int)produceCABBlockWithInputBuffer:(uint8_t *)buffer length:(int)length atOffset:(off_t)pos length:(int)uncomplength; 39 | 40 | @end 41 | 42 | -------------------------------------------------------------------------------- /XADMaster/XADRAR13CryptHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSByteStreamHandle.h" 2 | 3 | @interface XADRAR13CryptHandle:CSByteStreamHandle 4 | { 5 | NSData *password; 6 | 7 | uint8_t key1,key2,key3; 8 | } 9 | 10 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length password:(NSData *)passdata; 11 | -(void)dealloc; 12 | 13 | -(void)resetByteStream; 14 | -(uint8_t)produceByteAtOffset:(off_t)pos; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /XADMaster/XADRAR13CryptHandle.m: -------------------------------------------------------------------------------- 1 | #import "XADRAR13CryptHandle.h" 2 | 3 | // TODO: Find test cases and actually test this code. 4 | 5 | static inline uint16_t rol8(uint16_t val,int n) { return (val<>(8-n)); } 6 | 7 | @implementation XADRAR13CryptHandle 8 | 9 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length password:(NSData *)passdata 10 | { 11 | if((self=[super initWithInputBufferForHandle:handle length:length])) 12 | { 13 | password=[passdata retain]; 14 | } 15 | return self; 16 | } 17 | 18 | -(void)dealloc 19 | { 20 | [password release]; 21 | [super dealloc]; 22 | } 23 | 24 | 25 | 26 | -(void)resetByteStream 27 | { 28 | int passlength=[password length]; 29 | const uint8_t *passbytes=[password bytes]; 30 | 31 | key1=key2=key3=0; 32 | 33 | for(int i=0;i>n)|(val<<(16-n)); } 5 | 6 | @implementation XADRAR15CryptHandle 7 | 8 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length password:(NSData *)passdata 9 | { 10 | if((self=[super initWithInputBufferForHandle:handle length:length])) 11 | { 12 | password=[passdata retain]; 13 | } 14 | return self; 15 | } 16 | 17 | -(void)dealloc 18 | { 19 | [password release]; 20 | [super dealloc]; 21 | } 22 | 23 | 24 | 25 | -(void)resetByteStream 26 | { 27 | int passlength=[password length]; 28 | const uint8_t *passbytes=[password bytes]; 29 | 30 | uint32_t crc=XADCalculateCRC(0xffffffff,passbytes,passlength,XADCRCTable_edb88320); 31 | 32 | key0=crc; 33 | key1=crc>>16; 34 | key2=key3=0; 35 | 36 | for(int i=0;i>16); 41 | } 42 | } 43 | 44 | -(uint8_t)produceByteAtOffset:(off_t)pos 45 | { 46 | key0+=0x1234; 47 | key1^=XADCRCTable_edb88320[(key0>>1)&0xff]; 48 | key2-=XADCRCTable_edb88320[(key0>>1)&0xff]>>16; 49 | key0^=key2; 50 | key3=ror16(key3&0xffff,1)^key1; 51 | key3=ror16(key3&0xffff,1); 52 | key0^=key3; 53 | 54 | if(CSInputAtEOF(input)) CSByteStreamEOF(self); 55 | 56 | return CSInputNextByte(input)^(key0>>8); 57 | } 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /XADMaster/XADRAR15Handle.h: -------------------------------------------------------------------------------- 1 | #import "XADFastLZSSHandle.h" 2 | #import "XADRARParser.h" 3 | #import "XADPrefixCode.h" 4 | 5 | @interface XADRAR15Handle:XADFastLZSSHandle 6 | { 7 | XADRARParser *parser; 8 | 9 | NSArray *files; 10 | int file; 11 | off_t endpos; 12 | 13 | XADPrefixCode *lengthcode1,*lengthcode2; 14 | XADPrefixCode *huffmancode0,*huffmancode1,*huffmancode2,*huffmancode3,*huffmancode4; 15 | XADPrefixCode *shortmatchcode0,*shortmatchcode1,*shortmatchcode2,*shortmatchcode3; 16 | 17 | BOOL storedblock; 18 | 19 | unsigned int flags,flagbits; 20 | unsigned int literalweight,matchweight; 21 | unsigned int numrepeatedliterals,numrepeatedlastmatches; 22 | unsigned int runningaverageliteral,runningaverageselector; 23 | unsigned int runningaveragelength,runningaverageoffset,runningaveragebelowmaximum; 24 | unsigned int maximumoffset; 25 | BOOL bugfixflag; 26 | 27 | int lastoffset,lastlength; 28 | int oldoffset[4],oldoffsetindex; 29 | 30 | int flagtable[256],flagreverse[256]; 31 | int literaltable[256],literalreverse[256]; 32 | int offsettable[256],offsetreverse[256]; 33 | int shortoffsettable[256]; 34 | } 35 | 36 | -(id)initWithRARParser:(XADRARParser *)parentparser files:(NSArray *)filearray; 37 | -(void)dealloc; 38 | 39 | -(void)resetLZSSHandle; 40 | -(void)startNextFile; 41 | -(void)expandFromPosition:(off_t)pos; 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /XADMaster/XADRAR20CryptHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSBlockStreamHandle.h" 2 | 3 | @interface XADRAR20CryptHandle:CSBlockStreamHandle 4 | { 5 | off_t startoffs; 6 | NSData *password; 7 | 8 | uint8_t outblock[16]; 9 | uint32_t key[4]; 10 | uint8_t table[256]; 11 | } 12 | 13 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length password:(NSData *)passdata; 14 | -(void)dealloc; 15 | 16 | -(void)resetBlockStream; 17 | -(void)calculateKey; 18 | -(int)produceBlockAtOffset:(off_t)pos; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /XADMaster/XADRAR20Handle.h: -------------------------------------------------------------------------------- 1 | #import "XADFastLZSSHandle.h" 2 | #import "XADRARParser.h" 3 | #import "XADPrefixCode.h" 4 | #import "RARAudioDecoder.h" 5 | 6 | @interface XADRAR20Handle:XADFastLZSSHandle 7 | { 8 | XADRARParser *parser; 9 | 10 | NSArray *files; 11 | int file; 12 | off_t endpos; 13 | 14 | XADPrefixCode *maincode,*offsetcode,*lengthcode; 15 | XADPrefixCode *audiocode[4]; 16 | 17 | int lastoffset,lastlength; 18 | int oldoffset[4],oldoffsetindex; 19 | 20 | BOOL audioblock; 21 | int channel,channeldelta,numchannels; 22 | RAR20AudioState audiostate[4]; 23 | 24 | int lengthtable[1028]; 25 | } 26 | 27 | -(id)initWithRARParser:(XADRARParser *)parentparser files:(NSArray *)filearray; 28 | -(void)dealloc; 29 | 30 | -(void)resetLZSSHandle; 31 | -(void)startNextFile; 32 | -(void)expandFromPosition:(off_t)pos; 33 | -(void)allocAndParseCodes; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /XADMaster/XADRAR30Handle.h: -------------------------------------------------------------------------------- 1 | #import "CSBlockStreamHandle.h" 2 | #import "XADRARParser.h" 3 | #import "LZSS.h" 4 | #import "XADPrefixCode.h" 5 | #import "PPMd/VariantH.h" 6 | #import "PPMd/SubAllocatorVariantH.h" 7 | #import "XADRARVirtualMachine.h" 8 | 9 | @interface XADRAR30Handle:CSBlockStreamHandle 10 | { 11 | XADRARParser *parser; 12 | 13 | NSArray *files; 14 | int file; 15 | off_t lastend; 16 | BOOL startnewfile,startnewtable; 17 | 18 | LZSS lzss; 19 | 20 | XADPrefixCode *maincode,*offsetcode,*lowoffsetcode,*lengthcode; 21 | 22 | int lastoffset,lastlength; 23 | int oldoffset[4]; 24 | int lastlowoffset,numlowoffsetrepeats; 25 | 26 | BOOL ppmblock; 27 | PPMdModelVariantH ppmd; 28 | PPMdSubAllocatorVariantH *alloc; 29 | int ppmescape; 30 | 31 | XADRARVirtualMachine *vm; 32 | NSMutableArray *filtercode,*stack; 33 | off_t filterstart; 34 | int lastfilternum; 35 | int oldfilterlength[1024],usagecount[1024]; 36 | off_t currfilestartpos; 37 | 38 | int lengthtable[299+60+17+28]; 39 | } 40 | 41 | -(id)initWithRARParser:(XADRARParser *)parentparser files:(NSArray *)filearray; 42 | -(void)dealloc; 43 | 44 | -(void)resetBlockStream; 45 | -(int)produceBlockAtOffset:(off_t)pos; 46 | -(off_t)expandToPosition:(off_t)end; 47 | -(void)allocAndParseCodes; 48 | 49 | -(void)readFilterFromInput; 50 | -(void)readFilterFromPPMd; 51 | -(void)parseFilter:(const uint8_t *)bytes length:(int)length flags:(int)flags; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /XADMaster/XADRAR50Handle.h: -------------------------------------------------------------------------------- 1 | #import "CSBlockStreamHandle.h" 2 | #import "XADRAR5Parser.h" 3 | #import "LZSS.h" 4 | #import "XADPrefixCode.h" 5 | #import "PPMd/VariantH.h" 6 | #import "PPMd/SubAllocatorVariantH.h" 7 | 8 | @interface XADRAR50Handle:CSBlockStreamHandle 9 | { 10 | XADRAR5Parser *parser; 11 | 12 | NSArray *files; 13 | int file; 14 | BOOL startnewfile; 15 | off_t currfilestartpos; 16 | 17 | off_t blockbitend; 18 | BOOL islastblock; 19 | 20 | LZSS lzss; 21 | 22 | XADPrefixCode *maincode,*offsetcode,*lowoffsetcode,*lengthcode; 23 | 24 | int lastlength; 25 | int oldoffset[4]; 26 | int lastlowoffset,numlowoffsetrepeats; 27 | 28 | NSMutableArray *filters; 29 | NSMutableData *filterdata; 30 | 31 | int lengthtable[306+64+16+44]; 32 | } 33 | 34 | -(id)initWithRARParser:(XADRAR5Parser *)parentparser files:(NSArray *)filearray; 35 | -(void)dealloc; 36 | 37 | -(void)resetBlockStream; 38 | -(int)produceBlockAtOffset:(off_t)pos; 39 | -(off_t)expandToPosition:(off_t)end; 40 | -(void)readBlockHeader; 41 | -(void)allocAndParseCodes; 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /XADMaster/XADRAR5Parser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | typedef struct RAR5Block 4 | { 5 | uint32_t crc; 6 | uint64_t headersize,type,flags; 7 | uint64_t extrasize,datasize; 8 | off_t start,outerstart; 9 | CSHandle *fh; 10 | } RAR5Block; 11 | 12 | @interface XADRAR5Parser:XADArchiveParser 13 | { 14 | NSData *headerkey; 15 | NSMutableDictionary *cryptocache; 16 | 17 | NSMutableArray *solidstreams,*currsolidstream; 18 | off_t totalsolidsize; 19 | } 20 | 21 | +(int)requiredHeaderSize; 22 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 23 | +(NSArray *)volumesForHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 24 | 25 | -(void)parse; 26 | -(void)addEntryWithDictionary:(NSMutableDictionary *)dict 27 | inputParts:(NSArray *)parts isCorrupted:(BOOL)iscorrupted; 28 | 29 | -(NSMutableDictionary *)readFileBlockHeader:(RAR5Block)block; 30 | -(RAR5Block)readBlockHeader; 31 | -(void)skipBlock:(RAR5Block)block; 32 | -(off_t)endOfBlockHeader:(RAR5Block)block; 33 | -(NSData *)encryptionKeyForPassword:(NSString *)passwordstring salt:(NSData *)salt strength:(int)strength passwordCheck:(NSData *)check; 34 | -(NSData *)hashKeyForPassword:(NSString *)passwordstring salt:(NSData *)salt strength:(int)strength passwordCheck:(NSData *)check; 35 | -(NSDictionary *)keysForPassword:(NSString *)passwordstring salt:(NSData *)salt strength:(int)strength passwordCheck:(NSData *)check; 36 | 37 | -(CSInputBuffer *)inputBufferWithDictionary:(NSDictionary *)dict; 38 | -(CSHandle *)inputHandleWithDictionary:(NSDictionary *)dict; 39 | 40 | -(NSString *)formatName; 41 | 42 | @end 43 | 44 | @interface XADEmbeddedRAR5Parser:XADRAR5Parser 45 | { 46 | } 47 | 48 | -(NSString *)formatName; 49 | 50 | @end 51 | 52 | -------------------------------------------------------------------------------- /XADMaster/XADRARAESHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSBlockStreamHandle.h" 2 | 3 | #import "Crypto/aes.h" 4 | 5 | @interface XADRARAESHandle:CSStreamHandle 6 | { 7 | off_t startoffs; 8 | 9 | aes_decrypt_ctx aes; 10 | uint8_t iv[16],block[16],blockbuffer[16]; 11 | } 12 | 13 | +(NSData *)keyForPassword:(NSString *)password salt:(NSData *)salt brokenHash:(BOOL)brokenhash; 14 | 15 | -(id)initWithHandle:(CSHandle *)handle key:(NSData *)keydata; 16 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length key:(NSData *)keydata; 17 | -(id)initWithHandle:(CSHandle *)handle RAR5Key:(NSData *)keydata IV:(NSData *)ivdata; 18 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length RAR5Key:(NSData *)keydata IV:(NSData *)ivdata; 19 | 20 | -(void)resetStream; 21 | -(int)streamAtMost:(int)num toBuffer:(void *)buffer; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /XADMaster/XADRARInputHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSStreamHandle.h" 2 | 3 | @interface XADRARInputHandle:CSStreamHandle 4 | { 5 | NSArray *parts; 6 | 7 | int part; 8 | off_t partend; 9 | 10 | uint32_t crc,correctcrc; 11 | } 12 | 13 | -(id)initWithHandle:(CSHandle *)handle parts:(NSArray *)partarray; 14 | -(void)dealloc; 15 | 16 | -(void)resetStream; 17 | -(int)streamAtMost:(int)num toBuffer:(void *)buffer; 18 | 19 | -(void)startNextPart; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /XADMaster/XADRC4Handle.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "CSStreamHandle.h" 3 | 4 | @class XADRC4Engine; 5 | 6 | @interface XADRC4Handle:CSStreamHandle 7 | { 8 | off_t startoffs; 9 | NSData *key; 10 | XADRC4Engine *rc4; 11 | } 12 | 13 | -(id)initWithHandle:(CSHandle *)handle key:(NSData *)keydata; 14 | -(void)dealloc; 15 | 16 | -(void)resetStream; 17 | -(int)streamAtMost:(int)num toBuffer:(void *)buffer; 18 | 19 | @end 20 | 21 | @interface XADRC4Engine:NSObject 22 | { 23 | uint8_t s[256]; 24 | int i,j; 25 | } 26 | 27 | +(XADRC4Engine *)engineWithKey:(NSData *)key; 28 | 29 | -(id)initWithKey:(NSData *)key; 30 | 31 | -(NSData *)encryptedData:(NSData *)data; 32 | 33 | -(void)encryptBytes:(unsigned char *)bytes length:(int)length; 34 | -(void)skipBytes:(int)length; 35 | 36 | @end 37 | 38 | -------------------------------------------------------------------------------- /XADMaster/XADRLE90Handle.h: -------------------------------------------------------------------------------- 1 | #import "CSByteStreamHandle.h" 2 | 3 | @interface XADRLE90Handle:CSByteStreamHandle 4 | { 5 | int repeatedbyte,count; 6 | } 7 | 8 | -(id)initWithHandle:(CSHandle *)handle; 9 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 10 | 11 | -(void)resetByteStream; 12 | -(uint8_t)produceByteAtOffset:(off_t)pos; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /XADMaster/XADRLE90Handle.m: -------------------------------------------------------------------------------- 1 | #import "XADRLE90Handle.h" 2 | #import "XADException.h" 3 | 4 | @implementation XADRLE90Handle 5 | 6 | -(id)initWithHandle:(CSHandle *)handle 7 | { 8 | return [self initWithHandle:handle length:CSHandleMaxLength]; 9 | } 10 | 11 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length 12 | { 13 | return [super initWithInputBufferForHandle:handle length:length]; 14 | } 15 | 16 | -(void)resetByteStream 17 | { 18 | repeatedbyte=count=0; 19 | } 20 | 21 | -(uint8_t)produceByteAtOffset:(off_t)pos 22 | { 23 | if(count) 24 | { 25 | count--; 26 | return repeatedbyte; 27 | } 28 | else 29 | { 30 | if(CSInputAtEOF(input)) CSByteStreamEOF(self); 31 | 32 | uint8_t b=CSInputNextByte(input); 33 | 34 | if(b!=0x90) return repeatedbyte=b; 35 | else 36 | { 37 | uint8_t c=CSInputNextByte(input); 38 | if(c==0) return repeatedbyte=0x90; 39 | else 40 | { 41 | if(c==1) [XADException raiseDecrunchException]; 42 | count=c-2; 43 | return repeatedbyte; 44 | } 45 | } 46 | } 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /XADMaster/XADRPMParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADRPMParser:XADArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 9 | 10 | -(void)parse; 11 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 12 | -(NSString *)formatName; 13 | 14 | @end 15 | 16 | 17 | -------------------------------------------------------------------------------- /XADMaster/XADResourceFork.h: -------------------------------------------------------------------------------- 1 | #import "CSHandle.h" 2 | #import "XADException.h" 3 | 4 | @interface XADResourceFork:NSObject 5 | { 6 | NSDictionary *resources; 7 | } 8 | 9 | +(XADResourceFork *)resourceForkWithHandle:(CSHandle *)handle; 10 | +(XADResourceFork *)resourceForkWithHandle:(CSHandle *)handle error:(XADError *)errorptr; 11 | 12 | -(id)init; 13 | -(void)dealloc; 14 | 15 | -(void)parseFromHandle:(CSHandle *)handle; 16 | -(NSData *)resourceDataForType:(uint32_t)type identifier:(int)identifier; 17 | 18 | -(NSMutableDictionary *)_parseResourceDataFromHandle:(CSHandle *)handle; 19 | -(NSDictionary *)_parseMapFromHandle:(CSHandle *)handle withDataObjects:(NSMutableDictionary *)dataobjects; 20 | -(NSDictionary *)_parseReferencesFromHandle:(CSHandle *)handle count:(int)count; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /XADMaster/XADSARParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADSARParser:XADArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 9 | 10 | -(void)parse; 11 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 12 | -(NSString *)formatName; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /XADMaster/XADSARParser.m: -------------------------------------------------------------------------------- 1 | #import "XADSARParser.h" 2 | #import "XADRegex.h" 3 | 4 | @implementation XADSARParser 5 | 6 | +(int)requiredHeaderSize { return 6; } 7 | 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name 9 | { 10 | if(!name) return NO; 11 | if(![[name lastPathComponent] matchedByPattern:@"^arc[0-9]*\\.sar$" options:REG_ICASE]) return NO; 12 | 13 | //const uint8_t *bytes=[data bytes]; 14 | //int length=[data length]; 15 | 16 | return YES; 17 | } 18 | 19 | -(void)parse 20 | { 21 | CSHandle *fh=[self handle]; 22 | 23 | int numfiles=[fh readUInt16BE]; 24 | if(numfiles==0) numfiles=[fh readUInt16BE]; 25 | 26 | uint32_t offset=[fh readUInt32BE]; 27 | 28 | for(int i=0;i=257*2) [XADException raiseDecrunchException]; 47 | 48 | int nodes[numnodes]; 49 | nodes[0]=nodes[1]=-(256+1); 50 | 51 | for(int i=0;icurrsize) 34 | { 35 | free(buffer); 36 | buffer=malloc(size); 37 | currsize=size; 38 | [self setBlockPointer:buffer]; 39 | } 40 | 41 | return [parent readAtMost:size toBuffer:buffer]; 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /XADMaster/XADStuffItXCyanideHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSBlockStreamHandle.h" 2 | 3 | @interface XADStuffItXCyanideHandle:CSBlockStreamHandle 4 | { 5 | uint8_t *block,*sorted; 6 | uint32_t *table; 7 | size_t currsize; 8 | } 9 | 10 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 11 | -(void)dealloc; 12 | 13 | -(void)resetBlockStream; 14 | -(int)produceBlockAtOffset:(off_t)pos; 15 | 16 | -(void)readTernaryCodedBlock:(int)blocksize numberOfSymbols:(int)numsymbols; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /XADMaster/XADStuffItXDarkhorseHandle.h: -------------------------------------------------------------------------------- 1 | #import "XADLZSSHandle.h" 2 | #import "CarrylessRangeCoder.h" 3 | 4 | @interface XADStuffItXDarkhorseHandle:XADLZSSHandle 5 | { 6 | CarrylessRangeCoder coder; 7 | 8 | int next; 9 | 10 | uint32_t flagweights[4],flagweight2; 11 | uint32_t litweights[16][256],litweights2[16][256][2]; 12 | uint32_t recencyweight1,recencyweight2,recencyweight3,recencyweights[4]; 13 | uint32_t lenweight,shortweights[4][16],longweights[256]; 14 | uint32_t distlenweights[4][64],distweights[10][32],distlowbitweights[16]; 15 | 16 | int distancetable[4]; 17 | } 18 | 19 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length windowSize:(int)windowsize; 20 | 21 | -(void)resetLZSSHandle; 22 | -(int)nextLiteralOrOffset:(int *)offset andLength:(int *)length atPosition:(off_t)pos; 23 | 24 | -(int)readLiteralWithPrevious:(int)prev next:(int)next; 25 | -(int)readLengthWithIndex:(int)index; 26 | -(int)readDistanceWithLength:(int)len; 27 | -(int)readRecencyWithIndex:(int)index; 28 | 29 | -(int)readSymbolWithWeights:(uint32_t *)weights numberOfBits:(int)num; 30 | 31 | -(void)updateDistanceMemoryWithOldIndex:(int)oldindex distance:(int)distance; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /XADMaster/XADStuffItXEnglishHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSByteStreamHandle.h" 2 | 3 | @interface XADStuffItXEnglishHandle:CSByteStreamHandle 4 | { 5 | uint8_t esccode,wordcode,firstcode,uppercode; 6 | BOOL caseflag; 7 | 8 | uint8_t wordbuf[33]; 9 | int wordoffs,wordlen; 10 | } 11 | 12 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 13 | 14 | -(void)resetByteStream; 15 | -(uint8_t)produceByteAtOffset:(off_t)pos; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /XADMaster/XADStuffItXIronHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSBlockStreamHandle.h" 2 | 3 | @interface XADStuffItXIronHandle:CSBlockStreamHandle 4 | { 5 | uint8_t *block,*sorted; 6 | uint32_t *table; 7 | size_t currsize; 8 | 9 | int st4transform,fancymtf; 10 | 11 | int maxfreq1,maxfreq2,maxfreq3; 12 | int byteshift1,byteshift2,byteshift3; 13 | int countshift1,countshift2,countshift3; 14 | } 15 | 16 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 17 | -(void)dealloc; 18 | 19 | -(void)resetBlockStream; 20 | -(int)produceBlockAtOffset:(off_t)pos; 21 | 22 | -(void)decodeBlockWithLength:(int)blocksize; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /XADMaster/XADStuffItXParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | #import "CSMemoryHandle.h" 3 | 4 | @interface XADStuffItXParser:XADArchiveParser 5 | { 6 | NSData *repeatedentrydata; 7 | NSArray *repeatedentries; 8 | BOOL repeatedentryhaschecksum,repeatedentryiscorrect; 9 | } 10 | 11 | +(int)requiredHeaderSize; 12 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 13 | 14 | -(void)parse; 15 | -(void)parseCatalogWithHandle:(CSHandle *)fh entryArray:(NSArray *)entries entryDictionary:(NSDictionary *)dict; 16 | 17 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 18 | -(CSHandle *)handleForSolidStreamWithObject:(id)obj wantChecksum:(BOOL)checksum; 19 | -(NSString *)formatName; 20 | 21 | @end 22 | 23 | @interface XADStuffItXRepeatedEntryHandle:CSMemoryHandle 24 | { 25 | BOOL haschecksum,ischecksumcorrect; 26 | } 27 | 28 | -(id)initWithData:(NSData *)data hasChecksum:(BOOL)hascheck isChecksumCorrect:(BOOL)iscorrect; 29 | 30 | -(BOOL)hasChecksum; 31 | -(BOOL)isChecksumCorrect; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /XADMaster/XADStuffItXX86Handle.h: -------------------------------------------------------------------------------- 1 | #import "CSByteStreamHandle.h" 2 | 3 | @interface XADStuffItXX86Handle:CSByteStreamHandle 4 | { 5 | off_t lasthit; 6 | uint32_t bitfield; 7 | 8 | int numbufferbytes,currbufferbyte; 9 | uint8_t buffer[4]; 10 | } 11 | 12 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 13 | 14 | -(void)resetByteStream; 15 | -(uint8_t)produceByteAtOffset:(off_t)pos; 16 | 17 | @end 18 | 19 | -------------------------------------------------------------------------------- /XADMaster/XADTarParser.h: -------------------------------------------------------------------------------- 1 | #import "XADMacArchiveParser.h" 2 | #import "XADTarSparseHandle.h" 3 | 4 | // TODO later: Multivolume tar. 5 | 6 | @interface XADTarParser:XADMacArchiveParser 7 | { 8 | NSData *currentGlobalHeader; 9 | } 10 | 11 | +(int)requiredHeaderSize; 12 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 13 | +(uint64_t)readOctalNumberInRangeFromBuffer:(NSRange)range buffer:(NSData *)buffer; 14 | +(BOOL)isTarChecksumCorrect:(NSData *)header checksum:(int)checksum; 15 | 16 | -(void)dealloc; 17 | 18 | -(void)parseWithSeparateMacForks; 19 | -(CSHandle *)rawHandleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 20 | -(NSString *)formatName; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /XADMaster/XADTarSparseHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSHandle.h" 2 | 3 | typedef struct XADTarSparseRegion 4 | { 5 | int nextRegion; 6 | off_t offset; 7 | off_t size; 8 | BOOL hasData; 9 | off_t dataOffset; 10 | } XADTarSparseRegion; 11 | 12 | @interface XADTarSparseHandle:CSHandle 13 | { 14 | XADTarSparseRegion *regions; 15 | int numRegions; 16 | int currentRegion; 17 | off_t currentOffset; 18 | off_t realFileSize; 19 | } 20 | 21 | -(id)initWithHandle:(CSHandle *)handle size:(off_t)size; 22 | -(id)initAsCopyOf:(XADTarSparseHandle *)other; 23 | -(void)dealloc; 24 | 25 | -(void)addSparseRegionFrom:(off_t)start length:(off_t)length; 26 | -(void)addFinalSparseRegionEndingAt:(off_t)regionEndsAt; 27 | -(void)setSingleEmptySparseRegion; 28 | 29 | -(off_t)fileSize; 30 | -(off_t)offsetInFile; 31 | -(BOOL)atEndOfFile; 32 | 33 | -(void)seekToFileOffset:(off_t)offs; 34 | -(void)seekToEndOfFile; 35 | -(int)readAtMost:(int)num toBuffer:(void *)buffer; 36 | 37 | @end -------------------------------------------------------------------------------- /XADMaster/XADWARCParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | 3 | @interface XADWARCParser:XADArchiveParser 4 | { 5 | } 6 | 7 | +(int)requiredHeaderSize; 8 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 9 | 10 | -(void)parse; 11 | -(NSMutableDictionary *)parseHTTPHeadersWithHandle:(CSHandle *)handle; 12 | -(NSArray *)readHTTPHeadersWithHandle:(CSHandle *)handle; 13 | 14 | -(NSArray *)pathComponentsForURLString:(NSString *)urlstring; 15 | -(NSMutableDictionary *)insertDirectory:(NSString *)name inDirectory:(NSMutableDictionary *)dir; 16 | -(void)insertFile:(NSString *)name record:(NSMutableDictionary *)record inDirectory:(NSMutableDictionary *)dir; 17 | -(void)buildXADPathsForFilesInDirectory:(NSMutableDictionary *)dir parentPath:(XADPath *)parent; 18 | 19 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 20 | -(NSString *)formatName; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /XADMaster/XADWinZipAESHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSStreamHandle.h" 2 | #import "Crypto/aes.h" 3 | #import "Crypto/hmac_sha1.h" 4 | 5 | @interface XADWinZipAESHandle:CSStreamHandle 6 | { 7 | NSData *password; 8 | int keybytes; 9 | off_t startoffs; 10 | 11 | aes_encrypt_ctx aes; 12 | uint8_t counter[16],aesbuffer[16]; 13 | HMAC_SHA1_CTX hmac; 14 | BOOL hmac_done,hmac_correct; 15 | } 16 | 17 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length password:(NSData *)passdata keyLength:(int)keylength; 18 | -(void)dealloc; 19 | 20 | -(void)resetStream; 21 | -(int)streamAtMost:(int)num toBuffer:(void *)buffer; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /XADMaster/XADWinZipJPEGHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSBlockStreamHandle.h" 2 | 3 | #import "WinZipJPEG/Decompressor.h" 4 | 5 | @interface XADWinZipJPEGHandle:CSBlockStreamHandle 6 | { 7 | WinZipJPEGDecompressor *decompressor; 8 | uint8_t buffer[65536]; 9 | } 10 | 11 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 12 | -(void)dealloc; 13 | 14 | -(void)resetBlockStream; 15 | -(int)produceBlockAtOffset:(off_t)pos; 16 | 17 | @end 18 | 19 | -------------------------------------------------------------------------------- /XADMaster/XADWinZipWavPackHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSBlockStreamHandle.h" 2 | 3 | #import "wavpack/wavpack.h" 4 | 5 | @interface XADWinZipWavPackHandle:CSBlockStreamHandle 6 | { 7 | WavpackContext *context; 8 | BOOL header; 9 | int headerlength; 10 | uint8_t *buffer; 11 | } 12 | 13 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 14 | -(void)dealloc; 15 | 16 | -(void)resetBlockStream; 17 | -(int)produceBlockAtOffset:(off_t)pos; 18 | 19 | @end 20 | 21 | -------------------------------------------------------------------------------- /XADMaster/XADXORHandle.h: -------------------------------------------------------------------------------- 1 | #import "CSHandle.h" 2 | 3 | @interface XADXORHandle:CSHandle 4 | { 5 | NSData *password; 6 | const uint8_t *passwordbytes; 7 | int passwordlength; 8 | } 9 | 10 | -(id)initWithHandle:(CSHandle *)handle password:(NSData *)passdata; 11 | -(id)initAsCopyOf:(XADXORHandle *)other; 12 | -(void)dealloc; 13 | 14 | -(off_t)fileSize; 15 | -(off_t)offsetInFile; 16 | -(BOOL)atEndOfFile; 17 | -(void)seekToFileOffset:(off_t)offs; 18 | -(void)seekToEndOfFile; 19 | -(int)readAtMost:(int)num toBuffer:(void *)buffer; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /XADMaster/XADXORHandle.m: -------------------------------------------------------------------------------- 1 | #import "XADXORHandle.h" 2 | 3 | @implementation XADXORHandle 4 | 5 | -(id)initWithHandle:(CSHandle *)handle password:(NSData *)passdata 6 | { 7 | if((self=[super initWithParentHandle:handle])) 8 | { 9 | password=[passdata retain]; 10 | passwordbytes=[password bytes]; 11 | passwordlength=[password length]; 12 | } 13 | return self; 14 | } 15 | 16 | -(id)initAsCopyOf:(XADXORHandle *)other 17 | { 18 | [self _raiseNotSupported:_cmd]; 19 | return nil; 20 | } 21 | 22 | -(void)dealloc 23 | { 24 | [password release]; 25 | [super dealloc]; 26 | } 27 | 28 | 29 | 30 | -(off_t)fileSize { return [parent fileSize]; } 31 | 32 | -(off_t)offsetInFile { return [parent offsetInFile]; } 33 | 34 | -(BOOL)atEndOfFile { return [parent atEndOfFile]; } 35 | 36 | -(void)seekToFileOffset:(off_t)offs { [parent seekToFileOffset:offs]; } 37 | 38 | -(void)seekToEndOfFile { [parent seekToEndOfFile]; } 39 | 40 | -(int)readAtMost:(int)num toBuffer:(void *)buffer 41 | { 42 | off_t pos=[parent offsetInFile]; 43 | int actual=[parent readAtMost:num toBuffer:buffer]; 44 | 45 | if(passwordlength) 46 | { 47 | uint8_t *buf=(uint8_t *)buffer; 48 | for(int i=0;ikey0=XADCRC(self->key0,b,XADCRCTable_edb88320); 10 | self->key1+=self->key0&0xff; 11 | self->key1=self->key1*134775813+1; 12 | self->key2=XADCRC(self->key2,self->key1>>24,XADCRCTable_edb88320); 13 | } 14 | 15 | static uint8_t DecryptByte(XADZipCryptHandle *self) 16 | { 17 | uint16_t temp=self->key2|2; 18 | return (temp*(temp^1))>>8; 19 | } 20 | 21 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length password:(NSData *)passdata testByte:(uint8_t)testbyte 22 | { 23 | if((self=[super initWithInputBufferForHandle:handle length:length-12])) 24 | { 25 | password=[passdata retain]; 26 | test=testbyte; 27 | } 28 | return self; 29 | } 30 | 31 | -(void)dealloc 32 | { 33 | [password release]; 34 | [super dealloc]; 35 | } 36 | 37 | 38 | 39 | -(void)resetByteStream 40 | { 41 | key0=305419896; 42 | key1=591751049; 43 | key2=878082192; 44 | 45 | int passlength=[password length]; 46 | const uint8_t *passbytes=[password bytes]; 47 | for(int i=0;i13) [XADException raiseDecrunchException]; 44 | } 45 | else if(next==2) ClearLZWTable(lzw); 46 | } 47 | else break; 48 | } 49 | 50 | if(NextLZWSymbol(lzw,symbol)!=LZWNoError) [XADException raiseDecrunchException]; 51 | currbyte=LZWReverseOutputToBuffer(lzw,buffer); 52 | } 53 | 54 | return buffer[--currbyte]; 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /XADMaster/XADZooParser.h: -------------------------------------------------------------------------------- 1 | #import "XADArchiveParser.h" 2 | #import "CSByteStreamHandle.h" 3 | #import "LZW.h" 4 | 5 | @interface XADZooParser:XADArchiveParser 6 | { 7 | } 8 | 9 | +(int)requiredHeaderSize; 10 | +(BOOL)recognizeFileWithHandle:(CSHandle *)handle firstBytes:(NSData *)data name:(NSString *)name; 11 | 12 | -(void)parse; 13 | -(CSHandle *)handleForEntryWithDictionary:(NSDictionary *)dict wantChecksum:(BOOL)checksum; 14 | -(NSString *)formatName; 15 | 16 | @end 17 | 18 | @interface XADZooMethod1Handle:CSByteStreamHandle 19 | { 20 | LZW *lzw; 21 | 22 | int currbyte; 23 | uint8_t buffer[8192]; 24 | } 25 | 26 | -(id)initWithHandle:(CSHandle *)handle length:(off_t)length; 27 | 28 | -(void)resetByteStream; 29 | -(uint8_t)produceByteAtOffset:(off_t)pos; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /XADMaster/libxad/all.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/all.c -------------------------------------------------------------------------------- /XADMaster/libxad/clientfunc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clientfunc.c -------------------------------------------------------------------------------- /XADMaster/libxad/clients/Ace.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clients/Ace.c -------------------------------------------------------------------------------- /XADMaster/libxad/clients/DCS.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clients/DCS.c -------------------------------------------------------------------------------- /XADMaster/libxad/clients/FS_SOS.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clients/FS_SOS.c -------------------------------------------------------------------------------- /XADMaster/libxad/clients/LhF.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clients/LhF.c -------------------------------------------------------------------------------- /XADMaster/libxad/clients/MDC.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clients/MDC.c -------------------------------------------------------------------------------- /XADMaster/libxad/clients/MXM-SimpleArc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clients/MXM-SimpleArc.c -------------------------------------------------------------------------------- /XADMaster/libxad/clients/PackDev.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clients/PackDev.c -------------------------------------------------------------------------------- /XADMaster/libxad/clients/PackDisk.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clients/PackDisk.c -------------------------------------------------------------------------------- /XADMaster/libxad/clients/SuperDuper3.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clients/SuperDuper3.c -------------------------------------------------------------------------------- /XADMaster/libxad/clients/Tar.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clients/Tar.c -------------------------------------------------------------------------------- /XADMaster/libxad/clients/Zoom.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clients/Zoom.c -------------------------------------------------------------------------------- /XADMaster/libxad/clients/xDisk.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clients/xDisk.c -------------------------------------------------------------------------------- /XADMaster/libxad/clients/xMash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clients/xMash.c -------------------------------------------------------------------------------- /XADMaster/libxad/clients/xadCRC_1021.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clients/xadCRC_1021.c -------------------------------------------------------------------------------- /XADMaster/libxad/clients/xadIO.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clients/xadIO.c -------------------------------------------------------------------------------- /XADMaster/libxad/clients/xadIO.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clients/xadIO.h -------------------------------------------------------------------------------- /XADMaster/libxad/clients/xadIO_Compress.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/clients/xadIO_Compress.c -------------------------------------------------------------------------------- /XADMaster/libxad/copymem.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/copymem.c -------------------------------------------------------------------------------- /XADMaster/libxad/crc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/crc.c -------------------------------------------------------------------------------- /XADMaster/libxad/debug.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/debug.c -------------------------------------------------------------------------------- /XADMaster/libxad/diskunarc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/diskunarc.c -------------------------------------------------------------------------------- /XADMaster/libxad/error.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/error.c -------------------------------------------------------------------------------- /XADMaster/libxad/fileunarc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/fileunarc.c -------------------------------------------------------------------------------- /XADMaster/libxad/hook_diskarc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/hook_diskarc.c -------------------------------------------------------------------------------- /XADMaster/libxad/hook_mem.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/hook_mem.c -------------------------------------------------------------------------------- /XADMaster/libxad/hook_stream.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/hook_stream.c -------------------------------------------------------------------------------- /XADMaster/libxad/include/ConvertE.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/include/ConvertE.c -------------------------------------------------------------------------------- /XADMaster/libxad/include/SDI_compiler.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/include/SDI_compiler.h -------------------------------------------------------------------------------- /XADMaster/libxad/include/functions.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/include/functions.h -------------------------------------------------------------------------------- /XADMaster/libxad/include/privdefs.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/include/privdefs.h -------------------------------------------------------------------------------- /XADMaster/libxad/include/version.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/include/version.h -------------------------------------------------------------------------------- /XADMaster/libxad/include/xadmaster.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/include/xadmaster.h -------------------------------------------------------------------------------- /XADMaster/libxad/info.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/info.c -------------------------------------------------------------------------------- /XADMaster/libxad/protection.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/protection.c -------------------------------------------------------------------------------- /XADMaster/libxad/unix/emulation.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/unix/emulation.h -------------------------------------------------------------------------------- /XADMaster/libxad/unix/hook_fh.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/unix/hook_fh.c -------------------------------------------------------------------------------- /XADMaster/libxad/unix/init.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/unix/init.c -------------------------------------------------------------------------------- /XADMaster/libxad/unix/xadClient.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashang/unar/473488cc612c3f47e1c76f9baf92d268db259dc1/XADMaster/libxad/unix/xadClient.h -------------------------------------------------------------------------------- /XADMaster/wavpack/wavpack_version.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////// 2 | // **** WAVPACK **** // 3 | // Hybrid Lossless Wavefile Compressor // 4 | // Copyright (c) 1998 - 2006 Conifer Software. // 5 | // All Rights Reserved. // 6 | // Distributed under the BSD Software License (see license.txt) // 7 | //////////////////////////////////////////////////////////////////////////// 8 | 9 | // wavpack_version.h 10 | 11 | #ifndef WAVPACK_VERSION_H 12 | #define WAVPACK_VERSION_H 13 | 14 | #define LIBWAVPACK_MAJOR 4 15 | #define LIBWAVPACK_MINOR 60 16 | #define LIBWAVPACK_MICRO 1 17 | #define LIBWAVPACK_VERSION_STRING "4.60.1" 18 | 19 | #endif 20 | --------------------------------------------------------------------------------