ebook Format Quest

Source: Internet
Author: User

1. epub Format we are very familiar with, is the PK company compression software is made, so you can use: right--and open mode--compression software (many kinds of kernel should be similar), open use, but the core is top secret. We can't analyze it without it.
2. mobi format (only for English text and unencrypted documents) relative compression is relatively simple, and sometimes we can guess what the content, Mobi text compression roughly as follows:
A. English: Must be a complete word at the beginning (because there is nothing in front of it), if there is a previous content >=3 and <=10, with 2 16 binary numbers: The first 4 bits must be 80--BF (x000-), and the last 12 bits represent the values and lengths of the forward index. The last 3 bits represent the length, and the 9-bit right-shift 3-bit resulting number is the forward-indexed value. For example: This is a test. can be compressed into (this 8018a test) interpreted as (X000 0000 000X 0000) At the beginning of 4 bits for 8 means that there are previous occurrences, the latter three bits is 0 for the length of 0+3, up to (XXX) 7+3, Move right 3 bits to get (000000XX), that is, 8080 the position is 3 characters ahead (the space is also the character) length of 3 to get is+ space.
B. English spaces appear very high frequency, so if there is no repetition of length 3-10, the space and the following character +80 (16 binary) to synthesize a character, such as: Space +he (48+80) encoded as: C865, the space +he encoded as: E865. F765 decompression as: we.
c. Chinese and some special symbols: it seems that the compression of Mobi is not suitable for Chinese, perhaps the dynamic suggested dictionary to index, analysis is difficult, usually Chinese and special symbols with a 16 in the number of means: the first 4 bits must be 0 (0000), the last 4 bits indicates that the characters are not compressed, As 06 means: The following 6 characters are not compressed (copied).

The above is Mobi format compression decompression ABC, the actual document also has other pictures, Chinese index and other content compression, there is no way to analyze.

The decoding program written with Delphi is the following code:

Begin//begins to read verbatim into the compressed Mobi, assuming that the variables and functions are defined;
counter:=0; Counter
j:=0; Reading device;
Tm. position:=0; Tm=tmemorystream; Dynamically allocated memory and has been read into the Mobi file;
while (j<size-2) does//size is the file length, you can adjust the starting position according to the file index;
Begin
Tm. Read (rd1,1); Read into a character;
Inc (J);
Fm. Seek (counter,0); The positioning of the pointer to move forward, sometimes back, so read into each character when re-positioning;
Case Rd1 of//simple handling of different situations with a single cases;

$ $BF: the//dollar sign indicates a 16-digit number, and only a preliminary estimate of the possible approximate demarcation. (compression designers will use all the space available to find ways to use the foot);
Begin
Tm. Position:=tm. Position-1;
Tm. Read (bw,2);
Bw:=swap (BW) and $7FFF;
Sm1:=counttrace (BW) +3;
Writemem (SM1);
Inc (J);
End


$1..$0F:


For i:=0 to Rd1-1 do
Begin
Tm. Read (rd2,1);
Inc (J);
Fm. Write (rd2,1);
Inc (counter);
End

$c 0.. $FF:
Begin
c:=$20;
Fm. Write (c,1);
Inc (counter);
C:=rd1 and $7f;
Fm. Write (c,1);
Inc (counter);
End
$0:inc (counter);
Else
Fm. Write (rd1,1);
Inc (counter);
End
End
Fm. position:=0;
OutStream. CopyFrom (FM,COUNTER-1);
Fm. Free;
Tm. Free;
End

The above program is compiled by delphi7.0.




ebook Format Quest

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.