├── .gitignore
├── .nuget
└── packages.config
├── DiskImager.Installer
└── DiskImager.Installer.vdproj
├── DiskImager.sln
├── DiskImager
├── DD-All.ico
├── Detection
│ └── DriveDetector.cs
├── Disk.cs
├── DiskGeometry.cs
├── DiskImager.csproj
├── Enumerations.cs
├── Globals.cs
├── Handle.cs
├── IDiskAccess.cs
├── IHandle.cs
├── MainForm.Designer.cs
├── MainForm.cs
├── MainForm.resx
├── MessageBoxEx.cs
├── NativeMethods.cs
├── Program.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── Utility.cs
├── Win32
│ ├── LinuxDiskAccess.cs
│ └── Win32DiskAccess.cs
└── app.manifest
├── ICSharpCode.SharpZipLib
├── AssemblyInfo.cs
├── 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
├── ICSharpCode.SharpZLib.csproj
├── ICSharpCode.SharpZLib.prjx
├── Lzw
│ ├── LzwConstants.cs
│ ├── LzwException.cs
│ └── LzwInputStream.cs
├── Main.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
├── LICENSE
├── Libs
└── Libs.csproj
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.sln.docstates
8 |
9 | # Build results
10 |
11 | [Dd]ebug/
12 | [Rr]elease/
13 | x64/
14 | build/
15 | [Bb]in/
16 | [Oo]bj/
17 |
18 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
19 | !packages/*/build/
20 |
21 | # MSTest test Results
22 | [Tt]est[Rr]esult*/
23 | [Bb]uild[Ll]og.*
24 |
25 | *_i.c
26 | *_p.c
27 | *.ilk
28 | *.meta
29 | *.obj
30 | *.pch
31 | *.pdb
32 | *.pgc
33 | *.pgd
34 | *.rsp
35 | *.sbr
36 | *.tlb
37 | *.tli
38 | *.tlh
39 | *.tmp
40 | *.tmp_proj
41 | *.log
42 | *.vspscc
43 | *.vssscc
44 | .builds
45 | *.pidb
46 | *.log
47 | *.scc
48 |
49 | # Visual C++ cache files
50 | ipch/
51 | *.aps
52 | *.ncb
53 | *.opensdf
54 | *.sdf
55 | *.cachefile
56 |
57 | # Visual Studio profiler
58 | *.psess
59 | *.vsp
60 | *.vspx
61 |
62 | # Guidance Automation Toolkit
63 | *.gpState
64 |
65 | # ReSharper is a .NET coding add-in
66 | _ReSharper*/
67 | *.[Rr]e[Ss]harper
68 |
69 | # TeamCity is a build add-in
70 | _TeamCity*
71 |
72 | # DotCover is a Code Coverage Tool
73 | *.dotCover
74 |
75 | # NCrunch
76 | *.ncrunch*
77 | .*crunch*.local.xml
78 |
79 | # Installshield output folder
80 | [Ee]xpress/
81 |
82 | # DocProject is a documentation generator add-in
83 | DocProject/buildhelp/
84 | DocProject/Help/*.HxT
85 | DocProject/Help/*.HxC
86 | DocProject/Help/*.hhc
87 | DocProject/Help/*.hhk
88 | DocProject/Help/*.hhp
89 | DocProject/Help/Html2
90 | DocProject/Help/html
91 |
92 | # Click-Once directory
93 | publish/
94 |
95 | # Publish Web Output
96 | *.Publish.xml
97 | *.pubxml
98 |
99 | # NuGet Packages Directory
100 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
101 | #packages/
102 |
103 | # Windows Azure Build Output
104 | csx
105 | *.build.csdef
106 |
107 | # Windows Store app package directory
108 | AppPackages/
109 |
110 | # Others
111 | sql/
112 | *.Cache
113 | ClientBin/
114 | [Ss]tyle[Cc]op.*
115 | ~$*
116 | *~
117 | *.dbmdl
118 | *.[Pp]ublish.xml
119 | *.pfx
120 | *.publishsettings
121 |
122 | # RIA/Silverlight projects
123 | Generated_Code/
124 |
125 | # Backup & report files from converting an old project file to a newer
126 | # Visual Studio version. Backup files are not needed, because we have git ;-)
127 | _UpgradeReport_Files/
128 | Backup*/
129 | UpgradeLog*.XML
130 | UpgradeLog*.htm
131 |
132 | # SQL Server files
133 | App_Data/*.mdf
134 | App_Data/*.ldf
135 |
136 | # =========================
137 | # Windows detritus
138 | # =========================
139 |
140 | # Windows image file caches
141 | Thumbs.db
142 | ehthumbs.db
143 |
144 | # Folder config file
145 | Desktop.ini
146 |
147 | # Recycle Bin used on file shares
148 | $RECYCLE.BIN/
149 |
150 | # Mac crap
151 | .DS_Store
152 |
--------------------------------------------------------------------------------
/.nuget/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/DiskImager.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiskImager", "DiskImager\DiskImager.csproj", "{4A73C63C-2BF2-4F85-AA55-A5CA581A33B4}"
5 | EndProject
6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0FB24EA0-02E1-48C7-852F-CF51898CCF93}"
7 | ProjectSection(SolutionItems) = preProject
8 | LICENSE = LICENSE
9 | README.md = README.md
10 | EndProjectSection
11 | EndProject
12 | Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "DiskImager.Installer", "DiskImager.Installer\DiskImager.Installer.vdproj", "{001C286E-8D1F-4B60-8E76-FF20CDE63C39}"
13 | EndProject
14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libs", "Libs\Libs.csproj", "{1B0F140A-DFA6-4693-9C09-FCB9E0B35189}"
15 | EndProject
16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{19CD6AEC-F046-48F6-8C68-E4C460CCAE47}"
17 | ProjectSection(SolutionItems) = preProject
18 | .nuget\packages.config = .nuget\packages.config
19 | EndProjectSection
20 | EndProject
21 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpZLib", "ICSharpCode.SharpZipLib\ICSharpCode.SharpZLib.csproj", "{0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}"
22 | EndProject
23 | Global
24 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
25 | Debug|Any CPU = Debug|Any CPU
26 | Debug|Mixed Platforms = Debug|Mixed Platforms
27 | Debug|x86 = Debug|x86
28 | Release|Any CPU = Release|Any CPU
29 | Release|Mixed Platforms = Release|Mixed Platforms
30 | Release|x86 = Release|x86
31 | EndGlobalSection
32 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
33 | {4A73C63C-2BF2-4F85-AA55-A5CA581A33B4}.Debug|Any CPU.ActiveCfg = Debug|x86
34 | {4A73C63C-2BF2-4F85-AA55-A5CA581A33B4}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
35 | {4A73C63C-2BF2-4F85-AA55-A5CA581A33B4}.Debug|Mixed Platforms.Build.0 = Debug|x86
36 | {4A73C63C-2BF2-4F85-AA55-A5CA581A33B4}.Debug|x86.ActiveCfg = Debug|x86
37 | {4A73C63C-2BF2-4F85-AA55-A5CA581A33B4}.Debug|x86.Build.0 = Debug|x86
38 | {4A73C63C-2BF2-4F85-AA55-A5CA581A33B4}.Release|Any CPU.ActiveCfg = Release|x86
39 | {4A73C63C-2BF2-4F85-AA55-A5CA581A33B4}.Release|Mixed Platforms.ActiveCfg = Release|x86
40 | {4A73C63C-2BF2-4F85-AA55-A5CA581A33B4}.Release|Mixed Platforms.Build.0 = Release|x86
41 | {4A73C63C-2BF2-4F85-AA55-A5CA581A33B4}.Release|x86.ActiveCfg = Release|x86
42 | {4A73C63C-2BF2-4F85-AA55-A5CA581A33B4}.Release|x86.Build.0 = Release|x86
43 | {001C286E-8D1F-4B60-8E76-FF20CDE63C39}.Debug|Any CPU.ActiveCfg = Debug
44 | {001C286E-8D1F-4B60-8E76-FF20CDE63C39}.Debug|Any CPU.Build.0 = Debug
45 | {001C286E-8D1F-4B60-8E76-FF20CDE63C39}.Debug|Mixed Platforms.ActiveCfg = Debug
46 | {001C286E-8D1F-4B60-8E76-FF20CDE63C39}.Debug|Mixed Platforms.Build.0 = Debug
47 | {001C286E-8D1F-4B60-8E76-FF20CDE63C39}.Debug|x86.ActiveCfg = Debug
48 | {001C286E-8D1F-4B60-8E76-FF20CDE63C39}.Release|Any CPU.ActiveCfg = Release
49 | {001C286E-8D1F-4B60-8E76-FF20CDE63C39}.Release|Any CPU.Build.0 = Release
50 | {001C286E-8D1F-4B60-8E76-FF20CDE63C39}.Release|Mixed Platforms.ActiveCfg = Release
51 | {001C286E-8D1F-4B60-8E76-FF20CDE63C39}.Release|Mixed Platforms.Build.0 = Release
52 | {001C286E-8D1F-4B60-8E76-FF20CDE63C39}.Release|x86.ActiveCfg = Release
53 | {1B0F140A-DFA6-4693-9C09-FCB9E0B35189}.Debug|Any CPU.ActiveCfg = Debug|x86
54 | {1B0F140A-DFA6-4693-9C09-FCB9E0B35189}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
55 | {1B0F140A-DFA6-4693-9C09-FCB9E0B35189}.Debug|x86.ActiveCfg = Debug|x86
56 | {1B0F140A-DFA6-4693-9C09-FCB9E0B35189}.Release|Any CPU.ActiveCfg = Release|x86
57 | {1B0F140A-DFA6-4693-9C09-FCB9E0B35189}.Release|Mixed Platforms.ActiveCfg = Release|x86
58 | {1B0F140A-DFA6-4693-9C09-FCB9E0B35189}.Release|x86.ActiveCfg = Release|x86
59 | {0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
60 | {0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
61 | {0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
62 | {0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
63 | {0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}.Debug|x86.ActiveCfg = Debug|Any CPU
64 | {0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
65 | {0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}.Release|Any CPU.Build.0 = Release|Any CPU
66 | {0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
67 | {0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}.Release|Mixed Platforms.Build.0 = Release|Any CPU
68 | {0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}.Release|x86.ActiveCfg = Release|Any CPU
69 | EndGlobalSection
70 | GlobalSection(SolutionProperties) = preSolution
71 | HideSolutionNode = FALSE
72 | EndGlobalSection
73 | GlobalSection(ExtensibilityGlobals) = postSolution
74 | VisualSVNWorkingCopyRoot = .
75 | EndGlobalSection
76 | EndGlobal
77 |
--------------------------------------------------------------------------------
/DiskImager/DD-All.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DynamicDevices/DiskImager/fbd1ab3430537c0042de63341568a0fec28fcb21/DiskImager/DD-All.ico
--------------------------------------------------------------------------------
/DiskImager/DiskGeometry.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 |
3 | namespace DynamicDevices.DiskWriter
4 | {
5 | [StructLayout(LayoutKind.Sequential)]
6 | internal struct DiskGeometry
7 | {
8 | public long Cylinders;
9 | public int MediaType;
10 | public int TracksPerCylinder;
11 | public int SectorsPerTrack;
12 | public int BytesPerSector;
13 | }
14 |
15 | [StructLayout(LayoutKind.Sequential)]
16 | internal struct DiskGeometryEx
17 | {
18 | public DiskGeometry Geometry;
19 | public long DiskSize;
20 | public byte Data;
21 | }
22 |
23 | [StructLayout(LayoutKind.Sequential)]
24 | internal struct DISK_EXTENT
25 | {
26 | public int DiskNumber;
27 | public ulong StartingOffset;
28 | public ulong ExtentLength;
29 | }
30 |
31 | [StructLayout(LayoutKind.Sequential)]
32 | internal struct VolumeDiskExtents
33 | {
34 | public uint NumberOfDiskExtents;
35 | public DISK_EXTENT DiskExtent1;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/DiskImager/DiskImager.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | x86
6 | 8.0.30703
7 | 2.0
8 | {4A73C63C-2BF2-4F85-AA55-A5CA581A33B4}
9 | WinExe
10 | Properties
11 | DynamicDevices.DiskWriter
12 | DiskImager
13 | v4.0
14 | Client
15 | 512
16 | publish\
17 | true
18 | Disk
19 | false
20 | Foreground
21 | 7
22 | Days
23 | false
24 | false
25 | true
26 | 0
27 | 1.0.0.%2a
28 | false
29 | false
30 | true
31 |
32 |
33 | x86
34 | true
35 | full
36 | false
37 | bin\Debug\
38 | DEBUG;TRACE
39 | prompt
40 | 4
41 |
42 |
43 | x86
44 | pdbonly
45 | true
46 | bin\Release\
47 | TRACE
48 | prompt
49 | 4
50 |
51 |
52 | DD-All.ico
53 |
54 |
55 | app.manifest
56 |
57 |
58 | Always
59 |
60 |
61 | false
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 | Form
83 |
84 |
85 |
86 |
87 |
88 |
89 | Form
90 |
91 |
92 | MainForm.cs
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 | MainForm.cs
106 |
107 |
108 | ResXFileCodeGenerator
109 | Resources.Designer.cs
110 | Designer
111 |
112 |
113 | True
114 | Resources.resx
115 | True
116 |
117 |
118 |
119 | SettingsSingleFileGenerator
120 | Settings.Designer.cs
121 |
122 |
123 | True
124 | Settings.settings
125 | True
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 | False
134 | Microsoft .NET Framework 4 Client Profile %28x86 and x64%29
135 | true
136 |
137 |
138 | False
139 | .NET Framework 3.5 SP1 Client Profile
140 | false
141 |
142 |
143 | False
144 | .NET Framework 3.5 SP1
145 | false
146 |
147 |
148 | False
149 | Windows Installer 3.1
150 | true
151 |
152 |
153 |
154 |
155 | {0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}
156 | ICSharpCode.SharpZLib
157 |
158 |
159 |
160 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 | $(ProjectDir)$(OutDir)DiskImager-merged.exe
176 |
177 |
178 |
179 |
180 |
--------------------------------------------------------------------------------
/DiskImager/Enumerations.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace DynamicDevices.DiskWriter
3 | {
4 | public enum EnumCompressionType
5 | {
6 | None = 0,
7 | Zip = 1,
8 | Gzip = 2,
9 | Targzip = 3
10 | }
11 | }
--------------------------------------------------------------------------------
/DiskImager/Globals.cs:
--------------------------------------------------------------------------------
1 | namespace DynamicDevices.DiskWriter
2 | {
3 | internal class Globals
4 | {
5 | private const int MAX_BUFFER_SIZE = 1 * 1024 * 1024;
6 | private const int DEFAULT_COMPRESSION_LEVEL = 3;
7 |
8 | private static int _maxBufferSize = MAX_BUFFER_SIZE;
9 | private static int _compressionLevel = DEFAULT_COMPRESSION_LEVEL;
10 |
11 | public static int MaxBufferSize { get { return _maxBufferSize; } set { _maxBufferSize = value; } }
12 |
13 | public static int CompressionLevel { get { return _compressionLevel; } set { _compressionLevel = value; } }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/DiskImager/Handle.cs:
--------------------------------------------------------------------------------
1 | namespace DynamicDevices.DiskWriter
2 | {
3 | internal class Handle : IHandle
4 | {
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/DiskImager/IDiskAccess.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DynamicDevices.DiskWriter
4 | {
5 | internal interface IDiskAccess
6 | {
7 | event TextHandler OnLogMsg;
8 |
9 | event ProgressHandler OnProgress;
10 |
11 | Handle Open(string drivePath);
12 |
13 | bool LockDrive(string drivePath);
14 |
15 | void UnlockDrive();
16 |
17 | int Read(byte[] buffer, int readMaxLength, out int readBytes);
18 |
19 | int Write(byte[] buffer, int bytesToWrite, out int wroteBytes);
20 |
21 | void Close();
22 |
23 | string GetPhysicalPathForLogicalPath(string logicalPath);
24 |
25 | long GetDriveSize(string drivePath);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/DiskImager/IHandle.cs:
--------------------------------------------------------------------------------
1 | namespace DynamicDevices.DiskWriter
2 | {
3 | internal interface IHandle
4 | {
5 |
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/DiskImager/MainForm.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 | 17, 17
122 |
123 |
124 | 273, 17
125 |
126 |
127 | 409, 17
128 |
129 |
--------------------------------------------------------------------------------
/DiskImager/MessageBoxEx.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 | using System.Text;
4 | using System.Drawing;
5 | using System.Runtime.InteropServices;
6 |
7 | namespace DynamicDevices.DiskWriter
8 | {
9 | public class MessageBoxEx
10 | {
11 | private static readonly HookProc _hookProc;
12 | private static IntPtr _hHook;
13 |
14 | public static IntPtr Owner { get; set; }
15 | public static DialogResult Show(string text)
16 | {
17 | Initialize();
18 | return MessageBox.Show(text);
19 | }
20 |
21 | public static DialogResult Show(string text, string caption)
22 | {
23 | Initialize();
24 | return MessageBox.Show(text, caption);
25 | }
26 |
27 | public static DialogResult Show(string text, string caption, MessageBoxButtons buttons)
28 | {
29 | Initialize();
30 | return MessageBox.Show(text, caption, buttons);
31 | }
32 |
33 | public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
34 | {
35 | Initialize();
36 | return MessageBox.Show(text, caption, buttons, icon);
37 | }
38 |
39 | public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defButton)
40 | {
41 | Initialize();
42 | return MessageBox.Show(text, caption, buttons, icon, defButton);
43 | }
44 |
45 | public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defButton, MessageBoxOptions options)
46 | {
47 | Initialize();
48 | return MessageBox.Show(text, caption, buttons, icon, defButton, options);
49 | }
50 |
51 | public delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam);
52 |
53 | public delegate void TimerProc(IntPtr hWnd, uint uMsg, UIntPtr nIdEvent, uint dwTime);
54 |
55 | public const int WH_CALLWNDPROCRET = 12;
56 |
57 | public enum CbtHookAction : int
58 | {
59 | HCBT_MOVESIZE = 0,
60 | HCBT_MINMAX = 1,
61 | HCBT_QS = 2,
62 | HCBT_CREATEWND = 3,
63 | HCBT_DESTROYWND = 4,
64 | HCBT_ACTIVATE = 5,
65 | HCBT_CLICKSKIPPED = 6,
66 | HCBT_KEYSKIPPED = 7,
67 | HCBT_SYSCOMMAND = 8,
68 | HCBT_SETFOCUS = 9
69 | }
70 |
71 | [DllImport("user32.dll")]
72 | private static extern bool GetWindowRect(IntPtr hWnd, ref Rectangle lpRect);
73 |
74 | [DllImport("user32.dll")]
75 | private static extern int MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
76 |
77 | [DllImport("User32.dll")]
78 | public static extern UIntPtr SetTimer(IntPtr hWnd, UIntPtr nIDEvent, uint uElapse, TimerProc lpTimerFunc);
79 |
80 | [DllImport("User32.dll")]
81 | public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
82 |
83 | [DllImport("user32.dll")]
84 | public static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
85 |
86 | [DllImport("user32.dll")]
87 | public static extern int UnhookWindowsHookEx(IntPtr idHook);
88 |
89 | [DllImport("user32.dll")]
90 | public static extern IntPtr CallNextHookEx(IntPtr idHook, int nCode, IntPtr wParam, IntPtr lParam);
91 |
92 | [DllImport("user32.dll")]
93 | public static extern int GetWindowTextLength(IntPtr hWnd);
94 |
95 | [DllImport("user32.dll")]
96 | public static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int maxLength);
97 |
98 | [DllImport("user32.dll")]
99 | public static extern int EndDialog(IntPtr hDlg, IntPtr nResult);
100 |
101 | [StructLayout(LayoutKind.Sequential)]
102 | public struct CWPRETSTRUCT
103 | {
104 | public IntPtr lResult;
105 | public IntPtr lParam;
106 | public IntPtr wParam;
107 | public uint message;
108 | public IntPtr hwnd;
109 | } ;
110 |
111 | static MessageBoxEx()
112 | {
113 | _hookProc = new HookProc(MessageBoxHookProc);
114 | _hHook = IntPtr.Zero;
115 | }
116 |
117 | private static void Initialize()
118 | {
119 | if (_hHook != IntPtr.Zero)
120 | {
121 | throw new NotSupportedException("multiple calls are not supported");
122 | }
123 |
124 | if (Owner != IntPtr.Zero)
125 | {
126 | #pragma warning disable 612,618
127 | _hHook = SetWindowsHookEx(WH_CALLWNDPROCRET, _hookProc, IntPtr.Zero, AppDomain.GetCurrentThreadId());
128 | #pragma warning restore 612,618
129 | }
130 | }
131 |
132 | private static IntPtr MessageBoxHookProc(int nCode, IntPtr wParam, IntPtr lParam)
133 | {
134 | if (nCode < 0)
135 | {
136 | return CallNextHookEx(_hHook, nCode, wParam, lParam);
137 | }
138 |
139 | var msg = (CWPRETSTRUCT)Marshal.PtrToStructure(lParam, typeof(CWPRETSTRUCT));
140 | IntPtr hook = _hHook;
141 |
142 | if (msg.message == (int)CbtHookAction.HCBT_ACTIVATE)
143 | {
144 | try
145 | {
146 | CenterWindow(msg.hwnd);
147 | }
148 | finally
149 | {
150 | UnhookWindowsHookEx(_hHook);
151 | _hHook = IntPtr.Zero;
152 | }
153 | }
154 |
155 | return CallNextHookEx(hook, nCode, wParam, lParam);
156 | }
157 |
158 | private static void CenterWindow(IntPtr hChildWnd)
159 | {
160 | var recChild = new Rectangle(0, 0, 0, 0);
161 | GetWindowRect(hChildWnd, ref recChild);
162 |
163 | int width = recChild.Width - recChild.X;
164 | int height = recChild.Height - recChild.Y;
165 |
166 | var recParent = new Rectangle(0, 0, 0, 0);
167 | GetWindowRect(Owner, ref recParent);
168 |
169 | var ptCenter = new Point(0, 0);
170 | ptCenter.X = recParent.X + ((recParent.Width - recParent.X) / 2);
171 | ptCenter.Y = recParent.Y + ((recParent.Height - recParent.Y) / 2);
172 |
173 |
174 | var ptStart = new Point(0, 0);
175 | ptStart.X = (ptCenter.X - (width / 2));
176 | ptStart.Y = (ptCenter.Y - (height / 2));
177 |
178 | ptStart.X = (ptStart.X < 0) ? 0 : ptStart.X;
179 | ptStart.Y = (ptStart.Y < 0) ? 0 : ptStart.Y;
180 |
181 | MoveWindow(hChildWnd, ptStart.X, ptStart.Y, width,
182 | height, false);
183 | }
184 |
185 | }
186 | }
187 |
--------------------------------------------------------------------------------
/DiskImager/NativeMethods.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 | using Microsoft.Win32.SafeHandles;
4 |
5 | namespace DynamicDevices.DiskWriter
6 | {
7 |
8 | public enum EMoveMethod : int
9 | {
10 | Begin = 0,
11 | Current = 1,
12 | End = 2
13 | }
14 |
15 | public static class NativeMethods
16 | {
17 | internal const uint OPEN_EXISTING = 3;
18 | internal const uint GENERIC_WRITE = (0x40000000);
19 | internal const uint GENERIC_READ = 0x80000000;
20 | internal const uint FSCTL_LOCK_VOLUME = 0x00090018;
21 | internal const uint FSCTL_UNLOCK_VOLUME = 0x0009001c;
22 | internal const uint FSCTL_DISMOUNT_VOLUME = 0x00090020;
23 | internal const uint FILE_SHARE_READ = 0x1;
24 | internal const uint FILE_SHARE_WRITE = 0x2;
25 | internal const uint IOCTL_DISK_GET_DRIVE_GEOMETRY = 0x70000;
26 | internal const uint IOCTL_DISK_GET_DRIVE_GEOMETRY_EX = 0x700a0;
27 | internal const uint IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS = 0x00560000;
28 | internal const uint IOCTL_STORAGE_GET_DEVICE_NUMBER = 0x2D1080;
29 | internal const uint BCM_SETSHIELD = 0x160C;
30 | internal const int INVALID_SET_FILE_POINTER = -1;
31 |
32 | [DllImport("user32.dll", CharSet = CharSet.Unicode)]
33 | static extern internal IntPtr LoadIcon(IntPtr hInstance, string lpIconName);
34 |
35 | [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
36 | static extern internal IntPtr LoadLibrary(string lpFileName);
37 |
38 | [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
39 | static extern internal int SetFilePointer([In] SafeFileHandle hFile, [In] int lDistanceToMove, ref int lpDistanceToMoveHigh, [In] EMoveMethod dwMoveMethod);
40 |
41 | [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
42 | static extern internal SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
43 |
44 | [DllImport("kernel32", SetLastError = true)]
45 | static extern internal int ReadFile(SafeFileHandle handle, byte[] bytes, int numBytesToRead, out int numBytesRead, IntPtr overlapped_MustBeZero);
46 |
47 | [DllImport("kernel32.dll", SetLastError = true)]
48 | static extern internal int WriteFile(SafeFileHandle handle, byte[] bytes, int numBytesToWrite, out int numBytesWritten, IntPtr overlapped_MustBeZero);
49 |
50 | [DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
51 | static extern internal bool DeviceIoControl(SafeFileHandle hDevice, uint dwIoControlCode, byte[] lpInBuffer, int nInBufferSize, byte[] lpOutBuffer, int nOutBufferSize, out int lpBytesReturned, IntPtr lpOverlapped);
52 |
53 | [DllImport("Kernel32.dll", SetLastError = false, CharSet = CharSet.Auto)]
54 | public static extern bool DeviceIoControl(SafeFileHandle device, uint dwIoControlCode, IntPtr inBuffer, uint inBufferSize, IntPtr outBuffer, uint outBufferSize, ref uint bytesReturned, IntPtr overlapped);
55 |
56 | [DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
57 | static extern internal bool CloseHandle(SafeFileHandle handle);
58 |
59 | [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)]
60 | static extern int SendMessage(IntPtr hWnd, UInt32 Msg, int wParam, IntPtr lParam);
61 |
62 | }
63 | }
--------------------------------------------------------------------------------
/DiskImager/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | namespace DynamicDevices.DiskWriter
5 | {
6 | static class Program
7 | {
8 | ///
9 | /// The main entry point for the application.
10 | ///
11 | [STAThread]
12 | static void Main()
13 | {
14 | try
15 | {
16 | Application.EnableVisualStyles();
17 | Application.SetCompatibleTextRenderingDefault(false);
18 | Application.Run(new MainForm());
19 | } catch(Exception e)
20 | {
21 | MessageBox.Show(e.Message + " | " + e.StackTrace);
22 | }
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/DiskImager/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("DiskWriter")]
8 | #if DEBUG
9 | [assembly: AssemblyDescription("Windows Disk Writer - reads/writes images to removable storage (DEBUG BUILD)")]
10 | #else
11 | [assembly: AssemblyDescription("Windows Disk Writer - reads/writes images to removable storage")]
12 | #endif
13 | [assembly: AssemblyConfiguration("")]
14 | [assembly: AssemblyCompany("Dynamic Devices Ltd")]
15 | [assembly: AssemblyProduct("DiskWriter")]
16 | [assembly: AssemblyCopyright("Copyright © Dynamic Devices 2013")]
17 | [assembly: AssemblyTrademark("")]
18 | [assembly: AssemblyCulture("")]
19 |
20 | // Setting ComVisible to false makes the types in this assembly not visible
21 | // to COM components. If you need to access a type in this assembly from
22 | // COM, set the ComVisible attribute to true on that type.
23 | [assembly: ComVisible(false)]
24 |
25 | // The following GUID is for the ID of the typelib if this project is exposed to COM
26 | [assembly: Guid("3a86a357-2384-4264-8f2d-bdddabace819")]
27 |
28 | // Version information for an assembly consists of the following four values:
29 | //
30 | // Major Version
31 | // Minor Version
32 | // Build Number
33 | // Revision
34 | //
35 | // You can specify all the values or you can default the Build and Revision Numbers
36 | // by using the '*' as shown below:
37 | // [assembly: AssemblyVersion("1.0.*")]
38 | [assembly: AssemblyVersion("1.1.3.*")]
39 | [assembly: AssemblyFileVersion("1.1.3.0")]
40 |
--------------------------------------------------------------------------------
/DiskImager/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.34003
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace DynamicDevices.DiskWriter.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
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 | /// Returns the cached ResourceManager instance used by this class.
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("DynamicDevices.DiskWriter.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
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 |
--------------------------------------------------------------------------------
/DiskImager/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 |
--------------------------------------------------------------------------------
/DiskImager/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.34003
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace DynamicDevices.DiskWriter.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.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 |
--------------------------------------------------------------------------------
/DiskImager/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/DiskImager/Utility.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 | using System.Reflection;
4 |
5 | namespace DynamicDevices.DiskWriter
6 | {
7 | internal class Utility
8 | {
9 | public static Icon GetAppIcon()
10 | {
11 | var fileName = Assembly.GetEntryAssembly().Location;
12 |
13 | var hLibrary = NativeMethods.LoadLibrary(fileName);
14 | if (!hLibrary.Equals(IntPtr.Zero))
15 | {
16 | var hIcon = NativeMethods.LoadIcon(hLibrary, "#32512");
17 | if (!hIcon.Equals(IntPtr.Zero))
18 | return Icon.FromHandle(hIcon);
19 | }
20 | return null; //no icon was retrieved
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/DiskImager/Win32/LinuxDiskAccess.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace DynamicDevices.DiskWriter.Win32
7 | {
8 | internal class LinuxDiskAccess : IDiskAccess
9 | {
10 | #region IDiskAccess Members
11 |
12 | public event TextHandler OnLogMsg;
13 |
14 | public event ProgressHandler OnProgress;
15 |
16 | public Handle Open(string drivePath)
17 | {
18 | throw new NotImplementedException();
19 | }
20 |
21 | public bool LockDrive(string drivePath)
22 | {
23 | throw new NotImplementedException();
24 | }
25 |
26 |
27 | public void UnlockDrive()
28 | {
29 | throw new NotImplementedException();
30 | }
31 |
32 | public int Read(byte[] buffer, int readMaxLength, out int readBytes)
33 | {
34 | throw new NotImplementedException();
35 | }
36 |
37 | public int Write(byte[] buffer, int bytesToWrite, out int wroteBytes)
38 | {
39 | throw new NotImplementedException();
40 | }
41 |
42 | public void Close()
43 | {
44 | throw new NotImplementedException();
45 | }
46 |
47 | public string GetPhysicalPathForLogicalPath(string logicalPath)
48 | {
49 | throw new NotImplementedException();
50 | }
51 |
52 | public long GetDriveSize(string drivePath)
53 | {
54 | throw new NotImplementedException();
55 | }
56 |
57 | #endregion
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/DiskImager/Win32/Win32DiskAccess.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 | using Microsoft.Win32.SafeHandles;
4 |
5 | namespace DynamicDevices.DiskWriter.Win32
6 | {
7 | internal class Win32DiskAccess : IDiskAccess
8 | {
9 | #region Fields
10 |
11 | SafeFileHandle _partitionHandle = null;
12 | SafeFileHandle _diskHandle = null;
13 |
14 | #endregion
15 |
16 | #region IDiskAccess Members
17 |
18 | public event TextHandler OnLogMsg;
19 |
20 | public event ProgressHandler OnProgress;
21 |
22 | public event EventHandler OnDiskChanged;
23 |
24 | public Handle Open(string drivePath)
25 | {
26 | int intOut;
27 |
28 | //
29 | // Now that we've dismounted the logical volume mounted on the removable drive we can open up the physical disk to write
30 | //
31 | var diskHandle = NativeMethods.CreateFile(drivePath, NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE, NativeMethods.FILE_SHARE_READ | NativeMethods.FILE_SHARE_WRITE, IntPtr.Zero, NativeMethods.OPEN_EXISTING, 0, IntPtr.Zero);
32 | if (diskHandle.IsInvalid)
33 | {
34 | LogMsg(@"Failed to open device: " + Marshal.GetHRForLastWin32Error());
35 | return null;
36 | }
37 |
38 | var success = NativeMethods.DeviceIoControl(diskHandle, NativeMethods.FSCTL_LOCK_VOLUME, null, 0, null, 0, out intOut, IntPtr.Zero);
39 | if (!success)
40 | {
41 | LogMsg(@"Failed to lock device");
42 | diskHandle.Dispose();
43 | return null;
44 | }
45 |
46 | _diskHandle = diskHandle;
47 |
48 | return new Handle();
49 | }
50 |
51 | public bool LockDrive(string drivePath)
52 | {
53 | bool success;
54 | int intOut;
55 | SafeFileHandle partitionHandle;
56 |
57 | //
58 | // Unmount partition (Todo: Note that we currently only handle unmounting of one partition, which is the usual case for SD Cards)
59 | //
60 |
61 | //
62 | // Open the volume
63 | ///
64 | partitionHandle = NativeMethods.CreateFile(@"\\.\" + drivePath, NativeMethods.GENERIC_READ, NativeMethods.FILE_SHARE_READ, IntPtr.Zero, NativeMethods.OPEN_EXISTING, 0, IntPtr.Zero);
65 | if (partitionHandle.IsInvalid)
66 | {
67 | LogMsg(@"Failed to open device");
68 | partitionHandle.Dispose();
69 | return false;
70 | }
71 |
72 | //
73 | // Lock it
74 | //
75 | success = NativeMethods.DeviceIoControl(partitionHandle, NativeMethods.FSCTL_LOCK_VOLUME, null, 0, null, 0, out intOut, IntPtr.Zero);
76 | if (!success)
77 | {
78 | LogMsg(@"Failed to lock device");
79 | partitionHandle.Dispose();
80 | return false;
81 | }
82 |
83 | //
84 | // Dismount it
85 | //
86 | success = NativeMethods.DeviceIoControl(partitionHandle, NativeMethods.FSCTL_DISMOUNT_VOLUME, null, 0, null, 0, out intOut, IntPtr.Zero);
87 | if (!success)
88 | {
89 | LogMsg(@"Error dismounting volume: " + Marshal.GetHRForLastWin32Error());
90 | NativeMethods.DeviceIoControl(partitionHandle, NativeMethods.FSCTL_UNLOCK_VOLUME, null, 0, null, 0, out intOut, IntPtr.Zero);
91 | partitionHandle.Dispose();
92 | return false;
93 | }
94 |
95 | _partitionHandle = partitionHandle;
96 |
97 | return true;
98 | }
99 |
100 |
101 | public void UnlockDrive()
102 | {
103 | if(_partitionHandle != null)
104 | {
105 | _partitionHandle.Dispose();
106 | _partitionHandle = null;
107 | }
108 | }
109 |
110 | public int Read(byte[] buffer, int readMaxLength, out int readBytes)
111 | {
112 | readBytes = 0;
113 |
114 | if(_diskHandle == null)
115 | return -1;
116 |
117 | return NativeMethods.ReadFile(_diskHandle, buffer, readMaxLength, out readBytes, IntPtr.Zero);
118 | }
119 |
120 | public int Write(byte[] buffer, int bytesToWrite, out int wroteBytes)
121 | {
122 | wroteBytes = 0;
123 | if(_diskHandle == null)
124 | return -1;
125 |
126 | return NativeMethods.WriteFile(_diskHandle, buffer, bytesToWrite, out wroteBytes, IntPtr.Zero);
127 | }
128 |
129 | public void Close()
130 | {
131 | if (_diskHandle != null)
132 | {
133 | _diskHandle.Dispose();
134 | _diskHandle = null;
135 | }
136 | }
137 |
138 | public string GetPhysicalPathForLogicalPath(string logicalPath)
139 | {
140 | var diskIndex = -1;
141 |
142 | //
143 | // Now that we've dismounted the logical volume mounted on the removable drive we can open up the physical disk to write
144 | //
145 | var diskHandle = NativeMethods.CreateFile(@"\\.\" + logicalPath, NativeMethods.GENERIC_READ, NativeMethods.FILE_SHARE_READ, IntPtr.Zero, NativeMethods.OPEN_EXISTING, 0, IntPtr.Zero);
146 | if (diskHandle.IsInvalid)
147 | {
148 | LogMsg(@"Failed to open device: " + Marshal.GetHRForLastWin32Error());
149 | return null;
150 | }
151 |
152 | var vdeSize = Marshal.SizeOf(typeof(VolumeDiskExtents));
153 | var vdeBlob = Marshal.AllocHGlobal(vdeSize);
154 | uint numBytesRead = 0;
155 |
156 | var success = NativeMethods.DeviceIoControl(diskHandle, NativeMethods.IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, IntPtr.Zero,
157 | 0, vdeBlob, (uint)vdeSize, ref numBytesRead, IntPtr.Zero);
158 |
159 | var vde = (VolumeDiskExtents)Marshal.PtrToStructure(vdeBlob, typeof(VolumeDiskExtents));
160 | if (success)
161 | {
162 | if (vde.NumberOfDiskExtents == 1)
163 | diskIndex = vde.DiskExtent1.DiskNumber;
164 | }
165 | else
166 | {
167 | LogMsg(@"Failed get physical disk: " + Marshal.GetHRForLastWin32Error());
168 | }
169 | Marshal.FreeHGlobal(vdeBlob);
170 |
171 | diskHandle.Dispose();
172 |
173 | var path = "";
174 | if(diskIndex >= 0)
175 | path = @"\\.\PhysicalDrive" + diskIndex;
176 |
177 | return path;
178 |
179 | }
180 |
181 | public long GetDriveSize(string drivePath)
182 | {
183 | //
184 | // Now that we've dismounted the logical volume mounted on the removable drive we can open up the physical disk to write
185 | //
186 | var diskHandle = NativeMethods.CreateFile(drivePath, NativeMethods.GENERIC_WRITE, 0, IntPtr.Zero, NativeMethods.OPEN_EXISTING, 0, IntPtr.Zero);
187 | if (diskHandle.IsInvalid)
188 | {
189 | LogMsg( @"Failed to open device: " + Marshal.GetHRForLastWin32Error());
190 | return -1;
191 | }
192 |
193 | //
194 | // Get drive size (NOTE: that WMI and IOCTL_DISK_GET_DRIVE_GEOMETRY don't give us the right value so we do it this way)
195 | //
196 | long size = -1;
197 |
198 | var geometrySize = Marshal.SizeOf(typeof(DiskGeometryEx));
199 | var geometryBlob = Marshal.AllocHGlobal(geometrySize);
200 | uint numBytesRead = 0;
201 |
202 | var success = NativeMethods.DeviceIoControl(diskHandle, NativeMethods.IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, IntPtr.Zero,
203 | 0, geometryBlob, (uint)geometrySize, ref numBytesRead, IntPtr.Zero);
204 |
205 | var geometry = (DiskGeometryEx)Marshal.PtrToStructure(geometryBlob, typeof(DiskGeometryEx));
206 | if (success)
207 | size = geometry.DiskSize;
208 |
209 | Marshal.FreeHGlobal(geometryBlob);
210 |
211 | diskHandle.Dispose();
212 |
213 | return size;
214 | }
215 |
216 | #endregion
217 |
218 | private void Progress(int progressValue)
219 | {
220 | if (OnProgress != null)
221 | OnProgress(this, progressValue);
222 | }
223 |
224 | private void LogMsg(string msg)
225 | {
226 | if (OnLogMsg != null)
227 | OnLogMsg(this, msg);
228 | }
229 |
230 | }
231 | }
232 |
--------------------------------------------------------------------------------
/DiskImager/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/ICSharpCode.SharpZipLib/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // AssemblyInfo.cs
2 | //
3 | // Copyright (C) 2001 Mike Krueger
4 | // Copyright 2004 John Reilly
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 | using System;
38 | using System.Reflection;
39 | using System.Runtime.CompilerServices;
40 | using System.Runtime.InteropServices;
41 |
42 | #if (NET_1_0)
43 | [assembly: AssemblyTitle("SharpZipLib for .NET Framework 1.0")]
44 | #elif (NET_1_1)
45 | [assembly: AssemblyTitle("SharpZipLib for .NET Framework 1.1")]
46 | #elif (NET_2_0)
47 | [assembly: AssemblyTitle("SharpZipLib for .NET Framework 2.0")]
48 | #elif (NET_3_0)
49 | [assembly: AssemblyTitle("SharpZipLib for .NET Framework 3.0")]
50 | #elif (NET_3_5)
51 | [assembly: AssemblyTitle("SharpZipLib for .NET Framework 3.5")]
52 | #elif (NET_4_0)
53 | [assembly: AssemblyTitle("SharpZipLib for .NET Framework 4.0")]
54 | #elif (NETCF_1_0)
55 | [assembly: AssemblyTitle("SharpZipLib for .NET Compact Framework 1.0")]
56 | #elif (NETCF_2_0)
57 | [assembly: AssemblyTitle("SharpZipLib for .NET Compact Framework 2.0")]
58 | #elif (MONO_1_0)
59 | [assembly: AssemblyTitle("SharpZipLib for Mono 1.0")]
60 | #elif (MONO_2_0)
61 | [assembly: AssemblyTitle("SharpZipLib for Mono 2.0")]
62 | #else
63 | [assembly: AssemblyTitle("SharpZipLibrary unlabelled version")]
64 | #endif
65 |
66 | [assembly: AssemblyDescription("A free C# compression library")]
67 | [assembly: AssemblyProduct("#ZipLibrary")]
68 | [assembly: AssemblyDefaultAlias("SharpZipLib")]
69 | [assembly: AssemblyCulture("")]
70 |
71 | #if DEBUG
72 | [assembly: AssemblyConfiguration("Debug")]
73 | #else
74 | [assembly: AssemblyConfiguration("Release")]
75 | #endif
76 |
77 |
78 | [assembly: AssemblyCompany("ICSharpCode.net")]
79 | [assembly: AssemblyCopyright("Copyright 2001-2010 Mike Krueger, John Reilly")]
80 | [assembly: AssemblyTrademark("Copyright 2001-2010 Mike Krueger, John Reilly")]
81 |
82 | [assembly: AssemblyVersion("0.86.0.518")]
83 | [assembly: AssemblyInformationalVersionAttribute("0.86.0")]
84 |
85 |
86 | [assembly: CLSCompliant(true)]
87 |
88 | #if (!NETCF)
89 | //
90 | // If #Zip is strongly named it still allows partially trusted callers
91 | //
92 | [assembly: System.Security.AllowPartiallyTrustedCallers]
93 | #endif
94 |
95 | // Setting ComVisible to false makes the types in this assembly not visible
96 | // to COM components. If you need to access a type in this assembly from
97 | // COM, set the ComVisible attribute to true on that type.
98 | [assembly: ComVisible(false)]
99 |
100 | //
101 | // In order to sign your assembly you must specify a key to use. Refer to the
102 | // Microsoft .NET Framework documentation for more information on assembly signing.
103 | //
104 | // Use the attributes below to control which key is used for signing.
105 | //
106 | // Notes:
107 | // (*) If no key is specified, the assembly is not signed.
108 | // (*) KeyName refers to a key that has been installed in the Crypto Service
109 | // Provider (CSP) on your machine. KeyFile refers to a file which contains
110 | // a key.
111 | // (*) If the KeyFile and the KeyName values are both specified, the
112 | // following processing occurs:
113 | // (1) If the KeyName can be found in the CSP, that key is used.
114 | // (2) If the KeyName does not exist and the KeyFile does exist, the key
115 | // in the KeyFile is installed into the CSP and used.
116 | // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
117 | // When specifying the KeyFile, the location of the KeyFile should be
118 | // relative to the project output directory which is
119 | // %Project Directory%\obj\. For example, if your KeyFile is
120 | // located in the project directory, you would specify the AssemblyKeyFile
121 | // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
122 | // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
123 | // documentation for more information on this.
124 | //
125 | #if (CLI_1_0 || NET_1_0 || NET_1_1 || NETCF_1_0 || SSCLI)
126 | [assembly: AssemblyDelaySign(false)]
127 | #if VSTUDIO
128 | [assembly: AssemblyKeyFile("../../ICSharpCode.SharpZipLib.key")]
129 | #elif AUTOBUILD
130 | [assembly: AssemblyKeyFile("ICSharpCode.SharpZipLib.key")]
131 | #else
132 | [assembly: AssemblyKeyFile("../ICSharpCode.SharpZipLib.key")]
133 | #endif
134 | #endif
135 |
136 |
137 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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
--------------------------------------------------------------------------------
/ICSharpCode.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
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.SharpZipLib/ICSharpCode.SharpZLib.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Release
5 | AnyCPU
6 | 2.0
7 | {0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}
8 | ICSharpCode.SharpZipLib
9 | ICSharpCode.SharpZipLib
10 | Library
11 |
12 | 4
13 |
14 | False
15 | False
16 | OnOutputUpdated
17 |
18 |
19 | ..\bin\ICSharpCode.SharpZipLib.xml
20 | v2.0
21 |
22 |
23 |
24 |
25 | 2.0
26 |
27 |
28 | false
29 | True
30 | False
31 | False
32 | ..\bin\
33 | false
34 | None
35 | AllRules.ruleset
36 |
37 |
38 | true
39 | False
40 | False
41 | False
42 | ..\bin\
43 | false
44 | Full
45 | AllRules.ruleset
46 |
47 |
48 | False
49 | Auto
50 | 4194304
51 | AnyCPU
52 | 4096
53 |
54 |
55 | NET_2_0
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 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/ICSharpCode.SharpZipLib/Lzw/LzwConstants.cs:
--------------------------------------------------------------------------------
1 | // LzwConstants.cs
2 | //
3 | // Copyright (C) 2009 Gabriel Burca
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.LZW {
37 |
38 | ///
39 | /// This class contains constants used for LZW
40 | ///
41 | sealed public class LzwConstants {
42 | ///
43 | /// Magic number found at start of LZW header: 0x1f 0x9d
44 | ///
45 | public const int MAGIC = 0x1f9d;
46 |
47 | ///
48 | /// Maximum number of bits per code
49 | ///
50 | public const int MAX_BITS = 16;
51 |
52 | /* 3rd header byte:
53 | * bit 0..4 Number of compression bits
54 | * bit 5 Extended header
55 | * bit 6 Free
56 | * bit 7 Block mode
57 | */
58 |
59 | ///
60 | /// Mask for 'number of compression bits'
61 | ///
62 | public const int BIT_MASK = 0x1f;
63 |
64 | ///
65 | /// Indicates the presence of a fourth header byte
66 | ///
67 | public const int EXTENDED_MASK = 0x20;
68 | //public const int FREE_MASK = 0x40;
69 |
70 | ///
71 | /// Reserved bits
72 | ///
73 | public const int RESERVED_MASK = 0x60;
74 |
75 | ///
76 | /// Block compression: if table is full and compression rate is dropping,
77 | /// clear the dictionary.
78 | ///
79 | public const int BLOCK_MODE_MASK = 0x80;
80 |
81 | ///
82 | /// LZW file header size (in bytes)
83 | ///
84 | public const int HDR_SIZE = 3;
85 |
86 | ///
87 | /// Initial number of bits per code
88 | ///
89 | public const int INIT_BITS = 9;
90 |
91 | LzwConstants() {
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/ICSharpCode.SharpZipLib/Lzw/LzwException.cs:
--------------------------------------------------------------------------------
1 | // LzwException.cs
2 | //
3 | // Copyright (C) 2009 Gabriel Burca
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.LZW
43 | {
44 |
45 | ///
46 | /// LzwException represents a LZW specific exception
47 | ///
48 | #if !NETCF_1_0 && !NETCF_2_0
49 | [Serializable]
50 | #endif
51 | public class LzwException : SharpZipBaseException
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 LzwException(SerializationInfo info, StreamingContext context)
61 | : base(info, context) {
62 | }
63 | #endif
64 |
65 | ///
66 | /// Initialise a new instance of LzwException
67 | ///
68 | public LzwException() {
69 | }
70 |
71 | ///
72 | /// Initialise a new instance of LzwException with its message string.
73 | ///
74 | /// A that describes the error.
75 | public LzwException(string message)
76 | : base(message) {
77 | }
78 |
79 | ///
80 | /// Initialise a new instance of .
81 | ///
82 | /// A that describes the error.
83 | /// The that caused this exception.
84 | public LzwException(string message, Exception innerException)
85 | : base(message, innerException) {
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/ICSharpCode.SharpZipLib/Main.cs:
--------------------------------------------------------------------------------
1 | // Main.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 |
37 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/ICSharpCode.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 |
--------------------------------------------------------------------------------
/Libs/Libs.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | x86
6 | 8.0.30703
7 | 2.0
8 | {1B0F140A-DFA6-4693-9C09-FCB9E0B35189}
9 | Exe
10 | Properties
11 | Libs
12 | Libs
13 | v4.0
14 | Client
15 | 512
16 |
17 |
18 | x86
19 | true
20 | full
21 | false
22 | bin\Debug\
23 | DEBUG;TRACE
24 | prompt
25 | 4
26 |
27 |
28 | x86
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 |
36 |
37 |
44 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | DiskImager
2 | ==========
3 |
4 | A Windows Disk Imager. A C#.NET utility for reading / writing SD cards and USB devices
5 |
6 | License: This software utility is released under GPLv3.
7 |
8 | The current release can be downloaded here
9 |
10 | http://www.dynamicdevices.co.uk/downloads/DiskImager.Installer.msi
11 |
12 | (Please feed back any platform testing you do, or any issues you encounter. Thanks.)
13 |
14 | This utility is a C#.NET implementation, and adds a couple of features I wanted to see:
15 |
16 | - reads/writes images to/from compressed file formats: ZIP, TGZ, GZ
17 |
18 | - remembers the last file you read/wrote
19 |
20 | - provides more file filters within file dialog for typical image files (.img, .bin, .sdcard)
21 |
22 | - it also *might* be slightly faster when dealing with uncompressed read/write
23 |
24 | *NOTE This application could possibly cause damage to your computer drive(s). We cannot take responsibility for any damage caused or losses incurred through use of this utility. Use at own risk!*
25 |
26 | Credits: Inspired by the excellent Win32DiskImager.
27 |
28 | ChangeLog
29 | =========
30 |
31 | 1.1.3 03/05/16 AJL Add button to erase MBR (allows us to then reformat the drive to full capacity)
32 |
33 | 1.1.2 20/08/15 AJL Add support for writing partial files (start/length)
34 |
35 | 1.1.1 02/03/14 AJL Minor fix to error message when source file not available
36 |
37 | 1.1.0 12/05/14 AJL Updated to use latest SharpZipLib as we were encountering (de-)compression errors with the previous version
38 | Added the option to truncate the read image based on the partition sizes found in the master boot record on the disk/stick
39 | Improved logging of sizes read and written
40 |
41 | 1.0.3 30/04/14 AJL Added warning dialog box when there's a write error
42 |
43 | 1.0.2 09/11/13 AJL Added support for reading and writing directly to compressed formats: .zip, .tgz, .gz
44 |
45 | Testing - Windows 8.1 Professional
46 |
47 | 1.0.1 08/11/13 AJL Refactoring for cleanup. Fixed issue with SEH exception due to SafeHandle disposal
48 |
49 | Testing - Windows 8.1 Professional
50 |
51 | 1.0.0 08/11/13 AJL Initial Commit. Reads and Writes SD cards
52 |
53 | Testing - Windows 8.1 Professional
54 |
55 | Contact
56 | =======
57 |
58 | Alex J Lennon - ajlennon@dynamicdevices.co.uk
--------------------------------------------------------------------------------