⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 misc.c

📁 CHM decompiler is a program that converts the internal files of CHM files back into the HHP, HHC, an
💻 C
📖 第 1 页 / 共 2 页
字号:
				doc_index_s = header[0x1E];				doc_index_r = header[0x1F];				code_count_s = header[0x20];				code_count_r = header[0x21];				loc_codes_s = header[0x22];				loc_codes_r = header[0x23];				if( doc_index_s != 2 || code_count_s != 2 || loc_codes_s != 2 ){					fprintf( stderr, "%s: %s/%s: %s\n", PROGNAME, input, "$FIftiMain", "one of the scale parameters has a value other than two, which is not yet supported" );					EMAIL_CHM;					goto E_FCLOSE;				}				node_len = get_DWORD( header + 0x2E );				leaf_node = malloc(node_len);				if( !leaf_node ){					fprintf( stderr, "%s: %s %s: %s\n", PROGNAME, input, "leaf node buffer", strerror(errno) );					goto E_FCLOSE;				}				num_topics = get_DWORD( header + 4 );				tree_depth = get_WORD( header + 0x18 );				/* Descend the index tree */				fseek( fiftimain, node_offset, SEEK_SET );				while( --tree_depth ){					int len;					fseek( fiftimain, 2, SEEK_CUR );					len = fgetc( fiftimain );					if( len == EOF ){						fprintf( stderr, "%s: %s/%s: %s\n", PROGNAME, input, "$FIftiMain", feof( fiftimain ) ? "unexpected end of file" : strerror(errno) );						goto E_MALLOC;					}					fseek( fiftimain, (unsigned)len, SEEK_CUR );					if( !read_DWORD( fiftimain, &node_offset ) ){						fprintf( stderr, "%s: %s/%s: %s\n", PROGNAME, input, "$FIftiMain", feof( fiftimain ) ? "unexpected end of file" : strerror(errno) );						goto E_MALLOC;					}					fseek( fiftimain, node_offset, SEEK_SET );				}				/* Read all the words into memory */				for(;;){					if( !fread( leaf_node, node_len, 1, fiftimain ) ){						fprintf( stderr, "%s: %s/%s: %s\n", PROGNAME, input, "$FIftiMain", feof( fiftimain ) ? "unexpected end of file" : strerror(errno) );						goto E_MALLOC;					}					node_offset = get_DWORD( leaf_node );					tmp = get_WORD( leaf_node + 4 );					free_space = get_WORD( leaf_node + 6 );					if( tmp ){						fprintf( stderr, "%s: warning: %s/%s: %s\n", PROGNAME, input, "$FIftiMain", "an unknown field was non-zero" );						EMAIL_CHM;					}					if( current_word ) memset( current_word, 0, current_word_len );					offset = leaf_node + 8;					for( word_i = 0; offset < leaf_node+node_len-free_space; word_i++ ){						new_len = *(offset++);						old_len = *(offset++);						if( !word_i && old_len ){							fprintf( stderr, "%s: warning: %s/%s: %s\n", PROGNAME, input, "$FIftiMain", "old_len was non-zero at the start of a node" );							EMAIL_CHM;						}						{ /* Grow the current_word string */							size_t new_current_word_len = old_len+new_len;							size_t new_current_word_size = ((new_current_word_len/current_word_grow)+1)*current_word_grow;							if( new_current_word_size > current_word_size ){								char* new_current_word = (char*)realloc(current_word,new_current_word_size);								if( !new_current_word ){									fprintf( stderr, "%s: %s %s: %s\n", PROGNAME, input, "current word buffer", strerror(errno) );									goto E_MALLOC;								}								current_word = new_current_word;								current_word_size = new_current_word_size;							}							current_word_len = new_current_word_len;						}						if(new_len){							memcpy( current_word+old_len, offset, new_len-1 );							offset += new_len-1;						} else {							fprintf( stderr, "%s: %s/%s: %s\n", PROGNAME, input, "$FIftiMain", "zero new_len" );							goto E_MALLOC;						}						if(old_len+new_len) current_word[old_len+new_len-1] = 0;						{ /* Grow the word array */							size_t new_words_len = words_len + 1;							size_t new_words_size = ((new_words_len/words_grow)+1)*words_grow;							if( new_words_size > words_size ){								char** new_words = (char**)realloc(words,sizeof(char*)*new_words_size);								if( !new_words ){									fprintf( stderr, "%s: %s %s: %s\n", PROGNAME, input, "word array buffer", strerror(errno) );									goto E_MALLOC;								}								words = new_words;								words_size = new_words_size;							}							words_len = new_words_len;						}						/* Store the current word */						words[words_len-1] = strdup(current_word);						if( !words[words_len-1] ){							fprintf( stderr, "%s: %s %s: %s\n", PROGNAME, input, "word buffer", strerror(errno) );							goto E_MALLOC;						}						context = *(offset++);						if( context != 0 && context != 1 ){							fprintf( stderr, "%s: warning: %s/%s: %s\n", PROGNAME, input, "$FIftiMain", "unknown context" );							EMAIL_CHM;						}						wlc_count = get_be_ENCINT( &offset );						wlc_offset = get_DWORD( offset ); offset += 4;						tmp = get_WORD( offset ); offset += 2;						if( tmp ){							fprintf( stderr, "%s: warning: %s/%s: %s\n", PROGNAME, input, "$FIftiMain", "an unknown field was non-zero" );							EMAIL_CHM;						}						wlc_length = get_be_ENCINT( &offset );						{ /* Grow the word location codes buffer */							size_t new_word_location_codes_len = wlc_length;							size_t new_word_location_codes_size = ((new_word_location_codes_len/word_location_codes_grow)+1)*word_location_codes_grow;							if( new_word_location_codes_size > word_location_codes_size ){								BYTE* new_word_location_codes = (BYTE*)realloc(word_location_codes,new_word_location_codes_size);								if( !new_word_location_codes ){									fprintf( stderr, "%s: %s %s: %s\n", PROGNAME, input, "encoded word locations buffer", strerror(errno) );									goto E_MALLOC;								}								word_location_codes = new_word_location_codes;								word_location_codes_size = new_word_location_codes_size;							}							word_location_codes_len = new_word_location_codes_len;						}						fseek( fiftimain, wlc_offset,  SEEK_SET );						if( !fread( word_location_codes, wlc_length, 1, fiftimain ) ){							fprintf( stderr, "%s: %s/%s: %s\n", PROGNAME, input, "$FIftiMain", feof( fiftimain ) ? "unexpected end of file" : strerror(errno) );							goto E_MALLOC;						}						wlc_bit = 7;						wlc_p = word_location_codes;						document_index = 0;						for( di_i = 0; di_i < wlc_count && wlc_p < word_location_codes+wlc_length; di_i++ ){							/* Entries are padded to a full byte (usually with zeros) */							if( wlc_bit != 7 ) wlc_p++;							wlc_bit = 7;							document_index += get_SRINT( &wlc_p, &wlc_bit, doc_index_s, doc_index_r );							code_count = get_SRINT( &wlc_p, &wlc_bit, code_count_s, code_count_r );							{ /* grow document array if nessecary */								size_t new_docs_len = document_index + 1;								size_t new_docs_size = ((new_docs_len/docs_grow)+1)*docs_grow;								if( new_docs_size > docs_size ){									document_t* new_docs = (document_t*)realloc(docs,sizeof(document_t)*new_docs_size);									if( !new_docs ){										fprintf( stderr, "%s: %s %s: %s\n", PROGNAME, input, "document array buffer", strerror(errno) );										goto E_MALLOC;									}									docs = new_docs;									docs_size = new_docs_size;								}								/* Initialize the new entries */								if( new_docs_len > docs_len ){									for( docs_i = docs_len; docs_i < new_docs_len; docs_i++ ){										docs[docs_i].words = NULL;										docs[docs_i].words_len = docs[docs_i].words_size = 0;										docs[docs_i].latest_title = docs[docs_i].earliest_non_title = ~(SRINT)0;									}									docs_len = new_docs_len;								}							}							location_code = 0;							for( lc_i = 0; lc_i < code_count; lc_i++ ){								location_code += get_SRINT( &wlc_p, &wlc_bit, loc_codes_s, loc_codes_r );								{ /* grow word array if nessecary */									size_t new_words_len = location_code + 1;									size_t new_words_size = ((new_words_len/doc_words_grow)+1)*doc_words_grow;									if( new_words_size > docs[document_index].words_size ){										char** new_words = (char**)realloc(docs[document_index].words,sizeof(char*)*new_words_size);										if( !new_words ){											fprintf( stderr, "%s: %s %s: %s\n", PROGNAME, input, "document word array buffer", strerror(errno) );											goto E_MALLOC;										}										docs[document_index].words = new_words;										docs[document_index].words_size = new_words_size;									}									if( new_words_len > docs[document_index].words_len ){										/* memset( &docs[document_index].words[docs[document_index].words_len-1], 0, sizeof(docs[document_index].words[0])*(new_words_len-docs[document_index].words_len-1) ); */										for( words_i = docs[document_index].words_len; words_i < new_words_len; words_i++ )											docs[document_index].words[words_i] = NULL;										docs[document_index].words_len = new_words_len;									}								}								/* Initialize this entry */								docs[document_index].words[location_code] = words[words_len-1];								if( context ){									if( docs[document_index].latest_title == ~(SRINT)0 || docs[document_index].latest_title < location_code )										docs[document_index].latest_title = location_code;								} else if( docs[document_index].earliest_non_title == ~(SRINT)0 || docs[document_index].earliest_non_title > location_code )									docs[document_index].earliest_non_title = location_code;							}						}					}					if( !node_offset ) break;					fseek( fiftimain, node_offset, SEEK_SET );				}				if( open_sitemap() ){					chdir( "#recreated" );					chdir( "#from-fts" );					/* Write out all the words into documents */					for( docs_i = 0; docs_i < docs_len; docs_i++ ){						/* Long enough for either a #TOPICS entry (16) or a sprintf( "#%d.html", int 64 ) */	/* #if ( sizeof(SRINT) > 4)		#error You need to increase the size of topic on the next line	#end */						BYTE entry[26];						char* out_file = NULL;						if( !docs[docs_i].words ) continue;						if( docs[docs_i].earliest_non_title != ~(SRINT)0 && docs[docs_i].latest_title != ~(SRINT)0 && docs[docs_i].earliest_non_title <= docs[docs_i].latest_title ){							fprintf( stderr, "%s: warning: %s/%s: %s\n", PROGNAME, input, "$FIftiMain", "a document had overlapping title & body" );							EMAIL_CHM;						}						fseek( topics, docs_i*16, SEEK_SET );						if( fread( entry, 16, 1, topics ) ){							fseek( urltbl, get_DWORD(entry+8)+8, SEEK_SET);							if( read_DWORD(urltbl,&tmp) ){								out_file = get_urlstr(tmp+8);							}						}						/* Default in case of errors*/						if( !out_file || !*out_file ){							if( out_file ) free( out_file );							sprintf( entry, "#%d.html", docs_i );							out_file = entry;						}						f = fopen( out_file, "wb" );						if( f ){							fputs( "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\"><html>\n", f );								fputs( "<head>\n", f );									fputs( "<title>", f );										print_string( f, get_DWORD(entry+4) );									fputs( "</title>", f );									if( docs[docs_i].latest_title != ~(SRINT)0 ){										fputs( "\n<title>", f );											for( word_i = 0 ; word_i < docs[docs_i].latest_title; word_i++ ){												fputs( docs[docs_i].words[word_i] ? docs[docs_i].words[word_i] : "????", f );												fputc( ' ', f );											}											fputs( docs[docs_i].words[word_i] ? docs[docs_i].words[word_i] : "????", f );										fputs( "</title>", f );									}								fputs( "\n</head>\n", f );								if( docs[docs_i].earliest_non_title != ~(SRINT)0 ){									fputs( "<body><p>\n", f );										for( word_i = docs[docs_i].earliest_non_title; word_i < docs[docs_i].words_len; word_i++ ){											fputs( docs[docs_i].words[word_i] ? docs[docs_i].words[word_i] : "????", f );											fputc( '\n', f );										}									fputs( "</p></body>\n", f );								}							fputs( "</html>", f );							if( ferror( f ) | feof( f ) ){								fprintf( stderr, "%s: %s/%s: %s\n", PROGNAME, input, "$FIftiMain", feof( fiftimain ) ? "unexpected end of file" : strerror(errno) );							}							fclose( f );							f = NULL;						}						FREE(docs[docs_i].words);						if( out_file != (char*)entry ){ FREE( out_file); }					}					chdir( ".." );					chdir( ".." );					close_sitemap();				}E_MALLOC:				for(docs_i = 0; docs_i < docs_len; docs_i++ )					free(docs[docs_i].words);				free(docs);				for(words_i = 0; words_i < words_len; words_i++ )					free(words[words_i]);				free(words);				free(word_location_codes);				free(current_word);				free(leaf_node);			} else chdir( ".." );		}E_FCLOSE:		fclose( fiftimain );	} else if( errno && errno != ENOENT )		fprintf( stderr, "%s: %s/%s: %s\n", PROGNAME, input, "$FIftiMain", strerror(errno) );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -