add first packing method
This commit is contained in:
34
kpack_c.c
34
kpack_c.c
@@ -8,6 +8,11 @@
|
||||
#include <sys/stat.h>
|
||||
#include "lzma_c/LZMAEncoderApi.h"
|
||||
|
||||
#define METHOD_LZMA 1
|
||||
#define METHOD_FLAG_CALLTRICK 0
|
||||
#define METHOD_FLAG_CALLTRICK_1 0x40
|
||||
#define METHOD_FLAG_CALLTRICK_2 0x80
|
||||
|
||||
static const char* str_usage = "Usage: %s [--nologo / -n] [--kernel / -k] [--unpack / -u] <infile> [<outfile>]\n";
|
||||
|
||||
static void error_load_infile() {
|
||||
@@ -20,6 +25,23 @@ static void error_malloc_failed() {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
unsigned byteswap(unsigned val)
|
||||
{
|
||||
val = ((val << 8) & 0xFF00FF00 ) | ((val >> 8) & 0xFF00FF );
|
||||
return (val << 16) | (val >> 16);
|
||||
}
|
||||
|
||||
unsigned pack_lzma(unsigned char *infile, unsigned char *outfile, unsigned insize, unsigned char *workmem, unsigned is_kerpack)
|
||||
{
|
||||
unsigned outsize = lzma_compress(infile, outfile + 11, insize, workmem, is_kerpack);
|
||||
unsigned tmp = 0;
|
||||
memcpy(&tmp, outfile + 12, 4);
|
||||
tmp = byteswap(tmp);
|
||||
memcpy(outfile + 12, &tmp, 4);
|
||||
return outsize - 1;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
bool flag_nologo = false;
|
||||
@@ -112,6 +134,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
fclose(infile_handle);
|
||||
|
||||
// TODO check option -k or not. Below goes packing for without -k option
|
||||
|
||||
// calculate maximum size of the output:
|
||||
unsigned max_output_size = infile_size*9/8 + 0x400; // should be enough for header
|
||||
printf("max_output_size = 0x%x\n", max_output_size);
|
||||
@@ -137,12 +161,18 @@ int main(int argc, char *argv[])
|
||||
error_malloc_failed();
|
||||
}
|
||||
|
||||
printf("Compressing ... ");
|
||||
printf("Compressing ... \n");
|
||||
|
||||
outfile = outfile2;
|
||||
memcpy(outfile2, outfile1, 8);
|
||||
// TODO call pack_lzma
|
||||
unsigned outsize = pack_lzma(infile_buf, outfile, infile_size, workmem, 0);
|
||||
printf("1. outsize = %u bytes\n", outsize);
|
||||
outfilebest = outfile;
|
||||
unsigned method = METHOD_LZMA;
|
||||
|
||||
// TODO ...
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user