Online CHM reader (1) -- Overview of CHM file formats

Source: Internet
Author: User
The cloud Xiang online software platform provides webim, online storage, online reading of CHM e-books, and other services, as well as free Group Creation (unlimited number of users) and online storage of chat records.

Once I used my cloud Xiang online software platform, I should know that there is a CHM reader above. The purpose of this article is to introduce how to use a function-like online CHM reader.

Related Technologies

1. Structured Storage

Structured Storage provides file and data persistence in COM by handling a single file as a structured collection of objects known as storages and streams.

The purpose of structured storage is to reduce the performance penalties and overhead associated with storing separate objects in a single file. structured Storage provides a solution by defining how to handle a single file entity as a structured collection of two types of objects-storages and streams-through a standard implementation called compound files. this enables the user to interact with, and manage, a compound file as if it were a single file rather than a nested hierarchy of separate objects.

For more information about structured storage, see msdn. The CHM File is essentially a structured storage format file. Therefore, to read files in CHM, you need to know the structured storage APIs.

2. ISAPI filter

As an alternative to CGI, ISAPI (Internet Server Application Programming Interface) is an API standard on Web servers jointly proposed by Microsoft and process software. Isapis are closely integrated with web servers and provide powerful functions to obtain a large amount of information. Therefore, isapis can be used to develop flexible and efficient Web Server enhancements.Program. To implement the CHM online reader (without decompiling), you must use the ISAPI filter to implement URL redirection.

3.Lesktop

Lesktop is an open source JS interface library used to develop Ria websites. lesktop provides a powerful visual development tool to help you quickly develop Ria websites. The CHM online reader described in this article uses lesktop to develop the front-end interface.

CHM File Format

1. decompile the CHM File

To read the CHM file, you must decompile the CHM File and extract the files (web pages, images, etc.). to decompile the CHM file, you must use the stgopenstorage function of Win32 API ,. net decompilation of CHM files. read this article.Article:

CHM Help File Extractor

2. # System File

After decompiling the CHM file, you can see the file named # System in the extracted file. This file stores information about the CHM File, such as the start page and title. # System is a binary file, and its format is not complex. The format is as follows:

ID (2 bytes) + Data Length (2 bytes) + data (the number of bytes is determined by the Data Length)

# The system file is composed of more than one such data. According to this rule, you can read the data corresponding to all IDs and save it to a hashtable,CodeAs follows:

 Private bool  Readsession (  Binaryreader  Reader ){  If  (Reader. basestream. Position> = reader. basestream. length)  Return false  ;  Uint16  Id = reader. readuint16 ();  Uint16  Count = reader. readuint16 (); If  (Count + reader. basestream. Position <= reader. basestream. Length ){  If  (Count> 0) {_ session [ID] = reader. readbytes (count );}  Return true  ;}  Else  {  Return false  ;}}  Public  Chminfo (  Stream  Stream ){  Binaryreader  Reader =  New Binaryreader  (Stream );  While  (Readsession (Reader ));} 

The relationships between IDs and data are as follows:

0x0002-path to the start page

0x0003-title

0x0004-language

Based on this relationship, you can read the title and start page of the CHM File.

3. directory file (*. HHC)

If CHM has a directory, after decompiling the CHM file, you can see a file with the HHC extension in the extracted file, which saves the directory structure of CHM.

Is the content of an HHC file. The general rule is that every <li> <Object>... <Object> corresponds to a node in the directory tree. <Object>... The parameters in <Object> record the node attributes (corresponding pages, names, etc ). If this node has sub-nodes, <li> followed by a <ul> </ul>, and <ul> all nodes in it are their sub-nodes.

The previous section briefly describes how to decompile the CHM File Format and key file format. In the next article, we will introduce how to process directory files (*. HHC file) and how to use the ISAPI filter to implement an online CHM reader without decompiling the CHM internal file.

Although this series is not completed yet, you can download it firstSource codePreview the online CHM reader:

Source code of online CHM reader (Note: ISAPI filter is required for this CHM reader. Read the deployment instructions carefully)

If you have any questions, contact me through webim.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.