├── .gitignore ├── CREDITS ├── LICENSE ├── Makefile.frag ├── README.md ├── appveyor.bat ├── appveyor.yml ├── azure-pipelines.yml ├── azure-template.yml ├── composer.json ├── config.m4 ├── config.w32 ├── example.php ├── extflow.txt ├── package.xml ├── php-rar.config ├── php-rar.creator ├── php-rar.files ├── php-rar.includes ├── php_compat.h ├── php_rar.h ├── rar.c ├── rar_error.c ├── rar_navigation.c ├── rar_stream.c ├── rar_time.c ├── rararch.c ├── rarentry.c ├── report.xml ├── run-tests8.php ├── technote.txt ├── test_funcs.sh ├── tests ├── 001.phpt ├── 002.phpt ├── 003.phpt ├── 004.phpt ├── 005.phpt ├── 006.phpt ├── 007.phpt ├── 008.phpt ├── 009.phpt ├── 010.phpt ├── 011.phpt ├── 012.phpt ├── 013.phpt ├── 014.phpt ├── 015.phpt ├── 016.phpt ├── 017.phpt ├── 018.phpt ├── 019.phpt ├── 020.phpt ├── 021.phpt ├── 022.phpt ├── 023.phpt ├── 024.phpt ├── 025.phpt ├── 026.phpt ├── 027.phpt ├── 028.phpt ├── 029.phpt ├── 030.phpt ├── 031.phpt ├── 032.phpt ├── 033.phpt ├── 034.phpt ├── 035.phpt ├── 036.phpt ├── 037.phpt ├── 038.phpt ├── 039.phpt ├── 040.phpt ├── 041.phpt ├── 042.phpt ├── 043.phpt ├── 044.phpt ├── 045.phpt ├── 046.phpt ├── 047.phpt ├── 048.phpt ├── 049.phpt ├── 050.phpt ├── 051.phpt ├── 052.phpt ├── 053.phpt ├── 054.phpt ├── 055.phpt ├── 056.phpt ├── 057.phpt ├── 058.phpt ├── 059.phpt ├── 060.phpt ├── 061.phpt ├── 062.phpt ├── 063.phpt ├── 064.phpt ├── 065.phpt ├── 066.phpt ├── 067.phpt ├── 068.phpt ├── 069.phpt ├── 070.phpt ├── 071.phpt ├── 072.phpt ├── 073.phpt ├── 074.phpt ├── 075.phpt ├── 076.phpt ├── 077.phpt ├── 078.phpt ├── 079.phpt ├── 080.phpt ├── 081.phpt ├── 082.phpt ├── 083.phpt ├── 084.phpt ├── 085.phpt ├── 086.phpt ├── 087.phpt ├── 088.phpt ├── 089.phpt ├── 090.phpt ├── 091.phpt ├── 092.phpt ├── 093.phpt ├── 094.phpt ├── 095.phpt ├── 096.phpt ├── 097.phpt ├── 098.phpt ├── 099.phpt ├── 100.phpt ├── 101.phpt ├── 102.phpt ├── 103.phpt ├── 104.phpt ├── 105.phpt ├── 106.phpt ├── 107.phpt ├── 108.phpt ├── 109.phpt ├── 110.phpt ├── 111.phpt ├── 112.phpt ├── 113.phpt ├── 114.phpt ├── 115.phpt ├── 4mb.rar ├── commented.rar ├── corrupted.rar ├── directories.rar ├── dirlink_unix.rar ├── dirs_and_extra_headers.rar ├── empty_file.rar ├── encrypted_headers.rar ├── encrypted_only_files.rar ├── garbage.part03.rar ├── latest_winrar.rar ├── linux_rar.rar ├── multi.part1.rar ├── multi.part2.rar ├── multi.part3.rar ├── multi_broken.part1.rar ├── php8compat.php.inc ├── rar5-links.rar ├── rar5_multi.part1.rar ├── rar5_multi.part2.rar ├── rar_notrar.rar ├── rar_unicode.rar ├── repeated_name.rar ├── secret-crypted-none.rar ├── secret-none.rar ├── solid.rar ├── sparsefiles_rar.rar └── store_method.rar ├── unrar ├── LICENSE.txt ├── README.txt ├── UnRAR.vcxproj ├── UnRARDll.vcxproj ├── acknow.txt ├── arccmt.cpp ├── archive.cpp ├── archive.hpp ├── arcread.cpp ├── array.hpp ├── blake2s.cpp ├── blake2s.hpp ├── blake2s_sse.cpp ├── blake2sp.cpp ├── cmddata.cpp ├── cmddata.hpp ├── cmdfilter.cpp ├── cmdmix.cpp ├── coder.cpp ├── coder.hpp ├── compress.hpp ├── consio.cpp ├── consio.hpp ├── crc.cpp ├── crc.hpp ├── crypt.cpp ├── crypt.hpp ├── crypt1.cpp ├── crypt2.cpp ├── crypt2.loT ├── crypt3.cpp ├── crypt5.cpp ├── dll.cpp ├── dll.hpp ├── dll.rc ├── dll_nocrypt.def ├── encname.cpp ├── encname.hpp ├── errhnd.cpp ├── errhnd.hpp ├── extinfo.cpp ├── extinfo.hpp ├── extract.cpp ├── extract.hpp ├── extractchunk.cpp ├── filcreat.cpp ├── filcreat.hpp ├── file.cpp ├── file.hpp ├── filefn.cpp ├── filefn.hpp ├── filestr.cpp ├── filestr.hpp ├── find.cpp ├── find.hpp ├── getbits.cpp ├── getbits.hpp ├── global.cpp ├── global.hpp ├── hardlinks.cpp ├── hash.cpp ├── hash.hpp ├── headers.cpp ├── headers.hpp ├── headers5.hpp ├── isnt.cpp ├── isnt.hpp ├── list.cpp ├── list.hpp ├── loclang.hpp ├── log.cpp ├── log.hpp ├── makefile ├── match.cpp ├── match.hpp ├── model.cpp ├── model.hpp ├── options.cpp ├── options.hpp ├── os.hpp ├── pathfn.cpp ├── pathfn.hpp ├── qopen.cpp ├── qopen.hpp ├── rar.cpp ├── rar.hpp ├── rardefs.hpp ├── rarlang.hpp ├── raros.hpp ├── rartypes.hpp ├── rarvm.cpp ├── rarvm.hpp ├── rawint.hpp ├── rawread.cpp ├── rawread.hpp ├── rdwrfn.cpp ├── rdwrfn.hpp ├── recvol.cpp ├── recvol.hpp ├── recvol3.cpp ├── recvol5.cpp ├── resource.cpp ├── resource.hpp ├── rijndael.cpp ├── rijndael.hpp ├── rs.cpp ├── rs.hpp ├── rs16.cpp ├── rs16.hpp ├── savepos.hpp ├── scantree.cpp ├── scantree.hpp ├── secpassword.cpp ├── secpassword.hpp ├── sha1.cpp ├── sha1.hpp ├── sha256.cpp ├── sha256.hpp ├── smallfn.cpp ├── smallfn.hpp ├── strfn.cpp ├── strfn.hpp ├── strlist.cpp ├── strlist.hpp ├── suballoc.cpp ├── suballoc.hpp ├── system.cpp ├── system.hpp ├── threadmisc.cpp ├── threadpool.cpp ├── threadpool.hpp ├── timefn.cpp ├── timefn.hpp ├── ui.cpp ├── ui.hpp ├── uicommon.cpp ├── uiconsole.cpp ├── uisilent.cpp ├── ulinks.cpp ├── unicode.cpp ├── unicode.hpp ├── unpack.cpp ├── unpack.hpp ├── unpack15.cpp ├── unpack20.cpp ├── unpack30.cpp ├── unpack50.cpp ├── unpack50frag.cpp ├── unpack50mt.cpp ├── unpackinline.cpp ├── uowners.cpp ├── uowners.loT ├── version.hpp ├── volume.cpp ├── volume.hpp ├── win32acl.cpp ├── win32lnk.cpp └── win32stm.cpp ├── unrardll.txt └── valgrind.supp /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.lo 3 | /tests/*.sh 4 | /tests/*.exp 5 | /tests/*.diff 6 | /tests/*.log 7 | /tests/*.php 8 | /tests/*.out 9 | /tests/*.mem 10 | /run-tests.php 11 | /modules 12 | /missing 13 | /.deps 14 | /.libs 15 | /Makefile 16 | /Makefile.fragments 17 | /Makefile.global 18 | /Makefile.objects 19 | /acinclude.m4 20 | /aclocal.m4 21 | /autom4te.cache 22 | /build 23 | /config.guess 24 | /config.h 25 | /config.h.in 26 | /config.h.in~ 27 | /config.log 28 | /config.nice 29 | /config.status 30 | /config.sub 31 | /configure 32 | /configure.in 33 | /configure.ac 34 | /install-sh 35 | /intl.la 36 | /libtool 37 | /mkinstalldirs 38 | /ltmain.sh 39 | /.cproject 40 | /.project 41 | /.settings 42 | /pecl-rar.* 43 | /rar.la 44 | *.autosave 45 | /unrar/.libs 46 | /tmp-php.ini 47 | /php-rar.creator.user 48 | /compile_commands.json 49 | /.clangd 50 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | RAR 2 | Antony Dovgal, Gustavo Lopes 3 | -------------------------------------------------------------------------------- /Makefile.frag: -------------------------------------------------------------------------------- 1 | replace-run-tests: 2 | @if ! grep -q 'Minimum required PHP version: 5\.3\.0' run-tests.php; then \ 3 | cp run-tests8.php run-tests.php; \ 4 | fi 5 | 6 | test: replace-run-tests 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PHP extension for reading RAR archives using the bundled UnRAR library. 2 | 3 | This extension uses a modified version of the UnRAR library. The UnRAR library 4 | is an official open-source library by RARLabs, an auto generated subset of the 5 | RAR codebase. It is available from http://www.rarlab.com/rar_add.htm 6 | Please note that it has a more restrictive license than the PHP bindings, 7 | barring using it to re-create the RAR compression algorithm. See 8 | unrar/LICENSE.txt for details. 9 | 10 | Some modifications have been applied to the UnRAR library, mainly to allow 11 | streaming extraction of files without using threads. 12 | 13 | [![Build Status Appveyor](https://ci.appveyor.com/api/projects/status/cbgpepx6kyax2198/branch/master?svg=true)](https://ci.appveyor.com/project/cataphract/php-rar/branch/master) 14 | [![Build Status Travis](https://travis-ci.org/cataphract/php-rar.svg?branch=master)](https://travis-ci.org/cataphract/php-rar) 15 | [![codecov](https://codecov.io/gh/cataphract/php-rar/branch/master/graph/badge.svg)](https://codecov.io/gh/cataphract/php-rar) 16 | -------------------------------------------------------------------------------- /appveyor.bat: -------------------------------------------------------------------------------- 1 | echo Running appveyor.bat 2 | echo on 3 | 4 | CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat" 5 | 6 | IF NOT EXIST "C:\projects\php-sdk" ( 7 | wget -nv http://windows.php.net/downloads/php-sdk/php-sdk-binary-tools-20110915.zip 8 | 7z x -y php-sdk-binary-tools-20110915.zip -oC:\projects\php-sdk 9 | ) 10 | IF NOT EXIST "C:\projects\php-src\Release_TS\php7ts.lib" ( 11 | git clone --depth=1 --branch=PHP-7.1 https://github.com/php/php-src C:\projects\php-src 12 | wget -nv http://windows.php.net/downloads/php-sdk/deps-7.1-vc14-x86.7z 13 | 7z x -y deps-7.1-vc14-x86.7z -oC:\projects\php-src 14 | CALL C:\projects\php-sdk\bin\phpsdk_setvars.bat 15 | cd C:\projects\php-src 16 | CALL buildconf.bat 17 | CALL configure.bat --disable-all --enable-cli --with-config-file-scan-dir=C:\projects\extension\bin\modules.d --with-prefix=%APPVEYOR_BUILD_FOLDER%\bin --with-php-build=deps 18 | nmake 19 | ) ELSE ( 20 | echo php7ts.lib already exists 21 | cd C:\projects\php-src 22 | CALL C:\projects\php-sdk\bin\phpsdk_setvars.bat 23 | ) 24 | 25 | CALL buildconf.bat --force --add-modules-dir=%APPVEYOR_BUILD_FOLDER%\.. 26 | CALL configure.bat --disable-all --enable-cli --enable-rar=shared --with-config-file-scan-dir=C:\projects\extension\bin\modules.d --with-prefix=%APPVEYOR_BUILD_FOLDER%\bin --with-php-build=deps 27 | nmake || exit /b 28 | rmdir Release_TS\php-rar /S /Q 29 | del /S /Q "Release_TS\*.sbr" 30 | 31 | copy %APPVEYOR_BUILD_FOLDER%\run-tests8.php C:\projects\php-src\run-tests.php 32 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # Based on igbinary's appveyor config. 2 | 3 | version: '{branch}.{build}' 4 | install: 5 | - cmd: choco feature enable -n=allowGlobalConfirmation 6 | - cmd: cinst wget 7 | - cmd: mkdir %APPVEYOR_BUILD_FOLDER%\bin 8 | 9 | build_script: 10 | - cmd: "%APPVEYOR_BUILD_FOLDER%\\appveyor.bat" 11 | 12 | test_script: 13 | - cmd: cd C:\projects\php-src 14 | - cmd: set NO_INTERACTION=1 15 | - cmd: set REPORT_EXIT_STATUS=1 16 | - cmd: set TZ=UTC 17 | - cmd: 'nmake test TESTS="--show-diff --set-timeout 30 -d extension=C:\projects\php-src\Release_TS\php_rar.dll %APPVEYOR_BUILD_FOLDER%\tests"' 18 | 19 | after_test: 20 | # - cmd: dir /S C:\projects\php-src\Release_TS 21 | - cmd: 'del C:\projects\php-src\Release_TS\php_rar.*' 22 | 23 | cache: 24 | - C:\ProgramData\chocolatey\lib -> appveyor.yml 25 | - C:\projects\php-src 26 | - C:\projects\php-sdk 27 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | - template: azure-template.yml 3 | parameters: 4 | name: php_5_3_valgrind 5 | displayName: PHP 5.3 ZTS (valgrind, clang) 6 | phpVersion: '5.3' 7 | clang: true 8 | valgrind: true 9 | zts: true 10 | 11 | - template: azure-template.yml 12 | parameters: 13 | name: php_5_4 14 | displayName: PHP 5.4 15 | phpVersion: '5.4' 16 | 17 | - template: azure-template.yml 18 | parameters: 19 | name: php_5_5 20 | displayName: PHP 5.5 21 | phpVersion: '5.5' 22 | 23 | - template: azure-template.yml 24 | parameters: 25 | name: php_5_6 26 | displayName: PHP 5.6 27 | phpVersion: '5.6' 28 | 29 | - template: azure-template.yml 30 | parameters: 31 | name: php_5_6_valgrind 32 | displayName: PHP 5.6 ZTS (valgrind, clang) 33 | phpVersion: '5.6' 34 | clang: true 35 | valgrind: true 36 | zts: true 37 | 38 | - template: azure-template.yml 39 | parameters: 40 | name: php_7_0 41 | displayName: PHP 7.0 42 | phpVersion: '7.0' 43 | 44 | - template: azure-template.yml 45 | parameters: 46 | name: php_7_1 47 | displayName: PHP 7.1 48 | phpVersion: '7.1' 49 | 50 | - template: azure-template.yml 51 | parameters: 52 | name: php_7_2 53 | displayName: PHP 7.2 54 | phpVersion: '7.2' 55 | 56 | - template: azure-template.yml 57 | parameters: 58 | name: php_7_3 59 | displayName: PHP 7.3 60 | phpVersion: '7.3' 61 | 62 | - template: azure-template.yml 63 | parameters: 64 | name: php_7_4 65 | displayName: PHP 7.4 ZTS (valgrind, clang) 66 | phpVersion: '7.4' 67 | clang: true 68 | valgrind: true 69 | zts: true 70 | 71 | - template: azure-template.yml 72 | parameters: 73 | name: php_8_0 74 | displayName: PHP 8.0 ZTS 75 | phpVersion: '8.0' 76 | zts: true 77 | publishCoverage: true 78 | 79 | - template: azure-template.yml 80 | parameters: 81 | name: php_8_0_valgrind 82 | displayName: PHP 8.0 (valgrind, clang) 83 | phpVersion: '8.0' 84 | clang: true 85 | valgrind: true 86 | -------------------------------------------------------------------------------- /azure-template.yml: -------------------------------------------------------------------------------- 1 | parameters: 2 | name: ~ 3 | displayName: ~ 4 | phpVersion: bundled 5 | imageName: ubuntu-20.04 6 | zts: false 7 | clang: false 8 | publishCoverage: false 9 | valgrind: false 10 | 11 | jobs: 12 | - job: ${{ parameters.name }} 13 | displayName: ${{ parameters.displayName }} 14 | pool: 15 | vmImage: ${{ parameters.imageName }} 16 | 17 | variables: 18 | ${{ if eq(parameters.clang, true) }}: 19 | CC: clang 20 | CXX: clang++ 21 | 22 | steps: 23 | - checkout: self 24 | displayName: Checkout 25 | clean: true 26 | submodules: recursive 27 | 28 | - bash: | 29 | source test_funcs.sh 30 | install_php ${{ parameters.phpVersion }} ${{ parameters.zts }} 31 | displayName: Install PHP ${{ parameters.phpVersion }} 32 | 33 | - ${{ if eq(parameters.valgrind, true) }}: 34 | - bash: > 35 | sudo apt-get install valgrind 36 | displayName: "Install Valgrind" 37 | 38 | - script: | 39 | source test_funcs.sh 40 | build_ext ${{ parameters.phpVersion }} ${{ parameters.zts }} ${{ parameters.publishCoverage }} 41 | displayName: Build extension 42 | 43 | - script: | 44 | source test_funcs.sh 45 | run_tests ${{ parameters.phpVersion }} ${{ parameters.zts }} ${{ parameters.publishCoverage }} 46 | ${{ if eq(parameters.valgrind, true) }}: 47 | env: 48 | RUN_TESTS_FLAGS: -m 49 | displayName: Run tests 50 | 51 | - task: PublishTestResults@2 52 | displayName: Publish test results 53 | condition: succeededOrFailed() 54 | inputs: 55 | testResultsFormat: 'JUnit' 56 | testResultsFiles: 'report.xml' 57 | searchFolder: '$(System.DefaultWorkingDirectory)' 58 | mergeTestResults: true 59 | 60 | - ${{ if eq(parameters.publishCoverage, true) }}: 61 | - bash: > 62 | bash <(curl -s https://codecov.io/bash) 63 | displayName: "Publish coverage (Codecov)" 64 | env: 65 | CODECOV_TOKEN: $(CODECOV_TOKEN) 66 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rar", 3 | "type": "extension", 4 | "license": [ 5 | "PHP License" 6 | ], 7 | "authors": [ 8 | { 9 | "name": "Gustavo Lopes", 10 | "email": "cataphract@php.net" 11 | }, 12 | { 13 | "name": "Antony Dovgal", 14 | "email": "tony@daylessday.org" 15 | } 16 | ], 17 | "description": "rar extension" 18 | } -------------------------------------------------------------------------------- /config.w32: -------------------------------------------------------------------------------- 1 | // $Id$ 2 | // vim:ft=javascript 3 | 4 | ARG_ENABLE("rar", "Rar support", "no"); 5 | 6 | if (PHP_RAR != "no") { 7 | EXTENSION("rar", "rar.c rar_error.c rararch.c rarentry.c rar_stream.c rar_navigation.c rar_time.c", PHP_RAR_SHARED, "/DRARDLL /DSILENT /EHsc /D_WSTDIO_DEFINED"); 8 | ADD_SOURCES(configure_module_dirname + "/unrar", 9 | "sha256.cpp qopen.cpp \ 10 | blake2s.cpp recvol.cpp \ 11 | headers.cpp match.cpp \ 12 | find.cpp \ 13 | resource.cpp \ 14 | pathfn.cpp \ 15 | dll.cpp threadpool.cpp volume.cpp \ 16 | unpack.cpp \ 17 | extract.cpp errhnd.cpp \ 18 | crc.cpp rijndael.cpp crypt.cpp \ 19 | rawread.cpp \ 20 | rs.cpp smallfn.cpp \ 21 | isnt.cpp rar.cpp consio.cpp \ 22 | scantree.cpp archive.cpp strfn.cpp \ 23 | strlist.cpp \ 24 | getbits.cpp hash.cpp \ 25 | filestr.cpp \ 26 | extinfo.cpp ui.cpp rarvm.cpp \ 27 | timefn.cpp sha1.cpp \ 28 | rdwrfn.cpp rs16.cpp cmddata.cpp \ 29 | extractchunk.cpp system.cpp \ 30 | unicode.cpp filcreat.cpp \ 31 | arcread.cpp filefn.cpp \ 32 | global.cpp list.cpp \ 33 | encname.cpp file.cpp \ 34 | secpassword.cpp options.cpp", "rar"); 35 | 36 | AC_DEFINE("HAVE_RAR", 1, "Rar support"); 37 | } 38 | -------------------------------------------------------------------------------- /example.php: -------------------------------------------------------------------------------- 1 | extract($dir_to_extract_to); 14 | /* OR */ 15 | 16 | // this will create only one new file $new_entry_name in $dir_to_extract_to 17 | $entry->extract('', $dir_to_extract_to.'/'.$new_entry_name); 18 | 19 | // this line is really not necessary 20 | rar_close($rar); 21 | 22 | ?> 23 | -------------------------------------------------------------------------------- /php-rar.config: -------------------------------------------------------------------------------- 1 | // Add predefined macros for your project here. For example: 2 | // #define THE_ANSWER 42 3 | #define RARDLL 1 4 | #define HAVE_CONFIG_H 1 5 | #define _Float32 float 6 | #define _Float32x float 7 | #define _Float64 double 8 | #define _Float64x double 9 | #define _Float128 long double 10 | #define _Float128x long double 11 | #define _BITS_FLOATN_H 12 | -------------------------------------------------------------------------------- /php-rar.creator: -------------------------------------------------------------------------------- 1 | [General] 2 | -------------------------------------------------------------------------------- /php-rar.includes: -------------------------------------------------------------------------------- 1 | /home/glopes/repos/php-src/Zend 2 | /home/glopes/repos/php-src/TSRM 3 | /home/glopes/repos/php-src/main 4 | /home/glopes/repos/php-src 5 | -------------------------------------------------------------------------------- /php_compat.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if PHP_MAJOR_VERSION >= 8 4 | # define TSRMLS_DC 5 | # define TSRMLS_D 6 | # define TSRMLS_CC 7 | # define TSRMLS_C 8 | # define TSRMLS_FETCH() 9 | # define IS_CALLABLE_STRICT 0 10 | # define zend_qsort zend_sort 11 | # define ZV_TO_THIS_FOR_HANDLER(zv) (Z_OBJ_P(zv)) 12 | typedef zend_object handler_this_t; 13 | #else 14 | # define ZV_TO_THIS_FOR_HANDLER(zv) (zv) 15 | typedef zval handler_this_t; 16 | #endif 17 | 18 | #if PHP_MAJOR_VERSION >= 7 19 | typedef zend_object* rar_obj_ref; 20 | 21 | #define rar_zval_add_ref(ppzv) zval_add_ref(*ppzv) 22 | 23 | #define ZVAL_ALLOC_DUP(dst, src) \ 24 | do { \ 25 | dst = (zval*) emalloc(sizeof(zval)); \ 26 | ZVAL_DUP(dst, src); \ 27 | } while (0) 28 | 29 | #define RAR_RETURN_STRINGL(s, l, duplicate) \ 30 | do { \ 31 | RETVAL_STRINGL(s, l); \ 32 | if (duplicate == 0) { \ 33 | efree(s); \ 34 | } \ 35 | return; \ 36 | } while (0) 37 | 38 | #define RAR_ZVAL_STRING(z, s, duplicate) \ 39 | do { \ 40 | ZVAL_STRING(z, s); \ 41 | if (duplicate == 0) { \ 42 | efree(s); \ 43 | } \ 44 | } while (0) 45 | 46 | typedef size_t zpp_s_size_t; 47 | 48 | #define MAKE_STD_ZVAL(zv_p) \ 49 | do { \ 50 | (zv_p) = emalloc(sizeof(zval)); \ 51 | ZVAL_NULL(zv_p); \ 52 | } while (0) 53 | #define INIT_ZVAL(zv) ZVAL_UNDEF(&zv) 54 | 55 | #define ZEND_ACC_FINAL_CLASS ZEND_ACC_FINAL 56 | 57 | #else /* PHP 5.x */ 58 | typedef zend_object_handle rar_obj_ref; 59 | 60 | #define rar_zval_add_ref zval_add_ref 61 | #define ZVAL_ALLOC_DUP(dst, src) \ 62 | do { \ 63 | zval *z_src = src; \ 64 | dst = z_src; \ 65 | zval_add_ref(&dst); \ 66 | SEPARATE_ZVAL(&dst); \ 67 | } while (0) 68 | #define RAR_ZVAL_STRING ZVAL_STRING 69 | #define RAR_RETURN_STRINGL(s, l, duplicate) RETURN_STRINGL(s, l, duplicate) 70 | typedef int zpp_s_size_t; 71 | #define zend_hash_str_del zend_hash_del 72 | #endif 73 | -------------------------------------------------------------------------------- /rar_time.c: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | #include 6 | #include "php_rar.h" 7 | 8 | void rar_time_convert(unsigned low, unsigned high, time_t *to) /* {{{ */ 9 | { 10 | time_t default_ = (time_t) 0, 11 | local_time; 12 | struct tm tm = {0}; 13 | TSRMLS_FETCH(); 14 | 15 | if (high == 0U && low == 0U) { 16 | *to = default_; 17 | return; 18 | } 19 | 20 | /* 11644473600000000000 - number of ns between 01-01-1601 and 01-01-1970. */ 21 | uint64 ushift=INT32TO64(0xA1997B0B,0x4C6A0000); 22 | 23 | /* value is in 10^-7 seconds since 01-01-1601 */ 24 | /* convert to nanoseconds, shift to 01-01-1970 and convert to seconds */ 25 | local_time = (time_t) ((INT32TO64(high, low) * 100 - ushift) / 1000000000); 26 | 27 | /* now we have the time in... I don't know what. It gives UTC - tz offset */ 28 | /* we need to try and convert it to UTC */ 29 | /* abuse gmtime, which is supposed to work with UTC */ 30 | if (php_gmtime_r(&local_time, &tm) == NULL) { 31 | php_error_docref(NULL TSRMLS_CC, E_WARNING, 32 | "Could not convert time to UTC, using local time"); 33 | *to = local_time; 34 | } 35 | 36 | tm.tm_isdst = -1; 37 | *to = local_time + (local_time - mktime(&tm)); 38 | } 39 | /* }}} */ 40 | 41 | int rar_dos_time_convert(unsigned dos_time, time_t *to) /* {{{ */ 42 | { 43 | struct tm time_s = {0}; 44 | 45 | time_s.tm_sec = (dos_time & 0x1f)*2; 46 | time_s.tm_min = (dos_time>>5) & 0x3f; 47 | time_s.tm_hour = (dos_time>>11) & 0x1f; 48 | time_s.tm_mday = (dos_time>>16) & 0x1f; 49 | time_s.tm_mon = ((dos_time>>21) & 0x0f) - 1; 50 | time_s.tm_year = (dos_time>>25) + 80; 51 | /* the dos times that unrar gives out seem to be already in UTC. 52 | * Or at least they don't depend on TZ */ 53 | if ((*to = timegm(&time_s)) == (time_t) -1) { 54 | return FAILURE; 55 | } 56 | 57 | return SUCCESS; 58 | } 59 | /* }}} */ 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | -------------------------------------------------------------------------------- /report.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/report.xml -------------------------------------------------------------------------------- /test_funcs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | JOBS=3 4 | 5 | function package_name { 6 | local readonly version=$1 zts=$2 7 | local zts_suffix='' 8 | if [[ $zts = 'true' ]]; then 9 | zts_suffix='-zts' 10 | fi 11 | 12 | echo "php-${version}${zts_suffix}-bare-dbg" 13 | } 14 | 15 | function prefix { 16 | local readonly version=$1 zts=$2 17 | 18 | echo "/opt/$(package_name $version $zts)" 19 | } 20 | 21 | function build_ext { 22 | local readonly version=$1 zts=$2 coverage=$3 23 | local readonly prefix=$(prefix $1 $2) 24 | local cflags= cxxflags= ldflags= 25 | "$prefix"/bin/phpize 26 | if [[ $coverage == true ]]; then 27 | cflags=--coverage 28 | cxxflags=--coverage 29 | ldflags=--coverage 30 | fi 31 | CFLAGS="$cflags" CXXFLAGS="$cxxflags" LDFLAGS="$ldflags" \ 32 | ./configure --with-php-config="$prefix/bin/php-config" 33 | make -j $JOBS 34 | } 35 | 36 | function do_tests { 37 | local readonly prefix=$1 38 | local found_leaks= dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 39 | local ret=0 40 | sed -i s/-@if/@if/ Makefile 41 | TEST_PHP_EXECUTABLE="$prefix/bin/php" \ 42 | TEST_PHP_JUNIT=report.xml \ 43 | REPORT_EXIT_STATUS=1 \ 44 | NO_INTERACTION=1 \ 45 | TESTS="--set-timeout 300 --show-diff $RUN_TESTS_FLAGS" make test \ 46 | || ret=$? 47 | found_leaks=$(find tests -name '*.mem' | wc -l) 48 | if [[ $found_leaks -gt 0 ]]; then 49 | echo "Found $found_leaks leaks. Failing." 50 | find tests -name "*.mem" -print -exec cat {} \; 51 | fi 52 | return $ret 53 | } 54 | 55 | function install_php { 56 | local readonly version=$1 zts=$2 57 | local readonly url="$MIRROR/php-$version.tar.gz" 58 | 59 | sudo apt-get install -y gnupg 60 | sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 5D98E7264E3F3D89463B314B12229434A9F003C9 61 | echo deb [arch=amd64] http://artefacto-test.s3.amazonaws.com/php-bare-dbg bionic main | sudo tee -a /etc/apt/sources.list 62 | sudo apt-get update 63 | sudo apt-get install -y $(package_name $version $zts) 64 | } 65 | 66 | function run_tests { 67 | set -e 68 | set -o pipefail 69 | do_tests "$(prefix $1 $2)" 70 | } 71 | -------------------------------------------------------------------------------- /tests/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | rar_open() function 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 19 | --EXPECTF-- 20 | object(RarArchive)#%d (%d) { 21 | } 22 | object(RarArchive)#%d (%d) { 23 | } 24 | 25 | Warning: rar_open(): Failed to open %sno_such_file.rar: ERAR_EOPEN (file open error) in %s on line %d 26 | bool(false) 27 | Done 28 | -------------------------------------------------------------------------------- /tests/003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | rar_entry_get() function 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 24 | --EXPECTF-- 25 | object(RarEntry)#%d (%d) { 26 | ["rarfile%sprivate%s=> 27 | object(RarArchive)#%d (%d) { 28 | } 29 | ["position%sprivate%s=> 30 | int(1) 31 | ["name%sprivate%s=> 32 | string(30) "test file with whitespaces.txt" 33 | ["unpacked_size%sprivate%s=> 34 | int(14) 35 | ["packed_size%sprivate%s=> 36 | int(20) 37 | ["host_os%sprivate%s=> 38 | int(3) 39 | ["file_time%sprivate%s=> 40 | string(19) "2004-06-11 11:01:32" 41 | ["crc%sprivate%s=> 42 | string(8) "21890dd9" 43 | ["attr%sprivate%s=> 44 | int(33188) 45 | ["version%sprivate%s=> 46 | int(29) 47 | ["method%sprivate%s=> 48 | int(51) 49 | ["flags%sprivate%s=> 50 | int(0) 51 | ["redir_type%sprivate%s=> 52 | int(0) 53 | ["redir_to_directory%sprivate%s=> 54 | NULL 55 | ["redir_target%sprivate%s=> 56 | NULL 57 | } 58 | object(RarEntry)#%d (%d) { 59 | ["rarfile%sprivate%s=> 60 | object(RarArchive)#%d (%d) { 61 | } 62 | ["position%sprivate%s=> 63 | int(1) 64 | ["name%sprivate%s=> 65 | string(5) "2.txt" 66 | ["unpacked_size%sprivate%s=> 67 | int(5) 68 | ["packed_size%sprivate%s=> 69 | int(16) 70 | ["host_os%sprivate%s=> 71 | int(2) 72 | ["file_time%sprivate%s=> 73 | string(19) "2004-06-11 10:07:26" 74 | ["crc%sprivate%s=> 75 | string(8) "45a918de" 76 | ["attr%sprivate%s=> 77 | int(32) 78 | ["version%sprivate%s=> 79 | int(29) 80 | ["method%sprivate%s=> 81 | int(53) 82 | ["flags%sprivate%s=> 83 | int(16) 84 | ["redir_type%sprivate%s=> 85 | int(0) 86 | ["redir_to_directory%sprivate%s=> 87 | NULL 88 | ["redir_target%sprivate%s=> 89 | NULL 90 | } 91 | 92 | Warning: rar_open(): Failed to open %s: ERAR_EOPEN (file open error) in %s on line %d 93 | 94 | Warning: rar_entry_get() expects parameter 1 to be RarArchive, boo%s given in %s on line %d 95 | Done 96 | -------------------------------------------------------------------------------- /tests/004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::extract() method 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | extract(dirname(__FILE__)); 12 | $contents11 = file_get_contents(dirname(__FILE__).'/test file with whitespaces.txt'); 13 | echo $contents11."\n"; 14 | @unlink(dirname(__FILE__).'/test file with whitespaces.txt'); 15 | 16 | $entry1->extract(false,dirname(__FILE__).'/1.txt'); 17 | $contents12 = file_get_contents(dirname(__FILE__).'/1.txt'); 18 | echo $contents12."\n"; 19 | @unlink(dirname(__FILE__).'/1.txt'); 20 | 21 | $rar_file2 = rar_open(dirname(__FILE__).'/latest_winrar.rar'); 22 | $entry2 = rar_entry_get($rar_file2, '2.txt'); 23 | 24 | $entry2->extract(dirname(__FILE__)); 25 | $contents21 = file_get_contents(dirname(__FILE__).'/2.txt'); 26 | echo $contents21."\n"; 27 | @unlink(dirname(__FILE__).'/2.txt'); 28 | 29 | $entry2->extract(false,dirname(__FILE__).'/some.txt'); 30 | $contents22 = file_get_contents(dirname(__FILE__).'/some.txt'); 31 | echo $contents22."\n"; 32 | @unlink(dirname(__FILE__).'/some.txt'); 33 | 34 | $entry2->extract(dirname(__FILE__)); 35 | var_dump(file_get_contents(dirname(__FILE__).'/2.txt')); 36 | @unlink(dirname(__FILE__).'/2.txt'); 37 | 38 | $oldcwd = getcwd(); 39 | chdir(dirname(__FILE__)); 40 | 41 | var_dump($entry2); 42 | var_dump($entry2->extract("","")); 43 | 44 | @unlink('2.txt'); 45 | 46 | chdir($oldcwd); 47 | 48 | echo "Done\n"; 49 | ?> 50 | --EXPECTF-- 51 | blah-blah-blah 52 | blah-blah-blah 53 | 22222 54 | 22222 55 | string(5) "22222" 56 | object(RarEntry)#%d (%d) { 57 | ["rarfile%sprivate%s=> 58 | object(RarArchive)#%d (%d) { 59 | } 60 | ["position%sprivate%s=> 61 | int(1) 62 | ["name%sprivate%s=> 63 | string(5) "2.txt" 64 | ["unpacked_size%sprivate%s=> 65 | int(5) 66 | ["packed_size%sprivate%s=> 67 | int(16) 68 | ["host_os%sprivate%s=> 69 | int(2) 70 | ["file_time%sprivate%s=> 71 | string(19) "2004-06-11 10:07:26" 72 | ["crc%sprivate%s=> 73 | string(8) "45a918de" 74 | ["attr%sprivate%s=> 75 | int(32) 76 | ["version%sprivate%s=> 77 | int(29) 78 | ["method%sprivate%s=> 79 | int(53) 80 | ["flags%sprivate%s=> 81 | int(16) 82 | ["redir_type%sprivate%s=> 83 | int(0) 84 | ["redir_to_directory%sprivate%s=> 85 | NULL 86 | ["redir_target%sprivate%s=> 87 | NULL 88 | } 89 | bool(true) 90 | Done 91 | -------------------------------------------------------------------------------- /tests/005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | rar_comment_get() function 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getComment()); 14 | echo "\n"; 15 | 16 | $rar_file2 = rar_open(dirname(__FILE__).'/linux_rar.rar'); 17 | var_export(rar_comment_get($rar_file2)); 18 | echo "\n"; 19 | rar_close($rar_file2); 20 | var_export(rar_comment_get($rar_file2)); 21 | echo "\n"; 22 | 23 | 24 | 25 | 26 | echo "Done\n"; 27 | ?> 28 | --EXPECTF-- 29 | 'This is the comment of the file commented.rar.' 30 | 'This is the comment of the file commented.rar.' 31 | 'This is the comment of the file commented.rar.' 32 | NULL 33 | 34 | Warning: rar_comment_get(): The archive is already closed in %s on line %d 35 | false 36 | Done 37 | -------------------------------------------------------------------------------- /tests/006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getCrc() method in multi-volume archives (PECL bug #9470) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getCrc()."\n"; 11 | echo $list[1]->getCrc()."\n"; 12 | echo $list[2]->getCrc()."\n"; 13 | echo "\n"; 14 | 15 | echo "Done\n"; 16 | ?> 17 | --EXPECTF-- 18 | 52b28202 19 | f2c79881 20 | bcbce32e 21 | 22 | Done 23 | -------------------------------------------------------------------------------- /tests/007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | rar_open() function with a non-RAR 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 14 | --EXPECTF-- 15 | Warning: rar_open(): Failed to open %s: ERAR_BAD_ARCHIVE in %s on line %d 16 | bool(false) 17 | 18 | Done 19 | -------------------------------------------------------------------------------- /tests/008.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | rar_entry_get() function 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 25 | --EXPECTF-- 26 | RarEntry for file "file1.txt" (52b28202) 27 | 28 | Warning: rar_entry_get(): cannot find file "nonexistent_file.txt" in Rar archive "%s" in %s on line %d 29 | bool(false) 30 | 31 | 32 | Warning: rar_open(): Failed to open %s: ERAR_EOPEN (file open error) in %s on line %d 33 | 34 | Warning: rar_entry_get() expects parameter 1 to be RarArchive, boo%s given in %s on line %d 35 | 36 | Done 37 | -------------------------------------------------------------------------------- /tests/009.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getName() function with unicode filenames 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getName(); 11 | var_dump($name); 12 | echo "\n"; 13 | 14 | echo "Done\n"; 15 | ?> 16 | --EXPECTF-- 17 | string(13) "file1À۞.txt" 18 | 19 | Done 20 | -------------------------------------------------------------------------------- /tests/010.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getStream() function (good RAR file, one volume) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getStream(); 14 | echo $e->getName().":\n"; 15 | while (!feof($stream)) { 16 | echo fread($stream, 8192); 17 | } 18 | echo "\n\n"; 19 | } 20 | 21 | echo "Done\n"; 22 | ?> 23 | --EXPECTF-- 24 | 2 files: 25 | 26 | 1.txt: 27 | 11111 28 | 29 | 2.txt: 30 | 22222 31 | 32 | Done 33 | -------------------------------------------------------------------------------- /tests/011.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getStream() function (good RAR file, several volumes) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getStream(); 18 | if ($stream === false) { 19 | die("Failed to get stream.\n"); 20 | break; 21 | } 22 | echo $e->getName().": "; 23 | $a = ""; 24 | while (!feof($stream)) { 25 | $a .= fread($stream, 8192); 26 | } 27 | echo strlen($a)." bytes, CRC "; 28 | echo int32_to_hex(crc32($a))."\n\n"; //you can confirm they're equal to those given by $e->getCrc() 29 | } 30 | 31 | echo "Done\n"; 32 | ?> 33 | --EXPECTF-- 34 | 3 files: 35 | 36 | file1.txt: 18 bytes, CRC 52B28202 37 | 38 | file2.txt: 17704 bytes, CRC F2C79881 39 | 40 | file3.txt: 18 bytes, CRC BCBCE32E 41 | 42 | Done 43 | -------------------------------------------------------------------------------- /tests/012.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getStream() function (bad RAR file) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | = 2) 14 | break; 15 | //$e->extract(false, dirname(__FILE__).'/temp.txt'); 16 | //echo "now stream\n"; 17 | $stream = $e->getStream(); 18 | echo $e->getName().": "; 19 | if ($stream === false) { 20 | echo "Could not get stream.\n\n"; 21 | continue; 22 | } 23 | while (!feof($stream) && $i != 2) { 24 | echo fread($stream, 8192); 25 | } 26 | fclose($stream); 27 | echo "\n"; 28 | 29 | } 30 | 31 | echo "Done\n"; 32 | ?> 33 | --EXPECTF-- 34 | 51 files (will test only the first 4): 35 | 36 | test%s: The great battle of Gunprex versus Optiter!!!!!1 37 | Gunprex, Fire! 38 | So long, Optiter! 39 | 40 | test%s 41 | Done 42 | -------------------------------------------------------------------------------- /tests/013.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | rar_entry_get() and RarEntry::getName() coherence 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getName(); 11 | $entryback = rar_entry_get($rar_file1, $name); 12 | echo "$entryback\n"; 13 | echo "\n"; 14 | 15 | echo "Done\n"; 16 | ?> 17 | --EXPECTF-- 18 | RarEntry for file "file1À۞.txt" (52b28202) 19 | 20 | Done 21 | -------------------------------------------------------------------------------- /tests/014.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getStream() on unicode entry 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getStream(); 13 | if ($stream !== false) 14 | while (!feof($stream)) { 15 | echo fread($stream, 8192); 16 | } 17 | 18 | echo "\n"; 19 | 20 | echo "Done\n"; 21 | ?> 22 | --EXPECTF-- 23 | RarEntry for file "file1À۞.txt" (52b28202) 24 | 25 | contents of file 1 26 | Done 27 | -------------------------------------------------------------------------------- /tests/015.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | rar_close() liberates resource (PECL bug #9649) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | extract("."); 19 | unlink(dirname(__FILE__).'/temp.rar'); 20 | 21 | echo "Done\n"; 22 | ?> 23 | --EXPECTF-- 24 | RAR Archive "%s" 25 | RarEntry for file "1.txt" (a0de71c0) 26 | 27 | RAR Archive "%s" (closed) 28 | 29 | Warning: RarEntry::extract(): The archive is already closed in %s on line %d 30 | Done 31 | -------------------------------------------------------------------------------- /tests/016.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::extract() method (corrupt RAR file) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | = 4) 14 | break; 15 | echo "Extraction of file #$i:\n"; 16 | $ret = $e->extract(false, dirname(__FILE__).'/temp.txt'); 17 | if ($ret) 18 | echo "\tSUCCESS\n"; 19 | else 20 | echo "\tFAILED\n"; 21 | 22 | echo "\n"; 23 | } 24 | 25 | @unlink(dirname(__FILE__).'/temp.txt'); 26 | 27 | echo "Done\n"; 28 | ?> 29 | --EXPECTF-- 30 | 51 files (will test only the first 4): 31 | 32 | Extraction of file #1: 33 | SUCCESS 34 | 35 | Extraction of file #2: 36 | 37 | Warning: RarEntry::extract(): ERAR_BAD_DATA in %s on line %d 38 | FAILED 39 | 40 | Extraction of file #3: 41 | 42 | Warning: RarEntry::extract(): ERAR_BAD_DATA in %s on line %d 43 | FAILED 44 | 45 | Extraction of file #4: 46 | 47 | Warning: RarEntry::extract(): ERAR_BAD_DATA in %s on line %d 48 | FAILED 49 | 50 | Done 51 | -------------------------------------------------------------------------------- /tests/017.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::extract() with unicode files 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | extract(false, dirname(__FILE__).'/temp.txt'); 12 | 13 | echo file_get_contents(dirname(__FILE__).'/temp.txt'); 14 | echo "\n"; 15 | 16 | @unlink(dirname(__FILE__).'/temp.txt'); 17 | 18 | echo "Done\n"; 19 | ?> 20 | --EXPECTF-- 21 | contents of file 1 22 | Done 23 | -------------------------------------------------------------------------------- /tests/018.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | rar_list()/rar_entry_get() with not first volume 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | getStream(); 18 | echo $e->getName().": "; 19 | $a = ""; 20 | while (!feof($stream)) { 21 | $a .= fread($stream, 512); 22 | } 23 | echo strlen($a)." bytes, CRC "; 24 | echo int32_to_hex(crc32($a))."\n\n"; //you can confirm they're equal to those given by $e->getCrc() 25 | } 26 | 27 | echo "Done\n"; 28 | ?> 29 | --EXPECTF-- 30 | 1 files: 31 | 32 | tese.txt: 787 bytes, CRC 23B93A7A 33 | 34 | Done 35 | -------------------------------------------------------------------------------- /tests/020.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getStream() function (solid archive) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getStream(); 18 | echo $e->getName().": "; 19 | $a = ""; 20 | while (!feof($stream)) { 21 | $a .= fread($stream, 8192); 22 | } 23 | echo strlen($a)." bytes, CRC "; 24 | echo int32_to_hex(crc32($a))."\n\n"; //you can confirm they're equal to those given by $e->getCrc() 25 | } 26 | 27 | echo "Done\n"; 28 | ?> 29 | --EXPECTF-- 30 | 2 files: 31 | 32 | tese.txt: 787 bytes, CRC 23B93A7A 33 | 34 | unrardll.txt: 19192 bytes, CRC 2ED64B6E 35 | 36 | Done 37 | -------------------------------------------------------------------------------- /tests/021.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::isDirectory() basic test 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getName()} is ". ($e->isDirectory()?"":"not ") . "a directory.\n"; 12 | } 13 | 14 | echo "Done\n"; 15 | --EXPECTF-- 16 | dirwithsth%cfileindir.txt is not a directory. 17 | dirwithsth is a directory. 18 | emptydir is a directory. 19 | Done 20 | -------------------------------------------------------------------------------- /tests/022.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::extract() with directory 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | extract(dirname(__FILE__)); 14 | var_dump($extrres); 15 | $exists = is_dir($dir); 16 | var_dump($exists); 17 | @rmdir($dir); 18 | 19 | echo "\n\n"; 20 | 21 | $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . "emptydircust"; 22 | $exists = is_dir($dir); 23 | var_dump($exists); 24 | $extrres = $e->extract(false, $dir); 25 | var_dump($extrres); 26 | $exists = is_dir($dir); 27 | var_dump($exists); 28 | @rmdir($dir); 29 | 30 | echo "Done\n"; 31 | --EXPECTF-- 32 | bool(false) 33 | bool(true) 34 | bool(true) 35 | 36 | 37 | bool(false) 38 | bool(true) 39 | bool(true) 40 | Done 41 | -------------------------------------------------------------------------------- /tests/023.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getStream() with directory 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getStream(); 10 | var_dump($stream); 11 | var_dump(feof($stream)); 12 | var_dump(fread($stream, 200)); 13 | var_dump(feof($stream)); 14 | 15 | echo "Done\n"; 16 | --EXPECTF-- 17 | resource(%d) of type (stream) 18 | bool(false) 19 | string(0) "" 20 | bool(true) 21 | Done 22 | -------------------------------------------------------------------------------- /tests/024.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | rar_open()/RarEntry::getStream() (headers level password) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | should fail (no password):\n"; 8 | $rar_file1 = rar_open(dirname(__FILE__).'/encrypted_headers.rar'); 9 | $entries = rar_list($rar_file1); 10 | 11 | echo "\n--> should fail (wrong password):\n"; 12 | $rar_file1 = rar_open(dirname(__FILE__).'/encrypted_headers.rar', 'wrongpassword'); 13 | $entries = rar_list($rar_file1); 14 | 15 | echo "\n--> should work:\n"; 16 | $rar_file2 = rar_open(dirname(__FILE__).'/encrypted_headers.rar', 'samplepassword'); 17 | $entries = rar_list($rar_file2); 18 | 19 | echo "Found " . count($entries) . " files.\n"; 20 | echo "Content of first one follows:\n"; 21 | //reset($entries)->extract(false, "./temp.txt"); 22 | $stream = reset($entries)->getStream(); 23 | var_dump($stream); 24 | if ($stream !== FALSE) { 25 | while (!feof($stream)) { 26 | echo fread($stream, 128); 27 | } 28 | } 29 | echo "\n"; 30 | 31 | echo "Done\n"; 32 | --EXPECTF-- 33 | --> should fail (no password): 34 | 35 | Warning: rar_list(): ERAR_MISSING_PASSWORD (password needed but not specified) in %s on line %d 36 | 37 | --> should fail (wrong password): 38 | 39 | Warning: rar_list(): ERAR_BAD_DATA in %s on line %d 40 | 41 | --> should work: 42 | Found 2 files. 43 | Content of first one follows: 44 | resource(%d) of type (stream) 45 | Encrypted file 1 contents. 46 | Done 47 | -------------------------------------------------------------------------------- /tests/025.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | rar_open()/RarEntry::extract() (headers level password) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | extract(false, $tempfile)); 14 | echo "Content of first one follows:\n"; 15 | echo file_get_contents($tempfile); 16 | $stream = reset($entries)->getStream(); 17 | @unlink($tempfile); 18 | echo "\n"; 19 | 20 | echo "Done\n"; 21 | --EXPECTF-- 22 | Found 2 files. 23 | bool(true) 24 | Content of first one follows: 25 | Encrypted file 1 contents. 26 | Done 27 | -------------------------------------------------------------------------------- /tests/026.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getStream() (file level password) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | should fail (no password):\n"; 8 | $rar_file1 = rar_open(dirname(__FILE__).'/encrypted_only_files.rar'); 9 | $entries = rar_list($rar_file1); 10 | var_dump(count($entries)); 11 | var_dump($entries[0]->getStream()); 12 | echo "\n"; 13 | 14 | echo "--> success (password is the same as the one given on rar_open):\n"; 15 | $rar_file2 = rar_open(dirname(__FILE__).'/encrypted_only_files.rar', 'samplepassword'); 16 | $entries = rar_list($rar_file2); 17 | echo stream_get_contents($entries[0]->getStream()); 18 | echo "\n\n"; 19 | 20 | echo "--> should give incorrect data (password of 2nd file different from the one given on rar_open):\n"; 21 | echo rawurlencode(stream_get_contents($entries[1]->getStream())); 22 | echo "\n\n"; 23 | 24 | echo "--> should give correct data (password of 2nd file is specified):\n"; 25 | echo stream_get_contents($entries[1]->getStream('samplepassword2')); 26 | echo "\n\n"; 27 | 28 | echo "--> success (password is the same as the one given on rar_open, which shouldn't have been forgotten):\n"; 29 | echo stream_get_contents($entries[0]->getStream()); 30 | echo "\n\n"; 31 | 32 | echo "Done\n"; 33 | --EXPECTF-- 34 | --> should fail (no password): 35 | int(2) 36 | 37 | Warning: RarEntry::getStream(): ERAR_MISSING_PASSWORD (password needed but not specified) in %s on line %d 38 | bool(false) 39 | 40 | --> success (password is the same as the one given on rar_open): 41 | Encrypted file 1 contents. 42 | 43 | --> should give incorrect data (password of 2nd file different from the one given on rar_open): 44 | t%09%A6%2B%0D%1B%F6%815%5E%E7%EC%C0%0BF%5EH%3A%C0%0D%815%5E%E7%EC%C0 45 | 46 | --> should give correct data (password of 2nd file is specified): 47 | Encrypted file 1 contents. 48 | 49 | --> success (password is the same as the one given on rar_open, which shouldn't have been forgotten): 50 | Encrypted file 1 contents. 51 | 52 | Done 53 | -------------------------------------------------------------------------------- /tests/027.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getStream() with Linux directories and links 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getAttr() & 0x1FF) . "\n"; //no read/write/execute perms 14 | echo "win directory bit: " . (($e->getAttr() & RarEntry::ATTRIBUTE_WIN_DIRECTORY) != 0) ."\n"; 15 | echo "unix directory attr: " . (($e->getAttr() & RarEntry::ATTRIBUTE_UNIX_FINAL_QUARTET) 16 | == RarEntry::ATTRIBUTE_UNIX_DIRECTORY) ."\n"; 17 | echo "unix symlink attr: " . (($e->getAttr() & RarEntry::ATTRIBUTE_UNIX_FINAL_QUARTET) 18 | == RarEntry::ATTRIBUTE_UNIX_SYM_LINK) ."\n"; 19 | $stream = $e->getStream(); 20 | $cont = stream_get_contents($stream); 21 | echo "$cont (strlen() " . strlen($cont) . ")\n"; 22 | 23 | echo "\nLink\n"; 24 | 25 | $e = rar_entry_get($rar, "link"); 26 | echo $e."\n"; 27 | echo "perms: " . decoct($e->getAttr() & 0x1FF) . "\n"; 28 | echo "win directory bit: " . (($e->getAttr() & RarEntry::ATTRIBUTE_WIN_DIRECTORY) != 0) ."\n"; //coincidence 29 | echo "unix directory attr: " . (($e->getAttr() & RarEntry::ATTRIBUTE_UNIX_FINAL_QUARTET) 30 | == RarEntry::ATTRIBUTE_UNIX_DIRECTORY) ."\n"; 31 | echo "unix symlink attr: " . (($e->getAttr() & RarEntry::ATTRIBUTE_UNIX_FINAL_QUARTET) 32 | == RarEntry::ATTRIBUTE_UNIX_SYM_LINK) ."\n"; 33 | $stream = $e->getStream(); 34 | $cont = stream_get_contents($stream); 35 | echo "$cont (strlen() " . strlen($cont) . ")\n"; //varies on windows and linux 36 | 37 | echo "Done\n"; 38 | --EXPECTF-- 39 | Directory 40 | RarEntry for directory "nopermdir" (0) 41 | perms: 0 42 | win directory bit: 43 | unix directory attr: 1 44 | unix symlink attr: 45 | (strlen() 0) 46 | 47 | Link 48 | RarEntry for file "link" (43e55b49) 49 | perms: 777 50 | win directory bit: 1 51 | unix directory attr: 52 | unix symlink attr: 1 53 | %s 54 | Done 55 | -------------------------------------------------------------------------------- /tests/028.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarArchive::open() basic test 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | getEntries() as $e) { 9 | echo $e . "\n"; 10 | } 11 | 12 | echo "Done\n"; 13 | --EXPECTF-- 14 | RarEntry for file "emptydir%clink" (36ac99f1) 15 | RarEntry for file "file" (b95e8411) 16 | RarEntry for file "link" (43e55b49) 17 | RarEntry for directory "emptydir" (0) 18 | RarEntry for directory "nopermdir" (0) 19 | RarEntry for directory "setuiddir" (0) 20 | RarEntry for directory "stickydir" (0) 21 | Done 22 | -------------------------------------------------------------------------------- /tests/030.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarArchive::getEntry() basic test 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getEntry('tese.txt'); 9 | echo $rar_entry; 10 | echo "\n"; 11 | echo "Done\n"; 12 | --EXPECTF-- 13 | RarEntry for file "tese.txt" (23b93a7a) 14 | Done 15 | -------------------------------------------------------------------------------- /tests/031.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarArchive::getComment() basic test 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getComment(); 9 | echo "\n"; 10 | echo "Done\n"; 11 | --EXPECTF-- 12 | This is the comment of the file commented.rar. 13 | Done 14 | -------------------------------------------------------------------------------- /tests/032.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarArchive traversal with multi-part archive 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | $rarE) { 9 | echo "$k. $rarE\n"; 10 | } 11 | echo "Done\n"; 12 | --EXPECTF-- 13 | 0. RarEntry for file "file1.txt" (52b28202) 14 | 1. RarEntry for file "file2.txt" (f2c79881) 15 | 2. RarEntry for file "file3.txt" (bcbce32e) 16 | Done 17 | -------------------------------------------------------------------------------- /tests/033.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | rar_solid_is() basic test 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | isSolid()?'yes':'no') ."\n"; 10 | echo "$arch2: " . (rar_solid_is($arch2)?'yes':'no') . "\n"; 11 | 12 | $arch2->close(); 13 | var_dump(rar_solid_is($arch2)); 14 | 15 | echo "\n"; 16 | echo "Done.\n"; 17 | --EXPECTF-- 18 | RAR Archive "%sstore_method.rar": no 19 | RAR Archive "%ssolid.rar": yes 20 | 21 | Warning: rar_solid_is(): The archive is already closed in %s on line %d 22 | bool(false) 23 | 24 | Done. 25 | -------------------------------------------------------------------------------- /tests/034.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarException::(set/is)UsingExceptions() test 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | getEntry('nonexistentfile.txt'); 11 | } catch (RarException $re) { 12 | echo "Message: " . $re->getMessage()."\n"; 13 | echo "Code: " . $re->getCode() ."\n"; 14 | } 15 | echo "Done.\n"; 16 | --EXPECTF-- 17 | Message: cannot find file "nonexistentfile.txt" in Rar archive "%slatest_winrar.rar" 18 | Code: -1 19 | Done. 20 | -------------------------------------------------------------------------------- /tests/036.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | rar_open() non-existent archive with exceptions 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getMessage()."\n"; 12 | echo "Code: " . $re->getCode() ."\n"; 13 | } 14 | echo "Done.\n"; 15 | --EXPECTF-- 16 | Message: unRAR internal error: Failed to open %snonexistentarchive.rar: ERAR_EOPEN (file open error) 17 | Code: 15 18 | Done. 19 | -------------------------------------------------------------------------------- /tests/037.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getStream(), password not given, with exceptions 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | should fail (no password):\n"; 9 | $rar_file1 = rar_open(dirname(__FILE__).'/encrypted_only_files.rar'); 10 | $entries = rar_list($rar_file1); 11 | var_dump(count($entries)); 12 | try { 13 | var_dump($entries[0]->getStream()); 14 | } catch (RarException $re) { 15 | echo "Message: " . $re->getMessage()."\n"; 16 | echo "Code: " . $re->getCode() ."\n"; 17 | } 18 | echo "Done.\n"; 19 | --EXPECTF-- 20 | --> should fail (no password): 21 | int(2) 22 | Message: unRAR internal error: ERAR_MISSING_PASSWORD (password needed but not specified) 23 | Code: 22 24 | Done. 25 | -------------------------------------------------------------------------------- /tests/038.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarArchive get iterator on closed file 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | close(); 9 | foreach ($rarF as $k => $rarE) { 10 | echo "$k. $rarE\n"; 11 | unset($rarE); 12 | } 13 | echo "Done.\n"; 14 | --EXPECTF-- 15 | Fatal error: main(): The archive is already closed, cannot give an iterator in %s on line %d 16 | -------------------------------------------------------------------------------- /tests/039.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Access RAR archive with missing volumes 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getEntries(); 13 | reset($t)->extract(false, $fn2); 14 | $rarF2 = RarArchive::open($fn2); 15 | $t = $rarF2->getEntries(); 16 | var_dump($t[0]->getUnpackedSize()); 17 | var_dump($t[1]->getUnpackedSize()); 18 | echo "Done.\n"; 19 | --CLEAN-- 20 | getEntries(); 13 | reset($t)->extract(false, $fn2); 14 | $rarF2 = RarArchive::open($fn2); 15 | $t = $rarF2->getEntries(); 16 | var_dump($t[0]->getUnpackedSize()); 17 | var_dump($t[1]->getUnpackedSize()); 18 | echo "Done.\n"; 19 | --CLEAN-- 20 | getEntries(); 29 | $rar = RarArchive::open($fn, null, array("A", "resolveStatic")); 30 | $rar->getEntries(); 31 | $rar = RarArchive::open($fn, null, array(new A(), "resolveInstance")); 32 | $rar->getEntries(); 33 | function testA() { 34 | global $fn; 35 | $obj = new A(); 36 | return RarArchive::open($fn, null, array($obj, "resolveInstance")); 37 | } 38 | $rar = testA(); 39 | $rar->getEntries(); 40 | echo "Done.\n"; 41 | --EXPECTF-- 42 | A::resolveStatic() 43 | A::resolveStatic() 44 | A::resolveInstance() 45 | A::resolveInstance() 46 | Done. 47 | 48 | -------------------------------------------------------------------------------- /tests/044.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | rar_open() with volume find (callback variants 2) 3 | --SKIPIF-- 4 | getEntries(); 29 | $rar = RarArchive::open($fn, null, $f); 30 | $rar->getEntries(); 31 | 32 | $f2 = function ($vol) { 33 | echo "Closure (2)\n"; 34 | return A::resolve($vol); 35 | }; 36 | $rar = RarArchive::open($fn, null, $f2); 37 | unset($f2); 38 | $rar->getEntries(); 39 | echo "Done.\n"; 40 | --EXPECTF-- 41 | A::__invoke() 42 | Closure 43 | Closure (2) 44 | Done. 45 | 46 | -------------------------------------------------------------------------------- /tests/046.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getStream() function (broken set fixed with volume callback) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getStream(); 20 | echo $e->getName().": "; 21 | $a = ""; 22 | while (is_resource($stream) && !feof($stream)) { 23 | $a .= fread($stream, 8192); 24 | } 25 | echo strlen($a)." bytes, CRC "; 26 | echo int32_to_hex(crc32($a))."\n\n"; //you can confirm they're equal to those given by $e->getCrc() 27 | } 28 | 29 | echo "Done\n"; 30 | ?> 31 | --EXPECTF-- 32 | file1.txt: 18 bytes, CRC 52B28202 33 | 34 | file2.txt: 17704 bytes, CRC F2C79881 35 | 36 | file3.txt: 18 bytes, CRC BCBCE32E 37 | 38 | Done 39 | -------------------------------------------------------------------------------- /tests/047.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::extract() function (broken set fixed with volume callback) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getEntry('file2.txt'); 20 | 21 | echo "\nSuccess:\n"; 22 | $rar_file1 = rar_open(dirname(__FILE__).'/multi_broken.part1.rar', null, 'resolve'); 23 | $entry = $rar_file1->getEntry('file2.txt'); 24 | $entry->extract(null, dirname(__FILE__) . "/temp_file2.txt"); 25 | echo int32_to_hex(crc32(file_get_contents(dirname(__FILE__) . "/temp_file2.txt"))); 26 | echo "\n"; 27 | echo "Done\n"; 28 | ?> 29 | --CLEAN-- 30 | getEntries(); 20 | 21 | echo "Done.\n"; 22 | --EXPECTF-- 23 | Warning: RarArchive::getEntries(): Cound not expand filename aaaa%s in %s on line %d 24 | 25 | Warning: RarArchive::getEntries(): ERAR_EOPEN (file open error) in %s on line %d 26 | Done. 27 | -------------------------------------------------------------------------------- /tests/049.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarArchive::open() volume callback long return (case MAXPATHLEN > NM) 3 | --SKIPIF-- 4 | 2048)) 9 | die("skip test is for systems where MAXPATHLEN > 2048"); 10 | $rp = dirname(__FILE__) . "/" . str_repeat("a", 2048); 11 | if (strlen(dirname(__FILE__) > PHP_MAXPATHLEN - 1)) 12 | die("skip current directory is too deep."); 13 | --FILE-- 14 | getEntries(); 24 | 25 | echo "Done.\n"; 26 | --EXPECTF-- 27 | Warning: RarArchive::getEntries(): Resolved path is too big for the unRAR library in %s on line %d 28 | 29 | Warning: RarArchive::getEntries(): ERAR_EOPEN (file open error) in %s on line %d 30 | Done. 31 | -------------------------------------------------------------------------------- /tests/050.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Stream wrapper basic test 3 | --SKIPIF-- 4 | [*]#" in %s on line %d 31 | 32 | Test no fragment: 33 | 34 | Warning: fopen(rar://file.rar): %cailed to open stream: The url must contain a path and a non-empty fragment; it must be in the form "rar://[*]#" in %s on line %d 35 | 36 | Test empty fragment: 37 | 38 | Warning: fopen(rar://file.rar#): %cailed to open stream: The url must contain a path and a non-empty fragment; it must be in the form "rar://[*]#" in %s on line %d 39 | 40 | Test no path: 41 | 42 | Warning: fopen(rar://#frag): %cailed to open stream: The url must contain a path and a non-empty fragment; it must be in the form "rar://[*]#" in %s on line %d 43 | 44 | Test no path and empty fragment: 45 | 46 | Warning: fopen(rar://#): %cailed to open stream: The url must contain a path and a non-empty fragment; it must be in the form "rar://[*]#" in %s on line %d 47 | Done. 48 | -------------------------------------------------------------------------------- /tests/055.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Stream wrapper with volume find callback 3 | --SKIPIF-- 4 | array('volume_callback'=>'resolve')))); 22 | $a = stream_get_contents($stream); 23 | echo strlen($a)." bytes, CRC "; 24 | echo int32_to_hex(crc32($a))."\n\n"; //you can confirm they're equal to those given by $e->getCrc() 25 | echo "Done.\n"; 26 | --EXPECTF-- 27 | 17704 bytes, CRC F2C79881 28 | 29 | Done. 30 | 31 | -------------------------------------------------------------------------------- /tests/056.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RAR file stream stat 3 | --SKIPIF-- 4 | 0 27 | [ino] => 0 28 | [mode] => 33206 29 | [nlink] => 1 30 | [uid] => 0 31 | [gid] => 0 32 | [rdev] => 0 33 | [size] => 5 34 | [atime] => 0 35 | [mtime] => 1086948439 36 | [ctime] => 0 37 | [blksize] => %s 38 | [blocks] => %s 39 | ) 40 | Done. 41 | -------------------------------------------------------------------------------- /tests/057.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RAR file stream stat consistency with url stat 3 | --SKIPIF-- 4 | read())) { 15 | echo $entry."\n"; 16 | } 17 | $d->close(); 18 | 19 | echo "\nRoot entries encoded:\n"; 20 | $u = "rar://" . 21 | dirname(__FILE__) . '/dirs_and_extra_headers.rar'; 22 | 23 | $d = dir($u); 24 | while (false !== ($entry = $d->read())) { 25 | echo $entry."\n"; 26 | } 27 | $d->close(); 28 | 29 | echo "\nSub-root directory entries unencoded:\n"; 30 | $u = "rar://" . 31 | dirname(__FILE__) . '/dirs_and_extra_headers.rar*#%EF%AC%B0'; 32 | 33 | $d = dir($u); 34 | while (false !== ($entry = $d->read())) { 35 | echo $entry."\n"; 36 | } 37 | 38 | echo "\nDone.\n"; 39 | --EXPECTF-- 40 | Root entries unencoded: 41 | allow_everyone_ni 42 | file1.txt 43 | file2_אּ.txt 44 | with_streams.txt 45 | אּ 46 | 47 | Root entries encoded: 48 | allow_everyone_ni 49 | file1.txt 50 | file2_%EF%AC%B0.txt 51 | with_streams.txt 52 | %EF%AC%B0 53 | 54 | Sub-root directory entries unencoded: 55 | %2Fempty%2E 56 | empty 57 | file3.txt 58 | file4_אּ.txt 59 | אּ_2 60 | 61 | Done. 62 | -------------------------------------------------------------------------------- /tests/061.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RAR directory stream attempt on file 3 | --SKIPIF-- 4 | 0 39 | [ino] => 0 40 | [mode] => 16895 41 | [nlink] => 1 42 | [uid] => 0 43 | [gid] => 0 44 | [rdev] => 0 45 | [size] => 0 46 | [atime] => 0 47 | [mtime] => 312768000 48 | [ctime] => 0 49 | [blksize] => %s 50 | [blocks] => %s 51 | ) 52 | 53 | Sub-root directory: 54 | Array 55 | ( 56 | [dev] => 0 57 | [ino] => 0 58 | [mode] => 16895 59 | [nlink] => 1 60 | [uid] => 0 61 | [gid] => 0 62 | [rdev] => 0 63 | [size] => 0 64 | [atime] => 1272938643 65 | [mtime] => 1272938643 66 | [ctime] => 1272813170 67 | [blksize] => %s 68 | [blocks] => %s 69 | ) 70 | Done. 71 | -------------------------------------------------------------------------------- /tests/063.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RAR directory stream stat consistency with url stat 3 | --SKIPIF-- 4 | rewind(); 14 | while($it->valid()) { 15 | if (!$it->isDot()) { 16 | echo 'SubPathName: ' . rawurldecode($it->getSubPathName()) . "\n"; 17 | echo 'SubPath: ' . rawurldecode($it->getSubPath()) . "\n"; 18 | echo 'Key: ' . $it->key() . "\n\n"; 19 | } 20 | $it->next(); 21 | } 22 | 23 | echo "Done.\n"; 24 | --EXPECTF-- 25 | SubPathName: file1.txt 26 | SubPath: 27 | Key: rar://%s/dirs_and_extra_headers.rar#%sfile1.txt 28 | 29 | SubPathName: file2_אּ.txt 30 | SubPath: 31 | Key: rar://%s/dirs_and_extra_headers.rar#%sfile2_%EF%AC%B0.txt 32 | 33 | SubPathName: with_streams.txt 34 | SubPath: 35 | Key: rar://%s/dirs_and_extra_headers.rar#%swith_streams.txt 36 | 37 | SubPathName: אּ%s%2Fempty%2E%sfile7.txt 38 | SubPath: אּ%s%2Fempty%2E 39 | Key: rar://%s/dirs_and_extra_headers.rar#%s%EF%AC%B0%s%252Fempty%252E%sfile7.txt 40 | 41 | SubPathName: אּ%sfile3.txt 42 | SubPath: אּ 43 | Key: rar://%s/dirs_and_extra_headers.rar#%s%EF%AC%B0%sfile3.txt 44 | 45 | SubPathName: אּ%sfile4_אּ.txt 46 | SubPath: אּ 47 | Key: rar://%s/dirs_and_extra_headers.rar#%s%EF%AC%B0%sfile4_%EF%AC%B0.txt 48 | 49 | SubPathName: אּ%sאּ_2%sfile5.txt 50 | SubPath: אּ%sאּ_2 51 | Key: rar://%s/dirs_and_extra_headers.rar#%s%EF%AC%B0%s%EF%AC%B0_2%sfile5.txt 52 | 53 | SubPathName: אּ%sאּ_2%sfile6_אּ.txt 54 | SubPath: אּ%sאּ_2 55 | Key: rar://%s/dirs_and_extra_headers.rar#%s%EF%AC%B0%s%EF%AC%B0_2%sfile6_%EF%AC%B0.txt 56 | 57 | Done. 58 | -------------------------------------------------------------------------------- /tests/066.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::extract() (file level password) 3 | --SKIPIF-- 4 | 5 | --CLEAN-- 6 | @unlink(dirname(__FILE__).'/extract_temp'); 7 | --FILE-- 8 | should fail (no password):\n"; 12 | $rar_file1 = rar_open(dirname(__FILE__).'/encrypted_only_files.rar'); 13 | $entries = rar_list($rar_file1); 14 | var_dump(count($entries)); 15 | var_dump($entries[0]->extract(false, $dest)); 16 | echo "\n"; 17 | 18 | echo "--> success (password is the same as the one given on rar_open):\n"; 19 | $rar_file2 = rar_open(dirname(__FILE__).'/encrypted_only_files.rar', 'samplepassword'); 20 | $entries = rar_list($rar_file2); 21 | var_dump($entries[0]->extract(false, $dest)); 22 | echo file_get_contents($dest); 23 | unlink($dest); 24 | echo "\n\n"; 25 | 26 | echo "--> should fail (password of 2nd file different from the one given on rar_open):\n"; 27 | var_dump($entries[1]->extract(false, $dest)); 28 | echo "\n\n"; 29 | 30 | echo "--> should give correct data (password of 2nd file is specified):\n"; 31 | var_dump($entries[1]->extract(false, $dest, 'samplepassword2')); 32 | echo file_get_contents($dest); 33 | unlink($dest); 34 | echo "\n\n"; 35 | 36 | echo "Done\n"; 37 | --EXPECTF-- 38 | --> should fail (no password): 39 | int(2) 40 | 41 | Warning: RarEntry::extract(): ERAR_MISSING_PASSWORD (password needed but not specified) in %s on line %d 42 | bool(false) 43 | 44 | --> success (password is the same as the one given on rar_open): 45 | bool(true) 46 | Encrypted file 1 contents. 47 | 48 | --> should fail (password of 2nd file different from the one given on rar_open): 49 | 50 | Warning: RarEntry::extract(): ERAR_BAD_DATA in %s on line %d 51 | bool(false) 52 | 53 | 54 | --> should give correct data (password of 2nd file is specified): 55 | bool(true) 56 | Encrypted file 1 contents. 57 | 58 | Done 59 | -------------------------------------------------------------------------------- /tests/067.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::extract() process extended (Windows) 3 | --SKIPIF-- 4 | 13 | --CLEAN-- 14 | @rmdir(dirname(__FILE__).'/temp_directory'); 15 | --FILE-- 16 | should have default permissions:\n"; 24 | $rarF = RarArchive::open($fn1); 25 | $t = $rarF->getEntry('allow_everyone_ni'); 26 | $t->extract(false, $dest, NULL); 27 | exec('cacls ' . escapeshellarg($dest), $perms); 28 | $perms = array_reduce($perms, 'concat'); 29 | var_dump(preg_match('/.* Everyone:\\(OI\\)\\(CI\\)F/i', $perms)); 30 | @rmdir($dest); 31 | echo "\n"; 32 | 33 | echo "--> should have permissions for everyone:\n"; 34 | $rarF = RarArchive::open($fn1); 35 | $t = $rarF->getEntry('allow_everyone_ni'); 36 | $t->extract(false, $dest, NULL, true); 37 | exec('cacls ' . escapeshellarg($dest), $perms); 38 | $perms = array_reduce($perms, 'concat'); 39 | var_dump(preg_match('/.* Everyone:\\(OI\\)\\(CI\\)F/i', $perms)); 40 | echo "\n"; 41 | @rmdir($dest); 42 | 43 | echo "Done\n"; 44 | --EXPECTF-- 45 | --> should have default permissions: 46 | int(0) 47 | 48 | --> should have permissions for everyone: 49 | int(1) 50 | 51 | Done 52 | -------------------------------------------------------------------------------- /tests/068.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarArchive direct instantiation does not crash (PHP 5.x) 3 | --SKIPIF-- 4 | = 70000) die("skip for PHP 5.x"); 7 | if (key_exists('USE_ZEND_ALLOC', $_ENV) && PHP_VERSION_ID < 70000) die('skip do not use with valgrind in PHP <7'); 8 | --FILE-- 9 | = 70000) die("skip for PHP 5.x"); 6 | if (key_exists('USE_ZEND_ALLOC', $_ENV) && PHP_VERSION_ID < 70000) die('skip do not use with valgrind in PHP <7'); 7 | --FILE-- 8 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | getPosition() . ". $e\n"; 12 | } 13 | echo "\n"; 14 | 15 | echo "Done.\n"; 16 | --EXPECTF-- 17 | 0. RarEntry for file "file1.txt" (52b28202) 18 | 1. RarEntry for file "file2.txt" (f2c79881) 19 | 2. RarEntry for file "file3.txt" (bcbce32e) 20 | 21 | Done. 22 | -------------------------------------------------------------------------------- /tests/072.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | rar_list handles files with non-unique entry names 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getPosition() . ". $e\n"; 13 | } 14 | echo "\n"; 15 | 16 | echo "Done.\n"; 17 | --EXPECTF-- 18 | 0. RarEntry for file "file.txt" (ae2a88a7) 19 | 1. RarEntry for file "file.txt" (771df243) 20 | 21 | Done. 22 | -------------------------------------------------------------------------------- /tests/073.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getStream handles files with non-unique entry names 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getStream(); 12 | if ($stream) { 13 | echo $e->getPosition() . ". $e\n"; 14 | echo stream_get_contents($stream); 15 | echo "\n"; 16 | } 17 | } 18 | 19 | echo "Done.\n"; 20 | --EXPECTF-- 21 | 0. RarEntry for file "file.txt" (ae2a88a7) 22 | Content of first file. 23 | 1. RarEntry for file "file.txt" (771df243) 24 | Content of second file. 25 | Done. 26 | -------------------------------------------------------------------------------- /tests/074.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::extract handles files with non-unique entry names 3 | --SKIPIF-- 4 | 5 | --CLEAN-- 6 | extract("", $dest); 17 | if ($res) { 18 | echo $e->getPosition() . ". $e\n"; 19 | echo file_get_contents($dest); 20 | echo "\n"; 21 | } 22 | else { 23 | die("failed extraction"); 24 | } 25 | } 26 | 27 | echo "Done.\n"; 28 | --EXPECTF-- 29 | 0. RarEntry for file "file.txt" (ae2a88a7) 30 | Content of first file. 31 | 1. RarEntry for file "file.txt" (771df243) 32 | Content of second file. 33 | Done. 34 | -------------------------------------------------------------------------------- /tests/075.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getStream NULL can be given to indicate there's no password 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getStream(); 13 | var_dump($stream); 14 | 15 | echo "\n* NULL given (should have the same effect as no password):\n"; 16 | $stream = $e->getStream(NULL); 17 | var_dump($stream); 18 | 19 | echo "\n* empty string given as password (should have the same effect; " 20 | . "rar disallows empty passwords):\n"; 21 | $stream = $e->getStream(''); 22 | var_dump($stream); 23 | 24 | echo "\n* non-empty password given; should give stream:\n"; 25 | $stream = $e->getStream('bugabuga'); 26 | var_dump($stream); 27 | 28 | break; 29 | } 30 | 31 | echo "\n"; 32 | echo "Done.\n"; 33 | --EXPECTF-- 34 | * No password given: 35 | 36 | Warning: RarEntry::getStream(): ERAR_MISSING_PASSWORD (password needed but not specified) in %s on line %d 37 | bool(false) 38 | 39 | * NULL given (should have the same effect as no password): 40 | 41 | Warning: RarEntry::getStream(): ERAR_MISSING_PASSWORD (password needed but not specified) in %s on line %d 42 | bool(false) 43 | 44 | * empty string given as password (should have the same effect; rar disallows empty passwords): 45 | 46 | Warning: RarEntry::getStream(): ERAR_MISSING_PASSWORD (password needed but not specified) in %s on line %d 47 | bool(false) 48 | 49 | * non-empty password given; should give stream: 50 | resource(%d) of type (stream) 51 | 52 | Done. 53 | -------------------------------------------------------------------------------- /tests/076.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::extract NULL can be given to indicate there's no password 3 | --SKIPIF-- 4 | 5 | --CLEAN-- 6 | extract('', $dest); 19 | var_dump($result); 20 | 21 | echo "\n* NULL given (should have the same effect as no password):\n"; 22 | $result = $e->extract('', $dest, NULL); 23 | var_dump($result); 24 | 25 | echo "\n* empty string given as password (should have the same ". 26 | "effect as no password):\n"; 27 | $result = $e->extract('', $dest, ''); 28 | var_dump($result); 29 | 30 | echo "\n* password given; a wrong one:\n"; 31 | $result = $e->extract('', $dest, 'wrongpassword'); 32 | var_dump($result); 33 | 34 | break; 35 | } 36 | 37 | echo "\n"; 38 | echo "Done.\n"; 39 | --EXPECTF-- 40 | * No password given: 41 | 42 | Warning: RarEntry::extract(): ERAR_MISSING_PASSWORD (password needed but not specified) in %s on line %d 43 | bool(false) 44 | 45 | * NULL given (should have the same effect as no password): 46 | 47 | Warning: RarEntry::extract(): ERAR_MISSING_PASSWORD (password needed but not specified) in %s on line %d 48 | bool(false) 49 | 50 | * empty string given as password (should have the same effect as no password): 51 | 52 | Warning: RarEntry::extract(): ERAR_MISSING_PASSWORD (password needed but not specified) in %s on line %d 53 | bool(false) 54 | 55 | * password given; a wrong one: 56 | 57 | Warning: RarEntry::extract(): ERAR_BAD_DATA in %s on line %d 58 | bool(false) 59 | 60 | Done. 61 | -------------------------------------------------------------------------------- /tests/077.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarArchive::open NULL can be given to indicate there's no password 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | getEntry("garbage.txt")); 27 | 28 | echo "\nUsage of directory stream:\n"; 29 | $it = new DirectoryIterator("rar://" . rawurlencode($f)); 30 | foreach ($it as $e) { 31 | die("should not get here"); 32 | } 33 | echo "Success.\n"; 34 | 35 | echo "\nUsage of static url stat:\n"; 36 | stat("rar://" . rawurlencode($f) . "#not_there"); 37 | echo "Success.\n"; 38 | 39 | echo "\n"; 40 | echo "Done.\n"; 41 | --EXPECTF-- 42 | Traversal with rar_list: 43 | array(0) { 44 | } 45 | Traversal with rar_list (again with the same object): 46 | array(0) { 47 | } 48 | 49 | Traversal with foreach: 50 | Success. 51 | 52 | Usage of RarArchive::getEntry: 53 | 54 | Warning: RarArchive::getEntry(): cannot find file "garbage.txt" in Rar archive "%sgarbage.part03.rar" in %s on line %d 55 | bool(false) 56 | 57 | Usage of directory stream: 58 | Success. 59 | 60 | Usage of static url stat: 61 | 62 | Warning: stat(): Found no entry not_there in archive %sgarbage.part03.rar in %s on line %d 63 | 64 | Warning: stat(): stat failed for rar://%sgarbage.part03.rar#not_there in %s on line %d 65 | Success. 66 | 67 | Done. 68 | -------------------------------------------------------------------------------- /tests/079.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarArchive count elements handler test 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | close(); 18 | var_dump(count($a)); 19 | 20 | echo "\n* Closed file test (2):\n"; 21 | $a = RarArchive::open($f); 22 | $a->getEntries(); 23 | $a->close(); 24 | var_dump(count($a)); 25 | 26 | echo "\n* Closed file test (3, exceptions):\n"; 27 | $a = RarArchive::open($f); 28 | RarException::setUsingExceptions(true); 29 | $a->getEntries(); 30 | $a->close(); 31 | try { 32 | var_dump(count($a)); 33 | } catch (RarException $e) { 34 | echo "OK, threw exception with message \"".$e->getMessage()."\"\n"; 35 | } 36 | RarException::setUsingExceptions(false); 37 | 38 | echo "\n* Empty file:\n"; 39 | 40 | $a = RarArchive::open($fempty); 41 | echo "Count: " . count($a) . "\n"; 42 | 43 | echo "\n"; 44 | echo "Done.\n"; 45 | --EXPECTF-- 46 | * Normal test: 47 | Count: 13 48 | 49 | * Closed file test (1): 50 | 51 | Warning: %s(): The archive is already closed in %s on line %d 52 | int(0) 53 | 54 | * Closed file test (2): 55 | 56 | Warning: %s(): The archive is already closed in %s on line %d 57 | int(0) 58 | 59 | * Closed file test (3, exceptions): 60 | OK, threw exception with message "The archive is already closed" 61 | 62 | * Empty file: 63 | Count: 0 64 | 65 | Done. 66 | -------------------------------------------------------------------------------- /tests/082.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarArchive read_property handler basic test 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 21 | 22 | Notice: A non well formed numeric value encountered in %s on line %d 23 | 24 | string ("1abc"). RarEntry for file "2.txt" (45a918de) 25 | float (0.001). RarEntry for file "1.txt" (a0de71c0) 26 | string ("0.001"). RarEntry for file "1.txt" (a0de71c0) 27 | 28 | Done. 29 | -------------------------------------------------------------------------------- /tests/084.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarArchive read_property handler invalid dimensions 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | = 80000) { ?> 85 | Warning: main(): Could not convert object given as dimension index into an integer (cast_object failed) in %s on line %d 86 | 87 | 88 | Notice: Object of class stdClass could not be converted to int in %s on line %d 89 | RarEntry for file "2.txt" (45a918de) 90 | 91 | Done. 92 | -------------------------------------------------------------------------------- /tests/085.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarArchive has_property handler is given a closed archive 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | close(); 11 | 12 | var_dump(isset($a[0])); 13 | 14 | echo "\n"; 15 | echo "Done.\n"; 16 | --EXPECTF-- 17 | Warning: main(): The archive is already closed in %s on line %d 18 | bool(false) 19 | 20 | Done. 21 | -------------------------------------------------------------------------------- /tests/086.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarArchive write_property gives a fatal error 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 5 | --FILE-- 6 | 8 | --FILE-- 9 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | isBroken("jjj"); 16 | }); 17 | argerr(function() use ($a) { 18 | rar_broken_is($a, "jjj"); 19 | }); 20 | 21 | echo "\n* unbroken file; as first call\n"; 22 | var_dump($a->isBroken()); 23 | 24 | echo "\n* unbroken file; as second call\n"; 25 | $a = RarArchive::open($f); 26 | $a->getEntries(); 27 | var_dump($a->isBroken()); 28 | 29 | echo "\n* broken file; as first call; don't allow broken\n"; 30 | $a = RarArchive::open($b); 31 | var_dump($a->isBroken()); 32 | 33 | echo "\n* broken file; as first call; don't allow broken; kill warning\n"; 34 | function retnull() { return null; } 35 | $a = RarArchive::open($b, null, 'retnull'); 36 | var_dump($a->isBroken()); 37 | 38 | echo "\n* broken file; as first call; don't allow broken; kill warning; non OOP\n"; 39 | $a = RarArchive::open($b, null, 'retnull'); 40 | var_dump(rar_broken_is($a)); 41 | 42 | echo "\n* broken file; as second call; don't allow broken\n"; 43 | $a = RarArchive::open($b); 44 | $a->getEntries(); 45 | var_dump($a->isBroken()); 46 | 47 | 48 | echo "\n"; 49 | echo "Done.\n"; 50 | --EXPECTF-- 51 | * unbroken file; bad arguments 52 | 53 | Warning: RarArchive::isBroken() expects exactly 0 parameters, 1 given in %s on line %d 54 | 55 | Warning: rar_broken_is() expects exactly 1 parameter, 2 given in %s on line %d 56 | 57 | * unbroken file; as first call 58 | bool(false) 59 | 60 | * unbroken file; as second call 61 | bool(false) 62 | 63 | * broken file; as first call; don't allow broken 64 | 65 | Warning: RarArchive::isBroken(): Volume %smulti_broken.part2.rar was not found in %s on line %d 66 | bool(true) 67 | 68 | * broken file; as first call; don't allow broken; kill warning 69 | bool(true) 70 | 71 | * broken file; as first call; don't allow broken; kill warning; non OOP 72 | bool(true) 73 | 74 | * broken file; as second call; don't allow broken 75 | 76 | Warning: RarArchive::getEntries(): Volume %smulti_broken.part2.rar was not found in %s on line %d 77 | 78 | Warning: RarArchive::getEntries(): ERAR_EOPEN (file open error) in %s on line %d 79 | bool(true) 80 | 81 | Done. 82 | -------------------------------------------------------------------------------- /tests/092.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarArchive::setAllowBroken has the desired effect 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setAllowBroken(); 16 | }); 17 | argerr(function() use ($a) { 18 | rar_allow_broken_set($a); 19 | }); 20 | 21 | echo "\n* broken file; do not allow broken (default)\n"; 22 | $a = RarArchive::open($b, null, 'retnull'); 23 | var_dump($a->getEntries()); 24 | var_dump(count($a)); 25 | 26 | echo "\n* broken file; do not allow broken (explicit)\n"; 27 | $a = RarArchive::open($b, null, 'retnull'); 28 | $a->setAllowBroken(false); 29 | var_dump($a->getEntries()); 30 | var_dump(count($a)); 31 | 32 | echo "\n* broken file; allow broken\n"; 33 | $a = RarArchive::open($b, null, 'retnull'); 34 | $a->setAllowBroken(true); 35 | foreach ($a->getEntries() as $e) { 36 | echo "$e\n"; 37 | } 38 | var_dump(count($a)); 39 | 40 | echo "\n* broken file; allow broken; non OOP\n"; 41 | $a = RarArchive::open($b, null, 'retnull'); 42 | rar_allow_broken_set($a, true); 43 | foreach ($a->getEntries() as $e) { 44 | echo "$e\n"; 45 | } 46 | var_dump(count($a)); 47 | 48 | echo "\n"; 49 | echo "Done.\n"; 50 | --EXPECTF-- 51 | * broken file; bad arguments 52 | 53 | Warning: RarArchive::setAllowBroken() expects exactly 1 parameter, 0 given in %s on line %d 54 | 55 | Warning: rar_allow_broken_set() expects exactly 2 parameters, 1 given in %s on line %d 56 | 57 | * broken file; do not allow broken (default) 58 | 59 | Warning: RarArchive::getEntries(): ERAR_EOPEN (file open error) in %s on line %d 60 | bool(false) 61 | 62 | Warning: %s(): ERAR_EOPEN (file open error) in %s on line %d 63 | int(0) 64 | 65 | * broken file; do not allow broken (explicit) 66 | 67 | Warning: RarArchive::getEntries(): ERAR_EOPEN (file open error) in %s on line %d 68 | bool(false) 69 | 70 | Warning: %s(): ERAR_EOPEN (file open error) in %s on line %d 71 | int(0) 72 | 73 | * broken file; allow broken 74 | RarEntry for file "file1.txt" (52b28202) 75 | int(1) 76 | 77 | * broken file; allow broken; non OOP 78 | RarEntry for file "file1.txt" (52b28202) 79 | int(1) 80 | 81 | Done. 82 | -------------------------------------------------------------------------------- /tests/093.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Traversal of RarArchive with foreach by reference gives error 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | close(); 14 | echo $a."\n"; 15 | 16 | $a->close(); 17 | echo $a."\n"; 18 | 19 | echo "\n"; 20 | echo "Done.\n"; 21 | --EXPECTF-- 22 | RAR Archive "%slatest_winrar.rar" 23 | RAR Archive "%slatest_winrar.rar" (closed) 24 | 25 | Warning: RarArchive::close(): The archive is already closed in %s on line %d 26 | RAR Archive "%slatest_winrar.rar" (closed) 27 | 28 | Done. 29 | -------------------------------------------------------------------------------- /tests/096.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Module info test 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | enabled 41 | RAR EXT version => %d.%d.%s 42 | UnRAR version => %d.%d%spatch%d %d-%d-%d 43 | UnRAR API version => %d extension %d 44 | 45 | Done. 46 | -------------------------------------------------------------------------------- /tests/097.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | PECL bug #18449 (Extraction of uncompressed and encrypted files fails) 3 | --SKIPIF-- 4 | 5 | --CLEAN-- 6 | extract(dirname(__FILE__)); 20 | } 21 | @unlink(dirname(__FILE__) . '/base.css'); 22 | @unlink(dirname(__FILE__) . '/reset.css'); 23 | rar_close($rar); 24 | } 25 | 26 | echo "\nDone.\n"; 27 | --EXPECTF-- 28 | secret-crypted-none.rar 29 | secret-none.rar 30 | 31 | Done. -------------------------------------------------------------------------------- /tests/098.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | PECL bug #18449 (Extraction of uncompressed and encrypted files fails; stream variant) 3 | --SKIPIF-- 4 | 5 | --CLEAN-- 6 | getStream()))); 15 | } 16 | 17 | echo "\nDone.\n"; 18 | --EXPECTF-- 19 | Warning: stream_get_contents(): The file size is supposed to be 2279 bytes, but we read more: 2288 bytes (corruption/wrong pwd) in %s on line %d 20 | int(2288) 21 | 22 | Warning: stream_get_contents(): The file size is supposed to be 1316 bytes, but we read more: 1328 bytes (corruption/wrong pwd) in %s on line %d 23 | int(1328) 24 | 25 | Done. 26 | -------------------------------------------------------------------------------- /tests/099.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #59939: Streaming empty file from archive issues a warning 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getEntry('empty_file'); 12 | if ($rar_file === false) die("could not find entry"); 13 | 14 | $stream = $rar_file->getStream(); 15 | if ($stream === false) die("could not open stream"); 16 | 17 | var_dump(feof($stream), 18 | fread($stream, 1024*1024), 19 | feof($stream)); 20 | 21 | echo "\n"; 22 | echo "Done.\n"; 23 | ?> 24 | --EXPECT-- 25 | bool(false) 26 | string(0) "" 27 | bool(true) 28 | 29 | Done. 30 | -------------------------------------------------------------------------------- /tests/100.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | fopen modes 'r' and 'rb' are the only allowed 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 26 | --EXPECTF-- 27 | Testing 'r' 28 | opened 29 | 30 | Testing 'rb' 31 | opened 32 | 33 | Testing 'r+' 34 | 35 | Warning: fopen(%s): %cailed to open stream: Only the "r" and "rb" open modes are permitted, given r+ in %s on line %d 36 | 37 | Done. 38 | -------------------------------------------------------------------------------- /tests/101.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Supports version 5 RAR files 3 | --SKIPIF-- 4 | getEntry('usr' . DIRECTORY_SEPARATOR . 'bin' . 12 | DIRECTORY_SEPARATOR . 'text2image'); 13 | var_dump($entry); 14 | $stream = $entry->getStream('passw0rd'); 15 | $contents = stream_get_contents($stream); 16 | echo "(unpacked) MD5: ", md5($contents), "\n"; 17 | echo "Done.\n"; 18 | ?> 19 | --EXPECTF-- 20 | object(RarEntry)#%d (%d) { 21 | ["rarfile%sprivate%s=> 22 | object(RarArchive)#%d (%d) { 23 | } 24 | ["position%sprivate%s=> 25 | int(0) 26 | ["name%sprivate%s=> 27 | string(18) "usr%sbin%stext2image" 28 | ["unpacked_size%sprivate%s=> 29 | int(147528) 30 | ["packed_size%sprivate%s=> 31 | int(57104) 32 | ["host_os%sprivate%s=> 33 | int(3) 34 | ["file_time%sprivate%s=> 35 | string(19) "%s" 36 | ["crc%sprivate%s=> 37 | string(8) "83c9a6b7" 38 | ["attr%sprivate%s=> 39 | int(33261) 40 | ["version%sprivate%s=> 41 | int(50) 42 | ["method%sprivate%s=> 43 | int(51) 44 | ["flags%sprivate%s=> 45 | int(5) 46 | ["redir_type%sprivate%s=> 47 | int(0) 48 | ["redir_to_directory%sprivate%s=> 49 | NULL 50 | ["redir_target%sprivate%s=> 51 | NULL 52 | } 53 | (unpacked) MD5: c07ce36ec260848f47fe8ac1408f938f 54 | Done. 55 | -------------------------------------------------------------------------------- /tests/102.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarArchive direct instantiation does not crash (PHP 7) 3 | --SKIPIF-- 4 | = 7"); 7 | --FILE-- 8 | = 7"); 6 | --FILE-- 7 | = 7"); 6 | --FILE-- 7 | getEntries(); 13 | echo "Never reached.\n"; 14 | ?> 15 | --EXPECTF-- 16 | Fatal error: Uncaught Error: Trying to clone an uncloneable object of class RarArchive in %s:5 17 | Stack trace: 18 | #0 {main} 19 | thrown in %s on line %d 20 | -------------------------------------------------------------------------------- /tests/105.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Clone of RarArchive is forbidden (PHP 5.x) 3 | --SKIPIF-- 4 | = 70000) die("skip for PHP 5.x"); 6 | --FILE-- 7 | getEntries(); 13 | echo "Never reached.\n"; 14 | ?> 15 | --EXPECTF-- 16 | Fatal error: Trying to clone an uncloneable object of class RarArchive in %s on line %d 17 | -------------------------------------------------------------------------------- /tests/106.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Stat times don't depend on timezone (cf. 056.phpt) 3 | --SKIPIF-- 4 | 'FSREDIR_UNIXSYMLINK', 10 | RarEntry::FSREDIR_WINSYMLINK => 'FSREDIR_WINSYMLINK', 11 | RarEntry::FSREDIR_JUNCTION => 'FSREDIR_JUNCTION', 12 | RarEntry::FSREDIR_HARDLINK => 'FSREDIR_HARDLINK', 13 | RarEntry::FSREDIR_FILECOPY => 'FSREDIR_FILECOPY', 14 | ); 15 | $a = rar_open(dirname(__FILE__) . '/rar5-links.rar'); 16 | $i = 0; 17 | foreach ($a as $e) { 18 | if ($i++ != 0) echo "\n"; 19 | echo "$i. ", $e->getName(), "\n"; 20 | $type = $e->getRedirType(); 21 | $type = $type ? $m[$type] : $type; 22 | echo "redir type: ", var_export($type, true), "\n"; 23 | echo "redir to dir: ", var_export($e->isRedirectToDirectory(), true), "\n"; 24 | echo "redir target: ", var_export($e->getRedirTarget(), true), "\n"; 25 | // break; 26 | } 27 | echo "Done.\n"; 28 | --EXPECTF-- 29 | 1. file1-hardlink.txt 30 | redir type: NULL 31 | redir to dir: NULL 32 | redir target: NULL 33 | 34 | 2. file1.txt 35 | redir type: 'FSREDIR_HARDLINK' 36 | redir to dir: false 37 | redir target: 'file1-hardlink.txt' 38 | 39 | 3. dir-link 40 | redir type: 'FSREDIR_UNIXSYMLINK' 41 | redir to dir: true 42 | redir target: 'dir' 43 | 44 | 4. file1-link.txt 45 | redir type: 'FSREDIR_UNIXSYMLINK' 46 | redir to dir: false 47 | redir target: 'file1.txt' 48 | 49 | 5. dir 50 | redir type: NULL 51 | redir to dir: NULL 52 | redir target: NULL 53 | Done. 54 | -------------------------------------------------------------------------------- /tests/108.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getPackedSize() 3 | --SKIPIF-- 4 | getEntry('4mb.txt'); 10 | var_dump($e->getPackedSize()); 11 | echo "Done.\n"; 12 | --EXPECTF-- 13 | int(2444) 14 | Done. 15 | -------------------------------------------------------------------------------- /tests/109.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getHostOs() 3 | --SKIPIF-- 4 | getEntry('4mb.txt'); 10 | var_dump($e->getHostOs()); 11 | var_dump(RarEntry::HOST_WIN32); 12 | echo "Done.\n"; 13 | --EXPECTF-- 14 | int(2) 15 | int(2) 16 | Done. 17 | -------------------------------------------------------------------------------- /tests/110.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getFileTime() 3 | --SKIPIF-- 4 | getEntry('4mb.txt'); 10 | var_dump($e->getFileTime()); 11 | echo "Done.\n"; 12 | --EXPECTF-- 13 | string(19) "2010-05-30 01:22:00" 14 | Done. 15 | -------------------------------------------------------------------------------- /tests/111.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getVersion() 3 | --SKIPIF-- 4 | getEntry('file1.txt'); 10 | var_dump($e->getVersion()); 11 | echo "Done.\n"; 12 | --EXPECTF-- 13 | int(50) 14 | Done. 15 | -------------------------------------------------------------------------------- /tests/112.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::getMethod() 3 | --SKIPIF-- 4 | getEntry('file1.txt'); 10 | var_dump($e->getMethod()); 11 | echo "Done.\n"; 12 | --EXPECTF-- 13 | int(48) 14 | Done. 15 | -------------------------------------------------------------------------------- /tests/113.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | RarEntry::isEncrypted() 3 | --SKIPIF-- 4 | getEntry('file1.txt'); 10 | var_dump($e->isEncrypted()); 11 | 12 | $a = rar_open(dirname(__FILE__) . '/encrypted_only_files.rar'); 13 | $e = $a->getEntry('encfile1.txt'); 14 | var_dump($e->isEncrypted()); 15 | echo "Done.\n"; 16 | --EXPECTF-- 17 | bool(false) 18 | bool(true) 19 | Done. 20 | -------------------------------------------------------------------------------- /tests/114.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug 76592: solid files are partially extracted 3 | --SKIPIF-- 4 | setAllowBroken(true); // we don't fixup the headers checksum, only the contents. Ignore the error 27 | $entry = $rar->getEntry('test.dat') or die('Unable to get entry'); 28 | 29 | $contents = stream_get_contents($entry->getStream(), $entry->getUnpackedSize()); 30 | $crc32_rar = $entry->getCrc(); 31 | $crc32_cont = dechex(crc32($contents)); 32 | $crc32_orig_content = dechex(crc32($contents)); 33 | 34 | unlink($file); 35 | 36 | echo 'orig content size: ', strlen($middle), "\n"; 37 | echo 'read content size: ', strlen($contents), "\n"; 38 | 39 | if ($crc32_rar !== $crc32_cont) { 40 | die("CRC values do not match"); 41 | } 42 | if ($crc32_rar !== $crc32_orig_content) { 43 | die("CRC values do not match (2)"); 44 | } 45 | ?> 46 | ==DONE== 47 | --EXPECT-- 48 | orig content size: 10485760 49 | read content size: 10485760 50 | ==DONE== 51 | -------------------------------------------------------------------------------- /tests/115.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | getIterator() (PHP 8+) 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | getIterator(); 13 | var_dump($it); 14 | foreach ($it as $e) { 15 | echo $e->getName(), "\n"; 16 | } 17 | 18 | echo "Done\n"; 19 | ?> 20 | --EXPECT-- 21 | object(InternalIterator)#3 (0) { 22 | } 23 | plain.txt 24 | test file with whitespaces.txt 25 | Done 26 | -------------------------------------------------------------------------------- /tests/4mb.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/4mb.rar -------------------------------------------------------------------------------- /tests/commented.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/commented.rar -------------------------------------------------------------------------------- /tests/corrupted.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/corrupted.rar -------------------------------------------------------------------------------- /tests/directories.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/directories.rar -------------------------------------------------------------------------------- /tests/dirlink_unix.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/dirlink_unix.rar -------------------------------------------------------------------------------- /tests/dirs_and_extra_headers.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/dirs_and_extra_headers.rar -------------------------------------------------------------------------------- /tests/empty_file.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/empty_file.rar -------------------------------------------------------------------------------- /tests/encrypted_headers.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/encrypted_headers.rar -------------------------------------------------------------------------------- /tests/encrypted_only_files.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/encrypted_only_files.rar -------------------------------------------------------------------------------- /tests/garbage.part03.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/garbage.part03.rar -------------------------------------------------------------------------------- /tests/latest_winrar.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/latest_winrar.rar -------------------------------------------------------------------------------- /tests/linux_rar.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/linux_rar.rar -------------------------------------------------------------------------------- /tests/multi.part1.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/multi.part1.rar -------------------------------------------------------------------------------- /tests/multi.part2.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/multi.part2.rar -------------------------------------------------------------------------------- /tests/multi.part3.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/multi.part3.rar -------------------------------------------------------------------------------- /tests/multi_broken.part1.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/multi_broken.part1.rar -------------------------------------------------------------------------------- /tests/php8compat.php.inc: -------------------------------------------------------------------------------- 1 | getMessage(); 10 | $msg = "Warning: $msg in {$err->getFile()} on line {$err->getLine()}"; 11 | $msg = preg_replace('/: Argument #(\d) \(\$\S+\) must be of type/', 12 | ' expects parameter \1 to be', $msg); 13 | $msg = preg_replace('/expects (.+) (\d) argument/', 14 | 'expects \1 \2 parameter', $msg); 15 | echo "\n", $msg, "\n"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/rar5-links.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/rar5-links.rar -------------------------------------------------------------------------------- /tests/rar5_multi.part1.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/rar5_multi.part1.rar -------------------------------------------------------------------------------- /tests/rar5_multi.part2.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/rar5_multi.part2.rar -------------------------------------------------------------------------------- /tests/rar_notrar.rar: -------------------------------------------------------------------------------- 1 | 6TGStcOyuEWU8uIuUALyOj7+iCAgQNcpGomfIg1QBpnXaiT93Ie8RbflCUO8u/1Z4hKNrieUqfoz 2 | R8hO/foBjEosLYUxjjMMqg7JYNd//Mp8UNqcI/0Ao8tXUfAdpKzNu2N3gYV99xRG3yUOWeAXI1Gx 3 | CaTj0uHuyzUQbskZdxInMqzajd9f9GVjpgrrz3sJNYMAT1qnFbCfXvRynv+Aby3TAiZKgnPVxuLs 4 | VpaieK8VmL0fNzIqoPSUqyMn+9t8fd/fuJmvkXSl/et7YSsE/4hmSGf1XPLw0khH7jmnyTMxh7BF 5 | VLjAt0bypII0tWZsQG7tHFtUb4UG2Np5Wt8ejCowkIHrBsUdZ4ALnySQmmqtakkqeFr73YPrhKGr 6 | y7ZeQb2sCAPv/NbDMj3q6JeeiIbBNx0OS2oIf1UVbU8fzvbDdZnd579K/b0YP3B7wKK5P54fd9eg 7 | kiapUkMAcFv7rSFBDGpszDhQFWpWJBY2OJCrAz0B+ZLymTYxiiirT4wTrTerAExTVHlHJF2r66m7 8 | VvXnJ+f6VnqIkSSFhAiHfT1ckCyGcTHBU7wy5ODDDsvUy7dZ2/eq1OhhnPS0lpvZLUiDtAAnBMcq 9 | axoA18HW9yccAh8BAnbQ/H7fIXqc4P3zA5CnxjAal25HE+3IVT4DCqOpT27aZvb/fJIkZDeXxwYv -------------------------------------------------------------------------------- /tests/rar_unicode.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/rar_unicode.rar -------------------------------------------------------------------------------- /tests/repeated_name.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/repeated_name.rar -------------------------------------------------------------------------------- /tests/secret-crypted-none.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/secret-crypted-none.rar -------------------------------------------------------------------------------- /tests/secret-none.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/secret-none.rar -------------------------------------------------------------------------------- /tests/solid.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/solid.rar -------------------------------------------------------------------------------- /tests/sparsefiles_rar.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/sparsefiles_rar.rar -------------------------------------------------------------------------------- /tests/store_method.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/tests/store_method.rar -------------------------------------------------------------------------------- /unrar/LICENSE.txt: -------------------------------------------------------------------------------- 1 | ****** ***** ****** UnRAR - free utility for RAR archives 2 | ** ** ** ** ** ** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 | ****** ******* ****** License for use and distribution of 4 | ** ** ** ** ** ** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | ** ** ** ** ** ** FREE portable version 6 | ~~~~~~~~~~~~~~~~~~~~~ 7 | 8 | The source code of UnRAR utility is freeware. This means: 9 | 10 | 1. All copyrights to RAR and the utility UnRAR are exclusively 11 | owned by the author - Alexander Roshal. 12 | 13 | 2. UnRAR source code may be used in any software to handle 14 | RAR archives without limitations free of charge, but cannot be 15 | used to develop RAR (WinRAR) compatible archiver and to 16 | re-create RAR compression algorithm, which is proprietary. 17 | Distribution of modified UnRAR source code in separate form 18 | or as a part of other software is permitted, provided that 19 | full text of this paragraph, starting from "UnRAR source code" 20 | words, is included in license, or in documentation if license 21 | is not available, and in source code comments of resulting package. 22 | 23 | 3. The UnRAR utility may be freely distributed. It is allowed 24 | to distribute UnRAR inside of other software packages. 25 | 26 | 4. THE RAR ARCHIVER AND THE UnRAR UTILITY ARE DISTRIBUTED "AS IS". 27 | NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED. YOU USE AT 28 | YOUR OWN RISK. THE AUTHOR WILL NOT BE LIABLE FOR DATA LOSS, 29 | DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING 30 | OR MISUSING THIS SOFTWARE. 31 | 32 | 5. Installing and using the UnRAR utility signifies acceptance of 33 | these terms and conditions of the license. 34 | 35 | 6. If you don't agree with terms of the license you must remove 36 | UnRAR files from your storage devices and cease to use the 37 | utility. 38 | 39 | Thank you for your interest in RAR and UnRAR. 40 | 41 | 42 | Alexander L. Roshal 43 | -------------------------------------------------------------------------------- /unrar/README.txt: -------------------------------------------------------------------------------- 1 | 2 | Portable UnRAR version 3 | 4 | 5 | 1. General 6 | 7 | This package includes freeware Unrar C++ source and makefile for 8 | several Unix compilers. 9 | 10 | Unrar source is subset of RAR and generated from RAR source automatically, 11 | by a small program removing blocks like '#ifndef UNRAR ... #endif'. 12 | Such method is not perfect and you may find some RAR related stuff 13 | unnecessary in Unrar, especially in header files. 14 | 15 | If you wish to port Unrar to a new platform, you may need to edit 16 | '#define LITTLE_ENDIAN' in os.hpp and data type definitions 17 | in rartypes.hpp. 18 | 19 | if computer architecture does not allow not aligned data access, 20 | you need to undefine ALLOW_NOT_ALIGNED_INT and define 21 | STRICT_ALIGNMENT_REQUIRED in os.h. 22 | 23 | 24 | 2. Unrar binaries 25 | 26 | If you compiled Unrar for OS, which is not present in "Downloads" 27 | and "RAR extras" on www.rarlab.com, we will appreciate if you send 28 | us the compiled executable to place it to our site. 29 | 30 | 31 | 3. Acknowledgements 32 | 33 | This source includes parts of code written by other authors. 34 | Please see acknow.txt file for details. 35 | 36 | 37 | 4. Legal stuff 38 | 39 | Unrar source may be used in any software to handle RAR archives 40 | without limitations free of charge, but cannot be used to re-create 41 | the RAR compression algorithm, which is proprietary. Distribution 42 | of modified Unrar source in separate form or as a part of other 43 | software is permitted, provided that it is clearly stated in 44 | the documentation and source comments that the code may not be used 45 | to develop a RAR (WinRAR) compatible archiver. 46 | 47 | More detailed license text is available in license.txt. 48 | -------------------------------------------------------------------------------- /unrar/cmddata.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_CMDDATA_ 2 | #define _RAR_CMDDATA_ 3 | 4 | 5 | #define DefaultStoreList L"7z;ace;arj;bz2;cab;gz;jpeg;jpg;lha;lz;lzh;mp3;rar;taz;tgz;xz;z;zip;zipx" 6 | 7 | enum RAR_CMD_LIST_MODE {RCLM_AUTO,RCLM_REJECT_LISTS,RCLM_ACCEPT_LISTS}; 8 | 9 | enum IS_PROCESS_FILE_FLAGS {IPFF_EXCLUDE_PARENT=1}; 10 | 11 | class CommandData:public RAROptions 12 | { 13 | private: 14 | void ProcessSwitch(const wchar *Switch); 15 | void BadSwitch(const wchar *Switch); 16 | uint GetExclAttr(const wchar *Str,bool &Dir); 17 | #if !defined(SFX_MODULE) 18 | void SetTimeFilters(const wchar *Mod,bool Before,bool Age); 19 | void SetStoreTimeMode(const wchar *S); 20 | #endif 21 | 22 | bool FileLists; 23 | bool NoMoreSwitches; 24 | RAR_CMD_LIST_MODE ListMode; 25 | bool BareOutput; 26 | public: 27 | CommandData(); 28 | void Init(); 29 | 30 | void ParseCommandLine(bool Preprocess,int argc, char *argv[]); 31 | void ParseArg(wchar *ArgW); 32 | void ParseDone(); 33 | void ParseEnvVar(); 34 | void ReadConfig(); 35 | void PreprocessArg(const wchar *Arg); 36 | void ProcessSwitchesString(const wchar *Str); 37 | void OutTitle(); 38 | void OutHelp(RAR_EXIT ExitCode); 39 | bool IsSwitch(int Ch); 40 | bool ExclCheck(const wchar *CheckName,bool Dir,bool CheckFullPath,bool CheckInclList); 41 | static bool CheckArgs(StringList *Args,bool Dir,const wchar *CheckName,bool CheckFullPath,int MatchMode); 42 | bool ExclDirByAttr(uint FileAttr); 43 | bool TimeCheck(RarTime &ftm,RarTime &ftc,RarTime &fta); 44 | bool SizeCheck(int64 Size); 45 | bool AnyFiltersActive(); 46 | int IsProcessFile(FileHeader &FileHead,bool *ExactMatch,int MatchType, 47 | bool Flags,wchar *MatchedArg,uint MatchedArgSize); 48 | void ProcessCommand(); 49 | void AddArcName(const wchar *Name); 50 | bool GetArcName(wchar *Name,int MaxSize); 51 | bool CheckWinSize(); 52 | 53 | int GetRecoverySize(const wchar *Str,int DefSize); 54 | 55 | #ifndef SFX_MODULE 56 | void ReportWrongSwitches(RARFORMAT Format); 57 | #endif 58 | 59 | wchar Command[NM+16]; 60 | 61 | wchar ArcName[NM]; 62 | 63 | StringList FileArgs; 64 | StringList ExclArgs; 65 | StringList InclArgs; 66 | StringList ArcNames; 67 | StringList StoreArgs; 68 | }; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /unrar/coder.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | inline unsigned int RangeCoder::GetChar() 4 | { 5 | return(UnpackRead->GetChar()); 6 | } 7 | 8 | 9 | void RangeCoder::InitDecoder(Unpack *UnpackRead) 10 | { 11 | RangeCoder::UnpackRead=UnpackRead; 12 | 13 | low=code=0; 14 | range=uint(-1); 15 | for (int i=0;i < 4;i++) 16 | code=(code << 8) | GetChar(); 17 | } 18 | 19 | 20 | // (int) cast before "low" added only to suppress compiler warnings. 21 | #define ARI_DEC_NORMALIZE(code,low,range,read) \ 22 | { \ 23 | while ((low^(low+range))GetChar(); \ 26 | range <<= 8; \ 27 | low <<= 8; \ 28 | } \ 29 | } 30 | 31 | 32 | inline int RangeCoder::GetCurrentCount() 33 | { 34 | return (code-low)/(range /= SubRange.scale); 35 | } 36 | 37 | 38 | inline uint RangeCoder::GetCurrentShiftCount(uint SHIFT) 39 | { 40 | return (code-low)/(range >>= SHIFT); 41 | } 42 | 43 | 44 | inline void RangeCoder::Decode() 45 | { 46 | low += range*SubRange.LowCount; 47 | range *= SubRange.HighCount-SubRange.LowCount; 48 | } 49 | -------------------------------------------------------------------------------- /unrar/coder.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Contents: 'Carryless rangecoder' by Dmitry Subbotin * 3 | ****************************************************************************/ 4 | 5 | 6 | class RangeCoder 7 | { 8 | public: 9 | void InitDecoder(Unpack *UnpackRead); 10 | inline int GetCurrentCount(); 11 | inline uint GetCurrentShiftCount(uint SHIFT); 12 | inline void Decode(); 13 | inline void PutChar(unsigned int c); 14 | inline unsigned int GetChar(); 15 | 16 | uint low, code, range; 17 | struct SUBRANGE 18 | { 19 | uint LowCount, HighCount, scale; 20 | } SubRange; 21 | 22 | Unpack *UnpackRead; 23 | }; 24 | -------------------------------------------------------------------------------- /unrar/compress.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_COMPRESS_ 2 | #define _RAR_COMPRESS_ 3 | 4 | // Combine pack and unpack constants to class to avoid polluting global 5 | // namespace with numerous short names. 6 | class PackDef 7 | { 8 | public: 9 | // Maximum LZ match length we can encode even for short distances. 10 | static const uint MAX_LZ_MATCH = 0x1001; 11 | 12 | // We increment LZ match length for longer distances, because shortest 13 | // matches are not allowed for them. Maximum length increment is 3 14 | // for distances larger than 256KB (0x40000). Here we define the maximum 15 | // incremented LZ match. Normally packer does not use it, but we must be 16 | // ready to process it in corrupt archives. 17 | static const uint MAX_INC_LZ_MATCH = MAX_LZ_MATCH + 3; 18 | 19 | static const uint MAX3_LZ_MATCH = 0x101; // Maximum match length for RAR v3. 20 | static const uint LOW_DIST_REP_COUNT = 16; 21 | 22 | static const uint NC = 306; /* alphabet = {0, 1, 2, ..., NC - 1} */ 23 | static const uint DC = 64; 24 | static const uint LDC = 16; 25 | static const uint RC = 44; 26 | static const uint HUFF_TABLE_SIZE = NC + DC + RC + LDC; 27 | static const uint BC = 20; 28 | 29 | static const uint NC30 = 299; /* alphabet = {0, 1, 2, ..., NC - 1} */ 30 | static const uint DC30 = 60; 31 | static const uint LDC30 = 17; 32 | static const uint RC30 = 28; 33 | static const uint BC30 = 20; 34 | static const uint HUFF_TABLE_SIZE30 = NC30 + DC30 + RC30 + LDC30; 35 | 36 | static const uint NC20 = 298; /* alphabet = {0, 1, 2, ..., NC - 1} */ 37 | static const uint DC20 = 48; 38 | static const uint RC20 = 28; 39 | static const uint BC20 = 19; 40 | static const uint MC20 = 257; 41 | 42 | // Largest alphabet size among all values listed above. 43 | static const uint LARGEST_TABLE_SIZE = 306; 44 | 45 | enum { 46 | CODE_HUFFMAN, CODE_LZ, CODE_REPEATLZ, CODE_CACHELZ, CODE_STARTFILE, 47 | CODE_ENDFILE, CODE_FILTER, CODE_FILTERDATA 48 | }; 49 | }; 50 | 51 | 52 | enum FilterType { 53 | // These values must not be changed, because we use them directly 54 | // in RAR5 compression and decompression code. 55 | FILTER_DELTA=0, FILTER_E8, FILTER_E8E9, FILTER_ARM, 56 | FILTER_AUDIO, FILTER_RGB, FILTER_ITANIUM, FILTER_PPM, FILTER_NONE 57 | }; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /unrar/consio.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_CONSIO_ 2 | #define _RAR_CONSIO_ 3 | 4 | void InitConsole(); 5 | void SetConsoleMsgStream(MESSAGE_TYPE MsgStream); 6 | void SetConsoleRedirectCharset(RAR_CHARSET RedirectCharset); 7 | void OutComment(const wchar *Comment,size_t Size); 8 | 9 | #ifndef SILENT 10 | bool GetConsolePassword(UIPASSWORD_TYPE Type,const wchar *FileName,SecPassword *Password); 11 | #endif 12 | 13 | #ifdef SILENT 14 | inline void mprintf(const wchar *fmt,...) {} 15 | inline void eprintf(const wchar *fmt,...) {} 16 | inline void Alarm() {} 17 | inline int Ask(const wchar *AskStr) {return 0;} 18 | inline bool getwstr(wchar *str,size_t n) {return false;} 19 | #else 20 | void mprintf(const wchar *fmt,...); 21 | void eprintf(const wchar *fmt,...); 22 | void Alarm(); 23 | int Ask(const wchar *AskStr); 24 | bool getwstr(wchar *str,size_t n); 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /unrar/crc.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_CRC_ 2 | #define _RAR_CRC_ 3 | 4 | // This function is only to intialize external CRC tables. We do not need to 5 | // call it before calculating CRC32. 6 | void InitCRC32(uint *CRCTab); 7 | 8 | uint CRC32(uint StartCRC,const void *Addr,size_t Size); 9 | 10 | #ifndef SFX_MODULE 11 | ushort Checksum14(ushort StartCRC,const void *Addr,size_t Size); 12 | #endif 13 | 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /unrar/crypt1.cpp: -------------------------------------------------------------------------------- 1 | extern uint CRCTab[256]; 2 | 3 | void CryptData::SetKey13(const char *Password) 4 | { 5 | Key13[0]=Key13[1]=Key13[2]=0; 6 | for (size_t I=0;Password[I]!=0;I++) 7 | { 8 | byte P=Password[I]; 9 | Key13[0]+=P; 10 | Key13[1]^=P; 11 | Key13[2]+=P; 12 | Key13[2]=(byte)rotls(Key13[2],1,8); 13 | } 14 | } 15 | 16 | 17 | void CryptData::SetKey15(const char *Password) 18 | { 19 | InitCRC32(CRCTab); 20 | uint PswCRC=CRC32(0xffffffff,Password,strlen(Password)); 21 | Key15[0]=PswCRC&0xffff; 22 | Key15[1]=(PswCRC>>16)&0xffff; 23 | Key15[2]=Key15[3]=0; 24 | for (size_t I=0;Password[I]!=0;I++) 25 | { 26 | byte P=Password[I]; 27 | Key15[2]^=P^CRCTab[P]; 28 | Key15[3]+=P+(CRCTab[P]>>16); 29 | } 30 | } 31 | 32 | 33 | void CryptData::SetAV15Encryption() 34 | { 35 | InitCRC32(CRCTab); 36 | Method=CRYPT_RAR15; 37 | Key15[0]=0x4765; 38 | Key15[1]=0x9021; 39 | Key15[2]=0x7382; 40 | Key15[3]=0x5215; 41 | } 42 | 43 | 44 | void CryptData::SetCmt13Encryption() 45 | { 46 | Method=CRYPT_RAR13; 47 | Key13[0]=0; 48 | Key13[1]=7; 49 | Key13[2]=77; 50 | } 51 | 52 | 53 | void CryptData::Decrypt13(byte *Data,size_t Count) 54 | { 55 | while (Count--) 56 | { 57 | Key13[1]+=Key13[2]; 58 | Key13[0]+=Key13[1]; 59 | *Data-=Key13[0]; 60 | Data++; 61 | } 62 | } 63 | 64 | 65 | void CryptData::Crypt15(byte *Data,size_t Count) 66 | { 67 | while (Count--) 68 | { 69 | Key15[0]+=0x1234; 70 | Key15[1]^=CRCTab[(Key15[0] & 0x1fe)>>1]; 71 | Key15[2]-=CRCTab[(Key15[0] & 0x1fe)>>1]>>16; 72 | Key15[0]^=Key15[2]; 73 | Key15[3]=rotrs(Key15[3]&0xffff,1,16)^Key15[1]; 74 | Key15[3]=rotrs(Key15[3]&0xffff,1,16); 75 | Key15[0]^=Key15[3]; 76 | *Data^=(byte)(Key15[0]>>8); 77 | Data++; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /unrar/crypt2.loT: -------------------------------------------------------------------------------- 1 | # unrar/crypt2.lo - a libtool object file 2 | # Generated by ltmain.sh - GNU libtool 1.5.26 (1.1220.2.492 2008/01/30 06:40:56) 3 | # 4 | # Please DO NOT delete this file! 5 | # It is necessary for linking the library. 6 | 7 | # Name of the PIC object. 8 | -------------------------------------------------------------------------------- /unrar/crypt3.cpp: -------------------------------------------------------------------------------- 1 | void CryptData::SetKey30(bool Encrypt,SecPassword *Password,const wchar *PwdW,const byte *Salt) 2 | { 3 | byte AESKey[16],AESInit[16]; 4 | 5 | bool Cached=false; 6 | for (uint I=0;I>8); 38 | PswNum[2]=(byte)(I>>16); 39 | sha1_process(&c, PswNum, 3); 40 | if (I%(HashRounds/16)==0) 41 | { 42 | sha1_context tempc=c; 43 | uint32 digest[5]; 44 | sha1_done( &tempc, digest ); 45 | AESInit[I/(HashRounds/16)]=(byte)digest[4]; 46 | } 47 | } 48 | uint32 digest[5]; 49 | sha1_done( &c, digest ); 50 | for (uint I=0;I<4;I++) 51 | for (uint J=0;J<4;J++) 52 | AESKey[I*4+J]=(byte)(digest[I]>>(J*8)); 53 | 54 | KDF3Cache[KDF3CachePos].Pwd=*Password; 55 | if ((KDF3Cache[KDF3CachePos].SaltPresent=(Salt!=NULL))==true) 56 | memcpy(KDF3Cache[KDF3CachePos].Salt,Salt,SIZE_SALT30); 57 | memcpy(KDF3Cache[KDF3CachePos].Key,AESKey,sizeof(AESKey)); 58 | SecHideData(KDF3Cache[KDF3CachePos].Key,sizeof(KDF3Cache[KDF3CachePos].Key),true,false); 59 | memcpy(KDF3Cache[KDF3CachePos].Init,AESInit,sizeof(AESInit)); 60 | KDF3CachePos=(KDF3CachePos+1)%ASIZE(KDF3Cache); 61 | 62 | cleandata(RawPsw,sizeof(RawPsw)); 63 | } 64 | rin.Init(Encrypt, AESKey, 128, AESInit); 65 | cleandata(AESKey,sizeof(AESKey)); 66 | cleandata(AESInit,sizeof(AESInit)); 67 | } 68 | 69 | -------------------------------------------------------------------------------- /unrar/dll.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/unrar/dll.rc -------------------------------------------------------------------------------- /unrar/dll_nocrypt.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | RAROpenArchive 3 | RAROpenArchiveEx 4 | RARCloseArchive 5 | RARReadHeader 6 | RARReadHeaderEx 7 | RARProcessFile 8 | RARProcessFileW 9 | RARSetCallback 10 | RARSetChangeVolProc 11 | RARSetProcessDataProc 12 | ; RARSetPassword 13 | RARGetDllVersion 14 | -------------------------------------------------------------------------------- /unrar/encname.cpp: -------------------------------------------------------------------------------- 1 | #include "rar.hpp" 2 | 3 | EncodeFileName::EncodeFileName() 4 | { 5 | Flags=0; 6 | FlagBits=0; 7 | FlagsPos=0; 8 | DestSize=0; 9 | } 10 | 11 | 12 | 13 | 14 | void EncodeFileName::Decode(char *Name,size_t NameSize,byte *EncName,size_t EncSize, 15 | wchar *NameW,size_t MaxDecSize) 16 | { 17 | size_t EncPos=0,DecPos=0; 18 | byte HighByte=EncPos=EncSize) 24 | break; 25 | Flags=EncName[EncPos++]; 26 | FlagBits=8; 27 | } 28 | switch(Flags>>6) 29 | { 30 | case 0: 31 | if (EncPos>=EncSize) 32 | break; 33 | NameW[DecPos++]=EncName[EncPos++]; 34 | break; 35 | case 1: 36 | if (EncPos>=EncSize) 37 | break; 38 | NameW[DecPos++]=EncName[EncPos++]+(HighByte<<8); 39 | break; 40 | case 2: 41 | if (EncPos+1>=EncSize) 42 | break; 43 | NameW[DecPos++]=EncName[EncPos]+(EncName[EncPos+1]<<8); 44 | EncPos+=2; 45 | break; 46 | case 3: 47 | { 48 | if (EncPos>=EncSize) 49 | break; 50 | int Length=EncName[EncPos++]; 51 | if ((Length & 0x80)!=0) 52 | { 53 | if (EncPos>=EncSize) 54 | break; 55 | byte Correction=EncName[EncPos++]; 56 | for (Length=(Length&0x7f)+2;Length>0 && DecPos0 && DecPos>3; 29 | InBit=Bits&7; 30 | } 31 | 32 | // Return 16 bits from current position in the buffer. 33 | // Bit at (InAddr,InBit) has the highest position in returning data. 34 | uint getbits() 35 | { 36 | uint BitField=(uint)InBuf[InAddr] << 16; 37 | BitField|=(uint)InBuf[InAddr+1] << 8; 38 | BitField|=(uint)InBuf[InAddr+2]; 39 | BitField >>= (8-InBit); 40 | return BitField & 0xffff; 41 | } 42 | 43 | // Return 32 bits from current position in the buffer. 44 | // Bit at (InAddr,InBit) has the highest position in returning data. 45 | uint getbits32() 46 | { 47 | uint BitField=(uint)InBuf[InAddr] << 24; 48 | BitField|=(uint)InBuf[InAddr+1] << 16; 49 | BitField|=(uint)InBuf[InAddr+2] << 8; 50 | BitField|=(uint)InBuf[InAddr+3]; 51 | BitField <<= InBit; 52 | BitField|=(uint)InBuf[InAddr+4] >> (8-InBit); 53 | return BitField & 0xffffffff; 54 | } 55 | 56 | void faddbits(uint Bits); 57 | uint fgetbits(); 58 | 59 | // Check if buffer has enough space for IncPtr bytes. Returns 'true' 60 | // if buffer will be overflown. 61 | bool Overflow(uint IncPtr) 62 | { 63 | return InAddr+IncPtr>=MAX_SIZE; 64 | } 65 | 66 | void SetExternalBuffer(byte *Buf); 67 | }; 68 | #endif 69 | -------------------------------------------------------------------------------- /unrar/global.cpp: -------------------------------------------------------------------------------- 1 | #define INCLUDEGLOBAL 2 | 3 | #if defined(__BORLANDC__) || defined(_MSC_VER) 4 | #pragma hdrstop 5 | #endif 6 | 7 | #include "rar.hpp" 8 | -------------------------------------------------------------------------------- /unrar/global.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_GLOBAL_ 2 | #define _RAR_GLOBAL_ 3 | 4 | #ifdef INCLUDEGLOBAL 5 | #define EXTVAR 6 | #else 7 | #define EXTVAR extern 8 | #endif 9 | 10 | EXTVAR ErrorHandler ErrHandler; 11 | 12 | 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /unrar/hardlinks.cpp: -------------------------------------------------------------------------------- 1 | bool ExtractHardlink(wchar *NameNew,wchar *NameExisting,size_t NameExistingSize) 2 | { 3 | SlashToNative(NameExisting,NameExisting,NameExistingSize); // Not needed for RAR 5.1+ archives. 4 | 5 | if (!FileExist(NameExisting)) 6 | { 7 | uiMsg(UIERROR_HLINKCREATE,NameNew); 8 | uiMsg(UIERROR_NOLINKTARGET); 9 | ErrHandler.SetErrorCode(RARX_CREATE); 10 | return false; 11 | } 12 | CreatePath(NameNew,true); 13 | 14 | #ifdef _WIN_ALL 15 | bool Success=CreateHardLink(NameNew,NameExisting,NULL)!=0; 16 | if (!Success) 17 | { 18 | uiMsg(UIERROR_HLINKCREATE,NameNew); 19 | ErrHandler.SysErrMsg(); 20 | ErrHandler.SetErrorCode(RARX_CREATE); 21 | } 22 | return Success; 23 | #elif defined(_UNIX) 24 | char NameExistingA[NM],NameNewA[NM]; 25 | WideToChar(NameExisting,NameExistingA,ASIZE(NameExistingA)); 26 | WideToChar(NameNew,NameNewA,ASIZE(NameNewA)); 27 | bool Success=link(NameExistingA,NameNewA)==0; 28 | if (!Success) 29 | { 30 | uiMsg(UIERROR_HLINKCREATE,NameNew); 31 | ErrHandler.SysErrMsg(); 32 | ErrHandler.SetErrorCode(RARX_CREATE); 33 | } 34 | return Success; 35 | #else 36 | return false; 37 | #endif 38 | } 39 | 40 | -------------------------------------------------------------------------------- /unrar/hash.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_DATAHASH_ 2 | #define _RAR_DATAHASH_ 3 | 4 | enum HASH_TYPE {HASH_NONE,HASH_RAR14,HASH_CRC32,HASH_BLAKE2}; 5 | 6 | struct HashValue 7 | { 8 | void Init(HASH_TYPE Type); 9 | bool operator == (const HashValue &cmp); 10 | bool operator != (const HashValue &cmp) {return !(*this==cmp);} 11 | 12 | HASH_TYPE Type; 13 | union 14 | { 15 | uint CRC32; 16 | byte Digest[SHA256_DIGEST_SIZE]; 17 | }; 18 | }; 19 | 20 | 21 | #ifdef RAR_SMP 22 | class ThreadPool; 23 | class DataHash; 24 | #endif 25 | 26 | 27 | class DataHash 28 | { 29 | private: 30 | HASH_TYPE HashType; 31 | uint CurCRC32; 32 | blake2sp_state *blake2ctx; 33 | 34 | #ifdef RAR_SMP 35 | ThreadPool *ThPool; 36 | 37 | uint MaxThreads; 38 | // Upper limit for maximum threads to prevent wasting threads in pool. 39 | static const uint MaxHashThreads=8; 40 | #endif 41 | public: 42 | DataHash(); 43 | ~DataHash(); 44 | void Init(HASH_TYPE Type,uint MaxThreads); 45 | void Update(const void *Data,size_t DataSize); 46 | void Result(HashValue *Result); 47 | uint GetCRC32(); 48 | bool Cmp(HashValue *CmpValue,byte *Key); 49 | HASH_TYPE Type() {return HashType;} 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /unrar/headers.cpp: -------------------------------------------------------------------------------- 1 | #include "rar.hpp" 2 | 3 | void FileHeader::Reset(size_t SubDataSize) 4 | { 5 | SubData.Alloc(SubDataSize); 6 | BaseBlock::Reset(); 7 | FileHash.Init(HASH_NONE); 8 | mtime.Reset(); 9 | atime.Reset(); 10 | ctime.Reset(); 11 | SplitBefore=false; 12 | SplitAfter=false; 13 | 14 | UnknownUnpSize=0; 15 | 16 | SubFlags=0; // Important for RAR 3.0 subhead. 17 | 18 | CryptMethod=CRYPT_NONE; 19 | Encrypted=false; 20 | SaltSet=false; 21 | UsePswCheck=false; 22 | UseHashKey=false; 23 | Lg2Count=0; 24 | 25 | Solid=false; 26 | Dir=false; 27 | WinSize=0; 28 | Inherited=false; 29 | SubBlock=false; 30 | CommentInHeader=false; 31 | Version=false; 32 | LargeFile=false; 33 | 34 | RedirType=FSREDIR_NONE; 35 | DirTarget=false; 36 | UnixOwnerSet=false; 37 | } 38 | 39 | 40 | FileHeader& FileHeader::operator = (FileHeader &hd) 41 | { 42 | SubData.Reset(); 43 | memcpy(this,&hd,sizeof(*this)); 44 | SubData.CleanData(); 45 | SubData=hd.SubData; 46 | return *this; 47 | } 48 | 49 | 50 | void MainHeader::Reset() 51 | { 52 | HighPosAV=0; 53 | PosAV=0; 54 | CommentInHeader=false; 55 | PackComment=false; 56 | Locator=false; 57 | QOpenOffset=0; 58 | QOpenMaxSize=0; 59 | RROffset=0; 60 | RRMaxSize=0; 61 | } 62 | -------------------------------------------------------------------------------- /unrar/isnt.cpp: -------------------------------------------------------------------------------- 1 | #include "rar.hpp" 2 | 3 | #ifdef _WIN_ALL 4 | DWORD WinNT() 5 | { 6 | static int dwPlatformId=-1; 7 | static DWORD dwMajorVersion,dwMinorVersion; 8 | if (dwPlatformId==-1) 9 | { 10 | OSVERSIONINFO WinVer; 11 | WinVer.dwOSVersionInfoSize=sizeof(WinVer); 12 | GetVersionEx(&WinVer); 13 | dwPlatformId=WinVer.dwPlatformId; 14 | dwMajorVersion=WinVer.dwMajorVersion; 15 | dwMinorVersion=WinVer.dwMinorVersion; 16 | } 17 | DWORD Result=0; 18 | if (dwPlatformId==VER_PLATFORM_WIN32_NT) 19 | Result=dwMajorVersion*0x100+dwMinorVersion; 20 | 21 | 22 | return Result; 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /unrar/isnt.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_ISNT_ 2 | #define _RAR_ISNT_ 3 | 4 | enum WINNT_VERSION { 5 | WNT_NONE=0,WNT_NT351=0x0333,WNT_NT4=0x0400,WNT_W2000=0x0500, 6 | WNT_WXP=0x0501,WNT_W2003=0x0502,WNT_VISTA=0x0600,WNT_W7=0x0601, 7 | WNT_W8=0x0602,WNT_W81=0x0603,WNT_W10=0x0a00 8 | }; 9 | 10 | DWORD WinNT(); 11 | 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /unrar/list.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_LIST_ 2 | #define _RAR_LIST_ 3 | 4 | void ListArchive(CommandData *Cmd); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /unrar/log.cpp: -------------------------------------------------------------------------------- 1 | #include "rar.hpp" 2 | 3 | 4 | static wchar LogName[NM]; 5 | static RAR_CHARSET LogCharset=RCH_DEFAULT; 6 | 7 | void InitLogOptions(const wchar *LogFileName,RAR_CHARSET CSet) 8 | { 9 | wcsncpyz(LogName,LogFileName,ASIZE(LogName)); 10 | LogCharset=CSet; 11 | } 12 | 13 | 14 | #ifndef SILENT 15 | void Log(const wchar *ArcName,const wchar *fmt,...) 16 | { 17 | // Preserve the error code for possible following system error message. 18 | int Code=ErrHandler.GetSystemErrorCode(); 19 | 20 | uiAlarm(UIALARM_ERROR); 21 | 22 | // This buffer is for format string only, not for entire output, 23 | // so it can be short enough. 24 | wchar fmtw[1024]; 25 | PrintfPrepareFmt(fmt,fmtw,ASIZE(fmtw)); 26 | 27 | safebuf wchar Msg[2*NM+1024]; 28 | va_list arglist; 29 | va_start(arglist,fmt); 30 | vswprintf(Msg,ASIZE(Msg),fmtw,arglist); 31 | va_end(arglist); 32 | eprintf(L"%ls",Msg); 33 | ErrHandler.SetSystemErrorCode(Code); 34 | } 35 | #endif 36 | 37 | 38 | -------------------------------------------------------------------------------- /unrar/log.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_LOG_ 2 | #define _RAR_LOG_ 3 | 4 | void InitLogOptions(const wchar *LogFileName,RAR_CHARSET CSet); 5 | 6 | #ifdef SILENT 7 | inline void Log(const wchar *ArcName,const wchar *fmt,...) {} 8 | #else 9 | void Log(const wchar *ArcName,const wchar *fmt,...); 10 | #endif 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /unrar/match.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_MATCH_ 2 | #define _RAR_MATCH_ 3 | 4 | enum { 5 | MATCH_NAMES, // Paths are ignored. 6 | // Compares names only using wildcards. 7 | 8 | MATCH_SUBPATHONLY, // Paths must match either exactly or path in wildcard 9 | // must be present in the beginning of file path. 10 | // For example, "c:\path1\*" or "c:\path1" will match 11 | // "c:\path1\path2\file". 12 | // Names are not compared. 13 | 14 | MATCH_EXACT, // Paths must match exactly. 15 | // Names must match exactly. 16 | 17 | MATCH_ALLWILD, // Paths and names are compared using wildcards. 18 | // Unlike MATCH_SUBPATH, paths do not match subdirs 19 | // unless a wildcard tells so. 20 | 21 | MATCH_EXACTPATH, // Paths must match exactly. 22 | // Names are compared using wildcards. 23 | 24 | MATCH_SUBPATH, // Names must be the same, but path in mask is allowed 25 | // to be only a part of name path. In other words, 26 | // we match all files matching the file mask 27 | // in current folder and subfolders. 28 | 29 | MATCH_WILDSUBPATH // Works as MATCH_SUBPATH if file mask contains 30 | // wildcards and as MATCH_EXACTPATH otherwise. 31 | }; 32 | 33 | #define MATCH_MODEMASK 0x0000ffff 34 | #define MATCH_FORCECASESENSITIVE 0x80000000 35 | 36 | bool CmpName(const wchar *Wildcard,const wchar *Name,int CmpMode); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /unrar/options.cpp: -------------------------------------------------------------------------------- 1 | #include "rar.hpp" 2 | 3 | RAROptions::RAROptions() 4 | { 5 | Init(); 6 | } 7 | 8 | 9 | RAROptions::~RAROptions() 10 | { 11 | // It is important for security reasons, so we do not have the unnecessary 12 | // password data left in memory. 13 | memset(this,0,sizeof(RAROptions)); 14 | } 15 | 16 | 17 | void RAROptions::Init() 18 | { 19 | memset(this,0,sizeof(RAROptions)); 20 | WinSize=0x2000000; 21 | Overwrite=OVERWRITE_DEFAULT; 22 | Method=3; 23 | MsgStream=MSG_STDOUT; 24 | ConvertNames=NAMES_ORIGINALCASE; 25 | xmtime=EXTTIME_MAX; 26 | FileSizeLess=INT64NDF; 27 | FileSizeMore=INT64NDF; 28 | HashType=HASH_CRC32; 29 | #ifdef RAR_SMP 30 | Threads=GetNumberOfThreads(); 31 | #endif 32 | #ifdef USE_QOPEN 33 | QOpenMode=QOPEN_AUTO; 34 | #endif 35 | } 36 | -------------------------------------------------------------------------------- /unrar/qopen.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_QOPEN_ 2 | #define _RAR_QOPEN_ 3 | 4 | struct QuickOpenItem 5 | { 6 | byte *Header; 7 | size_t HeaderSize; 8 | uint64 ArcPos; 9 | QuickOpenItem *Next; 10 | }; 11 | 12 | 13 | class Archive; 14 | class RawRead; 15 | 16 | class QuickOpen 17 | { 18 | private: 19 | void Close(); 20 | 21 | 22 | uint ReadBuffer(); 23 | bool ReadRaw(RawRead &Raw); 24 | bool ReadNext(); 25 | 26 | Archive *Arc; 27 | bool WriteMode; 28 | 29 | QuickOpenItem *ListStart; 30 | QuickOpenItem *ListEnd; 31 | 32 | byte *Buf; // Read quick open data here. 33 | static const size_t MaxBufSize=0x10000; // Buf size, must be multiple of CRYPT_BLOCK_SIZE. 34 | size_t CurBufSize; // Current size of buffered data in write mode. 35 | #ifndef RAR_NOCRYPT // For shell extension. 36 | CryptData Crypt; 37 | #endif 38 | 39 | bool Loaded; 40 | uint64 QOHeaderPos; // Main QO header position. 41 | uint64 RawDataStart; // Start of QO data, just after the main header. 42 | uint64 RawDataSize; // Size of entire QO data. 43 | uint64 RawDataPos; // Current read position in QO data. 44 | size_t ReadBufSize; // Size of Buf data currently read from QO. 45 | size_t ReadBufPos; // Current read position in Buf data. 46 | Array LastReadHeader; 47 | uint64 LastReadHeaderPos; 48 | uint64 SeekPos; 49 | bool UnsyncSeekPos; // QOpen SeekPos does not match an actual file pointer. 50 | public: 51 | QuickOpen(); 52 | ~QuickOpen(); 53 | void Init(Archive *Arc,bool WriteMode); 54 | void Load(uint64 BlockPos); 55 | void Unload() { Loaded=false; } 56 | bool Read(void *Data,size_t Size,size_t &Result); 57 | bool Seek(int64 Offset,int Method); 58 | bool Tell(int64 *Pos); 59 | }; 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /unrar/rar.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_RARCOMMON_ 2 | #define _RAR_RARCOMMON_ 3 | 4 | #include "raros.hpp" 5 | #include "rartypes.hpp" 6 | #include "os.hpp" 7 | 8 | #ifdef RARDLL 9 | #include "dll.hpp" 10 | #endif 11 | 12 | #include "version.hpp" 13 | #include "rardefs.hpp" 14 | #include "rarlang.hpp" 15 | #include "unicode.hpp" 16 | #include "errhnd.hpp" 17 | #include "secpassword.hpp" 18 | #include "array.hpp" 19 | #include "timefn.hpp" 20 | #include "sha1.hpp" 21 | #include "sha256.hpp" 22 | #include "blake2s.hpp" 23 | #include "hash.hpp" 24 | #include "options.hpp" 25 | #include "rijndael.hpp" 26 | #include "crypt.hpp" 27 | #include "headers5.hpp" 28 | #include "headers.hpp" 29 | #include "pathfn.hpp" 30 | #include "strfn.hpp" 31 | #include "strlist.hpp" 32 | #ifdef _WIN_ALL 33 | #include "isnt.hpp" 34 | #endif 35 | #include "file.hpp" 36 | #include "crc.hpp" 37 | #include "ui.hpp" 38 | #include "filefn.hpp" 39 | #include "filestr.hpp" 40 | #include "find.hpp" 41 | #include "scantree.hpp" 42 | #include "getbits.hpp" 43 | #include "rdwrfn.hpp" 44 | #ifdef USE_QOPEN 45 | #include "qopen.hpp" 46 | #endif 47 | #include "archive.hpp" 48 | #include "match.hpp" 49 | #include "cmddata.hpp" 50 | #include "filcreat.hpp" 51 | #include "consio.hpp" 52 | #include "system.hpp" 53 | #include "log.hpp" 54 | #include "rawint.hpp" 55 | #include "rawread.hpp" 56 | #include "encname.hpp" 57 | #include "resource.hpp" 58 | #include "compress.hpp" 59 | 60 | #include "rarvm.hpp" 61 | #include "model.hpp" 62 | 63 | #include "threadpool.hpp" 64 | 65 | #include "unpack.hpp" 66 | 67 | 68 | 69 | #include "extinfo.hpp" 70 | #include "extract.hpp" 71 | 72 | 73 | 74 | #include "list.hpp" 75 | 76 | 77 | #include "rs.hpp" 78 | #include "rs16.hpp" 79 | 80 | 81 | 82 | #include "recvol.hpp" 83 | #include "volume.hpp" 84 | #include "smallfn.hpp" 85 | 86 | #include "global.hpp" 87 | 88 | #if 0 89 | #include "benchmark.hpp" 90 | #endif 91 | 92 | 93 | 94 | 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /unrar/rardefs.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_DEFS_ 2 | #define _RAR_DEFS_ 3 | 4 | #define Min(x,y) (((x)<(y)) ? (x):(y)) 5 | #define Max(x,y) (((x)>(y)) ? (x):(y)) 6 | 7 | // Universal replacement of abs function. 8 | #define Abs(x) (((x)<0) ? -(x):(x)) 9 | 10 | #define ASIZE(x) (sizeof(x)/sizeof(x[0])) 11 | 12 | // MAXPASSWORD is expected to be multiple of CRYPTPROTECTMEMORY_BLOCK_SIZE (16) 13 | // for CryptProtectMemory in SecPassword. 14 | #define MAXPASSWORD 128 15 | 16 | #define MAXSFXSIZE 0x200000 17 | 18 | #define MAXCMTSIZE 0x40000 19 | 20 | #define DefSFXName L"default.sfx" 21 | #define DefSortListName L"rarfiles.lst" 22 | 23 | 24 | #ifndef SFX_MODULE 25 | #define USE_QOPEN 26 | #endif 27 | 28 | // Produce the value, which is equal or larger than 'v' and aligned to 'a'. 29 | #define ALIGN_VALUE(v,a) (size_t(v) + ( (~size_t(v) + 1) & (a - 1) ) ) 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /unrar/rarlang.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_LANG_ 2 | #define _RAR_LANG_ 3 | 4 | #ifdef USE_RC 5 | #include "rarres.hpp" 6 | #else 7 | #include "loclang.hpp" 8 | #endif 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /unrar/raros.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_RAROS_ 2 | #define _RAR_RAROS_ 3 | 4 | #ifdef __EMX__ 5 | #define _EMX 6 | #endif 7 | 8 | #ifdef __DJGPP__ 9 | #define _DJGPP 10 | #define _EMX 11 | #endif 12 | 13 | #if defined(__WIN32__) || defined(_WIN32) 14 | #define _WIN_ALL // Defined for all Windows platforms, 32 and 64 bit, mobile and desktop. 15 | #ifdef _M_X64 16 | #define _WIN_64 17 | #else 18 | #define _WIN_32 19 | #endif 20 | #endif 21 | 22 | #if defined(ANDROID) || defined(__ANDROID__) 23 | #define _UNIX 24 | #define _ANDROID 25 | #endif 26 | 27 | #ifdef __APPLE__ 28 | #define _UNIX 29 | #define _APPLE 30 | #endif 31 | 32 | #if !defined(_EMX) && !defined(_WIN_ALL) && !defined(_BEOS) && !defined(_APPLE) 33 | #define _UNIX 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /unrar/rartypes.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_TYPES_ 2 | #define _RAR_TYPES_ 3 | 4 | #include 5 | 6 | typedef uint8_t byte; // Unsigned 8 bits. 7 | typedef uint16_t ushort; // Preferably 16 bits, but can be more. 8 | typedef unsigned int uint; // 32 bits or more. 9 | typedef uint32_t uint32; // 32 bits exactly. 10 | typedef int32_t int32; // Signed 32 bits exactly. 11 | typedef uint64_t uint64; // 64 bits exactly. 12 | typedef int64_t int64; // Signed 64 bits exactly. 13 | typedef wchar_t wchar; // Unicode character 14 | 15 | // Get lowest 16 bits. 16 | #define GET_SHORT16(x) (sizeof(ushort)==2 ? (ushort)(x):((x)&0xffff)) 17 | 18 | // Make 64 bit integer from two 32 bit. 19 | #define INT32TO64(high,low) ((((uint64)(high))<<32)+((uint64)low)) 20 | 21 | // Maximum int64 value. 22 | #define MAX_INT64 int64(INT32TO64(0x7fffffff,0xffffffff)) 23 | 24 | // Special int64 value, large enough to never be found in real life 25 | // and small enough to fit to both signed and unsigned 64-bit ints. 26 | // We use it in situations, when we need to indicate that parameter 27 | // is not defined and probably should be calculated inside of function. 28 | // Lower part is intentionally 0x7fffffff, not 0xffffffff, to make it 29 | // compatible with 32 bit int64 if 64 bit type is not supported. 30 | #define INT64NDF INT32TO64(0x7fffffff,0x7fffffff) 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /unrar/rarvm.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_VM_ 2 | #define _RAR_VM_ 3 | 4 | #define VM_MEMSIZE 0x40000 5 | #define VM_MEMMASK (VM_MEMSIZE-1) 6 | 7 | enum VM_StandardFilters { 8 | VMSF_NONE, VMSF_E8, VMSF_E8E9, VMSF_ITANIUM, VMSF_RGB, VMSF_AUDIO, 9 | VMSF_DELTA 10 | }; 11 | 12 | struct VM_PreparedProgram 13 | { 14 | VM_PreparedProgram() 15 | { 16 | FilteredDataSize=0; 17 | Type=VMSF_NONE; 18 | } 19 | VM_StandardFilters Type; 20 | uint InitR[7]; 21 | byte *FilteredData; 22 | uint FilteredDataSize; 23 | }; 24 | 25 | class RarVM 26 | { 27 | private: 28 | bool ExecuteStandardFilter(VM_StandardFilters FilterType); 29 | uint FilterItanium_GetBits(byte *Data,uint BitPos,uint BitCount); 30 | void FilterItanium_SetBits(byte *Data,uint BitField,uint BitPos,uint BitCount); 31 | 32 | byte *Mem; 33 | uint R[8]; 34 | public: 35 | RarVM(); 36 | ~RarVM(); 37 | void Init(); 38 | void Prepare(byte *Code,uint CodeSize,VM_PreparedProgram *Prg); 39 | void Execute(VM_PreparedProgram *Prg); 40 | void SetMemory(size_t Pos,byte *Data,size_t DataSize); 41 | static uint ReadData(BitInput &Inp); 42 | }; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /unrar/rawread.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_RAWREAD_ 2 | #define _RAR_RAWREAD_ 3 | 4 | class RawRead 5 | { 6 | private: 7 | Array Data; 8 | File *SrcFile; 9 | size_t DataSize; 10 | size_t ReadPos; 11 | CryptData *Crypt; 12 | public: 13 | RawRead(); 14 | RawRead(File *SrcFile); 15 | void Reset(); 16 | size_t Read(size_t Size); 17 | void Read(byte *SrcData,size_t Size); 18 | byte Get1(); 19 | ushort Get2(); 20 | uint Get4(); 21 | uint64 Get8(); 22 | uint64 GetV(); 23 | uint GetVSize(size_t Pos); 24 | size_t GetB(void *Field,size_t Size); 25 | void GetW(wchar *Field,size_t Size); 26 | uint GetCRC15(bool ProcessedOnly); 27 | uint GetCRC50(); 28 | byte* GetDataPtr() {return &Data[0];} 29 | size_t Size() {return DataSize;} 30 | size_t PaddedSize() {return Data.Size()-DataSize;} 31 | size_t DataLeft() {return DataSize-ReadPos;} 32 | size_t GetPos() {return ReadPos;} 33 | void SetPos(size_t Pos) {ReadPos=Pos;} 34 | void Skip(size_t Size) {ReadPos+=Size;} 35 | void Rewind() {SetPos(0);} 36 | void SetCrypt(CryptData *Crypt) {RawRead::Crypt=Crypt;} 37 | }; 38 | 39 | uint64 RawGetV(const byte *Data,uint &ReadPos,uint DataSize,bool &Overflow); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /unrar/resource.cpp: -------------------------------------------------------------------------------- 1 | #include "rar.hpp" 2 | 3 | 4 | 5 | 6 | 7 | #ifndef RARDLL 8 | const wchar* St(MSGID StringId) 9 | { 10 | return StringId; 11 | } 12 | 13 | 14 | // Needed for Unix swprintf to convert %s to %ls in legacy language resources. 15 | const wchar *StF(MSGID StringId) 16 | { 17 | static wchar FormattedStr[512]; 18 | PrintfPrepareFmt(St(StringId),FormattedStr,ASIZE(FormattedStr)); 19 | return FormattedStr; 20 | } 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /unrar/resource.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_RESOURCE_ 2 | #define _RAR_RESOURCE_ 3 | 4 | #ifdef RARDLL 5 | #define St(x) (L"") 6 | #define StF(x) (L"") 7 | #else 8 | const wchar *St(MSGID StringId); 9 | const wchar *StF(MSGID StringId); 10 | #endif 11 | 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /unrar/rijndael.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RIJNDAEL_H_ 2 | #define _RIJNDAEL_H_ 3 | 4 | /************************************************************************** 5 | * This code is based on Szymon Stefanek AES implementation: * 6 | * http://www.esat.kuleuven.ac.be/~rijmen/rijndael/rijndael-cpplib.tar.gz * 7 | * * 8 | * Dynamic tables generation is based on the Brian Gladman's work: * 9 | * http://fp.gladman.plus.com/cryptography_technology/rijndael * 10 | **************************************************************************/ 11 | 12 | #define _MAX_KEY_COLUMNS (256/32) 13 | #define _MAX_ROUNDS 14 14 | #define MAX_IV_SIZE 16 15 | 16 | class Rijndael 17 | { 18 | private: 19 | #ifdef USE_SSE 20 | void blockEncryptSSE(const byte *input,size_t numBlocks,byte *outBuffer); 21 | void blockDecryptSSE(const byte *input, size_t numBlocks, byte *outBuffer); 22 | 23 | bool AES_NI; 24 | #endif 25 | void keySched(byte key[_MAX_KEY_COLUMNS][4]); 26 | void keyEncToDec(); 27 | void GenerateTables(); 28 | 29 | // RAR always uses CBC, but we may need to turn it off when calling 30 | // this code from other archive formats with CTR and other modes. 31 | bool CBCMode; 32 | 33 | int m_uRounds; 34 | byte m_initVector[MAX_IV_SIZE]; 35 | byte m_expandedKey[_MAX_ROUNDS+1][4][4]; 36 | public: 37 | Rijndael(); 38 | void Init(bool Encrypt,const byte *key,uint keyLen,const byte *initVector); 39 | void blockEncrypt(const byte *input, size_t inputLen, byte *outBuffer); 40 | void blockDecrypt(const byte *input, size_t inputLen, byte *outBuffer); 41 | void SetCBCMode(bool Mode) {CBCMode=Mode;} 42 | }; 43 | 44 | #endif // _RIJNDAEL_H_ 45 | -------------------------------------------------------------------------------- /unrar/rs.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_RS_ 2 | #define _RAR_RS_ 3 | 4 | #define MAXPAR 255 // Maximum parity data size. 5 | #define MAXPOL 512 // Maximum polynomial degree. 6 | 7 | class RSCoder 8 | { 9 | private: 10 | void gfInit(); 11 | int gfMult(int a,int b); 12 | void pnInit(); 13 | void pnMult(int *p1,int *p2,int *r); 14 | 15 | int gfExp[MAXPOL]; // Galois field exponents. 16 | int gfLog[MAXPAR+1]; // Galois field logarithms. 17 | 18 | int GXPol[MAXPOL*2]; // Generator polynomial g(x). 19 | 20 | int ErrorLocs[MAXPAR+1],ErrCount; 21 | int Dnm[MAXPAR+1]; 22 | 23 | int ParSize; // Parity bytes size and so the number of recovery volumes. 24 | int ELPol[MAXPOL]; // Error locator polynomial. 25 | bool FirstBlockDone; 26 | public: 27 | void Init(int ParSize); 28 | void Encode(byte *Data,int DataSize,byte *DestData); 29 | bool Decode(byte *Data,int DataSize,int *EraLoc,int EraSize); 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /unrar/rs16.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cataphract/php-rar/ab26d285759e4c917879967b09976a44829ed570/unrar/rs16.cpp -------------------------------------------------------------------------------- /unrar/rs16.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_RS16_ 2 | #define _RAR_RS16_ 3 | 4 | class RSCoder16 5 | { 6 | private: 7 | static const uint gfSize=65535; // Galois field size. 8 | void gfInit(); // Galois field inititalization. 9 | inline uint gfAdd(uint a,uint b); // Addition in Galois field. 10 | inline uint gfMul(uint a,uint b); // Multiplication in Galois field. 11 | inline uint gfInv(uint a); // Inverse element in Galois field. 12 | uint *gfExp; // Galois field exponents. 13 | uint *gfLog; // Galois field logarithms. 14 | 15 | void MakeEncoderMatrix(); 16 | void MakeDecoderMatrix(); 17 | void InvertDecoderMatrix(); 18 | 19 | #ifdef USE_SSE 20 | bool SSE_UpdateECC(uint DataNum, uint ECCNum, const byte *Data, byte *ECC, size_t BlockSize); 21 | #endif 22 | 23 | bool Decoding; // If we are decoding or encoding data. 24 | uint ND; // Number of data units. 25 | uint NR; // Number of Reed-Solomon code units. 26 | uint NE; // Number of erasures. 27 | bool *ValidFlags; // Validity flags for data and ECC units. 28 | uint *MX; // Cauchy based coding or decoding matrix. 29 | 30 | uint *DataLog; // Buffer to store data logarithms for UpdateECC. 31 | size_t DataLogSize; 32 | 33 | public: 34 | RSCoder16(); 35 | ~RSCoder16(); 36 | 37 | bool Init(uint DataCount, uint RecCount, bool *ValidityFlags); 38 | #if 0 // We use only UpdateECC now. 39 | void Process(const uint *Data, uint *Out); 40 | #endif 41 | void UpdateECC(uint DataNum, uint ECCNum, const byte *Data, byte *ECC, size_t BlockSize); 42 | }; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /unrar/savepos.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_SAVEPOS_ 2 | #define _RAR_SAVEPOS_ 3 | 4 | class SaveFilePos 5 | { 6 | private: 7 | File *SaveFile; 8 | int64 SavePos; 9 | public: 10 | SaveFilePos(File &Src) 11 | { 12 | SaveFile=&Src; 13 | SavePos=Src.Tell(); 14 | } 15 | ~SaveFilePos() 16 | { 17 | // Unless the file is already closed either by current exception 18 | // processing or intentionally by external code. 19 | if (SaveFile->IsOpened()) 20 | { 21 | try 22 | { 23 | SaveFile->Seek(SavePos,SEEK_SET); 24 | } 25 | catch(RAR_EXIT) 26 | { 27 | // Seek() can throw an exception and it terminates process 28 | // if we are already processing another exception. Also in C++ 11 29 | // an exception in destructor always terminates process unless 30 | // we mark destructor with noexcept(false). So we do not want to 31 | // throw here. To prevent data loss we do not want to continue 32 | // execution after seek error, so we close the file. 33 | // Any next access to this file will return an error. 34 | SaveFile->Close(); 35 | } 36 | } 37 | } 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /unrar/scantree.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_SCANTREE_ 2 | #define _RAR_SCANTREE_ 3 | 4 | enum SCAN_DIRS 5 | { 6 | SCAN_SKIPDIRS, // Skip directories, but recurse for files if recursion mode is enabled. 7 | SCAN_GETDIRS, // Get subdirectories in recurse mode. 8 | SCAN_GETDIRSTWICE, // Get the directory name both before and after the list of files it contains. 9 | SCAN_GETCURDIRS // Get subdirectories in current directory even in RECURSE_NONE mode. 10 | }; 11 | 12 | enum SCAN_CODE { SCAN_SUCCESS,SCAN_DONE,SCAN_ERROR,SCAN_NEXT }; 13 | 14 | #define MAXSCANDEPTH (NM/2) 15 | 16 | class CommandData; 17 | 18 | class ScanTree 19 | { 20 | private: 21 | bool ExpandFolderMask(); 22 | bool GetFilteredMask(); 23 | bool GetNextMask(); 24 | SCAN_CODE FindProc(FindData *FD); 25 | void ScanError(bool &Error); 26 | 27 | FindFile *FindStack[MAXSCANDEPTH]; 28 | int Depth; 29 | 30 | int SetAllMaskDepth; 31 | 32 | StringList *FileMasks; 33 | RECURSE_MODE Recurse; 34 | bool GetLinks; 35 | SCAN_DIRS GetDirs; 36 | int Errors; 37 | 38 | // Set when processing paths like c:\ (root directory without wildcards). 39 | bool ScanEntireDisk; 40 | 41 | wchar CurMask[NM]; 42 | wchar OrigCurMask[NM]; 43 | 44 | // Store all folder masks generated from folder wildcard mask in non-recursive mode. 45 | StringList ExpandedFolderList; 46 | 47 | // Store a filter string for folder wildcard in recursive mode. 48 | StringList FilterList; 49 | 50 | // Save the list of unreadable dirs here. 51 | StringList *ErrDirList; 52 | Array *ErrDirSpecPathLength; 53 | 54 | // Set if processing a folder wildcard mask. 55 | bool FolderWildcards; 56 | 57 | bool SearchAllInRoot; 58 | size_t SpecPathLength; 59 | 60 | wchar ErrArcName[NM]; 61 | 62 | CommandData *Cmd; 63 | public: 64 | ScanTree(StringList *FileMasks,RECURSE_MODE Recurse,bool GetLinks,SCAN_DIRS GetDirs); 65 | ~ScanTree(); 66 | SCAN_CODE GetNext(FindData *FindData); 67 | size_t GetSpecPathLength() {return SpecPathLength;} 68 | int GetErrors() {return Errors;}; 69 | void SetErrArcName(const wchar *Name) {wcsncpyz(ErrArcName,Name,ASIZE(ErrArcName));} 70 | void SetCommandData(CommandData *Cmd) {ScanTree::Cmd=Cmd;} 71 | void SetErrDirList(StringList *List,Array *Lengths) 72 | { 73 | ErrDirList=List; 74 | ErrDirSpecPathLength=Lengths; 75 | } 76 | }; 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /unrar/secpassword.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_SECURE_PASSWORD_ 2 | #define _RAR_SECURE_PASSWORD_ 3 | 4 | // Store a password securely (if data encryption is provided by OS) 5 | // or obfuscated to make search for password in memory dump less trivial. 6 | class SecPassword 7 | { 8 | private: 9 | void Process(const wchar *Src,size_t SrcSize,wchar *Dst,size_t DstSize,bool Encode); 10 | 11 | wchar Password[MAXPASSWORD]; 12 | 13 | // It is important to have this 'bool' value, so if our object is cleaned 14 | // with memset as a part of larger structure, it is handled correctly. 15 | bool PasswordSet; 16 | public: 17 | SecPassword(); 18 | ~SecPassword(); 19 | void Clean(); 20 | void Get(wchar *Psw,size_t MaxSize); 21 | void Set(const wchar *Psw); 22 | bool IsSet() {return PasswordSet;} 23 | size_t Length(); 24 | bool operator == (SecPassword &psw); 25 | 26 | // Set to true if we need to pass a password to another process. 27 | // We use it when transferring parameters to UAC elevated WinRAR. 28 | bool CrossProcess; 29 | }; 30 | 31 | 32 | void cleandata(void *data,size_t size); 33 | void SecHideData(void *Data,size_t DataSize,bool Encode,bool CrossProcess); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /unrar/sha1.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_SHA1_ 2 | #define _RAR_SHA1_ 3 | 4 | typedef struct { 5 | uint32 state[5]; 6 | uint64 count; 7 | unsigned char buffer[64]; 8 | } sha1_context; 9 | 10 | void sha1_init( sha1_context * c ); 11 | void sha1_process(sha1_context * c, const byte *data, size_t len); 12 | void sha1_process_rar29(sha1_context *context, const unsigned char *data, size_t len); 13 | void sha1_done( sha1_context * c, uint32 digest[5] ); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /unrar/sha256.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_SHA256_ 2 | #define _RAR_SHA256_ 3 | 4 | #define SHA256_DIGEST_SIZE 32 5 | 6 | typedef struct 7 | { 8 | uint32 H[8]; 9 | uint64 Count; 10 | byte Buffer[64]; 11 | } sha256_context; 12 | 13 | void sha256_init(sha256_context *ctx); 14 | void sha256_process(sha256_context *ctx, const void *Data, size_t Size); 15 | void sha256_done(sha256_context *ctx, byte *Digest); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /unrar/smallfn.cpp: -------------------------------------------------------------------------------- 1 | #include "rar.hpp" 2 | 3 | int ToPercent(int64 N1,int64 N2) 4 | { 5 | if (N2 StringData; 8 | size_t CurPos; 9 | 10 | size_t StringsCount; 11 | 12 | size_t SaveCurPos[16],SavePosNumber; 13 | public: 14 | StringList(); 15 | void Reset(); 16 | void AddStringA(const char *Str); 17 | void AddString(const wchar *Str); 18 | bool GetStringA(char *Str,size_t MaxLength); 19 | bool GetString(wchar *Str,size_t MaxLength); 20 | bool GetString(wchar *Str,size_t MaxLength,int StringNum); 21 | wchar* GetString(); 22 | bool GetString(wchar **Str); 23 | void Rewind(); 24 | size_t ItemsCount() {return StringsCount;}; 25 | size_t GetCharCount() {return StringData.Size();} 26 | bool Search(const wchar *Str,bool CaseSensitive); 27 | void SavePosition(); 28 | void RestorePosition(); 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /unrar/suballoc.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * This file is part of PPMd project * 3 | * Written and distributed to public domain by Dmitry Shkarin 1997, * 4 | * 1999-2000 * 5 | * Contents: interface to memory allocation routines * 6 | ****************************************************************************/ 7 | #if !defined(_SUBALLOC_H_) 8 | #define _SUBALLOC_H_ 9 | 10 | #if defined(__GNUC__) && defined(ALLOW_MISALIGNED) 11 | #define RARPPM_PACK_ATTR __attribute__ ((packed)) 12 | #else 13 | #define RARPPM_PACK_ATTR 14 | #endif /* defined(__GNUC__) */ 15 | 16 | #ifdef ALLOW_MISALIGNED 17 | #pragma pack(1) 18 | #endif 19 | 20 | struct RARPPM_MEM_BLK 21 | { 22 | ushort Stamp, NU; 23 | RARPPM_MEM_BLK* next, * prev; 24 | void insertAt(RARPPM_MEM_BLK* p) 25 | { 26 | next=(prev=p)->next; 27 | p->next=next->prev=this; 28 | } 29 | void remove() 30 | { 31 | prev->next=next; 32 | next->prev=prev; 33 | } 34 | } RARPPM_PACK_ATTR; 35 | 36 | #ifdef ALLOW_MISALIGNED 37 | #ifdef _AIX 38 | #pragma pack(pop) 39 | #else 40 | #pragma pack() 41 | #endif 42 | #endif 43 | 44 | 45 | class SubAllocator 46 | { 47 | private: 48 | static const int N1=4, N2=4, N3=4, N4=(128+3-1*N1-2*N2-3*N3)/4; 49 | static const int N_INDEXES=N1+N2+N3+N4; 50 | 51 | struct RAR_NODE 52 | { 53 | RAR_NODE* next; 54 | }; 55 | 56 | inline void InsertNode(void* p,int indx); 57 | inline void* RemoveNode(int indx); 58 | inline uint U2B(int NU); 59 | inline void SplitBlock(void* pv,int OldIndx,int NewIndx); 60 | inline void GlueFreeBlocks(); 61 | void* AllocUnitsRare(int indx); 62 | inline RARPPM_MEM_BLK* MBPtr(RARPPM_MEM_BLK *BasePtr,int Items); 63 | 64 | long SubAllocatorSize; 65 | byte Indx2Units[N_INDEXES], Units2Indx[128], GlueCount; 66 | byte *HeapStart,*LoUnit, *HiUnit; 67 | struct RAR_NODE FreeList[N_INDEXES]; 68 | public: 69 | SubAllocator(); 70 | ~SubAllocator() {StopSubAllocator();} 71 | void Clean(); 72 | bool StartSubAllocator(int SASize); 73 | void StopSubAllocator(); 74 | void InitSubAllocator(); 75 | inline void* AllocContext(); 76 | inline void* AllocUnits(int NU); 77 | inline void* ExpandUnits(void* ptr,int OldNU); 78 | inline void* ShrinkUnits(void* ptr,int OldNU,int NewNU); 79 | inline void FreeUnits(void* ptr,int OldNU); 80 | long GetAllocatedMemory() {return(SubAllocatorSize);} 81 | 82 | byte *pText, *UnitsStart,*HeapEnd,*FakeUnitsStart; 83 | }; 84 | 85 | 86 | #endif /* !defined(_SUBALLOC_H_) */ 87 | -------------------------------------------------------------------------------- /unrar/system.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_SYSTEM_ 2 | #define _RAR_SYSTEM_ 3 | 4 | #ifdef _WIN_ALL 5 | #ifndef BELOW_NORMAL_PRIORITY_CLASS 6 | #define BELOW_NORMAL_PRIORITY_CLASS 0x00004000 7 | #define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000 8 | #endif 9 | #ifndef PROCESS_MODE_BACKGROUND_BEGIN 10 | #define PROCESS_MODE_BACKGROUND_BEGIN 0x00100000 11 | #define PROCESS_MODE_BACKGROUND_END 0x00200000 12 | #endif 13 | #ifndef SHTDN_REASON_MAJOR_APPLICATION 14 | #define SHTDN_REASON_MAJOR_APPLICATION 0x00040000 15 | #define SHTDN_REASON_FLAG_PLANNED 0x80000000 16 | #define SHTDN_REASON_MINOR_MAINTENANCE 0x00000001 17 | #endif 18 | #endif 19 | 20 | void InitSystemOptions(int SleepTime); 21 | void SetPriority(int Priority); 22 | clock_t MonoClock(); 23 | void Wait(); 24 | bool EmailFile(const wchar *FileName,const wchar *MailToW); 25 | void Shutdown(POWER_MODE Mode); 26 | bool ShutdownCheckAnother(bool Open); 27 | 28 | #ifdef _WIN_ALL 29 | HMODULE WINAPI LoadSysLibrary(const wchar *Name); 30 | bool IsUserAdmin(); 31 | #endif 32 | 33 | 34 | #ifdef USE_SSE 35 | enum SSE_VERSION {SSE_NONE,SSE_SSE,SSE_SSE2,SSE_SSSE3,SSE_SSE41,SSE_AVX2}; 36 | SSE_VERSION GetSSEVersion(); 37 | extern SSE_VERSION _SSE_Version; 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /unrar/timefn.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_TIMEFN_ 2 | #define _RAR_TIMEFN_ 3 | 4 | struct RarLocalTime 5 | { 6 | uint Year; 7 | uint Month; 8 | uint Day; 9 | uint Hour; 10 | uint Minute; 11 | uint Second; 12 | uint Reminder; // Part of time smaller than 1 second, represented in 1/REMINDER_PRECISION intervals. 13 | uint wDay; 14 | uint yDay; 15 | }; 16 | 17 | 18 | class RarTime 19 | { 20 | private: 21 | static const uint TICKS_PER_SECOND = 1000000000; // Internal precision. 22 | 23 | // Internal time representation in 1/TICKS_PER_SECOND since 01.01.1601. 24 | // We use nanoseconds here to handle the high precision Unix time. 25 | uint64 itime; 26 | public: 27 | // RarLocalTime::Reminder precision. Must be equal to TICKS_PER_SECOND. 28 | // Unlike TICKS_PER_SECOND, it is a public field. 29 | static const uint REMINDER_PRECISION = TICKS_PER_SECOND; 30 | public: 31 | RarTime() {Reset();} 32 | bool operator == (RarTime &rt) {return itime==rt.itime;} 33 | bool operator != (RarTime &rt) {return itime!=rt.itime;} 34 | bool operator < (RarTime &rt) {return itime (RarTime &rt) {return itime>rt.itime;} 37 | bool operator >= (RarTime &rt) {return itime>rt.itime || itime==rt.itime;} 38 | 39 | void GetLocal(RarLocalTime *lt); 40 | void SetLocal(RarLocalTime *lt); 41 | #ifdef _WIN_ALL 42 | void GetWinFT(FILETIME *ft); 43 | void SetWinFT(FILETIME *ft); 44 | #endif 45 | uint64 GetWin(); 46 | void SetWin(uint64 WinTime); 47 | time_t GetUnix(); 48 | void SetUnix(time_t ut); 49 | uint64 GetUnixNS(); 50 | void SetUnixNS(uint64 ns); 51 | uint GetDos(); 52 | void SetDos(uint DosTime); 53 | void GetText(wchar *DateStr,size_t MaxSize,bool FullMS); 54 | void SetIsoText(const wchar *TimeText); 55 | void SetAgeText(const wchar *TimeText); 56 | void SetCurrentTime(); 57 | void Reset() {itime=0;} 58 | bool IsSet() {return itime!=0;} 59 | void Adjust(int64 ns); 60 | }; 61 | 62 | const wchar *GetMonthName(int Month); 63 | bool IsLeapYear(int Year); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /unrar/ui.cpp: -------------------------------------------------------------------------------- 1 | #include "rar.hpp" 2 | 3 | #include "uicommon.cpp" 4 | 5 | #ifdef SILENT 6 | #include "uisilent.cpp" 7 | #else 8 | 9 | 10 | 11 | 12 | #include "uiconsole.cpp" 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /unrar/uicommon.cpp: -------------------------------------------------------------------------------- 1 | static SOUND_NOTIFY_MODE uiSoundNotify; 2 | 3 | void uiInit(SOUND_NOTIFY_MODE Sound) 4 | { 5 | uiSoundNotify = Sound; 6 | } 7 | 8 | 9 | // Additionally to handling user input, it analyzes and sets command options. 10 | // Returns only 'replace', 'skip' and 'cancel' codes. 11 | UIASKREP_RESULT uiAskReplaceEx(RAROptions *Cmd,wchar *Name,size_t MaxNameSize,int64 FileSize,RarTime *FileTime,uint Flags) 12 | { 13 | if (Cmd->Overwrite==OVERWRITE_NONE) 14 | return UIASKREP_R_SKIP; 15 | 16 | #if !defined(SFX_MODULE) && !defined(SILENT) 17 | // Must be before Cmd->AllYes check or -y switch would override -or. 18 | if (Cmd->Overwrite==OVERWRITE_AUTORENAME && GetAutoRenamedName(Name,MaxNameSize)) 19 | return UIASKREP_R_REPLACE; 20 | #endif 21 | 22 | // This check must be after OVERWRITE_AUTORENAME processing or -y switch 23 | // would override -or. 24 | if (Cmd->AllYes || Cmd->Overwrite==OVERWRITE_ALL) 25 | { 26 | PrepareToDelete(Name); 27 | return UIASKREP_R_REPLACE; 28 | } 29 | 30 | wchar NewName[NM]; 31 | wcsncpyz(NewName,Name,ASIZE(NewName)); 32 | UIASKREP_RESULT Choice=uiAskReplace(NewName,ASIZE(NewName),FileSize,FileTime,Flags); 33 | 34 | if (Choice==UIASKREP_R_REPLACE || Choice==UIASKREP_R_REPLACEALL) 35 | PrepareToDelete(Name); 36 | 37 | if (Choice==UIASKREP_R_REPLACEALL) 38 | { 39 | Cmd->Overwrite=OVERWRITE_ALL; 40 | return UIASKREP_R_REPLACE; 41 | } 42 | if (Choice==UIASKREP_R_SKIPALL) 43 | { 44 | Cmd->Overwrite=OVERWRITE_NONE; 45 | return UIASKREP_R_SKIP; 46 | } 47 | if (Choice==UIASKREP_R_RENAME) 48 | { 49 | if (PointToName(NewName)==NewName) 50 | SetName(Name,NewName,MaxNameSize); 51 | else 52 | wcsncpyz(Name,NewName,MaxNameSize); 53 | if (FileExist(Name)) 54 | return uiAskReplaceEx(Cmd,Name,MaxNameSize,FileSize,FileTime,Flags); 55 | return UIASKREP_R_REPLACE; 56 | } 57 | #if !defined(SFX_MODULE) && !defined(SILENT) 58 | if (Choice==UIASKREP_R_RENAMEAUTO && GetAutoRenamedName(Name,MaxNameSize)) 59 | { 60 | Cmd->Overwrite=OVERWRITE_AUTORENAME; 61 | return UIASKREP_R_REPLACE; 62 | } 63 | #endif 64 | return Choice; 65 | } 66 | -------------------------------------------------------------------------------- /unrar/uisilent.cpp: -------------------------------------------------------------------------------- 1 | // Purely user interface function. Gets and returns user input. 2 | UIASKREP_RESULT uiAskReplace(wchar *Name,size_t MaxNameSize,int64 FileSize,RarTime *FileTime,uint Flags) 3 | { 4 | return UIASKREP_R_REPLACE; 5 | } 6 | 7 | 8 | 9 | 10 | void uiStartArchiveExtract(bool Extract,const wchar *ArcName) 11 | { 12 | } 13 | 14 | 15 | bool uiStartFileExtract(const wchar *FileName,bool Extract,bool Test,bool Skip) 16 | { 17 | return true; 18 | } 19 | 20 | 21 | void uiExtractProgress(int64 CurFileSize,int64 TotalFileSize,int64 CurSize,int64 TotalSize) 22 | { 23 | } 24 | 25 | 26 | void uiProcessProgress(const char *Command,int64 CurSize,int64 TotalSize) 27 | { 28 | } 29 | 30 | 31 | void uiMsgStore::Msg() 32 | { 33 | } 34 | 35 | 36 | bool uiGetPassword(UIPASSWORD_TYPE Type,const wchar *FileName,SecPassword *Password) 37 | { 38 | return false; 39 | } 40 | 41 | 42 | bool uiIsGlobalPasswordSet() 43 | { 44 | return false; 45 | } 46 | 47 | 48 | void uiAlarm(UIALARM_TYPE Type) 49 | { 50 | } 51 | 52 | 53 | bool uiIsAborted() 54 | { 55 | return false; 56 | } 57 | 58 | 59 | void uiGiveTick() 60 | { 61 | } 62 | 63 | 64 | #ifndef SFX_MODULE 65 | const wchar *uiGetMonthName(int Month) 66 | { 67 | return L""; 68 | } 69 | #endif 70 | 71 | 72 | void uiEolAfterMsg() 73 | { 74 | } 75 | -------------------------------------------------------------------------------- /unrar/unicode.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_UNICODE_ 2 | #define _RAR_UNICODE_ 3 | 4 | #if defined( _WIN_ALL) 5 | #define DBCS_SUPPORTED 6 | #endif 7 | 8 | bool WideToChar(const wchar *Src,char *Dest,size_t DestSize); 9 | bool CharToWide(const char *Src,wchar *Dest,size_t DestSize); 10 | byte* WideToRaw(const wchar *Src,byte *Dest,size_t SrcSize); 11 | wchar* RawToWide(const byte *Src,wchar *Dest,size_t DestSize); 12 | void WideToUtf(const wchar *Src,char *Dest,size_t DestSize); 13 | size_t WideToUtfSize(const wchar *Src); 14 | bool UtfToWide(const char *Src,wchar *Dest,size_t DestSize); 15 | bool IsTextUtf8(const byte *Src); 16 | bool IsTextUtf8(const byte *Src,size_t SrcSize); 17 | 18 | int wcsicomp(const wchar *s1,const wchar *s2); 19 | int wcsnicomp(const wchar *s1,const wchar *s2,size_t n); 20 | const wchar_t* wcscasestr(const wchar_t *str, const wchar_t *search); 21 | #ifndef SFX_MODULE 22 | wchar* wcslower(wchar *s); 23 | wchar* wcsupper(wchar *s); 24 | #endif 25 | int toupperw(int ch); 26 | int tolowerw(int ch); 27 | int atoiw(const wchar *s); 28 | int64 atoilw(const wchar *s); 29 | 30 | #ifdef DBCS_SUPPORTED 31 | class SupportDBCS 32 | { 33 | public: 34 | SupportDBCS(); 35 | void Init(); 36 | 37 | char* charnext(const char *s); 38 | size_t strlend(const char *s); 39 | char *strchrd(const char *s, int c); 40 | char *strrchrd(const char *s, int c); 41 | void copychrd(char *dest,const char *src); 42 | 43 | bool IsLeadByte[256]; 44 | bool DBCSMode; 45 | }; 46 | 47 | extern SupportDBCS gdbcs; 48 | 49 | inline char* charnext(const char *s) {return (char *)(gdbcs.DBCSMode ? gdbcs.charnext(s):s+1);} 50 | inline size_t strlend(const char *s) {return (uint)(gdbcs.DBCSMode ? gdbcs.strlend(s):strlen(s));} 51 | inline char* strchrd(const char *s, int c) {return (char *)(gdbcs.DBCSMode ? gdbcs.strchrd(s,c):strchr(s,c));} 52 | inline char* strrchrd(const char *s, int c) {return (char *)(gdbcs.DBCSMode ? gdbcs.strrchrd(s,c):strrchr(s,c));} 53 | inline void copychrd(char *dest,const char *src) {if (gdbcs.DBCSMode) gdbcs.copychrd(dest,src); else *dest=*src;} 54 | inline bool IsDBCSMode() {return(gdbcs.DBCSMode);} 55 | inline void InitDBCS() {gdbcs.Init();} 56 | 57 | #else 58 | #define charnext(s) ((s)+1) 59 | #define strlend strlen 60 | #define strchrd strchr 61 | #define strrchrd strrchr 62 | #define IsDBCSMode() (true) 63 | inline void copychrd(char *dest,const char *src) {*dest=*src;} 64 | #endif 65 | 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /unrar/uowners.loT: -------------------------------------------------------------------------------- 1 | # unrar/uowners.lo - a libtool object file 2 | # Generated by ltmain.sh - GNU libtool 1.5.26 (1.1220.2.492 2008/01/30 06:40:56) 3 | # 4 | # Please DO NOT delete this file! 5 | # It is necessary for linking the library. 6 | 7 | # Name of the PIC object. 8 | -------------------------------------------------------------------------------- /unrar/version.hpp: -------------------------------------------------------------------------------- 1 | #define RARVER_MAJOR 6 2 | #define RARVER_MINOR 0 3 | #define RARVER_BETA 2 4 | #define RARVER_PATCH 1 5 | #define RARVER_DAY 12 6 | #define RARVER_MONTH 11 7 | #define RARVER_YEAR 2020 8 | -------------------------------------------------------------------------------- /unrar/volume.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _RAR_VOLUME_ 2 | #define _RAR_VOLUME_ 3 | 4 | void SplitArchive(Archive &Arc,FileHeader *fh,int64 *HeaderPos, 5 | ComprDataIO *DataIO); 6 | bool MergeArchive(Archive &Arc,ComprDataIO *DataIO,bool ShowFileName, 7 | wchar Command); 8 | void SetVolWrite(Archive &Dest,int64 VolSize); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /valgrind.supp: -------------------------------------------------------------------------------- 1 | { 2 | 3 | Memcheck:Value8 4 | fun:_Z5CRC32jPKvm 5 | fun:_ZN7RawRead8GetCRC15Eb 6 | ... 7 | } 8 | { 9 | 10 | Memcheck:Value8 11 | fun:_Z6Xor128PhPKhS1_S1_S1_ 12 | fun:_ZN8Rijndael12blockDecryptEPKhmPh 13 | ... 14 | } 15 | { 16 | 17 | Memcheck:Value8 18 | fun:Xor128 19 | fun:_ZN8Rijndael12blockDecryptEPKhmPh 20 | ... 21 | } 22 | #see comment in unicode.cpp, func WideToChar 23 | { 24 | 25 | Memcheck:Cond 26 | ... 27 | fun:wcsrtombs 28 | ... 29 | } 30 | { 31 | 32 | Memcheck:Addr32 33 | ... 34 | fun:wcsrtombs 35 | ... 36 | } 37 | { 38 | <7.4 zend_string_equal_val> 39 | Memcheck:Cond 40 | fun:zend_string_equal_val 41 | fun:zend_string_equal_content 42 | ... 43 | } 44 | { 45 | <7.4 constructor exception> 46 | Memcheck:Leak 47 | match-leak-kinds: definite 48 | ... 49 | fun:_emalloc 50 | fun:zend_objects_new 51 | fun:zend_default_exception_new_ex 52 | fun:zend_default_exception_new 53 | fun:_object_and_properties_init 54 | fun:object_init_ex 55 | fun:zend_throw_exception 56 | ... 57 | } 58 | { 59 | <7.4 zend_compile> 60 | Memcheck:Leak 61 | match-leak-kinds: definite 62 | ... 63 | fun:_emalloc 64 | fun:zend_compile 65 | fun:compile_file 66 | ... 67 | } 68 | { 69 | <7.4 error> 70 | Memcheck:Leak 71 | match-leak-kinds: definite 72 | ... 73 | fun:_emalloc 74 | ... 75 | fun:php_verror 76 | ... 77 | } 78 | { 79 | 80 | Memcheck:Leak 81 | match-leak-kinds: definite 82 | ... 83 | fun:spprintf 84 | fun:php_verror 85 | fun:php_error_docref0 86 | ... 87 | } 88 | { 89 | 90 | Memcheck:Leak 91 | match-leak-kinds: definite 92 | ... 93 | fun:zend_spprintf 94 | fun:php_verror 95 | fun:php_error_docref0 96 | ... 97 | } 98 | { 99 | 100 | Memcheck:Leak 101 | match-leak-kinds: definite 102 | ... 103 | fun:_emalloc 104 | fun:compile_file 105 | fun:zend_execute_scripts 106 | fun:php_execute_script 107 | ... 108 | } 109 | { 110 | 111 | Memcheck:Leak 112 | match-leak-kinds: possible 113 | fun:realloc 114 | fun:__zend_realloc 115 | fun:_realloc_custom 116 | fun:_erealloc 117 | fun:pass_two 118 | fun:zend_compile 119 | fun:compile_file 120 | fun:zend_execute_scripts 121 | fun:php_execute_script 122 | fun:do_cli 123 | fun:main 124 | } 125 | --------------------------------------------------------------------------------