Compare commits
3 commits
look-ahead
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
60d40ac81b | ||
|
f2988212b0 | ||
|
7dba51dd28 |
3 changed files with 75 additions and 9 deletions
|
@ -4,7 +4,7 @@
|
|||
This code is released under the terms of the MIT license.
|
||||
See COPYING.txt for details.
|
||||
|
||||
Copyright (c) 2013 Devin Acker
|
||||
Copyright (c) 2013-2015 Devin Acker
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -101,7 +101,7 @@ size_t pack(uint8_t *unpacked, size_t inputsize, uint8_t *packed, int fast) {
|
|||
|
||||
debug("inputsize = %d\n", inputsize);
|
||||
|
||||
for (uint16_t i = 0; i < inputsize - 4; i++) {
|
||||
for (uint16_t i = 0; inputsize >= 4 && i < inputsize - 4; i++) {
|
||||
tuple_t *tuple;
|
||||
int currbytes = COMBINE(unpacked[i], unpacked[i+1], unpacked[i+2], unpacked[i+3]);
|
||||
|
||||
|
@ -119,7 +119,7 @@ size_t pack(uint8_t *unpacked, size_t inputsize, uint8_t *packed, int fast) {
|
|||
// check for a potential RLE
|
||||
rle = rle_check(unpacked, unpacked + inpos, inputsize, fast);
|
||||
// check for a potential back reference
|
||||
if (rle.size < LONG_RUN_SIZE && inpos < inputsize - 3)
|
||||
if (rle.size < LONG_RUN_SIZE && inputsize >= 3 && inpos < inputsize - 3)
|
||||
backref = ref_search(unpacked, unpacked + inpos, inputsize, offsets, fast);
|
||||
else backref.size = 0;
|
||||
|
||||
|
@ -224,7 +224,7 @@ size_t unpack(uint8_t *packed, uint8_t *unpacked) {
|
|||
|
||||
// don't try to decompress > 64kb
|
||||
if (((command == 2) && (outpos + 2*length > DATA_SIZE))
|
||||
|| (outpos + length > DATA_SIZE)) {
|
||||
|| (outpos + length > DATA_SIZE)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
51
include/compress.h
Normal file
51
include/compress.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
exhal / inhal (de)compression routines
|
||||
|
||||
Copyright (c) 2013 Devin Acker
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _COMPRESS_H
|
||||
#define _COMPRESS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#define DATA_SIZE 65536
|
||||
#define RUN_SIZE 32
|
||||
#define LONG_RUN_SIZE 1024
|
||||
|
||||
extern size_t pack (uint8_t *unpacked, size_t inputsize, uint8_t *packed, int fast);
|
||||
extern size_t unpack (uint8_t *packed, uint8_t *unpacked);
|
||||
|
||||
extern size_t unpack_from_file (FILE *file, size_t offset, uint8_t *unpacked);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// end include guard
|
||||
#endif
|
25
makefile
25
makefile
|
@ -2,24 +2,26 @@
|
|||
# copyright 2013 Devin Acker (Revenant)
|
||||
# See copying.txt for legal information.
|
||||
|
||||
CFLAGS += -std=c99 -Os -Wall -s
|
||||
|
||||
CFLAGS += -std=c99 -Os -Wall -s -fpic
|
||||
# Add extension when compiling for Windows
|
||||
ifdef SystemRoot
|
||||
CC = gcc
|
||||
EXT = .exe
|
||||
LIBEXT = .dll
|
||||
RM = del
|
||||
else
|
||||
LIBEXT = .so
|
||||
endif
|
||||
|
||||
# Comment this line to suppress detailed decompression information on stdout
|
||||
DEFINES += -DEXTRA_OUT
|
||||
# Uncomment this line to enable debug output
|
||||
#DEFINES += -DDEBUG_OUT
|
||||
DEFINES += -DDEBUG_OUT
|
||||
|
||||
all: inhal$(EXT) exhal$(EXT)
|
||||
all: inhal$(EXT) exhal$(EXT) libexhal$(LIBEXT) libexhal.a
|
||||
|
||||
clean:
|
||||
$(RM) inhal$(EXT) exhal$(EXT) compress.o
|
||||
$(RM) inhal$(EXT) exhal$(EXT) compress.o libexhal.so
|
||||
|
||||
inhal$(EXT): inhal.c compress.o
|
||||
$(CC) $(DEFINES) $(CFLAGS) -o inhal$(EXT) inhal.c compress.o
|
||||
|
@ -29,3 +31,16 @@ exhal$(EXT): exhal.c compress.o
|
|||
|
||||
compress.o: compress.c
|
||||
$(CC) $(DEFINES) $(CFLAGS) -c compress.c
|
||||
|
||||
libexhal$(LIBEXT): compress.o
|
||||
gcc -shared -o $@ $^
|
||||
libexhal.a: compress.o
|
||||
ar rcs $@ $^
|
||||
install: all libexhal.so
|
||||
mkdir -pv /usr/local/bin
|
||||
cp inhal$(EXT) exhal$(EXT) /usr/local/bin
|
||||
mkdir -pv /usr/local/lib
|
||||
cp libexhal$(LIBEXT) /usr/local/lib
|
||||
cp libexhal.a /usr/local/lib
|
||||
mkdir -pv /usr/local/include
|
||||
cp include/* /usr/local/include
|
||||
|
|
Loading…
Reference in a new issue