├── .gitignore ├── App.config ├── CL.IO.Zip ├── CL.IO.Zip.csproj ├── ProgressItem.cs ├── Properties │ └── AssemblyInfo.cs ├── SharpZipLib │ ├── BZip2 │ │ ├── BZip2.cs │ │ ├── BZip2Constants.cs │ │ ├── BZip2Exception.cs │ │ ├── BZip2InputStream.cs │ │ └── BZip2OutputStream.cs │ ├── Checksums │ │ ├── Adler32.cs │ │ ├── CRC32.cs │ │ ├── IChecksum.cs │ │ └── StrangeCRC.cs │ ├── Core │ │ ├── FileSystemScanner.cs │ │ ├── INameTransform.cs │ │ ├── IScanFilter.cs │ │ ├── NameFilter.cs │ │ ├── PathFilter.cs │ │ ├── StreamUtils.cs │ │ └── WindowsPathUtils.cs │ ├── Encryption │ │ ├── PkzipClassic.cs │ │ ├── ZipAESStream.cs │ │ └── ZipAESTransform.cs │ ├── GZip │ │ ├── GZIPConstants.cs │ │ ├── GZipException.cs │ │ ├── GzipInputStream.cs │ │ └── GzipOutputStream.cs │ ├── SharpZipBaseException.cs │ ├── Tar │ │ ├── InvalidHeaderException.cs │ │ ├── TarArchive.cs │ │ ├── TarBuffer.cs │ │ ├── TarEntry.cs │ │ ├── TarException.cs │ │ ├── TarHeader.cs │ │ ├── TarInputStream.cs │ │ └── TarOutputStream.cs │ └── Zip │ │ ├── Compression │ │ ├── Deflater.cs │ │ ├── DeflaterConstants.cs │ │ ├── DeflaterEngine.cs │ │ ├── DeflaterHuffman.cs │ │ ├── DeflaterPending.cs │ │ ├── Inflater.cs │ │ ├── InflaterDynHeader.cs │ │ ├── InflaterHuffmanTree.cs │ │ ├── PendingBuffer.cs │ │ └── Streams │ │ │ ├── DeflaterOutputStream.cs │ │ │ ├── InflaterInputStream.cs │ │ │ ├── OutputWindow.cs │ │ │ └── StreamManipulator.cs │ │ ├── FastZip.cs │ │ ├── IEntryFactory.cs │ │ ├── WindowsNameTransform.cs │ │ ├── ZipConstants.cs │ │ ├── ZipEntry.cs │ │ ├── ZipEntryFactory.cs │ │ ├── ZipException.cs │ │ ├── ZipExtraData.cs │ │ ├── ZipFile.cs │ │ ├── ZipHelperStream.cs │ │ ├── ZipInputStream.cs │ │ ├── ZipNameTransform.cs │ │ └── ZipOutputStream.cs └── ZipHandler.cs ├── LICENSE ├── MIUI_Theme_Magiskizer.csproj ├── MIUI_Theme_Magiskizer.csproj.user ├── Program.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs ├── Settings.settings └── app.manifest ├── frm_Editor.Designer.cs ├── frm_Editor.cs ├── frm_Editor.resx ├── frm_Main.Designer.cs ├── frm_Main.cs ├── frm_Main.resx ├── magiskTemplate ├── .gitattributes ├── META-INF │ └── com │ │ └── google │ │ └── android │ │ ├── update-binary │ │ └── updater-script ├── common │ └── list_of_moving_files ├── config.sh ├── module.prop └── system │ └── placeholder └── magiskTemplate_1500.zip /.gitignore: -------------------------------------------------------------------------------- 1 | obj 2 | bin 3 | -------------------------------------------------------------------------------- /App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /CL.IO.Zip/CL.IO.Zip.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {BE8465A3-F65A-4D0F-88FB-56062758922E} 8 | Library 9 | Properties 10 | CL.IO.Zip 11 | CL.IO.Zip 12 | v4.0 13 | 512 14 | 15 | 16 | 17 | 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 114 | -------------------------------------------------------------------------------- /CL.IO.Zip/ProgressItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace CL.IO.Zip 6 | { 7 | 8 | class ProcessItem 9 | { 10 | public ProcessItem(double NeedHandleCount) 11 | { 12 | this.NeedHandleCount = NeedHandleCount; 13 | this.HandledFiles = new List(); 14 | } 15 | public double NeedHandleCount { set; get; } 16 | public double HadHandleCount { set; get; } 17 | public List HandledFiles { set; get; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /CL.IO.Zip/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过以下 6 | // 特性集控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("CL.IO.Zip")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("CLStudio")] 12 | [assembly: AssemblyProduct("CL.IO.Zip")] 13 | [assembly: AssemblyCopyright("Copyright © CLStudio 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("3073006e-2867-4404-af76-7707774d3afe")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.1.0")] 36 | [assembly: AssemblyFileVersion("1.1.0")] 37 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/BZip2/BZip2.cs: -------------------------------------------------------------------------------- 1 | // BZip2.cs 2 | // 3 | // Copyright (C) 2010 David Pierson 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 2 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | // 19 | // Linking this library statically or dynamically with other modules is 20 | // making a combined work based on this library. Thus, the terms and 21 | // conditions of the GNU General Public License cover the whole 22 | // combination. 23 | // 24 | // As a special exception, the copyright holders of this library give you 25 | // permission to link this library with independent modules to produce an 26 | // executable, regardless of the license terms of these independent 27 | // modules, and to copy and distribute the resulting executable under 28 | // terms of your choice, provided that you also meet, for each linked 29 | // independent module, the terms and conditions of the license of that 30 | // module. An independent module is a module which is not derived from 31 | // or based on this library. If you modify this library, you may extend 32 | // this exception to your version of the library, but you are not 33 | // obligated to do so. If you do not wish to do so, delete this 34 | // exception statement from your version. 35 | 36 | // Suppress this in CF and 1.1, not needed. Static classes introduced in C# version 2.0 37 | #if !NETCF_2_0 && !NET_1_1 38 | 39 | using System; 40 | using System.IO; 41 | 42 | namespace ICSharpCode.SharpZipLib.BZip2 { 43 | 44 | /// 45 | /// An example class to demonstrate compression and decompression of BZip2 streams. 46 | /// 47 | public static class BZip2 48 | { 49 | /// 50 | /// Decompress the input writing 51 | /// uncompressed data to the output stream 52 | /// 53 | /// The readable stream containing data to decompress. 54 | /// The output stream to receive the decompressed data. 55 | /// Both streams are closed on completion if true. 56 | public static void Decompress(Stream inStream, Stream outStream, bool isStreamOwner) 57 | { 58 | if (inStream == null || outStream == null) { 59 | throw new Exception("Null Stream"); 60 | } 61 | 62 | try { 63 | using (BZip2InputStream bzipInput = new BZip2InputStream(inStream)) { 64 | bzipInput.IsStreamOwner = isStreamOwner; 65 | Core.StreamUtils.Copy(bzipInput, outStream, new byte[4096]); 66 | } 67 | } finally { 68 | if (isStreamOwner) { 69 | // inStream is closed by the BZip2InputStream if stream owner 70 | outStream.Close(); 71 | } 72 | } 73 | } 74 | 75 | /// 76 | /// Compress the input stream sending 77 | /// result data to output stream 78 | /// 79 | /// The readable stream to compress. 80 | /// The output stream to receive the compressed data. 81 | /// Both streams are closed on completion if true. 82 | /// Block size acts as compression level (1 to 9) with 1 giving 83 | /// the lowest compression and 9 the highest. 84 | public static void Compress(Stream inStream, Stream outStream, bool isStreamOwner, int level) 85 | { 86 | if (inStream == null || outStream == null) { 87 | throw new Exception("Null Stream"); 88 | } 89 | 90 | try { 91 | using (BZip2OutputStream bzipOutput = new BZip2OutputStream(outStream, level)) { 92 | bzipOutput.IsStreamOwner = isStreamOwner; 93 | Core.StreamUtils.Copy(inStream, bzipOutput, new byte[4096]); 94 | } 95 | } finally { 96 | if (isStreamOwner) { 97 | // outStream is closed by the BZip2OutputStream if stream owner 98 | inStream.Close(); 99 | } 100 | } 101 | } 102 | 103 | } 104 | } 105 | #endif 106 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/BZip2/BZip2Constants.cs: -------------------------------------------------------------------------------- 1 | // BZip2Constants.cs 2 | // Copyright (C) 2001 Mike Krueger 3 | // 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | // 18 | // Linking this library statically or dynamically with other modules is 19 | // making a combined work based on this library. Thus, the terms and 20 | // conditions of the GNU General Public License cover the whole 21 | // combination. 22 | // 23 | // As a special exception, the copyright holders of this library give you 24 | // permission to link this library with independent modules to produce an 25 | // executable, regardless of the license terms of these independent 26 | // modules, and to copy and distribute the resulting executable under 27 | // terms of your choice, provided that you also meet, for each linked 28 | // independent module, the terms and conditions of the license of that 29 | // module. An independent module is a module which is not derived from 30 | // or based on this library. If you modify this library, you may extend 31 | // this exception to your version of the library, but you are not 32 | // obligated to do so. If you do not wish to do so, delete this 33 | // exception statement from your version. 34 | 35 | namespace ICSharpCode.SharpZipLib.BZip2 36 | { 37 | 38 | /// 39 | /// Defines internal values for both compression and decompression 40 | /// 41 | internal sealed class BZip2Constants 42 | { 43 | /// 44 | /// Random numbers used to randomise repetitive blocks 45 | /// 46 | public readonly static int[] RandomNumbers = { 47 | 619, 720, 127, 481, 931, 816, 813, 233, 566, 247, 48 | 985, 724, 205, 454, 863, 491, 741, 242, 949, 214, 49 | 733, 859, 335, 708, 621, 574, 73, 654, 730, 472, 50 | 419, 436, 278, 496, 867, 210, 399, 680, 480, 51, 51 | 878, 465, 811, 169, 869, 675, 611, 697, 867, 561, 52 | 862, 687, 507, 283, 482, 129, 807, 591, 733, 623, 53 | 150, 238, 59, 379, 684, 877, 625, 169, 643, 105, 54 | 170, 607, 520, 932, 727, 476, 693, 425, 174, 647, 55 | 73, 122, 335, 530, 442, 853, 695, 249, 445, 515, 56 | 909, 545, 703, 919, 874, 474, 882, 500, 594, 612, 57 | 641, 801, 220, 162, 819, 984, 589, 513, 495, 799, 58 | 161, 604, 958, 533, 221, 400, 386, 867, 600, 782, 59 | 382, 596, 414, 171, 516, 375, 682, 485, 911, 276, 60 | 98, 553, 163, 354, 666, 933, 424, 341, 533, 870, 61 | 227, 730, 475, 186, 263, 647, 537, 686, 600, 224, 62 | 469, 68, 770, 919, 190, 373, 294, 822, 808, 206, 63 | 184, 943, 795, 384, 383, 461, 404, 758, 839, 887, 64 | 715, 67, 618, 276, 204, 918, 873, 777, 604, 560, 65 | 951, 160, 578, 722, 79, 804, 96, 409, 713, 940, 66 | 652, 934, 970, 447, 318, 353, 859, 672, 112, 785, 67 | 645, 863, 803, 350, 139, 93, 354, 99, 820, 908, 68 | 609, 772, 154, 274, 580, 184, 79, 626, 630, 742, 69 | 653, 282, 762, 623, 680, 81, 927, 626, 789, 125, 70 | 411, 521, 938, 300, 821, 78, 343, 175, 128, 250, 71 | 170, 774, 972, 275, 999, 639, 495, 78, 352, 126, 72 | 857, 956, 358, 619, 580, 124, 737, 594, 701, 612, 73 | 669, 112, 134, 694, 363, 992, 809, 743, 168, 974, 74 | 944, 375, 748, 52, 600, 747, 642, 182, 862, 81, 75 | 344, 805, 988, 739, 511, 655, 814, 334, 249, 515, 76 | 897, 955, 664, 981, 649, 113, 974, 459, 893, 228, 77 | 433, 837, 553, 268, 926, 240, 102, 654, 459, 51, 78 | 686, 754, 806, 760, 493, 403, 415, 394, 687, 700, 79 | 946, 670, 656, 610, 738, 392, 760, 799, 887, 653, 80 | 978, 321, 576, 617, 626, 502, 894, 679, 243, 440, 81 | 680, 879, 194, 572, 640, 724, 926, 56, 204, 700, 82 | 707, 151, 457, 449, 797, 195, 791, 558, 945, 679, 83 | 297, 59, 87, 824, 713, 663, 412, 693, 342, 606, 84 | 134, 108, 571, 364, 631, 212, 174, 643, 304, 329, 85 | 343, 97, 430, 751, 497, 314, 983, 374, 822, 928, 86 | 140, 206, 73, 263, 980, 736, 876, 478, 430, 305, 87 | 170, 514, 364, 692, 829, 82, 855, 953, 676, 246, 88 | 369, 970, 294, 750, 807, 827, 150, 790, 288, 923, 89 | 804, 378, 215, 828, 592, 281, 565, 555, 710, 82, 90 | 896, 831, 547, 261, 524, 462, 293, 465, 502, 56, 91 | 661, 821, 976, 991, 658, 869, 905, 758, 745, 193, 92 | 768, 550, 608, 933, 378, 286, 215, 979, 792, 961, 93 | 61, 688, 793, 644, 986, 403, 106, 366, 905, 644, 94 | 372, 567, 466, 434, 645, 210, 389, 550, 919, 135, 95 | 780, 773, 635, 389, 707, 100, 626, 958, 165, 504, 96 | 920, 176, 193, 713, 857, 265, 203, 50, 668, 108, 97 | 645, 990, 626, 197, 510, 357, 358, 850, 858, 364, 98 | 936, 638 99 | }; 100 | 101 | /// 102 | /// When multiplied by compression parameter (1-9) gives the block size for compression 103 | /// 9 gives the best compression but uses the most memory. 104 | /// 105 | public const int BaseBlockSize = 100000; 106 | 107 | /// 108 | /// Backend constant 109 | /// 110 | public const int MaximumAlphaSize = 258; 111 | 112 | /// 113 | /// Backend constant 114 | /// 115 | public const int MaximumCodeLength = 23; 116 | 117 | /// 118 | /// Backend constant 119 | /// 120 | public const int RunA = 0; 121 | 122 | /// 123 | /// Backend constant 124 | /// 125 | public const int RunB = 1; 126 | 127 | /// 128 | /// Backend constant 129 | /// 130 | public const int GroupCount = 6; 131 | 132 | /// 133 | /// Backend constant 134 | /// 135 | public const int GroupSize = 50; 136 | 137 | /// 138 | /// Backend constant 139 | /// 140 | public const int NumberOfIterations = 4; 141 | 142 | /// 143 | /// Backend constant 144 | /// 145 | public const int MaximumSelectors = (2 + (900000 / GroupSize)); 146 | 147 | /// 148 | /// Backend constant 149 | /// 150 | public const int OvershootBytes = 20; 151 | 152 | private BZip2Constants() 153 | { 154 | } 155 | } 156 | } 157 | 158 | /* This file was derived from a file containing this license: 159 | * 160 | * This file is a part of bzip2 and/or libbzip2, a program and 161 | * library for lossless, block-sorting data compression. 162 | * 163 | * Copyright (C) 1996-1998 Julian R Seward. All rights reserved. 164 | * 165 | * Redistribution and use in source and binary forms, with or without 166 | * modification, are permitted provided that the following conditions 167 | * are met: 168 | * 169 | * 1. Redistributions of source code must retain the above copyright 170 | * notice, this list of conditions and the following disclaimer. 171 | * 172 | * 2. The origin of this software must not be misrepresented; you must 173 | * not claim that you wrote the original software. If you use this 174 | * software in a product, an acknowledgment in the product 175 | * documentation would be appreciated but is not required. 176 | * 177 | * 3. Altered source versions must be plainly marked as such, and must 178 | * not be misrepresented as being the original software. 179 | * 180 | * 4. The name of the author may not be used to endorse or promote 181 | * products derived from this software without specific prior written 182 | * permission. 183 | * 184 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 185 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 186 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 187 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 188 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 189 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 190 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 191 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 192 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 193 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 194 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 195 | * 196 | * Java version ported by Keiron Liddle, Aftex Software 1999-2001 197 | */ 198 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/BZip2/BZip2Exception.cs: -------------------------------------------------------------------------------- 1 | // BZip2.cs 2 | // 3 | // Copyright 2004 John Reilly 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 2 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | // 19 | // Linking this library statically or dynamically with other modules is 20 | // making a combined work based on this library. Thus, the terms and 21 | // conditions of the GNU General Public License cover the whole 22 | // combination. 23 | // 24 | // As a special exception, the copyright holders of this library give you 25 | // permission to link this library with independent modules to produce an 26 | // executable, regardless of the license terms of these independent 27 | // modules, and to copy and distribute the resulting executable under 28 | // terms of your choice, provided that you also meet, for each linked 29 | // independent module, the terms and conditions of the license of that 30 | // module. An independent module is a module which is not derived from 31 | // or based on this library. If you modify this library, you may extend 32 | // this exception to your version of the library, but you are not 33 | // obligated to do so. If you do not wish to do so, delete this 34 | // exception statement from your version. 35 | 36 | using System; 37 | 38 | #if !NETCF_1_0 && !NETCF_2_0 39 | using System.Runtime.Serialization; 40 | #endif 41 | 42 | namespace ICSharpCode.SharpZipLib.BZip2 43 | { 44 | /// 45 | /// BZip2Exception represents exceptions specific to Bzip2 algorithm 46 | /// 47 | #if !NETCF_1_0 && !NETCF_2_0 48 | [Serializable] 49 | #endif 50 | public class BZip2Exception : SharpZipBaseException 51 | { 52 | 53 | #if !NETCF_1_0 && !NETCF_2_0 54 | /// 55 | /// Deserialization constructor 56 | /// 57 | /// for this constructor 58 | /// for this constructor 59 | protected BZip2Exception(SerializationInfo info, StreamingContext context) 60 | : base(info, context) 61 | 62 | { 63 | } 64 | #endif 65 | /// 66 | /// Initialise a new instance of BZip2Exception. 67 | /// 68 | public BZip2Exception() 69 | { 70 | } 71 | 72 | /// 73 | /// Initialise a new instance of BZip2Exception with its message set to message. 74 | /// 75 | /// The message describing the error. 76 | public BZip2Exception(string message) : base(message) 77 | { 78 | } 79 | 80 | /// 81 | /// Initialise an instance of BZip2Exception 82 | /// 83 | /// A message describing the error. 84 | /// The exception that is the cause of the current exception. 85 | public BZip2Exception(string message, Exception exception) 86 | : base(message, exception) 87 | { 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Checksums/Adler32.cs: -------------------------------------------------------------------------------- 1 | // Adler32.cs - Computes Adler32 data checksum of a data stream 2 | // Copyright (C) 2001 Mike Krueger 3 | // 4 | // This file was translated from java, it was part of the GNU Classpath 5 | // Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. 6 | // 7 | // This program is free software; you can redistribute it and/or 8 | // modify it under the terms of the GNU General Public License 9 | // as published by the Free Software Foundation; either version 2 10 | // of the License, or (at your option) any later version. 11 | // 12 | // This program is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | // GNU General Public License for more details. 16 | // 17 | // You should have received a copy of the GNU General Public License 18 | // along with this program; if not, write to the Free Software 19 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | // 21 | // Linking this library statically or dynamically with other modules is 22 | // making a combined work based on this library. Thus, the terms and 23 | // conditions of the GNU General Public License cover the whole 24 | // combination. 25 | // 26 | // As a special exception, the copyright holders of this library give you 27 | // permission to link this library with independent modules to produce an 28 | // executable, regardless of the license terms of these independent 29 | // modules, and to copy and distribute the resulting executable under 30 | // terms of your choice, provided that you also meet, for each linked 31 | // independent module, the terms and conditions of the license of that 32 | // module. An independent module is a module which is not derived from 33 | // or based on this library. If you modify this library, you may extend 34 | // this exception to your version of the library, but you are not 35 | // obligated to do so. If you do not wish to do so, delete this 36 | // exception statement from your version. 37 | 38 | using System; 39 | 40 | namespace ICSharpCode.SharpZipLib.Checksums 41 | { 42 | 43 | /// 44 | /// Computes Adler32 checksum for a stream of data. An Adler32 45 | /// checksum is not as reliable as a CRC32 checksum, but a lot faster to 46 | /// compute. 47 | /// 48 | /// The specification for Adler32 may be found in RFC 1950. 49 | /// ZLIB Compressed Data Format Specification version 3.3) 50 | /// 51 | /// 52 | /// From that document: 53 | /// 54 | /// "ADLER32 (Adler-32 checksum) 55 | /// This contains a checksum value of the uncompressed data 56 | /// (excluding any dictionary data) computed according to Adler-32 57 | /// algorithm. This algorithm is a 32-bit extension and improvement 58 | /// of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073 59 | /// standard. 60 | /// 61 | /// Adler-32 is composed of two sums accumulated per byte: s1 is 62 | /// the sum of all bytes, s2 is the sum of all s1 values. Both sums 63 | /// are done modulo 65521. s1 is initialized to 1, s2 to zero. The 64 | /// Adler-32 checksum is stored as s2*65536 + s1 in most- 65 | /// significant-byte first (network) order." 66 | /// 67 | /// "8.2. The Adler-32 algorithm 68 | /// 69 | /// The Adler-32 algorithm is much faster than the CRC32 algorithm yet 70 | /// still provides an extremely low probability of undetected errors. 71 | /// 72 | /// The modulo on unsigned long accumulators can be delayed for 5552 73 | /// bytes, so the modulo operation time is negligible. If the bytes 74 | /// are a, b, c, the second sum is 3a + 2b + c + 3, and so is position 75 | /// and order sensitive, unlike the first sum, which is just a 76 | /// checksum. That 65521 is prime is important to avoid a possible 77 | /// large class of two-byte errors that leave the check unchanged. 78 | /// (The Fletcher checksum uses 255, which is not prime and which also 79 | /// makes the Fletcher check insensitive to single byte changes 0 - 80 | /// 255.) 81 | /// 82 | /// The sum s1 is initialized to 1 instead of zero to make the length 83 | /// of the sequence part of s2, so that the length does not have to be 84 | /// checked separately. (Any sequence of zeroes has a Fletcher 85 | /// checksum of zero.)" 86 | /// 87 | /// 88 | /// 89 | public sealed class Adler32 : IChecksum 90 | { 91 | /// 92 | /// largest prime smaller than 65536 93 | /// 94 | const uint BASE = 65521; 95 | 96 | /// 97 | /// Returns the Adler32 data checksum computed so far. 98 | /// 99 | public long Value { 100 | get { 101 | return checksum; 102 | } 103 | } 104 | 105 | /// 106 | /// Creates a new instance of the Adler32 class. 107 | /// The checksum starts off with a value of 1. 108 | /// 109 | public Adler32() 110 | { 111 | Reset(); 112 | } 113 | 114 | /// 115 | /// Resets the Adler32 checksum to the initial value. 116 | /// 117 | public void Reset() 118 | { 119 | checksum = 1; 120 | } 121 | 122 | /// 123 | /// Updates the checksum with a byte value. 124 | /// 125 | /// 126 | /// The data value to add. The high byte of the int is ignored. 127 | /// 128 | public void Update(int value) 129 | { 130 | // We could make a length 1 byte array and call update again, but I 131 | // would rather not have that overhead 132 | uint s1 = checksum & 0xFFFF; 133 | uint s2 = checksum >> 16; 134 | 135 | s1 = (s1 + ((uint)value & 0xFF)) % BASE; 136 | s2 = (s1 + s2) % BASE; 137 | 138 | checksum = (s2 << 16) + s1; 139 | } 140 | 141 | /// 142 | /// Updates the checksum with an array of bytes. 143 | /// 144 | /// 145 | /// The source of the data to update with. 146 | /// 147 | public void Update(byte[] buffer) 148 | { 149 | if ( buffer == null ) { 150 | throw new ArgumentNullException("buffer"); 151 | } 152 | 153 | Update(buffer, 0, buffer.Length); 154 | } 155 | 156 | /// 157 | /// Updates the checksum with the bytes taken from the array. 158 | /// 159 | /// 160 | /// an array of bytes 161 | /// 162 | /// 163 | /// the start of the data used for this update 164 | /// 165 | /// 166 | /// the number of bytes to use for this update 167 | /// 168 | public void Update(byte[] buffer, int offset, int count) 169 | { 170 | if (buffer == null) { 171 | throw new ArgumentNullException("buffer"); 172 | } 173 | 174 | if (offset < 0) { 175 | #if NETCF_1_0 176 | throw new ArgumentOutOfRangeException("offset"); 177 | #else 178 | throw new ArgumentOutOfRangeException("offset", "cannot be negative"); 179 | #endif 180 | } 181 | 182 | if ( count < 0 ) 183 | { 184 | #if NETCF_1_0 185 | throw new ArgumentOutOfRangeException("count"); 186 | #else 187 | throw new ArgumentOutOfRangeException("count", "cannot be negative"); 188 | #endif 189 | } 190 | 191 | if (offset >= buffer.Length) 192 | { 193 | #if NETCF_1_0 194 | throw new ArgumentOutOfRangeException("offset"); 195 | #else 196 | throw new ArgumentOutOfRangeException("offset", "not a valid index into buffer"); 197 | #endif 198 | } 199 | 200 | if (offset + count > buffer.Length) 201 | { 202 | #if NETCF_1_0 203 | throw new ArgumentOutOfRangeException("count"); 204 | #else 205 | throw new ArgumentOutOfRangeException("count", "exceeds buffer size"); 206 | #endif 207 | } 208 | 209 | //(By Per Bothner) 210 | uint s1 = checksum & 0xFFFF; 211 | uint s2 = checksum >> 16; 212 | 213 | while (count > 0) { 214 | // We can defer the modulo operation: 215 | // s1 maximally grows from 65521 to 65521 + 255 * 3800 216 | // s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31 217 | int n = 3800; 218 | if (n > count) { 219 | n = count; 220 | } 221 | count -= n; 222 | while (--n >= 0) { 223 | s1 = s1 + (uint)(buffer[offset++] & 0xff); 224 | s2 = s2 + s1; 225 | } 226 | s1 %= BASE; 227 | s2 %= BASE; 228 | } 229 | 230 | checksum = (s2 << 16) | s1; 231 | } 232 | 233 | #region Instance Fields 234 | uint checksum; 235 | #endregion 236 | } 237 | } 238 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Checksums/IChecksum.cs: -------------------------------------------------------------------------------- 1 | // IChecksum.cs - Interface to compute a data checksum 2 | // Copyright (C) 2001 Mike Krueger 3 | // 4 | // This file was translated from java, it was part of the GNU Classpath 5 | // Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. 6 | // 7 | // This program is free software; you can redistribute it and/or 8 | // modify it under the terms of the GNU General Public License 9 | // as published by the Free Software Foundation; either version 2 10 | // of the License, or (at your option) any later version. 11 | // 12 | // This program is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | // GNU General Public License for more details. 16 | // 17 | // You should have received a copy of the GNU General Public License 18 | // along with this program; if not, write to the Free Software 19 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | // 21 | // Linking this library statically or dynamically with other modules is 22 | // making a combined work based on this library. Thus, the terms and 23 | // conditions of the GNU General Public License cover the whole 24 | // combination. 25 | // 26 | // As a special exception, the copyright holders of this library give you 27 | // permission to link this library with independent modules to produce an 28 | // executable, regardless of the license terms of these independent 29 | // modules, and to copy and distribute the resulting executable under 30 | // terms of your choice, provided that you also meet, for each linked 31 | // independent module, the terms and conditions of the license of that 32 | // module. An independent module is a module which is not derived from 33 | // or based on this library. If you modify this library, you may extend 34 | // this exception to your version of the library, but you are not 35 | // obligated to do so. If you do not wish to do so, delete this 36 | // exception statement from your version. 37 | 38 | namespace ICSharpCode.SharpZipLib.Checksums 39 | { 40 | 41 | /// 42 | /// Interface to compute a data checksum used by checked input/output streams. 43 | /// A data checksum can be updated by one byte or with a byte array. After each 44 | /// update the value of the current checksum can be returned by calling 45 | /// getValue. The complete checksum object can also be reset 46 | /// so it can be used again with new data. 47 | /// 48 | public interface IChecksum 49 | { 50 | /// 51 | /// Returns the data checksum computed so far. 52 | /// 53 | long Value 54 | { 55 | get; 56 | } 57 | 58 | /// 59 | /// Resets the data checksum as if no update was ever called. 60 | /// 61 | void Reset(); 62 | 63 | /// 64 | /// Adds one byte to the data checksum. 65 | /// 66 | /// 67 | /// the data value to add. The high byte of the int is ignored. 68 | /// 69 | void Update(int value); 70 | 71 | /// 72 | /// Updates the data checksum with the bytes taken from the array. 73 | /// 74 | /// 75 | /// buffer an array of bytes 76 | /// 77 | void Update(byte[] buffer); 78 | 79 | /// 80 | /// Adds the byte array to the data checksum. 81 | /// 82 | /// 83 | /// The buffer which contains the data 84 | /// 85 | /// 86 | /// The offset in the buffer where the data starts 87 | /// 88 | /// 89 | /// the number of data bytes to add. 90 | /// 91 | void Update(byte[] buffer, int offset, int count); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Checksums/StrangeCRC.cs: -------------------------------------------------------------------------------- 1 | // StrangeCRC.cs - computes a crc used in the bziplib 2 | // 3 | // Copyright (C) 2001 Mike Krueger 4 | // 5 | // This file was translated from java, it was part of the GNU Classpath 6 | // Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. 7 | // 8 | // This program is free software; you can redistribute it and/or 9 | // modify it under the terms of the GNU General Public License 10 | // as published by the Free Software Foundation; either version 2 11 | // of the License, or (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program; if not, write to the Free Software 20 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | // 22 | // Linking this library statically or dynamically with other modules is 23 | // making a combined work based on this library. Thus, the terms and 24 | // conditions of the GNU General Public License cover the whole 25 | // combination. 26 | // 27 | // As a special exception, the copyright holders of this library give you 28 | // permission to link this library with independent modules to produce an 29 | // executable, regardless of the license terms of these independent 30 | // modules, and to copy and distribute the resulting executable under 31 | // terms of your choice, provided that you also meet, for each linked 32 | // independent module, the terms and conditions of the license of that 33 | // module. An independent module is a module which is not derived from 34 | // or based on this library. If you modify this library, you may extend 35 | // this exception to your version of the library, but you are not 36 | // obligated to do so. If you do not wish to do so, delete this 37 | // exception statement from your version. 38 | 39 | using System; 40 | 41 | namespace ICSharpCode.SharpZipLib.Checksums 42 | { 43 | /// 44 | /// Bzip2 checksum algorithm 45 | /// 46 | public class StrangeCRC : IChecksum 47 | { 48 | readonly static uint[] crc32Table = { 49 | 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 50 | 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005, 51 | 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, 52 | 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 53 | 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 54 | 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, 55 | 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 56 | 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd, 57 | 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, 58 | 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 59 | 0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81, 60 | 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, 61 | 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 62 | 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95, 63 | 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 64 | 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 65 | 0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae, 66 | 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072, 67 | 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 68 | 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 69 | 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, 70 | 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 71 | 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066, 72 | 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, 73 | 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 74 | 0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692, 75 | 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, 76 | 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 77 | 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, 78 | 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 79 | 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 80 | 0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a, 81 | 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, 82 | 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 83 | 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 84 | 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, 85 | 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 86 | 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b, 87 | 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, 88 | 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 89 | 0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 90 | 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, 91 | 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 92 | 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, 93 | 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 94 | 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 95 | 0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f, 96 | 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3, 97 | 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 98 | 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 99 | 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, 100 | 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 101 | 0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30, 102 | 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, 103 | 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 104 | 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 105 | 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, 106 | 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 107 | 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, 108 | 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 109 | 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 110 | 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c, 111 | 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, 112 | 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 113 | }; 114 | 115 | int globalCrc; 116 | 117 | /// 118 | /// Initialise a default instance of 119 | /// 120 | public StrangeCRC() 121 | { 122 | Reset(); 123 | } 124 | 125 | /// 126 | /// Reset the state of Crc. 127 | /// 128 | public void Reset() 129 | { 130 | globalCrc = -1; 131 | } 132 | 133 | /// 134 | /// Get the current Crc value. 135 | /// 136 | public long Value { 137 | get { 138 | return ~globalCrc; 139 | } 140 | } 141 | 142 | /// 143 | /// Update the Crc value. 144 | /// 145 | /// data update is based on 146 | public void Update(int value) 147 | { 148 | int temp = (globalCrc >> 24) ^ value; 149 | if (temp < 0) { 150 | temp = 256 + temp; 151 | } 152 | globalCrc = unchecked((int)((globalCrc << 8) ^ crc32Table[temp])); 153 | } 154 | 155 | /// 156 | /// Update Crc based on a block of data 157 | /// 158 | /// The buffer containing data to update the crc with. 159 | public void Update(byte[] buffer) 160 | { 161 | if (buffer == null) { 162 | throw new ArgumentNullException("buffer"); 163 | } 164 | 165 | Update(buffer, 0, buffer.Length); 166 | } 167 | 168 | /// 169 | /// Update Crc based on a portion of a block of data 170 | /// 171 | /// block of data 172 | /// index of first byte to use 173 | /// number of bytes to use 174 | public void Update(byte[] buffer, int offset, int count) 175 | { 176 | if (buffer == null) { 177 | throw new ArgumentNullException("buffer"); 178 | } 179 | 180 | if ( offset < 0 ) 181 | { 182 | #if NETCF_1_0 183 | throw new ArgumentOutOfRangeException("offset"); 184 | #else 185 | throw new ArgumentOutOfRangeException("offset", "cannot be less than zero"); 186 | #endif 187 | } 188 | 189 | if ( count < 0 ) 190 | { 191 | #if NETCF_1_0 192 | throw new ArgumentOutOfRangeException("count"); 193 | #else 194 | throw new ArgumentOutOfRangeException("count", "cannot be less than zero"); 195 | #endif 196 | } 197 | 198 | if ( offset + count > buffer.Length ) 199 | { 200 | throw new ArgumentOutOfRangeException("count"); 201 | } 202 | 203 | for (int i = 0; i < count; ++i) { 204 | Update(buffer[offset++]); 205 | } 206 | } 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Core/INameTransform.cs: -------------------------------------------------------------------------------- 1 | // INameTransform.cs 2 | // 3 | // Copyright 2005 John Reilly 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 2 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | // 19 | // Linking this library statically or dynamically with other modules is 20 | // making a combined work based on this library. Thus, the terms and 21 | // conditions of the GNU General Public License cover the whole 22 | // combination. 23 | // 24 | // As a special exception, the copyright holders of this library give you 25 | // permission to link this library with independent modules to produce an 26 | // executable, regardless of the license terms of these independent 27 | // modules, and to copy and distribute the resulting executable under 28 | // terms of your choice, provided that you also meet, for each linked 29 | // independent module, the terms and conditions of the license of that 30 | // module. An independent module is a module which is not derived from 31 | // or based on this library. If you modify this library, you may extend 32 | // this exception to your version of the library, but you are not 33 | // obligated to do so. If you do not wish to do so, delete this 34 | // exception statement from your version. 35 | 36 | namespace ICSharpCode.SharpZipLib.Core 37 | { 38 | /// 39 | /// INameTransform defines how file system names are transformed for use with archives, or vice versa. 40 | /// 41 | public interface INameTransform 42 | { 43 | /// 44 | /// Given a file name determine the transformed value. 45 | /// 46 | /// The name to transform. 47 | /// The transformed file name. 48 | string TransformFile(string name); 49 | 50 | /// 51 | /// Given a directory name determine the transformed value. 52 | /// 53 | /// The name to transform. 54 | /// The transformed directory name 55 | string TransformDirectory(string name); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Core/IScanFilter.cs: -------------------------------------------------------------------------------- 1 | // IScanFilter.cs 2 | // 3 | // Copyright 2006 John Reilly 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 2 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | // 19 | // Linking this library statically or dynamically with other modules is 20 | // making a combined work based on this library. Thus, the terms and 21 | // conditions of the GNU General Public License cover the whole 22 | // combination. 23 | // 24 | // As a special exception, the copyright holders of this library give you 25 | // permission to link this library with independent modules to produce an 26 | // executable, regardless of the license terms of these independent 27 | // modules, and to copy and distribute the resulting executable under 28 | // terms of your choice, provided that you also meet, for each linked 29 | // independent module, the terms and conditions of the license of that 30 | // module. An independent module is a module which is not derived from 31 | // or based on this library. If you modify this library, you may extend 32 | // this exception to your version of the library, but you are not 33 | // obligated to do so. If you do not wish to do so, delete this 34 | // exception statement from your version. 35 | 36 | namespace ICSharpCode.SharpZipLib.Core 37 | { 38 | /// 39 | /// Scanning filters support filtering of names. 40 | /// 41 | public interface IScanFilter 42 | { 43 | /// 44 | /// Test a name to see if it 'matches' the filter. 45 | /// 46 | /// The name to test. 47 | /// Returns true if the name matches the filter, false if it does not match. 48 | bool IsMatch(string name); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Core/StreamUtils.cs: -------------------------------------------------------------------------------- 1 | // StreamUtils.cs 2 | // 3 | // Copyright 2005 John Reilly 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 2 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | // 19 | // Linking this library statically or dynamically with other modules is 20 | // making a combined work based on this library. Thus, the terms and 21 | // conditions of the GNU General Public License cover the whole 22 | // combination. 23 | // 24 | // As a special exception, the copyright holders of this library give you 25 | // permission to link this library with independent modules to produce an 26 | // executable, regardless of the license terms of these independent 27 | // modules, and to copy and distribute the resulting executable under 28 | // terms of your choice, provided that you also meet, for each linked 29 | // independent module, the terms and conditions of the license of that 30 | // module. An independent module is a module which is not derived from 31 | // or based on this library. If you modify this library, you may extend 32 | // this exception to your version of the library, but you are not 33 | // obligated to do so. If you do not wish to do so, delete this 34 | // exception statement from your version. 35 | 36 | using System; 37 | using System.IO; 38 | 39 | namespace ICSharpCode.SharpZipLib.Core 40 | { 41 | /// 42 | /// Provides simple " utilities. 43 | /// 44 | public sealed class StreamUtils 45 | { 46 | /// 47 | /// Read from a ensuring all the required data is read. 48 | /// 49 | /// The stream to read. 50 | /// The buffer to fill. 51 | /// 52 | static public void ReadFully(Stream stream, byte[] buffer) 53 | { 54 | ReadFully(stream, buffer, 0, buffer.Length); 55 | } 56 | 57 | /// 58 | /// Read from a " ensuring all the required data is read. 59 | /// 60 | /// The stream to read data from. 61 | /// The buffer to store data in. 62 | /// The offset at which to begin storing data. 63 | /// The number of bytes of data to store. 64 | /// Required parameter is null 65 | /// and or are invalid. 66 | /// End of stream is encountered before all the data has been read. 67 | static public void ReadFully(Stream stream, byte[] buffer, int offset, int count) 68 | { 69 | if ( stream == null ) { 70 | throw new ArgumentNullException("stream"); 71 | } 72 | 73 | if ( buffer == null ) { 74 | throw new ArgumentNullException("buffer"); 75 | } 76 | 77 | // Offset can equal length when buffer and count are 0. 78 | if ( (offset < 0) || (offset > buffer.Length) ) { 79 | throw new ArgumentOutOfRangeException("offset"); 80 | } 81 | 82 | if ( (count < 0) || (offset + count > buffer.Length) ) { 83 | throw new ArgumentOutOfRangeException("count"); 84 | } 85 | 86 | while ( count > 0 ) { 87 | int readCount = stream.Read(buffer, offset, count); 88 | if ( readCount <= 0 ) { 89 | throw new EndOfStreamException(); 90 | } 91 | offset += readCount; 92 | count -= readCount; 93 | } 94 | } 95 | 96 | /// 97 | /// Copy the contents of one to another. 98 | /// 99 | /// The stream to source data from. 100 | /// The stream to write data to. 101 | /// The buffer to use during copying. 102 | static public void Copy(Stream source, Stream destination, byte[] buffer) 103 | { 104 | if (source == null) { 105 | throw new ArgumentNullException("source"); 106 | } 107 | 108 | if (destination == null) { 109 | throw new ArgumentNullException("destination"); 110 | } 111 | 112 | if (buffer == null) { 113 | throw new ArgumentNullException("buffer"); 114 | } 115 | 116 | // Ensure a reasonable size of buffer is used without being prohibitive. 117 | if (buffer.Length < 128) { 118 | throw new ArgumentException("Buffer is too small", "buffer"); 119 | } 120 | 121 | bool copying = true; 122 | 123 | while (copying) { 124 | int bytesRead = source.Read(buffer, 0, buffer.Length); 125 | if (bytesRead > 0) { 126 | destination.Write(buffer, 0, bytesRead); 127 | } 128 | else { 129 | destination.Flush(); 130 | copying = false; 131 | } 132 | } 133 | } 134 | 135 | /// 136 | /// Copy the contents of one to another. 137 | /// 138 | /// The stream to source data from. 139 | /// The stream to write data to. 140 | /// The buffer to use during copying. 141 | /// The progress handler delegate to use. 142 | /// The minimum between progress updates. 143 | /// The source for this event. 144 | /// The name to use with the event. 145 | /// This form is specialised for use within #Zip to support events during archive operations. 146 | static public void Copy(Stream source, Stream destination, 147 | byte[] buffer, ProgressHandler progressHandler, TimeSpan updateInterval, object sender, string name) 148 | { 149 | Copy(source, destination, buffer, progressHandler, updateInterval, sender, name, -1); 150 | } 151 | 152 | /// 153 | /// Copy the contents of one to another. 154 | /// 155 | /// The stream to source data from. 156 | /// The stream to write data to. 157 | /// The buffer to use during copying. 158 | /// The progress handler delegate to use. 159 | /// The minimum between progress updates. 160 | /// The source for this event. 161 | /// The name to use with the event. 162 | /// A predetermined fixed target value to use with progress updates. 163 | /// If the value is negative the target is calculated by looking at the stream. 164 | /// This form is specialised for use within #Zip to support events during archive operations. 165 | static public void Copy(Stream source, Stream destination, 166 | byte[] buffer, 167 | ProgressHandler progressHandler, TimeSpan updateInterval, 168 | object sender, string name, long fixedTarget) 169 | { 170 | if (source == null) { 171 | throw new ArgumentNullException("source"); 172 | } 173 | 174 | if (destination == null) { 175 | throw new ArgumentNullException("destination"); 176 | } 177 | 178 | if (buffer == null) { 179 | throw new ArgumentNullException("buffer"); 180 | } 181 | 182 | // Ensure a reasonable size of buffer is used without being prohibitive. 183 | if (buffer.Length < 128) { 184 | throw new ArgumentException("Buffer is too small", "buffer"); 185 | } 186 | 187 | if (progressHandler == null) { 188 | throw new ArgumentNullException("progressHandler"); 189 | } 190 | 191 | bool copying = true; 192 | 193 | DateTime marker = DateTime.Now; 194 | long processed = 0; 195 | long target = 0; 196 | 197 | if (fixedTarget >= 0) { 198 | target = fixedTarget; 199 | } 200 | else if (source.CanSeek) { 201 | target = source.Length - source.Position; 202 | } 203 | 204 | // Always fire 0% progress.. 205 | ProgressEventArgs args = new ProgressEventArgs(name, processed, target); 206 | progressHandler(sender, args); 207 | 208 | bool progressFired = true; 209 | 210 | while (copying) { 211 | int bytesRead = source.Read(buffer, 0, buffer.Length); 212 | if (bytesRead > 0) { 213 | processed += bytesRead; 214 | progressFired = false; 215 | destination.Write(buffer, 0, bytesRead); 216 | } 217 | else { 218 | destination.Flush(); 219 | copying = false; 220 | } 221 | 222 | if (DateTime.Now - marker > updateInterval) { 223 | progressFired = true; 224 | marker = DateTime.Now; 225 | args = new ProgressEventArgs(name, processed, target); 226 | progressHandler(sender, args); 227 | 228 | copying = args.ContinueRunning; 229 | } 230 | } 231 | 232 | if (!progressFired) { 233 | args = new ProgressEventArgs(name, processed, target); 234 | progressHandler(sender, args); 235 | } 236 | } 237 | 238 | /// 239 | /// Initialise an instance of 240 | /// 241 | private StreamUtils() 242 | { 243 | // Do nothing. 244 | } 245 | } 246 | } 247 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Core/WindowsPathUtils.cs: -------------------------------------------------------------------------------- 1 | // WindowsPathUtils.cs 2 | // 3 | // Copyright 2007 John Reilly 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 2 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | // 19 | // Linking this library statically or dynamically with other modules is 20 | // making a combined work based on this library. Thus, the terms and 21 | // conditions of the GNU General Public License cover the whole 22 | // combination. 23 | // 24 | // As a special exception, the copyright holders of this library give you 25 | // permission to link this library with independent modules to produce an 26 | // executable, regardless of the license terms of these independent 27 | // modules, and to copy and distribute the resulting executable under 28 | // terms of your choice, provided that you also meet, for each linked 29 | // independent module, the terms and conditions of the license of that 30 | // module. An independent module is a module which is not derived from 31 | // or based on this library. If you modify this library, you may extend 32 | // this exception to your version of the library, but you are not 33 | // obligated to do so. If you do not wish to do so, delete this 34 | // exception statement from your version. 35 | 36 | namespace ICSharpCode.SharpZipLib.Core 37 | { 38 | /// 39 | /// WindowsPathUtils provides simple utilities for handling windows paths. 40 | /// 41 | public abstract class WindowsPathUtils 42 | { 43 | /// 44 | /// Initializes a new instance of the class. 45 | /// 46 | internal WindowsPathUtils() 47 | { 48 | } 49 | 50 | /// 51 | /// Remove any path root present in the path 52 | /// 53 | /// A containing path information. 54 | /// The path with the root removed if it was present; path otherwise. 55 | /// Unlike the class the path isnt otherwise checked for validity. 56 | public static string DropPathRoot(string path) 57 | { 58 | string result = path; 59 | 60 | if ( (path != null) && (path.Length > 0) ) { 61 | if ((path[0] == '\\') || (path[0] == '/')) { 62 | // UNC name ? 63 | if ((path.Length > 1) && ((path[1] == '\\') || (path[1] == '/'))) { 64 | int index = 2; 65 | int elements = 2; 66 | 67 | // Scan for two separate elements \\machine\share\restofpath 68 | while ((index <= path.Length) && 69 | (((path[index] != '\\') && (path[index] != '/')) || (--elements > 0))) { 70 | index++; 71 | } 72 | 73 | index++; 74 | 75 | if (index < path.Length) { 76 | result = path.Substring(index); 77 | } 78 | else { 79 | result = ""; 80 | } 81 | } 82 | } 83 | else if ((path.Length > 1) && (path[1] == ':')) { 84 | int dropCount = 2; 85 | if ((path.Length > 2) && ((path[2] == '\\') || (path[2] == '/'))) { 86 | dropCount = 3; 87 | } 88 | result = result.Remove(0, dropCount); 89 | } 90 | } 91 | return result; 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Encryption/ZipAESStream.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ZipAESStream.cs 3 | // 4 | // Copyright 2009 David Pierson 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program; if not, write to the Free Software 18 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | // 20 | // Linking this library statically or dynamically with other modules is 21 | // making a combined work based on this library. Thus, the terms and 22 | // conditions of the GNU General Public License cover the whole 23 | // combination. 24 | // 25 | // As a special exception, the copyright holders of this library give you 26 | // permission to link this library with independent modules to produce an 27 | // executable, regardless of the license terms of these independent 28 | // modules, and to copy and distribute the resulting executable under 29 | // terms of your choice, provided that you also meet, for each linked 30 | // independent module, the terms and conditions of the license of that 31 | // module. An independent module is a module which is not derived from 32 | // or based on this library. If you modify this library, you may extend 33 | // this exception to your version of the library, but you are not 34 | // obligated to do so. If you do not wish to do so, delete this 35 | // exception statement from your version. 36 | // 37 | 38 | #if !NET_1_1 && !NETCF_2_0 39 | 40 | using System; 41 | using System.IO; 42 | using System.Security.Cryptography; 43 | 44 | namespace ICSharpCode.SharpZipLib.Encryption { 45 | 46 | // Based on information from http://www.winzip.com/aes_info.htm 47 | // and http://www.gladman.me.uk/cryptography_technology/fileencrypt/ 48 | 49 | /// 50 | /// Encrypts and decrypts AES ZIP 51 | /// 52 | internal class ZipAESStream : CryptoStream { 53 | 54 | /// 55 | /// Constructor 56 | /// 57 | /// The stream on which to perform the cryptographic transformation. 58 | /// Instance of ZipAESTransform 59 | /// Read or Write 60 | public ZipAESStream(Stream stream, ZipAESTransform transform, CryptoStreamMode mode) 61 | : base(stream, transform, mode) { 62 | 63 | _stream = stream; 64 | _transform = transform; 65 | _slideBuffer = new byte[1024]; 66 | 67 | _blockAndAuth = CRYPTO_BLOCK_SIZE + AUTH_CODE_LENGTH; 68 | 69 | // mode: 70 | // CryptoStreamMode.Read means we read from "stream" and pass decrypted to our Read() method. 71 | // Write bypasses this stream and uses the Transform directly. 72 | if (mode != CryptoStreamMode.Read) { 73 | throw new Exception("ZipAESStream only for read"); 74 | } 75 | } 76 | 77 | // The final n bytes of the AES stream contain the Auth Code. 78 | private const int AUTH_CODE_LENGTH = 10; 79 | 80 | private Stream _stream; 81 | private ZipAESTransform _transform; 82 | private byte[] _slideBuffer; 83 | private int _slideBufStartPos; 84 | private int _slideBufFreePos; 85 | // Blocksize is always 16 here, even for AES-256 which has transform.InputBlockSize of 32. 86 | private const int CRYPTO_BLOCK_SIZE = 16; 87 | private int _blockAndAuth; 88 | 89 | /// 90 | /// Reads a sequence of bytes from the current CryptoStream into buffer, 91 | /// and advances the position within the stream by the number of bytes read. 92 | /// 93 | public override int Read(byte[] outBuffer, int offset, int count) { 94 | int nBytes = 0; 95 | while (nBytes < count) { 96 | // Calculate buffer quantities vs read-ahead size, and check for sufficient free space 97 | int byteCount = _slideBufFreePos - _slideBufStartPos; 98 | 99 | // Need to handle final block and Auth Code specially, but don't know total data length. 100 | // Maintain a read-ahead equal to the length of (crypto block + Auth Code). 101 | // When that runs out we can detect these final sections. 102 | int lengthToRead = _blockAndAuth - byteCount; 103 | if (_slideBuffer.Length - _slideBufFreePos < lengthToRead) { 104 | // Shift the data to the beginning of the buffer 105 | int iTo = 0; 106 | for (int iFrom = _slideBufStartPos; iFrom < _slideBufFreePos; iFrom++, iTo++) { 107 | _slideBuffer[iTo] = _slideBuffer[iFrom]; 108 | } 109 | _slideBufFreePos -= _slideBufStartPos; // Note the -= 110 | _slideBufStartPos = 0; 111 | } 112 | int obtained = _stream.Read(_slideBuffer, _slideBufFreePos, lengthToRead); 113 | _slideBufFreePos += obtained; 114 | 115 | // Recalculate how much data we now have 116 | byteCount = _slideBufFreePos - _slideBufStartPos; 117 | if (byteCount >= _blockAndAuth) { 118 | // At least a 16 byte block and an auth code remains. 119 | _transform.TransformBlock(_slideBuffer, 120 | _slideBufStartPos, 121 | CRYPTO_BLOCK_SIZE, 122 | outBuffer, 123 | offset); 124 | nBytes += CRYPTO_BLOCK_SIZE; 125 | offset += CRYPTO_BLOCK_SIZE; 126 | _slideBufStartPos += CRYPTO_BLOCK_SIZE; 127 | } else { 128 | // Last round. 129 | if (byteCount > AUTH_CODE_LENGTH) { 130 | // At least one byte of data plus auth code 131 | int finalBlock = byteCount - AUTH_CODE_LENGTH; 132 | _transform.TransformBlock(_slideBuffer, 133 | _slideBufStartPos, 134 | finalBlock, 135 | outBuffer, 136 | offset); 137 | 138 | nBytes += finalBlock; 139 | _slideBufStartPos += finalBlock; 140 | } 141 | else if (byteCount < AUTH_CODE_LENGTH) 142 | throw new Exception("Internal error missed auth code"); // Coding bug 143 | // Final block done. Check Auth code. 144 | byte[] calcAuthCode = _transform.GetAuthCode(); 145 | for (int i = 0; i < AUTH_CODE_LENGTH; i++) { 146 | if (calcAuthCode[i] != _slideBuffer[_slideBufStartPos + i]) { 147 | throw new Exception("AES Authentication Code does not match. This is a super-CRC check on the data in the file after compression and encryption. \r\n" 148 | + "The file may be damaged."); 149 | } 150 | } 151 | 152 | break; // Reached the auth code 153 | } 154 | } 155 | return nBytes; 156 | } 157 | 158 | /// 159 | /// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. 160 | /// 161 | /// An array of bytes. This method copies count bytes from buffer to the current stream. 162 | /// The byte offset in buffer at which to begin copying bytes to the current stream. 163 | /// The number of bytes to be written to the current stream. 164 | public override void Write(byte[] buffer, int offset, int count) { 165 | // ZipAESStream is used for reading but not for writing. Writing uses the ZipAESTransform directly. 166 | throw new NotImplementedException(); 167 | } 168 | } 169 | } 170 | #endif -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Encryption/ZipAESTransform.cs: -------------------------------------------------------------------------------- 1 | // 2 | // ZipAESTransform.cs 3 | // 4 | // Copyright 2009 David Pierson 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program; if not, write to the Free Software 18 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | // 20 | // Linking this library statically or dynamically with other modules is 21 | // making a combined work based on this library. Thus, the terms and 22 | // conditions of the GNU General Public License cover the whole 23 | // combination. 24 | // 25 | // As a special exception, the copyright holders of this library give you 26 | // permission to link this library with independent modules to produce an 27 | // executable, regardless of the license terms of these independent 28 | // modules, and to copy and distribute the resulting executable under 29 | // terms of your choice, provided that you also meet, for each linked 30 | // independent module, the terms and conditions of the license of that 31 | // module. An independent module is a module which is not derived from 32 | // or based on this library. If you modify this library, you may extend 33 | // this exception to your version of the library, but you are not 34 | // obligated to do so. If you do not wish to do so, delete this 35 | // exception statement from your version. 36 | // 37 | 38 | #if !NET_1_1 && !NETCF_2_0 39 | // Framework version 2.0 required for Rfc2898DeriveBytes 40 | 41 | using System; 42 | using System.Security.Cryptography; 43 | 44 | namespace ICSharpCode.SharpZipLib.Encryption { 45 | 46 | /// 47 | /// Transforms stream using AES in CTR mode 48 | /// 49 | internal class ZipAESTransform : ICryptoTransform { 50 | 51 | private const int PWD_VER_LENGTH = 2; 52 | 53 | // WinZip use iteration count of 1000 for PBKDF2 key generation 54 | private const int KEY_ROUNDS = 1000; 55 | 56 | // For 128-bit AES (16 bytes) the encryption is implemented as expected. 57 | // For 256-bit AES (32 bytes) WinZip do full 256 bit AES of the nonce to create the encryption 58 | // block but use only the first 16 bytes of it, and discard the second half. 59 | private const int ENCRYPT_BLOCK = 16; 60 | 61 | private int _blockSize; 62 | private ICryptoTransform _encryptor; 63 | private readonly byte[] _counterNonce; 64 | private byte[] _encryptBuffer; 65 | private int _encrPos; 66 | private byte[] _pwdVerifier; 67 | private HMACSHA1 _hmacsha1; 68 | private bool _finalised; 69 | 70 | private bool _writeMode; 71 | 72 | /// 73 | /// Constructor. 74 | /// 75 | /// Password string 76 | /// Random bytes, length depends on encryption strength. 77 | /// 128 bits = 8 bytes, 192 bits = 12 bytes, 256 bits = 16 bytes. 78 | /// The encryption strength, in bytes eg 16 for 128 bits. 79 | /// True when creating a zip, false when reading. For the AuthCode. 80 | /// 81 | public ZipAESTransform(string key, byte[] saltBytes, int blockSize, bool writeMode) { 82 | 83 | if (blockSize != 16 && blockSize != 32) // 24 valid for AES but not supported by Winzip 84 | throw new Exception("Invalid blocksize " + blockSize + ". Must be 16 or 32."); 85 | if (saltBytes.Length != blockSize / 2) 86 | throw new Exception("Invalid salt len. Must be " + blockSize / 2 + " for blocksize " + blockSize); 87 | // initialise the encryption buffer and buffer pos 88 | _blockSize = blockSize; 89 | _encryptBuffer = new byte[_blockSize]; 90 | _encrPos = ENCRYPT_BLOCK; 91 | 92 | // Performs the equivalent of derive_key in Dr Brian Gladman's pwd2key.c 93 | Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(key, saltBytes, KEY_ROUNDS); 94 | RijndaelManaged rm = new RijndaelManaged(); 95 | rm.Mode = CipherMode.ECB; // No feedback from cipher for CTR mode 96 | _counterNonce = new byte[_blockSize]; 97 | byte[] byteKey1 = pdb.GetBytes(_blockSize); 98 | byte[] byteKey2 = pdb.GetBytes(_blockSize); 99 | _encryptor = rm.CreateEncryptor(byteKey1, byteKey2); 100 | _pwdVerifier = pdb.GetBytes(PWD_VER_LENGTH); 101 | // 102 | _hmacsha1 = new HMACSHA1(byteKey2); 103 | _writeMode = writeMode; 104 | } 105 | 106 | /// 107 | /// Implement the ICryptoTransform method. 108 | /// 109 | public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) { 110 | 111 | // Pass the data stream to the hash algorithm for generating the Auth Code. 112 | // This does not change the inputBuffer. Do this before decryption for read mode. 113 | if (!_writeMode) { 114 | _hmacsha1.TransformBlock(inputBuffer, inputOffset, inputCount, inputBuffer, inputOffset); 115 | } 116 | // Encrypt with AES in CTR mode. Regards to Dr Brian Gladman for this. 117 | int ix = 0; 118 | while (ix < inputCount) { 119 | if (_encrPos == ENCRYPT_BLOCK) { 120 | /* increment encryption nonce */ 121 | int j = 0; 122 | while (++_counterNonce[j] == 0) { 123 | ++j; 124 | } 125 | /* encrypt the nonce to form next xor buffer */ 126 | _encryptor.TransformBlock(_counterNonce, 0, _blockSize, _encryptBuffer, 0); 127 | _encrPos = 0; 128 | } 129 | outputBuffer[ix + outputOffset] = (byte)(inputBuffer[ix + inputOffset] ^ _encryptBuffer[_encrPos++]); 130 | // 131 | ix++; 132 | } 133 | if (_writeMode) { 134 | // This does not change the buffer. 135 | _hmacsha1.TransformBlock(outputBuffer, outputOffset, inputCount, outputBuffer, outputOffset); 136 | } 137 | return inputCount; 138 | } 139 | 140 | /// 141 | /// Returns the 2 byte password verifier 142 | /// 143 | public byte[] PwdVerifier { 144 | get { 145 | return _pwdVerifier; 146 | } 147 | } 148 | 149 | /// 150 | /// Returns the 10 byte AUTH CODE to be checked or appended immediately following the AES data stream. 151 | /// 152 | public byte[] GetAuthCode() { 153 | // We usually don't get advance notice of final block. Hash requres a TransformFinal. 154 | if (!_finalised) { 155 | byte[] dummy = new byte[0]; 156 | _hmacsha1.TransformFinalBlock(dummy, 0, 0); 157 | _finalised = true; 158 | } 159 | return _hmacsha1.Hash; 160 | } 161 | 162 | #region ICryptoTransform Members 163 | 164 | /// 165 | /// Not implemented. 166 | /// 167 | public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount) { 168 | 169 | throw new NotImplementedException("ZipAESTransform.TransformFinalBlock"); 170 | } 171 | 172 | /// 173 | /// Gets the size of the input data blocks in bytes. 174 | /// 175 | public int InputBlockSize { 176 | get { 177 | return _blockSize; 178 | } 179 | } 180 | 181 | /// 182 | /// Gets the size of the output data blocks in bytes. 183 | /// 184 | public int OutputBlockSize { 185 | get { 186 | return _blockSize; 187 | } 188 | } 189 | 190 | /// 191 | /// Gets a value indicating whether multiple blocks can be transformed. 192 | /// 193 | public bool CanTransformMultipleBlocks { 194 | get { 195 | return true; 196 | } 197 | } 198 | 199 | /// 200 | /// Gets a value indicating whether the current transform can be reused. 201 | /// 202 | public bool CanReuseTransform { 203 | get { 204 | return true; 205 | } 206 | } 207 | 208 | /// 209 | /// Cleanup internal state. 210 | /// 211 | public void Dispose() { 212 | _encryptor.Dispose(); 213 | } 214 | 215 | #endregion 216 | 217 | } 218 | } 219 | #endif -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/GZip/GZIPConstants.cs: -------------------------------------------------------------------------------- 1 | // GZipConstants.cs 2 | // 3 | // Copyright (C) 2001 Mike Krueger 4 | // 5 | // This file was translated from java, it was part of the GNU Classpath 6 | // Copyright (C) 2001 Free Software Foundation, Inc. 7 | // 8 | // This program is free software; you can redistribute it and/or 9 | // modify it under the terms of the GNU General Public License 10 | // as published by the Free Software Foundation; either version 2 11 | // of the License, or (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program; if not, write to the Free Software 20 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | // 22 | // Linking this library statically or dynamically with other modules is 23 | // making a combined work based on this library. Thus, the terms and 24 | // conditions of the GNU General Public License cover the whole 25 | // combination. 26 | // 27 | // As a special exception, the copyright holders of this library give you 28 | // permission to link this library with independent modules to produce an 29 | // executable, regardless of the license terms of these independent 30 | // modules, and to copy and distribute the resulting executable under 31 | // terms of your choice, provided that you also meet, for each linked 32 | // independent module, the terms and conditions of the license of that 33 | // module. An independent module is a module which is not derived from 34 | // or based on this library. If you modify this library, you may extend 35 | // this exception to your version of the library, but you are not 36 | // obligated to do so. If you do not wish to do so, delete this 37 | // exception statement from your version. 38 | 39 | namespace ICSharpCode.SharpZipLib.GZip 40 | { 41 | 42 | /// 43 | /// This class contains constants used for gzip. 44 | /// 45 | sealed public class GZipConstants 46 | { 47 | /// 48 | /// Magic number found at start of GZIP header 49 | /// 50 | public const int GZIP_MAGIC = 0x1F8B; 51 | 52 | /* The flag byte is divided into individual bits as follows: 53 | 54 | bit 0 FTEXT 55 | bit 1 FHCRC 56 | bit 2 FEXTRA 57 | bit 3 FNAME 58 | bit 4 FCOMMENT 59 | bit 5 reserved 60 | bit 6 reserved 61 | bit 7 reserved 62 | */ 63 | 64 | /// 65 | /// Flag bit mask for text 66 | /// 67 | public const int FTEXT = 0x1; 68 | 69 | /// 70 | /// Flag bitmask for Crc 71 | /// 72 | public const int FHCRC = 0x2; 73 | 74 | /// 75 | /// Flag bit mask for extra 76 | /// 77 | public const int FEXTRA = 0x4; 78 | 79 | /// 80 | /// flag bitmask for name 81 | /// 82 | public const int FNAME = 0x8; 83 | 84 | /// 85 | /// flag bit mask indicating comment is present 86 | /// 87 | public const int FCOMMENT = 0x10; 88 | 89 | /// 90 | /// Initialise default instance. 91 | /// 92 | /// Constructor is private to prevent instances being created. 93 | GZipConstants() 94 | { 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/GZip/GZipException.cs: -------------------------------------------------------------------------------- 1 | // GZipException.cs 2 | // 3 | // Copyright 2004 John Reilly 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 2 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | // 19 | // Linking this library statically or dynamically with other modules is 20 | // making a combined work based on this library. Thus, the terms and 21 | // conditions of the GNU General Public License cover the whole 22 | // combination. 23 | // 24 | // As a special exception, the copyright holders of this library give you 25 | // permission to link this library with independent modules to produce an 26 | // executable, regardless of the license terms of these independent 27 | // modules, and to copy and distribute the resulting executable under 28 | // terms of your choice, provided that you also meet, for each linked 29 | // independent module, the terms and conditions of the license of that 30 | // module. An independent module is a module which is not derived from 31 | // or based on this library. If you modify this library, you may extend 32 | // this exception to your version of the library, but you are not 33 | // obligated to do so. If you do not wish to do so, delete this 34 | // exception statement from your version. 35 | 36 | using System; 37 | 38 | #if !NETCF_1_0 && !NETCF_2_0 39 | using System.Runtime.Serialization; 40 | #endif 41 | 42 | namespace ICSharpCode.SharpZipLib.GZip 43 | { 44 | /// 45 | /// GZipException represents a Gzip specific exception 46 | /// 47 | #if !NETCF_1_0 && !NETCF_2_0 48 | [Serializable] 49 | #endif 50 | public class GZipException : SharpZipBaseException 51 | { 52 | #if !NETCF_1_0 && !NETCF_2_0 53 | /// 54 | /// Deserialization constructor 55 | /// 56 | /// for this constructor 57 | /// for this constructor 58 | protected GZipException(SerializationInfo info, StreamingContext context) 59 | : base(info, context) 60 | 61 | { 62 | } 63 | #endif 64 | 65 | /// 66 | /// Initialise a new instance of GZipException 67 | /// 68 | public GZipException() 69 | { 70 | } 71 | 72 | /// 73 | /// Initialise a new instance of GZipException with its message string. 74 | /// 75 | /// A that describes the error. 76 | public GZipException(string message) 77 | : base(message) 78 | { 79 | } 80 | 81 | /// 82 | /// Initialise a new instance of . 83 | /// 84 | /// A that describes the error. 85 | /// The that caused this exception. 86 | public GZipException(string message, Exception innerException) 87 | : base (message, innerException) 88 | { 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/GZip/GzipOutputStream.cs: -------------------------------------------------------------------------------- 1 | // GZipOutputStream.cs 2 | // 3 | // Copyright (C) 2001 Mike Krueger 4 | // 5 | // This file was translated from java, it was part of the GNU Classpath 6 | // Copyright (C) 2001 Free Software Foundation, Inc. 7 | // 8 | // This program is free software; you can redistribute it and/or 9 | // modify it under the terms of the GNU General Public License 10 | // as published by the Free Software Foundation; either version 2 11 | // of the License, or (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program; if not, write to the Free Software 20 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | // 22 | // Linking this library statically or dynamically with other modules is 23 | // making a combined work based on this library. Thus, the terms and 24 | // conditions of the GNU General Public License cover the whole 25 | // combination. 26 | // 27 | // As a special exception, the copyright holders of this library give you 28 | // permission to link this library with independent modules to produce an 29 | // executable, regardless of the license terms of these independent 30 | // modules, and to copy and distribute the resulting executable under 31 | // terms of your choice, provided that you also meet, for each linked 32 | // independent module, the terms and conditions of the license of that 33 | // module. An independent module is a module which is not derived from 34 | // or based on this library. If you modify this library, you may extend 35 | // this exception to your version of the library, but you are not 36 | // obligated to do so. If you do not wish to do so, delete this 37 | // exception statement from your version. 38 | 39 | using System; 40 | using System.IO; 41 | 42 | using ICSharpCode.SharpZipLib.Checksums; 43 | using ICSharpCode.SharpZipLib.Zip.Compression; 44 | using ICSharpCode.SharpZipLib.Zip.Compression.Streams; 45 | 46 | namespace ICSharpCode.SharpZipLib.GZip 47 | { 48 | 49 | /// 50 | /// This filter stream is used to compress a stream into a "GZIP" stream. 51 | /// The "GZIP" format is described in RFC 1952. 52 | /// 53 | /// author of the original java version : John Leuner 54 | /// 55 | /// This sample shows how to gzip a file 56 | /// 57 | /// using System; 58 | /// using System.IO; 59 | /// 60 | /// using ICSharpCode.SharpZipLib.GZip; 61 | /// using ICSharpCode.SharpZipLib.Core; 62 | /// 63 | /// class MainClass 64 | /// { 65 | /// public static void Main(string[] args) 66 | /// { 67 | /// using (Stream s = new GZipOutputStream(File.Create(args[0] + ".gz"))) 68 | /// using (FileStream fs = File.OpenRead(args[0])) { 69 | /// byte[] writeData = new byte[4096]; 70 | /// Streamutils.Copy(s, fs, writeData); 71 | /// } 72 | /// } 73 | /// } 74 | /// } 75 | /// 76 | /// 77 | public class GZipOutputStream : DeflaterOutputStream 78 | { 79 | enum OutputState 80 | { 81 | Header, 82 | Footer, 83 | Finished, 84 | Closed, 85 | }; 86 | 87 | #region Instance Fields 88 | /// 89 | /// CRC-32 value for uncompressed data 90 | /// 91 | protected Crc32 crc = new Crc32(); 92 | OutputState state_ = OutputState.Header; 93 | #endregion 94 | 95 | #region Constructors 96 | /// 97 | /// Creates a GzipOutputStream with the default buffer size 98 | /// 99 | /// 100 | /// The stream to read data (to be compressed) from 101 | /// 102 | public GZipOutputStream(Stream baseOutputStream) 103 | : this(baseOutputStream, 4096) 104 | { 105 | } 106 | 107 | /// 108 | /// Creates a GZipOutputStream with the specified buffer size 109 | /// 110 | /// 111 | /// The stream to read data (to be compressed) from 112 | /// 113 | /// 114 | /// Size of the buffer to use 115 | /// 116 | public GZipOutputStream(Stream baseOutputStream, int size) : base(baseOutputStream, new Deflater(Deflater.DEFAULT_COMPRESSION, true), size) 117 | { 118 | } 119 | #endregion 120 | 121 | #region Public API 122 | /// 123 | /// Sets the active compression level (1-9). The new level will be activated 124 | /// immediately. 125 | /// 126 | /// The compression level to set. 127 | /// 128 | /// Level specified is not supported. 129 | /// 130 | /// 131 | public void SetLevel(int level) 132 | { 133 | if (level < Deflater.BEST_SPEED) { 134 | throw new ArgumentOutOfRangeException("level"); 135 | } 136 | deflater_.SetLevel(level); 137 | } 138 | 139 | /// 140 | /// Get the current compression level. 141 | /// 142 | /// The current compression level. 143 | public int GetLevel() 144 | { 145 | return deflater_.GetLevel(); 146 | } 147 | #endregion 148 | 149 | #region Stream overrides 150 | /// 151 | /// Write given buffer to output updating crc 152 | /// 153 | /// Buffer to write 154 | /// Offset of first byte in buf to write 155 | /// Number of bytes to write 156 | public override void Write(byte[] buffer, int offset, int count) 157 | { 158 | if ( state_ == OutputState.Header ) { 159 | WriteHeader(); 160 | } 161 | 162 | if( state_!=OutputState.Footer ) 163 | { 164 | throw new InvalidOperationException("Write not permitted in current state"); 165 | } 166 | 167 | crc.Update(buffer, offset, count); 168 | base.Write(buffer, offset, count); 169 | } 170 | 171 | /// 172 | /// Writes remaining compressed output data to the output stream 173 | /// and closes it. 174 | /// 175 | public override void Close() 176 | { 177 | try { 178 | Finish(); 179 | } 180 | finally { 181 | if ( state_ != OutputState.Closed ) { 182 | state_ = OutputState.Closed; 183 | if( IsStreamOwner ) { 184 | baseOutputStream_.Close(); 185 | } 186 | } 187 | } 188 | } 189 | #endregion 190 | 191 | #region DeflaterOutputStream overrides 192 | /// 193 | /// Finish compression and write any footer information required to stream 194 | /// 195 | public override void Finish() 196 | { 197 | // If no data has been written a header should be added. 198 | if ( state_ == OutputState.Header ) { 199 | WriteHeader(); 200 | } 201 | 202 | if( state_ == OutputState.Footer) 203 | { 204 | state_=OutputState.Finished; 205 | base.Finish(); 206 | 207 | uint totalin=(uint)(deflater_.TotalIn&0xffffffff); 208 | uint crcval=(uint)(crc.Value&0xffffffff); 209 | 210 | byte[] gzipFooter; 211 | 212 | unchecked 213 | { 214 | gzipFooter=new byte[] { 215 | (byte) crcval, (byte) (crcval >> 8), 216 | (byte) (crcval >> 16), (byte) (crcval >> 24), 217 | 218 | (byte) totalin, (byte) (totalin >> 8), 219 | (byte) (totalin >> 16), (byte) (totalin >> 24) 220 | }; 221 | } 222 | 223 | baseOutputStream_.Write(gzipFooter, 0, gzipFooter.Length); 224 | } 225 | } 226 | #endregion 227 | 228 | #region Support Routines 229 | void WriteHeader() 230 | { 231 | if ( state_ == OutputState.Header ) 232 | { 233 | state_=OutputState.Footer; 234 | 235 | int mod_time = (int)((DateTime.Now.Ticks - new DateTime(1970, 1, 1).Ticks) / 10000000L); // Ticks give back 100ns intervals 236 | byte[] gzipHeader = { 237 | // The two magic bytes 238 | (byte) (GZipConstants.GZIP_MAGIC >> 8), (byte) (GZipConstants.GZIP_MAGIC & 0xff), 239 | 240 | // The compression type 241 | (byte) Deflater.DEFLATED, 242 | 243 | // The flags (not set) 244 | 0, 245 | 246 | // The modification time 247 | (byte) mod_time, (byte) (mod_time >> 8), 248 | (byte) (mod_time >> 16), (byte) (mod_time >> 24), 249 | 250 | // The extra flags 251 | 0, 252 | 253 | // The OS type (unknown) 254 | (byte) 255 255 | }; 256 | baseOutputStream_.Write(gzipHeader, 0, gzipHeader.Length); 257 | } 258 | } 259 | #endregion 260 | } 261 | } 262 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/SharpZipBaseException.cs: -------------------------------------------------------------------------------- 1 | // SharpZipBaseException.cs 2 | // 3 | // Copyright 2004 John Reilly 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 2 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | // 19 | // Linking this library statically or dynamically with other modules is 20 | // making a combined work based on this library. Thus, the terms and 21 | // conditions of the GNU General Public License cover the whole 22 | // combination. 23 | // 24 | // As a special exception, the copyright holders of this library give you 25 | // permission to link this library with independent modules to produce an 26 | // executable, regardless of the license terms of these independent 27 | // modules, and to copy and distribute the resulting executable under 28 | // terms of your choice, provided that you also meet, for each linked 29 | // independent module, the terms and conditions of the license of that 30 | // module. An independent module is a module which is not derived from 31 | // or based on this library. If you modify this library, you may extend 32 | // this exception to your version of the library, but you are not 33 | // obligated to do so. If you do not wish to do so, delete this 34 | // exception statement from your version. 35 | 36 | using System; 37 | 38 | #if !NETCF_1_0 && !NETCF_2_0 39 | using System.Runtime.Serialization; 40 | #endif 41 | 42 | namespace ICSharpCode.SharpZipLib 43 | { 44 | /// 45 | /// SharpZipBaseException is the base exception class for the SharpZipLibrary. 46 | /// All library exceptions are derived from this. 47 | /// 48 | /// NOTE: Not all exceptions thrown will be derived from this class. 49 | /// A variety of other exceptions are possible for example 50 | #if !NETCF_1_0 && !NETCF_2_0 51 | [Serializable] 52 | #endif 53 | public class SharpZipBaseException : ApplicationException 54 | { 55 | #if !NETCF_1_0 && !NETCF_2_0 56 | /// 57 | /// Deserialization constructor 58 | /// 59 | /// for this constructor 60 | /// for this constructor 61 | protected SharpZipBaseException(SerializationInfo info, StreamingContext context ) 62 | : base( info, context ) 63 | { 64 | } 65 | #endif 66 | 67 | /// 68 | /// Initializes a new instance of the SharpZipBaseException class. 69 | /// 70 | public SharpZipBaseException() 71 | { 72 | } 73 | 74 | /// 75 | /// Initializes a new instance of the SharpZipBaseException class with a specified error message. 76 | /// 77 | /// A message describing the exception. 78 | public SharpZipBaseException(string message) 79 | : base(message) 80 | { 81 | } 82 | 83 | /// 84 | /// Initializes a new instance of the SharpZipBaseException class with a specified 85 | /// error message and a reference to the inner exception that is the cause of this exception. 86 | /// 87 | /// A message describing the exception. 88 | /// The inner exception 89 | public SharpZipBaseException(string message, Exception innerException) 90 | : base(message, innerException) 91 | { 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Tar/InvalidHeaderException.cs: -------------------------------------------------------------------------------- 1 | // InvalidHeaderException.cs 2 | // 3 | // Copyright (C) 2001 Mike Krueger 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 2 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | // 19 | // Linking this library statically or dynamically with other modules is 20 | // making a combined work based on this library. Thus, the terms and 21 | // conditions of the GNU General Public License cover the whole 22 | // combination. 23 | // 24 | // As a special exception, the copyright holders of this library give you 25 | // permission to link this library with independent modules to produce an 26 | // executable, regardless of the license terms of these independent 27 | // modules, and to copy and distribute the resulting executable under 28 | // terms of your choice, provided that you also meet, for each linked 29 | // independent module, the terms and conditions of the license of that 30 | // module. An independent module is a module which is not derived from 31 | // or based on this library. If you modify this library, you may extend 32 | // this exception to your version of the library, but you are not 33 | // obligated to do so. If you do not wish to do so, delete this 34 | // exception statement from your version. 35 | 36 | using System; 37 | 38 | #if !NETCF_1_0 && !NETCF_2_0 39 | using System.Runtime.Serialization; 40 | #endif 41 | 42 | namespace ICSharpCode.SharpZipLib.Tar { 43 | 44 | /// 45 | /// This exception is used to indicate that there is a problem 46 | /// with a TAR archive header. 47 | /// 48 | #if !NETCF_1_0 && !NETCF_2_0 49 | [Serializable] 50 | #endif 51 | public class InvalidHeaderException : TarException 52 | { 53 | 54 | #if !NETCF_1_0 && !NETCF_2_0 55 | /// 56 | /// Deserialization constructor 57 | /// 58 | /// for this constructor 59 | /// for this constructor 60 | protected InvalidHeaderException(SerializationInfo information, StreamingContext context) 61 | : base(information, context) 62 | 63 | { 64 | } 65 | #endif 66 | 67 | /// 68 | /// Initialise a new instance of the InvalidHeaderException class. 69 | /// 70 | public InvalidHeaderException() 71 | { 72 | } 73 | 74 | /// 75 | /// Initialises a new instance of the InvalidHeaderException class with a specified message. 76 | /// 77 | /// Message describing the exception cause. 78 | public InvalidHeaderException(string message) 79 | : base(message) 80 | { 81 | } 82 | 83 | /// 84 | /// Initialise a new instance of InvalidHeaderException 85 | /// 86 | /// Message describing the problem. 87 | /// The exception that is the cause of the current exception. 88 | public InvalidHeaderException(string message, Exception exception) 89 | : base(message, exception) 90 | { 91 | } 92 | } 93 | } 94 | 95 | /* The original Java file had this header: 96 | ** Authored by Timothy Gerard Endres 97 | ** 98 | ** 99 | ** This work has been placed into the public domain. 100 | ** You may use this work in any way and for any purpose you wish. 101 | ** 102 | ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, 103 | ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR 104 | ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY 105 | ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR 106 | ** REDISTRIBUTION OF THIS SOFTWARE. 107 | ** 108 | */ 109 | 110 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Tar/TarException.cs: -------------------------------------------------------------------------------- 1 | // TarException.cs 2 | // 3 | // Copyright 2004 John Reilly 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 2 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | // 19 | // Linking this library statically or dynamically with other modules is 20 | // making a combined work based on this library. Thus, the terms and 21 | // conditions of the GNU General Public License cover the whole 22 | // combination. 23 | // 24 | // As a special exception, the copyright holders of this library give you 25 | // permission to link this library with independent modules to produce an 26 | // executable, regardless of the license terms of these independent 27 | // modules, and to copy and distribute the resulting executable under 28 | // terms of your choice, provided that you also meet, for each linked 29 | // independent module, the terms and conditions of the license of that 30 | // module. An independent module is a module which is not derived from 31 | // or based on this library. If you modify this library, you may extend 32 | // this exception to your version of the library, but you are not 33 | // obligated to do so. If you do not wish to do so, delete this 34 | // exception statement from your version. 35 | 36 | using System; 37 | 38 | #if !NETCF_1_0 && !NETCF_2_0 39 | using System.Runtime.Serialization; 40 | #endif 41 | 42 | namespace ICSharpCode.SharpZipLib.Tar { 43 | 44 | /// 45 | /// TarExceptions are used for exceptions specific to tar classes and code. 46 | /// 47 | #if !NETCF_1_0 && !NETCF_2_0 48 | [Serializable] 49 | #endif 50 | public class TarException : SharpZipBaseException 51 | { 52 | #if !NETCF_1_0 && !NETCF_2_0 53 | /// 54 | /// Deserialization constructor 55 | /// 56 | /// for this constructor 57 | /// for this constructor 58 | protected TarException(SerializationInfo info, StreamingContext context) 59 | : base(info, context) 60 | 61 | { 62 | } 63 | #endif 64 | 65 | /// 66 | /// Initialises a new instance of the TarException class. 67 | /// 68 | public TarException() 69 | { 70 | } 71 | 72 | /// 73 | /// Initialises a new instance of the TarException class with a specified message. 74 | /// 75 | /// The message that describes the error. 76 | public TarException(string message) 77 | : base(message) 78 | { 79 | } 80 | 81 | /// 82 | /// 83 | /// 84 | /// A message describing the error. 85 | /// The exception that is the cause of the current exception. 86 | public TarException(string message, Exception exception) 87 | : base(message, exception) 88 | { 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Zip/Compression/DeflaterConstants.cs: -------------------------------------------------------------------------------- 1 | // DeflaterConstants.cs 2 | // 3 | // Copyright (C) 2001 Mike Krueger 4 | // Copyright (C) 2004 John Reilly 5 | // 6 | // This file was translated from java, it was part of the GNU Classpath 7 | // Copyright (C) 2001 Free Software Foundation, Inc. 8 | // 9 | // This program is free software; you can redistribute it and/or 10 | // modify it under the terms of the GNU General Public License 11 | // as published by the Free Software Foundation; either version 2 12 | // of the License, or (at your option) any later version. 13 | // 14 | // This program is distributed in the hope that it will be useful, 15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | // GNU General Public License for more details. 18 | // 19 | // You should have received a copy of the GNU General Public License 20 | // along with this program; if not, write to the Free Software 21 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | // 23 | // Linking this library statically or dynamically with other modules is 24 | // making a combined work based on this library. Thus, the terms and 25 | // conditions of the GNU General Public License cover the whole 26 | // combination. 27 | // 28 | // As a special exception, the copyright holders of this library give you 29 | // permission to link this library with independent modules to produce an 30 | // executable, regardless of the license terms of these independent 31 | // modules, and to copy and distribute the resulting executable under 32 | // terms of your choice, provided that you also meet, for each linked 33 | // independent module, the terms and conditions of the license of that 34 | // module. An independent module is a module which is not derived from 35 | // or based on this library. If you modify this library, you may extend 36 | // this exception to your version of the library, but you are not 37 | // obligated to do so. If you do not wish to do so, delete this 38 | // exception statement from your version. 39 | 40 | using System; 41 | 42 | namespace ICSharpCode.SharpZipLib.Zip.Compression 43 | { 44 | 45 | /// 46 | /// This class contains constants used for deflation. 47 | /// 48 | public class DeflaterConstants 49 | { 50 | /// 51 | /// Set to true to enable debugging 52 | /// 53 | public const bool DEBUGGING = false; 54 | 55 | /// 56 | /// Written to Zip file to identify a stored block 57 | /// 58 | public const int STORED_BLOCK = 0; 59 | 60 | /// 61 | /// Identifies static tree in Zip file 62 | /// 63 | public const int STATIC_TREES = 1; 64 | 65 | /// 66 | /// Identifies dynamic tree in Zip file 67 | /// 68 | public const int DYN_TREES = 2; 69 | 70 | /// 71 | /// Header flag indicating a preset dictionary for deflation 72 | /// 73 | public const int PRESET_DICT = 0x20; 74 | 75 | /// 76 | /// Sets internal buffer sizes for Huffman encoding 77 | /// 78 | public const int DEFAULT_MEM_LEVEL = 8; 79 | 80 | /// 81 | /// Internal compression engine constant 82 | /// 83 | public const int MAX_MATCH = 258; 84 | 85 | /// 86 | /// Internal compression engine constant 87 | /// 88 | public const int MIN_MATCH = 3; 89 | 90 | /// 91 | /// Internal compression engine constant 92 | /// 93 | public const int MAX_WBITS = 15; 94 | 95 | /// 96 | /// Internal compression engine constant 97 | /// 98 | public const int WSIZE = 1 << MAX_WBITS; 99 | 100 | /// 101 | /// Internal compression engine constant 102 | /// 103 | public const int WMASK = WSIZE - 1; 104 | 105 | /// 106 | /// Internal compression engine constant 107 | /// 108 | public const int HASH_BITS = DEFAULT_MEM_LEVEL + 7; 109 | 110 | /// 111 | /// Internal compression engine constant 112 | /// 113 | public const int HASH_SIZE = 1 << HASH_BITS; 114 | 115 | /// 116 | /// Internal compression engine constant 117 | /// 118 | public const int HASH_MASK = HASH_SIZE - 1; 119 | 120 | /// 121 | /// Internal compression engine constant 122 | /// 123 | public const int HASH_SHIFT = (HASH_BITS + MIN_MATCH - 1) / MIN_MATCH; 124 | 125 | /// 126 | /// Internal compression engine constant 127 | /// 128 | public const int MIN_LOOKAHEAD = MAX_MATCH + MIN_MATCH + 1; 129 | 130 | /// 131 | /// Internal compression engine constant 132 | /// 133 | public const int MAX_DIST = WSIZE - MIN_LOOKAHEAD; 134 | 135 | /// 136 | /// Internal compression engine constant 137 | /// 138 | public const int PENDING_BUF_SIZE = 1 << (DEFAULT_MEM_LEVEL + 8); 139 | 140 | /// 141 | /// Internal compression engine constant 142 | /// 143 | public static int MAX_BLOCK_SIZE = Math.Min(65535, PENDING_BUF_SIZE - 5); 144 | 145 | /// 146 | /// Internal compression engine constant 147 | /// 148 | public const int DEFLATE_STORED = 0; 149 | 150 | /// 151 | /// Internal compression engine constant 152 | /// 153 | public const int DEFLATE_FAST = 1; 154 | 155 | /// 156 | /// Internal compression engine constant 157 | /// 158 | public const int DEFLATE_SLOW = 2; 159 | 160 | /// 161 | /// Internal compression engine constant 162 | /// 163 | public static int[] GOOD_LENGTH = { 0, 4, 4, 4, 4, 8, 8, 8, 32, 32 }; 164 | 165 | /// 166 | /// Internal compression engine constant 167 | /// 168 | public static int[] MAX_LAZY = { 0, 4, 5, 6, 4, 16, 16, 32, 128, 258 }; 169 | 170 | /// 171 | /// Internal compression engine constant 172 | /// 173 | public static int[] NICE_LENGTH = { 0, 8, 16, 32, 16, 32, 128, 128, 258, 258 }; 174 | 175 | /// 176 | /// Internal compression engine constant 177 | /// 178 | public static int[] MAX_CHAIN = { 0, 4, 8, 32, 16, 32, 128, 256, 1024, 4096 }; 179 | 180 | /// 181 | /// Internal compression engine constant 182 | /// 183 | public static int[] COMPR_FUNC = { 0, 1, 1, 1, 1, 2, 2, 2, 2, 2 }; 184 | 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Zip/Compression/DeflaterPending.cs: -------------------------------------------------------------------------------- 1 | // DeflaterPending.cs 2 | // 3 | // Copyright (C) 2001 Mike Krueger 4 | // Copyright (C) 2004 John Reilly 5 | // 6 | // This file was translated from java, it was part of the GNU Classpath 7 | // Copyright (C) 2001 Free Software Foundation, Inc. 8 | // 9 | // This program is free software; you can redistribute it and/or 10 | // modify it under the terms of the GNU General Public License 11 | // as published by the Free Software Foundation; either version 2 12 | // of the License, or (at your option) any later version. 13 | // 14 | // This program is distributed in the hope that it will be useful, 15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | // GNU General Public License for more details. 18 | // 19 | // You should have received a copy of the GNU General Public License 20 | // along with this program; if not, write to the Free Software 21 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | // 23 | // Linking this library statically or dynamically with other modules is 24 | // making a combined work based on this library. Thus, the terms and 25 | // conditions of the GNU General Public License cover the whole 26 | // combination. 27 | // 28 | // As a special exception, the copyright holders of this library give you 29 | // permission to link this library with independent modules to produce an 30 | // executable, regardless of the license terms of these independent 31 | // modules, and to copy and distribute the resulting executable under 32 | // terms of your choice, provided that you also meet, for each linked 33 | // independent module, the terms and conditions of the license of that 34 | // module. An independent module is a module which is not derived from 35 | // or based on this library. If you modify this library, you may extend 36 | // this exception to your version of the library, but you are not 37 | // obligated to do so. If you do not wish to do so, delete this 38 | // exception statement from your version. 39 | 40 | namespace ICSharpCode.SharpZipLib.Zip.Compression 41 | { 42 | 43 | /// 44 | /// This class stores the pending output of the Deflater. 45 | /// 46 | /// author of the original java version : Jochen Hoenicke 47 | /// 48 | public class DeflaterPending : PendingBuffer 49 | { 50 | /// 51 | /// Construct instance with default buffer size 52 | /// 53 | public DeflaterPending() : base(DeflaterConstants.PENDING_BUF_SIZE) 54 | { 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Zip/Compression/InflaterDynHeader.cs: -------------------------------------------------------------------------------- 1 | // InflaterDynHeader.cs 2 | // Copyright (C) 2001 Mike Krueger 3 | // 4 | // This file was translated from java, it was part of the GNU Classpath 5 | // Copyright (C) 2001 Free Software Foundation, Inc. 6 | // 7 | // This program is free software; you can redistribute it and/or 8 | // modify it under the terms of the GNU General Public License 9 | // as published by the Free Software Foundation; either version 2 10 | // of the License, or (at your option) any later version. 11 | // 12 | // This program is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | // GNU General Public License for more details. 16 | // 17 | // You should have received a copy of the GNU General Public License 18 | // along with this program; if not, write to the Free Software 19 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | // 21 | // Linking this library statically or dynamically with other modules is 22 | // making a combined work based on this library. Thus, the terms and 23 | // conditions of the GNU General Public License cover the whole 24 | // combination. 25 | // 26 | // As a special exception, the copyright holders of this library give you 27 | // permission to link this library with independent modules to produce an 28 | // executable, regardless of the license terms of these independent 29 | // modules, and to copy and distribute the resulting executable under 30 | // terms of your choice, provided that you also meet, for each linked 31 | // independent module, the terms and conditions of the license of that 32 | // module. An independent module is a module which is not derived from 33 | // or based on this library. If you modify this library, you may extend 34 | // this exception to your version of the library, but you are not 35 | // obligated to do so. If you do not wish to do so, delete this 36 | // exception statement from your version. 37 | 38 | using System; 39 | 40 | using ICSharpCode.SharpZipLib.Zip.Compression.Streams; 41 | 42 | namespace ICSharpCode.SharpZipLib.Zip.Compression 43 | { 44 | 45 | class InflaterDynHeader 46 | { 47 | #region Constants 48 | const int LNUM = 0; 49 | const int DNUM = 1; 50 | const int BLNUM = 2; 51 | const int BLLENS = 3; 52 | const int LENS = 4; 53 | const int REPS = 5; 54 | 55 | static readonly int[] repMin = { 3, 3, 11 }; 56 | static readonly int[] repBits = { 2, 3, 7 }; 57 | 58 | static readonly int[] BL_ORDER = 59 | { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; 60 | 61 | #endregion 62 | 63 | #region Constructors 64 | public InflaterDynHeader() 65 | { 66 | } 67 | #endregion 68 | 69 | public bool Decode(StreamManipulator input) 70 | { 71 | decode_loop: 72 | for (;;) { 73 | switch (mode) { 74 | case LNUM: 75 | lnum = input.PeekBits(5); 76 | if (lnum < 0) { 77 | return false; 78 | } 79 | lnum += 257; 80 | input.DropBits(5); 81 | // System.err.println("LNUM: "+lnum); 82 | mode = DNUM; 83 | goto case DNUM; // fall through 84 | case DNUM: 85 | dnum = input.PeekBits(5); 86 | if (dnum < 0) { 87 | return false; 88 | } 89 | dnum++; 90 | input.DropBits(5); 91 | // System.err.println("DNUM: "+dnum); 92 | num = lnum+dnum; 93 | litdistLens = new byte[num]; 94 | mode = BLNUM; 95 | goto case BLNUM; // fall through 96 | case BLNUM: 97 | blnum = input.PeekBits(4); 98 | if (blnum < 0) { 99 | return false; 100 | } 101 | blnum += 4; 102 | input.DropBits(4); 103 | blLens = new byte[19]; 104 | ptr = 0; 105 | // System.err.println("BLNUM: "+blnum); 106 | mode = BLLENS; 107 | goto case BLLENS; // fall through 108 | case BLLENS: 109 | while (ptr < blnum) { 110 | int len = input.PeekBits(3); 111 | if (len < 0) { 112 | return false; 113 | } 114 | input.DropBits(3); 115 | // System.err.println("blLens["+BL_ORDER[ptr]+"]: "+len); 116 | blLens[BL_ORDER[ptr]] = (byte) len; 117 | ptr++; 118 | } 119 | blTree = new InflaterHuffmanTree(blLens); 120 | blLens = null; 121 | ptr = 0; 122 | mode = LENS; 123 | goto case LENS; // fall through 124 | case LENS: 125 | { 126 | int symbol; 127 | while (((symbol = blTree.GetSymbol(input)) & ~15) == 0) { 128 | /* Normal case: symbol in [0..15] */ 129 | 130 | // System.err.println("litdistLens["+ptr+"]: "+symbol); 131 | litdistLens[ptr++] = lastLen = (byte)symbol; 132 | 133 | if (ptr == num) { 134 | /* Finished */ 135 | return true; 136 | } 137 | } 138 | 139 | /* need more input ? */ 140 | if (symbol < 0) { 141 | return false; 142 | } 143 | 144 | /* otherwise repeat code */ 145 | if (symbol >= 17) { 146 | /* repeat zero */ 147 | // System.err.println("repeating zero"); 148 | lastLen = 0; 149 | } else { 150 | if (ptr == 0) { 151 | throw new SharpZipBaseException(); 152 | } 153 | } 154 | repSymbol = symbol-16; 155 | } 156 | mode = REPS; 157 | goto case REPS; // fall through 158 | case REPS: 159 | { 160 | int bits = repBits[repSymbol]; 161 | int count = input.PeekBits(bits); 162 | if (count < 0) { 163 | return false; 164 | } 165 | input.DropBits(bits); 166 | count += repMin[repSymbol]; 167 | // System.err.println("litdistLens repeated: "+count); 168 | 169 | if (ptr + count > num) { 170 | throw new SharpZipBaseException(); 171 | } 172 | while (count-- > 0) { 173 | litdistLens[ptr++] = lastLen; 174 | } 175 | 176 | if (ptr == num) { 177 | /* Finished */ 178 | return true; 179 | } 180 | } 181 | mode = LENS; 182 | goto decode_loop; 183 | } 184 | } 185 | } 186 | 187 | public InflaterHuffmanTree BuildLitLenTree() 188 | { 189 | byte[] litlenLens = new byte[lnum]; 190 | Array.Copy(litdistLens, 0, litlenLens, 0, lnum); 191 | return new InflaterHuffmanTree(litlenLens); 192 | } 193 | 194 | public InflaterHuffmanTree BuildDistTree() 195 | { 196 | byte[] distLens = new byte[dnum]; 197 | Array.Copy(litdistLens, lnum, distLens, 0, dnum); 198 | return new InflaterHuffmanTree(distLens); 199 | } 200 | 201 | #region Instance Fields 202 | byte[] blLens; 203 | byte[] litdistLens; 204 | 205 | InflaterHuffmanTree blTree; 206 | 207 | /// 208 | /// The current decode mode 209 | /// 210 | int mode; 211 | int lnum, dnum, blnum, num; 212 | int repSymbol; 213 | byte lastLen; 214 | int ptr; 215 | #endregion 216 | 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Zip/Compression/InflaterHuffmanTree.cs: -------------------------------------------------------------------------------- 1 | // InflaterHuffmanTree.cs 2 | // Copyright (C) 2001 Mike Krueger 3 | // 4 | // This file was translated from java, it was part of the GNU Classpath 5 | // Copyright (C) 2001 Free Software Foundation, Inc. 6 | // 7 | // This program is free software; you can redistribute it and/or 8 | // modify it under the terms of the GNU General Public License 9 | // as published by the Free Software Foundation; either version 2 10 | // of the License, or (at your option) any later version. 11 | // 12 | // This program is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | // GNU General Public License for more details. 16 | // 17 | // You should have received a copy of the GNU General Public License 18 | // along with this program; if not, write to the Free Software 19 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | // 21 | // Linking this library statically or dynamically with other modules is 22 | // making a combined work based on this library. Thus, the terms and 23 | // conditions of the GNU General Public License cover the whole 24 | // combination. 25 | // 26 | // As a special exception, the copyright holders of this library give you 27 | // permission to link this library with independent modules to produce an 28 | // executable, regardless of the license terms of these independent 29 | // modules, and to copy and distribute the resulting executable under 30 | // terms of your choice, provided that you also meet, for each linked 31 | // independent module, the terms and conditions of the license of that 32 | // module. An independent module is a module which is not derived from 33 | // or based on this library. If you modify this library, you may extend 34 | // this exception to your version of the library, but you are not 35 | // obligated to do so. If you do not wish to do so, delete this 36 | // exception statement from your version. 37 | 38 | using System; 39 | 40 | using ICSharpCode.SharpZipLib.Zip.Compression.Streams; 41 | 42 | namespace ICSharpCode.SharpZipLib.Zip.Compression 43 | { 44 | 45 | /// 46 | /// Huffman tree used for inflation 47 | /// 48 | public class InflaterHuffmanTree 49 | { 50 | #region Constants 51 | const int MAX_BITLEN = 15; 52 | #endregion 53 | 54 | #region Instance Fields 55 | short[] tree; 56 | #endregion 57 | 58 | /// 59 | /// Literal length tree 60 | /// 61 | public static InflaterHuffmanTree defLitLenTree; 62 | 63 | /// 64 | /// Distance tree 65 | /// 66 | public static InflaterHuffmanTree defDistTree; 67 | 68 | static InflaterHuffmanTree() 69 | { 70 | try { 71 | byte[] codeLengths = new byte[288]; 72 | int i = 0; 73 | while (i < 144) { 74 | codeLengths[i++] = 8; 75 | } 76 | while (i < 256) { 77 | codeLengths[i++] = 9; 78 | } 79 | while (i < 280) { 80 | codeLengths[i++] = 7; 81 | } 82 | while (i < 288) { 83 | codeLengths[i++] = 8; 84 | } 85 | defLitLenTree = new InflaterHuffmanTree(codeLengths); 86 | 87 | codeLengths = new byte[32]; 88 | i = 0; 89 | while (i < 32) { 90 | codeLengths[i++] = 5; 91 | } 92 | defDistTree = new InflaterHuffmanTree(codeLengths); 93 | } catch (Exception) { 94 | throw new SharpZipBaseException("InflaterHuffmanTree: static tree length illegal"); 95 | } 96 | } 97 | 98 | #region Constructors 99 | /// 100 | /// Constructs a Huffman tree from the array of code lengths. 101 | /// 102 | /// 103 | /// the array of code lengths 104 | /// 105 | public InflaterHuffmanTree(byte[] codeLengths) 106 | { 107 | BuildTree(codeLengths); 108 | } 109 | #endregion 110 | 111 | void BuildTree(byte[] codeLengths) 112 | { 113 | int[] blCount = new int[MAX_BITLEN + 1]; 114 | int[] nextCode = new int[MAX_BITLEN + 1]; 115 | 116 | for (int i = 0; i < codeLengths.Length; i++) { 117 | int bits = codeLengths[i]; 118 | if (bits > 0) { 119 | blCount[bits]++; 120 | } 121 | } 122 | 123 | int code = 0; 124 | int treeSize = 512; 125 | for (int bits = 1; bits <= MAX_BITLEN; bits++) { 126 | nextCode[bits] = code; 127 | code += blCount[bits] << (16 - bits); 128 | if (bits >= 10) { 129 | /* We need an extra table for bit lengths >= 10. */ 130 | int start = nextCode[bits] & 0x1ff80; 131 | int end = code & 0x1ff80; 132 | treeSize += (end - start) >> (16 - bits); 133 | } 134 | } 135 | 136 | /* -jr comment this out! doesnt work for dynamic trees and pkzip 2.04g 137 | if (code != 65536) 138 | { 139 | throw new SharpZipBaseException("Code lengths don't add up properly."); 140 | } 141 | */ 142 | /* Now create and fill the extra tables from longest to shortest 143 | * bit len. This way the sub trees will be aligned. 144 | */ 145 | tree = new short[treeSize]; 146 | int treePtr = 512; 147 | for (int bits = MAX_BITLEN; bits >= 10; bits--) { 148 | int end = code & 0x1ff80; 149 | code -= blCount[bits] << (16 - bits); 150 | int start = code & 0x1ff80; 151 | for (int i = start; i < end; i += 1 << 7) { 152 | tree[DeflaterHuffman.BitReverse(i)] = (short) ((-treePtr << 4) | bits); 153 | treePtr += 1 << (bits-9); 154 | } 155 | } 156 | 157 | for (int i = 0; i < codeLengths.Length; i++) { 158 | int bits = codeLengths[i]; 159 | if (bits == 0) { 160 | continue; 161 | } 162 | code = nextCode[bits]; 163 | int revcode = DeflaterHuffman.BitReverse(code); 164 | if (bits <= 9) { 165 | do { 166 | tree[revcode] = (short) ((i << 4) | bits); 167 | revcode += 1 << bits; 168 | } while (revcode < 512); 169 | } else { 170 | int subTree = tree[revcode & 511]; 171 | int treeLen = 1 << (subTree & 15); 172 | subTree = -(subTree >> 4); 173 | do { 174 | tree[subTree | (revcode >> 9)] = (short) ((i << 4) | bits); 175 | revcode += 1 << bits; 176 | } while (revcode < treeLen); 177 | } 178 | nextCode[bits] = code + (1 << (16 - bits)); 179 | } 180 | 181 | } 182 | 183 | /// 184 | /// Reads the next symbol from input. The symbol is encoded using the 185 | /// huffman tree. 186 | /// 187 | /// 188 | /// input the input source. 189 | /// 190 | /// 191 | /// the next symbol, or -1 if not enough input is available. 192 | /// 193 | public int GetSymbol(StreamManipulator input) 194 | { 195 | int lookahead, symbol; 196 | if ((lookahead = input.PeekBits(9)) >= 0) { 197 | if ((symbol = tree[lookahead]) >= 0) { 198 | input.DropBits(symbol & 15); 199 | return symbol >> 4; 200 | } 201 | int subtree = -(symbol >> 4); 202 | int bitlen = symbol & 15; 203 | if ((lookahead = input.PeekBits(bitlen)) >= 0) { 204 | symbol = tree[subtree | (lookahead >> 9)]; 205 | input.DropBits(symbol & 15); 206 | return symbol >> 4; 207 | } else { 208 | int bits = input.AvailableBits; 209 | lookahead = input.PeekBits(bits); 210 | symbol = tree[subtree | (lookahead >> 9)]; 211 | if ((symbol & 15) <= bits) { 212 | input.DropBits(symbol & 15); 213 | return symbol >> 4; 214 | } else { 215 | return -1; 216 | } 217 | } 218 | } else { 219 | int bits = input.AvailableBits; 220 | lookahead = input.PeekBits(bits); 221 | symbol = tree[lookahead]; 222 | if (symbol >= 0 && (symbol & 15) <= bits) { 223 | input.DropBits(symbol & 15); 224 | return symbol >> 4; 225 | } else { 226 | return -1; 227 | } 228 | } 229 | } 230 | } 231 | } 232 | 233 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Zip/Compression/PendingBuffer.cs: -------------------------------------------------------------------------------- 1 | // PendingBuffer.cs 2 | // 3 | // Copyright (C) 2001 Mike Krueger 4 | // Copyright (C) 2004 John Reilly 5 | // 6 | // This file was translated from java, it was part of the GNU Classpath 7 | // Copyright (C) 2001 Free Software Foundation, Inc. 8 | // 9 | // This program is free software; you can redistribute it and/or 10 | // modify it under the terms of the GNU General Public License 11 | // as published by the Free Software Foundation; either version 2 12 | // of the License, or (at your option) any later version. 13 | // 14 | // This program is distributed in the hope that it will be useful, 15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | // GNU General Public License for more details. 18 | // 19 | // You should have received a copy of the GNU General Public License 20 | // along with this program; if not, write to the Free Software 21 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | // 23 | // Linking this library statically or dynamically with other modules is 24 | // making a combined work based on this library. Thus, the terms and 25 | // conditions of the GNU General Public License cover the whole 26 | // combination. 27 | // 28 | // As a special exception, the copyright holders of this library give you 29 | // permission to link this library with independent modules to produce an 30 | // executable, regardless of the license terms of these independent 31 | // modules, and to copy and distribute the resulting executable under 32 | // terms of your choice, provided that you also meet, for each linked 33 | // independent module, the terms and conditions of the license of that 34 | // module. An independent module is a module which is not derived from 35 | // or based on this library. If you modify this library, you may extend 36 | // this exception to your version of the library, but you are not 37 | // obligated to do so. If you do not wish to do so, delete this 38 | // exception statement from your version. 39 | 40 | using System; 41 | 42 | namespace ICSharpCode.SharpZipLib.Zip.Compression 43 | { 44 | 45 | /// 46 | /// This class is general purpose class for writing data to a buffer. 47 | /// 48 | /// It allows you to write bits as well as bytes 49 | /// Based on DeflaterPending.java 50 | /// 51 | /// author of the original java version : Jochen Hoenicke 52 | /// 53 | public class PendingBuffer 54 | { 55 | #region Instance Fields 56 | /// 57 | /// Internal work buffer 58 | /// 59 | byte[] buffer_; 60 | 61 | int start; 62 | int end; 63 | 64 | uint bits; 65 | int bitCount; 66 | #endregion 67 | 68 | #region Constructors 69 | /// 70 | /// construct instance using default buffer size of 4096 71 | /// 72 | public PendingBuffer() : this( 4096 ) 73 | { 74 | } 75 | 76 | /// 77 | /// construct instance using specified buffer size 78 | /// 79 | /// 80 | /// size to use for internal buffer 81 | /// 82 | public PendingBuffer(int bufferSize) 83 | { 84 | buffer_ = new byte[bufferSize]; 85 | } 86 | 87 | #endregion 88 | 89 | /// 90 | /// Clear internal state/buffers 91 | /// 92 | public void Reset() 93 | { 94 | start = end = bitCount = 0; 95 | } 96 | 97 | /// 98 | /// Write a byte to buffer 99 | /// 100 | /// 101 | /// The value to write 102 | /// 103 | public void WriteByte(int value) 104 | { 105 | #if DebugDeflation 106 | if (DeflaterConstants.DEBUGGING && (start != 0) ) 107 | { 108 | throw new SharpZipBaseException("Debug check: start != 0"); 109 | } 110 | #endif 111 | buffer_[end++] = unchecked((byte) value); 112 | } 113 | 114 | /// 115 | /// Write a short value to buffer LSB first 116 | /// 117 | /// 118 | /// The value to write. 119 | /// 120 | public void WriteShort(int value) 121 | { 122 | #if DebugDeflation 123 | if (DeflaterConstants.DEBUGGING && (start != 0) ) 124 | { 125 | throw new SharpZipBaseException("Debug check: start != 0"); 126 | } 127 | #endif 128 | buffer_[end++] = unchecked((byte) value); 129 | buffer_[end++] = unchecked((byte) (value >> 8)); 130 | } 131 | 132 | /// 133 | /// write an integer LSB first 134 | /// 135 | /// The value to write. 136 | public void WriteInt(int value) 137 | { 138 | #if DebugDeflation 139 | if (DeflaterConstants.DEBUGGING && (start != 0) ) 140 | { 141 | throw new SharpZipBaseException("Debug check: start != 0"); 142 | } 143 | #endif 144 | buffer_[end++] = unchecked((byte) value); 145 | buffer_[end++] = unchecked((byte) (value >> 8)); 146 | buffer_[end++] = unchecked((byte) (value >> 16)); 147 | buffer_[end++] = unchecked((byte) (value >> 24)); 148 | } 149 | 150 | /// 151 | /// Write a block of data to buffer 152 | /// 153 | /// data to write 154 | /// offset of first byte to write 155 | /// number of bytes to write 156 | public void WriteBlock(byte[] block, int offset, int length) 157 | { 158 | #if DebugDeflation 159 | if (DeflaterConstants.DEBUGGING && (start != 0) ) 160 | { 161 | throw new SharpZipBaseException("Debug check: start != 0"); 162 | } 163 | #endif 164 | System.Array.Copy(block, offset, buffer_, end, length); 165 | end += length; 166 | } 167 | 168 | /// 169 | /// The number of bits written to the buffer 170 | /// 171 | public int BitCount { 172 | get { 173 | return bitCount; 174 | } 175 | } 176 | 177 | /// 178 | /// Align internal buffer on a byte boundary 179 | /// 180 | public void AlignToByte() 181 | { 182 | #if DebugDeflation 183 | if (DeflaterConstants.DEBUGGING && (start != 0) ) 184 | { 185 | throw new SharpZipBaseException("Debug check: start != 0"); 186 | } 187 | #endif 188 | if (bitCount > 0) 189 | { 190 | buffer_[end++] = unchecked((byte) bits); 191 | if (bitCount > 8) { 192 | buffer_[end++] = unchecked((byte) (bits >> 8)); 193 | } 194 | } 195 | bits = 0; 196 | bitCount = 0; 197 | } 198 | 199 | /// 200 | /// Write bits to internal buffer 201 | /// 202 | /// source of bits 203 | /// number of bits to write 204 | public void WriteBits(int b, int count) 205 | { 206 | #if DebugDeflation 207 | if (DeflaterConstants.DEBUGGING && (start != 0) ) 208 | { 209 | throw new SharpZipBaseException("Debug check: start != 0"); 210 | } 211 | 212 | // if (DeflaterConstants.DEBUGGING) { 213 | // //Console.WriteLine("writeBits("+b+","+count+")"); 214 | // } 215 | #endif 216 | bits |= (uint)(b << bitCount); 217 | bitCount += count; 218 | if (bitCount >= 16) { 219 | buffer_[end++] = unchecked((byte) bits); 220 | buffer_[end++] = unchecked((byte) (bits >> 8)); 221 | bits >>= 16; 222 | bitCount -= 16; 223 | } 224 | } 225 | 226 | /// 227 | /// Write a short value to internal buffer most significant byte first 228 | /// 229 | /// value to write 230 | public void WriteShortMSB(int s) 231 | { 232 | #if DebugDeflation 233 | if (DeflaterConstants.DEBUGGING && (start != 0) ) 234 | { 235 | throw new SharpZipBaseException("Debug check: start != 0"); 236 | } 237 | #endif 238 | buffer_[end++] = unchecked((byte) (s >> 8)); 239 | buffer_[end++] = unchecked((byte) s); 240 | } 241 | 242 | /// 243 | /// Indicates if buffer has been flushed 244 | /// 245 | public bool IsFlushed { 246 | get { 247 | return end == 0; 248 | } 249 | } 250 | 251 | /// 252 | /// Flushes the pending buffer into the given output array. If the 253 | /// output array is to small, only a partial flush is done. 254 | /// 255 | /// The output array. 256 | /// The offset into output array. 257 | /// The maximum number of bytes to store. 258 | /// The number of bytes flushed. 259 | public int Flush(byte[] output, int offset, int length) 260 | { 261 | if (bitCount >= 8) { 262 | buffer_[end++] = unchecked((byte) bits); 263 | bits >>= 8; 264 | bitCount -= 8; 265 | } 266 | 267 | if (length > end - start) { 268 | length = end - start; 269 | System.Array.Copy(buffer_, start, output, offset, length); 270 | start = 0; 271 | end = 0; 272 | } else { 273 | System.Array.Copy(buffer_, start, output, offset, length); 274 | start += length; 275 | } 276 | return length; 277 | } 278 | 279 | /// 280 | /// Convert internal buffer to byte array. 281 | /// Buffer is empty on completion 282 | /// 283 | /// 284 | /// The internal buffer contents converted to a byte array. 285 | /// 286 | public byte[] ToByteArray() 287 | { 288 | byte[] result = new byte[end - start]; 289 | System.Array.Copy(buffer_, start, result, 0, result.Length); 290 | start = 0; 291 | end = 0; 292 | return result; 293 | } 294 | } 295 | } 296 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Zip/Compression/Streams/OutputWindow.cs: -------------------------------------------------------------------------------- 1 | // OutputWindow.cs 2 | // 3 | // Copyright (C) 2001 Mike Krueger 4 | // 5 | // This file was translated from java, it was part of the GNU Classpath 6 | // Copyright (C) 2001 Free Software Foundation, Inc. 7 | // 8 | // This program is free software; you can redistribute it and/or 9 | // modify it under the terms of the GNU General Public License 10 | // as published by the Free Software Foundation; either version 2 11 | // of the License, or (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program; if not, write to the Free Software 20 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | // 22 | // Linking this library statically or dynamically with other modules is 23 | // making a combined work based on this library. Thus, the terms and 24 | // conditions of the GNU General Public License cover the whole 25 | // combination. 26 | // 27 | // As a special exception, the copyright holders of this library give you 28 | // permission to link this library with independent modules to produce an 29 | // executable, regardless of the license terms of these independent 30 | // modules, and to copy and distribute the resulting executable under 31 | // terms of your choice, provided that you also meet, for each linked 32 | // independent module, the terms and conditions of the license of that 33 | // module. An independent module is a module which is not derived from 34 | // or based on this library. If you modify this library, you may extend 35 | // this exception to your version of the library, but you are not 36 | // obligated to do so. If you do not wish to do so, delete this 37 | // exception statement from your version. 38 | 39 | using System; 40 | 41 | 42 | namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams 43 | { 44 | 45 | /// 46 | /// Contains the output from the Inflation process. 47 | /// We need to have a window so that we can refer backwards into the output stream 48 | /// to repeat stuff.
49 | /// Author of the original java version : John Leuner 50 | ///
51 | public class OutputWindow 52 | { 53 | #region Constants 54 | const int WindowSize = 1 << 15; 55 | const int WindowMask = WindowSize - 1; 56 | #endregion 57 | 58 | #region Instance Fields 59 | byte[] window = new byte[WindowSize]; //The window is 2^15 bytes 60 | int windowEnd; 61 | int windowFilled; 62 | #endregion 63 | 64 | /// 65 | /// Write a byte to this output window 66 | /// 67 | /// value to write 68 | /// 69 | /// if window is full 70 | /// 71 | public void Write(int value) 72 | { 73 | if (windowFilled++ == WindowSize) { 74 | throw new InvalidOperationException("Window full"); 75 | } 76 | window[windowEnd++] = (byte) value; 77 | windowEnd &= WindowMask; 78 | } 79 | 80 | 81 | private void SlowRepeat(int repStart, int length, int distance) 82 | { 83 | while (length-- > 0) { 84 | window[windowEnd++] = window[repStart++]; 85 | windowEnd &= WindowMask; 86 | repStart &= WindowMask; 87 | } 88 | } 89 | 90 | /// 91 | /// Append a byte pattern already in the window itself 92 | /// 93 | /// length of pattern to copy 94 | /// distance from end of window pattern occurs 95 | /// 96 | /// If the repeated data overflows the window 97 | /// 98 | public void Repeat(int length, int distance) 99 | { 100 | if ((windowFilled += length) > WindowSize) { 101 | throw new InvalidOperationException("Window full"); 102 | } 103 | 104 | int repStart = (windowEnd - distance) & WindowMask; 105 | int border = WindowSize - length; 106 | if ( (repStart <= border) && (windowEnd < border) ) { 107 | if (length <= distance) { 108 | System.Array.Copy(window, repStart, window, windowEnd, length); 109 | windowEnd += length; 110 | } else { 111 | // We have to copy manually, since the repeat pattern overlaps. 112 | while (length-- > 0) { 113 | window[windowEnd++] = window[repStart++]; 114 | } 115 | } 116 | } else { 117 | SlowRepeat(repStart, length, distance); 118 | } 119 | } 120 | 121 | /// 122 | /// Copy from input manipulator to internal window 123 | /// 124 | /// source of data 125 | /// length of data to copy 126 | /// the number of bytes copied 127 | public int CopyStored(StreamManipulator input, int length) 128 | { 129 | length = Math.Min(Math.Min(length, WindowSize - windowFilled), input.AvailableBytes); 130 | int copied; 131 | 132 | int tailLen = WindowSize - windowEnd; 133 | if (length > tailLen) { 134 | copied = input.CopyBytes(window, windowEnd, tailLen); 135 | if (copied == tailLen) { 136 | copied += input.CopyBytes(window, 0, length - tailLen); 137 | } 138 | } else { 139 | copied = input.CopyBytes(window, windowEnd, length); 140 | } 141 | 142 | windowEnd = (windowEnd + copied) & WindowMask; 143 | windowFilled += copied; 144 | return copied; 145 | } 146 | 147 | /// 148 | /// Copy dictionary to window 149 | /// 150 | /// source dictionary 151 | /// offset of start in source dictionary 152 | /// length of dictionary 153 | /// 154 | /// If window isnt empty 155 | /// 156 | public void CopyDict(byte[] dictionary, int offset, int length) 157 | { 158 | if ( dictionary == null ) { 159 | throw new ArgumentNullException("dictionary"); 160 | } 161 | 162 | if (windowFilled > 0) { 163 | throw new InvalidOperationException(); 164 | } 165 | 166 | if (length > WindowSize) { 167 | offset += length - WindowSize; 168 | length = WindowSize; 169 | } 170 | System.Array.Copy(dictionary, offset, window, 0, length); 171 | windowEnd = length & WindowMask; 172 | } 173 | 174 | /// 175 | /// Get remaining unfilled space in window 176 | /// 177 | /// Number of bytes left in window 178 | public int GetFreeSpace() 179 | { 180 | return WindowSize - windowFilled; 181 | } 182 | 183 | /// 184 | /// Get bytes available for output in window 185 | /// 186 | /// Number of bytes filled 187 | public int GetAvailable() 188 | { 189 | return windowFilled; 190 | } 191 | 192 | /// 193 | /// Copy contents of window to output 194 | /// 195 | /// buffer to copy to 196 | /// offset to start at 197 | /// number of bytes to count 198 | /// The number of bytes copied 199 | /// 200 | /// If a window underflow occurs 201 | /// 202 | public int CopyOutput(byte[] output, int offset, int len) 203 | { 204 | int copyEnd = windowEnd; 205 | if (len > windowFilled) { 206 | len = windowFilled; 207 | } else { 208 | copyEnd = (windowEnd - windowFilled + len) & WindowMask; 209 | } 210 | 211 | int copied = len; 212 | int tailLen = len - copyEnd; 213 | 214 | if (tailLen > 0) { 215 | System.Array.Copy(window, WindowSize - tailLen, output, offset, tailLen); 216 | offset += tailLen; 217 | len = copyEnd; 218 | } 219 | System.Array.Copy(window, copyEnd - len, output, offset, len); 220 | windowFilled -= copied; 221 | if (windowFilled < 0) { 222 | throw new InvalidOperationException(); 223 | } 224 | return copied; 225 | } 226 | 227 | /// 228 | /// Reset by clearing window so GetAvailable returns 0 229 | /// 230 | public void Reset() 231 | { 232 | windowFilled = windowEnd = 0; 233 | } 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Zip/IEntryFactory.cs: -------------------------------------------------------------------------------- 1 | // IEntryFactory.cs 2 | // 3 | // Copyright 2006 John Reilly 4 | // 5 | // Copyright (C) 2001 Free Software Foundation, Inc. 6 | // 7 | // This program is free software; you can redistribute it and/or 8 | // modify it under the terms of the GNU General Public License 9 | // as published by the Free Software Foundation; either version 2 10 | // of the License, or (at your option) any later version. 11 | // 12 | // This program is distributed in the hope that it will be useful, 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | // GNU General Public License for more details. 16 | // 17 | // You should have received a copy of the GNU General Public License 18 | // along with this program; if not, write to the Free Software 19 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | // 21 | // Linking this library statically or dynamically with other modules is 22 | // making a combined work based on this library. Thus, the terms and 23 | // conditions of the GNU General Public License cover the whole 24 | // combination. 25 | // 26 | // As a special exception, the copyright holders of this library give you 27 | // permission to link this library with independent modules to produce an 28 | // executable, regardless of the license terms of these independent 29 | // modules, and to copy and distribute the resulting executable under 30 | // terms of your choice, provided that you also meet, for each linked 31 | // independent module, the terms and conditions of the license of that 32 | // module. An independent module is a module which is not derived from 33 | // or based on this library. If you modify this library, you may extend 34 | // this exception to your version of the library, but you are not 35 | // obligated to do so. If you do not wish to do so, delete this 36 | // exception statement from your version. 37 | 38 | // HISTORY 39 | // 2012-11-29 Z-1684 Added MakeFileEntry(string fileName, string entryName, bool useFileSystem) 40 | 41 | using ICSharpCode.SharpZipLib.Core; 42 | 43 | namespace ICSharpCode.SharpZipLib.Zip 44 | { 45 | /// 46 | /// Defines factory methods for creating new values. 47 | /// 48 | public interface IEntryFactory 49 | { 50 | /// 51 | /// Create a for a file given its name 52 | /// 53 | /// The name of the file to create an entry for. 54 | /// Returns a file entry based on the passed. 55 | ZipEntry MakeFileEntry(string fileName); 56 | 57 | /// 58 | /// Create a for a file given its name 59 | /// 60 | /// The name of the file to create an entry for. 61 | /// If true get details from the file system if the file exists. 62 | /// Returns a file entry based on the passed. 63 | ZipEntry MakeFileEntry(string fileName, bool useFileSystem); 64 | 65 | /// 66 | /// Create a for a file given its actual name and optional override name 67 | /// 68 | /// The name of the file to create an entry for. 69 | /// An alternative name to be used for the new entry. Null if not applicable. 70 | /// If true get details from the file system if the file exists. 71 | /// Returns a file entry based on the passed. 72 | ZipEntry MakeFileEntry(string fileName, string entryName, bool useFileSystem); 73 | 74 | /// 75 | /// Create a for a directory given its name 76 | /// 77 | /// The name of the directory to create an entry for. 78 | /// Returns a directory entry based on the passed. 79 | ZipEntry MakeDirectoryEntry(string directoryName); 80 | 81 | /// 82 | /// Create a for a directory given its name 83 | /// 84 | /// The name of the directory to create an entry for. 85 | /// If true get details from the file system for this directory if it exists. 86 | /// Returns a directory entry based on the passed. 87 | ZipEntry MakeDirectoryEntry(string directoryName, bool useFileSystem); 88 | 89 | /// 90 | /// Get/set the applicable. 91 | /// 92 | INameTransform NameTransform { get; set; } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Zip/WindowsNameTransform.cs: -------------------------------------------------------------------------------- 1 | // WindowsNameTransform.cs 2 | // 3 | // Copyright 2007 John Reilly 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 2 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | // 19 | // Linking this library statically or dynamically with other modules is 20 | // making a combined work based on this library. Thus, the terms and 21 | // conditions of the GNU General Public License cover the whole 22 | // combination. 23 | // 24 | // As a special exception, the copyright holders of this library give you 25 | // permission to link this library with independent modules to produce an 26 | // executable, regardless of the license terms of these independent 27 | // modules, and to copy and distribute the resulting executable under 28 | // terms of your choice, provided that you also meet, for each linked 29 | // independent module, the terms and conditions of the license of that 30 | // module. An independent module is a module which is not derived from 31 | // or based on this library. If you modify this library, you may extend 32 | // this exception to your version of the library, but you are not 33 | // obligated to do so. If you do not wish to do so, delete this 34 | // exception statement from your version. 35 | 36 | using System; 37 | using System.IO; 38 | using System.Text; 39 | 40 | using ICSharpCode.SharpZipLib.Core; 41 | 42 | namespace ICSharpCode.SharpZipLib.Zip 43 | { 44 | /// 45 | /// WindowsNameTransform transforms names to windows compatible ones. 46 | /// 47 | public class WindowsNameTransform : INameTransform 48 | { 49 | /// 50 | /// Initialises a new instance of 51 | /// 52 | /// 53 | public WindowsNameTransform(string baseDirectory) 54 | { 55 | if ( baseDirectory == null ) { 56 | throw new ArgumentNullException("baseDirectory", "Directory name is invalid"); 57 | } 58 | 59 | BaseDirectory = baseDirectory; 60 | } 61 | 62 | /// 63 | /// Initialise a default instance of 64 | /// 65 | public WindowsNameTransform() 66 | { 67 | // Do nothing. 68 | } 69 | 70 | /// 71 | /// Gets or sets a value containing the target directory to prefix values with. 72 | /// 73 | public string BaseDirectory 74 | { 75 | get { return _baseDirectory; } 76 | set { 77 | if ( value == null ) { 78 | throw new ArgumentNullException("value"); 79 | } 80 | 81 | _baseDirectory = Path.GetFullPath(value); 82 | } 83 | } 84 | 85 | /// 86 | /// Gets or sets a value indicating wether paths on incoming values should be removed. 87 | /// 88 | public bool TrimIncomingPaths 89 | { 90 | get { return _trimIncomingPaths; } 91 | set { _trimIncomingPaths = value; } 92 | } 93 | 94 | /// 95 | /// Transform a Zip directory name to a windows directory name. 96 | /// 97 | /// The directory name to transform. 98 | /// The transformed name. 99 | public string TransformDirectory(string name) 100 | { 101 | name = TransformFile(name); 102 | if (name.Length > 0) { 103 | while ( name.EndsWith(@"\") ) { 104 | name = name.Remove(name.Length - 1, 1); 105 | } 106 | } 107 | else { 108 | throw new ZipException("Cannot have an empty directory name"); 109 | } 110 | return name; 111 | } 112 | 113 | /// 114 | /// Transform a Zip format file name to a windows style one. 115 | /// 116 | /// The file name to transform. 117 | /// The transformed name. 118 | public string TransformFile(string name) 119 | { 120 | if (name != null) { 121 | name = MakeValidName(name, _replacementChar); 122 | 123 | if ( _trimIncomingPaths ) { 124 | name = Path.GetFileName(name); 125 | } 126 | 127 | // This may exceed windows length restrictions. 128 | // Combine will throw a PathTooLongException in that case. 129 | if ( _baseDirectory != null ) { 130 | name = Path.Combine(_baseDirectory, name); 131 | } 132 | } 133 | else { 134 | name = string.Empty; 135 | } 136 | return name; 137 | } 138 | 139 | /// 140 | /// Test a name to see if it is a valid name for a windows filename as extracted from a Zip archive. 141 | /// 142 | /// The name to test. 143 | /// Returns true if the name is a valid zip name; false otherwise. 144 | /// The filename isnt a true windows path in some fundamental ways like no absolute paths, no rooted paths etc. 145 | public static bool IsValidName(string name) 146 | { 147 | bool result = 148 | (name != null) && 149 | (name.Length <= MaxPath) && 150 | (string.Compare(name, MakeValidName(name, '_')) == 0) 151 | ; 152 | 153 | return result; 154 | } 155 | 156 | /// 157 | /// Initialise static class information. 158 | /// 159 | static WindowsNameTransform() 160 | { 161 | char[] invalidPathChars; 162 | 163 | #if NET_1_0 || NET_1_1 || NETCF_1_0 164 | invalidPathChars = Path.InvalidPathChars; 165 | #else 166 | invalidPathChars = Path.GetInvalidPathChars(); 167 | #endif 168 | int howMany = invalidPathChars.Length + 3; 169 | 170 | InvalidEntryChars = new char[howMany]; 171 | Array.Copy(invalidPathChars, 0, InvalidEntryChars, 0, invalidPathChars.Length); 172 | InvalidEntryChars[howMany - 1] = '*'; 173 | InvalidEntryChars[howMany - 2] = '?'; 174 | InvalidEntryChars[howMany - 3] = ':'; 175 | } 176 | 177 | /// 178 | /// Force a name to be valid by replacing invalid characters with a fixed value 179 | /// 180 | /// The name to make valid 181 | /// The replacement character to use for any invalid characters. 182 | /// Returns a valid name 183 | public static string MakeValidName(string name, char replacement) 184 | { 185 | if ( name == null ) { 186 | throw new ArgumentNullException("name"); 187 | } 188 | 189 | name = WindowsPathUtils.DropPathRoot(name.Replace("/", @"\")); 190 | 191 | // Drop any leading slashes. 192 | while ( (name.Length > 0) && (name[0] == '\\')) { 193 | name = name.Remove(0, 1); 194 | } 195 | 196 | // Drop any trailing slashes. 197 | while ( (name.Length > 0) && (name[name.Length - 1] == '\\')) { 198 | name = name.Remove(name.Length - 1, 1); 199 | } 200 | 201 | // Convert consecutive \\ characters to \ 202 | int index = name.IndexOf(@"\\"); 203 | while (index >= 0) { 204 | name = name.Remove(index, 1); 205 | index = name.IndexOf(@"\\"); 206 | } 207 | 208 | // Convert any invalid characters using the replacement one. 209 | index = name.IndexOfAny(InvalidEntryChars); 210 | if (index >= 0) { 211 | StringBuilder builder = new StringBuilder(name); 212 | 213 | while (index >= 0 ) { 214 | builder[index] = replacement; 215 | 216 | if (index >= name.Length) { 217 | index = -1; 218 | } 219 | else { 220 | index = name.IndexOfAny(InvalidEntryChars, index + 1); 221 | } 222 | } 223 | name = builder.ToString(); 224 | } 225 | 226 | // Check for names greater than MaxPath characters. 227 | // TODO: Were is CLR version of MaxPath defined? Can't find it in Environment. 228 | if ( name.Length > MaxPath ) { 229 | throw new PathTooLongException(); 230 | } 231 | 232 | return name; 233 | } 234 | 235 | /// 236 | /// Gets or set the character to replace invalid characters during transformations. 237 | /// 238 | public char Replacement 239 | { 240 | get { return _replacementChar; } 241 | set { 242 | for ( int i = 0; i < InvalidEntryChars.Length; ++i ) { 243 | if ( InvalidEntryChars[i] == value ) { 244 | throw new ArgumentException("invalid path character"); 245 | } 246 | } 247 | 248 | if ((value == '\\') || (value == '/')) { 249 | throw new ArgumentException("invalid replacement character"); 250 | } 251 | 252 | _replacementChar = value; 253 | } 254 | } 255 | 256 | /// 257 | /// The maximum windows path name permitted. 258 | /// 259 | /// This may not valid for all windows systems - CE?, etc but I cant find the equivalent in the CLR. 260 | const int MaxPath = 260; 261 | 262 | #region Instance Fields 263 | string _baseDirectory; 264 | bool _trimIncomingPaths; 265 | char _replacementChar = '_'; 266 | #endregion 267 | 268 | #region Class Fields 269 | static readonly char[] InvalidEntryChars; 270 | #endregion 271 | } 272 | } 273 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Zip/ZipException.cs: -------------------------------------------------------------------------------- 1 | // ZipException.cs 2 | // 3 | // Copyright (C) 2001 Mike Krueger 4 | // 5 | // This file was translated from java, it was part of the GNU Classpath 6 | // Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. 7 | // 8 | // This program is free software; you can redistribute it and/or 9 | // modify it under the terms of the GNU General Public License 10 | // as published by the Free Software Foundation; either version 2 11 | // of the License, or (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program; if not, write to the Free Software 20 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | // 22 | // Linking this library statically or dynamically with other modules is 23 | // making a combined work based on this library. Thus, the terms and 24 | // conditions of the GNU General Public License cover the whole 25 | // combination. 26 | // 27 | // As a special exception, the copyright holders of this library give you 28 | // permission to link this library with independent modules to produce an 29 | // executable, regardless of the license terms of these independent 30 | // modules, and to copy and distribute the resulting executable under 31 | // terms of your choice, provided that you also meet, for each linked 32 | // independent module, the terms and conditions of the license of that 33 | // module. An independent module is a module which is not derived from 34 | // or based on this library. If you modify this library, you may extend 35 | // this exception to your version of the library, but you are not 36 | // obligated to do so. If you do not wish to do so, delete this 37 | // exception statement from your version. 38 | 39 | using System; 40 | 41 | #if !NETCF_1_0 && !NETCF_2_0 42 | using System.Runtime.Serialization; 43 | #endif 44 | 45 | namespace ICSharpCode.SharpZipLib.Zip 46 | { 47 | 48 | /// 49 | /// Represents exception conditions specific to Zip archive handling 50 | /// 51 | #if !NETCF_1_0 && !NETCF_2_0 52 | [Serializable] 53 | #endif 54 | public class ZipException : SharpZipBaseException 55 | { 56 | #if !NETCF_1_0 && !NETCF_2_0 57 | /// 58 | /// Deserialization constructor 59 | /// 60 | /// for this constructor 61 | /// for this constructor 62 | protected ZipException(SerializationInfo info, StreamingContext context ) 63 | : base( info, context ) 64 | { 65 | } 66 | #endif 67 | 68 | /// 69 | /// Initializes a new instance of the ZipException class. 70 | /// 71 | public ZipException() 72 | { 73 | } 74 | 75 | /// 76 | /// Initializes a new instance of the ZipException class with a specified error message. 77 | /// 78 | /// The error message that explains the reason for the exception. 79 | public ZipException(string message) 80 | : base(message) 81 | { 82 | } 83 | 84 | /// 85 | /// Initialise a new instance of ZipException. 86 | /// 87 | /// A message describing the error. 88 | /// The exception that is the cause of the current exception. 89 | public ZipException(string message, Exception exception) 90 | : base(message, exception) 91 | { 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /CL.IO.Zip/SharpZipLib/Zip/ZipNameTransform.cs: -------------------------------------------------------------------------------- 1 | // ZipNameTransform.cs 2 | // 3 | // Copyright 2005 John Reilly 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 2 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program; if not, write to the Free Software 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | // 19 | // Linking this library statically or dynamically with other modules is 20 | // making a combined work based on this library. Thus, the terms and 21 | // conditions of the GNU General Public License cover the whole 22 | // combination. 23 | // 24 | // As a special exception, the copyright holders of this library give you 25 | // permission to link this library with independent modules to produce an 26 | // executable, regardless of the license terms of these independent 27 | // modules, and to copy and distribute the resulting executable under 28 | // terms of your choice, provided that you also meet, for each linked 29 | // independent module, the terms and conditions of the license of that 30 | // module. An independent module is a module which is not derived from 31 | // or based on this library. If you modify this library, you may extend 32 | // this exception to your version of the library, but you are not 33 | // obligated to do so. If you do not wish to do so, delete this 34 | // exception statement from your version. 35 | 36 | 37 | using System; 38 | using System.IO; 39 | using System.Text; 40 | 41 | using ICSharpCode.SharpZipLib.Core; 42 | 43 | namespace ICSharpCode.SharpZipLib.Zip 44 | { 45 | /// 46 | /// ZipNameTransform transforms names as per the Zip file naming convention. 47 | /// 48 | /// The use of absolute names is supported although its use is not valid 49 | /// according to Zip naming conventions, and should not be used if maximum compatability is desired. 50 | public class ZipNameTransform : INameTransform 51 | { 52 | #region Constructors 53 | /// 54 | /// Initialize a new instance of 55 | /// 56 | public ZipNameTransform() 57 | { 58 | } 59 | 60 | /// 61 | /// Initialize a new instance of 62 | /// 63 | /// The string to trim from the front of paths if found. 64 | public ZipNameTransform(string trimPrefix) 65 | { 66 | TrimPrefix = trimPrefix; 67 | } 68 | #endregion 69 | 70 | /// 71 | /// Static constructor. 72 | /// 73 | static ZipNameTransform() 74 | { 75 | char[] invalidPathChars; 76 | #if NET_1_0 || NET_1_1 || NETCF_1_0 77 | invalidPathChars = Path.InvalidPathChars; 78 | #else 79 | invalidPathChars = Path.GetInvalidPathChars(); 80 | #endif 81 | int howMany = invalidPathChars.Length + 2; 82 | 83 | InvalidEntryCharsRelaxed = new char[howMany]; 84 | Array.Copy(invalidPathChars, 0, InvalidEntryCharsRelaxed, 0, invalidPathChars.Length); 85 | InvalidEntryCharsRelaxed[howMany - 1] = '*'; 86 | InvalidEntryCharsRelaxed[howMany - 2] = '?'; 87 | 88 | howMany = invalidPathChars.Length + 4; 89 | InvalidEntryChars = new char[howMany]; 90 | Array.Copy(invalidPathChars, 0, InvalidEntryChars, 0, invalidPathChars.Length); 91 | InvalidEntryChars[howMany - 1] = ':'; 92 | InvalidEntryChars[howMany - 2] = '\\'; 93 | InvalidEntryChars[howMany - 3] = '*'; 94 | InvalidEntryChars[howMany - 4] = '?'; 95 | } 96 | 97 | /// 98 | /// Transform a windows directory name according to the Zip file naming conventions. 99 | /// 100 | /// The directory name to transform. 101 | /// The transformed name. 102 | public string TransformDirectory(string name) 103 | { 104 | name = TransformFile(name); 105 | if (name.Length > 0) { 106 | if ( !name.EndsWith("/") ) { 107 | name += "/"; 108 | } 109 | } 110 | else { 111 | throw new ZipException("Cannot have an empty directory name"); 112 | } 113 | return name; 114 | } 115 | 116 | /// 117 | /// Transform a windows file name according to the Zip file naming conventions. 118 | /// 119 | /// The file name to transform. 120 | /// The transformed name. 121 | public string TransformFile(string name) 122 | { 123 | if (name != null) { 124 | string lowerName = name.ToLower(); 125 | if ( (trimPrefix_ != null) && (lowerName.IndexOf(trimPrefix_) == 0) ) { 126 | name = name.Substring(trimPrefix_.Length); 127 | } 128 | 129 | name = name.Replace(@"\", "/"); 130 | name = WindowsPathUtils.DropPathRoot(name); 131 | 132 | // Drop any leading slashes. 133 | while ((name.Length > 0) && (name[0] == '/')) 134 | { 135 | name = name.Remove(0, 1); 136 | } 137 | 138 | // Drop any trailing slashes. 139 | while ((name.Length > 0) && (name[name.Length - 1] == '/')) 140 | { 141 | name = name.Remove(name.Length - 1, 1); 142 | } 143 | 144 | // Convert consecutive // characters to / 145 | int index = name.IndexOf("//"); 146 | while (index >= 0) 147 | { 148 | name = name.Remove(index, 1); 149 | index = name.IndexOf("//"); 150 | } 151 | 152 | name = MakeValidName(name, '_'); 153 | } 154 | else { 155 | name = string.Empty; 156 | } 157 | return name; 158 | } 159 | 160 | /// 161 | /// Get/set the path prefix to be trimmed from paths if present. 162 | /// 163 | /// The prefix is trimmed before any conversion from 164 | /// a windows path is done. 165 | public string TrimPrefix 166 | { 167 | get { return trimPrefix_; } 168 | set { 169 | trimPrefix_ = value; 170 | if (trimPrefix_ != null) { 171 | trimPrefix_ = trimPrefix_.ToLower(); 172 | } 173 | } 174 | } 175 | 176 | /// 177 | /// Force a name to be valid by replacing invalid characters with a fixed value 178 | /// 179 | /// The name to force valid 180 | /// The replacement character to use. 181 | /// Returns a valid name 182 | static string MakeValidName(string name, char replacement) 183 | { 184 | int index = name.IndexOfAny(InvalidEntryChars); 185 | if (index >= 0) { 186 | StringBuilder builder = new StringBuilder(name); 187 | 188 | while (index >= 0 ) { 189 | builder[index] = replacement; 190 | 191 | if (index >= name.Length) { 192 | index = -1; 193 | } 194 | else { 195 | index = name.IndexOfAny(InvalidEntryChars, index + 1); 196 | } 197 | } 198 | name = builder.ToString(); 199 | } 200 | 201 | if (name.Length > 0xffff) { 202 | throw new PathTooLongException(); 203 | } 204 | 205 | return name; 206 | } 207 | 208 | /// 209 | /// Test a name to see if it is a valid name for a zip entry. 210 | /// 211 | /// The name to test. 212 | /// If true checking is relaxed about windows file names and absolute paths. 213 | /// Returns true if the name is a valid zip name; false otherwise. 214 | /// Zip path names are actually in Unix format, and should only contain relative paths. 215 | /// This means that any path stored should not contain a drive or 216 | /// device letter, or a leading slash. All slashes should forward slashes '/'. 217 | /// An empty name is valid for a file where the input comes from standard input. 218 | /// A null name is not considered valid. 219 | /// 220 | public static bool IsValidName(string name, bool relaxed) 221 | { 222 | bool result = (name != null); 223 | 224 | if ( result ) { 225 | if ( relaxed ) { 226 | result = name.IndexOfAny(InvalidEntryCharsRelaxed) < 0; 227 | } 228 | else { 229 | result = 230 | (name.IndexOfAny(InvalidEntryChars) < 0) && 231 | (name.IndexOf('/') != 0); 232 | } 233 | } 234 | 235 | return result; 236 | } 237 | 238 | /// 239 | /// Test a name to see if it is a valid name for a zip entry. 240 | /// 241 | /// The name to test. 242 | /// Returns true if the name is a valid zip name; false otherwise. 243 | /// Zip path names are actually in unix format, 244 | /// and should only contain relative paths if a path is present. 245 | /// This means that the path stored should not contain a drive or 246 | /// device letter, or a leading slash. All slashes should forward slashes '/'. 247 | /// An empty name is valid where the input comes from standard input. 248 | /// A null name is not considered valid. 249 | /// 250 | public static bool IsValidName(string name) 251 | { 252 | bool result = 253 | (name != null) && 254 | (name.IndexOfAny(InvalidEntryChars) < 0) && 255 | (name.IndexOf('/') != 0) 256 | ; 257 | return result; 258 | } 259 | 260 | #region Instance Fields 261 | string trimPrefix_; 262 | #endregion 263 | 264 | #region Class Fields 265 | static readonly char[] InvalidEntryChars; 266 | static readonly char[] InvalidEntryCharsRelaxed; 267 | #endregion 268 | } 269 | } 270 | -------------------------------------------------------------------------------- /MIUI_Theme_Magiskizer.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {3D5A3937-A76B-4F07-8474-CC2C9951C81A} 8 | WinExe 9 | Properties 10 | MIUI_Theme_Magiskizer 11 | MIUI_Theme_Magiskizer 12 | v4.0 13 | 512 14 | true 15 | false 16 | publish\ 17 | true 18 | Disk 19 | false 20 | Foreground 21 | 7 22 | Days 23 | false 24 | false 25 | true 26 | 1 27 | 1.0.0.%2a 28 | false 29 | true 30 | true 31 | 32 | 33 | 34 | AnyCPU 35 | true 36 | full 37 | false 38 | bin\Debug\ 39 | DEBUG;TRACE 40 | prompt 41 | 4 42 | 43 | 44 | AnyCPU 45 | pdbonly 46 | true 47 | bin\Release\ 48 | TRACE 49 | prompt 50 | 4 51 | 52 | 53 | MIUI_Theme_Magiskizer.Program 54 | 55 | 56 | 1C27BBB4B18103EDDB8770FF539EACBF4C4E082C 57 | 58 | 59 | MIUI_Theme_Magiskizer_TemporaryKey.pfx 60 | 61 | 62 | false 63 | 64 | 65 | false 66 | 67 | 68 | LocalIntranet 69 | 70 | 71 | Properties\app.manifest 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | Form 88 | 89 | 90 | frm_Editor.cs 91 | 92 | 93 | Form 94 | 95 | 96 | frm_Main.cs 97 | 98 | 99 | 100 | 101 | frm_Editor.cs 102 | 103 | 104 | frm_Main.cs 105 | 106 | 107 | ResXFileCodeGenerator 108 | Resources.Designer.cs 109 | Designer 110 | 111 | 112 | True 113 | Resources.resx 114 | 115 | 116 | 117 | 118 | SettingsSingleFileGenerator 119 | Settings.Designer.cs 120 | 121 | 122 | True 123 | Settings.settings 124 | True 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | {be8465a3-f65a-4d0f-88fb-56062758922e} 133 | CL.IO.Zip 134 | 135 | 136 | 137 | 138 | False 139 | Microsoft .NET Framework 4.5.2 %28x86 和 x64%29 140 | true 141 | 142 | 143 | False 144 | .NET Framework 3.5 SP1 145 | false 146 | 147 | 148 | 149 | 156 | -------------------------------------------------------------------------------- /MIUI_Theme_Magiskizer.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | C:\Users\cjyby\Desktop\MIUI\|publish\ 5 | 6 | 7 | 8 | 9 | 10 | zh-CN 11 | false 12 | 13 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace MIUI_Theme_Magiskizer 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// 应用程序的主入口点。 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new frm_Main()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("MIUI_Theme_Magiskizer")] 9 | [assembly: AssemblyDescription("MIUI主题Magisk模块化工具")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("MIUI_Theme_Magiskizer")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | //将 ComVisible 设置为 false 将使此程序集中的类型 18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("3d5a3937-a76b-4f07-8474-cc2c9951c81a")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.3")] 36 | [assembly: AssemblyFileVersion("1.0.0.3")] 37 | -------------------------------------------------------------------------------- /Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace MIUI_Theme_Magiskizer.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MIUI_Theme_Magiskizer.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 使用此强类型资源类,为所有资源查找 51 | /// 重写当前线程的 CurrentUICulture 属性。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace MIUI_Theme_Magiskizer.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Properties/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 54 | 55 | 69 | -------------------------------------------------------------------------------- /frm_Editor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | using System.IO; 10 | 11 | namespace MIUI_Theme_Magiskizer 12 | { 13 | public partial class frm_Editor : Form 14 | { 15 | public static string tmpPath = Application.UserAppDataPath + @"\temp"; 16 | public string unitPath=tmpPath + @"\unitTmp"; 17 | 18 | public frm_Editor() 19 | { 20 | InitializeComponent(); 21 | LoadFilesAndDirectoriesToTree(unitPath,treeFile.Nodes); 22 | } 23 | 24 | private void LoadFilesAndDirectoriesToTree(string path, TreeNodeCollection treeNodeCollection) 25 | { 26 | string[] files = Directory.GetFiles(path); 27 | string[] dirs = Directory.GetDirectories(path); 28 | foreach (string item in files) 29 | { 30 | treeNodeCollection.Add(Path.GetFileName(item)); 31 | } 32 | foreach (string item in dirs) 33 | { 34 | TreeNode node = treeNodeCollection.Add(Path.GetFileName(item)); 35 | LoadFilesAndDirectoriesToTree(item, node.Nodes); 36 | } 37 | 38 | } 39 | 40 | private void 导入文件ToolStripMenuItem_Click(object sender, EventArgs e) 41 | { 42 | 43 | } 44 | 45 | private void 保存ToolStripMenuItem_Click(object sender, EventArgs e) 46 | { 47 | 48 | } 49 | 50 | private void 退出编辑ToolStripMenuItem_Click(object sender, EventArgs e) 51 | { 52 | Close(); 53 | } 54 | 55 | private void 导出ToolStripMenuItem_Click(object sender, EventArgs e) 56 | { 57 | 58 | } 59 | 60 | private void 删除ToolStripMenuItem_Click(object sender, EventArgs e) 61 | { 62 | treeFile.SelectedNode.Remove(); 63 | } 64 | 65 | private void treeFile_MouseClick(object sender, MouseEventArgs e) 66 | { 67 | if (e.Button == MouseButtons.Right && treeFile.SelectedNode == null) 68 | { 69 | 导出ToolStripMenuItem.Enabled = false; 70 | 删除ToolStripMenuItem.Enabled = false; 71 | } 72 | else 73 | { 74 | 导出ToolStripMenuItem.Enabled = true; 75 | 删除ToolStripMenuItem.Enabled = true; 76 | } 77 | 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /frm_Editor.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 328, 22 122 | 123 | 124 | 9, 19 125 | 126 | 127 | 110, 22 128 | 129 | 130 | 208, 22 131 | 132 | 133 | 52 134 | 135 | -------------------------------------------------------------------------------- /magiskTemplate/.gitattributes: -------------------------------------------------------------------------------- 1 | # Declare files that will always have LF line endings on checkout. 2 | META-INF/** text eol=lf 3 | *.prop text eol=lf 4 | *.sh text eol=lf 5 | *.md text eol=lf 6 | 7 | # Denote all files that are truly binary and should not be modified. 8 | system/** binary 9 | -------------------------------------------------------------------------------- /magiskTemplate/META-INF/com/google/android/update-binary: -------------------------------------------------------------------------------- 1 | #!/sbin/sh 2 | ########################################################################################## 3 | # 4 | # Magisk 模块安装脚本模板 5 | # by topjohnwu 6 | # 翻译: cjybyjk 7 | # 8 | ########################################################################################## 9 | 10 | TMPDIR=/dev/tmp 11 | INSTALLER=$TMPDIR/install 12 | # 总在 tmp 下挂载 13 | MOUNTPATH=$TMPDIR/magisk_img 14 | 15 | # 默认权限 16 | umask 022 17 | 18 | # 清除工作 19 | rm -rf $TMPDIR 2>/dev/null 20 | mkdir -p $INSTALLER 21 | 22 | # 在加载 util_functions 前 echo 23 | ui_print() { echo "$1"; } 24 | 25 | require_new_magisk() { 26 | ui_print "*******************************" 27 | ui_print " 请安装 Magisk v17.0+! " 28 | ui_print "*******************************" 29 | exit 1 30 | } 31 | 32 | ########################################################################################## 33 | # 环境设置 34 | ########################################################################################## 35 | 36 | OUTFD=$2 37 | ZIP=$3 38 | 39 | mount /data 2>/dev/null 40 | 41 | # 加载公用函数 42 | if [ -f /data/adb/magisk/util_functions.sh ]; then 43 | . /data/adb/magisk/util_functions.sh 44 | elif [ -f /data/magisk/util_functions.sh ]; then 45 | NVBASE=/data 46 | . /data/magisk/util_functions.sh 47 | else 48 | require_new_magisk 49 | fi 50 | 51 | # 如果处于 BOOTMODE(系统模式),则使用替代镜像 52 | $BOOTMODE && IMG=$NVBASE/magisk_merge.img 53 | 54 | # 准备卡刷 zip 包 55 | setup_flashable 56 | 57 | # 挂载分区 58 | mount_partitions 59 | 60 | # 检测版本和架构 61 | api_level_arch_detect 62 | 63 | # 你可以从 $API 取得 Android API 版本, 从 $ARCH 取得 CPU 架构 64 | # 如果您正在创建依赖特定 Android版本/平台 的模块,这是非常有用的 65 | 66 | # 安装 busybox 和二进制文件 67 | $BOOTMODE && boot_actions || recovery_actions 68 | 69 | ########################################################################################## 70 | # 准备 71 | ########################################################################################## 72 | 73 | # 提取公共文件 74 | unzip -o "$ZIP" module.prop config.sh 'common/*' -d $INSTALLER >&2 75 | 76 | [ ! -f $INSTALLER/config.sh ] && abort "! 从 zip 中提取文件失败!" 77 | # 加载设置 78 | . $INSTALLER/config.sh 79 | 80 | # 检查已安装的 Magisk 版本 81 | MIN_VER=`grep_prop minMagisk $INSTALLER/module.prop` 82 | [ ! -z $MAGISK_VER_CODE -a $MAGISK_VER_CODE -ge $MIN_VER ] || require_new_magisk 83 | MODID=`grep_prop id $INSTALLER/module.prop` 84 | MODPATH=$MOUNTPATH/$MODID 85 | 86 | # 打印模块名称 87 | print_modname 88 | 89 | # 请将这个信息保留在您的 zip 卡刷包中 :) 90 | ui_print "******************************" 91 | ui_print "Powered by Magisk (@topjohnwu)" 92 | ui_print "******************************" 93 | 94 | ########################################################################################## 95 | # 安装 96 | ########################################################################################## 97 | 98 | # 获取变量 reqSizeM。如果需要,可以使用自己的方法来确定 reqSizeM 99 | # reqSizeM 为安装这个模块需要的空间大小, 单位MB 100 | request_zip_size_check "$ZIP" 101 | 102 | # 这个函数将挂载 $IMG 到 $MOUNTPATH,并根据 $reqSizeM 调整镜像大小 103 | mount_magisk_img 104 | 105 | # 创建模块路径 106 | rm -rf $MODPATH 2>/dev/null 107 | mkdir -p $MODPATH 108 | 109 | # 将文件解压缩到 system 。如果需要,可以使用自己的方法 110 | ui_print "- 正在解压模块文件" 111 | unzip -o "$ZIP" 'system/*' -d $MODPATH >&2 112 | 113 | # 删除 placeholder 114 | rm -f $MODPATH/system/placeholder 2>/dev/null 115 | 116 | # 处理 replace 文件夹 117 | for TARGET in $REPLACE; do 118 | mktouch $MODPATH$TARGET/.replace 119 | done 120 | 121 | # 自动挂载 122 | $AUTOMOUNT && touch $MODPATH/auto_mount 123 | 124 | # prop 文件 125 | $PROPFILE && cp -af $INSTALLER/common/system.prop $MODPATH/system.prop 126 | 127 | # 模块信息 128 | cp -af $INSTALLER/module.prop $MODPATH/module.prop 129 | if $BOOTMODE; then 130 | # 为 Magisk Manager 更新信息 131 | mktouch /sbin/.core/img/$MODID/update 132 | cp -af $INSTALLER/module.prop /sbin/.core/img/$MODID/module.prop 133 | fi 134 | 135 | # post-fs-data 模式脚本 136 | $POSTFSDATA && cp -af $INSTALLER/common/post-fs-data.sh $MODPATH/post-fs-data.sh 137 | 138 | # service 模式脚本 139 | $LATESTARTSERVICE && cp -af $INSTALLER/common/service.sh $MODPATH/service.sh 140 | 141 | ui_print "- 移动文件......" 142 | move_files 143 | 144 | ui_print "- 正在设置权限" 145 | set_permissions 146 | 147 | ########################################################################################## 148 | # 结束 149 | ########################################################################################## 150 | 151 | # 卸载 magisk 镜像, 并尽可能地缩小它 152 | unmount_magisk_img 153 | 154 | $BOOTMODE || recovery_cleanup 155 | rm -rf $TMPDIR 156 | 157 | ui_print "- 完成" 158 | exit 0 159 | -------------------------------------------------------------------------------- /magiskTemplate/META-INF/com/google/android/updater-script: -------------------------------------------------------------------------------- 1 | #MAGISK 2 | -------------------------------------------------------------------------------- /magiskTemplate/common/list_of_moving_files: -------------------------------------------------------------------------------- 1 | wallpaper/default_wallpaper.jpg -> system/media/wallpaper/wallpaper_99.jpg 2 | wallpaper/default_lock_wallpaper.jpg -> system/media/lockscreen/lockscreen_99.jpg 3 | bootanimation -> system/media/bootanimation.zip 4 | fonts -> system/ 5 | boots/* -> system/media/ -------------------------------------------------------------------------------- /magiskTemplate/config.sh: -------------------------------------------------------------------------------- 1 | ########################################################################################## 2 | # 3 | # MIUI主题 Magisk模块配置脚本 4 | # author: cjybyjk 5 | # 6 | ########################################################################################## 7 | 8 | ########################################################################################## 9 | # 配置 10 | ########################################################################################## 11 | 12 | # 如果您需要启用 Magic Mount, 请把它设置为 true 13 | # 大多数模块都需要启用它 14 | AUTOMOUNT=true 15 | 16 | # 如果您需要加载 system.prop, 请把它设置为 true 17 | PROPFILE=false 18 | 19 | # 如果您需要执行 post-fs-data 脚本, 请把它设置为 true 20 | POSTFSDATA=false 21 | 22 | # 如果您需要执行 service 脚本, 请把它设置为 true 23 | LATESTARTSERVICE=false 24 | 25 | ########################################################################################## 26 | # 安装信息 27 | ########################################################################################## 28 | 29 | # 在这里设置您想要在模块安装过程中显示的信息 30 | 31 | print_modname() { 32 | ui_print "*******************************" 33 | ui_print " MIUI_Theme_Module" 34 | ui_print "Created by MIUI_Theme_Magiskizer" 35 | ui_print "*******************************" 36 | } 37 | 38 | ########################################################################################## 39 | # 替换列表 40 | ########################################################################################## 41 | 42 | # 列出您想在系统中直接替换的所有目录 43 | # 查看文档,了解更多关于Magic Mount如何工作的信息,以及您为什么需要它 44 | 45 | # 这是个示例 46 | REPLACE=" 47 | /system/app/Youtube 48 | /system/priv-app/SystemUI 49 | /system/priv-app/Settings 50 | /system/framework 51 | " 52 | 53 | # 在这里构建您自己的列表,它将覆盖上面的示例 54 | # 如果你不需要替换任何东西,!千万不要! 删除它,让它保持现在的状态 55 | REPLACE=" 56 | " 57 | 58 | ########################################################################################## 59 | # 权限设置 60 | ########################################################################################## 61 | 62 | set_permissions() { 63 | # 只有一些特殊文件需要特定的权限 64 | # 默认的权限应该适用于大多数情况 65 | 66 | # 下面是 set_perm 函数的一些示例: 67 | 68 | # set_perm_recursive <目录> <所有者> <用户组> <目录权限> <文件权限> <上下文> (默认值是: u:object_r:system_file:s0) 69 | # set_perm_recursive $MODPATH/system/lib 0 0 0755 0644 70 | 71 | # set_perm <文件名> <所有者> <用户组> <文件权限> <上下文> (默认值是: u:object_r:system_file:s0) 72 | # set_perm $MODPATH/system/bin/app_process32 0 2000 0755 u:object_r:zygote_exec:s0 73 | # set_perm $MODPATH/system/bin/dex2oat 0 2000 0755 u:object_r:dex2oat_exec:s0 74 | # set_perm $MODPATH/system/lib/libart.so 0 0 0644 75 | 76 | # 以下是默认权限,请勿删除 77 | set_perm_recursive $MODPATH 0 0 0755 0644 78 | } 79 | 80 | ########################################################################################## 81 | # 自定义函数 82 | ########################################################################################## 83 | 84 | # 这个文件 (config.sh) 将被安装脚本在 util_functions.sh 之后 source 化(设置为环境变量) 85 | # 如果你需要自定义操作, 请在这里以函数方式定义它们, 然后在 update-binary 里调用这些函数 86 | # 不要直接向 update-binary 添加代码,因为这会让您很难将模块迁移到新的模板版本 87 | # 尽量不要对 update-binary 文件做其他修改,尽量只在其中执行函数调用 88 | 89 | # 移动指定的文件 90 | move_files() { 91 | while read lineinText 92 | do 93 | sourceFile='system/media/theme/default/'`echo $lineinText | awk -F ' -> ' '{print \$1}'` 94 | pathtofile=`echo $lineinText | awk -F ' -> ' '{print \$2}'` 95 | filepath=${pathtofile%/*} 96 | if [ -f "$MODPATH/$sourceFile" ]; then 97 | mkdir -p $MODPATH/$filepath 98 | mv -f $MODPATH/$sourceFile $MODPATH/$pathtofile 99 | fi 100 | done < $INSTALLER/common/list_of_moving_files 101 | } 102 | -------------------------------------------------------------------------------- /magiskTemplate/module.prop: -------------------------------------------------------------------------------- 1 | id=%id% 2 | name=%name% 3 | version=%version% 4 | versionCode=%versionCode% 5 | author=%author% 6 | description=%description% 7 | minMagisk=17000 8 | -------------------------------------------------------------------------------- /magiskTemplate/system/placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cjybyjk/MIUI_Theme_Magiskizer/ddd108306c0a90988cc70f129c4fac3065192bdf/magiskTemplate/system/placeholder -------------------------------------------------------------------------------- /magiskTemplate_1500.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cjybyjk/MIUI_Theme_Magiskizer/ddd108306c0a90988cc70f129c4fac3065192bdf/magiskTemplate_1500.zip --------------------------------------------------------------------------------