TL;DR
- Do not buy any books from ConTenDo.jp; otherwise check this article on how to remove the encryptions.
- 千万不要在 ConTenDo.jp 上买书,但是买了的话看本教程可以破解书籍加密!
- ConTenDo.jp から本を購入しないでください。 それ以外の場合は、暗号化を削除する方法についてこの記事を確認してください。
If you are frustrated with the same thing and want to download the unencrypted books you purchased? Please feel free to leave a comment and I think I can help you.
I might consider releasing a dedicated tool for this platform, which entirely depends on my spare time, unfortunately. Here’s the proof-of-concept codes I used to decrypt my purchased books. (Please understand before using.)
The apps are made of:
- Desktop apps (Windows/Linux/MacOS v1.6.3): Java 12 + JavaFX.
- Mobile apps (Android/iOS v1.2.2): Cordova + JNI.
Encryptions used by the platform (apps):
- most files in
<user_dir>/<user_name>/.ConTenDoViewer/: Not encrypted. <user_dir>/<user_name>/.ConTenDoViewer/info: a serialized Java 12 object, containing book data decryption keys (encrypted by AES and different for each book), a random int64 number of which the MD5 checksum is your AES private key, and more account info (e.g. login status, expiry date, etc.).- book files (
*.pdfand*.epub):- EPUB: zip archive, encryption applies to each single file entry
- PDF: whole file
- Encryption for file:
- less than 1024 bytes: not encrypted
- otherwise: maybe encrypted, using custom XORs and Bitwise-shifts
(encrypted file magic numbers in Big-Endian:
0x43444546or0x49474546)
- Other book formats: not supported
Tools I used:
- VSCode on WSL 2 to search codes.
- JD-GUI v1.6.6 to decompile JAR packages.
- CFR v0.151 to decompile JAR packages differently.
- 010 Editor: hex editor.
- Fiddler: capturing network packages and providing proxies.
Codes are obfuscated and they make copy&paste harder to work here (for example, Java package names conflict with the same class names). :-(
How it all happened?
I was learning Japanese recently and I was looking for an ideal textbook as a begin. Since I am a native Mandarin Speaker, textbooks in Mandarin would be more preferred.
Looking for the textbook
There are some popular textbooks for preparing for JLPT (Japanese-Language Proficiency Test). However, I am not learning for the tests. I am just learning to unlock the ability. The books are (for the reference):
- 「みんなの日本語」 (a.k.a 《大家的日语》)
- 《新版 标准日本语》
After digging around, I found another book that looked more suitable for me:
- 「ニュー・システムによる日本語」 and 「ニュー・システムによる日本語 続編」
- In English: New System Japanese (English Edition) and New System Japanese Sequel (English Edition)
- In Traditional Chinese: 《ニュー・システムによる日本語(中国語・英語版)》
- In Simplified Chinese: 《海老原日本語》 (Discontinued)
These books teach Japanese in a new system obviously, mainly focusing on teaching the verbs more practically which are said to be the most difficult part in learning Japanese. The author is Minoko Ebihara (海老原 峰子), who is a Japanese educator teaching in Singapore.
Looking for sample pages and purchase
Since I have the target, I tried to look for some sample pages so that I can double-check if it was the one I was looking for. However, these books are not as popular as the other two books.
Checking the price on Amazon, they sell JPY ¥3080 and do not support international delivery. Apparently, I cannot use Amazon Japan this time.

Heard from a YouTuber saying they also sold digital versions. So, I successfully found their official digital shops, which was open on a platform called the base, similar to eBay.
JPY ¥1870 is quite cheap for error tolerance. So, I tried to purchase one. However, the official website rejected my Travel Money Card… Also, tried to phone the bank, 40 minutes passed and no human actually answered.
Therefore, I tried to find other sellers, and ConTenDo was the one…
ConTenDo ebook platform
ConTenDo.jp (電子書籍サイト [コンテン堂]) is an e-book platform, including selling, renting, reading e-books.
I found the book also available on ConTenDo with the same price, so I purchased the book with my newly registered accounts. The good news was that they accepted my visa card.
That was how everything began. Their website said the size of the book, so I thought I should at least be able to download the book.

However, they did not allow me to download my ebook. Instead, I had to use their apps to read. That was fine actually if the app was good enough. The thing is that I usually liked to print out those books and make notes.
For me, the app was very useless:
- The book I purchased was entirely in pictures, so I cannot select/copy contents.
- The app does not support print/copy functions.
- The app is very laggy and buggy.
- The Android app is not even available on the Australian Play Store!
Look at the UI:

All these reasons made me very unhappy. So, I tried to get a refund. And as you can imagine, they said a refund was impossible at all.
So, I was not happy and I wanted to get my book back digitally.
How to get your books back?
Screenshots!!!
Yes, it worked for me. I spent 10 minutes using Snapaste to take screenshots for each page. I set up the shortcuts:
- F1 - start screenshot
- Enter - full screen screenshot
- RightArrow - Next page

and then use ImageMagick to crop the screenshots:
$ convert Snipaste/Snipaste_2021-03-27_22-15-37.png -crop 985x1394+787+3 "New System English (English + Chinese)/Snipaste_2021-03-27_22-15-37.png"
$ convert Snipaste/Snipaste_2021-03-27_22-19-17.png -crop 985x1394+787+3 "New System English (English + Chinese)/Snipaste_2021-03-27_22-19-17.png"
$ convert Snipaste/Snipaste_2021-03-27_22-21-08_0.png -crop 985x1394+787+3 "New System English (English + Chinese)/Snipaste_2021-03-27_22-21-08_0.png"
$ convert Snipaste/Snipaste_2021-03-27_22-15-42.png -crop 985x1394+787+3 "New System English (English + Chinese)/Snipaste_2021-03-27_22-15-42.png"
$ convert Snipaste/Snipaste_2021-03-27_22-19-18.png -crop 985x1394+787+3 "New System English (English + Chinese)/Snipaste_2021-03-27_22-19-18.png"
...
At last, use any PDF generation tool (e.g. ImageMagick, Adobe Acrobat, etc.).
Analysis
General
The initial idea was to find the downloaded files first.
Since I was using Windows 10, I looked for:
<user_dir>\AppData\Local: usually where most apps store their data.<app_install_dir>: shouldn’t be the case as it requires Admin permission to write.<user_dir>\.config\: popular new *nix-like systems.<user_dir>\<hidden_dir>: popular old *nix-like systems.
So, the dir was <user_dir>/.ConTenDoViewer/. The file structure is like:
.ConTenDoViewer/
├── books
│ ├── user
│ │ ├── J<numbers>.S.epub
│ │ └── ... more books
│ └── web
│ └── user_mailprovider.com
│ ├── J<numbers>
│ │ └── thumb_small
│ ├── ... more books
│ │ └── thumb_small
│ ├── items
│ └── sort
├── config
├── fonts
│ └── ... more fonts
├── info
└── pid
So, the encrypted files were:
- ./info
- ./books/../*.epub
Initially, I didn’t realise the epub files were encrypted as I could use unzip to read the file. However, when I tried to use several different epub readers (Adobe Digital Editions and Moon+ Reader Pro), they all didn’t work.
So, I unzipped the EPUB file and looked into each file. I saw the single files were encrypted. On top of each file, there seemed to have some key texts:

Network capturing
The first thing I could think of the encryption definitely was related to some key exchange algorithms.
So, I set up Fiddler on Windows to capture the key texts. However, the packages could not be captured as expected.
Therefore, I looked deeper into the installed files. There was a JDK directory inside!
I also used 7-zip to check what the executable looks like.
It turned out to be a jar package.
That makes things much easier because I could just use java -jar <proxy> *.jar to set up the proxy.
However, I do not have JDK installed on my windows. My JDK was installed on WSL 2. ;-(
I also used RDP to connect to my WSL 2 to try running it within WSL 2. My installed JDK 11 did not contain JavaFX, so it could not be executed directly.
Considering the proxy setup between Windows host and WSL 2 is also another complicated work, I gave up this path.
Java Decompilation
Since it was a JAR package, using JD-GUI was intuitive. It was good to see the codes were obfuscated.
I like challenges!
It wasn’t easy to navigate to the entry point. Luckily JavaFX requires similar obfuscator settings like Android to not include activity classes.
So, in package net.zamasoft.reader.shelf, there are several controller classes.
These classes are like Android activity classes.
Also, if you are familiar JavaFX, there are layout files as well named *.fxml.
I didn’t upload them but you could simply unzip
the jar file to see them.
This took quite a long time to figure out what actually went on as JD-GUI was really hard to use for finding cross-references. I essentially debugged the function call stack on my brain LMAO. Here’s how it looked like:

One thing I would like to note here was that JD-GUI sometimes decompiled wrongly. So, I used another tool called CFR as an N+1 reference. That was how CFR look like when using VSCode:

Mobile debugging
You know, debugging these obfuscated codes was really painful, I also checked the Android application to see if would be easier.
I used dex2jar and jd-gui, and it seemed that the Android app is every more complicated for me. It used Cordova which I was not familiar with.
Plus, it used many JNI libraries, which made it harder to transcode on my proof-of-concept.
So, I ended up giving up this approach.
One interesting is that, Play Store reviews were the same as I thought:

How the encryption works
As I mentioned previously, there are two parts of the saved files encrypted.
The PoC (Proof of Concept) codes and decryption tools can be found here: https://github.com/MewX/contendo-viewer-decryptor.
info file
The info file stores the user login information and decryption keys for each book.
Essentially, it is a keystore.
Each book takes a different key to decrypt. The ConTenDo Viewer app checks this keystore when seeing an encrypted file.
The keystore structure is a hashmap:
// The map can look like this:
// {
// "3c9b6643958814859e22aef293d807ec": {..., encryption_key = "..."},
// "c566fb3127e5b49b299e388924db71e6": {..., encryption_key = "..."},
// }
HashMap<String, String> bookIdToDecryptionKeyMap;
The book ID is from 0x1C to 0x3B (included):
# Example 1 ID: 3c9b6643958814859e22aef293d807ec
0000h: 43 44 45 46 01 00 00 00 00 00 00 00 63 36 38 30 CDEF........c680
0010h: 66 66 35 64 63 36 38 30 66 66 35 64 33 63 39 62 ff5dc680ff5d3c9b
0020h: 36 36 34 33 39 35 38 38 31 34 38 35 39 65 32 32 6643958814859e22
0030h: 61 65 66 32 39 33 64 38 30 37 65 63 01 03 04 01 aef293d807ec....
# Example 2 ID: c566fb3127e5b49b299e388924db71e6
0000h: 49 47 45 46 02 00 00 00 00 00 00 00 ED 03 00 00 IGEF........í...
0010h: 80 00 00 00 00 01 00 00 00 00 00 00 63 35 36 36 €...........c566
0020h: 66 62 33 31 32 37 65 35 62 34 39 62 32 39 39 65 fb3127e5b49b299e
0030h: 33 38 38 39 32 34 64 62 37 31 65 36 00 00 00 00 388924db71e6....
Then there’s a random Long number at the beginning of the info file.
That’s the AES encryption secret key used to decode the keystore.
Detailed codes can be found here:
// Note, the key changes everytime because it's random.
// It's at the beginning of info file.
byte[] builtSecretKey = buildSecretKey(6874628185188049249L);
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
SecretKeySpec secretKeySpec = new SecretKeySpec(messageDigest.digest(builtSecretKey), "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(2, secretKeySpec);
ObjectInputStream objectInputStream = new ObjectInputStream(new CipherInputStream(fileInputStream, cipher));
long secretKey = objectInputStream.readLong();
HashMap<String, com.b.a.b.a> n = (HashMap<String, com.b.a.b.a>) objectInputStream.readObject();
// Note: com.b.a.b.a.a.f() is the decryption key.
Book file
Since we have the decryption key for the book, we can decrypt the book file.
ConTenDo Viewer supports EPUB and PDF files only. The codes check the file size first.
- If the file size is less than 1024, then there is no encryption.
- If the file does not have a magic number, then there is no encryption.
The magic numbers are in Big-Endian:
0x43444546(CDEF in text) or0x49474546(IGEF in text).
The encryption used a code table in the first 1024 bytes in each encrypted file.
For each file in the same EPUB, 0x3C to 0x400 (exclusive) are always the same.
Plus the decryption key, we can decrypt the file.
The implementation codes are here. To use it:
// https://github.com/MewX/contendo-viewer-decryptor/blob/b6af72d2a139770ec929725fc29d3f7251039894/Decrypt.java#L57-L68
net.zamasoft.reader.book.a.b randomAccessFile = new net.zamasoft.reader.book.a.b(file);
ArrayList<Byte> bytes = new ArrayList<>();
while (!randomAccessFile.isEOF()) {
byte b = (byte) randomAccessFile.read();
bytes.add(b);
}
assert randomAccessFile.length() == bytes.size();
byte[] bs = new byte[bytes.size()];
for (int ii = 0; ii < bs.length; ii++) {
bs[ii] = bytes.get(ii);
}
return bs;
Verifying
Since we have the tools to decrypt encrypted files, we can verify if it actually works.
I tried the book I purchased. Before:

After:

Note: the texts are encoded in UTF-8. Thus, don’t panic if you see weird texts.

Here’s another example (with a different decryption key):
$ java Decrypt /mnt/r/comic.S /mnt/r/asdf2

Some takeaways
Please feel free to leave a comment below if this article helped you or if you would need my help to decrypt your books voluntarily.
For me, I’ll double-check if a platform works as I expect before I purchase from them.
TL;DR
- Do not buy any books from ConTenDo.jp; otherwise check this article on how to remove the encryptions.
- 千万不要在 ConTenDo.jp 上买书,但是买了的话看本教程可以破解书籍加密!
- ConTenDo.jp から本を購入しないでください。 それ以外の場合は、暗号化を削除する方法についてこの記事を確認してください。
如果你也遇到了同样让人抓狂的情况,想把已经买好的书无加密地下载下来? 欢迎在评论区留言,我觉得我应该能帮到你。
我可能会考虑专门为这个平台做一个解密工具, 不过很遗憾,这完全取决于我有没有业余时间。 这是我用来解密已购电子书的 概念验证(PoC)代码。(使用前请先理解代码逻辑。)
它的客户端技术栈如下:
- 桌面端(Windows/Linux/MacOS v1.6.3):Java 12 + JavaFX。
- 移动端(Android/iOS v1.2.2):Cordova + JNI。
该平台(客户端)使用的加密方式:
<user_dir>/<user_name>/.ConTenDoViewer/目录下的大部分文件:未加密。<user_dir>/<user_name>/.ConTenDoViewer/info:一个序列化后的 Java 12 对象, 里面包含每本书各自不同的解密密钥(经 AES 加密)、 一个随机的 int64 数字(它的 MD5 校验和就是你的 AES 私钥), 以及更多账户信息(如登录状态、过期时间等)。- 电子书文件(
*.pdf和*.epub):- EPUB:本质是 zip 压缩包,加密作用于其中的每一个单独文件
- PDF:对整个文件加密
- 单文件加密规则:
- 小于 1024 字节:不加密
- 否则:可能被加密,采用自定义的异或(XOR)和位移(Bitwise-shift)算法
(加密文件的大端序魔数为:
0x43444546或0x49474546)
- 其他电子书格式:不支持
我用到的工具:
- WSL 2 上的 VSCode,用于搜索代码。
- JD-GUI v1.6.6,用于反编译 JAR 包。
- CFR v0.151,用于以另一种方式反编译 JAR 包。
- 010 Editor:十六进制编辑器。
- Fiddler:抓包及代理工具。
代码经过了混淆,直接复制粘贴复用起来很麻烦 (比如 Java 的包名和类名重名冲突)。:-(
事情是怎么开始的?
最近我在学日语,想找一本理想的入门教材。 因为我的母语是中文,所以更倾向于中文教材。
寻找教材
市面上有不少专门针对 JLPT(日本语能力测试)的热门教材。 不过我学日语不是为了考级,只是想点亮一项新技能而已。 常见教材有(供参考):
- 「みんなの日本語」(即《大家的日语》)
- 《新版 标准日本语》
一番搜寻之后,我发现了另一套看起来更适合我的书:
- 「ニュー・システムによる日本語」和「ニュー・システムによる日本語 続編」
- 英文版:New System Japanese (English Edition) 和 New System Japanese Sequel (English Edition)
- 繁体中文版:《ニュー・システムによる日本語(中国語・英語版)》
- 简体中文版:《海老原日本語》(已绝版)
顾名思义,这套书采用了“新体系(new system)”来教日语, 重点在于更实用地讲解日语学习中公认最难的动词部分。 作者是海老原峰子(Minoko Ebihara),一位在新加坡任教的日语教育家。
找样章与购买
有了目标之后,我想先找些样章看看, 确认一下这是不是我想要的那本书。 可惜这套书远没有前面那两本那么热门。
去亚马逊日本查了一下价格, 售价 3080 日元,而且不支持国际直邮。 看来这次日亚是指望不上了。

听一位 YouTuber 说 他们也卖电子版。 于是我顺利找到了他们的官方电子书店, 开在一个叫 the base 的平台上,类似 eBay。
1870 日元的价格试错成本不高,所以我试着买了一本。 然而官网居然拒了我的旅行货币卡(Travel Money Card)…… 我也给银行打了电话,等了整整 40 分钟,连个人工客服都没接通。
于是我只好另找其他渠道,结果就碰上了 ConTenDo……
ConTenDo 电子书平台
ConTenDo.jp(電子書籍サイト [コンテン堂])是一个提供电子书购买、租借和阅读的平台。
我发现这本书在 ConTenDo 上也有售,而且价格一样, 于是新注册了个账号把书买了下来。 好消息是他们接受了我的 Visa 卡。
噩梦就是从这里开始的。他们的网页上明明标注了电子书的文件大小, 所以我以为至少能把书下载下来。

结果他们根本不让我下载电子书, 而是强制我用他们自家的 App 阅读。 其实如果 App 做得够好用的话,倒也无所谓; 但问题是我平时习惯把教材打印出来做笔记。
对我来说,这个 App 简直一无是处:
- 我买的这本书通篇都是图片,根本没法选中或复制文字。
- App 不支持打印和复制功能。
- App 卡顿得要命,而且一堆 Bug。
- 它的 Android 客户端甚至没在澳大利亚区 Play Store 上架!
看看这界面:

种种槽点让我非常不爽,于是我申请了退款。 不出所料,对方回复称完全不可能退款。
这下我可彻底不爽了,我一定要把属于我的电子书完完整整地“拿”回来。
怎么把自己的书弄出来?
截屏!!!
没错,这招确实管用。 我花了 10 分钟,用 Snipaste 一页一页截了下来。 我设置了快捷键:
- F1 - 开始截屏
- Enter - 全屏截图
- 右方向键 - 下一页

接着用 ImageMagick 批量裁剪截图:
$ convert Snipaste/Snipaste_2021-03-27_22-15-37.png -crop 985x1394+787+3 "New System English (English + Chinese)/Snipaste_2021-03-27_22-15-37.png"
$ convert Snipaste/Snipaste_2021-03-27_22-19-17.png -crop 985x1394+787+3 "New System English (English + Chinese)/Snipaste_2021-03-27_22-19-17.png"
$ convert Snipaste/Snipaste_2021-03-27_22-21-08_0.png -crop 985x1394+787+3 "New System English (English + Chinese)/Snipaste_2021-03-27_22-21-08_0.png"
$ convert Snipaste/Snipaste_2021-03-27_22-15-42.png -crop 985x1394+787+3 "New System English (English + Chinese)/Snipaste_2021-03-27_22-15-42.png"
$ convert Snipaste/Snipaste_2021-03-27_22-19-18.png -crop 985x1394+787+3 "New System English (English + Chinese)/Snipaste_2021-03-27_22-19-18.png"
...
最后,用任意 PDF 生成工具(比如 ImageMagick、Adobe Acrobat 等)合并即可。
逆向分析
初步排查
最开始的想法是先找到客户端下载到本地的文件。
因为我用的是 Windows 10,所以我依次排查了几个常见路径:
<user_dir>\AppData\Local:大多数软件通常用来存放数据的位置。<app_install_dir>:一般不会放这里,因为写入需要管理员权限。<user_dir>\.config\:较新的类 *nix 系统常用路径。<user_dir>\<hidden_dir>:老派类 *nix 系统常用路径。
最后定位到的目录是 <user_dir>/.ConTenDoViewer/,文件结构如下:
.ConTenDoViewer/
├── books
│ ├── user
│ │ ├── J<numbers>.S.epub
│ │ └── ... more books
│ └── web
│ └── user_mailprovider.com
│ ├── J<numbers>
│ │ └── thumb_small
│ ├── ... more books
│ │ └── thumb_small
│ ├── items
│ └── sort
├── config
├── fonts
│ └── ... more fonts
├── info
└── pid
由此可知,被加密的文件就是:
- ./info
- ./books/../*.epub
一开始我并没意识到 epub 文件是加密的,因为用 unzip 竟然能直接解压读取。 但当我试了好几款不同的 epub 阅读器(Adobe Digital Editions 和静读天下专业版 / Moon+ Reader Pro)时,统统打不开。
于是我把 EPUB 解压出来,挨个查看里面的文件, 这才发现里面的单个文件都被加密了。 而且每个文件的头部看起来都有一些关键字段:

网络抓包
看到加密,我第一反应肯定是和某种密钥交换算法有关。
于是我在 Windows 上配置了 Fiddler 准备抓取密钥文本, 然而根本抓不到预期的网络包。
没办法,我只好深入翻了一下软件的安装目录。 好家伙,里面居然自带了一个 JDK 目录!
我又用 7-zip 看了一下它的可执行文件到底是什么来头,
结果发现本质上就是个 JAR 包。
这下事情就好办多了,因为我完全可以直接用 java -jar <proxy> *.jar 来指定代理。
可尴尬的是,我的 Windows 上没装 JDK, JDK 都装在 WSL 2 里。;-(
我还试着用 RDP 连上 WSL 2 想直接在里面跑起来, 结果我装的 JDK 11 不包含 JavaFX,根本无法直接运行。
考虑到在 Windows 宿主机和 WSL 2 之间折腾代理配置也挺麻烦的, 我便放弃了这条路。
Java 反编译
既然是个 JAR 包,用 JD-GUI 反编译就是最直接的想法。 看到代码经过了混淆,反而让我有点小兴奋。
我喜欢挑战!
想直接找到程序入口并不容易。 好在 JavaFX 和 Android 一样,在配置代码混淆时必须把类似 Activity 的类排除在外。
因此,在 package net.zamasoft.reader.shelf 包下有好几个 Controller 类,
它们就相当于 Android 里的 Activity。
另外,如果你熟悉 JavaFX,应该知道它还有名为 *.fxml 的布局文件。
我没把它们上传,不过你可以直接解压 JAR 文件 自己看。
由于 JD-GUI 查交叉引用实在太难用了, 我花了相当长的时间才理清楚到底发生了什么。 基本上全靠在脑子里“人肉调试”函数调用栈,笑死(LMAO)。 当时看起来就像这样:

有一点要特别提一下:JD-GUI 有时候会反编译出错。 所以我又找了另一个叫 CFR 的工具作为交叉对照参考。 用 VSCode 看 CFR 反编译出来的代码大概是这个样子:

移动端调试
你也知道,看这些混淆代码实在太折磨人了, 所以我顺手也看了一眼 Android 客户端,想看看会不会好搞一点。
我用 dex2jar 和 jd-gui 反编译了一下,结果发现 Android 端对我来说反而更复杂—— 它用了我并不熟悉的 Cordova 框架。
不仅如此,它还用了一堆 JNI 动态库,这让我更难把逻辑移植到我的概念验证(PoC)代码里。
所以我最终还是放弃了移动端这条路线。
有意思的是,Play Store 上的用户评价和我想的一模一样:

加密原理详解
正如前面提到的,本地保存的文件有两部分是加密的。
PoC(概念验证)代码和解密工具可以在这里找到: https://github.com/MewX/contendo-viewer-decryptor。
info 文件
info 文件存储了用户的登录信息以及每本书的解密密钥,
本质上就是一个 密钥库(keystore)。
每本书都有各自独立的解密密钥。 每当 ConTenDo Viewer 遇到加密文件时,就会去查这个密钥库。
密钥库的结构是一个 HashMap:
// The map can look like this:
// {
// "3c9b6643958814859e22aef293d807ec": {..., encryption_key = "..."},
// "c566fb3127e5b49b299e388924db71e6": {..., encryption_key = "..."},
// }
HashMap<String, String> bookIdToDecryptionKeyMap;
书籍 ID 位于文件偏移 0x1C 到 0x3B(包含两端):
# Example 1 ID: 3c9b6643958814859e22aef293d807ec
0000h: 43 44 45 46 01 00 00 00 00 00 00 00 63 36 38 30 CDEF........c680
0010h: 66 66 35 64 63 36 38 30 66 66 35 64 33 63 39 62 ff5dc680ff5d3c9b
0020h: 36 36 34 33 39 35 38 38 31 34 38 35 39 65 32 32 6643958814859e22
0030h: 61 65 66 32 39 33 64 38 30 37 65 63 01 03 04 01 aef293d807ec....
# Example 2 ID: c566fb3127e5b49b299e388924db71e6
0000h: 49 47 45 46 02 00 00 00 00 00 00 00 ED 03 00 00 IGEF........í...
0010h: 80 00 00 00 00 01 00 00 00 00 00 00 63 35 36 36 €...........c566
0020h: 66 62 33 31 32 37 65 35 62 34 39 62 32 39 39 65 fb3127e5b49b299e
0030h: 33 38 38 39 32 34 64 62 37 31 65 36 00 00 00 00 388924db71e6....
在 info 文件的开头还有一个随机的 Long 数值,
那就是用来解码密钥库的 AES 加密密钥源。
详细代码可以在这里看到:
// Note, the key changes everytime because it's random.
// It's at the beginning of info file.
byte[] builtSecretKey = buildSecretKey(6874628185188049249L);
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
SecretKeySpec secretKeySpec = new SecretKeySpec(messageDigest.digest(builtSecretKey), "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(2, secretKeySpec);
ObjectInputStream objectInputStream = new ObjectInputStream(new CipherInputStream(fileInputStream, cipher));
long secretKey = objectInputStream.readLong();
HashMap<String, com.b.a.b.a> n = (HashMap<String, com.b.a.b.a>) objectInputStream.readObject();
// Note: com.b.a.b.a.a.f() is the decryption key.
电子书文件
既然拿到了书籍的解密密钥,我们就可以着手解密电子书文件了。
ConTenDo Viewer 只支持 EPUB 和 PDF 两种格式。代码会先检查文件大小:
- 如果文件小于 1024 字节,则未加密。
- 如果文件头部没有对应的魔数(magic number),则未加密。
大端序魔数如下:
0x43444546(文本形式为 CDEF),或0x49474546(文本形式为 IGEF)。
加密算法在每个加密文件的前 1024 字节中存放了一张码表。
同一本 EPUB 里的每个加密文件,从 0x3C 到 0x400(不含)这一段字节始终是相同的。
结合解密密钥,我们就能将文件还原出来。
具体实现代码在这里。 使用方式如下:
// https://github.com/MewX/contendo-viewer-decryptor/blob/b6af72d2a139770ec929725fc29d3f7251039894/Decrypt.java#L57-L68
net.zamasoft.reader.book.a.b randomAccessFile = new net.zamasoft.reader.book.a.b(file);
ArrayList<Byte> bytes = new ArrayList<>();
while (!randomAccessFile.isEOF()) {
byte b = (byte) randomAccessFile.read();
bytes.add(b);
}
assert randomAccessFile.length() == bytes.size();
byte[] bs = new byte[bytes.size()];
for (int ii = 0; ii < bs.length; ii++) {
bs[ii] = bytes.get(ii);
}
return bs;
验证结果
既然已经写好了用于解密加密文件的工具, 那就来验证一下到底行不行。
我拿自己买的那本书试了一下。解密前:

解密后:

注意:文本采用的是 UTF-8 编码,所以如果看到乱码先别慌。

再放另一个测试样本(使用了不同的解密密钥):
$ java Decrypt /mnt/r/comic.S /mnt/r/asdf2

一点心得
如果这篇文章帮到了你,或者你需要我义务帮忙解密你的电子书, 欢迎在下方留言。
至于我自己,以后买书之前一定会先确认清楚平台到底好不好用,再决定要不要掏钱。