mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-07-05 20:51:18 -07:00
also delete *.bin and fpga_compressor when "make clean".
Add target to make fpga_compressor when client is not yet compiled. Get version information and cache it when client starts (avoids clearing BigBuf when calling hw version). Add some comments and remove debugging printouts. Add version info and ChangeLog in modified zlib.
This commit is contained in:
parent
4b3f6d79ea
commit
8e074056ac
16 changed files with 2132 additions and 99 deletions
|
@ -75,7 +75,10 @@ $(OBJDIR)/fpga_all.o: $(OBJDIR)/fpga_all.bit.z
|
|||
|
||||
$(OBJDIR)/fpga_all.bit.z: $(FPGA_BITSTREAMS) $(FPGA_COMPRESSOR)
|
||||
$(FPGA_COMPRESSOR) $(filter %.bit,$^) $@
|
||||
|
||||
|
||||
$(FPGA_COMPRESSOR):
|
||||
make -C ../client $(notdir $(FPGA_COMPRESSOR))
|
||||
|
||||
$(OBJDIR)/fullimage.stage1.elf: $(VERSIONOBJ) $(OBJDIR)/fpga_all.o $(THUMBOBJ) $(ARMOBJ)
|
||||
$(CC) $(LDFLAGS) -Wl,-T,ldscript,-Map,$(patsubst %.elf,%.map,$@) -o $@ $^ $(LIBS)
|
||||
|
||||
|
@ -107,6 +110,7 @@ clean:
|
|||
$(DELETE) $(OBJDIR)$(PATHSEP)*.map
|
||||
$(DELETE) $(OBJDIR)$(PATHSEP)*.d
|
||||
$(DELETE) $(OBJDIR)$(PATHSEP)*.z
|
||||
$(DELETE) $(OBJDIR)$(PATHSEP)*.bin
|
||||
$(DELETE) version.c
|
||||
|
||||
.PHONY: all clean help
|
||||
|
|
|
@ -313,8 +313,8 @@ extern struct version_information version_information;
|
|||
extern char *_bootphase1_version_pointer, _flash_start, _flash_end, _bootrom_start, _bootrom_end, __data_src_start__;
|
||||
void SendVersion(void)
|
||||
{
|
||||
char temp[512]; /* Limited data payload in USB packets */
|
||||
DbpString("Prox/RFID mark3 RFID instrument");
|
||||
char temp[USB_CMD_DATA_SIZE]; /* Limited data payload in USB packets */
|
||||
char VersionString[USB_CMD_DATA_SIZE] = { '\0' };
|
||||
|
||||
/* Try to find the bootrom version information. Expect to find a pointer at
|
||||
* symbol _bootphase1_version_pointer, perform slight sanity checks on the
|
||||
|
@ -322,24 +322,24 @@ void SendVersion(void)
|
|||
*/
|
||||
char *bootrom_version = *(char**)&_bootphase1_version_pointer;
|
||||
if( bootrom_version < &_flash_start || bootrom_version >= &_flash_end ) {
|
||||
DbpString("bootrom version information appears invalid");
|
||||
strcat(VersionString, "bootrom version information appears invalid\n");
|
||||
} else {
|
||||
FormatVersionInformation(temp, sizeof(temp), "bootrom: ", bootrom_version);
|
||||
DbpString(temp);
|
||||
strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1);
|
||||
}
|
||||
|
||||
FormatVersionInformation(temp, sizeof(temp), "os: ", &version_information);
|
||||
DbpString(temp);
|
||||
strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1);
|
||||
|
||||
FpgaGatherVersion(FPGA_BITSTREAM_LF, temp, sizeof(temp));
|
||||
DbpString(temp);
|
||||
strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1);
|
||||
FpgaGatherVersion(FPGA_BITSTREAM_HF, temp, sizeof(temp));
|
||||
DbpString(temp);
|
||||
strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1);
|
||||
|
||||
// Send Chip ID and used flash memory
|
||||
uint32_t text_and_rodata_section_size = (uint32_t)&__data_src_start__ - (uint32_t)&_flash_start;
|
||||
uint32_t compressed_data_section_size = common_area.arg1;
|
||||
cmd_send(CMD_ACK, *(AT91C_DBGU_CIDR), text_and_rodata_section_size + compressed_data_section_size, 0, NULL, 0);
|
||||
cmd_send(CMD_ACK, *(AT91C_DBGU_CIDR), text_and_rodata_section_size + compressed_data_section_size, 0, VersionString, strlen(VersionString));
|
||||
}
|
||||
|
||||
#ifdef WITH_LF
|
||||
|
|
|
@ -173,6 +173,10 @@ bool FpgaSetupSscDma(uint8_t *buf, int len)
|
|||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Uncompress (inflate) the FPGA data. Returns one decompressed byte with
|
||||
// each call.
|
||||
//----------------------------------------------------------------------------
|
||||
static int get_from_fpga_combined_stream(z_streamp compressed_fpga_stream, uint8_t *output_buffer)
|
||||
{
|
||||
if (fpga_image_ptr == compressed_fpga_stream->next_out) { // need more data
|
||||
|
@ -193,7 +197,11 @@ static int get_from_fpga_combined_stream(z_streamp compressed_fpga_stream, uint8
|
|||
return *fpga_image_ptr++;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Undo the interleaving of several FPGA config files. FPGA config files
|
||||
// are combined into one big file:
|
||||
// 288 bytes from FPGA file 1, followed by 288 bytes from FGPA file 2, etc.
|
||||
//----------------------------------------------------------------------------
|
||||
static int get_from_fpga_stream(int bitstream_version, z_streamp compressed_fpga_stream, uint8_t *output_buffer)
|
||||
{
|
||||
while((uncompressed_bytes_cnt / FPGA_INTERLEAVE_SIZE) % FPGA_BITSTREAM_MAX != (bitstream_version - 1)) {
|
||||
|
@ -208,18 +216,19 @@ static int get_from_fpga_stream(int bitstream_version, z_streamp compressed_fpga
|
|||
|
||||
static voidpf fpga_inflate_malloc(voidpf opaque, uInt items, uInt size)
|
||||
{
|
||||
Dbprintf("zlib requested %d bytes", items*size);
|
||||
return BigBuf_malloc(items*size);
|
||||
}
|
||||
|
||||
|
||||
static void fpga_inflate_free(voidpf opaque, voidpf address)
|
||||
{
|
||||
Dbprintf("zlib frees memory");
|
||||
BigBuf_free_keep_EM();
|
||||
BigBuf_free();
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Initialize decompression of the respective (HF or LF) FPGA stream
|
||||
//----------------------------------------------------------------------------
|
||||
static bool reset_fpga_stream(int bitstream_version, z_streamp compressed_fpga_stream, uint8_t *output_buffer)
|
||||
{
|
||||
uint8_t header[FPGA_BITSTREAM_FIXED_HEADER_SIZE];
|
||||
|
@ -234,7 +243,7 @@ static bool reset_fpga_stream(int bitstream_version, z_streamp compressed_fpga_s
|
|||
compressed_fpga_stream->zalloc = &fpga_inflate_malloc;
|
||||
compressed_fpga_stream->zfree = &fpga_inflate_free;
|
||||
|
||||
inflateInit2(compressed_fpga_stream, 15);
|
||||
inflateInit2(compressed_fpga_stream, 0);
|
||||
|
||||
fpga_image_ptr = output_buffer;
|
||||
|
||||
|
@ -330,8 +339,6 @@ static void DownloadFPGA(int bitstream_version, int FpgaImageLen, z_streamp comp
|
|||
DownloadFPGA_byte(b);
|
||||
}
|
||||
|
||||
Dbprintf("%d bytes loaded into FPGA", i);
|
||||
|
||||
// continue to clock FPGA until ready signal goes high
|
||||
i=100000;
|
||||
while ( (i--) && ( !(AT91C_BASE_PIOA->PIO_PDSR & GPIO_FPGA_DONE ) ) ) {
|
||||
|
@ -402,10 +409,10 @@ static int bitparse_find_section(int bitstream_version, char section_name, unsig
|
|||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Find out which FPGA image format is stored in flash, then call DownloadFPGA
|
||||
// with the right parameters to download the image
|
||||
//-----------------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------------
|
||||
// Check which FPGA image is currently loaded (if any). If necessary
|
||||
// decompress and load the correct (HF or LF) image to the FPGA
|
||||
//----------------------------------------------------------------------------
|
||||
void FpgaDownloadAndGo(int bitstream_version)
|
||||
{
|
||||
z_stream compressed_fpga_stream;
|
||||
|
@ -415,6 +422,9 @@ void FpgaDownloadAndGo(int bitstream_version)
|
|||
if (downloaded_bitstream == bitstream_version)
|
||||
return;
|
||||
|
||||
// make sure that we have enough memory to decompress
|
||||
BigBuf_free();
|
||||
|
||||
if (!reset_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer)) {
|
||||
return;
|
||||
}
|
||||
|
@ -426,10 +436,15 @@ void FpgaDownloadAndGo(int bitstream_version)
|
|||
}
|
||||
|
||||
inflateEnd(&compressed_fpga_stream);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gather version information from FPGA image. Needs to decompress the begin
|
||||
// of the respective (HF or LF) image.
|
||||
// Note: decompression makes use of (i.e. overwrites) BigBuf[]. It is therefore
|
||||
// advisable to call this only once and store the results for later use.
|
||||
//-----------------------------------------------------------------------------
|
||||
void FpgaGatherVersion(int bitstream_version, char *dst, int len)
|
||||
{
|
||||
unsigned int fpga_info_len;
|
||||
|
@ -439,6 +454,9 @@ void FpgaGatherVersion(int bitstream_version, char *dst, int len)
|
|||
|
||||
dst[0] = '\0';
|
||||
|
||||
// ensure that we can allocate enough memory for decompression:
|
||||
BigBuf_free();
|
||||
|
||||
if (!reset_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer)) {
|
||||
return;
|
||||
}
|
||||
|
@ -487,8 +505,9 @@ void FpgaGatherVersion(int bitstream_version, char *dst, int len)
|
|||
strncat(dst, tempstr, len-1);
|
||||
}
|
||||
|
||||
inflateEnd(&compressed_fpga_stream);
|
||||
strncat(dst, "\n", len-1);
|
||||
|
||||
inflateEnd(&compressed_fpga_stream);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -268,15 +268,15 @@ void FormatVersionInformation(char *dst, int len, const char *prefix, void *vers
|
|||
dst[0] = 0;
|
||||
strncat(dst, prefix, len-1);
|
||||
if(v->magic != VERSION_INFORMATION_MAGIC) {
|
||||
strncat(dst, "Missing/Invalid version information", len - strlen(dst) - 1);
|
||||
strncat(dst, "Missing/Invalid version information\n", len - strlen(dst) - 1);
|
||||
return;
|
||||
}
|
||||
if(v->versionversion != 1) {
|
||||
strncat(dst, "Version information not understood", len - strlen(dst) - 1);
|
||||
strncat(dst, "Version information not understood\n", len - strlen(dst) - 1);
|
||||
return;
|
||||
}
|
||||
if(!v->present) {
|
||||
strncat(dst, "Version information not available", len - strlen(dst) - 1);
|
||||
strncat(dst, "Version information not available\n", len - strlen(dst) - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -289,6 +289,7 @@ void FormatVersionInformation(char *dst, int len, const char *prefix, void *vers
|
|||
|
||||
strncat(dst, " ", len - strlen(dst) - 1);
|
||||
strncat(dst, v->buildtime, len - strlen(dst) - 1);
|
||||
strncat(dst, "\n", len - strlen(dst) - 1);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
|
|
@ -104,7 +104,8 @@ CMDSRCS = nonce2key/crapto1.c\
|
|||
protocols.c\
|
||||
|
||||
ZLIBSRCS = deflate.c adler32.c trees.c zutil.c inflate.c inffast.c inftrees.c
|
||||
ZLIB_FLAGS = -DZ_SOLO -DZ_PREFIX -DNO_GZIP -DZLIB_PM3_TUNED -DDEBUG -Dverbose=1
|
||||
ZLIB_FLAGS = -DZ_SOLO -DZ_PREFIX -DNO_GZIP -DZLIB_PM3_TUNED
|
||||
#-DDEBUG -Dverbose=1
|
||||
|
||||
|
||||
COREOBJS = $(CORESRCS:%.c=$(OBJDIR)/%.o)
|
||||
|
@ -113,7 +114,7 @@ ZLIBOBJS = $(ZLIBSRCS:%.c=$(OBJDIR)/%.o)
|
|||
|
||||
RM = rm -f
|
||||
BINS = proxmark3 flasher fpga_compress #snooper cli
|
||||
CLEAN = cli cli.exe flasher flasher.exe proxmark3 proxmark3.exe snooper snooper.exe $(CMDOBJS) $(OBJDIR)/*.o *.o *.moc.cpp
|
||||
CLEAN = cli cli.exe flasher flasher.exe proxmark3 proxmark3.exe fpga_compress fpga_compress.exe snooper snooper.exe $(CMDOBJS) $(OBJDIR)/*.o *.o *.moc.cpp
|
||||
|
||||
all: lua_build $(BINS)
|
||||
|
||||
|
|
|
@ -404,13 +404,24 @@ int CmdTune(const char *Cmd)
|
|||
|
||||
int CmdVersion(const char *Cmd)
|
||||
{
|
||||
UsbCommand c = {CMD_VERSION};
|
||||
UsbCommand resp;
|
||||
SendCommand(&c);
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
|
||||
lookupChipID(resp.arg[0], resp.arg[1]);
|
||||
}
|
||||
return 0;
|
||||
|
||||
UsbCommand c = {CMD_VERSION};
|
||||
static UsbCommand resp = {0, {0, 0, 0}};
|
||||
|
||||
if (resp.arg[0] == 0 && resp.arg[1] == 0) { // no cached information available
|
||||
SendCommand(&c);
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1000) && Cmd != NULL) {
|
||||
PrintAndLog("Prox/RFID mark3 RFID instrument");
|
||||
PrintAndLog((char*)resp.d.asBytes);
|
||||
lookupChipID(resp.arg[0], resp.arg[1]);
|
||||
}
|
||||
} else if (Cmd != NULL) {
|
||||
PrintAndLog("Prox/RFID mark3 RFID instrument");
|
||||
PrintAndLog((char*)resp.d.asBytes);
|
||||
lookupChipID(resp.arg[0], resp.arg[1]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static command_t CommandTable[] =
|
||||
|
|
|
@ -3,7 +3,10 @@
|
|||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Flasher frontend tool
|
||||
// Compression tool for FPGA config files. Compress several *.bit files at
|
||||
// compile time. Decompression is done at run time (see fpgaloader.c).
|
||||
// This uses the zlib library tuned to this specific case. The small file sizes
|
||||
// allow to use "insane" parameters for optimum compression ratio.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -17,8 +20,8 @@
|
|||
|
||||
// zlib configuration
|
||||
#define COMPRESS_LEVEL 9 // use best possible compression
|
||||
#define COMPRESS_WINDOW_BITS 15 // default = 15 for a window of 2^15 = 32KBytes
|
||||
#define COMPRESS_MEM_LEVEL 9 // determines the amount of memory allocated during compression. Default = 8. Must be < 9
|
||||
#define COMPRESS_WINDOW_BITS 15 // default = max = 15 for a window of 2^15 = 32KBytes
|
||||
#define COMPRESS_MEM_LEVEL 9 // determines the amount of memory allocated during compression. Default = 8.
|
||||
/* COMPRESS_STRATEGY can be
|
||||
Z_DEFAULT_STRATEGY (the default),
|
||||
Z_FILTERED (more huffmann, less string matching),
|
||||
|
@ -36,10 +39,12 @@
|
|||
#define FPGA_INTERLEAVE_SIZE 288 // (the FPGA's internal config frame size is 288 bits. Interleaving with 288 bytes should give best compression)
|
||||
#define FPGA_CONFIG_SIZE 42336 // our current fpga_[lh]f.bit files are 42175 bytes. Rounded up to next multiple of FPGA_INTERLEAVE_SIZE
|
||||
|
||||
static void usage(char *argv0)
|
||||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s <infile1> <infile2> ... <infile_n> <outfile>\n\n", argv0);
|
||||
fprintf(stderr, "Combines n FPGA bitstream files and compresses them into one.\n\n");
|
||||
fprintf(stderr, "Usage: fpga_compress <infile1> <infile2> ... <infile_n> <outfile>\n");
|
||||
fprintf(stderr, " Combine n FPGA bitstream files and compress them into one.\n\n");
|
||||
fprintf(stderr, " fpga_compress -d <infile> <outfile>");
|
||||
fprintf(stderr, " Decompress <infile>. Write result to <outfile>");
|
||||
}
|
||||
|
||||
|
||||
|
@ -77,7 +82,7 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile)
|
|||
|
||||
fpga_config = malloc(num_infiles * FPGA_CONFIG_SIZE);
|
||||
|
||||
// read the input files interleaving into fpga_config[]
|
||||
// read the input files. Interleave them into fpga_config[]
|
||||
i = 0;
|
||||
do {
|
||||
for(uint16_t j = 0; j < num_infiles; j++) {
|
||||
|
@ -100,8 +105,6 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile)
|
|||
}
|
||||
} while (!all_feof(infile, num_infiles));
|
||||
|
||||
fprintf(stderr, "Read a total of %ld bytes from %d files\n", i, num_infiles);
|
||||
|
||||
// initialize zlib structures
|
||||
compressed_fpga_stream.next_in = fpga_config;
|
||||
compressed_fpga_stream.avail_in = i;
|
||||
|
@ -120,7 +123,6 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile)
|
|||
uint8_t *outbuf = malloc(outsize_max);
|
||||
compressed_fpga_stream.next_out = outbuf;
|
||||
compressed_fpga_stream.avail_out = outsize_max;
|
||||
|
||||
|
||||
if (ret == Z_OK) {
|
||||
ret = deflateTune(&compressed_fpga_stream,
|
||||
|
@ -134,7 +136,7 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile)
|
|||
ret = deflate(&compressed_fpga_stream, Z_FINISH);
|
||||
}
|
||||
|
||||
fprintf(stderr, "\ncompressed %d input bytes to %d output bytes\n", i, compressed_fpga_stream.total_out);
|
||||
fprintf(stderr, "compressed %d input bytes to %d output bytes\n", i, compressed_fpga_stream.total_out);
|
||||
|
||||
if (ret != Z_STREAM_END) {
|
||||
fprintf(stderr, "Error in deflate(): %d %s\n", ret, compressed_fpga_stream.msg);
|
||||
|
@ -175,6 +177,7 @@ int zlib_decompress(FILE *infile, FILE *outfile)
|
|||
int ret;
|
||||
|
||||
z_stream compressed_fpga_stream;
|
||||
|
||||
// initialize zlib structures
|
||||
compressed_fpga_stream.next_in = inbuf;
|
||||
compressed_fpga_stream.avail_in = 0;
|
||||
|
@ -240,14 +243,14 @@ int main(int argc, char **argv)
|
|||
FILE *outfile;
|
||||
|
||||
if (argc == 1 || argc == 2) {
|
||||
usage(argv[0]);
|
||||
usage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "-d")) {
|
||||
if (!strcmp(argv[1], "-d")) { // Decompress
|
||||
infiles = calloc(1, sizeof(FILE*));
|
||||
if (argc != 4) {
|
||||
usage(argv[0]);
|
||||
usage();
|
||||
return -1;
|
||||
}
|
||||
infiles[0] = fopen(argv[2], "rb");
|
||||
|
@ -261,24 +264,22 @@ int main(int argc, char **argv)
|
|||
return -1;
|
||||
}
|
||||
return zlib_decompress(infiles[0], outfile);
|
||||
}
|
||||
|
||||
|
||||
infiles = calloc(argc-2, sizeof(FILE*));
|
||||
|
||||
for (uint16_t i = 0; i < argc-2; i++) {
|
||||
infiles[i] = fopen(argv[i+1], "rb");
|
||||
if (infiles[i] == NULL) {
|
||||
fprintf(stderr, "Error. Cannot open input file %s", argv[i+1]);
|
||||
} else { // Compress
|
||||
|
||||
infiles = calloc(argc-2, sizeof(FILE*));
|
||||
for (uint16_t i = 0; i < argc-2; i++) {
|
||||
infiles[i] = fopen(argv[i+1], "rb");
|
||||
if (infiles[i] == NULL) {
|
||||
fprintf(stderr, "Error. Cannot open input file %s", argv[i+1]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
outfile = fopen(argv[argc-1], "wb");
|
||||
if (outfile == NULL) {
|
||||
fprintf(stderr, "Error. Cannot open output file %s", argv[argc-1]);
|
||||
return -1;
|
||||
}
|
||||
return zlib_compress(infiles, argc-2, outfile);
|
||||
}
|
||||
|
||||
outfile = fopen(argv[argc-1], "wb");
|
||||
if (outfile == NULL) {
|
||||
fprintf(stderr, "Error. Cannot open output file %s", argv[argc-1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return zlib_compress(infiles, argc-2, outfile);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include "ui.h"
|
||||
#include "sleep.h"
|
||||
#include "cmdparser.h"
|
||||
#include "cmdmain.h"
|
||||
#include "cmdhw.h"
|
||||
|
||||
// a global mutex to prevent interlaced printing from different threads
|
||||
pthread_mutex_t print_lock;
|
||||
|
@ -105,6 +105,8 @@ static void *main_loop(void *targ) {
|
|||
if (arg->usb_present == 1) {
|
||||
rarg.run = 1;
|
||||
pthread_create(&reader_thread, NULL, &uart_receiver, &rarg);
|
||||
// cache Version information now:
|
||||
CmdVersion(NULL);
|
||||
}
|
||||
|
||||
FILE *script_file = NULL;
|
||||
|
|
1481
zlib/ChangeLog
Normal file
1481
zlib/ChangeLog
Normal file
File diff suppressed because it is too large
Load diff
368
zlib/FAQ
Normal file
368
zlib/FAQ
Normal file
|
@ -0,0 +1,368 @@
|
|||
|
||||
Frequently Asked Questions about zlib
|
||||
|
||||
|
||||
If your question is not there, please check the zlib home page
|
||||
http://zlib.net/ which may have more recent information.
|
||||
The lastest zlib FAQ is at http://zlib.net/zlib_faq.html
|
||||
|
||||
|
||||
1. Is zlib Y2K-compliant?
|
||||
|
||||
Yes. zlib doesn't handle dates.
|
||||
|
||||
2. Where can I get a Windows DLL version?
|
||||
|
||||
The zlib sources can be compiled without change to produce a DLL. See the
|
||||
file win32/DLL_FAQ.txt in the zlib distribution. Pointers to the
|
||||
precompiled DLL are found in the zlib web site at http://zlib.net/ .
|
||||
|
||||
3. Where can I get a Visual Basic interface to zlib?
|
||||
|
||||
See
|
||||
* http://marknelson.us/1997/01/01/zlib-engine/
|
||||
* win32/DLL_FAQ.txt in the zlib distribution
|
||||
|
||||
4. compress() returns Z_BUF_ERROR.
|
||||
|
||||
Make sure that before the call of compress(), the length of the compressed
|
||||
buffer is equal to the available size of the compressed buffer and not
|
||||
zero. For Visual Basic, check that this parameter is passed by reference
|
||||
("as any"), not by value ("as long").
|
||||
|
||||
5. deflate() or inflate() returns Z_BUF_ERROR.
|
||||
|
||||
Before making the call, make sure that avail_in and avail_out are not zero.
|
||||
When setting the parameter flush equal to Z_FINISH, also make sure that
|
||||
avail_out is big enough to allow processing all pending input. Note that a
|
||||
Z_BUF_ERROR is not fatal--another call to deflate() or inflate() can be
|
||||
made with more input or output space. A Z_BUF_ERROR may in fact be
|
||||
unavoidable depending on how the functions are used, since it is not
|
||||
possible to tell whether or not there is more output pending when
|
||||
strm.avail_out returns with zero. See http://zlib.net/zlib_how.html for a
|
||||
heavily annotated example.
|
||||
|
||||
6. Where's the zlib documentation (man pages, etc.)?
|
||||
|
||||
It's in zlib.h . Examples of zlib usage are in the files test/example.c
|
||||
and test/minigzip.c, with more in examples/ .
|
||||
|
||||
7. Why don't you use GNU autoconf or libtool or ...?
|
||||
|
||||
Because we would like to keep zlib as a very small and simple package.
|
||||
zlib is rather portable and doesn't need much configuration.
|
||||
|
||||
8. I found a bug in zlib.
|
||||
|
||||
Most of the time, such problems are due to an incorrect usage of zlib.
|
||||
Please try to reproduce the problem with a small program and send the
|
||||
corresponding source to us at zlib@gzip.org . Do not send multi-megabyte
|
||||
data files without prior agreement.
|
||||
|
||||
9. Why do I get "undefined reference to gzputc"?
|
||||
|
||||
If "make test" produces something like
|
||||
|
||||
example.o(.text+0x154): undefined reference to `gzputc'
|
||||
|
||||
check that you don't have old files libz.* in /usr/lib, /usr/local/lib or
|
||||
/usr/X11R6/lib. Remove any old versions, then do "make install".
|
||||
|
||||
10. I need a Delphi interface to zlib.
|
||||
|
||||
See the contrib/delphi directory in the zlib distribution.
|
||||
|
||||
11. Can zlib handle .zip archives?
|
||||
|
||||
Not by itself, no. See the directory contrib/minizip in the zlib
|
||||
distribution.
|
||||
|
||||
12. Can zlib handle .Z files?
|
||||
|
||||
No, sorry. You have to spawn an uncompress or gunzip subprocess, or adapt
|
||||
the code of uncompress on your own.
|
||||
|
||||
13. How can I make a Unix shared library?
|
||||
|
||||
By default a shared (and a static) library is built for Unix. So:
|
||||
|
||||
make distclean
|
||||
./configure
|
||||
make
|
||||
|
||||
14. How do I install a shared zlib library on Unix?
|
||||
|
||||
After the above, then:
|
||||
|
||||
make install
|
||||
|
||||
However, many flavors of Unix come with a shared zlib already installed.
|
||||
Before going to the trouble of compiling a shared version of zlib and
|
||||
trying to install it, you may want to check if it's already there! If you
|
||||
can #include <zlib.h>, it's there. The -lz option will probably link to
|
||||
it. You can check the version at the top of zlib.h or with the
|
||||
ZLIB_VERSION symbol defined in zlib.h .
|
||||
|
||||
15. I have a question about OttoPDF.
|
||||
|
||||
We are not the authors of OttoPDF. The real author is on the OttoPDF web
|
||||
site: Joel Hainley, jhainley@myndkryme.com.
|
||||
|
||||
16. Can zlib decode Flate data in an Adobe PDF file?
|
||||
|
||||
Yes. See http://www.pdflib.com/ . To modify PDF forms, see
|
||||
http://sourceforge.net/projects/acroformtool/ .
|
||||
|
||||
17. Why am I getting this "register_frame_info not found" error on Solaris?
|
||||
|
||||
After installing zlib 1.1.4 on Solaris 2.6, running applications using zlib
|
||||
generates an error such as:
|
||||
|
||||
ld.so.1: rpm: fatal: relocation error: file /usr/local/lib/libz.so:
|
||||
symbol __register_frame_info: referenced symbol not found
|
||||
|
||||
The symbol __register_frame_info is not part of zlib, it is generated by
|
||||
the C compiler (cc or gcc). You must recompile applications using zlib
|
||||
which have this problem. This problem is specific to Solaris. See
|
||||
http://www.sunfreeware.com for Solaris versions of zlib and applications
|
||||
using zlib.
|
||||
|
||||
18. Why does gzip give an error on a file I make with compress/deflate?
|
||||
|
||||
The compress and deflate functions produce data in the zlib format, which
|
||||
is different and incompatible with the gzip format. The gz* functions in
|
||||
zlib on the other hand use the gzip format. Both the zlib and gzip formats
|
||||
use the same compressed data format internally, but have different headers
|
||||
and trailers around the compressed data.
|
||||
|
||||
19. Ok, so why are there two different formats?
|
||||
|
||||
The gzip format was designed to retain the directory information about a
|
||||
single file, such as the name and last modification date. The zlib format
|
||||
on the other hand was designed for in-memory and communication channel
|
||||
applications, and has a much more compact header and trailer and uses a
|
||||
faster integrity check than gzip.
|
||||
|
||||
20. Well that's nice, but how do I make a gzip file in memory?
|
||||
|
||||
You can request that deflate write the gzip format instead of the zlib
|
||||
format using deflateInit2(). You can also request that inflate decode the
|
||||
gzip format using inflateInit2(). Read zlib.h for more details.
|
||||
|
||||
21. Is zlib thread-safe?
|
||||
|
||||
Yes. However any library routines that zlib uses and any application-
|
||||
provided memory allocation routines must also be thread-safe. zlib's gz*
|
||||
functions use stdio library routines, and most of zlib's functions use the
|
||||
library memory allocation routines by default. zlib's *Init* functions
|
||||
allow for the application to provide custom memory allocation routines.
|
||||
|
||||
Of course, you should only operate on any given zlib or gzip stream from a
|
||||
single thread at a time.
|
||||
|
||||
22. Can I use zlib in my commercial application?
|
||||
|
||||
Yes. Please read the license in zlib.h.
|
||||
|
||||
23. Is zlib under the GNU license?
|
||||
|
||||
No. Please read the license in zlib.h.
|
||||
|
||||
24. The license says that altered source versions must be "plainly marked". So
|
||||
what exactly do I need to do to meet that requirement?
|
||||
|
||||
You need to change the ZLIB_VERSION and ZLIB_VERNUM #defines in zlib.h. In
|
||||
particular, the final version number needs to be changed to "f", and an
|
||||
identification string should be appended to ZLIB_VERSION. Version numbers
|
||||
x.x.x.f are reserved for modifications to zlib by others than the zlib
|
||||
maintainers. For example, if the version of the base zlib you are altering
|
||||
is "1.2.3.4", then in zlib.h you should change ZLIB_VERNUM to 0x123f, and
|
||||
ZLIB_VERSION to something like "1.2.3.f-zachary-mods-v3". You can also
|
||||
update the version strings in deflate.c and inftrees.c.
|
||||
|
||||
For altered source distributions, you should also note the origin and
|
||||
nature of the changes in zlib.h, as well as in ChangeLog and README, along
|
||||
with the dates of the alterations. The origin should include at least your
|
||||
name (or your company's name), and an email address to contact for help or
|
||||
issues with the library.
|
||||
|
||||
Note that distributing a compiled zlib library along with zlib.h and
|
||||
zconf.h is also a source distribution, and so you should change
|
||||
ZLIB_VERSION and ZLIB_VERNUM and note the origin and nature of the changes
|
||||
in zlib.h as you would for a full source distribution.
|
||||
|
||||
25. Will zlib work on a big-endian or little-endian architecture, and can I
|
||||
exchange compressed data between them?
|
||||
|
||||
Yes and yes.
|
||||
|
||||
26. Will zlib work on a 64-bit machine?
|
||||
|
||||
Yes. It has been tested on 64-bit machines, and has no dependence on any
|
||||
data types being limited to 32-bits in length. If you have any
|
||||
difficulties, please provide a complete problem report to zlib@gzip.org
|
||||
|
||||
27. Will zlib decompress data from the PKWare Data Compression Library?
|
||||
|
||||
No. The PKWare DCL uses a completely different compressed data format than
|
||||
does PKZIP and zlib. However, you can look in zlib's contrib/blast
|
||||
directory for a possible solution to your problem.
|
||||
|
||||
28. Can I access data randomly in a compressed stream?
|
||||
|
||||
No, not without some preparation. If when compressing you periodically use
|
||||
Z_FULL_FLUSH, carefully write all the pending data at those points, and
|
||||
keep an index of those locations, then you can start decompression at those
|
||||
points. You have to be careful to not use Z_FULL_FLUSH too often, since it
|
||||
can significantly degrade compression. Alternatively, you can scan a
|
||||
deflate stream once to generate an index, and then use that index for
|
||||
random access. See examples/zran.c .
|
||||
|
||||
29. Does zlib work on MVS, OS/390, CICS, etc.?
|
||||
|
||||
It has in the past, but we have not heard of any recent evidence. There
|
||||
were working ports of zlib 1.1.4 to MVS, but those links no longer work.
|
||||
If you know of recent, successful applications of zlib on these operating
|
||||
systems, please let us know. Thanks.
|
||||
|
||||
30. Is there some simpler, easier to read version of inflate I can look at to
|
||||
understand the deflate format?
|
||||
|
||||
First off, you should read RFC 1951. Second, yes. Look in zlib's
|
||||
contrib/puff directory.
|
||||
|
||||
31. Does zlib infringe on any patents?
|
||||
|
||||
As far as we know, no. In fact, that was originally the whole point behind
|
||||
zlib. Look here for some more information:
|
||||
|
||||
http://www.gzip.org/#faq11
|
||||
|
||||
32. Can zlib work with greater than 4 GB of data?
|
||||
|
||||
Yes. inflate() and deflate() will process any amount of data correctly.
|
||||
Each call of inflate() or deflate() is limited to input and output chunks
|
||||
of the maximum value that can be stored in the compiler's "unsigned int"
|
||||
type, but there is no limit to the number of chunks. Note however that the
|
||||
strm.total_in and strm_total_out counters may be limited to 4 GB. These
|
||||
counters are provided as a convenience and are not used internally by
|
||||
inflate() or deflate(). The application can easily set up its own counters
|
||||
updated after each call of inflate() or deflate() to count beyond 4 GB.
|
||||
compress() and uncompress() may be limited to 4 GB, since they operate in a
|
||||
single call. gzseek() and gztell() may be limited to 4 GB depending on how
|
||||
zlib is compiled. See the zlibCompileFlags() function in zlib.h.
|
||||
|
||||
The word "may" appears several times above since there is a 4 GB limit only
|
||||
if the compiler's "long" type is 32 bits. If the compiler's "long" type is
|
||||
64 bits, then the limit is 16 exabytes.
|
||||
|
||||
33. Does zlib have any security vulnerabilities?
|
||||
|
||||
The only one that we are aware of is potentially in gzprintf(). If zlib is
|
||||
compiled to use sprintf() or vsprintf(), then there is no protection
|
||||
against a buffer overflow of an 8K string space (or other value as set by
|
||||
gzbuffer()), other than the caller of gzprintf() assuring that the output
|
||||
will not exceed 8K. On the other hand, if zlib is compiled to use
|
||||
snprintf() or vsnprintf(), which should normally be the case, then there is
|
||||
no vulnerability. The ./configure script will display warnings if an
|
||||
insecure variation of sprintf() will be used by gzprintf(). Also the
|
||||
zlibCompileFlags() function will return information on what variant of
|
||||
sprintf() is used by gzprintf().
|
||||
|
||||
If you don't have snprintf() or vsnprintf() and would like one, you can
|
||||
find a portable implementation here:
|
||||
|
||||
http://www.ijs.si/software/snprintf/
|
||||
|
||||
Note that you should be using the most recent version of zlib. Versions
|
||||
1.1.3 and before were subject to a double-free vulnerability, and versions
|
||||
1.2.1 and 1.2.2 were subject to an access exception when decompressing
|
||||
invalid compressed data.
|
||||
|
||||
34. Is there a Java version of zlib?
|
||||
|
||||
Probably what you want is to use zlib in Java. zlib is already included
|
||||
as part of the Java SDK in the java.util.zip package. If you really want
|
||||
a version of zlib written in the Java language, look on the zlib home
|
||||
page for links: http://zlib.net/ .
|
||||
|
||||
35. I get this or that compiler or source-code scanner warning when I crank it
|
||||
up to maximally-pedantic. Can't you guys write proper code?
|
||||
|
||||
Many years ago, we gave up attempting to avoid warnings on every compiler
|
||||
in the universe. It just got to be a waste of time, and some compilers
|
||||
were downright silly as well as contradicted each other. So now, we simply
|
||||
make sure that the code always works.
|
||||
|
||||
36. Valgrind (or some similar memory access checker) says that deflate is
|
||||
performing a conditional jump that depends on an uninitialized value.
|
||||
Isn't that a bug?
|
||||
|
||||
No. That is intentional for performance reasons, and the output of deflate
|
||||
is not affected. This only started showing up recently since zlib 1.2.x
|
||||
uses malloc() by default for allocations, whereas earlier versions used
|
||||
calloc(), which zeros out the allocated memory. Even though the code was
|
||||
correct, versions 1.2.4 and later was changed to not stimulate these
|
||||
checkers.
|
||||
|
||||
37. Will zlib read the (insert any ancient or arcane format here) compressed
|
||||
data format?
|
||||
|
||||
Probably not. Look in the comp.compression FAQ for pointers to various
|
||||
formats and associated software.
|
||||
|
||||
38. How can I encrypt/decrypt zip files with zlib?
|
||||
|
||||
zlib doesn't support encryption. The original PKZIP encryption is very
|
||||
weak and can be broken with freely available programs. To get strong
|
||||
encryption, use GnuPG, http://www.gnupg.org/ , which already includes zlib
|
||||
compression. For PKZIP compatible "encryption", look at
|
||||
http://www.info-zip.org/
|
||||
|
||||
39. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
|
||||
|
||||
"gzip" is the gzip format, and "deflate" is the zlib format. They should
|
||||
probably have called the second one "zlib" instead to avoid confusion with
|
||||
the raw deflate compressed data format. While the HTTP 1.1 RFC 2616
|
||||
correctly points to the zlib specification in RFC 1950 for the "deflate"
|
||||
transfer encoding, there have been reports of servers and browsers that
|
||||
incorrectly produce or expect raw deflate data per the deflate
|
||||
specification in RFC 1951, most notably Microsoft. So even though the
|
||||
"deflate" transfer encoding using the zlib format would be the more
|
||||
efficient approach (and in fact exactly what the zlib format was designed
|
||||
for), using the "gzip" transfer encoding is probably more reliable due to
|
||||
an unfortunate choice of name on the part of the HTTP 1.1 authors.
|
||||
|
||||
Bottom line: use the gzip format for HTTP 1.1 encoding.
|
||||
|
||||
40. Does zlib support the new "Deflate64" format introduced by PKWare?
|
||||
|
||||
No. PKWare has apparently decided to keep that format proprietary, since
|
||||
they have not documented it as they have previous compression formats. In
|
||||
any case, the compression improvements are so modest compared to other more
|
||||
modern approaches, that it's not worth the effort to implement.
|
||||
|
||||
41. I'm having a problem with the zip functions in zlib, can you help?
|
||||
|
||||
There are no zip functions in zlib. You are probably using minizip by
|
||||
Giles Vollant, which is found in the contrib directory of zlib. It is not
|
||||
part of zlib. In fact none of the stuff in contrib is part of zlib. The
|
||||
files in there are not supported by the zlib authors. You need to contact
|
||||
the authors of the respective contribution for help.
|
||||
|
||||
42. The match.asm code in contrib is under the GNU General Public License.
|
||||
Since it's part of zlib, doesn't that mean that all of zlib falls under the
|
||||
GNU GPL?
|
||||
|
||||
No. The files in contrib are not part of zlib. They were contributed by
|
||||
other authors and are provided as a convenience to the user within the zlib
|
||||
distribution. Each item in contrib has its own license.
|
||||
|
||||
43. Is zlib subject to export controls? What is its ECCN?
|
||||
|
||||
zlib is not subject to export controls, and so is classified as EAR99.
|
||||
|
||||
44. Can you please sign these lengthy legal documents and fax them back to us
|
||||
so that we can use your software in our product?
|
||||
|
||||
No. Go away. Shoo.
|
124
zlib/README
Normal file
124
zlib/README
Normal file
|
@ -0,0 +1,124 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// This version of zlib is modified for use within the Proxmark3 project.
|
||||
// Files from the original distribution which are not required for this
|
||||
// purpose are not included. All modifications can easily be found
|
||||
// by searching for #ifdef ZLIB_PM3_TUNED and #ifndef ZLIB_PM3_TUNED.
|
||||
//
|
||||
// The rest of this file consists of the original README content
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ZLIB DATA COMPRESSION LIBRARY
|
||||
|
||||
zlib 1.2.8 is a general purpose data compression library. All the code is
|
||||
thread safe. The data format used by the zlib library is described by RFCs
|
||||
(Request for Comments) 1950 to 1952 in the files
|
||||
http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and
|
||||
rfc1952 (gzip format).
|
||||
|
||||
All functions of the compression library are documented in the file zlib.h
|
||||
(volunteer to write man pages welcome, contact zlib@gzip.org). A usage example
|
||||
of the library is given in the file test/example.c which also tests that
|
||||
the library is working correctly. Another example is given in the file
|
||||
test/minigzip.c. The compression library itself is composed of all source
|
||||
files in the root directory.
|
||||
|
||||
To compile all files and run the test program, follow the instructions given at
|
||||
the top of Makefile.in. In short "./configure; make test", and if that goes
|
||||
well, "make install" should work for most flavors of Unix. For Windows, use
|
||||
one of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use
|
||||
make_vms.com.
|
||||
|
||||
Questions about zlib should be sent to <zlib@gzip.org>, or to Gilles Vollant
|
||||
<info@winimage.com> for the Windows DLL version. The zlib home page is
|
||||
http://zlib.net/ . Before reporting a problem, please check this site to
|
||||
verify that you have the latest version of zlib; otherwise get the latest
|
||||
version and check whether the problem still exists or not.
|
||||
|
||||
PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help.
|
||||
|
||||
Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997
|
||||
issue of Dr. Dobb's Journal; a copy of the article is available at
|
||||
http://marknelson.us/1997/01/01/zlib-engine/ .
|
||||
|
||||
The changes made in version 1.2.8 are documented in the file ChangeLog.
|
||||
|
||||
Unsupported third party contributions are provided in directory contrib/ .
|
||||
|
||||
zlib is available in Java using the java.util.zip package, documented at
|
||||
http://java.sun.com/developer/technicalArticles/Programming/compression/ .
|
||||
|
||||
A Perl interface to zlib written by Paul Marquess <pmqs@cpan.org> is available
|
||||
at CPAN (Comprehensive Perl Archive Network) sites, including
|
||||
http://search.cpan.org/~pmqs/IO-Compress-Zlib/ .
|
||||
|
||||
A Python interface to zlib written by A.M. Kuchling <amk@amk.ca> is
|
||||
available in Python 1.5 and later versions, see
|
||||
http://docs.python.org/library/zlib.html .
|
||||
|
||||
zlib is built into tcl: http://wiki.tcl.tk/4610 .
|
||||
|
||||
An experimental package to read and write files in .zip format, written on top
|
||||
of zlib by Gilles Vollant <info@winimage.com>, is available in the
|
||||
contrib/minizip directory of zlib.
|
||||
|
||||
|
||||
Notes for some targets:
|
||||
|
||||
- For Windows DLL versions, please see win32/DLL_FAQ.txt
|
||||
|
||||
- For 64-bit Irix, deflate.c must be compiled without any optimization. With
|
||||
-O, one libpng test fails. The test works in 32 bit mode (with the -n32
|
||||
compiler flag). The compiler bug has been reported to SGI.
|
||||
|
||||
- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works
|
||||
when compiled with cc.
|
||||
|
||||
- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is
|
||||
necessary to get gzprintf working correctly. This is done by configure.
|
||||
|
||||
- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
|
||||
other compilers. Use "make test" to check your compiler.
|
||||
|
||||
- gzdopen is not supported on RISCOS or BEOS.
|
||||
|
||||
- For PalmOs, see http://palmzlib.sourceforge.net/
|
||||
|
||||
|
||||
Acknowledgments:
|
||||
|
||||
The deflate format used by zlib was defined by Phil Katz. The deflate and
|
||||
zlib specifications were written by L. Peter Deutsch. Thanks to all the
|
||||
people who reported problems and suggested various improvements in zlib; they
|
||||
are too numerous to cite here.
|
||||
|
||||
Copyright notice:
|
||||
|
||||
(C) 1995-2013 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
|
||||
jloup@gzip.org madler@alumni.caltech.edu
|
||||
|
||||
If you use the zlib library in a product, we would appreciate *not* receiving
|
||||
lengthy legal documents to sign. The sources are provided for free but without
|
||||
warranty of any kind. The library has been entirely written by Jean-loup
|
||||
Gailly and Mark Adler; it does not include third-party code.
|
||||
|
||||
If you redistribute modified sources, we would appreciate that you include in
|
||||
the file ChangeLog history information documenting your changes. Please read
|
||||
the FAQ for more information on the distribution of modified source versions.
|
|
@ -52,7 +52,7 @@
|
|||
#include "deflate.h"
|
||||
|
||||
const char deflate_copyright[] =
|
||||
" deflate 1.2.8 Copyright 1995-2013 Jean-loup Gailly and Mark Adler ";
|
||||
" deflate 1.2.8.f-Proxmark3 Copyright 1995-2013 Jean-loup Gailly and Mark Adler ";
|
||||
/*
|
||||
If you use the zlib library in a product, an acknowledgment is welcome
|
||||
in the documentation of your product. If for some reason you cannot
|
||||
|
@ -60,6 +60,15 @@ const char deflate_copyright[] =
|
|||
copyright string in the executable of your product.
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This version of zlib is modified for use within the Proxmark3 project.
|
||||
// Files from the original distribution which are not required for this
|
||||
// purpose are not included. All modifications can easily be found
|
||||
// by searching for #ifdef ZLIB_PM3_TUNED and #ifndef ZLIB_PM3_TUNED.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Function prototypes.
|
||||
*/
|
||||
|
@ -1727,12 +1736,11 @@ local block_state deflate_fast(s, flush)
|
|||
|
||||
|
||||
#ifdef ZLIB_PM3_TUNED
|
||||
local uInt try_harder(s, strstart, lookahead, hash_head, level)
|
||||
local uInt try_harder(s, strstart, lookahead, hash_head)
|
||||
deflate_state *s;
|
||||
uInt strstart;
|
||||
uInt lookahead;
|
||||
IPos hash_head;
|
||||
uInt level;
|
||||
{
|
||||
uInt strstart_save = s->strstart;
|
||||
s->strstart = strstart;
|
||||
|
@ -1768,22 +1776,11 @@ local uInt try_harder(s, strstart, lookahead, hash_head, level)
|
|||
} else {
|
||||
combined_gain = s->strstart - strstart + 1 - MIN_MATCH; // (possibly truncated) previous_length - 3 literals
|
||||
}
|
||||
if (level > 1 && s->strstart+1 <= s->window_size - MIN_LOOKAHEAD) { // test one level more
|
||||
s->prev_length = match_length;
|
||||
uInt save_ins_h = s->ins_h;
|
||||
UPDATE_HASH(s, s->ins_h, s->window[(s->strstart+1) + (MIN_MATCH-1)]);
|
||||
combined_gain += try_harder(s, s->strstart+1, s->lookahead-1, s->head[s->ins_h], level-1);
|
||||
s->ins_h = save_ins_h;
|
||||
if (match_length < MIN_MATCH) {
|
||||
combined_gain += 0; // no gain
|
||||
} else {
|
||||
if (match_length < MIN_MATCH) {
|
||||
combined_gain += 0; // no gain
|
||||
} else {
|
||||
combined_gain += match_length - MIN_MATCH; // match_length bytes coded as approx three literals
|
||||
}
|
||||
combined_gain += match_length - MIN_MATCH; // match_length bytes are coded as three literals
|
||||
}
|
||||
// if (combined_length > s->lookahead - 1) {
|
||||
// combined_length = s->lookahead;
|
||||
// }
|
||||
if (combined_gain >= best_combined_gain) { // in case of a tie we prefer the longer prev_length
|
||||
best_combined_gain = combined_gain;
|
||||
best_prev_length = s->strstart - strstart + 1;
|
||||
|
@ -1792,12 +1789,6 @@ local uInt try_harder(s, strstart, lookahead, hash_head, level)
|
|||
s->lookahead--;
|
||||
UPDATE_HASH(s, s->ins_h, s->window[(s->strstart) + (MIN_MATCH-1)]);
|
||||
hash_head = s->head[s->ins_h];
|
||||
// if (s->strstart - strstart + 1 == MIN_MATCH-1) { // a match with length == 2 is not possible
|
||||
// s->strstart++;
|
||||
// s->lookahead--;
|
||||
// UPDATE_HASH(s, s->ins_h, s->window[(s->strstart) + (MIN_MATCH-1)]);
|
||||
// hash_head = s->head[s->ins_h];
|
||||
// }
|
||||
} while (s->strstart <= strstart-1 + prev_length // try to truncate the previous match to 1, 3, ... prev_length
|
||||
&& s->strstart <= s->window_size - MIN_LOOKAHEAD); // watch out for the end of the input
|
||||
|
||||
|
@ -1806,11 +1797,6 @@ local uInt try_harder(s, strstart, lookahead, hash_head, level)
|
|||
s->ins_h = ins_h_save;
|
||||
s->match_length = current_match_length;
|
||||
s->match_start = current_match_start;
|
||||
if (prev_length >= MIN_MATCH) {
|
||||
if (best_prev_length != prev_length && best_prev_length >= MIN_MATCH) {
|
||||
printf("at %d, level %d: Reducing prev_length from %d to %d\n", s->strstart, level, prev_length, best_prev_length);
|
||||
}
|
||||
}
|
||||
if (best_prev_length >= MIN_MATCH) {
|
||||
s->prev_length = best_prev_length;
|
||||
s->match_length = MIN_MATCH - 1;
|
||||
|
@ -1865,7 +1851,7 @@ local block_state deflate_slow(s, flush)
|
|||
|
||||
#ifdef ZLIB_PM3_TUNED
|
||||
if (s->prev_length < s->max_lazy_match) {
|
||||
try_harder(s, s->strstart, s->lookahead, hash_head, 1);
|
||||
try_harder(s, s->strstart, s->lookahead, hash_head);
|
||||
}
|
||||
|
||||
#else
|
||||
|
|
|
@ -80,6 +80,15 @@
|
|||
* The history for versions after 1.2.0 are in ChangeLog in zlib distribution.
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This version of zlib is modified for use within the Proxmark3 project.
|
||||
// Files from the original distribution which are not required for this
|
||||
// purpose are not included. All modifications can easily be found
|
||||
// by searching for #ifdef ZLIB_PM3_TUNED and #ifndef ZLIB_PM3_TUNED.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
#include "inflate.h"
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#define MAXBITS 15
|
||||
|
||||
const char inflate_copyright[] =
|
||||
" inflate 1.2.8 Copyright 1995-2013 Mark Adler ";
|
||||
" inflate 1.2.8.f-Proxmark3 Copyright 1995-2013 Mark Adler ";
|
||||
/*
|
||||
If you use the zlib library in a product, an acknowledgment is welcome
|
||||
in the documentation of your product. If for some reason you cannot
|
||||
|
|
16
zlib/trees.c
16
zlib/trees.c
|
@ -32,8 +32,16 @@
|
|||
|
||||
/* @(#) $Id$ */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This version of zlib is modified for use within the Proxmark3 project.
|
||||
// Files from the original distribution which are not required for this
|
||||
// purpose are not included. All modifications can easily be found
|
||||
// by searching for #ifdef ZLIB_PM3_TUNED and #ifndef ZLIB_PM3_TUNED.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/* #define GEN_TREES_H */
|
||||
|
||||
|
||||
#include "deflate.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -910,10 +918,10 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
|
|||
ulg stored_len; /* length of input block */
|
||||
int last; /* one if this is the last block for a file */
|
||||
{
|
||||
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
|
||||
int max_blindex = 0; /* index of last bit length code of non zero freq */
|
||||
|
||||
#ifndef ZLIB_PM3_TUNED
|
||||
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
|
||||
|
||||
/* Build the Huffman trees unless a stored block is forced */
|
||||
if (s->level > 0) {
|
||||
#endif
|
||||
|
@ -938,6 +946,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
|
|||
*/
|
||||
max_blindex = build_bl_tree(s);
|
||||
|
||||
#ifndef ZLIB_PM3_TUNED
|
||||
/* Determine the best encoding. Compute the block lengths in bytes. */
|
||||
opt_lenb = (s->opt_len+3+7)>>3;
|
||||
static_lenb = (s->static_len+3+7)>>3;
|
||||
|
@ -946,7 +955,6 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
|
|||
opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
|
||||
s->last_lit));
|
||||
|
||||
#ifndef ZLIB_PM3_TUNED
|
||||
if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
|
||||
|
||||
} else {
|
||||
|
@ -980,7 +988,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
|
|||
s->compressed_len += 3 + s->static_len;
|
||||
#endif
|
||||
} else {
|
||||
#endif /* ZLIB_PM3_TUNED */
|
||||
#endif /* !ZLIB_PM3_TUNED */
|
||||
send_bits(s, (DYN_TREES<<1)+last, 3);
|
||||
send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
|
||||
max_blindex+1);
|
||||
|
|
18
zlib/zlib.h
18
zlib/zlib.h
|
@ -28,6 +28,13 @@
|
|||
(zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This version of zlib is modified for use within the Proxmark3 project.
|
||||
// Files from the original distribution which are not required for this
|
||||
// purpose are not included. All modifications can easily be found
|
||||
// by searching for #ifdef ZLIB_PM3_TUNED and #ifndef ZLIB_PM3_TUNED.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef ZLIB_H
|
||||
#define ZLIB_H
|
||||
|
||||
|
@ -37,12 +44,23 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef ZLIB_PM3_TUNED
|
||||
#define ZLIB_VERSION "1.2.8"
|
||||
#define ZLIB_VERNUM 0x1280
|
||||
#define ZLIB_VER_MAJOR 1
|
||||
#define ZLIB_VER_MINOR 2
|
||||
#define ZLIB_VER_REVISION 8
|
||||
#define ZLIB_VER_SUBREVISION 0
|
||||
#else
|
||||
#define ZLIB_VERSION "1.2.8.f-Proxmark3"
|
||||
#define ZLIB_VERNUM 0x128f
|
||||
#define ZLIB_VER_MAJOR 1
|
||||
#define ZLIB_VER_MINOR 2
|
||||
#define ZLIB_VER_REVISION 8
|
||||
#define ZLIB_VER_SUBREVISION f
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
The 'zlib' compression library provides in-memory compression and
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue