fix some mistakes but still the same segfault

This commit is contained in:
2025-04-18 16:38:04 +03:00
parent 1f985d3fba
commit 9d4984371b
2 changed files with 11 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
CFLAGS=-Wall -Wextra CFLAGS=-Wall -Wextra -g
LZMA_CFLAGS=-Wall -Wextra -O3 LZMA_CFLAGS=-Wall -Wextra -O3
all: kpack_c all: kpack_c
kpack_c: kpack_c.o LZMAEncoder.o MatchFinder.o RangeCoder.o kpack_c: kpack_c.o LZMAEncoder.o MatchFinder.o RangeCoder.o

View File

@@ -50,13 +50,16 @@ unsigned preprocess_calltrick(unsigned char *infile, unsigned insize, unsigned c
if (buf == NULL) { if (buf == NULL) {
goto pack_calltrick_fail; goto pack_calltrick_fail;
} }
*ctn = 0;
*cti = 0;
memset(ct1, 0, 256); memset(ct1, 0, 256);
unsigned char *infile_ptr = infile; unsigned char *infile_ptr = infile;
unsigned count = insize; unsigned count = insize;
unsigned char *buf_ptr = buf; unsigned char *buf_ptr = buf;
do { do {
unsigned al = *infile_ptr++; //printf("infile_ptr = %p, count = %u\n", infile_ptr, count);
unsigned al = *(infile_ptr++);
al -= 0x0E8; al -= 0x0E8;
if (al > 1) { if (al > 1) {
continue; continue;
@@ -76,8 +79,8 @@ unsigned preprocess_calltrick(unsigned char *infile, unsigned insize, unsigned c
num = byteswap(num); num = byteswap(num);
memcpy(infile_ptr - 4, &num, 4); memcpy(infile_ptr - 4, &num, 4);
(*ctn)++; (*ctn)++;
memcpy(buf_ptr, &infile_ptr, 4); memcpy(buf_ptr, &infile_ptr, sizeof(buf_ptr));
buf_ptr += 8; buf_ptr += sizeof(buf_ptr);
} }
} while(count > 0); } while(count > 0);
@@ -91,11 +94,11 @@ unsigned preprocess_calltrick(unsigned char *infile, unsigned insize, unsigned c
} }
*cti = ~(unsigned char)256; *cti = ~(unsigned char)256;
unsigned tmp; unsigned char *tmp;
while (buf_ptr != buf) { while (buf_ptr != buf) {
buf_ptr -= 8; buf_ptr -= sizeof(tmp);
memcpy(&tmp, buf_ptr, 4); memcpy(&tmp, buf_ptr, sizeof(tmp));
memcpy((unsigned char*)(size_t)(tmp - 4), cti, 1); memcpy(tmp - 4, cti, 1);
} }
free(buf); free(buf);
return tmp; return tmp;