diff --git a/precomp.cpp b/precomp.cpp index dbd0c01..27e3d8f 100644 --- a/precomp.cpp +++ b/precomp.cpp @@ -16,7 +16,7 @@ #define DLL __declspec(dllexport) #endif -//Version information +// version information #define V_MAJOR 0 #define V_MINOR 4 #define V_MINOR2 5 @@ -69,7 +69,7 @@ #include "contrib/bzip2/bzlib.h" -//GIF things +// GIF things const short InterlacedOffset[] = { 0, 4, 2, 1 }; /* The way Interlaced image should. */ const short InterlacedJumps[] = { 8, 8, 4, 2 }; /* be read - offsets and jumps... */ @@ -138,8 +138,8 @@ using namespace std; #include "contrib/zlib/zlib.h" -#define CHUNK 262144 //256 KB buffersize -#define DIV3CHUNK 262143 //DIV3CHUNK is a bit smaller/larger than CHUNK, so that DIV3CHUNK mod 3 = 0 +#define CHUNK 262144 // 256 KB buffersize +#define DIV3CHUNK 262143 // DIV3CHUNK is a bit smaller/larger than CHUNK, so that DIV3CHUNK mod 3 = 0 #define CHECKBUF_SIZE 4096 #define COPY_BUF_SIZE 512 #define FAST_COPY_WORK_SIGN_DIST 64 // update work sign after (FAST_COPY_WORK_SIGN_DIST * COPY_BUF_SIZE) bytes @@ -150,12 +150,12 @@ unsigned char copybuf[COPY_BUF_SIZE]; unsigned char in_buf[IN_BUF_SIZE]; long long in_buf_pos; -int cb; //"checkbuf" +int cb; // "checkbuf" unsigned char in[CHUNK]; unsigned char out[CHUNK]; -// Name of temporary files +// name of temporary files char metatempfile[18] = "~temp00000000.dat"; char tempfile0[19] = "~temp000000000.dat"; char tempfile1[19] = "~temp000000001.dat"; @@ -250,7 +250,7 @@ static char work_signs[5] = "|/-\\"; int work_sign_var = 0; long long work_sign_start_time = get_time_ms(); -// Recursion +// recursion int recursion_stack_size = 0; int recursion_depth = 0; int max_recursion_depth = 10; @@ -275,12 +275,12 @@ struct recursion_result { recursion_result recursion_compress(int compressed_bytes, int decompressed_bytes); recursion_result recursion_decompress(long long recursion_data_length); -// Compression-on-the-fly +// compression-on-the-fly unsigned char bz2_in[CHUNK]; unsigned char bz2_out[CHUNK]; -int compression_otf_method = 1; //0 = uncompressed, 1 = bZip2 -int conversion_from_method; //0 = uncompressed, 1 = bZip2 -int conversion_to_method; //0 = uncompressed, 1 = bZip2 +int compression_otf_method = 1; // 0 = uncompressed, 1 = bZip2 +int conversion_from_method; // 0 = uncompressed, 1 = bZip2 +int conversion_to_method; // 0 = uncompressed, 1 = bZip2 bool decompress_otf_end = false; bz_stream otf_bz2_stream_c, otf_bz2_stream_d; void own_fputc(char c, FILE* f); @@ -327,7 +327,7 @@ bool anything_was_used; bool level_switch_used = false; bool non_zlib_was_used; -//Statistics +// statistics unsigned int recompressed_streams_count = 0; unsigned int recompressed_pdf_count = 0; unsigned int recompressed_pdf_count_8_bit = 0; @@ -343,8 +343,8 @@ unsigned int recompressed_mp3_count = 0; unsigned int recompressed_swf_count = 0; unsigned int recompressed_base64_count = 0; unsigned int recompressed_bzip2_count = 0; -unsigned int recompressed_zlib_count = 0; //Intense mode -unsigned int recompressed_brute_count = 0; //Brute mode +unsigned int recompressed_zlib_count = 0; // intense mode +unsigned int recompressed_brute_count = 0; // brute mode unsigned int decompressed_streams_count = 0; unsigned int decompressed_pdf_count = 0; @@ -361,8 +361,8 @@ unsigned int decompressed_mp3_count = 0; unsigned int decompressed_swf_count = 0; unsigned int decompressed_base64_count = 0; unsigned int decompressed_bzip2_count = 0; -unsigned int decompressed_zlib_count = 0; //Intense mode -unsigned int decompressed_brute_count = 0; //Brute mode +unsigned int decompressed_zlib_count = 0; // intense mode +unsigned int decompressed_brute_count = 0; // brute mode #define P_NONE 0 #define P_COMPRESS 1 @@ -370,7 +370,7 @@ unsigned int decompressed_brute_count = 0; //Brute mode #define P_CONVERT 3 int comp_decomp_state = P_NONE; -//Penalty bytes +// penalty bytes #define MAX_PENALTY_BYTES 16384 long long compare_files_penalty(FILE* file1, FILE* file2, long long pos1, long long pos2); #ifndef PRECOMPDLL @@ -384,7 +384,7 @@ char* best_penalty_bytes; #endif int penalty_bytes_len = 0; -long long* ignore_list = NULL; //Positions to ignore +long long* ignore_list = NULL; // positions to ignore int ignore_list_len = 0; // Base64 line length list @@ -409,7 +409,7 @@ bool use_mjpeg = true; int slow_mode_depth_limit = -1; int brute_mode_depth_limit = -1; -//Compression type bools +// compression type bools bool use_pdf = true; bool use_zip = true; bool use_gzip = true; @@ -421,7 +421,7 @@ bool use_swf = true; bool use_base64 = true; bool use_bzip2 = true; -//Precomp DLL things +// Precomp DLL things #ifdef PRECOMPDLL #include "precomp.h" @@ -430,7 +430,7 @@ DLL void get_copyright_msg(char* msg); DLL bool precompress_file(char* in_file, char* out_file, char* msg, Switches switches); DLL bool recompress_file(char* in_file, char* out_file, char* msg, Switches switches); -//Get copyright message +// get copyright message // msg = Buffer for error messages (256 bytes buffer size are enough) DLL void get_copyright_msg(char* msg) { if (V_MINOR2 == 0) { @@ -477,13 +477,13 @@ void setSwitches(Switches switches) { } } -//Precompress a file +// precompress a file // in_file = input filename // out_file = output filename // msg = Buffer for error messages (256 bytes buffer size are enough) DLL bool precompress_file(char* in_file, char* out_file, char* msg, Switches switches) { - //Init compression and memory level count + // init compression and memory level count for (int i = 0; i < 81; i++) { comp_mem_level_count[i] = 0; zlib_level_was_used[i] = false; @@ -497,9 +497,6 @@ DLL bool precompress_file(char* in_file, char* out_file, char* msg, Switches swi return false; } - //fseek(fin, 0, SEEK_END); - //fin_length = ftell(fin); - //fseek(fin, 0, SEEK_SET); fout = fopen(out_file, "wb"); @@ -529,13 +526,13 @@ DLL bool precompress_file(char* in_file, char* out_file, char* msg, Switches swi return true; } -//Recompress a file +// recompress a file // in_file = input filename // out_file = output filename // msg = Buffer for error messages (256 bytes buffer size are enough) DLL bool recompress_file(char* in_file, char* out_file, char* msg, Switches switches) { - //Init compression and memory level count + // init compression and memory level count for (int i = 0; i < 81; i++) { comp_mem_level_count[i] = 0; zlib_level_was_used[i] = false; @@ -549,9 +546,6 @@ DLL bool recompress_file(char* in_file, char* out_file, char* msg, Switches swit return false; } - //fseek(fin, 0, SEEK_END); - //fin_length = ftell(fin); - //fseek(fin, 0, SEEK_SET); fout = fopen(out_file, "wb"); if (fout == NULL) { @@ -580,7 +574,7 @@ DLL bool recompress_file(char* in_file, char* out_file, char* msg, Switches swit return true; } -//Test if a file contains streams that can be precompressed +// test if a file contains streams that can be precompressed DLL bool file_precompressable(char* in, char* msg) { return false; } @@ -591,7 +585,7 @@ int main(int argc, char* argv[]) { int return_errorlevel = 0; - // Register CTRL-C handler + // register CTRL-C handler (void) signal(SIGINT, ctrl_c_handler); #ifndef COMFORT @@ -603,7 +597,7 @@ int main(int argc, char* argv[]) case P_COMPRESS: { start_time = get_time_ms(); - if (!compress_file()) { // None of the streams could be decompressed + if (!compress_file()) { // none of the streams could be decompressed return_errorlevel = RETURN_NOTHING_DECOMPRESSED; } break; @@ -625,7 +619,6 @@ int main(int argc, char* argv[]) } #ifdef COMFORT - //Wait for key wait_for_key(); #endif @@ -649,7 +642,7 @@ int init(int argc, char* argv[]) { printf(" - %s\n",V_MSG); printf("Free for non-commercial use - Copyright 2006-2016 by Christian Schneider\n\n"); - //Init compression and memory level count + // init compression and memory level count bool use_zlib_level[81]; for (i = 0; i < 81; i++) { comp_mem_level_count[i] = 0; @@ -668,7 +661,7 @@ int init(int argc, char* argv[]) { bool long_help = false; for (i = 1; (i < argc) && (parse_on); i++) { - if (argv[i][0] == '-') { //switch + if (argv[i][0] == '-') { // switch if (input_file_given) { valid_syntax = false; parse_on = false; @@ -683,7 +676,7 @@ int init(int argc, char* argv[]) { } case 'I': { - if (toupper(argv[i][2]) == 'N') { //intense mode + if (toupper(argv[i][2]) == 'N') { // intense mode if ((toupper(argv[i][3]) == 'T') && (toupper(argv[i][4]) == 'E') && (toupper(argv[i][5]) == 'N') && (toupper(argv[i][6]) == 'S') && (toupper(argv[i][7]) == 'E')) { slow_mode = true; @@ -885,34 +878,34 @@ int init(int argc, char* argv[]) { } for (j = 3; j < (int)strlen(argv[i]); j++) { switch (toupper(argv[i][j])) { - case 'P': //PDF + case 'P': // PDF use_pdf = set_to; break; - case 'Z': //ZIP + case 'Z': // ZIP use_zip = set_to; break; - case 'G': //GZip + case 'G': // GZip use_gzip = set_to; break; - case 'N': //PNG + case 'N': // PNG use_png = set_to; break; - case 'F': //GIF + case 'F': // GIF use_gif = set_to; break; - case 'J': //JPG + case 'J': // JPG use_jpg = set_to; break; - case '3': //MP3 + case '3': // MP3 use_mp3 = set_to; break; - case 'S': //SWF + case 'S': // SWF use_swf = set_to; break; - case 'M': //MIME Base64 + case 'M': // MIME Base64 use_base64 = set_to; break; - case 'B': //bZip2 + case 'B': // bZip2 use_bzip2 = set_to; break; default: @@ -926,7 +919,7 @@ int init(int argc, char* argv[]) { case 'C': { switch (toupper(argv[i][2])) { - case 'N': // No compression + case 'N': // no compression compression_otf_method = 0; break; case 'B': // bZip2 @@ -942,7 +935,7 @@ int init(int argc, char* argv[]) { case 'N': { switch (toupper(argv[i][2])) { - case 'N': // No compression + case 'N': // no compression conversion_to_method = 0; break; case 'B': // bZip2 @@ -1016,10 +1009,10 @@ int init(int argc, char* argv[]) { output_file_name = new char[strlen(argv[i]) + 5]; strcpy(output_file_name, argv[i] + 2); - //Check for backslash in file name + // check for backslash in file name char* backslash_at_pos = strrchr(output_file_name, PATH_DELIM); - //Dot in output file name? If not, use .pcf extension + // dot in output file name? If not, use .pcf extension char* dot_at_pos = strrchr(output_file_name, '.'); if ((dot_at_pos == NULL) || ((backslash_at_pos != NULL) && (backslash_at_pos > dot_at_pos))) { strcpy(output_file_name + strlen(argv[i]) - 2, ".pcf"); @@ -1068,7 +1061,7 @@ int init(int argc, char* argv[]) { exit(1); } } - } else { //no switch + } else { // no switch if (input_file_given) { error(ERR_MORE_THAN_ONE_INPUT_FILE); } @@ -1084,11 +1077,8 @@ int init(int argc, char* argv[]) { exit(1); } - //fseek(fin, 0, SEEK_END); - //fin_length = ftell(fin); - //fseek(fin, 0, SEEK_SET); - //Output file given? If not, use input filename with .pcf extension + // output file given? If not, use input filename with .pcf extension if ((!output_file_given) && (operation == P_COMPRESS)) { output_file_name = new char[strlen(input_file_name) + 9]; strcpy(output_file_name, input_file_name); @@ -1098,7 +1088,7 @@ int init(int argc, char* argv[]) { strcpy(output_file_name + strlen(input_file_name), ".pcf"); } else { strcpy(dot_at_pos, ".pcf"); - //Same as output file because input file had .pcf extension? + // same as output file because input file had .pcf extension? if (strcmp(input_file_name, output_file_name) == 0) { strcpy(dot_at_pos, "_pcf.pcf"); } @@ -1160,7 +1150,7 @@ int init(int argc, char* argv[]) { } if (operation == P_DECOMPRESS) { - //If .pcf was appended, remove it + // if .pcf was appended, remove it if (appended_pcf) { output_file_name[strlen(output_file_name)-4] = 0; } @@ -1198,7 +1188,6 @@ int init(int argc, char* argv[]) { printf("\n"); printf("Ignore position list:\n"); for (j = 0; j < ignore_list_len; j++) { - //printf("%u\n",ignore_list[j]); print64(ignore_list[j]); printf("\n"); } @@ -1247,7 +1236,7 @@ int init_comfort(int argc, char* argv[]) { printf(" - %s\n",V_MSG); printf("Free for non-commercial use - Copyright 2006-2016 by Christian Schneider\n\n"); - //Init compression and memory level count + // init compression and memory level count bool use_zlib_level[81]; for (i = 0; i < 81; i++) { comp_mem_level_count[i] = 0; @@ -1255,7 +1244,7 @@ int init_comfort(int argc, char* argv[]) { use_zlib_level[i] = true; } - //Parse parameters (should be input file only) + // parse parameters (should be input file only) if (argc == 1) { printf("Usage:\n"); printf("Drag and drop a file on the executable to precompress/restore it.\n"); @@ -1276,10 +1265,8 @@ int init_comfort(int argc, char* argv[]) { wait_for_key(); exit(1); } - //fseek(fin, 0, SEEK_END); - //fin_length = ftell(fin); - //fseek(fin, 0, SEEK_SET); - if (fin_length > 6) { + + if (fin_length > 6) { if (check_for_pcf_file()) { operation = P_DECOMPRESS; } @@ -1293,7 +1280,7 @@ int init_comfort(int argc, char* argv[]) { strcpy(output_file_name + strlen(input_file_name), ".pcf"); } else { strcpy(dot_at_pos, ".pcf"); - //Same as output file because input file had .pcf extension? + // same as output file because input file had .pcf extension? if (strcmp(input_file_name, output_file_name) == 0) { strcpy(dot_at_pos, "_pcf.pcf"); } @@ -1302,10 +1289,10 @@ int init_comfort(int argc, char* argv[]) { } - //Precomf.ini in EXE directory? + // precomf.ini in EXE directory? char precomf_ini[1024]; GetModuleFileName(NULL, precomf_ini, 1024); - //Truncate to get directory of executable only + // truncate to get directory of executable only char* lastslash = strrchr(precomf_ini, PATH_DELIM) + 1; strcpy(lastslash, "precomf.ini"); printf("INI file: %s\n", precomf_ini); @@ -1359,7 +1346,7 @@ int init_comfort(int argc, char* argv[]) { } if (parse_ini_file) { - //Parse INI file + // parse INI file bool print_ignore_positions_message = true; ifstream ini_file(precomf_ini); @@ -1375,7 +1362,7 @@ int init_comfort(int argc, char* argv[]) { line.erase(semicolon_at_pos, line.length() - semicolon_at_pos); } - //Valid line must contain an equal sign (=) + // valid line must contain an equal sign (=) string::size_type equal_at_pos = line.find("=", 0); if (line.empty()) { equal_at_pos = string::npos; @@ -1384,9 +1371,9 @@ int init_comfort(int argc, char* argv[]) { stringstream ss; ss << line; - //Get parameter name + // get parameter name getline(ss, parName, '='); - //Remove spaces + // remove spaces for (it = parName.begin(); it != parName.end(); it++) { if (*it == ' ') { parName.erase(it); @@ -1406,11 +1393,10 @@ int init_comfort(int argc, char* argv[]) { } memset(param, '\0', 256); parName.copy(param, 256); - //printf("parName: <%s>\n", param); - //Get value + // get value getline(ss, valuestr); - //Remove spaces + // remove spaces for (it = valuestr.begin(); it != valuestr.end(); it++) { if (*it == ' ') { valuestr.erase(it); @@ -1430,12 +1416,10 @@ int init_comfort(int argc, char* argv[]) { } memset(value, '\0', 256); valuestr.copy(value, 256); - //printf("value: <%s>\n", value); if (strcmp(param, "") != 0) { bool valid_param = false; - //Minimal identical byte size if (strcmp(param, "minimal_size") == 0) { if (min_ident_size_set) { error(ERR_ONLY_SET_MIN_SIZE_ONCE); @@ -1457,7 +1441,6 @@ int init_comfort(int argc, char* argv[]) { valid_param = true; } - //Verbose mode if (strcmp(param, "verbose") == 0) { if (strcmp(value, "off") == 0) { printf("INI: Disabled verbose mode\n"); @@ -1477,7 +1460,6 @@ int init_comfort(int argc, char* argv[]) { } } - //Compression method if (strcmp(param, "compression_method") == 0) { if (strcmp(value, "0") == 0) { printf("INI: Using no compression method\n"); @@ -1498,7 +1480,6 @@ int init_comfort(int argc, char* argv[]) { } } - //Fast mode if (strcmp(param, "fast_mode") == 0) { if (strcmp(value, "off") == 0) { printf("INI: Disabled fast mode\n"); @@ -1518,7 +1499,6 @@ int init_comfort(int argc, char* argv[]) { } } - //Intense mode if (strcmp(param, "intense_mode") == 0) { if (strcmp(value, "off") == 0) { printf("INI: Disabled intense mode\n"); @@ -1538,7 +1518,6 @@ int init_comfort(int argc, char* argv[]) { } } - //Brute mode if (strcmp(param, "brute_mode") == 0) { if (strcmp(value, "off") == 0) { printf("INI: Disabled brute mode\n"); @@ -1562,7 +1541,6 @@ int init_comfort(int argc, char* argv[]) { } } - //PDF BMP mode if (strcmp(param, "pdf_bmp_mode") == 0) { if (strcmp(value, "off") == 0) { printf("INI: Disabled PDF BMP mode\n"); @@ -1583,7 +1561,6 @@ int init_comfort(int argc, char* argv[]) { } } - //Progressive JPGs only if (strcmp(param, "jpg_progressive_only") == 0) { if (strcmp(value, "off") == 0) { printf("INI: Disabled progressive only JPG mode\n"); @@ -1604,7 +1581,6 @@ int init_comfort(int argc, char* argv[]) { } } - //MJPEG recompression if (strcmp(param, "mjpeg_recompression") == 0) { if (strcmp(value, "off") == 0) { printf("INI: Disabled MJPEG recompression\n"); @@ -1625,7 +1601,6 @@ int init_comfort(int argc, char* argv[]) { } } - //Compression types if (strcmp(param, "compression_types") == 0) { use_pdf = false; use_zip = false; @@ -1640,34 +1615,34 @@ int init_comfort(int argc, char* argv[]) { for (j = 0; j < (int)strlen(value); j++) { switch (toupper(value[j])) { - case 'P': //PDF + case 'P': // PDF use_pdf = true; break; - case 'Z': //ZIP + case 'Z': // ZIP use_zip = true; break; - case 'G': //GZip + case 'G': // GZip use_gzip = true; break; - case 'N': //PNG + case 'N': // PNG use_png = true; break; - case 'F': //GIF + case 'F': // GIF use_gif = true; break; - case 'J': //JPG + case 'J': // JPG use_jpg = true; break; - case '3': //MP3 + case '3': // MP3 use_mp3 = true; break; - case 'S': //SWF + case 'S': // SWF use_swf = true; break; - case 'M': //MIME Base64 + case 'M': // MIME Base64 use_base64 = true; break; - case 'B': //bZip2 + case 'B': // bZip2 use_bzip2 = true; break; default: @@ -1740,7 +1715,7 @@ int init_comfort(int argc, char* argv[]) { valid_param = true; } - //zLib levels + // zLib levels if (strcmp(param, "zlib_levels") == 0) { for (j = 0; j < 81; j++) { use_zlib_level[j] = false; @@ -1776,7 +1751,6 @@ int init_comfort(int argc, char* argv[]) { valid_param = true; } - //Maximal recursion depth if (strcmp(param, "maximal_recursion_depth") == 0) { if (recursion_depth_set) { error(ERR_ONLY_SET_RECURSION_DEPTH_ONCE); @@ -1799,7 +1773,6 @@ int init_comfort(int argc, char* argv[]) { valid_param = true; } - //Ignore position if (strcmp(param, "ignore_positions") == 0) { long long act_ignore_pos = -1; @@ -1830,7 +1803,6 @@ int init_comfort(int argc, char* argv[]) { ignore_list = (long long*)realloc(ignore_list, (ignore_list_len + 1) * sizeof(long long)); ignore_list[ignore_list_len] = act_ignore_pos; ignore_list_len++; - //printf ("INI: Added ignore position %i\n", act_ignore_pos); act_ignore_pos = -1; } break; @@ -1846,7 +1818,6 @@ int init_comfort(int argc, char* argv[]) { ignore_list = (long long*)realloc(ignore_list, (ignore_list_len + 1) * sizeof(long long)); ignore_list[ignore_list_len] = act_ignore_pos; ignore_list_len++; - //printf ("INI: Added ignore position %i\n", act_ignore_pos); } if (print_ignore_positions_message) { @@ -1899,7 +1870,6 @@ int init_comfort(int argc, char* argv[]) { printf("\n"); printf("Ignore position list:\n"); for (i = 0; i < ignore_list_len; i++) { - //printf("%u\n",ignore_list[i]); print64(ignore_list[i]); printf("\n"); } @@ -1972,7 +1942,7 @@ void denit_compress() { printf("\nDone.\n"); printf_time(get_time_ms() - start_time); - //Statistics + // statistics printf("\nRecompressed streams: %i/%i\n", recompressed_streams_count, decompressed_streams_count); if ((recompressed_streams_count > 0) || (decompressed_streams_count > 0)) { @@ -2352,7 +2322,7 @@ size_t fread_skip(unsigned char *ptr, size_t size, size_t count, FILE* stream) { if (read_tmp == 0) return bytes_read; bytes_read += read_tmp; } - // Skip padding bytes + // skip padding bytes read_tmp = own_fread(frs_skipbuf, size, frs_skip_len, stream); if (read_tmp == 0) return bytes_read; frs_offset = 0; @@ -2622,7 +2592,7 @@ int def_bzip2(FILE *source, FILE *dest, int level) { return BZ_OK; } -int file_recompress(FILE* origfile, int compression_level, int windowbits, int memlevel) { // Recompress file +int file_recompress(FILE* origfile, int compression_level, int windowbits, int memlevel) { int retval; ftempout = fopen(tempfile1,"rb"); @@ -2654,7 +2624,7 @@ int file_recompress(FILE* origfile, int compression_level, int windowbits, int m return retval; } -int file_recompress_bzip2(FILE* origfile, int level) { // Recompress file +int file_recompress_bzip2(FILE* origfile, int level) { int retval; ftempout = fopen(tempfile1,"rb"); @@ -2666,7 +2636,6 @@ int file_recompress_bzip2(FILE* origfile, int level) { // Recompress file frecomp = tryOpen(tempfile2,"w+b"); fseek(ftempout, 0, SEEK_SET); - //retval = def_compare(ftempout, frecomp, origfile, compression_level, windowbits, memlevel); retval = def_bzip2(ftempout, frecomp, level); if (retval > -1) { @@ -2758,7 +2727,7 @@ void start_uncompressed_data() { uncompressed_length = 0; uncompressed_pos = input_file_pos; - //Uncompressed data + // uncompressed data fout_fputc(0); uncompressed_data_in_work = true; @@ -2777,7 +2746,7 @@ void end_uncompressed_data() { fout_fputc((uncompressed_length >> 8) % 256); fout_fputc(uncompressed_length % 256); - //Fast copy of uncompressed data + // fast copy of uncompressed data seek_64(fin, uncompressed_pos); fast_copy(fin, fout, uncompressed_length); @@ -2807,12 +2776,12 @@ void try_decompression_pdf(int windowbits, int pdf_header_length, int img_width, identical_bytes_decomp = -1; real_identical_bytes = -1; final_compression_found = false; - int bmp_header_type = 0; //0 = none, 1 = 8-bit, 2 = 24-bit + int bmp_header_type = 0; // 0 = none, 1 = 8-bit, 2 = 24-bit - // Try to decompress at current position + // try to decompress at current position retval = try_to_decompress(fin, windowbits); - if (retval > 0) { //Seems to be a zLib-Stream + if (retval > 0) { // seems to be a zLib-Stream decompressed_streams_count++; if (img_bpc == 8) { @@ -2844,7 +2813,6 @@ void try_decompression_pdf(int windowbits, int pdf_header_length, int img_width, if (final_compression_found) break; } - //if ((best_identical_bytes > 4) && (best_identical_bytes < identical_bytes_decomp)) { if ((best_identical_bytes > min_ident_size) && (best_identical_bytes < identical_bytes_decomp)) { recompressed_streams_count++; recompressed_pdf_count++; @@ -2897,13 +2865,13 @@ void try_decompression_pdf(int windowbits, int pdf_header_length, int img_width, } } - //End uncompressed data + // end uncompressed data compressed_data_found = true; end_uncompressed_data(); - //Write compressed data header (PDF) without 12 first bytes - // (/FlateDecode) + // write compressed data header (PDF) without 12 first bytes + // (/FlateDecode) unsigned char bmp_c = 0; @@ -2920,7 +2888,7 @@ void try_decompression_pdf(int windowbits, int pdf_header_length, int img_width, } else { fout_fputc(1 + 2 + (best_compression << 2) + bmp_c); } - fout_fputc(0); //PDF + fout_fputc(0); // PDF fout_fputc((((-windowbits) - 8) << 4) + best_mem_level); pdf_header_length -= 12; @@ -2931,7 +2899,7 @@ void try_decompression_pdf(int windowbits, int pdf_header_length, int img_width, own_fwrite(in_buf + cb + 12, 1, pdf_header_length, fout); - //Store penalty bytes, if any + // store penalty bytes, if any if (best_penalty_bytes_len != 0) { if (DEBUG_MODE) { printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); @@ -2955,7 +2923,7 @@ void try_decompression_pdf(int windowbits, int pdf_header_length, int img_width, fout_fputc((best_identical_bytes_decomp >> 8) % 256); fout_fputc(best_identical_bytes_decomp % 256); - // Eventually write BMP header + // eventually write BMP header if (bmp_header_type > 0) { @@ -3030,14 +2998,14 @@ void try_decompression_pdf(int windowbits, int pdf_header_length, int img_width, } if (bmp_header_type == 1) { - // Write BMP palette + // write BMP palette for (i = 0; i < 1024; i++) { fout_fputc(0); } } } - // Write decompressed data + // write decompressed data if ((bmp_header_type == 0) || ((img_width % 4) == 0)) { write_decompressed_data(best_identical_bytes_decomp); @@ -3063,9 +3031,9 @@ void try_decompression_pdf(int windowbits, int pdf_header_length, int img_width, safe_fclose(&ftempout); } - //Start new uncompressed data + // start new uncompressed data - //Set input file pointer after recompressed data + // set input file pointer after recompressed data input_file_pos += best_identical_bytes - 1; cb += best_identical_bytes - 1; @@ -3093,10 +3061,10 @@ void try_decompression_zip(int zip_header_length) { int windowbits; - // Try to decompress at current position + // try to decompress at current position retval = try_to_decompress(fin, -15); - if (retval > 0) { //Seems to be a zLib-Stream + if (retval > 0) { // seems to be a zLib-Stream decompressed_streams_count++; decompressed_zip_count++; @@ -3125,7 +3093,6 @@ void try_decompression_zip(int zip_header_length) { } } - //if ((best_identical_bytes > 4) && (best_identical_bytes < identical_bytes_decomp)) { if ((best_identical_bytes > min_ident_size) && (best_identical_bytes < best_identical_bytes_decomp)) { recompressed_streams_count++; recompressed_zip_count++; @@ -3154,15 +3121,15 @@ void try_decompression_zip(int zip_header_length) { } } - //End uncompressed data + // end uncompressed data compressed_data_found = true; end_uncompressed_data(); - //Check recursion + // check recursion recursion_result r = recursion_compress(best_identical_bytes, best_identical_bytes_decomp); - //Write compressed data header (ZIP) without 4 first bytes (PK..) + // write compressed data header (ZIP) without 4 first bytes (PK..) int header_byte = 1 + (best_compression << 2); if (best_penalty_bytes_len != 0) { @@ -3172,7 +3139,7 @@ void try_decompression_zip(int zip_header_length) { header_byte += 128; } fout_fputc(header_byte); - fout_fputc(1); //ZIP + fout_fputc(1); // ZIP fout_fputc((((-windowbits) - 8) << 4) + best_mem_level); zip_header_length -= 4; @@ -3183,7 +3150,7 @@ void try_decompression_zip(int zip_header_length) { own_fwrite(in_buf + cb + 4, 1, zip_header_length, fout); - //Store penalty bytes, if any + // store penalty bytes, if any if (best_penalty_bytes_len != 0) { if (DEBUG_MODE) { printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); @@ -3218,7 +3185,7 @@ void try_decompression_zip(int zip_header_length) { fout_fputc(r.file_length % 256); } - // Write decompressed data + // write decompressed data if (r.success) { write_decompressed_data(r.file_length, r.file_name); remove(r.file_name); @@ -3227,7 +3194,7 @@ void try_decompression_zip(int zip_header_length) { write_decompressed_data(best_identical_bytes_decomp); } - //Set input file pointer after recompressed data + // set input file pointer after recompressed data input_file_pos += best_identical_bytes - 1; cb += best_identical_bytes - 1; @@ -3346,9 +3313,6 @@ bool compress_file(float min_percent, float max_percent) { global_min_percent = min_percent; global_max_percent = max_percent; - //fseek(fin, 0, SEEK_END); - //unsigned int size_in = ftell(fin); - if (recursion_depth == 0) write_header(); uncompressed_length = -1; @@ -3423,7 +3387,7 @@ bool compress_file(float min_percent, float max_percent) { // ZIP header? if (((in_buf[cb] == 'P') && (in_buf[cb + 1] == 'K')) && (use_zip)) { - //Local file header? + // local file header? if ((in_buf[cb + 2] == 3) && (in_buf[cb + 3] == 4)) { if (DEBUG_MODE) { printf("ZIP header detected\n"); @@ -3443,16 +3407,6 @@ bool compress_file(float min_percent, float max_percent) { printf("extra field length: %i\n", extra_field_length); } - // Stored ZIP detection - removed because it skips valid ZIP streams. - // Perhaps try to skip only if compressed_size and uncompressed_size - // are greater than 0: - // if ((compressed_size == uncompressed_size) && (compressed_size > 0)) { - /*if (compressed_size == uncompressed_size) { - if (DEBUG_MODE) { - printf("seems to be stored, skipping\n"); - } - } else*/ - if ((filename_length + extra_field_length) <= CHECKBUF_SIZE) { int header_length = 30 + filename_length + extra_field_length; @@ -3475,12 +3429,12 @@ bool compress_file(float min_percent, float max_percent) { } } - if ((!compressed_data_found) && (use_gzip)) { // No ZIP header -> GZip header? + if ((!compressed_data_found) && (use_gzip)) { // no ZIP header -> GZip header? if ((in_buf[cb] == 31) && (in_buf[cb + 1] == 139)) { - //Check zLib header in GZip header + // check zLib header in GZip header int compression_method = (in_buf[cb + 2] & 15); if ((compression_method == 8) && - ((in_buf[cb + 3] & 224) == 0) //Reserved FLG bits must be zero. + ((in_buf[cb + 3] & 224) == 0) // reserved FLG bits must be zero ) { //((in_buf[cb + 8] == 2) || (in_buf[cb + 8] == 4)) { //XFL = 2 or 4 @@ -3506,7 +3460,6 @@ bool compress_file(float min_percent, float max_percent) { int act_checkbuf_pos = 10; if (fextra) { - //int xlen = fgetc(fin) + (fgetc(fin) << 8); int xlen = in_buf[cb + act_checkbuf_pos] + (in_buf[cb + act_checkbuf_pos + 1] << 8); if ((act_checkbuf_pos + xlen) > CHECKBUF_SIZE) { dont_compress = true; @@ -3540,7 +3493,7 @@ bool compress_file(float min_percent, float max_percent) { if (!dont_compress) { - input_file_pos += header_length; //Skip GZip header + input_file_pos += header_length; // skip GZip header try_decompression_gzip(header_length); @@ -3556,7 +3509,7 @@ bool compress_file(float min_percent, float max_percent) { } } - if ((!compressed_data_found) && (use_pdf)) { // No Gzip header -> PDF FlateDecode? + if ((!compressed_data_found) && (use_pdf)) { // no Gzip header -> PDF FlateDecode? if (memcmp(in_buf + cb, "/FlateDecode", 12) == 0) { saved_input_file_pos = input_file_pos; saved_cb = cb; @@ -3575,9 +3528,9 @@ bool compress_file(float min_percent, float max_percent) { if (found_stream) { - // Check if the stream is an image and width and height are given + // check if the stream is an image and width and height are given - // Read 4096 bytes before stream + // read 4096 bytes before stream unsigned char type_buf[4097]; int type_buf_length; @@ -3594,7 +3547,7 @@ bool compress_file(float min_percent, float max_percent) { type_buf_length = input_file_pos + act_search_pos; } - // Find "<<" + // find "<<" int start_pos = -1; @@ -3611,7 +3564,7 @@ bool compress_file(float min_percent, float max_percent) { int width_pos, height_pos, bpc_pos; - // Find "/Width" + // find "/Width" width_pos = (unsigned char*)strstr((const char*)(type_buf + start_pos), "/Width") - type_buf; if (width_pos > 0) @@ -3625,7 +3578,7 @@ bool compress_file(float min_percent, float max_percent) { } } - // Find "/Height" + // find "/Height" height_pos = (unsigned char*)strstr((const char*)(type_buf + start_pos), "/Height") - type_buf; if (height_pos > 0) @@ -3639,7 +3592,7 @@ bool compress_file(float min_percent, float max_percent) { } } - // Find "/BitsPerComponent" + // find "/BitsPerComponent" bpc_pos = (unsigned char*)strstr((const char*)(type_buf + start_pos), "/BitsPerComponent") - type_buf; if (bpc_pos > 0) @@ -3662,15 +3615,15 @@ bool compress_file(float min_percent, float max_percent) { if ((in_buf[cb + act_search_pos + 6] == 13) || (in_buf[cb + act_search_pos + 6] == 10)) { if ((in_buf[cb + act_search_pos + 7] == 13) || (in_buf[cb + act_search_pos + 7] == 10)) { - //Seems to be two byte EOL - zLib Header present? + // seems to be two byte EOL - zLib Header present? if (((((in_buf[cb + act_search_pos + 8] << 8) + in_buf[cb + act_search_pos + 9]) % 31) == 0) && - ((in_buf[cb + act_search_pos + 9] & 32) == 0)) { //FDICT must not be set + ((in_buf[cb + act_search_pos + 9] & 32) == 0)) { // FDICT must not be set int compression_method = (in_buf[cb + act_search_pos + 8] & 15); if (compression_method == 8) { int windowbits = (in_buf[cb + act_search_pos + 8] >> 4) + 8; - input_file_pos += act_search_pos + 10; //Skip PDF part + input_file_pos += act_search_pos + 10; // skip PDF part try_decompression_pdf(-windowbits, act_search_pos + 10, width_val, height_val, bpc_val); @@ -3678,13 +3631,13 @@ bool compress_file(float min_percent, float max_percent) { } } } else { - //Seems to be one byte EOL - zLib Header present? + // seems to be one byte EOL - zLib Header present? if ((((in_buf[cb + act_search_pos + 7] << 8) + in_buf[cb + act_search_pos + 8]) % 31) == 0) { int compression_method = (in_buf[cb + act_search_pos + 7] & 15); if (compression_method == 8) { int windowbits = (in_buf[cb + act_search_pos + 7] >> 4) + 8; - input_file_pos += act_search_pos + 9; //Skip PDF part + input_file_pos += act_search_pos + 9; // skip PDF part try_decompression_pdf(-windowbits, act_search_pos + 9, width_val, height_val, bpc_val); @@ -3702,10 +3655,10 @@ bool compress_file(float min_percent, float max_percent) { } } - if ((!compressed_data_found) && (use_png)) { // No PDF header -> PNG IDAT? + if ((!compressed_data_found) && (use_png)) { // no PDF header -> PNG IDAT? if (memcmp(in_buf + cb, "IDAT", 4) == 0) { - //space for length and crc parts of IDAT chunks + // space for length and crc parts of IDAT chunks idat_lengths = (unsigned int*)(realloc(idat_lengths, 100 * sizeof(unsigned int))); idat_crcs = (unsigned int*)(realloc(idat_crcs, 100 * sizeof(unsigned int))); @@ -3716,7 +3669,7 @@ bool compress_file(float min_percent, float max_percent) { bool zlib_header_correct = false; int windowbits = 0; - //Get preceding length bytes + // get preceding length bytes if (input_file_pos >= 4) { seek_64(fin, input_file_pos - 4); @@ -3726,12 +3679,12 @@ bool compress_file(float min_percent, float max_percent) { idat_lengths[0] = (in[0] << 24) + (in[1] << 16) + (in[2] << 8) + in[3]; if (idat_lengths[0] > 2) { - //Check zLib header and get windowbits + // check zLib header and get windowbits zlib_header[0] = in[8]; zlib_header[1] = in[9]; if ((((in[8] << 8) + in[9]) % 31) == 0) { if ((in[8] & 15) == 8) { - if ((in[9] & 32) == 0) { //FDICT must not be set + if ((in[9] & 32) == 0) { // FDICT must not be set windowbits = (in[8] >> 4) + 8; zlib_header_correct = true; } @@ -3742,10 +3695,10 @@ bool compress_file(float min_percent, float max_percent) { idat_count++; - //Go through additional IDATs + // go through additional IDATs for (;;) { seek_64(fin, tell_64(fin) + idat_lengths[idat_count - 1]); - if (fread(in, 1, 12, fin) != 12) { //CRC, Length, "IDAT" + if (fread(in, 1, 12, fin) != 12) { // CRC, length, "IDAT" idat_count = 0; break; } @@ -3775,18 +3728,18 @@ bool compress_file(float min_percent, float max_percent) { if (idat_count == 1) { - //Try to recompress directly + // try to recompress directly input_file_pos += 6; try_decompression_png(-windowbits); cb += 6; } else if (idat_count > 1) { - //Copy to temp0.dat before trying to recompress + // copy to temp0.dat before trying to recompress remove(tempfile0); fpng = tryOpen(tempfile0,"w+b"); - seek_64(fin, input_file_pos + 6); // Start after zLib header + seek_64(fin, input_file_pos + 6); // start after zLib header - idat_lengths[0] -= 2; //zLib header length + idat_lengths[0] -= 2; // zLib header length for (int i = 0; i < idat_count; i++) { fast_copy(fin, fpng, idat_lengths[i]); seek_64(fin, tell_64(fin) + 12); @@ -3813,7 +3766,7 @@ bool compress_file(float min_percent, float max_percent) { } - if ((!compressed_data_found) && (use_gif)) { // No PNG header -> GIF header? + if ((!compressed_data_found) && (use_gif)) { // no PNG header -> GIF header? if ((in_buf[cb] == 'G') && (in_buf[cb + 1] == 'I') && (in_buf[cb + 2] == 'F')) { if ((in_buf[cb + 3] == '8') && (in_buf[cb + 5] == 'a')) { if ((in_buf[cb + 4] == '7') || (in_buf[cb + 4] == '9')) { @@ -3838,8 +3791,8 @@ bool compress_file(float min_percent, float max_percent) { } } - if ((!compressed_data_found) && (use_jpg)) { // No GIF header -> JPG header? - if ((in_buf[cb] == 0xFF) && (in_buf[cb + 1] == 0xD8)) { //SOI (FF D8) + if ((!compressed_data_found) && (use_jpg)) { // no GIF header -> JPG header? + if ((in_buf[cb] == 0xFF) && (in_buf[cb + 1] == 0xD8)) { // SOI (FF D8) if ((in_buf[cb + 2] == 0xFF)) { saved_input_file_pos = input_file_pos; saved_cb = cb; @@ -3847,7 +3800,7 @@ bool compress_file(float min_percent, float max_percent) { int eoi_count = 1; bool progressive_flag = false; - //Find SOF + // find SOF bool ff_sof_found = false; bool sof_found = false; long long sof_pos = input_file_pos + 1; @@ -3856,11 +3809,11 @@ bool compress_file(float min_percent, float max_percent) { while (fread(in, 1, 1, fin) == 1) { sof_pos++; if (ff_sof_found) { - if (in[0] == 0xD8) { //Another SOI (FF D8) - increase EOI count + if (in[0] == 0xD8) { // another SOI (FF D8) - increase EOI count eoi_count++; } - sof_found = ((in[0] == 0xC0) //baseline - || (in[0] == 0xC2)); //progressive + sof_found = ((in[0] == 0xC0) // baseline + || (in[0] == 0xC2)); // progressive if (sof_found) { progressive_flag = (in[0] == 0xC2); if (fread(in, 1, 3, fin) == 3) { @@ -3880,7 +3833,7 @@ bool compress_file(float min_percent, float max_percent) { } } - //Find EOI + // find EOI bool ff_eoi_found = false; long long eoi_pos = 0; @@ -3891,7 +3844,7 @@ bool compress_file(float min_percent, float max_percent) { while (fread(in, 1, 1, fin) == 1) { eoi_pos++; if (ff_eoi_found) { - if (in[0] == 0xD8) { //Another SOI (FF D8) - increase EOI count + if (in[0] == 0xD8) { // another SOI (FF D8) - increase EOI count eoi_count++; } if (in[0] == 0xD9) { @@ -3911,65 +3864,18 @@ bool compress_file(float min_percent, float max_percent) { long long jpg_length = (eoi_pos + 1) - input_file_pos; - //Check for DHT (0xFFC4) and DQT (0xFFDB) before 1st SOS (0xFFDA) - //Additionaly, check if there is _exactly one_ SOF (0xFFC0, 0xFFC1 - // or 0xFFC2) before 1st SOS (0xFFDA) - - /*fseek(fin, input_file_pos + 2, SEEK_SET); - - bool dht_found = false; - bool dqt_found = false; - bool ff_found = false; - bool sos_found = false; - int sof_count = 0; - int act_pos = input_file_pos + 2; - - while ((fread(in, 1, 1, fin) == 1) && (act_pos != eoi_pos)) { - act_pos++; - if (ff_found) { - if (in[0] == 0xC4) { - dht_found = true; - } - if (in[0] == 0xDB) { - dqt_found = true; - } - if ((in[0] == 0xC0) || (in[0] == 0xC1) || (in[0] == 0xC2)) { - sof_count++; - if (sos_found) { //SOF after SOS -> invalid - sof_count = 0; - break; - } - } - if (in[0] == 0xD9) { //EOI - sos_found = false; //reset SOS status - if (sof_count != 1) break; - sof_count = 0; - } - if (in[0] == 0xDA) { //SOS - sos_found = true; - } - ff_found = (in[0] == 0xFF); - } else { - ff_found = (in[0] == 0xFF); - } - } - - if (dht_found && dqt_found && (sof_count == 1)) {*/ - try_decompression_jpg(jpg_length, progressive_flag); - //} else { - //} + try_decompression_jpg(jpg_length, progressive_flag); if (!compressed_data_found) { input_file_pos = saved_input_file_pos; cb = saved_cb; } - } } } } - if ((!compressed_data_found) && (use_mp3)) { // No JPG header -> MP3 header? + if ((!compressed_data_found) && (use_mp3)) { // no JPG header -> MP3 header? if ((in_buf[cb] == 0xFF) && ((in_buf[cb + 1] & 0xE0) == 0xE0)) { // frame start int mpeg = -1; int layer = -1; @@ -4038,15 +3944,15 @@ bool compress_file(float min_percent, float max_percent) { } } - if ((!compressed_data_found) && (use_swf)) { // No MP3 header -> SWF header? + if ((!compressed_data_found) && (use_swf)) { // no MP3 header -> SWF header? // CWS = Compressed SWF file if ((in_buf[cb] == 'C') && (in_buf[cb + 1] == 'W') && (in_buf[cb + 2] == 'S')) { char swf_version = in_buf[cb + 3]; - // Check version number is 1 - 10 + // check version number is 1 - 10 if ((swf_version > 0) && (swf_version < 10)) { - // Check zLib header + // check zLib header if (((((in_buf[cb + 8] << 8) + in_buf[cb + 9]) % 31) == 0) && - ((in_buf[cb + 9] & 32) == 0)) { //FDICT must not be set + ((in_buf[cb + 9] & 32) == 0)) { // FDICT must not be set int compression_method = (in_buf[cb + 8] & 15); if (compression_method == 8) { int windowbits = (in_buf[cb + 8] >> 4) + 8; @@ -4054,7 +3960,7 @@ bool compress_file(float min_percent, float max_percent) { saved_input_file_pos = input_file_pos; saved_cb = cb; - input_file_pos += 10; //Skip CWS and zLib header + input_file_pos += 10; // skip CWS and zLib header try_decompression_swf(-windowbits, swf_version); @@ -4070,14 +3976,14 @@ bool compress_file(float min_percent, float max_percent) { } } - if ((!compressed_data_found) && (use_base64)) { // No SWF header -> Base64? + if ((!compressed_data_found) && (use_base64)) { // no SWF header -> Base64? if ((in_buf[cb + 1] == 'o') && (in_buf[cb + 2] == 'n') && (in_buf[cb + 3] == 't') && (in_buf[cb + 4] == 'e')) { unsigned char cte_detect[33]; for (int i = 0; i < 33; i++) { cte_detect[i] = tolower(in_buf[cb + i]); } if (memcmp(cte_detect, "content-transfer-encoding: base64", 33) == 0) { - // Search for double CRLF, all between is "header" + // search for double CRLF, all between is "header" int base64_header_length = 33; bool found_double_crlf = false; do { @@ -4085,7 +3991,7 @@ bool compress_file(float min_percent, float max_percent) { if ((in_buf[cb + base64_header_length + 2] == 13) && (in_buf[cb + base64_header_length + 3] == 10)) { found_double_crlf = true; base64_header_length += 4; - // Skip additional CRLFs + // skip additional CRLFs while ((in_buf[cb + base64_header_length] == 13) && (in_buf[cb + base64_header_length + 1] == 10)) { base64_header_length += 2; } @@ -4100,7 +4006,7 @@ bool compress_file(float min_percent, float max_percent) { saved_input_file_pos = input_file_pos; saved_cb = cb; - input_file_pos += base64_header_length; //Skip "header" + input_file_pos += base64_header_length; // skip "header" try_decompression_base64(base64_header_length); @@ -4115,7 +4021,7 @@ bool compress_file(float min_percent, float max_percent) { } } - if ((!compressed_data_found) && (use_bzip2)) { // No Base64 header -> bZip2? + if ((!compressed_data_found) && (use_bzip2)) { // no Base64 header -> bZip2? // BZhx = header, x = compression level/blocksize (1-9) if ((in_buf[cb] == 'B') && (in_buf[cb + 1] == 'Z') && (in_buf[cb + 2] == 'h')) { int compression_level = in_buf[cb + 3] - '0'; @@ -4134,11 +4040,11 @@ bool compress_file(float min_percent, float max_percent) { } - // Nothing so far -> if slow mode is enabled, look for raw zLib header + // nothing so far -> if slow mode is enabled, look for raw zLib header if ((slow_mode) && ((slow_mode_depth_limit == -1) || (recursion_depth <= slow_mode_depth_limit))) { if (!compressed_data_found) { if (((((in_buf[cb] << 8) + in_buf[cb + 1]) % 31) == 0) && - ((in_buf[cb + 1] & 32) == 0)) { //FDICT must not be set + ((in_buf[cb + 1] & 32) == 0)) { // FDICT must not be set int compression_method = (in_buf[cb] & 15); if (compression_method == 8) { int windowbits = (in_buf[cb] >> 4) + 8; @@ -4146,7 +4052,7 @@ bool compress_file(float min_percent, float max_percent) { saved_input_file_pos = input_file_pos; saved_cb = cb; - input_file_pos += 2; //Skip zLib header + input_file_pos += 2; // skip zLib header try_decompression_zlib(-windowbits); @@ -4163,7 +4069,7 @@ bool compress_file(float min_percent, float max_percent) { } } else { - // Nothing so far -> if brute mode is enabled, brute force for zLib streams + // nothing so far -> if brute mode is enabled, brute force for zLib streams if ((brute_mode) && ((brute_mode_depth_limit == -1) || (recursion_depth <= brute_mode_depth_limit))) { if (!compressed_data_found) { saved_input_file_pos = input_file_pos; @@ -4208,10 +4114,6 @@ void decompress_file() { init_decompress_otf(); } - //fseek(fin, 0, SEEK_END); - //int fin_length = ftell(fin); - //fseek(fin, 0, SEEK_SET); - #ifndef PRECOMPDLL if (recursion_depth == 0) { if (!DEBUG_MODE) { @@ -4234,7 +4136,6 @@ void decompress_file() { fin_pos = tell_64(fin); -//while (ftell(fin) < fin_length) { while (fin_pos < fin_length) { #ifndef PRECOMPDLL @@ -4262,7 +4163,7 @@ while (fin_pos < fin_length) { #endif unsigned char header1 = fin_fgetc(); - if (header1 == 0) { //Uncompressed data + if (header1 == 0) { // uncompressed data long long uncompressed_data_length; uncompressed_data_length = ((long long)fin_fgetc() << 56); uncompressed_data_length += ((long long)fin_fgetc() << 48); @@ -4273,10 +4174,9 @@ while (fin_pos < fin_length) { uncompressed_data_length += ((long long)fin_fgetc() << 8); uncompressed_data_length += (long long)fin_fgetc(); - if (uncompressed_data_length == 0) break; // End of PCF file, used by bZip2 compress-on-the-fly + if (uncompressed_data_length == 0) break; // end of PCF file, used by bZip2 compress-on-the-fly if (DEBUG_MODE) { - //printf("Uncompressed data, length=%i\n", uncompressed_data_length); printf("Uncompressed data, length="); print64(uncompressed_data_length); printf("\n"); @@ -4284,7 +4184,7 @@ while (fin_pos < fin_length) { fast_copy(fin, fout, uncompressed_data_length); - } else { //Decompressed data, recompress + } else { // decompressed data, recompress unsigned char headertype = fin_fgetc(); @@ -4314,13 +4214,13 @@ while (fin_pos < fin_length) { pdf_header_length += (fin_fgetc() << 8); pdf_header_length += fin_fgetc(); - //Restore PDF header + // restore PDF header fprintf(fout, "/FlateDecode"); own_fread(in, 1, pdf_header_length, fin); own_fwrite(in, 1, pdf_header_length, fout); - //Read penalty bytes + // read penalty bytes if (penalty_bytes_stored) { penalty_bytes_len = (fin_fgetc() << 24); penalty_bytes_len += (fin_fgetc() << 16); @@ -4345,10 +4245,10 @@ while (fin_pos < fin_length) { printf("Recompressed Length: %i - Decompressed length: %i\n", recompressed_data_length, decompressed_data_length); } - //Keep file position for penalty bytes + // keep file position for penalty bytes long long old_fout_pos = tell_64(fout); - // Read BMP header + // read BMP header int bmp_width = 0; @@ -4366,15 +4266,15 @@ while (fin_pos < fin_length) { } if ((bmp_c == 0) || ((bmp_width % 4) == 0)) { - // Recompress directly to fout + // recompress directly to fout retval = def_part(fin, fout, compression_level, windowbits, memlevel, decompressed_data_length, recompressed_data_length); if (retval != Z_OK) { printf("Error recompressing data!"); printf("retval = %i\n", retval); exit(0); } - } else { // Lines aligned to 4 byte, skip those bytes - // Recompress directly to fout, but skipping bytes + } else { // lines aligned to 4 byte, skip those bytes + // recompress directly to fout, but skipping bytes retval = def_part_skip(fin, fout, compression_level, windowbits, memlevel, decompressed_data_length, recompressed_data_length, bmp_width); @@ -4442,7 +4342,7 @@ while (fin_pos < fin_length) { own_fread(in, 1, zip_header_length, fin); own_fwrite(in, 1, zip_header_length, fout); - //Read penalty bytes + // read penalty bytes if (penalty_bytes_stored) { penalty_bytes_len = (fin_fgetc() << 24); penalty_bytes_len += (fin_fgetc() << 16); @@ -4557,7 +4457,7 @@ while (fin_pos < fin_length) { own_fread(in, 1, gzip_header_length, fin); own_fwrite(in, 1, gzip_header_length, fout); - //Read penalty bytes + // read penalty bytes if (penalty_bytes_stored) { penalty_bytes_len = (fin_fgetc() << 24); penalty_bytes_len += (fin_fgetc() << 16); @@ -4655,16 +4555,16 @@ while (fin_pos < fin_length) { printf("Memory level: %i\n", memlevel); } - //Restore IDAT + // restore IDAT fprintf(fout, "IDAT"); - //Restore zLib header (decrease by 1) + // restore zLib header (decrease by 1) own_fread(in, 1, 2, fin); unsigned char decchar = *(in + 1) - 1; own_fwrite(in, 1, 1, fout); fputc(decchar, fout); - //Read penalty bytes + // read penalty bytes if (penalty_bytes_stored) { penalty_bytes_len = (fin_fgetc() << 24); penalty_bytes_len += (fin_fgetc() << 16); @@ -4737,16 +4637,16 @@ while (fin_pos < fin_length) { printf("Memory level: %i\n", memlevel); } - //Restore first IDAT + // restore first IDAT fprintf(fout, "IDAT"); - //Restore zLib header (decrease by 1) + // restore zLib header (decrease by 1) own_fread(in, 1, 2, fin); unsigned char decchar = *(in + 1) - 1; own_fwrite(in, 1, 1, fout); fputc(decchar, fout); - //Get IDAT count + // get IDAT count own_fread(in, 1, 2, fin); idat_count = (in[0] << 8) + in[1]; idat_count++; @@ -4754,12 +4654,12 @@ while (fin_pos < fin_length) { idat_crcs = (unsigned int*)(realloc(idat_crcs, idat_count * sizeof(unsigned int))); idat_lengths = (unsigned int*)(realloc(idat_lengths, idat_count * sizeof(unsigned int))); - //Get first IDAT length + // get first IDAT length own_fread(in, 1, 4, fin); idat_lengths[0] = (in[0] << 24) + (in[1] << 16) + (in[2] << 8) + in[3]; - idat_lengths[0] -= 2; //zLib header length + idat_lengths[0] -= 2; // zLib header length - //Get IDAT chunk lengths and CRCs + // get IDAT chunk lengths and CRCs for (int i = 1; i < idat_count; i++) { own_fread(in, 1, 4, fin); idat_crcs[i] = (in[0] << 24) + (in[1] << 16) + (in[2] << 8) + in[3]; @@ -4767,7 +4667,7 @@ while (fin_pos < fin_length) { idat_lengths[i] = (in[0] << 24) + (in[1] << 16) + (in[2] << 8) + in[3]; } - //Read penalty bytes + // read penalty bytes if (penalty_bytes_stored) { penalty_bytes_len = (fin_fgetc() << 24); penalty_bytes_len += (fin_fgetc() << 16); @@ -4806,7 +4706,7 @@ while (fin_pos < fin_length) { long long old_frecomp_pos = tell_64(frecomp); - //Recompress data + // recompress data retval = def(ftempout, frecomp, compression_level, windowbits, memlevel); if ((!penalty_bytes_stored) || (retval != Z_OK)) safe_fclose(&frecomp); safe_fclose(&ftempout); @@ -4818,7 +4718,6 @@ while (fin_pos < fin_length) { } if (penalty_bytes_stored) { - //frecomp = tryOpen(tempfile2,"wb"); fflush(frecomp); int pb_pos = 0; @@ -4840,7 +4739,6 @@ while (fin_pos < fin_length) { unsigned int remaining_bytes = recompressed_data_length; unsigned int act_idat_chunk = 0; for (;;) { - //printf("DEBUG: Remaining bytes: %i - IDAT_length: %i\n", remaining_bytes, idat_lengths[act_idat_chunk]); if ((remaining_bytes + 2) > idat_lengths[act_idat_chunk]) { fast_copy(frecomp, fout, idat_lengths[act_idat_chunk]); remaining_bytes -= idat_lengths[act_idat_chunk]; @@ -4885,7 +4783,7 @@ while (fin_pos < fin_length) { GifDiffStruct gDiff; - //Read diff bytes + // read diff bytes gDiff.GIFDiffIndex = (fin_fgetc() << 24); gDiff.GIFDiffIndex += (fin_fgetc() << 16); gDiff.GIFDiffIndex += (fin_fgetc() << 8); @@ -4899,7 +4797,7 @@ while (fin_pos < fin_length) { gDiff.GIFDiffIndex = 0; gDiff.GIFCodeCount = 0; - //Read penalty bytes + // read penalty bytes if (penalty_bytes_stored) { penalty_bytes_len = (fin_fgetc() << 24); penalty_bytes_len += (fin_fgetc() << 16); @@ -4938,7 +4836,7 @@ while (fin_pos < fin_length) { ftempout = tryOpen(tempfile1,"rb"); frecomp = tryOpen(tempfile2,"wb"); - //Recompress data + // recompress data recompress_success = recompress_gif(ftempout, frecomp, block_size, NULL, &gDiff); safe_fclose(&frecomp); @@ -5095,22 +4993,22 @@ while (fin_pos < fin_length) { fputc('C', fout); fputc('W', fout); fputc('S', fout); - // Get Flash version + // get Flash version char c = fin_fgetc(); fputc(c, fout); - // Get length from SWF header + // get length from SWF header for (int i = 0; i < 4; i++) { c = fin_fgetc(); fputc(c, fout); } - //Restore zLib header (decrease by 1) + // restore zLib header (decrease by 1) own_fread(in, 1, 2, fin); unsigned char decchar = *(in + 1) - 1; own_fwrite(in, 1, 1, fout); fputc(decchar, fout); - //Read penalty bytes + // read penalty bytes if (penalty_bytes_stored) { penalty_bytes_len = (fin_fgetc() << 24); penalty_bytes_len += (fin_fgetc() << 16); @@ -5198,7 +5096,7 @@ while (fin_pos < fin_length) { int line_case = (header1 >> 2) & 3; bool recursion_used = ((header1 & 128) == 128); - // Restore Base64 "header" + // restore Base64 "header" int base64_header_length; base64_header_length = (fin_fgetc() << 8); base64_header_length += fin_fgetc(); @@ -5207,10 +5105,10 @@ while (fin_pos < fin_length) { printf("Base64 header length: %i\n", base64_header_length); } own_fread(in, 1, base64_header_length, fin); - fputc(*(in) + 1, fout); // First char was decreased + fputc(*(in) + 1, fout); // first char was decreased own_fwrite(in + 1, 1, base64_header_length - 1, fout); - // Read line length list + // read line length list int line_count = fin_fgetc() << 8; line_count += fin_fgetc(); if (line_case == 2) { @@ -5259,7 +5157,7 @@ while (fin_pos < fin_length) { } } - // Re-encode Base64 + // re-encode Base64 if (recursion_used) { recursion_result r = recursion_decompress(recursion_data_length); @@ -5288,7 +5186,7 @@ while (fin_pos < fin_length) { printf("Compression level: %i\n", level); } - //Read penalty bytes + // read penalty bytes if (penalty_bytes_stored) { penalty_bytes_len = (fin_fgetc() << 24); penalty_bytes_len += (fin_fgetc() << 16); @@ -5440,7 +5338,7 @@ while (fin_pos < fin_length) { printf("Memory level: %i\n", memlevel); } - //Read penalty bytes + // read penalty bytes if (penalty_bytes_stored) { penalty_bytes_len = (fin_fgetc() << 24); penalty_bytes_len += (fin_fgetc() << 16); @@ -5539,13 +5437,13 @@ while (fin_pos < fin_length) { printf("Memory level: %i\n", memlevel); } - //Restore zLib header (decrease by 1) + // restore zLib header (decrease by 1) own_fread(in, 1, 2, fin); unsigned char decchar = *(in + 1) - 1; own_fwrite(in, 1, 1, fout); fputc(decchar, fout); - //Read penalty bytes + // read penalty bytes if (penalty_bytes_stored) { penalty_bytes_len = (fin_fgetc() << 24); penalty_bytes_len += (fin_fgetc() << 16); @@ -5666,7 +5564,7 @@ void convert_file() { for (;;) { bytes_read = own_fread(copybuf, 1, COPY_BUF_SIZE, fin); - // Truncate by 9 bytes (Precomp bZip2 delimiter) if converting from bZip2 + // truncate by 9 bytes (Precomp bZip2 delimiter) if converting from bZip2 if ((conversion_from_method == 1) && (bytes_read < COPY_BUF_SIZE)) { bytes_read -= 9; if (bytes_read < 0) { @@ -5764,25 +5662,18 @@ void try_recompress(FILE* origfile, int comp_level, int mem_level, int windowbit print_work_sign(true); - //if (file_recompress(comp_level, windowbits, mem_level) == Z_OK) { //Successfully recompressed? identical_bytes = file_recompress(origfile, comp_level, windowbits, mem_level); - if (identical_bytes > -1) { //Successfully recompressed? + if (identical_bytes > -1) { // successfully recompressed? if (identical_bytes > best_identical_bytes) { - //if (identical_bytes > 4) { if (identical_bytes > min_ident_size) { if (DEBUG_MODE) { printf("Identical recompressed bytes: %i\n", identical_bytes); } - //DEBUG - //system("copy temp1.dat recomp1.dat"); - //system("copy temp2.dat recomp2.dat"); - - - //Shorten temp2.dat to the identical bytes + // shorten temp2.dat to the identical bytes frecomp = tryOpen(tempfile2,"rb"); fident = tryOpen(tempfile2a, "wb"); fast_copy(frecomp, fident, identical_bytes); @@ -5790,7 +5681,7 @@ void try_recompress(FILE* origfile, int comp_level, int mem_level, int windowbit safe_fclose(&frecomp); - //Decompress temp2.dat to temp3.dat for comparison with temp1.dat + // decompress temp2.dat to temp3.dat for comparison with temp1.dat fident = tryOpen(tempfile2a,"rb"); fseek(fident, 0, SEEK_SET); @@ -5817,7 +5708,7 @@ void try_recompress(FILE* origfile, int comp_level, int mem_level, int windowbit final_compression_found = (identical_bytes_decomp == ftempout_size); if (!final_compression_found) { - //Recompress temp3.dat for comparison with input file + // recompress temp3.dat for comparison with input file remove(tempfile4); fdecomp = tryOpen(tempfile3,"rb"); frecomp2 = tryOpen(tempfile4,"wb"); @@ -5825,10 +5716,6 @@ void try_recompress(FILE* origfile, int comp_level, int mem_level, int windowbit safe_fclose(&frecomp2); safe_fclose(&fdecomp); - //DEBUG - //system("copy temp3.dat recomp3.dat"); - //system("copy temp4.dat recomp4.dat"); - frecomp2 = tryOpen(tempfile4,"rb"); } else { // tempfile4 would be the same as tempfile2a, no need to recompress again frecomp2 = tryOpen(tempfile2a,"rb"); @@ -5871,25 +5758,18 @@ void try_recompress_bzip2(FILE* origfile, int level) { print_work_sign(true); - //if (file_recompress(comp_level, windowbits, mem_level) == Z_OK) { //Successfully recompressed? identical_bytes = file_recompress_bzip2(origfile, level); if (identical_bytes > -1) { //Successfully recompressed? if (identical_bytes > best_identical_bytes) { - //if (identical_bytes > 4) { if (identical_bytes > min_ident_size) { if (DEBUG_MODE) { printf("Identical recompressed bytes: %i\n", identical_bytes); } - //DEBUG - //system("copy temp1.dat recomp1.dat"); - //system("copy temp2.dat recomp2.dat"); - - - //Shorten temp2.dat to the identical bytes + // shorten temp2.dat to the identical bytes frecomp = tryOpen(tempfile2,"rb"); fident = tryOpen(tempfile2a, "wb"); fast_copy(frecomp, fident, identical_bytes); @@ -5897,7 +5777,7 @@ void try_recompress_bzip2(FILE* origfile, int level) { safe_fclose(&frecomp); - //Decompress temp2.dat to temp3.dat for comparison with temp1.dat + // decompress temp2.dat to temp3.dat for comparison with temp1.dat fident = tryOpen(tempfile2a,"rb"); fseek(fident, 0, SEEK_SET); @@ -5924,7 +5804,7 @@ void try_recompress_bzip2(FILE* origfile, int level) { final_compression_found = (identical_bytes_decomp == ftempout_size); if (!final_compression_found) { - //Recompress temp3.dat for comparison with input file + // recompress temp3.dat for comparison with input file remove(tempfile4); fdecomp = tryOpen(tempfile3,"rb"); frecomp2 = tryOpen(tempfile4,"wb"); @@ -5932,10 +5812,6 @@ void try_recompress_bzip2(FILE* origfile, int level) { safe_fclose(&frecomp2); safe_fclose(&fdecomp); - //DEBUG - //system("copy temp3.dat recomp3.dat"); - //system("copy temp4.dat recomp4.dat"); - frecomp2 = tryOpen(tempfile4,"rb"); } else { // tempfile4 would be the same as tempfile2a, no need to recompress again frecomp2 = tryOpen(tempfile2a,"rb"); @@ -5978,15 +5854,15 @@ void write_header() { fprintf(fout, "PCF"); - //Version number + // version number fputc(V_MAJOR, fout); fputc(V_MINOR, fout); fputc(V_MINOR2, fout); - // Compression-on-the-fly method used + // compression-on-the-fly method used fputc(compression_otf_method, fout); - //Write input file name without path + // write input file name without path char* last_backslash = strrchr(input_file_name, PATH_DELIM); if (last_backslash != NULL) { strcpy(input_file_name_without_path, last_backslash + 1); @@ -5999,7 +5875,7 @@ void write_header() { delete[] input_file_name_without_path; - // Initialize compression-on-the-fly now + // initialize compression-on-the-fly now if (compression_otf_method != 0) { init_compress_otf(); } @@ -6023,7 +5899,7 @@ bool check_for_pcf_file() { exit(1); } - // Skip compression method + // skip compression method fread(in, 1, 1, fin); string header_filename = ""; @@ -6033,10 +5909,10 @@ bool check_for_pcf_file() { if (c != 0) header_filename += c; } while (c != 0); - //Append output filename to the executable directory + // append output filename to the executable directory char exec_dir[1024]; GetModuleFileName(NULL, exec_dir, 1024); - //Truncate to get directory of executable only + // truncate to get directory of executable only char* lastslash = strrchr(exec_dir, PATH_DELIM) + 1; strcpy(lastslash, ""); header_filename = exec_dir + header_filename; @@ -6166,7 +6042,7 @@ size_t own_fwrite(const void *ptr, size_t size, size_t count, FILE* stream, int } } else { switch (compression_otf_method) { - case 1: { //bZip2 + case 1: { // bZip2 int flush, ret; unsigned have; @@ -6217,7 +6093,7 @@ size_t own_fread(void *ptr, size_t size, size_t count, FILE* stream) { return fread(ptr, size, count, stream); } else { switch (compression_otf_method) { - case 1: { //bZip2 + case 1: { // bZip2 int ret; int bytes_read = 0; @@ -6292,7 +6168,6 @@ long long compare_files_penalty(FILE* file1, FILE* file2, long long pos1, long l long long same_byte_count_penalty = 0; long long rek_same_byte_count = 0; long long rek_same_byte_count_penalty = -1; - //int old_same_byte_count = 0; long long size1, size2, minsize; long long i; bool endNow = false; @@ -6325,35 +6200,34 @@ long long compare_files_penalty(FILE* file1, FILE* file2, long long pos1, long l for (i = 0; i < minsize; i++) { if (input_bytes1[i] != input_bytes2[i]) { - same_byte_count_penalty -= 5; //4 bytes = position, 1 byte = new byte + same_byte_count_penalty -= 5; // 4 bytes = position, 1 byte = new byte - //if same_byte_count_penalty is too low, stop + // if same_byte_count_penalty is too low, stop if ((long long)(same_byte_count_penalty + (compare_end - same_byte_count)) < 0) { endNow = true; break; } - //stop, if local_penalty_bytes_len gets too big + // stop, if local_penalty_bytes_len gets too big if ((local_penalty_bytes_len + 5) >= MAX_PENALTY_BYTES) { endNow = true; break; } local_penalty_bytes_len += 5; - //Position + // position local_penalty_bytes[local_penalty_bytes_len-5] = (same_byte_count >> 24) % 256; local_penalty_bytes[local_penalty_bytes_len-4] = (same_byte_count >> 16) % 256; local_penalty_bytes[local_penalty_bytes_len-3] = (same_byte_count >> 8) % 256; local_penalty_bytes[local_penalty_bytes_len-2] = same_byte_count % 256; - //New byte + // new byte local_penalty_bytes[local_penalty_bytes_len-1] = input_bytes1[i]; } else { same_byte_count_penalty++; } same_byte_count++; - //if (!endNow) old_same_byte_count = same_byte_count; - if (same_byte_count_penalty > rek_same_byte_count_penalty) { + if (same_byte_count_penalty > rek_same_byte_count_penalty) { use_penalty_bytes = true; rek_penalty_bytes_len = local_penalty_bytes_len; @@ -6363,7 +6237,6 @@ long long compare_files_penalty(FILE* file1, FILE* file2, long long pos1, long l } } - //} while (minsize == COMP_CHUNK); } while ((minsize == COMP_CHUNK) && (!endNow)); if ((rek_penalty_bytes_len > 0) && (use_penalty_bytes)) { @@ -6373,15 +6246,6 @@ long long compare_files_penalty(FILE* file1, FILE* file2, long long pos1, long l penalty_bytes_len = 0; } - - /*if (old_same_byte_count != rek_same_byte_count) { - printf("old_same_byte_count: %i, rek_same_byte_count: %i\n", old_same_byte_count, rek_same_byte_count); - printf("penalty_bytes_len: %i\n\n", penalty_bytes_len); - if (old_same_byte_count > rek_same_byte_count) exit(0); - }*/ - - //return old_same_byte_count; - return rek_same_byte_count; } @@ -6398,10 +6262,10 @@ void try_decompression_gzip(int gzip_header_length) { int windowbits; - // Try to decompress at current position + // try to decompress at current position retval = try_to_decompress(fin, -15); - if (retval > 0) { //Seems to be a zLib-Stream + if (retval > 0) { // seems to be a zLib-Stream decompressed_streams_count++; decompressed_gzip_count++; @@ -6430,7 +6294,6 @@ void try_decompression_gzip(int gzip_header_length) { } } - //if ((best_identical_bytes > 4) && (best_identical_bytes < identical_bytes_decomp)) { if ((best_identical_bytes > min_ident_size) && (best_identical_bytes < identical_bytes_decomp)) { recompressed_streams_count++; recompressed_gzip_count++; @@ -6459,15 +6322,15 @@ void try_decompression_gzip(int gzip_header_length) { } } - //End uncompressed data + // end uncompressed data compressed_data_found = true; end_uncompressed_data(); - //Check recursion + // check recursion recursion_result r = recursion_compress(best_identical_bytes, best_identical_bytes_decomp); - //Write compressed data header (GZip) without 2 first bytes + // write compressed data header (GZip) without 2 first bytes int header_byte = 1 + (best_compression << 2); if (best_penalty_bytes_len != 0) { @@ -6477,7 +6340,7 @@ void try_decompression_gzip(int gzip_header_length) { header_byte += 128; } fout_fputc(header_byte); - fout_fputc(2); //GZip + fout_fputc(2); // GZip fout_fputc((((-windowbits) - 8) << 4) + best_mem_level); gzip_header_length -= 2; @@ -6488,7 +6351,7 @@ void try_decompression_gzip(int gzip_header_length) { own_fwrite(in_buf + cb + 2, 1, gzip_header_length, fout); - //Store penalty bytes, if any + // store penalty bytes, if any if (best_penalty_bytes_len != 0) { if (DEBUG_MODE) { printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); @@ -6523,7 +6386,7 @@ void try_decompression_gzip(int gzip_header_length) { fout_fputc(r.file_length % 256); } - //Write decompressed data + // write decompressed data if (r.success) { write_decompressed_data(r.file_length, r.file_name); remove(r.file_name); @@ -6532,9 +6395,9 @@ void try_decompression_gzip(int gzip_header_length) { write_decompressed_data(best_identical_bytes_decomp); } - //Start new uncompressed data + // start new uncompressed data - //Set input file pointer after recompressed data + // set input file pointer after recompressed data input_file_pos += best_identical_bytes - 1; cb += best_identical_bytes - 1; @@ -6560,10 +6423,10 @@ void try_decompression_png (int windowbits) { real_identical_bytes = -1; final_compression_found = false; - // Try to decompress at current position + // try to decompress at current position retval = try_to_decompress(fin, windowbits); - if (retval > 0) { //Seems to be a zLib-Stream + if (retval > 0) { // seems to be a zLib-Stream decompressed_streams_count++; decompressed_png_count++; @@ -6590,7 +6453,6 @@ void try_decompression_png (int windowbits) { if (final_compression_found) break; } - //if ((best_identical_bytes > 4) && (best_identical_bytes < identical_bytes_decomp)) { if ((best_identical_bytes > min_ident_size) && (best_identical_bytes < identical_bytes_decomp)) { recompressed_streams_count++; recompressed_png_count++; @@ -6618,28 +6480,28 @@ void try_decompression_png (int windowbits) { } } - //End uncompressed data + // end uncompressed data compressed_data_found = true; end_uncompressed_data(); - //Write compressed data header (PNG) + // write compressed data header (PNG) if (best_penalty_bytes_len == 0) { fout_fputc(1 + (best_compression << 2)); } else { fout_fputc(1 + 2 + (best_compression << 2)); } - fout_fputc(3); //PNG + fout_fputc(3); // PNG fout_fputc((((-windowbits) - 8) << 4) + best_mem_level); - //Store zLib header, but increased by 1 to prevent finding it - // again in the next pass + // store zLib header, but increased by 1 to prevent finding it + // again in the next pass own_fwrite(zlib_header, 1, 1, fout); unsigned char incchar = *(zlib_header + 1) + 1; fout_fputc(incchar); - //Store penalty bytes, if any + // store penalty bytes, if any if (best_penalty_bytes_len != 0) { if (DEBUG_MODE) { printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); @@ -6663,13 +6525,13 @@ void try_decompression_png (int windowbits) { fout_fputc((best_identical_bytes_decomp >> 8) % 256); fout_fputc(best_identical_bytes_decomp % 256); - //Write decompressed data + // write decompressed data write_decompressed_data(best_identical_bytes_decomp); - //Start new uncompressed data + // start new uncompressed data - //Set input file pointer after recompressed data + // set input file pointer after recompressed data input_file_pos += best_identical_bytes - 1; cb += best_identical_bytes - 1; @@ -6695,10 +6557,10 @@ void try_decompression_png_multi(int windowbits) { real_identical_bytes = -1; final_compression_found = false; - // Try to decompress at current position + // try to decompress at current position retval = try_to_decompress(fpng, windowbits); - if (retval > 0) { //Seems to be a zLib-Stream + if (retval > 0) { // seems to be a zLib-Stream decompressed_streams_count++; decompressed_png_multi_count++; @@ -6725,7 +6587,6 @@ void try_decompression_png_multi(int windowbits) { if (final_compression_found) break; } - //if ((best_identical_bytes > 4) && (best_identical_bytes < identical_bytes_decomp)) { if ((best_identical_bytes > min_ident_size) && (best_identical_bytes < identical_bytes_decomp)) { recompressed_streams_count++; recompressed_png_multi_count++; @@ -6753,28 +6614,28 @@ void try_decompression_png_multi(int windowbits) { } } - //End uncompressed data + // end uncompressed data compressed_data_found = true; end_uncompressed_data(); - //Write compressed data header (PNG) + // write compressed data header (PNG) if (best_penalty_bytes_len == 0) { fout_fputc(1 + (best_compression << 2)); } else { fout_fputc(1 + 2 + (best_compression << 2)); } - fout_fputc(4); //PNG multi + fout_fputc(4); // PNG multi fout_fputc((((-windowbits) - 8) << 4) + best_mem_level); - //Store zLib header, but increased by 1 to prevent finding it - // again in the next pass + // store zLib header, but increased by 1 to prevent finding it + // again in the next pass own_fwrite(zlib_header, 1, 1, fout); unsigned char incchar = *(zlib_header + 1) + 1; fout_fputc(incchar); - //Simulate IDAT write to get IDAT pairs count + // simulate IDAT write to get IDAT pairs count int i = 1; int idat_pos = idat_lengths[0] - 2; unsigned int idat_pairs_written_count = 0; @@ -6788,17 +6649,17 @@ void try_decompression_png_multi(int windowbits) { i++; } while (i < idat_count); } - //Store IDAT pairs count + // store IDAT pairs count fout_fputc((idat_pairs_written_count >> 8) % 256); fout_fputc(idat_pairs_written_count % 256); - //Store IDAT CRCs and lengths + // store IDAT CRCs and lengths fout_fputc((idat_lengths[0] >> 24) % 256); fout_fputc((idat_lengths[0] >> 16) % 256); fout_fputc((idat_lengths[0] >> 8) % 256); fout_fputc(idat_lengths[0] % 256); - //Store IDAT CRCs and lengths + // store IDAT CRCs and lengths i = 1; idat_pos = idat_lengths[0] - 2; idat_pairs_written_count = 0; @@ -6823,7 +6684,7 @@ void try_decompression_png_multi(int windowbits) { } while (i < idat_count); } - //Store penalty bytes, if any + // store penalty bytes, if any if (best_penalty_bytes_len != 0) { if (DEBUG_MODE) { printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); @@ -6847,16 +6708,16 @@ void try_decompression_png_multi(int windowbits) { fout_fputc((best_identical_bytes_decomp >> 8) % 256); fout_fputc(best_identical_bytes_decomp % 256); - //Write decompressed data + // write decompressed data write_decompressed_data(best_identical_bytes_decomp); - //Start new uncompressed data + // start new uncompressed data - //Set input file pointer after recompressed data + // set input file pointer after recompressed data input_file_pos += best_identical_bytes - 1; cb += best_identical_bytes - 1; - //Now add IDAT chunk overhead + // now add IDAT chunk overhead input_file_pos += (idat_pairs_written_count * 12); cb += (idat_pairs_written_count * 12); @@ -6871,7 +6732,7 @@ void try_decompression_png_multi(int windowbits) { } -//GIF functions +// GIF functions bool newgif_may_write; FILE* frecompress_gif = NULL; @@ -6991,7 +6852,7 @@ bool recompress_gif(FILE* srcfile, FILE* dstfile, unsigned char block_size, GifC long long dstfile_pos = tell_64(dstfile); seek_64(dstfile, 0); - //Change PGF8xa to GIF8xa + // change PGF8xa to GIF8xa fputc('G', dstfile); fputc('I', dstfile); seek_64(dstfile, dstfile_pos); @@ -7011,7 +6872,7 @@ bool recompress_gif(FILE* srcfile, FILE* dstfile, unsigned char block_size, GifC own_fread(&ScreenBuff[i][Col], 1, Width, srcfile); } - // This does send a clear code, so we pass g and gd + // this does send a clear code, so we pass g and gd EGifPutImageDesc(newGifFile, g, gd, Row, Col, Width, Height, myGifFile->Image.Interlace, myGifFile->Image.ColorMap); newgif_may_write = true; @@ -7142,7 +7003,7 @@ bool decompress_gif(FILE* srcfile, FILE* dstfile, long long src_pos, int& gif_le long long dstfile_pos = tell_64(dstfile); seek_64(dstfile, 0); - //Change GIF8xa to PGF8xa + // change GIF8xa to PGF8xa fputc('P', dstfile); fputc('G', dstfile); seek_64(dstfile, dstfile_pos); @@ -7189,13 +7050,13 @@ bool decompress_gif(FILE* srcfile, FILE* dstfile, long long src_pos, int& gif_le delete[] ScreenBuff; } DGifCloseFile(myGifFile); - //TODO: If this fails, write as much rows to dstfile - // as possible to support second decompression. + // TODO: If this fails, write as much rows to dstfile + // as possible to support second decompression. return false; } } } - //Write to dstfile + // write to dstfile for (i = Row; i < (Row + Height); i++) { own_fwrite(&ScreenBuff[i][Col], 1, Width, dstfile); } @@ -7211,7 +7072,7 @@ bool decompress_gif(FILE* srcfile, FILE* dstfile, long long src_pos, int& gif_le DGifCloseFile(myGifFile); return false; } - //Write to dstfile + // write to dstfile own_fwrite(&ScreenBuff[i][Col], 1, Width, dstfile); } } @@ -7296,7 +7157,7 @@ void try_decompression_gif(unsigned char version[5]) { seek_64(fin, input_file_pos); - //Read GIF file + // read GIF file ftempout = tryOpen(tempfile1, "wb"); if (!decompress_gif(fin, ftempout, input_file_pos, gif_length, decomp_length, block_size, &gCode)) { @@ -7324,7 +7185,6 @@ void try_decompression_gif(unsigned char version[5]) { safe_fclose(&ftempout); frecomp = tryOpen(tempfile2,"rb"); - //best_identical_bytes = compare_files(fin, frecomp, input_file_pos, 0); best_identical_bytes = compare_files_penalty(fin, frecomp, input_file_pos, 0); safe_fclose(&frecomp); @@ -7338,14 +7198,14 @@ void try_decompression_gif(unsigned char version[5]) { int decomp_length2 = -1; unsigned char block_size2 = 255; - //Shorten temp2.dat to the identical bytes + // shorten temp2.dat to the identical bytes frecomp = tryOpen(tempfile2,"rb"); fident = tryOpen(tempfile2a, "wb"); fast_copy(frecomp, fident, best_identical_bytes); safe_fclose(&fident); safe_fclose(&frecomp); - //Decompress temp2.dat to temp3.dat for comparison with temp1.dat + // decompress temp2.dat to temp3.dat for comparison with temp1.dat fident = tryOpen(tempfile2a,"rb"); fseek(fident, 0, SEEK_SET); @@ -7355,7 +7215,7 @@ void try_decompression_gif(unsigned char version[5]) { GifCodeFree(&gCode); GifCodeInit(&gCode); decompress_gif(fident, fdecomp, 0, gif_length2, decomp_length2, block_size2, &gCode); - // Do not exit on failure as the GIF file was shortened, so + // do not exit on failure as the GIF file was shortened, so // we surely can't succeed in decompression safe_fclose(&fdecomp); @@ -7374,7 +7234,7 @@ void try_decompression_gif(unsigned char version[5]) { printf ("Identical decompressed bytes: %i of %i\n", identical_bytes_decomp, ftempout_size); } - //Recompress temp3.dat for comparison with input file + // recompress temp3.dat for comparison with input file GifDiffFree(&gDiff); GifDiffInit(&gDiff); @@ -7385,10 +7245,6 @@ void try_decompression_gif(unsigned char version[5]) { safe_fclose(&frecomp2); safe_fclose(&fdecomp); - //DEBUG - //system("copy temp3.dat recomp3.dat"); - //system("copy temp4.dat recomp4.dat"); - frecomp2 = tryOpen(tempfile4,"rb"); real_identical_bytes = compare_files_penalty(fin, frecomp2, input_file_pos, 0); if (DEBUG_MODE) { @@ -7419,12 +7275,12 @@ void try_decompression_gif(unsigned char version[5]) { best_penalty_bytes_len = 0; } - //End uncompressed data + // end uncompressed data compressed_data_found = true; end_uncompressed_data(); - //Write compressed data header (GIF) + // write compressed data header (GIF) unsigned char add_bits = 0; if (best_penalty_bytes_len != 0) add_bits += 2; @@ -7432,9 +7288,9 @@ void try_decompression_gif(unsigned char version[5]) { if (recompress_success_needed) add_bits += 128; fout_fputc(1 + add_bits); - fout_fputc(5); //GIF + fout_fputc(5); // GIF - //Store diff bytes + // store diff bytes fout_fputc((gDiff.GIFDiffIndex >> 24) % 256); fout_fputc((gDiff.GIFDiffIndex >> 16) % 256); fout_fputc((gDiff.GIFDiffIndex >> 8) % 256); @@ -7447,7 +7303,7 @@ void try_decompression_gif(unsigned char version[5]) { fout_fputc(gDiff.GIFDiff[dbc]); } - //Store penalty bytes, if any + // store penalty bytes, if any if (best_penalty_bytes_len != 0) { if (DEBUG_MODE) { printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); @@ -7473,13 +7329,13 @@ void try_decompression_gif(unsigned char version[5]) { fout_fputc((decomp_length >> 8) % 256); fout_fputc(decomp_length % 256); - //Write decompressed data + // write decompressed data write_decompressed_data(decomp_length); - //Start new uncompressed data + // start new uncompressed data - //Set input file pointer after recompressed data + // set input file pointer after recompressed data input_file_pos += gif_length - 1; cb += gif_length - 1; @@ -7499,14 +7355,12 @@ void try_decompression_gif(unsigned char version[5]) { GifDiffFree(&gDiff); GifCodeFree(&gCode); - //exit(0); //Use this to have a look at ~temp1.dat and ~temp2.dat - remove(tempfile2); remove(tempfile1); } -//JPEG routines +// JPG routines void packjpg_mp3_dll_msg() { @@ -7530,18 +7384,18 @@ void try_decompression_jpg (long long jpg_length, bool progressive_jpg) { printf (", length "); print64(jpg_length); printf ("\n"); - // Do not recompress non-progressive JPGs when prog_only is set + // do not recompress non-progressive JPGs when prog_only is set if ((!progressive_jpg) && (prog_only)) { printf("Skipping (only progressive JPGs mode set)\n"); } } - // Do not recompress non-progressive JPGs when prog_only is set + // do not recompress non-progressive JPGs when prog_only is set if ((!progressive_jpg) && (prog_only)) return; bool jpg_success = false; - // Try to decompress at current position + // try to decompress at current position fjpg = tryOpen(tempfile0,"wb"); seek_64(fin, input_file_pos); fast_copy(fin, fjpg, jpg_length); @@ -7562,7 +7416,7 @@ void try_decompression_jpg (long long jpg_length, bool progressive_jpg) { if ((!recompress_success) && (strncmp(msg, "huffman table missing", 21) == 0) && (use_mjpeg)) { if (DEBUG_MODE) printf ("huffman table missing, trying to use Motion JPEG DHT\n"); - // Search 0xFF 0xDA, insert MJPGDHT (MJPGDHT_LEN bytes) + // search 0xFF 0xDA, insert MJPGDHT (MJPGDHT_LEN bytes) fjpg = tryOpen(tempfile0,"rb"); bool found_ffda = false; bool found_ff = false; @@ -7582,7 +7436,7 @@ void try_decompression_jpg (long long jpg_length, bool progressive_jpg) { fdecomp = tryOpen(tempfile3,"wb"); seek_64(fjpg, 0); fast_copy(fjpg, fdecomp, ffda_pos - 1); - // Insert MJPGDHT + // insert MJPGDHT own_fwrite(MJPGDHT, 1, MJPGDHT_LEN, fdecomp); seek_64(fjpg, ffda_pos - 1); fast_copy(fjpg, fdecomp, jpg_length - (ffda_pos - 1)); @@ -7633,19 +7487,19 @@ void try_decompression_jpg (long long jpg_length, bool progressive_jpg) { printf("Best match: %i bytes, recompressed to %i bytes\n", best_identical_bytes, best_identical_bytes_decomp); } - //End uncompressed data + // end uncompressed data compressed_data_found = true; end_uncompressed_data(); - //Write compressed data header (JPG) + // write compressed data header (JPG) if (mjpg_dht_used) { - fout_fputc(1 + 4); //No penalty bytes, Motion JPG DHT used + fout_fputc(1 + 4); // no penalty bytes, Motion JPG DHT used } else { - fout_fputc(1); //No penalty bytes + fout_fputc(1); // no penalty bytes } - fout_fputc(6); //JPG + fout_fputc(6); // JPG fout_fputc((best_identical_bytes >> 24) % 256); fout_fputc((best_identical_bytes >> 16) % 256); @@ -7657,12 +7511,12 @@ void try_decompression_jpg (long long jpg_length, bool progressive_jpg) { fout_fputc((best_identical_bytes_decomp >> 8) % 256); fout_fputc(best_identical_bytes_decomp % 256); - //Write compressed JPG + // write compressed JPG write_decompressed_data(best_identical_bytes_decomp); - //Start new uncompressed data + // start new uncompressed data - //Set input file pointer after recompressed data + // set input file pointer after recompressed data input_file_pos += best_identical_bytes - 1; cb += best_identical_bytes - 1; @@ -7687,14 +7541,14 @@ void try_decompression_mp3 (long long mp3_length) { bool mp3_success = false; - // Try to decompress at current position + // try to decompress at current position fmp3 = tryOpen(tempfile0,"wb"); seek_64(fin, input_file_pos); fast_copy(fin, fmp3, mp3_length); safe_fclose(&fmp3); remove(tempfile1); - // Workaround for bugs, similar to packJPG. + // workaround for bugs, similar to packJPG FILE* fworkaround = tryOpen(tempfile1,"wb"); safe_fclose(&fworkaround); @@ -7735,15 +7589,15 @@ void try_decompression_mp3 (long long mp3_length) { printf("Best match: %i bytes, recompressed to %i bytes\n", best_identical_bytes, best_identical_bytes_decomp); } - //End uncompressed data + // end uncompressed data compressed_data_found = true; end_uncompressed_data(); - //Write compressed data header (MP3) + // write compressed data header (MP3) - fout_fputc(1); //No penalty bytes - fout_fputc(10); //MP3 + fout_fputc(1); // no penalty bytes + fout_fputc(10); // MP3 fout_fputc((best_identical_bytes >> 24) % 256); fout_fputc((best_identical_bytes >> 16) % 256); @@ -7755,12 +7609,12 @@ void try_decompression_mp3 (long long mp3_length) { fout_fputc((best_identical_bytes_decomp >> 8) % 256); fout_fputc(best_identical_bytes_decomp % 256); - //Write compressed MP3 + // write compressed MP3 write_decompressed_data(best_identical_bytes_decomp); - //Start new uncompressed data + // start new uncompressed data - //Set input file pointer after recompressed data + // set input file pointer after recompressed data input_file_pos += best_identical_bytes - 1; cb += best_identical_bytes - 1; @@ -7783,10 +7637,10 @@ void try_decompression_zlib(int windowbits) { real_identical_bytes = -1; final_compression_found = false; - // Try to decompress at current position + // try to decompress at current position retval = try_to_decompress(fin, windowbits); - if (retval > 0) { //Seems to be a zLib-Stream + if (retval > 0) { // seems to be a zLib-Stream decompressed_streams_count++; decompressed_zlib_count++; @@ -7825,7 +7679,6 @@ void try_decompression_zlib(int windowbits) { if (final_compression_found) break; } - //if ((best_identical_bytes > 4) && (best_identical_bytes < identical_bytes_decomp)) { if ((best_identical_bytes > min_ident_size_slow_brute_mode) && (best_identical_bytes < identical_bytes_decomp)) { recompressed_streams_count++; recompressed_zlib_count++; @@ -7853,15 +7706,15 @@ void try_decompression_zlib(int windowbits) { } } - //End uncompressed data + // end uncompressed data compressed_data_found = true; end_uncompressed_data(); - //Check recursion + // check recursion recursion_result r = recursion_compress(best_identical_bytes, best_identical_bytes_decomp); - //Write compressed data header (zLib) + // write compressed data header (zLib) int header_byte = 1 + (best_compression << 2); if (best_penalty_bytes_len != 0) { @@ -7871,16 +7724,16 @@ void try_decompression_zlib(int windowbits) { header_byte += 128; } fout_fputc(header_byte); - fout_fputc(255); //raw zLib + fout_fputc(255); // raw zLib fout_fputc((((-windowbits) - 8) << 4) + best_mem_level); - //Store zLib header, but increased by 1 to prevent finding it - // again in the next pass + // store zLib header, but increased by 1 to prevent finding it + // again in the next pass own_fwrite(in_buf + cb, 1, 1, fout); unsigned char incchar = *(in_buf + cb + 1) + 1; fout_fputc(incchar); - //Store penalty bytes, if any + // store penalty bytes, if any if (best_penalty_bytes_len != 0) { if (DEBUG_MODE) { printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); @@ -7915,7 +7768,7 @@ void try_decompression_zlib(int windowbits) { fout_fputc(r.file_length % 256); } - // Write decompressed data + // write decompressed data if (r.success) { write_decompressed_data(r.file_length, r.file_name); remove(r.file_name); @@ -7924,9 +7777,9 @@ void try_decompression_zlib(int windowbits) { write_decompressed_data(best_identical_bytes_decomp); } - //Start new uncompressed data + // start new uncompressed data - //Set input file pointer after recompressed data + // set input file pointer after recompressed data input_file_pos += best_identical_bytes - 1; cb += best_identical_bytes - 1; @@ -7954,10 +7807,10 @@ void try_decompression_brute() { int windowbits; - // Try to decompress at current position + // try to decompress at current position retval = try_to_decompress(fin, -15); - if (retval > 0) { //Seems to be a zLib-Stream + if (retval > 0) { // seems to be a zLib-Stream decompressed_streams_count++; decompressed_brute_count++; @@ -7998,7 +7851,6 @@ void try_decompression_brute() { } } - //if ((best_identical_bytes > 4) && (best_identical_bytes < identical_bytes_decomp)) { if ((best_identical_bytes > min_ident_size_slow_brute_mode) && (best_identical_bytes < best_identical_bytes_decomp)) { recompressed_streams_count++; recompressed_brute_count++; @@ -8027,15 +7879,15 @@ void try_decompression_brute() { } } - //End uncompressed data + // end uncompressed data compressed_data_found = true; end_uncompressed_data(); - //Check recursion + // check recursion recursion_result r = recursion_compress(best_identical_bytes, best_identical_bytes_decomp); - //Write compressed data header (brute) + // write compressed data header (brute) int header_byte = 1 + (best_compression << 2); if (best_penalty_bytes_len != 0) { @@ -8045,10 +7897,10 @@ void try_decompression_brute() { header_byte += 128; } fout_fputc(header_byte); - fout_fputc(254); //brute + fout_fputc(254); // brute fout_fputc((((-windowbits) - 8) << 4) + best_mem_level); - //Store penalty bytes, if any + // store penalty bytes, if any if (best_penalty_bytes_len != 0) { if (DEBUG_MODE) { printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); @@ -8083,7 +7935,7 @@ void try_decompression_brute() { fout_fputc(r.file_length % 256); } - // Write decompressed data + // write decompressed data if (r.success) { write_decompressed_data(r.file_length, r.file_name); remove(r.file_name); @@ -8092,7 +7944,7 @@ void try_decompression_brute() { write_decompressed_data(best_identical_bytes_decomp); } - //Set input file pointer after recompressed data + // set input file pointer after recompressed data input_file_pos += best_identical_bytes - 1; cb += best_identical_bytes - 1; @@ -8118,10 +7970,10 @@ void try_decompression_swf(int windowbits, char swf_version) { real_identical_bytes = -1; final_compression_found = false; - // Try to decompress at current position + // try to decompress at current position retval = try_to_decompress(fin, windowbits); - if (retval > 0) { //Seems to be a zLib-Stream + if (retval > 0) { // seems to be a zLib-Stream decompressed_streams_count++; decompressed_swf_count++; @@ -8150,7 +8002,6 @@ void try_decompression_swf(int windowbits, char swf_version) { if (final_compression_found) break; } - //if ((best_identical_bytes > 4) && (best_identical_bytes < identical_bytes_decomp)) { if ((best_identical_bytes > min_ident_size) && (best_identical_bytes < identical_bytes_decomp)) { recompressed_streams_count++; recompressed_swf_count++; @@ -8178,15 +8029,15 @@ void try_decompression_swf(int windowbits, char swf_version) { } } - //End uncompressed data + // end uncompressed data compressed_data_found = true; end_uncompressed_data(); - //Check recursion + // check recursion recursion_result r = recursion_compress(best_identical_bytes, best_identical_bytes_decomp); - //Write compressed data header (SWF) + // write compressed data header (SWF) int header_byte = 1 + (best_compression << 2); if (best_penalty_bytes_len != 0) { @@ -8201,16 +8052,16 @@ void try_decompression_swf(int windowbits, char swf_version) { fout_fputc(swf_version); - // Store length from SWF header + // store length from SWF header own_fwrite(in_buf + cb + 4, 1, 4, fout); - //Store zLib header, but increased by 1 to prevent finding it - // again in the next pass + // store zLib header, but increased by 1 to prevent finding it + // again in the next pass own_fwrite(in_buf + cb + 8, 1, 1, fout); unsigned char incchar = *(in_buf + cb + 9) + 1; fout_fputc(incchar); - //Store penalty bytes, if any + // store penalty bytes, if any if (best_penalty_bytes_len != 0) { if (DEBUG_MODE) { printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); @@ -8245,7 +8096,7 @@ void try_decompression_swf(int windowbits, char swf_version) { fout_fputc(r.file_length % 256); } - // Write decompressed data + // write decompressed data if (r.success) { write_decompressed_data(r.file_length, r.file_name); remove(r.file_name); @@ -8254,9 +8105,9 @@ void try_decompression_swf(int windowbits, char swf_version) { write_decompressed_data(best_identical_bytes_decomp); } - //Start new uncompressed data + // start new uncompressed data - //Set input file pointer after recompressed data + // set input file pointer after recompressed data input_file_pos += best_identical_bytes - 1; cb += best_identical_bytes - 1; @@ -8281,10 +8132,10 @@ void try_decompression_bzip2(int compression_level) { real_identical_bytes = -1; final_compression_found = false; - // Try to decompress at current position + // try to decompress at current position retval = try_to_decompress_bzip2(fin, compression_level); - if (retval > 0) { //Seems to be a zLib-Stream + if (retval > 0) { // seems to be a zLib-Stream decompressed_streams_count++; decompressed_bzip2_count++; @@ -8315,15 +8166,15 @@ void try_decompression_bzip2(int compression_level) { non_zlib_was_used = true; - //End uncompressed data + // end uncompressed data compressed_data_found = true; end_uncompressed_data(); - //Check recursion + // check recursion recursion_result r = recursion_compress(best_identical_bytes, best_identical_bytes_decomp); - //Write compressed data header (bZip2) + // write compressed data header (bZip2) int header_byte = 1; if (best_penalty_bytes_len != 0) { @@ -8336,7 +8187,7 @@ void try_decompression_bzip2(int compression_level) { fout_fputc(9); // Base64 fout_fputc(compression_level); - //Store penalty bytes, if any + // store penalty bytes, if any if (best_penalty_bytes_len != 0) { if (DEBUG_MODE) { printf("Penalty bytes were used: %i bytes\n", best_penalty_bytes_len); @@ -8371,7 +8222,7 @@ void try_decompression_bzip2(int compression_level) { fout_fputc(r.file_length % 256); } - // Write decompressed data + // write decompressed data if (r.success) { write_decompressed_data(r.file_length, r.file_name); remove(r.file_name); @@ -8380,9 +8231,9 @@ void try_decompression_bzip2(int compression_level) { write_decompressed_data(best_identical_bytes_decomp); } - //Start new uncompressed data + // start new uncompressed data - //Set input file pointer after recompressed data + // set input file pointer after recompressed data input_file_pos += best_identical_bytes - 1; cb += best_identical_bytes - 1; @@ -8413,7 +8264,7 @@ unsigned char base64_char_decode(unsigned char c) { if (c == '/') return 63; if (c == '=') return 64; // padding - return 65; //invalid + return 65; // invalid } void base64_reencode(FILE* file_in, FILE* file_out, int line_count, int max_in_count, int max_byte_count) { @@ -8434,7 +8285,7 @@ void base64_reencode(FILE* file_in, FILE* file_out, int line_count, int max_in_c } remaining_bytes -= avail_in; - // Make sure avail_in mod 3 = 0, pad with 0 bytes + // make sure avail_in mod 3 = 0, pad with 0 bytes while ((avail_in % 3) != 0) { in[avail_in] = 0; avail_in++; @@ -8447,7 +8298,7 @@ void base64_reencode(FILE* file_in, FILE* file_out, int line_count, int max_in_c if (act_byte_count < max_byte_count) own_fputc(b64[a >> 2], file_out); act_byte_count++; act_line_len++; - if (act_line_len == base64_line_len[line_nr]) { // End of line, write CRLF + if (act_line_len == base64_line_len[line_nr]) { // end of line, write CRLF if (act_byte_count < max_byte_count) own_fputc(13, file_out); act_byte_count++; if (act_byte_count < max_byte_count) own_fputc(10, file_out); @@ -8459,7 +8310,7 @@ void base64_reencode(FILE* file_in, FILE* file_out, int line_count, int max_in_c if (act_byte_count < max_byte_count) own_fputc(b64[((a & 0x03) << 4) | (b >> 4)], file_out); act_byte_count++; act_line_len++; - if (act_line_len == base64_line_len[line_nr]) { // End of line, write CRLF + if (act_line_len == base64_line_len[line_nr]) { // end of line, write CRLF if (act_byte_count < max_byte_count) own_fputc(13, file_out); act_byte_count++; if (act_byte_count < max_byte_count) own_fputc(10, file_out); @@ -8471,7 +8322,7 @@ void base64_reencode(FILE* file_in, FILE* file_out, int line_count, int max_in_c if (act_byte_count < max_byte_count) own_fputc(b64[((b & 0x0F) << 2) | (c >> 6)], file_out); act_byte_count++; act_line_len++; - if (act_line_len == base64_line_len[line_nr]) { // End of line, write CRLF + if (act_line_len == base64_line_len[line_nr]) { // end of line, write CRLF if (act_byte_count < max_byte_count) own_fputc(13, file_out); act_byte_count++; if (act_byte_count < max_byte_count) own_fputc(10, file_out); @@ -8483,7 +8334,7 @@ void base64_reencode(FILE* file_in, FILE* file_out, int line_count, int max_in_c if (act_byte_count < max_byte_count) own_fputc(b64[c & 63], file_out); act_byte_count++; act_line_len++; - if (act_line_len == base64_line_len[line_nr]) { // End of line, write CRLF + if (act_line_len == base64_line_len[line_nr]) { // end of line, write CRLF if (act_byte_count < max_byte_count) own_fputc(13, file_out); act_byte_count++; if (act_byte_count < max_byte_count) own_fputc(10, file_out); @@ -8509,7 +8360,7 @@ void try_decompression_base64(int base64_header_length) { real_identical_bytes = -1; final_compression_found = false; - // Try to decode at current position + // try to decode at current position remove(tempfile1); ftempout = tryOpen(tempfile1,"wb"); seek_64(fin, input_file_pos); @@ -8531,7 +8382,7 @@ void try_decompression_base64(int base64_header_length) { do { avail_in = fread(in, 1, CHUNK, fin); for (i = 0; i < (avail_in >> 2); i++) { - // Are these valid base64 chars? + // are these valid base64 chars? for (j = (i << 2); j < ((i << 2) + 4); j++) { c = base64_char_decode(in[j]); if (c < 64) { @@ -8544,7 +8395,7 @@ void try_decompression_base64(int base64_header_length) { if ((in[j] == 13) || (in[j] == 10)) { if (in[j] == 13) { cr_count++; - if (cr_count == 2) { // Double CRLF -> base64 end + if (cr_count == 2) { // double CRLF -> base64 end stream_finished = true; break; } @@ -8607,7 +8458,7 @@ void try_decompression_base64(int base64_header_length) { if (!decoding_failed) { int line_case = -1; - // Check line case + // check line case if (line_count == 1) { line_case = 0; // one length for all lines } else { @@ -8644,7 +8495,7 @@ void try_decompression_base64(int base64_header_length) { printf ("Can be decoded to %i bytes\n", identical_bytes); } - // Try to re-encode Base64 data + // try to re-encode Base64 data ftempout = fopen(tempfile1,"rb"); if (ftempout == NULL) { @@ -8669,26 +8520,26 @@ void try_decompression_base64(int base64_header_length) { printf("Match: encoded to %i bytes\n", identical_bytes_decomp); } - //End uncompressed data + // end uncompressed data compressed_data_found = true; end_uncompressed_data(); - //Check recursion + // check recursion recursion_result r = recursion_compress(identical_bytes_decomp, identical_bytes); - //Write compressed data header (Base64) + // write compressed data header (Base64) int header_byte = 1 + (line_case << 2); if (r.success) { header_byte += 128; } fout_fputc(header_byte); - fout_fputc(8); //Base64 + fout_fputc(8); // Base64 fout_fputc((base64_header_length >> 8) % 256); fout_fputc(base64_header_length % 256); - //Write "header", but change first char to prevent re-detection + // write "header", but change first char to prevent re-detection fout_fputc(in_buf[cb] - 1); own_fwrite(in_buf + cb + 1, 1, base64_header_length - 1, fout); @@ -8724,7 +8575,7 @@ void try_decompression_base64(int base64_header_length) { fout_fputc(r.file_length % 256); } - //Write decompressed data + // write decompressed data if (r.success) { write_decompressed_data(r.file_length, r.file_name); remove(r.file_name); @@ -8733,9 +8584,9 @@ void try_decompression_base64(int base64_header_length) { write_decompressed_data(identical_bytes); } - //Start new uncompressed data + // start new uncompressed data - //Set input file pointer after recompressed data + // set input file pointer after recompressed data input_file_pos += identical_bytes_decomp - 1; cb += identical_bytes_decomp - 1; } else { @@ -8751,7 +8602,7 @@ void try_decompression_base64(int base64_header_length) { #ifdef COMFORT void wait_for_key() { printf("\nPress any key to continue\n"); - //Wait for key + // wait for key do { } while (!kbhit()); } @@ -8783,7 +8634,7 @@ void error(int error_nr) { break; case ERR_DISK_FULL: printf("There is not enough space on disk"); - // Delete output file + // delete output file safe_fclose(&fout); remove(output_file_name); break; @@ -8850,7 +8701,6 @@ long long fileSize64(char* filename) { #ifndef LINUX unsigned long s1 = 0, s2 = 0; - //HANDLE h = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); #ifdef _MSC_VER HANDLE h = CreateFile(convertCharArrayToLPCWSTR(filename), 0, (FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE), NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); #else @@ -8921,18 +8771,18 @@ void init_temp_files() { k /= 10; } - // Create meta file + // create meta file FILE* f = fopen(metatempfile, "wb"); safe_fclose(&f); - // Update temporary file list + // update temporary file list tempfilelist_count += 8; tempfilelist = (char*)realloc(tempfilelist, 20 * tempfilelist_count * sizeof(char)); strcpy(tempfilelist + (tempfilelist_count - 8) * 20, metatempfile); strcpy(tempfilelist + (tempfilelist_count - 7) * 20, tempfile0); strcpy(tempfilelist + (tempfilelist_count - 6) * 20, tempfile1); - // Recursion input file + // recursion input file strcpy(tempfilelist + (tempfilelist_count - 5) * 20, tempfile1); tempfilelist[(tempfilelist_count - 5) * 20 + 18] = '_'; tempfilelist[(tempfilelist_count - 5) * 20 + 19] = 0; @@ -9097,7 +8947,7 @@ recursion_result recursion_compress(int compressed_bytes, int decompressed_bytes recursion_push(); - // Shorten tempfile1 to decompressed_bytes + // shorten tempfile1 to decompressed_bytes FILE* ftempfile1 = fopen(tempfile1, "r+b"); ftruncate(fileno(ftempfile1), decompressed_bytes); fclose(ftempfile1); @@ -9124,7 +8974,7 @@ recursion_result recursion_compress(int compressed_bytes, int decompressed_bytes local_penalty_bytes = new char[MAX_PENALTY_BYTES]; best_penalty_bytes = new char[MAX_PENALTY_BYTES]; - // Disable compression-on-the-fly in recursion - we don't want compressed compressed streams + // disable compression-on-the-fly in recursion - we don't want compressed compressed streams compression_otf_method = 0; recursion_depth++; @@ -9162,7 +9012,7 @@ recursion_result recursion_compress(int compressed_bytes, int decompressed_bytes } else { if ((recursion_depth + 1) > max_recursion_depth_used) max_recursion_depth_used = (recursion_depth + 1); - // Get recursion file size + // get recursion file size tmp_r.file_length = fileSize64(tmp_r.file_name); } @@ -9205,7 +9055,7 @@ recursion_result recursion_decompress(long long recursion_data_length) { local_penalty_bytes = new char[MAX_PENALTY_BYTES]; best_penalty_bytes = new char[MAX_PENALTY_BYTES]; - // Disable compression-on-the-fly in recursion - we don't want compressed compressed streams + // disable compression-on-the-fly in recursion - we don't want compressed compressed streams compression_otf_method = 0; recursion_depth++; @@ -9221,7 +9071,7 @@ recursion_result recursion_decompress(long long recursion_data_length) { printf("Recursion end - back to recursion depth %i\n", recursion_depth); } - // Get recursion file size + // get recursion file size tmp_r.file_length = fileSize64(tmp_r.file_name); tmp_r.frecurse = fopen(tmp_r.file_name, "rb"); @@ -9252,11 +9102,11 @@ void own_fputc(char c, FILE* f) { void fout_fputc(char c) { switch (compression_otf_method) { - case 0: { //uncompressed + case 0: { // uncompressed fputc(c, fout); break; } - case 1: { //bZip2 + case 1: { // bZip2 unsigned char temp_buf[1]; temp_buf[0] = c; own_fwrite(temp_buf, 1, 1, fout); @@ -9269,11 +9119,11 @@ unsigned char fin_fgetc() { if (comp_decomp_state == P_CONVERT) compression_otf_method = conversion_from_method; switch (compression_otf_method) { - case 0: { //uncompressed + case 0: { // uncompressed return fgetc(fin); break; } - case 1: { //bZip2 + case 1: { // bZip2 unsigned char temp_buf[1]; own_fread(temp_buf, 1, 1, fin); return temp_buf[0]; @@ -9288,7 +9138,7 @@ void init_compress_otf() { if (comp_decomp_state == P_CONVERT) compression_otf_method = conversion_to_method; switch (compression_otf_method) { - case 1: { //bZip2 + case 1: { // bZip2 otf_bz2_stream_c.bzalloc = NULL; otf_bz2_stream_c.bzfree = NULL; otf_bz2_stream_c.opaque = NULL; @@ -9305,9 +9155,9 @@ void denit_compress_otf() { if (comp_decomp_state == P_CONVERT) compression_otf_method = conversion_to_method; switch (compression_otf_method) { - case 1: { //bZip2 + case 1: { // bZip2 - // Uncompressed data of length 0 ends bZip2 compress-on-the-fly data + // uncompressed data of length 0 ends bZip2 compress-on-the-fly data char final_buf[9]; for (int i = 0; i < 9; i++) { final_buf[i] = 0; @@ -9324,7 +9174,7 @@ void init_decompress_otf() { if (comp_decomp_state == P_CONVERT) compression_otf_method = conversion_from_method; switch (compression_otf_method) { - case 1: { //bZip2 + case 1: { // bZip2 otf_bz2_stream_d.bzalloc = NULL; otf_bz2_stream_d.bzfree = NULL; otf_bz2_stream_d.opaque = NULL; @@ -9344,7 +9194,7 @@ void denit_decompress_otf() { if (comp_decomp_state == P_CONVERT) compression_otf_method = conversion_from_method; switch (compression_otf_method) { - case 1: { //bZip2 + case 1: { // bZip2 (void)BZ2_bzDecompressEnd(&otf_bz2_stream_d); break; @@ -9352,7 +9202,7 @@ void denit_decompress_otf() { } } -// Get current time in ms +// get current time in ms long long get_time_ms() { #ifndef LINUX return GetTickCount(); @@ -9363,7 +9213,7 @@ long long get_time_ms() { #endif } -// Nice time output, input t in ms +// nice time output, input t in ms // 2^32 ms maximum, so will display incorrect negative values after about 49 days void printf_time(long long t) { printf("Time: "); @@ -9425,4 +9275,4 @@ void ctrl_c_handler(int sig) { (void) signal(SIGINT, SIG_DFL); error(ERR_CTRL_C); -} +} \ No newline at end of file