17 #define IN_CHUNK_SIZE (16*1024)
33 size_t const writtenSize = fwrite(
buf, eltSize, nbElt,
f);
34 size_t const expectedSize = eltSize * nbElt;
35 if (nbElt>0)
assert(expectedSize / nbElt == eltSize);
36 if (writtenSize < expectedSize) {
38 fprintf(stderr,
"Write failed \n");
40 fprintf(stderr,
"Write too short \n");
59 void* inBuff,
size_t inChunkSize,
60 void* outBuff,
size_t outCapacity)
63 unsigned long long count_in = 0, count_out;
73 printf(
"Failed to start compression: error %u \n", (
unsigned)headerSize);
76 count_out = headerSize;
77 printf(
"Buffer size is %u bytes, header size %u bytes \n",
78 (
unsigned)outCapacity, (
unsigned)headerSize);
84 size_t const readSize = fread(inBuff, 1,
IN_CHUNK_SIZE, f_in);
85 if (readSize == 0)
break;
104 outBuff, outCapacity,
133 void*
const outbuff =
malloc(outbufCapacity);
140 outbuff, outbufCapacity);
142 printf(
"error : ressource allocation failed \n");
157 switch (
info->blockSizeID) {
164 printf(
"Impossible with expected frame specification (<=v1.6.1)\n");
173 void*
src,
size_t srcCapacity,
size_t filled,
size_t alreadyConsumed,
174 void*
dst,
size_t dstCapacity)
187 size_t readSize = firstChunk ? filled : fread(
src, 1, srcCapacity, f_in); firstChunk=0;
188 const void* srcPtr = (
const char*)
src + alreadyConsumed; alreadyConsumed=0;
189 const void*
const srcEnd = (
const char*)srcPtr + readSize;
190 if (readSize == 0 || ferror(f_in)) {
191 printf(
"Decompress: not enough input or error reading file\n");
199 while (srcPtr < srcEnd && ret != 0) {
201 size_t dstSize = dstCapacity;
202 size_t srcSize = (
const char*)srcEnd - (
const char*)srcPtr;
211 srcPtr = (
const char*)srcPtr +
srcSize;
220 if (srcPtr < srcEnd) {
221 printf(
"Decompress: Trailing data left in file after frame\n");
230 {
size_t const readSize = fread(
src, 1, 1, f_in);
231 if (readSize != 0 || !feof(f_in)) {
232 printf(
"Decompress: Trailing data left in file after frame\n");
244 void*
src,
size_t srcCapacity)
252 size_t const readSize = fread(
src, 1, srcCapacity, f_in);
253 if (readSize == 0 || ferror(f_in)) {
254 printf(
"Decompress: not enough input or error reading file\n");
259 size_t consumedSize = readSize;
271 if (!
dst) { perror(
"decompress_file(dst)");
return 1; }
276 src, srcCapacity, readSize-consumedSize, consumedSize,
280 return decompressionResult;
291 if (!
src) { perror(
"decompress_file(src)");
return 1; }
299 int const result = !dctx ? 1 :
315 size_t const r0 = fread(b0, 1,
sizeof(b0), fp0);
316 size_t const r1 = fread(
b1, 1,
sizeof(
b1), fp1);
319 if (!
r0 || !
r1)
break;
320 if (!result) result = memcmp(b0,
b1,
r0);
328 char inpFilename[256] = { 0 };
329 char lz4Filename[256] = { 0 };
330 char decFilename[256] = { 0 };
333 printf(
"Please specify input filename\n");
341 printf(
"inp = [%s]\n", inpFilename);
342 printf(
"lz4 = [%s]\n", lz4Filename);
343 printf(
"dec = [%s]\n", decFilename);
346 {
FILE*
const inpFp = fopen(inpFilename,
"rb");
347 FILE*
const outFp = fopen(lz4Filename,
"wb");
349 printf(
"compress : %s -> %s\n", inpFilename, lz4Filename);
356 printf(
"compress : failed with code %i\n", ret.
error);
359 printf(
"%s: %zu → %zu bytes, %.1f%%\n",
363 printf(
"compress : done\n");
367 {
FILE*
const inpFp = fopen(lz4Filename,
"rb");
368 FILE*
const outFp = fopen(decFilename,
"wb");
370 printf(
"decompress : %s -> %s\n", lz4Filename, decFilename);
377 printf(
"decompress : failed with code %i\n", ret);
380 printf(
"decompress : done\n");
384 {
FILE*
const inpFp = fopen(inpFilename,
"rb");
385 FILE*
const decFp = fopen(decFilename,
"rb");
387 printf(
"verify : %s <-> %s\n", inpFilename, decFilename);
394 printf(
"corruption detected : decompressed file differs from original\n");
static RzILOpEffect * cmp(cs_insn *insn, bool is_thumb)
RzBinInfo * info(RzBinFile *bf)
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
static compressResult_t compress_file(FILE *f_in, FILE *f_out)
int compareFiles(FILE *fp0, FILE *fp1)
int main(int argc, const char **argv)
static size_t get_block_size(const LZ4F_frameInfo_t *info)
static int decompress_file_internal(FILE *f_in, FILE *f_out, LZ4F_dctx *dctx, void *src, size_t srcCapacity, size_t filled, size_t alreadyConsumed, void *dst, size_t dstCapacity)
static compressResult_t compress_file_internal(FILE *f_in, FILE *f_out, LZ4F_compressionContext_t ctx, void *inBuff, size_t inChunkSize, void *outBuff, size_t outCapacity)
static void safe_fwrite(void *buf, size_t eltSize, size_t nbElt, FILE *f)
static int decompress_file_allocDst(FILE *f_in, FILE *f_out, LZ4F_dctx *dctx, void *src, size_t srcCapacity)
static const LZ4F_preferences_t kPrefs
static int decompress_file(FILE *f_in, FILE *f_out)
RZ_API void Ht_() free(HtName_(Ht) *ht)
void * malloc(size_t size)
static static fork const void static count static fd const char const char static newpath char char argv
LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_dctx *dctx)
size_t LZ4F_compressBegin(LZ4F_cctx *cctxPtr, void *dstBuffer, size_t dstCapacity, const LZ4F_preferences_t *preferencesPtr)
size_t LZ4F_compressUpdate(LZ4F_cctx *cctxPtr, void *dstBuffer, size_t dstCapacity, const void *srcBuffer, size_t srcSize, const LZ4F_compressOptions_t *compressOptionsPtr)
size_t LZ4F_decompress(LZ4F_dctx *dctx, void *dstBuffer, size_t *dstSizePtr, const void *srcBuffer, size_t *srcSizePtr, const LZ4F_decompressOptions_t *decompressOptionsPtr)
size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t *preferencesPtr)
LZ4F_errorCode_t LZ4F_freeCompressionContext(LZ4F_cctx *cctxPtr)
unsigned LZ4F_isError(LZ4F_errorCode_t code)
LZ4F_errorCode_t LZ4F_getFrameInfo(LZ4F_dctx *dctx, LZ4F_frameInfo_t *frameInfoPtr, const void *srcBuffer, size_t *srcSizePtr)
LZ4F_errorCode_t LZ4F_createDecompressionContext(LZ4F_dctx **LZ4F_decompressionContextPtr, unsigned versionNumber)
LZ4F_errorCode_t LZ4F_createCompressionContext(LZ4F_cctx **LZ4F_compressionContextPtr, unsigned version)
const char * LZ4F_getErrorName(LZ4F_errorCode_t code)
size_t LZ4F_compressEnd(LZ4F_cctx *cctxPtr, void *dstBuffer, size_t dstCapacity, const LZ4F_compressOptions_t *compressOptionsPtr)
#define LZ4F_HEADER_SIZE_MAX
assert(limit<=UINT32_MAX/2)
unsigned long long size_in
unsigned long long size_out