|
Welcome to the GSM-Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. Only registered members may post questions, contact other members or search our database of over 8 million posts. Registration is fast, simple and absolutely free so please - Click to REGISTER! If you have any problems with the registration process or your account login, please contact contact us . |
|
Register | FAQ | Donate | Forum Rules | Root any Device | ★iPhone Unlock★ | ★ Direct Codes ★ | Direct Unlock Source |
GSM Programming & Reverse Engineering Here you can post all Kind of GSM Programming and Reverse Engineering tools and Secrets. |
| LinkBack | Thread Tools | Display Modes |
06-18-2007, 20:46 | #2 (permalink) |
Freak Poster Join Date: Jul 2005 Age: 46
Posts: 366
Member: 163721 Status: Offline Thanks Meter: 148 | Code: Unit Crc; { crc32.c -- compute the CRC-32 of a data stream Copyright (C) 1995-1998 Mark Adler Pascal tranlastion Copyright (C) 1998 by Jacques Nomssi Nzali For conditions of distribution and use, see copyright notice in readme.txt } interface {$I zconf.inc} uses zutil, zlib_1; function crc32(crc : uLong; buf : pBytef; len : uInt) : uLong; { Update a running crc with the bytes buf[0..len-1] and return the updated crc. If buf is NULL, this function returns the required initial value for the crc. Pre- and post-conditioning (one's complement) is performed within this function so it shouldn't be done by the application. Usage example: var crc : uLong; begin crc := crc32(0, Z_NULL, 0); while (read_buffer(buffer, length) <> EOF) do crc := crc32(crc, buffer, length); if (crc <> original_crc) then error(); end; } function get_crc_table : puLong; { can be used by asm versions of crc32() } implementation {$IFDEF DYNAMIC_CRC_TABLE} {local} const crc_table_empty : boolean = TRUE; {local} var crc_table : array[0..256-1] of uLongf; { Generate a table for a byte-wise 32-bit CRC calculation on the polynomial: x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. Polynomials over GF(2) are represented in binary, one bit per coefficient, with the lowest powers in the most significant bit. Then adding polynomials is just exclusive-or, and multiplying a polynomial by x is a right shift by one. If we call the above polynomial p, and represent a byte as the polynomial q, also with the lowest power in the most significant bit (so the byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, where a mod b means the remainder after dividing a by b. This calculation is done using the shift-register method of multiplying and taking the remainder. The register is initialized to zero, and for each incoming bit, x^32 is added mod p to the register if the bit is a one (where x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by x (which is shifting right by one and adding x^32 mod p if the bit shifted out is a one). We start with the highest power (least significant bit) of q and repeat for all eight bits of q. The table is simply the CRC of all possible eight bit values. This is all the information needed to generate CRC's on data a byte at a time for all combinations of CRC register values and incoming bytes. } {local} procedure make_crc_table; var c : uLong; n,k : int; poly : uLong; { polynomial exclusive-or pattern } const { terms of polynomial defining this crc (except x^32): } p: array [0..13] of Byte = (0,1,2,4,5,7,8,10,11,12,16,22,23,26); begin { make exclusive-or pattern from polynomial ($EDB88320) } poly := Long(0); for n := 0 to (sizeof(p) div sizeof(Byte))-1 do poly := poly or (Long(1) shl (31 - p[n])); for n := 0 to 255 do begin c := uLong(n); for k := 0 to 7 do begin if (c and 1) <> 0 then c := poly xor (c shr 1) else c := (c shr 1); end; crc_table[n] := c; end; crc_table_empty := FALSE; end; {$ELSE} { ======================================================================== Table of CRC-32's of all single-byte values (made by make_crc_table) } {local} const crc_table : array[0..256-1] of uLongf = ( $00000000, $77073096, $ee0e612c, $990951ba, $076dc419, $706af48f, $e963a535, $9e6495a3, $0edb8832, $79dcb8a4, $e0d5e91e, $97d2d988, $09b64c2b, $7eb17cbd, $e7b82d07, $90bf1d91, $1db71064, $6ab020f2, $f3b97148, $84be41de, $1adad47d, $6ddde4eb, $f4d4b551, $83d385c7, $136c9856, $646ba8c0, $fd62f97a, $8a65c9ec, $14015c4f, $63066cd9, $fa0f3d63, $8d080df5, $3b6e20c8, $4c69105e, $d56041e4, $a2677172, $3c03e4d1, $4b04d447, $d20d85fd, $a50ab56b, $35b5a8fa, $42b2986c, $dbbbc9d6, $acbcf940, $32d86ce3, $45df5c75, $dcd60dcf, $abd13d59, $26d930ac, $51de003a, $c8d75180, $bfd06116, $21b4f4b5, $56b3c423, $cfba9599, $b8bda50f, $2802b89e, $5f058808, $c60cd9b2, $b10be924, $2f6f7c87, $58684c11, $c1611dab, $b6662d3d, $76dc4190, $01db7106, $98d220bc, $efd5102a, $71b18589, $06b6b51f, $9fbfe4a5, $e8b8d433, $7807c9a2, $0f00f934, $9609a88e, $e10e9818, $7f6a0dbb, $086d3d2d, $91646c97, $e6635c01, $6b6b51f4, $1c6c6162, $856530d8, $f262004e, $6c0695ed, $1b01a57b, $8208f4c1, $f50fc457, $65b0d9c6, $12b7e950, $8bbeb8ea, $fcb9887c, $62dd1ddf, $15da2d49, $8cd37cf3, $fbd44c65, $4db26158, $3ab551ce, $a3bc0074, $d4bb30e2, $4adfa541, $3dd895d7, $a4d1c46d, $d3d6f4fb, $4369e96a, $346ed9fc, $ad678846, $da60b8d0, $44042d73, $33031de5, $aa0a4c5f, $dd0d7cc9, $5005713c, $270241aa, $be0b1010, $c90c2086, $5768b525, $206f85b3, $b966d409, $ce61e49f, $5edef90e, $29d9c998, $b0d09822, $c7d7a8b4, $59b33d17, $2eb40d81, $b7bd5c3b, $c0ba6cad, $edb88320, $9abfb3b6, $03b6e20c, $74b1d29a, $ead54739, $9dd277af, $04db2615, $73dc1683, $e3630b12, $94643b84, $0d6d6a3e, $7a6a5aa8, $e40ecf0b, $9309ff9d, $0a00ae27, $7d079eb1, $f00f9344, $8708a3d2, $1e01f268, $6906c2fe, $f762575d, $806567cb, $196c3671, $6e6b06e7, $fed41b76, $89d32be0, $10da7a5a, $67dd4acc, $f9b9df6f, $8ebeeff9, $17b7be43, $60b08ed5, $d6d6a3e8, $a1d1937e, $38d8c2c4, $4fdff252, $d1bb67f1, $a6bc5767, $3fb506dd, $48b2364b, $d80d2bda, $af0a1b4c, $36034af6, $41047a60, $df60efc3, $a867df55, $316e8eef, $4669be79, $cb61b38c, $bc66831a, $256fd2a0, $5268e236, $cc0c7795, $bb0b4703, $220216b9, $5505262f, $c5ba3bbe, $b2bd0b28, $2bb45a92, $5cb36a04, $c2d7ffa7, $b5d0cf31, $2cd99e8b, $5bdeae1d, $9b64c2b0, $ec63f226, $756aa39c, $026d930a, $9c0906a9, $eb0e363f, $72076785, $05005713, $95bf4a82, $e2b87a14, $7bb12bae, $0cb61b38, $92d28e9b, $e5d5be0d, $7cdcefb7, $0bdbdf21, $86d3d2d4, $f1d4e242, $68ddb3f8, $1fda836e, $81be16cd, $f6b9265b, $6fb077e1, $18b74777, $88085ae6, $ff0f6a70, $66063bca, $11010b5c, $8f659eff, $f862ae69, $616bffd3, $166ccf45, $a00ae278, $d70dd2ee, $4e048354, $3903b3c2, $a7672661, $d06016f7, $4969474d, $3e6e77db, $aed16a4a, $d9d65adc, $40df0b66, $37d83bf0, $a9bcae53, $debb9ec5, $47b2cf7f, $30b5ffe9, $bdbdf21c, $cabac28a, $53b39330, $24b4a3a6, $bad03605, $cdd70693, $54de5729, $23d967bf, $b3667a2e, $c4614ab8, $5d681b02, $2a6f2b94, $b40bbe37, $c30c8ea1, $5a05df1b, $2d02ef8d); {$ENDIF} { ========================================================================= This function can be used by asm versions of crc32() } function get_crc_table : {const} puLong; begin {$ifdef DYNAMIC_CRC_TABLE} if (crc_table_empty) then make_crc_table; {$endif} get_crc_table := {const} puLong(@crc_table); end; { ========================================================================= } function crc32 (crc : uLong; buf : pBytef; len : uInt): uLong; begin if (buf = Z_NULL) then crc32 := Long(0) else begin {$IFDEF DYNAMIC_CRC_TABLE} if crc_table_empty then make_crc_table; {$ENDIF} crc := crc xor uLong($ffffffff); while (len >= 8) do begin {DO8(buf)} crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); inc(buf); crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); inc(buf); crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); inc(buf); crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); inc(buf); crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); inc(buf); crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); inc(buf); crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); inc(buf); crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); inc(buf); Dec(len, 8); end; if (len <> 0) then repeat {DO1(buf)} crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); inc(buf); Dec(len); until (len = 0); crc32 := crc xor uLong($ffffffff); end; end; end. |
06-19-2007, 22:03 | #5 (permalink) |
Freak Poster Join Date: Jul 2005 Age: 46
Posts: 366
Member: 163721 Status: Offline Thanks Meter: 148 | Code: Unit Zlib_1; { Original: zlib.h -- interface of the 'zlib' general purpose compression library version 1.1.0, Feb 24th, 1998 Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Jean-loup Gailly Mark Adler [email protected] [email protected] The data format used by the zlib library is described by RFCs (Request for Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). Pascal tranlastion Copyright (C) 1998 by Jacques Nomssi Nzali For conditions of distribution and use, see copyright notice in readme.txt } interface {$I zconf.inc} uses zutil; { zconf.h -- configuration of the zlib compression library } { zutil.c -- target dependent utility functions for the compression library } { The 'zlib' compression library provides in-memory compression and decompression functions, including integrity checks of the uncompressed data. This version of the library supports only one compression method (deflation) but other algorithms will be added later and will have the same stream interface. Compression can be done in a single step if the buffers are large enough (for example if an input file is mmap'ed), or can be done by repeated calls of the compression function. In the latter case, the application must provide more input and/or consume the output (providing more output space) before each call. The library also supports reading and writing files in gzip (.gz) format with an interface similar to that of stdio. The library does not install any signal handler. The decoder checks the consistency of the compressed data, so the library should never crash even in case of corrupted input. } { Compile with -DMAXSEG_64K if the alloc function cannot allocate more than 64k bytes at a time (needed on systems with 16-bit int). } { Maximum value for memLevel in deflateInit2 } {$ifdef MAXSEG_64K} {$IFDEF VER70} const MAX_MEM_LEVEL = 7; DEF_MEM_LEVEL = MAX_MEM_LEVEL; { default memLevel } {$ELSE} const MAX_MEM_LEVEL = 8; DEF_MEM_LEVEL = MAX_MEM_LEVEL; { default memLevel } {$ENDIF} {$else} const MAX_MEM_LEVEL = 9; DEF_MEM_LEVEL = 8; { if MAX_MEM_LEVEL > 8 } {$endif} { Maximum value for windowBits in deflateInit2 and inflateInit2 } const {$IFDEF VER70} MAX_WBITS = 14; { 32K LZ77 window } {$ELSE} MAX_WBITS = 15; { 32K LZ77 window } {$ENDIF} { default windowBits for decompression. MAX_WBITS is for compression only } const DEF_WBITS = MAX_WBITS; { The memory requirements for deflate are (in bytes): 1 shl (windowBits+2) + 1 shl (memLevel+9) that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) plus a few kilobytes for small objects. For example, if you want to reduce the default memory requirements from 256K to 128K, compile with DMAX_WBITS=14 DMAX_MEM_LEVEL=7 Of course this will generally degrade compression (there's no free lunch). The memory requirements for inflate are (in bytes) 1 shl windowBits that is, 32K for windowBits=15 (default value) plus a few kilobytes for small objects. } { Huffman code lookup table entry--this entry is four bytes for machines that have 16-bit pointers (e.g. PC's in the small or medium model). } type pInflate_huft = ^inflate_huft; inflate_huft = Record Exop, { number of extra bits or operation } bits : Byte; { number of bits in this code or subcode } {pad : uInt;} { pad structure to a power of 2 (4 bytes for } { 16-bit, 8 bytes for 32-bit int's) } base : uInt; { literal, length base, or distance base } { or table offset } End; type huft_field = Array[0..(MaxMemBlock div SizeOf(inflate_huft))-1] of inflate_huft; huft_ptr = ^huft_field; type ppInflate_huft = ^pInflate_huft; type inflate_codes_mode = ( { waiting for "i:"=input, "o:"=output, "x:"=nothing } START, { x: set up for LEN } LEN, { i: get length/literal/eob next } LENEXT, { i: getting length extra (have base) } DIST, { i: get distance next } DISTEXT, { i: getting distance extra } COPY, { o: copying bytes in window, waiting for space } LIT, { o: got literal, waiting for output space } WASH, { o: got eob, possibly still output waiting } ZEND, { x: got eob and all data flushed } BADCODE); { x: got error } { inflate codes private state } type pInflate_codes_state = ^inflate_codes_state; inflate_codes_state = record mode : inflate_codes_mode; { current inflate_codes mode } { mode dependent information } len : uInt; sub : record { submode } Case Byte of 0:(code : record { if LEN or DIST, where in tree } tree : pInflate_huft; { pointer into tree } need : uInt; { bits needed } end); 1:(lit : uInt); { if LIT, literal } 2:(copy: record { if EXT or COPY, where and how much } get : uInt; { bits to get for extra } dist : uInt; { distance back to copy from } end); end; { mode independent information } lbits : Byte; { ltree bits decoded per branch } dbits : Byte; { dtree bits decoder per branch } ltree : pInflate_huft; { literal/length/eob tree } dtree : pInflate_huft; { distance tree } end; type check_func = function(check : uLong; buf : pBytef; {const buf : array of byte;} len : uInt) : uLong; type inflate_block_mode = (ZTYPE, { get type bits (3, including end bit) } LENS, { get lengths for stored } STORED, { processing stored block } TABLE, { get table lengths } BTREE, { get bit lengths tree for a dynamic block } DTREE, { get length, distance trees for a dynamic block } CODES, { processing fixed or dynamic block } DRY, { output remaining window bytes } BLKDONE, { finished last block, done } BLKBAD); { got a data error--stuck here } type pInflate_blocks_state = ^inflate_blocks_state; { inflate blocks semi-private state } inflate_blocks_state = record mode : inflate_block_mode; { current inflate_block mode } { mode dependent information } sub : record { submode } case Byte of 0:(left : uInt); { if STORED, bytes left to copy } 1:(trees : record { if DTREE, decoding info for trees } table : uInt; { table lengths (14 bits) } index : uInt; { index into blens (or border) } blens : PuIntArray; { bit lengths of codes } bb : uInt; { bit length tree depth } tb : pInflate_huft; { bit length decoding tree } end); 2:(decode : record { if CODES, current state } tl : pInflate_huft; td : pInflate_huft; { trees to free } codes : pInflate_codes_state; end); end; last : boolean; { true if this block is the last block } { mode independent information } bitk : uInt; { bits in bit buffer } bitb : uLong; { bit buffer } hufts : huft_ptr; {pInflate_huft;} { single malloc for tree space } window : pBytef; { sliding window } zend : pBytef; { one byte after sliding window } read : pBytef; { window read pointer } write : pBytef; { window write pointer } checkfn : check_func; { check function } check : uLong; { check on output } end; type inflate_mode = ( METHOD, { waiting for method byte } FLAG, { waiting for flag byte } DICT4, { four dictionary check bytes to go } DICT3, { three dictionary check bytes to go } DICT2, { two dictionary check bytes to go } DICT1, { one dictionary check byte to go } DICT0, { waiting for inflateSetDictionary } BLOCKS, { decompressing blocks } CHECK4, { four check bytes to go } CHECK3, { three check bytes to go } CHECK2, { two check bytes to go } CHECK1, { one check byte to go } DONE, { finished check, done } BAD); { got an error--stay here } { inflate private state } type pInternal_state = ^internal_state; { or point to a deflate_state record } internal_state = record mode : inflate_mode; { current inflate mode } { mode dependent information } sub : record { submode } case byte of 0:(method : uInt); { if FLAGS, method byte } 1:(check : record { if CHECK, check values to compare } was : uLong; { computed check value } need : uLong; { stream check value } end); 2:(marker : uInt); { if BAD, inflateSync's marker bytes count } end; { mode independent information } nowrap : boolean; { flag for no wrapper } wbits : uInt; { log2(window size) (8..15, defaults to 15) } blocks : pInflate_blocks_state; { current inflate_blocks state } end; type alloc_func = function(opaque : voidpf; items : uInt; size : uInt) : voidpf; free_func = procedure(opaque : voidpf; address : voidpf); type z_streamp = ^z_stream; z_stream = record next_in : pBytef; { next input byte } avail_in : uInt; { number of bytes available at next_in } total_in : uLong; { total nb of input bytes read so far } next_out : pBytef; { next output byte should be put there } avail_out : uInt; { remaining free space at next_out } total_out : uLong; { total nb of bytes output so far } msg : string[255]; { last error message, '' if no error } state : pInternal_state; { not visible by applications } zalloc : alloc_func; { used to allocate the internal state } zfree : free_func; { used to free the internal state } opaque : voidpf; { private data object passed to zalloc and zfree } data_type : int; { best guess about the data type: ascii or binary } adler : uLong; { adler32 value of the uncompressed data } reserved : uLong; { reserved for future use } end; { The application must update next_in and avail_in when avail_in has dropped to zero. It must update next_out and avail_out when avail_out has dropped to zero. The application must initialize zalloc, zfree and opaque before calling the init function. All other fields are set by the compression library and must not be updated by the application. The opaque value provided by the application will be passed as the first parameter for calls of zalloc and zfree. This can be useful for custom memory management. The compression library attaches no meaning to the opaque value. zalloc must return Z_NULL if there is not enough memory for the object. On 16-bit systems, the functions zalloc and zfree must be able to allocate exactly 65536 bytes, but will not be required to allocate more than this if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers returned by zalloc for objects of exactly 65536 bytes *must* have their offset normalized to zero. The default allocation function provided by this library ensures this (see zutil.c). To reduce memory requirements and avoid any allocation of 64K objects, at the expense of compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). The fields total_in and total_out can be used for statistics or progress reports. After compression, total_in holds the total size of the uncompressed data and may be saved for use in the decompressor (particularly if the decompressor wants to decompress everything in a single step). } const { constants } Z_NO_FLUSH = 0; Z_PARTIAL_FLUSH = 1; Z_SYNC_FLUSH = 2; Z_FULL_FLUSH = 3; Z_FINISH = 4; { Allowed flush values; see deflate() below for details } Z_OK = 0; Z_STREAM_END = 1; Z_NEED_DICT = 2; Z_ERRNO = (-1); Z_STREAM_ERROR = (-2); Z_DATA_ERROR = (-3); Z_MEM_ERROR = (-4); Z_BUF_ERROR = (-5); Z_VERSION_ERROR = (-6); { Return codes for the compression/decompression functions. Negative values are errors, positive values are used for special but normal events.} Z_NO_COMPRESSION = 0; Z_BEST_SPEED = 1; Z_BEST_COMPRESSION = 9; Z_DEFAULT_COMPRESSION = (-1); { compression levels } Z_FILTERED = 1; Z_HUFFMAN_ONLY = 2; Z_DEFAULT_STRATEGY = 0; { compression strategy; see deflateInit2() below for details } Z_BINARY = 0; Z_ASCII = 1; Z_UNKNOWN = 2; { Possible values of the data_type field } Z_DEFLATED = 8; { The deflate compression method (the only one supported in this version) } Z_NULL = NIL; { for initializing zalloc, zfree, opaque } {$IFDEF GZIO} var errno : int; {$ENDIF} { common constants } { The three kinds of block type } const STORED_BLOCK = 0; STATIC_TREES = 1; DYN_TREES = 2; { The minimum and maximum match lengths } const MIN_MATCH = 3; {$ifdef MAX_MATCH_IS_258} MAX_MATCH = 258; {$else} MAX_MATCH = ??; { deliberate syntax error } {$endif} const PRESET_DICT = $20; { preset dictionary flag in zlib header } {$IFDEF DEBUG} // procedure Assert(cond : boolean; msg : string); {$ENDIF} procedure Trace(x : string); procedure Tracev(x : string); procedure Tracevv(x : string); procedure Tracevvv(x : string); procedure Tracec(c : boolean; x : string); procedure Tracecv(c : boolean; x : string); function zlibVersion : string; { The application can compare zlibVersion and ZLIB_VERSION for consistency. If the first character differs, the library code actually used is not compatible with the zlib.h header file used by the application. This check is automatically made by deflateInit and inflateInit. } function zError(err : int) : string; function ZALLOC (var strm : z_stream; items : uInt; size : uInt) : voidpf; procedure ZFREE (var strm : z_stream; ptr : voidpf); procedure TRY_FREE (var strm : z_stream; ptr : voidpf); const ZLIB_VERSION : string[10] = '1.1.2'; const z_errbase = Z_NEED_DICT; z_errmsg : Array[0..9] of string[21] = { indexed by 2-zlib_error } ('need dictionary', { Z_NEED_DICT 2 } 'stream end', { Z_STREAM_END 1 } '', { Z_OK 0 } 'file error', { Z_ERRNO (-1) } 'stream error', { Z_STREAM_ERROR (-2) } 'data error', { Z_DATA_ERROR (-3) } 'insufficient memory', { Z_MEM_ERROR (-4) } 'buffer error', { Z_BUF_ERROR (-5) } 'incompatible version',{ Z_VERSION_ERROR (-6) } ''); const z_verbose : int = 1; {$IFDEF DEBUG} procedure z_error (m : string); {$ENDIF} implementation function zError(err : int) : string; begin zError := z_errmsg[Z_NEED_DICT-err]; end; function zlibVersion : string; begin zlibVersion := ZLIB_VERSION; end; //procedure z_error (m : string); //begin // WriteLn(output, m); // Write('Zlib - Halt...'); // ReadLn; // Halt(1); //end; //procedure Assert(cond : boolean; msg : string); //begin // if not cond then // z_error(msg); //end; procedure Trace(x : string); begin WriteLn(x); end; procedure Tracev(x : string); begin if (z_verbose>0) then WriteLn(x); end; procedure Tracevv(x : string); begin if (z_verbose>1) then WriteLn(x); end; procedure Tracevvv(x : string); begin if (z_verbose>2) then WriteLn(x); end; procedure Tracec(c : boolean; x : string); begin if (z_verbose>0) and (c) then WriteLn(x); end; procedure Tracecv(c : boolean; x : string); begin if (z_verbose>1) and c then WriteLn(x); end; function ZALLOC (var strm : z_stream; items : uInt; size : uInt) : voidpf; begin ZALLOC := strm.zalloc(strm.opaque, items, size); end; procedure ZFREE (var strm : z_stream; ptr : voidpf); begin strm.zfree(strm.opaque, ptr); end; procedure TRY_FREE (var strm : z_stream; ptr : voidpf); begin {if @strm <> Z_NULL then} strm.zfree(strm.opaque, ptr); end; end. |
06-19-2007, 22:06 | #6 (permalink) |
Freak Poster Join Date: Jul 2005 Age: 46
Posts: 366
Member: 163721 Status: Offline Thanks Meter: 148 | Code: Unit ZUtil; { Copyright (C) 1998 by Jacques Nomssi Nzali For conditions of distribution and use, see copyright notice in readme.txt } interface {$I zconf.inc} { Type declarations } type {Byte = usigned char; 8 bits} Bytef = byte; charf = byte; {$IFDEF FPC} int = longint; {$ELSE} int = integer; {$ENDIF} intf = int; {$IFDEF MSDOS} uInt = Word; {$ELSE} {$IFDEF FPC} uInt = longint; { 16 bits or more } {$INFO Cardinal} {$ELSE} uInt = cardinal; { 16 bits or more } {$ENDIF} {$ENDIF} uIntf = uInt; Long = longint; {$ifdef Delphi5} uLong = Cardinal; {$else} // uLong = LongInt; { 32 bits or more } uLong = LongWord; { DelphiGzip: LongInt is Signed, longword not } {$endif} uLongf = uLong; voidp = pointer; voidpf = voidp; pBytef = ^Bytef; pIntf = ^intf; puIntf = ^uIntf; puLong = ^uLongf; ptr2int = uInt; { a pointer to integer casting is used to do pointer arithmetic. ptr2int must be an integer type and sizeof(ptr2int) must be less than sizeof(pointer) - Nomssi } const {$IFDEF MAXSEG_64K} MaxMemBlock = $FFFF; {$ELSE} MaxMemBlock = MaxInt; {$ENDIF} type zByteArray = array[0..(MaxMemBlock div SizeOf(Bytef))-1] of Bytef; pzByteArray = ^zByteArray; type zIntfArray = array[0..(MaxMemBlock div SizeOf(Intf))-1] of Intf; pzIntfArray = ^zIntfArray; type zuIntArray = array[0..(MaxMemBlock div SizeOf(uInt))-1] of uInt; PuIntArray = ^zuIntArray; { Type declarations - only for deflate } type uch = Byte; uchf = uch; { FAR } ush = Word; ushf = ush; ulg = LongInt; unsigned = uInt; pcharf = ^charf; puchf = ^uchf; pushf = ^ushf; type zuchfArray = zByteArray; puchfArray = ^zuchfArray; type zushfArray = array[0..(MaxMemBlock div SizeOf(ushf))-1] of ushf; pushfArray = ^zushfArray; procedure zmemcpy(destp : pBytef; sourcep : pBytef; len : uInt); function zmemcmp(s1p, s2p : pBytef; len : uInt) : int; procedure zmemzero(destp : pBytef; len : uInt); procedure zcfree(opaque : voidpf; ptr : voidpf); function zcalloc (opaque : voidpf; items : uInt; size : uInt) : voidpf; implementation {$ifdef ver80} {$define Delphi16} {$endif} {$ifdef ver70} {$define HugeMem} {$endif} {$ifdef ver60} {$define HugeMem} {$endif} {$IFDEF CALLDOS} uses WinDos; {$ENDIF} {$IFDEF Delphi16} uses WinTypes, WinProcs; {$ENDIF} {$IFNDEF FPC} {$IFDEF DPMI} uses WinAPI; {$ENDIF} {$ENDIF} {$IFDEF CALLDOS} { reduce your application memory footprint with $M before using this } function dosAlloc (Size : Longint) : Pointer; var regs: TRegisters; begin regs.bx := (Size + 15) div 16; { number of 16-bytes-paragraphs } regs.ah := $48; { Allocate memory block } msdos(regs); if regs.Flags and FCarry <> 0 then DosAlloc := NIL else DosAlloc := Ptr(regs.ax, 0); end; function dosFree(P : pointer) : boolean; var regs: TRegisters; begin dosFree := FALSE; regs.bx := Seg(P^); { segment } if Ofs(P) <> 0 then exit; regs.ah := $49; { Free memory block } msdos(regs); dosFree := (regs.Flags and FCarry = 0); end; {$ENDIF} type LH = record L, H : word; end; {$IFDEF HugeMem} {$define HEAP_LIST} {$endif} {$IFDEF HEAP_LIST} {--- to avoid Mark and Release --- } const MaxAllocEntries = 50; type TMemRec = record orgvalue, value : pointer; size: longint; end; const allocatedCount : 0..MaxAllocEntries = 0; var allocatedList : array[0..MaxAllocEntries-1] of TMemRec; function NewAllocation(ptr0, ptr : pointer; memsize : longint) : boolean; begin if (allocatedCount < MaxAllocEntries) and (ptr0 <> NIL) then begin with allocatedList[allocatedCount] do begin orgvalue := ptr0; value := ptr; size := memsize; end; Inc(allocatedCount); { we don't check for duplicate } NewAllocation := TRUE; end else NewAllocation := FALSE; end; {$ENDIF} {$IFDEF HugeMem} { The code below is extremely version specific to the TP 6/7 heap manager!!} type PFreeRec = ^TFreeRec; TFreeRec = record next: PFreeRec; size: Pointer; end; type HugePtr = voidpf; procedure IncPtr(var p:pointer;count:word); { Increments pointer } begin inc(LH(p).L,count); if LH(p).L < count then inc(LH(p).H,SelectorInc); { $1000 } end; procedure DecPtr(var p:pointer;count:word); { decrements pointer } begin if count > LH(p).L then dec(LH(p).H,SelectorInc); dec(LH(p).L,Count); end; procedure IncPtrLong(var p:pointer;count:longint); { Increments pointer; assumes count > 0 } begin inc(LH(p).H,SelectorInc*LH(count).H); inc(LH(p).L,LH(Count).L); if LH(p).L < LH(count).L then inc(LH(p).H,SelectorInc); end; procedure DecPtrLong(var p:pointer;count:longint); { Decrements pointer; assumes count > 0 } begin if LH(count).L > LH(p).L then dec(LH(p).H,SelectorInc); dec(LH(p).L,LH(Count).L); dec(LH(p).H,SelectorInc*LH(Count).H); end; { The next section is for real mode only } function Normalized(p : pointer) : pointer; var count : word; begin count := LH(p).L and $FFF0; Normalized := Ptr(LH(p).H + (count shr 4), LH(p).L and $F); end; procedure FreeHuge(var p:HugePtr; size : longint); const blocksize = $FFF0; var block : word; begin while size > 0 do begin { block := minimum(size, blocksize); } if size > blocksize then block := blocksize else block := size; dec(size,block); freemem(p,block); IncPtr(p,block); { we may get ptr($xxxx, $fff8) and 31 bytes left } p := Normalized(p); { to free, so we must normalize } end; end; function FreeMemHuge(ptr : pointer) : boolean; var i : integer; { -1..MaxAllocEntries } begin FreeMemHuge := FALSE; i := allocatedCount - 1; while (i >= 0) do begin if (ptr = allocatedList[i].value) then begin with allocatedList[i] do FreeHuge(orgvalue, size); Move(allocatedList[i+1], allocatedList[i], SizeOf(TMemRec)*(allocatedCount - 1 - i)); Dec(allocatedCount); FreeMemHuge := TRUE; break; end; Dec(i); end; end; procedure GetMemHuge(var p:HugePtr;memsize:Longint); const blocksize = $FFF0; var size : longint; prev,free : PFreeRec; save,temp : pointer; block : word; begin p := NIL; { Handle the easy cases first } if memsize > maxavail then exit else if memsize <= blocksize then begin getmem(p, memsize); if not NewAllocation(p, p, memsize) then begin FreeMem(p, memsize); p := NIL; end; end else begin size := memsize + 15; { Find the block that has enough space } prev := PFreeRec(@freeList); free := prev^.next; while (free <> heapptr) and (ptr2int(free^.size) < size) do begin prev := free; free := prev^.next; end; { Now free points to a region with enough space; make it the first one and multiple allocations will be contiguous. } save := freelist; freelist := free; { In TP 6, this works; check against other heap managers } while size > 0 do begin { block := minimum(size, blocksize); } if size > blocksize then block := blocksize else block := size; dec(size,block); getmem(temp,block); end; { We've got what we want now; just sort things out and restore the free list to normal } p := free; if prev^.next <> freelist then begin prev^.next := freelist; freelist := save; end; if (p <> NIL) then begin { return pointer with 0 offset } temp := p; if Ofs(p^)<>0 Then p := Ptr(Seg(p^)+1,0); { hack } if not NewAllocation(temp, p, memsize + 15) then begin FreeHuge(temp, size); p := NIL; end; end; end; end; {$ENDIF} procedure zmemcpy(destp : pBytef; sourcep : pBytef; len : uInt); begin Move(sourcep^, destp^, len); end; function zmemcmp(s1p, s2p : pBytef; len : uInt) : int; var j : uInt; source, dest : pBytef; begin source := s1p; dest := s2p; for j := 0 to pred(len) do begin if (source^ <> dest^) then begin zmemcmp := 2*Ord(source^ > dest^)-1; exit; end; Inc(source); Inc(dest); end; zmemcmp := 0; end; procedure zmemzero(destp : pBytef; len : uInt); begin FillChar(destp^, len, 0); end; procedure zcfree(opaque : voidpf; ptr : voidpf); {$ifdef Delphi16} var Handle : THandle; {$endif} {$IFDEF FPC} var memsize : uint; {$ENDIF} begin {$IFDEF DPMI} {h :=} GlobalFreePtr(ptr); {$ELSE} {$IFDEF CALL_DOS} dosFree(ptr); {$ELSE} {$ifdef HugeMem} FreeMemHuge(ptr); {$else} {$ifdef Delphi16} Handle := GlobalHandle(LH(ptr).H); { HiWord(LongInt(ptr)) } GlobalUnLock(Handle); GlobalFree(Handle); {$else} {$IFDEF FPC} Dec(puIntf(ptr)); memsize := puIntf(ptr)^; FreeMem(ptr, memsize+SizeOf(uInt)); {$ELSE} FreeMem(ptr); { Delphi 2,3,4 } {$ENDIF} {$endif} {$endif} {$ENDIF} {$ENDIF} end; function zcalloc (opaque : voidpf; items : uInt; size : uInt) : voidpf; var p : voidpf; memsize : uLong; {$ifdef Delphi16} handle : THandle; {$endif} begin memsize := uLong(items) * size; {$IFDEF DPMI} p := GlobalAllocPtr(gmem_moveable, memsize); {$ELSE} {$IFDEF CALLDOS} p := dosAlloc(memsize); {$ELSE} {$ifdef HugeMem} GetMemHuge(p, memsize); {$else} {$ifdef Delphi16} Handle := GlobalAlloc(HeapAllocFlags, memsize); p := GlobalLock(Handle); {$else} {$IFDEF FPC} GetMem(p, memsize+SizeOf(uInt)); puIntf(p)^:= memsize; Inc(puIntf(p)); {$ELSE} GetMem(p, memsize); { Delphi: p := AllocMem(memsize); } {$ENDIF} {$endif} {$endif} {$ENDIF} {$ENDIF} zcalloc := p; end; {$WARNINGS OFF} end. { edited from a SWAG posting: In Turbo Pascal 6, the heap is the memory allocated when using the Procedures 'New' and 'GetMem'. The heap starts at the address location pointed to by 'Heaporg' and grows to higher addresses as more memory is allocated. The top of the heap, the first address of allocatable memory space above the allocated memory space, is pointed to by 'HeapPtr'. Memory is deallocated by the Procedures 'Dispose' and 'FreeMem'. As memory blocks are deallocated more memory becomes available, but..... When a block of memory, which is not the top-most block in the heap is deallocated, a gap in the heap will appear. to keep track of these gaps Turbo Pascal maintains a so called free list. The Function 'MaxAvail' holds the size of the largest contiguous free block _in_ the heap. The Function 'MemAvail' holds the sum of all free blocks in the heap. TP6.0 keeps track of the free blocks by writing a 'free list Record' to the first eight Bytes of the freed memory block! A (TP6.0) free-list Record contains two four Byte Pointers of which the first one points to the next free memory block, the second Pointer is not a Real Pointer but contains the size of the memory block. Summary TP6.0 maintains a linked list with block sizes and Pointers to the _next_ free block. An extra heap Variable 'Heapend' designate the end of the heap. When 'HeapPtr' and 'FreeList' have the same value, the free list is empty. TP6.0 Heapend ÚÄÄÄÄÄÄÄÄÄ¿ <ÄÄÄÄ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ HeapPtr ÚÄ>ÃÄÄÄÄÄÄÄÄÄ´ <ÄÄÄÄ ³ ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄ´ ÀÄij Free ³ ÚÄ>ÃÄÄÄÄÄÄÄÄÄ´ ³ ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄ´ ÀÄij Free ³ FreeList ÃÄÄÄÄÄÄÄÄÄ´ <ÄÄÄÄ ³ ³ Heaporg ÃÄÄÄÄÄÄÄÄÄ´ <ÄÄÄÄ } {$WARNINGS ON} |
06-19-2007, 22:06 | #8 (permalink) |
Freak Poster Join Date: Jul 2005 Age: 46
Posts: 366
Member: 163721 Status: Offline Thanks Meter: 148 | zconf.inc Code: { -------------------------------------------------------------------- } {$DEFINE MAX_MATCH_IS_258} { Compile with -DMAXSEG_64K if the alloc function cannot allocate more than 64k bytes at a time (needed on systems with 16-bit int). } {- $DEFINE MAXSEG_64K} {$IFDEF VER70} {$DEFINE MAXSEG_64K} {$ENDIF} {$IFNDEF WIN32} {$DEFINE UNALIGNED_OK} { requires SizeOf(ush) = 2 ! } {$ENDIF} {$UNDEF DYNAMIC_CRC_TABLE} {$UNDEF FASTEST} {$define patch112} { apply patch from the zlib home page } { -------------------------------------------------------------------- } {$IFDEF WIN32} {$DEFINE Delphi32} {- $DEFINE Delphi5} { keep compiler quiet } {$ENDIF} {$IFDEF FPC} {$DEFINE Use32} {$UNDEF DPMI} {$UNDEF MSDOS} {$UNDEF UNALIGNED_OK} { requires SizeOf(ush) = 2 ! } {$UNDEF MAXSEG_64K} {$UNDEF Delphi32} {$ENDIF} |
06-25-2007, 14:52 | #10 (permalink) |
Freak Poster Join Date: Jun 2002 Age: 47
Posts: 352
Member: 13188 Status: Offline Thanks Meter: 201 | Hi . Code: unsigned long getCRC (char *pchBuf, int nBufLen) { int i; int nIndex; char ch; unsigned long res; unsigned long table [] = { 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D }; res = 0xFFFFFFFF; for (i=0;i<nBufLen+4;i++) { nIndex = (res >> 24) & 0xFF; if (i<nBufLen) ch = pchBuf[i]; else ch = 0x0; res = (res << 8) | ch; res ^= table[nIndex]; } return res; } |
06-25-2007, 17:35 | #11 (permalink) | |
No Life Poster Join Date: Apr 2005 Location: ALGERIA, Tlemcen, Tounane Age: 37
Posts: 4,191
Member: 135039 Status: Offline Thanks Meter: 1,486 | Can u explain us this ? !s Quote:
| |
06-26-2007, 09:31 | #12 (permalink) |
No Life Poster Join Date: Nov 2001 Location: England Age: 41
Posts: 2,821
Member: 7653 Status: Offline Thanks Meter: 823 | simple algo, your work is here: Code: res = 0xFFFFFFFF; for (i=0;i<nBufLen+4;i++) { nIndex = (res >> 24) & 0xFF; if (i<nBufLen) ch = pchBuf[i]; else ch = 0x0; res = (res << 8) | ch; res ^= table[nIndex]; each character from the inputted string is ORed with (0xFFFFFFFF shifted left by 8). the result of this is XORed with the table index to create you result |
Bookmarks |
| |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
ATF and Windows 7 32-bit / Windows 7 64-bit | frozenice | Advance-Box | 24 | 05-22-2012 09:41 |
We search Smart Breaker for this Algo | Fre3 Crack3r | Off Topic Zone | 4 | 02-05-2006 12:52 |
32 Bit or 64 Bit Diiferences? | WIFI | Bluetooth-Software | 1 | 11-25-2005 17:41 |
Search function is a bit lame :( | CountMagistus | Board, Server and Login Problems/Support | 2 | 02-28-2002 20:28 |
Convert Motorola S19 file - SHX 32 bit file to 16 bit file | ptkrf | Old Ericsson Phones & Sony Phones | 7 | 06-10-1999 19:41 |
|