Rizin
unix-like reverse engineering framework and cli tools
DotZLib.cs
Go to the documentation of this file.
1 //
2 // © Copyright Henrik Ravn 2004
3 //
4 // Use, modification and distribution are subject to the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 
8 using System;
9 using System.IO;
10 using System.Runtime.InteropServices;
11 using System.Text;
12 
13 
14 namespace DotZLib
15 {
16 
17  #region Internal types
18 
22  internal enum FlushTypes
23  {
25  }
26 
27  #region ZStream structure
28  // internal mapping of the zlib zstream structure for marshalling
29  [StructLayoutAttribute(LayoutKind.Sequential, Pack=4, Size=0, CharSet=CharSet.Ansi)]
30  internal struct ZStream
31  {
32  public IntPtr next_in;
33  public uint avail_in;
34  public uint total_in;
35 
36  public IntPtr next_out;
37  public uint avail_out;
38  public uint total_out;
39 
40  [MarshalAs(UnmanagedType.LPStr)]
41  string msg;
43 
47 
48  int data_type;
49  public uint adler;
51  }
52 
53  #endregion
54 
55  #endregion
56 
57  #region Public enums
61  public enum CompressLevel : int
62  {
66  Default = -1,
70  None = 0,
74  Best = 9,
78  Fastest = 1
79  }
80  #endregion
81 
82  #region Exception classes
86  public class ZLibException : ApplicationException
87  {
94  public ZLibException(int errorCode, string msg) : base(String.Format("ZLib error {0} {1}", errorCode, msg))
95  {
96  }
97 
103  public ZLibException(int errorCode) : base(String.Format("ZLib error {0}", errorCode))
104  {
105  }
106  }
107  #endregion
108 
109  #region Interfaces
110 
114  public interface ChecksumGenerator
115  {
119  uint Value { get; }
120 
124  void Reset();
125 
130  void Update(byte[] data);
131 
141  void Update(byte[] data, int offset, int count);
142 
148  void Update(string data);
149 
155  void Update(string data, Encoding encoding);
156  }
157 
158 
169  public delegate void DataAvailableHandler(byte[] data, int startIndex, int count);
170 
174  public interface Codec
175  {
180 
186  void Add(byte[] data);
187 
195  void Add(byte[] data, int offset, int count);
196 
200  void Finish();
201 
205  uint Checksum { get; }
206 
207 
208  }
209 
210  #endregion
211 
212  #region Classes
216  public class Info
217  {
218  #region DLL imports
219  [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
220  private static extern uint zlibCompileFlags();
221 
222  [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
223  private static extern string zlibVersion();
224  #endregion
225 
226  #region Private stuff
227  private uint _flags;
228 
229  // helper function that unpacks a bitsize mask
230  private static int bitSize(uint bits)
231  {
232  switch (bits)
233  {
234  case 0: return 16;
235  case 1: return 32;
236  case 2: return 64;
237  }
238  return -1;
239  }
240  #endregion
241 
245  public Info()
246  {
248  }
249 
253  public bool HasDebugInfo { get { return 0 != (_flags & 0x100); } }
254 
258  public bool UsesAssemblyCode { get { return 0 != (_flags & 0x200); } }
259 
263  public int SizeOfUInt { get { return bitSize(_flags & 3); } }
264 
268  public int SizeOfULong { get { return bitSize((_flags >> 2) & 3); } }
269 
273  public int SizeOfPointer { get { return bitSize((_flags >> 4) & 3); } }
274 
278  public int SizeOfOffset { get { return bitSize((_flags >> 6) & 3); } }
279 
283  public static string Version { get { return zlibVersion(); } }
284  }
285 
286  #endregion
287 
288 }
int bits(struct state *s, int need)
Definition: blast.c:72
Encapsulates general information about the ZLib library
Definition: DotZLib.cs:217
static string Version
Gets the version of ZLib as a string, e.g. "1.2.1"
Definition: DotZLib.cs:283
int SizeOfULong
Gets the size of the unsigned long that was compiled into Zlib
Definition: DotZLib.cs:268
static uint zlibCompileFlags()
Info()
Constructs an instance of the Info class.
Definition: DotZLib.cs:245
uint _flags
Definition: DotZLib.cs:227
static string zlibVersion()
int SizeOfOffset
Gets the size of the z_off_t type that was compiled into Zlib
Definition: DotZLib.cs:278
bool HasDebugInfo
True if the library is compiled with debug info
Definition: DotZLib.cs:253
int SizeOfUInt
Gets the size of the unsigned int that was compiled into Zlib
Definition: DotZLib.cs:263
int SizeOfPointer
Gets the size of the pointers that were compiled into Zlib
Definition: DotZLib.cs:273
static int bitSize(uint bits)
Definition: DotZLib.cs:230
bool UsesAssemblyCode
True if the library is compiled with assembly optimizations
Definition: DotZLib.cs:258
The exception that is thrown when an error occurs on the zlib dll
Definition: DotZLib.cs:87
ZLibException(int errorCode, string msg)
Initializes a new instance of the ZLibException class with a specified error message and error code
Definition: DotZLib.cs:94
ZLibException(int errorCode)
Initializes a new instance of the ZLibException class with a specified error code
Definition: DotZLib.cs:103
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
unsigned int uint
Definition: gzlog.c:242
Declares methods and properties that enables a running checksum to be calculated
Definition: DotZLib.cs:115
void Update(byte[] data)
Updates the current checksum with an array of bytes
uint Value
Gets the current value of the checksum
Definition: DotZLib.cs:119
void Update(string data, Encoding encoding)
Updates the current checksum with the data from a string, using a specific encoding
void Update(string data)
Updates the current checksum with the data from a string
void Reset()
Clears the current checksum to 0
void Update(byte[] data, int offset, int count)
Updates the current checksum with part of an array of bytes
Declares methods and events for implementing compressors/decompressors
Definition: DotZLib.cs:175
void Add(byte[] data, int offset, int count)
Adds more data to the codec to be processed.
DataAvailableHandler DataAvailable
Occurs when more processed data are available.
Definition: DotZLib.cs:179
void Add(byte[] data)
Adds more data to the codec to be processed.
uint Checksum
Gets the checksum of the data that has been added so far
Definition: DotZLib.cs:205
void Finish()
Finishes up any pending data that needs to be processed and handled.
voidpf uLong offset
Definition: ioapi.h:144
CompressLevel
Defines constants for the available compression levels in zlib
Definition: DotZLib.cs:62
@ Best
The maximum compression rate available.
@ Default
The default compression level with a reasonable compromise between compression and speed
@ Fastest
The fastest available compression level.
delegate void DataAvailableHandler(byte[] data, int startIndex, int count)
Represents the method that will be called from a codec when new data are available.
FlushTypes
Defines constants for the various flush types used with zlib
Definition: DotZLib.cs:23
static struct sockaddr static addrlen static backlog const void msg
Definition: sfsocketcall.h:119
uint avail_in
Definition: DotZLib.cs:33
uint reserved
Definition: DotZLib.cs:50
IntPtr next_in
Definition: DotZLib.cs:32
uint total_out
Definition: DotZLib.cs:38
uint avail_out
Definition: DotZLib.cs:37
IntPtr next_out
Definition: DotZLib.cs:36
string msg
Definition: DotZLib.cs:41
uint total_in
Definition: DotZLib.cs:34
Definition: diff.c:71