impl more
This commit is contained in:
27
kpack_c.c
27
kpack_c.c
@@ -6,6 +6,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include "lzma_c/LZMAEncoderApi.h"
|
||||||
|
|
||||||
static const char* str_usage = "Usage: %s [--nologo / -n] [--kernel / -k] [--unpack / -u] <infile> [<outfile>]\n";
|
static const char* str_usage = "Usage: %s [--nologo / -n] [--kernel / -k] [--unpack / -u] <infile> [<outfile>]\n";
|
||||||
|
|
||||||
@@ -112,15 +113,33 @@ int main(int argc, char *argv[])
|
|||||||
fclose(infile_handle);
|
fclose(infile_handle);
|
||||||
|
|
||||||
// calculate maximum size of the output:
|
// calculate maximum size of the output:
|
||||||
unsigned bufsize = infile_size*9/8 + 0x400; // should be enough for header
|
unsigned max_output_size = infile_size*9/8 + 0x400; // should be enough for header
|
||||||
printf("bufsize = 0x%x\n", bufsize);
|
printf("max_output_size = 0x%x\n", max_output_size);
|
||||||
unsigned char *buf = malloc(2*bufsize); // allocate memory for two copies of maximum output
|
unsigned char *buf = malloc(2*max_output_size); // allocate memory for two copies of maximum output
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
error_malloc_failed();
|
error_malloc_failed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned char *outfile = buf, *outfile1 = buf, *outfilebest = buf, *outfile2 = buf + max_output_size;
|
||||||
|
memcpy(buf, "KPCK", 4);
|
||||||
|
memcpy(buf + 4, (void*)&infile_size, sizeof(infile_size));
|
||||||
|
|
||||||
|
unsigned log_dict_size = (31 - __builtin_clz(infile_size - 1)) + 1;
|
||||||
|
if (log_dict_size > 28) {
|
||||||
|
log_dict_size = 28;
|
||||||
|
}
|
||||||
|
lzma_set_dict_size(log_dict_size);
|
||||||
|
unsigned dict_size = (1 << log_dict_size);
|
||||||
|
|
||||||
|
unsigned workmem_size = dict_size*19/2 + 0x509000;
|
||||||
|
unsigned char *workmem = malloc(workmem_size);
|
||||||
|
if (workmem == NULL) {
|
||||||
|
error_malloc_failed();
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Compressing ... ");
|
||||||
|
|
||||||
// TODO ...
|
// TODO ...
|
||||||
// https://git.kolibrios.org/KolibriOS/kolibrios/src/commit/293e1d195a14d01a0f8812a954ff1449048f6209/programs/other/kpack/kerpack_linux/kpack64.asm#L236
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Reference in New Issue
Block a user