├── .gitignore
├── KindleTool
├── .gitignore
├── kindle_main.h
├── convert.h
├── create.h
├── kindle_table.h
├── version.sh
├── kindletool.1
├── nettle_pem.c
├── Makefile
└── kindle_tool.h
├── .github
└── workflows
│ └── CI.yaml
├── Makefile
├── tools
├── mingw
│ ├── zlib-1.2.7-mingw-makefile-fix.patch
│ └── kindletool-mingw-build.sh
├── TableGen.lua
├── simple-linux-static-build.sh
├── kindle_model_sort.py
└── kindletool-static-build.sh
├── COMPILING
├── .clang-format
├── KindleTool.xcodeproj
└── project.pbxproj
├── README.md
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore Kdevelop related stuff
2 | *.kdev4
3 |
4 | # Ignore extra XCode related stuff
5 | KindleTool.xcodeproj/project.xcworkspace
6 | KindleTool.xcodeproj/xcuserdata
7 |
8 |
--------------------------------------------------------------------------------
/KindleTool/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore custom headers & libs searchpath
2 | includes/
3 | lib/
4 | # Ignore build output directories
5 | Release/
6 | Debug/
7 | Kindle/
8 | MinGW/
9 | # Ignore version tag
10 | version-inc
11 | VERSION
12 | # Ignore my Test directory
13 | Test/
14 |
--------------------------------------------------------------------------------
/.github/workflows/CI.yaml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | pull_request:
6 | workflow_dispatch:
7 |
8 | jobs:
9 | CI:
10 | runs-on: ubuntu-latest
11 | steps:
12 | - uses: actions/checkout@v6
13 | - name: Compile KindleTool
14 | run: |
15 | sudo apt-get install -y zlib1g-dev libarchive-dev nettle-dev
16 | make
17 | - uses: actions/upload-artifact@v5
18 | with:
19 | name: kindletool
20 | path: KindleTool/Release/kindletool
21 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # Toplevel Makefile, all the fun stuff happens in KindleTool/Makefile ;)
2 |
3 | default: all
4 |
5 | all:
6 | $(MAKE) -C KindleTool all
7 |
8 | kindle:
9 | $(MAKE) -C KindleTool kindle
10 |
11 | mingw:
12 | $(MAKE) -C KindleTool mingw
13 |
14 | debug:
15 | $(MAKE) -C KindleTool debug
16 |
17 | strip:
18 | $(MAKE) -C KindleTool strip
19 |
20 | clean:
21 | $(MAKE) -C KindleTool clean
22 |
23 | install:
24 | $(MAKE) -C KindleTool install
25 |
26 | format:
27 | clang-format -style=file -i KindleTool/*.c KindleTool/*.h
28 |
29 | .PHONY: default all kindle mingw debug strip clean install format
30 |
--------------------------------------------------------------------------------
/tools/mingw/zlib-1.2.7-mingw-makefile-fix.patch:
--------------------------------------------------------------------------------
1 | diff -Nuarp zlib-1.2.7-ori/win32/Makefile.gcc zlib-1.2.7/win32/Makefile.gcc
2 | --- zlib-1.2.7-ori/win32/Makefile.gcc 2012-05-02 20:17:58.000000000 +0200
3 | +++ zlib-1.2.7/win32/Makefile.gcc 2012-07-04 23:19:10.747624677 +0200
4 | @@ -41,15 +41,15 @@ SHARED_MODE=0
5 | #LOC = -DASMV
6 | #LOC = -DDEBUG -g
7 |
8 | -PREFIX =
9 | +PREFIX = x86_64-w64-mingw32-
10 | CC = $(PREFIX)gcc
11 | -CFLAGS = $(LOC) -O3 -Wall
12 | +CFLAGS = $(LOC) -O2 -march=x86-64 -mtune=generic -pipe -fomit-frame-pointer -Wall
13 |
14 | AS = $(CC)
15 | ASFLAGS = $(LOC) -Wall
16 |
17 | LD = $(CC)
18 | -LDFLAGS = $(LOC)
19 | +LDFLAGS = $(LOC) -Wl,-O1 -Wl,--as-needed
20 |
21 | AR = $(PREFIX)ar
22 | ARFLAGS = rcs
23 |
--------------------------------------------------------------------------------
/KindleTool/kindle_main.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** KindleTool, kindle_main.h
3 | **
4 | ** Copyright (C) 2011-2012 Yifan Lu
5 | ** Copyright (C) 2012-2023 NiLuJe
6 | ** Concept based on an original Python implementation by Igor Skochinsky & Jean-Yves Avenard,
7 | ** cf., http://www.mobileread.com/forums/showthread.php?t=63225
8 | **
9 | ** This program is free software: you can redistribute it and/or modify
10 | ** it under the terms of the GNU General Public License as published by
11 | ** the Free Software Foundation, either version 3 of the License, or
12 | ** (at your option) any later version.
13 | **
14 | ** This program is distributed in the hope that it will be useful,
15 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ** GNU General Public License for more details.
18 | **
19 | ** You should have received a copy of the GNU General Public License
20 | ** along with this program. If not, see .
21 | */
22 |
23 | #ifndef __KINDLETOOL_MAIN_H
24 | #define __KINDLETOOL_MAIN_H
25 |
26 | #include "kindle_tool.h"
27 |
28 | // Ugly globals.
29 | unsigned int kt_with_unknown_devcodes;
30 | const char* kt_pkg_metadata_dump;
31 | char kt_tempdir[PATH_MAX] = { 0 };
32 |
33 | static int kindle_print_help(const char*);
34 | static int kindle_print_version(const char*);
35 | static int kindle_deobfuscate_main(int, char**);
36 | static int kindle_obfuscate_main(int, char**);
37 | static int kindle_info_main(int, char**);
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/KindleTool/convert.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** KindleTool, convert.h
3 | **
4 | ** Copyright (C) 2011-2012 Yifan Lu
5 | ** Copyright (C) 2012-2023 NiLuJe
6 | ** Concept based on an original Python implementation by Igor Skochinsky & Jean-Yves Avenard,
7 | ** cf., http://www.mobileread.com/forums/showthread.php?t=63225
8 | **
9 | ** This program is free software: you can redistribute it and/or modify
10 | ** it under the terms of the GNU General Public License as published by
11 | ** the Free Software Foundation, either version 3 of the License, or
12 | ** (at your option) any later version.
13 | **
14 | ** This program is distributed in the hope that it will be useful,
15 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ** GNU General Public License for more details.
18 | **
19 | ** You should have received a copy of the GNU General Public License
20 | ** along with this program. If not, see .
21 | */
22 |
23 | #ifndef __KINDLETOOL_CONVERT_H
24 | #define __KINDLETOOL_CONVERT_H
25 |
26 | #include "kindle_tool.h"
27 |
28 | static const char* convert_magic_number(const char[MAGIC_NUMBER_LENGTH]);
29 |
30 | static char* to_base(int64_t, uint8_t, size_t);
31 |
32 | static int kindle_read_bundle_header(UpdateHeader*, FILE*);
33 | static int kindle_convert(FILE*, FILE*, FILE*, const bool, const bool, FILE*, char*, BundleHashAlgorithm*);
34 | static int kindle_convert_ota_update_v2(FILE*, FILE*, const bool, char*);
35 | static int kindle_convert_signature(UpdateHeader*, FILE*, FILE*);
36 | static int kindle_convert_ota_update(UpdateHeader*, FILE*, FILE*, const bool, char*);
37 | static int kindle_convert_recovery(UpdateHeader*, FILE*, FILE*, const bool, char*, const bool);
38 | static int kindle_convert_recovery_v2(FILE*, FILE*, const bool, char*);
39 | static int kindle_convert_component(FILE*, FILE*, const bool, char*);
40 |
41 | static int libarchive_extract(const char*, const char*);
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/COMPILING:
--------------------------------------------------------------------------------
1 | Recommended Compilation Directions
2 |
3 | Basically, you'll need a working toolchain, nettle, and libarchive >= 3.0.3 (with gzip support).
4 |
5 | If you don't want to bother, static binaries are available:
6 | here for the latest releases: http://www.mobileread.com/forums/showthread.php?t=187880
7 | and here for the latest development snapshots, which are most likely the builds you'll be interested in: http://www.mobileread.com/forums/showthread.php?t=225030
8 |
9 | To compile for Linux:
10 | 1) Install the required (development) dependencies in the appropriate manner for your distro (i.e., use your PMS).
11 | 1.5) For Debian/Ubuntu people: You'll need zlib1g-dev, libarchive-dev and nettle-dev
12 | 1.5) For Fedora people: You'll need zlib-devel, libarchive-devel and nettle-devel
13 | 1.5) For OpenSuse people: You'll need zlib-devel, libarchive-devel and libnettle-devel
14 | 2) Compile using "make" in the tool's directory
15 | 3) If you want to install it in /usr/local, run "make install". (I'd recommend using this through the checkinstall tool on Debian/Ubuntu).
16 | 2.5) If GCC throws a fit about libarchive, or if it fails to link with a bunch of undefined references to archive_* symbols, your libarchive version is too old.
17 | You'll have to build it manually (get the latest 3.x release from http://libarchive.github.com/).
18 | See https://github.com/NiLuJe/KindleTool/issues/1 for more details. Or try using the simple-linux-static-build.sh script in the tools folder.
19 |
20 | Fellow Gentoo users, there's a portage overlay over on https://github.com/NiLuJe/gentoo-kindletool, enjoy ;).
21 |
22 | To compile for OSX:
23 | 1) If you're using Homebrew, see https://github.com/NiLuJe/homebrew-kindletool
24 |
25 | To compile for Windows:
26 | Native)
27 | You can build a native version with a MinGW-w64 toolchain.
28 | On a native MinGW+MSYS toolchain, you'll probably have to tweak the Makefile, but it should handle a Linux cross toolchain properly with the mingw target ;).
29 | Check the tools/mingw directory for more details.
30 |
31 | Cygwin)
32 | 1) Get Cygwin
33 | 2) Install the required packages for a proper toolchain (gcc, binutils, autoconf, automake, libtool, make, ...)
34 | 3) Install the packages: zlib / zlib-devel, libarchive13 / libarchive-devel, libnettle4 / libnettle-devel, git, cmake, patch, pkg-config, libxml2-devel
35 | 5) Compile using "make" in the tool's directory
36 | 6) Install it by running "make install"
37 |
38 |
39 | ----
40 |
41 | If you need more complex examples, the various scripts found in the tools directory are what I personally use.
42 |
--------------------------------------------------------------------------------
/tools/TableGen.lua:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env luajit
2 | --[[
3 | Table generator for Amazon byte mangle, de-mangle algorithm.
4 | Output is to stdout, the result is the body of kindle_tool.h
5 |
6 | Each bit-wise operator used was tested in the commented examples.
7 | In lua the only data-type is double and the bitop package uses
8 | the 53 bit integer field of double as a 32 bit array.
9 | --]]
10 |
11 | local bit = require("bit")
12 | local band, bor, bxor = bit.band, bit.bor, bit.bxor
13 | local lshift, rshift, tohex = bit.lshift, bit.rshift, bit.tohex
14 |
15 | function printx (x)
16 | print("0x"..tohex(x))
17 | end
18 |
19 | function print2x (x) return "0x"..tohex(x, 2) end
20 |
21 | function col4 (w, x, y, z)
22 | return string.format('%s\t%s\t\t%s\t%s\n',
23 | print2x(w), print2x(x), print2x(y), print2x(z)) end
24 |
25 | -- printx(bit.band(0x12345678, 0x0f)) --> 0x00000008
26 | -- printx(bit.band(0x12345678, 0xf0)) --> 0x00000070
27 |
28 | -- printx(lshift(band(0x12345678, 0x0f), 4)) --> 0x00000080
29 | -- printx(rshift(band(0x12345678, 0xf0), 4)) --> 0x00000007
30 |
31 | -- printx(bor(rshift(band(0x12345678, 0xf0), 4), lshift(band(0x12345678, 0x0f), 4)))
32 | --> 0x00000087
33 |
34 | -- printx(bxor(bor(rshift(band(0x12345678, 0xf0), 4), lshift(band(0x12345678, 0x0f), 4)), 0x7A))
35 | --> 0x000000fd
36 |
37 | -- swap nibbles in a byte
38 | function swap_nibbles (x)
39 | return bor(rshift(band(x, 0xF0), 4), lshift(band(x, 0x0F), 4)) end
40 |
41 | -- obscure nibbles in a byte
42 | function obsc_nibbles (x, y) return bxor(swap_nibbles(x), y) end
43 |
44 | -- Input plain byte, return obscure byte
45 | function md_nibbles (x) return obsc_nibbles(x, 0x7A) end
46 |
47 | -- Input obscure byte, return plain byte
48 | function dm_nibbles (x) return obsc_nibbles(x, 0xA7) end
49 |
50 | md_tbl = { 0, 0, 0, 0, 0, 0, 0, 0 } -- start with eight elements, let double to 256
51 | dm_tbl = { 0, 0, 0, 0, 0, 0, 0, 0 } -- table only has to be re-allocated 5 times.
52 |
53 | for i = 0, 255, 1 do
54 | local md = md_nibbles(i)
55 | md_tbl[i] = md
56 | dm_tbl[md] = i -- a.k.a: dm_nibbles(md_nibbles(i))
57 | end
58 |
59 | local hdl = io.output() -- stdout
60 |
61 | --[[
62 | print('plain', 'obfuscated', 'dm-tbl', 'dm-func')
63 | for i = 0, 255, 1 do
64 | local md = md_tbl[i]
65 | hdl:write(col4(i, md, dm_tbl[md], dm_nibbles(md)))
66 | end
67 | ]]
68 |
69 | -- Header, plain to garbled
70 | hd_ptog = '/* index by plain, result garbled */\nstatic const uint8_t ptog[] = {\n'
71 | -- Header, garbled to plain
72 | hd_gtop = '\n/* index by garbled, result plain */\nstatic const uint8_t gtop[] = {\n'
73 |
74 | -- lines ('C' doesn't like trailing commas)
75 | lns = '\t%4s, %4s, %4s, %4s, %4s, %4s, %4s, %4s,\n'
76 | lnl = '\t%4s, %4s, %4s, %4s, %4s, %4s, %4s, %4s\n};\n'
77 |
78 | hdl:write(hd_ptog)
79 | for i = 0, 247, 8 do
80 | hdl:write(string.format(lns,
81 | print2x(md_tbl[ i ]), print2x(md_tbl[i+1]), print2x(md_tbl[i+2]), print2x(md_tbl[i+3]),
82 | print2x(md_tbl[i+4]), print2x(md_tbl[i+5]), print2x(md_tbl[i+6]), print2x(md_tbl[i+7])
83 | ))
84 | end
85 | hdl:write(string.format(lnl,
86 | print2x(md_tbl[248]), print2x(md_tbl[249]), print2x(md_tbl[250]), print2x(md_tbl[251]),
87 | print2x(md_tbl[252]), print2x(md_tbl[253]), print2x(md_tbl[254]), print2x(md_tbl[255])
88 | ))
89 |
90 | hdl:write(hd_gtop)
91 | for i = 0, 247, 8 do
92 | hdl:write(string.format(lns,
93 | print2x(dm_tbl[ i ]), print2x(dm_tbl[i+1]), print2x(dm_tbl[i+2]), print2x(dm_tbl[i+3]),
94 | print2x(dm_tbl[i+4]), print2x(dm_tbl[i+5]), print2x(dm_tbl[i+6]), print2x(dm_tbl[i+7])
95 | ))
96 | end
97 | hdl:write(string.format(lnl,
98 | print2x(dm_tbl[248]), print2x(dm_tbl[249]), print2x(dm_tbl[250]), print2x(dm_tbl[251]),
99 | print2x(dm_tbl[252]), print2x(dm_tbl[253]), print2x(dm_tbl[254]), print2x(dm_tbl[255])
100 | ))
101 |
102 | hdl:flush()
103 | hdl:close()
104 |
--------------------------------------------------------------------------------
/KindleTool/create.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** KindleTool, create.h
3 | **
4 | ** Copyright (C) 2011-2012 Yifan Lu
5 | ** Copyright (C) 2012-2023 NiLuJe
6 | ** Concept based on an original Python implementation by Igor Skochinsky & Jean-Yves Avenard,
7 | ** cf., http://www.mobileread.com/forums/showthread.php?t=63225
8 | **
9 | ** This program is free software: you can redistribute it and/or modify
10 | ** it under the terms of the GNU General Public License as published by
11 | ** the Free Software Foundation, either version 3 of the License, or
12 | ** (at your option) any later version.
13 | **
14 | ** This program is distributed in the hope that it will be useful,
15 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ** GNU General Public License for more details.
18 | **
19 | ** You should have received a copy of the GNU General Public License
20 | ** along with this program. If not, see .
21 | */
22 |
23 | #ifndef __KINDLETOOL_CREATE_H
24 | #define __KINDLETOOL_CREATE_H
25 |
26 | #include "kindle_tool.h"
27 |
28 | typedef struct
29 | {
30 | // NOTE: We resort to a nonstring (and non-portable, heh!) attribute because it's true, this isn't NULL terminated,
31 | // so this easily shuts up the many, many, GCC 8 strncpy warnings...
32 | // This is helpful in the few cases where we do want to keep using strncpy instead of memcpy,
33 | // because of its NULL-padding assurance.
34 | char magic_number[MAGIC_NUMBER_LENGTH] __attribute__((nonstring));
35 | BundleVersion version;
36 | struct rsa_private_key sign_pkey;
37 | uint64_t source_revision;
38 | uint64_t target_revision;
39 | uint32_t magic_1;
40 | uint32_t magic_2;
41 | uint32_t minor;
42 | uint16_t num_devices;
43 | Device* devices;
44 | Platform platform;
45 | Board board;
46 | uint32_t header_rev;
47 | CertificateNumber certificate_number;
48 | unsigned char optional;
49 | unsigned char critical;
50 | uint16_t num_meta;
51 | char** metastrings;
52 | } UpdateInformation;
53 |
54 | // This is modeled after libarchive's bsdtar...
55 | struct kttar
56 | {
57 | unsigned char* buff;
58 | size_t buff_size;
59 | char** to_sign_and_bundle_list;
60 | char** tweaked_to_sign_and_bundle_list;
61 | unsigned int sign_and_bundle_index;
62 | bool has_script;
63 | size_t tweak_pointer_index;
64 | };
65 |
66 | static const char* convert_bundle_version(BundleVersion);
67 |
68 | static struct rsa_private_key get_default_key(void);
69 | static int sign_file(FILE*, const struct rsa_private_key*, FILE*);
70 |
71 | static int metadata_filter(struct archive*, void*, struct archive_entry*);
72 | static int write_file(const struct kttar*, struct archive*, struct archive*, struct archive_entry*);
73 | static int write_entry(const struct kttar*, struct archive*, struct archive*, struct archive_entry*);
74 | static int copy_file_data_block(const struct kttar*, struct archive*, struct archive*, struct archive_entry*);
75 | static int create_from_archive_read_disk(struct kttar*,
76 | struct archive*,
77 | const char*,
78 | bool,
79 | const char*,
80 | const unsigned int);
81 |
82 | static int kindle_create_package_archive(const int,
83 | char**,
84 | const unsigned int,
85 | const struct rsa_private_key*,
86 | const unsigned int,
87 | const unsigned int);
88 | static int kindle_create(const UpdateInformation*, FILE*, FILE*, const bool);
89 | static int kindle_create_ota_update_v2(const UpdateInformation*, FILE*, FILE*, const bool);
90 | static int kindle_create_signature(const UpdateInformation*, FILE*, FILE*);
91 | static int kindle_create_ota_update(const UpdateInformation*, FILE*, FILE*, const bool);
92 | static int kindle_create_recovery(const UpdateInformation*, FILE*, FILE*, const bool);
93 | static int kindle_create_recovery_v2(const UpdateInformation*, FILE*, FILE*, const bool);
94 |
95 | #endif
96 |
--------------------------------------------------------------------------------
/KindleTool/kindle_table.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** KindleTool, kindle_table.h
3 | **
4 | ** Copyright (C) 2011-2012 Yifan Lu
5 | ** Copyright (C) 2012-2023 NiLuJe
6 | ** Concept based on an original Python implementation by Igor Skochinsky & Jean-Yves Avenard,
7 | ** cf., http://www.mobileread.com/forums/showthread.php?t=63225
8 | **
9 | ** This program is free software: you can redistribute it and/or modify
10 | ** it under the terms of the GNU General Public License as published by
11 | ** the Free Software Foundation, either version 3 of the License, or
12 | ** (at your option) any later version.
13 | **
14 | ** This program is distributed in the hope that it will be useful,
15 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ** GNU General Public License for more details.
18 | **
19 | ** You should have received a copy of the GNU General Public License
20 | ** along with this program. If not, see .
21 | */
22 |
23 | // NOTE: Full credit for this implementation goes to Michael S. Zick,
24 | // c.f., https://github.com/NiLuJe/KindleTool/pull/6 ;).
25 |
26 | /*
27 | Byte sized look-up tables that implement the Amazon mangle algorithm.
28 | The look-up tables where generated and tested by: tools/TableGen.lua
29 | */
30 |
31 | #ifndef __KINDLETOOL_TABLE_H
32 | #define __KINDLETOOL_TABLE_H
33 |
34 | #include "kindle_tool.h"
35 |
36 | /* index by plain, result garbled */
37 | static const uint8_t ptog[] = {
38 | 0x7a, 0x6a, 0x5a, 0x4a, 0x3a, 0x2a, 0x1a, 0x0a, 0xfa, 0xea, 0xda, 0xca, 0xba, 0xaa, 0x9a, 0x8a, 0x7b, 0x6b, 0x5b,
39 | 0x4b, 0x3b, 0x2b, 0x1b, 0x0b, 0xfb, 0xeb, 0xdb, 0xcb, 0xbb, 0xab, 0x9b, 0x8b, 0x78, 0x68, 0x58, 0x48, 0x38, 0x28,
40 | 0x18, 0x08, 0xf8, 0xe8, 0xd8, 0xc8, 0xb8, 0xa8, 0x98, 0x88, 0x79, 0x69, 0x59, 0x49, 0x39, 0x29, 0x19, 0x09, 0xf9,
41 | 0xe9, 0xd9, 0xc9, 0xb9, 0xa9, 0x99, 0x89, 0x7e, 0x6e, 0x5e, 0x4e, 0x3e, 0x2e, 0x1e, 0x0e, 0xfe, 0xee, 0xde, 0xce,
42 | 0xbe, 0xae, 0x9e, 0x8e, 0x7f, 0x6f, 0x5f, 0x4f, 0x3f, 0x2f, 0x1f, 0x0f, 0xff, 0xef, 0xdf, 0xcf, 0xbf, 0xaf, 0x9f,
43 | 0x8f, 0x7c, 0x6c, 0x5c, 0x4c, 0x3c, 0x2c, 0x1c, 0x0c, 0xfc, 0xec, 0xdc, 0xcc, 0xbc, 0xac, 0x9c, 0x8c, 0x7d, 0x6d,
44 | 0x5d, 0x4d, 0x3d, 0x2d, 0x1d, 0x0d, 0xfd, 0xed, 0xdd, 0xcd, 0xbd, 0xad, 0x9d, 0x8d, 0x72, 0x62, 0x52, 0x42, 0x32,
45 | 0x22, 0x12, 0x02, 0xf2, 0xe2, 0xd2, 0xc2, 0xb2, 0xa2, 0x92, 0x82, 0x73, 0x63, 0x53, 0x43, 0x33, 0x23, 0x13, 0x03,
46 | 0xf3, 0xe3, 0xd3, 0xc3, 0xb3, 0xa3, 0x93, 0x83, 0x70, 0x60, 0x50, 0x40, 0x30, 0x20, 0x10, 0x00, 0xf0, 0xe0, 0xd0,
47 | 0xc0, 0xb0, 0xa0, 0x90, 0x80, 0x71, 0x61, 0x51, 0x41, 0x31, 0x21, 0x11, 0x01, 0xf1, 0xe1, 0xd1, 0xc1, 0xb1, 0xa1,
48 | 0x91, 0x81, 0x76, 0x66, 0x56, 0x46, 0x36, 0x26, 0x16, 0x06, 0xf6, 0xe6, 0xd6, 0xc6, 0xb6, 0xa6, 0x96, 0x86, 0x77,
49 | 0x67, 0x57, 0x47, 0x37, 0x27, 0x17, 0x07, 0xf7, 0xe7, 0xd7, 0xc7, 0xb7, 0xa7, 0x97, 0x87, 0x74, 0x64, 0x54, 0x44,
50 | 0x34, 0x24, 0x14, 0x04, 0xf4, 0xe4, 0xd4, 0xc4, 0xb4, 0xa4, 0x94, 0x84, 0x75, 0x65, 0x55, 0x45, 0x35, 0x25, 0x15,
51 | 0x05, 0xf5, 0xe5, 0xd5, 0xc5, 0xb5, 0xa5, 0x95, 0x85
52 | };
53 |
54 | /* index by garbled, result plain */
55 | static const uint8_t gtop[] = {
56 | 0xa7, 0xb7, 0x87, 0x97, 0xe7, 0xf7, 0xc7, 0xd7, 0x27, 0x37, 0x07, 0x17, 0x67, 0x77, 0x47, 0x57, 0xa6, 0xb6, 0x86,
57 | 0x96, 0xe6, 0xf6, 0xc6, 0xd6, 0x26, 0x36, 0x06, 0x16, 0x66, 0x76, 0x46, 0x56, 0xa5, 0xb5, 0x85, 0x95, 0xe5, 0xf5,
58 | 0xc5, 0xd5, 0x25, 0x35, 0x05, 0x15, 0x65, 0x75, 0x45, 0x55, 0xa4, 0xb4, 0x84, 0x94, 0xe4, 0xf4, 0xc4, 0xd4, 0x24,
59 | 0x34, 0x04, 0x14, 0x64, 0x74, 0x44, 0x54, 0xa3, 0xb3, 0x83, 0x93, 0xe3, 0xf3, 0xc3, 0xd3, 0x23, 0x33, 0x03, 0x13,
60 | 0x63, 0x73, 0x43, 0x53, 0xa2, 0xb2, 0x82, 0x92, 0xe2, 0xf2, 0xc2, 0xd2, 0x22, 0x32, 0x02, 0x12, 0x62, 0x72, 0x42,
61 | 0x52, 0xa1, 0xb1, 0x81, 0x91, 0xe1, 0xf1, 0xc1, 0xd1, 0x21, 0x31, 0x01, 0x11, 0x61, 0x71, 0x41, 0x51, 0xa0, 0xb0,
62 | 0x80, 0x90, 0xe0, 0xf0, 0xc0, 0xd0, 0x20, 0x30, 0x00, 0x10, 0x60, 0x70, 0x40, 0x50, 0xaf, 0xbf, 0x8f, 0x9f, 0xef,
63 | 0xff, 0xcf, 0xdf, 0x2f, 0x3f, 0x0f, 0x1f, 0x6f, 0x7f, 0x4f, 0x5f, 0xae, 0xbe, 0x8e, 0x9e, 0xee, 0xfe, 0xce, 0xde,
64 | 0x2e, 0x3e, 0x0e, 0x1e, 0x6e, 0x7e, 0x4e, 0x5e, 0xad, 0xbd, 0x8d, 0x9d, 0xed, 0xfd, 0xcd, 0xdd, 0x2d, 0x3d, 0x0d,
65 | 0x1d, 0x6d, 0x7d, 0x4d, 0x5d, 0xac, 0xbc, 0x8c, 0x9c, 0xec, 0xfc, 0xcc, 0xdc, 0x2c, 0x3c, 0x0c, 0x1c, 0x6c, 0x7c,
66 | 0x4c, 0x5c, 0xab, 0xbb, 0x8b, 0x9b, 0xeb, 0xfb, 0xcb, 0xdb, 0x2b, 0x3b, 0x0b, 0x1b, 0x6b, 0x7b, 0x4b, 0x5b, 0xaa,
67 | 0xba, 0x8a, 0x9a, 0xea, 0xfa, 0xca, 0xda, 0x2a, 0x3a, 0x0a, 0x1a, 0x6a, 0x7a, 0x4a, 0x5a, 0xa9, 0xb9, 0x89, 0x99,
68 | 0xe9, 0xf9, 0xc9, 0xd9, 0x29, 0x39, 0x09, 0x19, 0x69, 0x79, 0x49, 0x59, 0xa8, 0xb8, 0x88, 0x98, 0xe8, 0xf8, 0xc8,
69 | 0xd8, 0x28, 0x38, 0x08, 0x18, 0x68, 0x78, 0x48, 0x58
70 | };
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/.clang-format:
--------------------------------------------------------------------------------
1 | ---
2 | Language: Cpp
3 | # BasedOnStyle: Mozilla
4 | AccessModifierOffset: -4
5 | AlignAfterOpenBracket: Align
6 | AlignArrayOfStructures: Right
7 | AlignConsecutiveAssignments:
8 | Enabled: true
9 | AcrossComments: true
10 | AlignCompound: true
11 | PadOperators: false
12 | AlignConsecutiveBitFields: AcrossComments
13 | AlignConsecutiveDeclarations:
14 | Enabled: true
15 | AcrossComments: true
16 | AlignFunctionPointers: false
17 | AlignConsecutiveMacros: AcrossComments
18 | AlignEscapedNewlines: Right
19 | AlignOperands: Align
20 | AlignTrailingComments:
21 | Kind: Always
22 | OverEmptyLines: 0
23 | AllowAllArgumentsOnNextLine: true
24 | AllowAllParametersOfDeclarationOnNextLine: false
25 | AllowBreakBeforeNoexceptSpecifier: OnlyWithParen
26 | AllowShortBlocksOnASingleLine: Empty
27 | AllowShortCaseLabelsOnASingleLine: false
28 | AllowShortCompoundRequirementOnASingleLine: true
29 | AllowShortEnumsOnASingleLine: false
30 | AllowShortFunctionsOnASingleLine: None
31 | AllowShortIfStatementsOnASingleLine: Never
32 | AllowShortLambdasOnASingleLine: Empty
33 | AllowShortLoopsOnASingleLine: false
34 | AlwaysBreakAfterDefinitionReturnType: TopLevel
35 | AlwaysBreakAfterReturnType: AllDefinitions
36 | AlwaysBreakBeforeMultilineStrings: true
37 | AlwaysBreakTemplateDeclarations: true
38 | AttributeMacros: ['__unused']
39 | BinPackArguments: false
40 | BinPackParameters: false
41 | BitFieldColonSpacing: Both
42 | BreakBeforeBraces: Custom
43 | BraceWrapping:
44 | AfterCaseLabel: false
45 | AfterClass: true
46 | AfterControlStatement: Never
47 | AfterEnum: true
48 | AfterFunction: true
49 | AfterNamespace: false
50 | AfterObjCDeclaration: false
51 | AfterStruct: true
52 | AfterUnion: true
53 | AfterExternBlock: false
54 | BeforeCatch: false
55 | BeforeElse: false
56 | BeforeLambdaBody: false
57 | BeforeWhile: false
58 | IndentBraces: false
59 | SplitEmptyFunction: true
60 | SplitEmptyRecord: false
61 | SplitEmptyNamespace: true
62 | BracedInitializerIndentWidth: 4
63 | BreakAdjacentStringLiterals: true
64 | BreakAfterAttributes: Never
65 | BreakAfterJavaFieldAnnotations: false
66 | BreakArrays: false
67 | BreakBeforeBinaryOperators: None
68 | BreakBeforeInheritanceComma: false
69 | BreakBeforeConceptDeclarations: Allowed
70 | BreakBeforeInlineASMColon: OnlyMultiline
71 | BreakBeforeTernaryOperators: true
72 | BreakConstructorInitializersBeforeComma: false
73 | BreakConstructorInitializers: AfterColon
74 | BreakInheritanceList: AfterColon
75 | BreakStringLiterals: false
76 | ColumnLimit: 122
77 | CommentPragmas: '^ IWYU pragma:'
78 | CompactNamespaces: false
79 | ConstructorInitializerIndentWidth: 4
80 | ContinuationIndentWidth: 4
81 | Cpp11BracedListStyle: false
82 | DeriveLineEnding: false
83 | DerivePointerAlignment: false
84 | DisableFormat: false
85 | EmptyLineAfterAccessModifier: Always
86 | EmptyLineBeforeAccessModifier: Always
87 | ExperimentalAutoDetectBinPacking: false
88 | FixNamespaceComments: true
89 | ForEachMacros:
90 | - foreach
91 | - Q_FOREACH
92 | - BOOST_FOREACH
93 | IncludeBlocks: Preserve
94 | IncludeCategories:
95 | - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
96 | Priority: 2
97 | SortPriority: 0
98 | CaseSensitive: true
99 | - Regex: '^(<|"(gtest|gmock|isl|json)/)'
100 | Priority: 3
101 | SortPriority: 0
102 | - Regex: '.*'
103 | Priority: 1
104 | SortPriority: 0
105 | IncludeIsMainRegex: '(_test)?$'
106 | IncludeIsMainSourceRegex: ''
107 | IndentAccessModifiers: false
108 | IndentCaseBlocks: false
109 | IndentCaseLabels: true
110 | IndentExternBlock: NoIndent
111 | IndentGotoLabels: false
112 | IndentPPDirectives: AfterHash
113 | IndentRequiresClause: true
114 | IndentWidth: 8
115 | IndentWrappedFunctionNames: true
116 | # NOTE: New as of Clang 15, may still misbehave
117 | InsertBraces: true
118 | InsertNewlineAtEOF: true
119 | InsertTrailingCommas: None
120 | # C++ only, which essentially means nope, because C headers ;).
121 | #IntegerLiteralSeparator:
122 | # Binary: 8
123 | #JavaImportGroups: ['com.example', 'com', 'org']
124 | JavaScriptQuotes: Double
125 | JavaScriptWrapImports: true
126 | KeepEmptyLinesAtEOF: false
127 | KeepEmptyLinesAtTheStartOfBlocks: false
128 | LambdaBodyIndentation: Signature
129 | LineEnding: DeriveLF
130 | MacroBlockBegin: ''
131 | MacroBlockEnd: ''
132 | #Macros:
133 | MaxEmptyLinesToKeep: 1
134 | NamespaceIndentation: All
135 | #NamespaceMacros: ['TESTSUITE']
136 | ObjCBinPackProtocolList: Auto
137 | ObjCBlockIndentWidth: 8
138 | ObjCBreakBeforeNestedBlockParam: true
139 | #ObjCPropertyAttributeOrder
140 | ObjCSpaceAfterProperty: true
141 | ObjCSpaceBeforeProtocolList: false
142 | PPIndentWidth: -1
143 | PackConstructorInitializers: NextLine
144 | PenaltyBreakAssignment: 2
145 | PenaltyBreakBeforeFirstCallParameter: 19
146 | PenaltyBreakComment: 300
147 | PenaltyBreakFirstLessLess: 120
148 | #PenaltyBreakOpenParenthesis:
149 | #PenaltyBreakScopeResolution:
150 | PenaltyBreakString: 1000
151 | PenaltyBreakTemplateDeclaration: 10
152 | PenaltyExcessCharacter: 1000000
153 | PenaltyIndentedWhitespace: 0
154 | PenaltyReturnTypeOnItsOwnLine: 200
155 | PointerAlignment: Left
156 | # NOTE: New as of Clang 14, may still misbehave (also currently takes an inordinate amount of time)
157 | #QualifierAlignment: Left
158 | # NOTE: Err, not actually in 15.0.0 :?
159 | #QualifierOrder: ['inline', 'static', 'volatile', 'constexpr', 'const', 'type', 'restrict']
160 | #RawStringFormats:
161 | ReferenceAlignment: Pointer
162 | ReflowComments: false
163 | RemoveBracesLLVM: false
164 | # NOTE: MultipleParentheses might be fun, but may misbehave
165 | RemoveParentheses: Leave
166 | RemoveSemicolon: true
167 | RequiresClausePosition: WithPreceding
168 | RequiresExpressionIndentation: OuterScope
169 | # NOTE: Nice in theory, but there can be exceptions in practice ;).
170 | SeparateDefinitionBlocks: Leave
171 | ShortNamespaceLines: 1
172 | SkipMacroDefinitionBody: false
173 | SortIncludes: CaseSensitive
174 | SortJavaStaticImport: Before
175 | SortUsingDeclarations: LexicographicNumeric
176 | SpaceAfterCStyleCast: true
177 | SpaceAfterLogicalNot: false
178 | SpaceAfterTemplateKeyword: false
179 | SpaceAroundPointerQualifiers: Default
180 | SpaceBeforeAssignmentOperators: true
181 | SpaceBeforeCaseColon: false
182 | SpaceBeforeCpp11BracedList: false
183 | SpaceBeforeCtorInitializerColon: true
184 | SpaceBeforeInheritanceColon: true
185 | SpaceBeforeJsonColon: false
186 | SpaceBeforeParens: ControlStatements
187 | SpaceBeforeRangeBasedForLoopColon: true
188 | SpaceBeforeSquareBrackets: false
189 | SpaceInEmptyBlock: false
190 | SpacesBeforeTrailingComments: 4
191 | SpacesInAngles: Never
192 | SpacesInCStyleCastParentheses: false
193 | SpacesInConditionalStatement: false
194 | SpacesInContainerLiterals: true
195 | SpacesInLineCommentPrefix:
196 | Minimum: 1
197 | Maximum: -1
198 | SpacesInParens: Never
199 | SpacesInSquareBrackets: false
200 | Standard: Latest
201 | StatementAttributeLikeMacros: ['emit']
202 | StatementMacros:
203 | - Q_UNUSED
204 | - QT_REQUIRE_VERSION
205 | TabWidth: 8
206 | #TypeNames: []
207 | TypenameMacros: ['STACK_OF', 'LIST_ENTRY']
208 | UseTab: ForContinuationAndIndentation
209 | VerilogBreakBetweenInstancePorts: true
210 | #WhitespaceSensitiveMacros: ['STRINGIZE', 'PP_STRINGIZE']
211 | ...
212 |
213 |
--------------------------------------------------------------------------------
/tools/simple-linux-static-build.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | #
5 | # Simple static build.
6 | # (Only libarchive & nettle will be built/statically linked).
7 | #
8 | ##
9 |
10 | OSTYPE="$(uname -s)"
11 | ARCH="$(uname -m)"
12 |
13 | ## Linux!
14 | Build_Linux() {
15 | echo "* Preparing a static KindleTool build on Linux . . ."
16 | unset CPPFLAGS # Let the Makefile take care of it ;).
17 | export CFLAGS="-march=native -pipe -O2 -fomit-frame-pointer"
18 | export CXXFLAGS="-march=native -pipe -O2 -fomit-frame-pointer"
19 | if [[ "${ARCH}" == "x86_64" ]] ; then
20 | export CFLAGS="${CFLAGS} -frename-registers -fweb"
21 | export CXXFLAGS="${CXXFLAGS} -frename-registers -fweb"
22 | GMPABI="64"
23 | else
24 | GMPABI="32"
25 | fi
26 |
27 | GMP_VER="6.2.1"
28 | GMP_DIR="gmp-${GMP_VER%a}"
29 | NETTLE_VER="3.6"
30 | NETTLE_DIR="nettle-${NETTLE_VER}"
31 | LIBARCHIVE_VER="3.5.0"
32 | LIBARCHIVE_DIR="libarchive-${LIBARCHIVE_VER}"
33 |
34 | # Make sure we're up to date
35 | git pull
36 |
37 | # Get out of our git tree
38 | cd ../..
39 |
40 | KT_SYSROOT="${PWD}/kt-sysroot-lin-${ARCH}"
41 | # NOTE: Use -isystem so that gmp doesn't do crazy stuff...
42 | export CPPFLAGS="-isystem${KT_SYSROOT}/include"
43 | export LDFLAGS="-L${KT_SYSROOT}/lib -Wl,-O1 -Wl,--as-needed"
44 |
45 | BASE_PKG_CONFIG_PATH="${KT_SYSROOT}/lib/pkgconfig"
46 | BASE_PKG_CONFIG_LIBDIR="${KT_SYSROOT}/lib/pkgconfig"
47 | export PKG_CONFIG_DIR=
48 | export PKG_CONFIG_PATH="${BASE_PKG_CONFIG_PATH}"
49 | export PKG_CONFIG_LIBDIR="${BASE_PKG_CONFIG_LIBDIR}"
50 |
51 | # GMP
52 | if [[ ! -d "${GMP_DIR}" ]] ; then
53 | echo "* Building ${GMP_DIR} . . ."
54 | echo ""
55 | if [[ ! -f "./${GMP_DIR}.tar.xz" ]] ; then
56 | wget -O "./${GMP_DIR}.tar.xz" "https://gmplib.org/download/gmp/${GMP_DIR}.tar.xz"
57 | fi
58 | tar -xvJf ./${GMP_DIR}.tar.xz
59 | cd ${GMP_DIR}
60 | autoreconf -fi
61 | libtoolize
62 | ./configure ABI=${GMPABI} --prefix="${KT_SYSROOT}" --enable-static --disable-shared --disable-cxx
63 | make -j2
64 | make install
65 | cd ..
66 | fi
67 |
68 | # nettle
69 | if [[ "${USE_STABLE_NETTLE}" == "true" ]] ; then
70 | if [[ ! -d "${NETTLE_DIR}" ]] ; then
71 | echo "* Building ${NETTLE_DIR} . . ."
72 | echo ""
73 | if [[ ! -f "./${NETTLE_DIR}.tar.gz" ]] ; then
74 | wget -O "./${NETTLE_DIR}.tar.gz" "http://www.lysator.liu.se/~nisse/archive/${NETTLE_DIR}.tar.gz"
75 | fi
76 | tar -xvzf ./${NETTLE_DIR}.tar.gz
77 | cd ${NETTLE_DIR}
78 | sed -e '/CFLAGS=/s: -ggdb3::' -e 's/solaris\*)/sunldsolaris*)/' -i configure.ac
79 | sed -i '/SUBDIRS/s/testsuite examples//' Makefile.in
80 | autoreconf -fi
81 | ./configure --prefix="${KT_SYSROOT}" --libdir="${KT_SYSROOT}/lib" --enable-static --disable-shared --enable-public-key --disable-openssl --disable-documentation
82 | make -j2
83 | make install
84 | cd ..
85 | fi
86 | else
87 | # Build from git to benefit from the more x86_64 friendly API changes
88 | if [[ ! -d "nettle-git" ]] ; then
89 | echo "* Building nettle . . ."
90 | echo ""
91 | git clone https://git.lysator.liu.se/nettle/nettle.git nettle-git
92 | cd nettle-git
93 | sed -e '/CFLAGS=/s: -ggdb3::' -e 's/solaris\*)/sunldsolaris*)/' -i configure.ac
94 | sed -i '/SUBDIRS/s/testsuite examples//' Makefile.in
95 | sh ./.bootstrap
96 | ./configure --prefix="${KT_SYSROOT}" --libdir="${KT_SYSROOT}/lib" --enable-static --disable-shared --enable-public-key --disable-openssl --disable-documentation
97 | make -j2
98 | make install
99 | cd ..
100 | fi
101 | fi
102 |
103 | # libarchive
104 | if [[ "${USE_STABLE_LIBARCHIVE}" == "true" ]] ; then
105 | if [[ ! -d "${LIBARCHIVE_DIR}" ]] ; then
106 | echo "* Building ${LIBARCHIVE_DIR} . . ."
107 | echo ""
108 | if [[ ! -f "./${LIBARCHIVE_DIR}.tar.gz" ]] ; then
109 | wget -O "./${LIBARCHIVE_DIR}.tar.gz" "http://github.com/libarchive/libarchive/archive/v${LIBARCHIVE_VER}.tar.gz"
110 | fi
111 | tar -xvzf ./${LIBARCHIVE_DIR}.tar.gz
112 | cd ${LIBARCHIVE_DIR}
113 | export ac_cv_header_ext2fs_ext2_fs_h=0
114 | ./build/autogen.sh
115 | ./configure --prefix="${KT_SYSROOT}" --enable-static --disable-shared --disable-xattr --disable-acl --with-zlib --without-bz2lib --without-lzmadec --without-iconv --without-lzma --without-nettle --without-openssl --without-expat --without-xml2
116 | make -j2
117 | make install
118 | unset ac_cv_header_ext2fs_ext2_fs_h
119 | cd ..
120 | fi
121 | else
122 | if [[ ! -d "libarchive-git" ]] ; then
123 | echo "* Building libarchive . . ."
124 | echo ""
125 | git clone https://github.com/libarchive/libarchive.git libarchive-git
126 | cd libarchive-git
127 | # Kill -Werror, git master doesn't always build with it...
128 | sed -e 's/-Werror //' -i ./Makefile.am
129 | export ac_cv_header_ext2fs_ext2_fs_h=0
130 | ./build/autogen.sh
131 | ./configure --prefix="${KT_SYSROOT}" --enable-static --disable-shared --disable-xattr --disable-acl --with-zlib --without-bz2lib --without-lzmadec --without-iconv --without-lzma --without-nettle --without-openssl --without-expat --without-xml2 -without-lz4
132 | make -j2
133 | make install
134 | unset ac_cv_header_ext2fs_ext2_fs_h
135 | cd ..
136 | fi
137 | fi
138 |
139 | # Build KT package credits
140 | cat > CREDITS << EOF
141 | * kindletool:
142 |
143 | KindleTool, Copyright (C) 2011-2012 Yifan Lu & Copyright (C) 2012-2023 NiLuJe, licensed under the GNU General Public License version 3+ (http://www.gnu.org/licenses/gpl.html).
144 | (https://github.com/NiLuJe/KindleTool/)
145 |
146 | |
147 | |-> libarchive, Copyright (C) Tim Kientzle, licensed under the New BSD License (http://www.opensource.org/licenses/bsd-license.php)
148 | | (http://libarchive.github.com/)
149 | |
150 | |-> GMP, GNU MP Library, Copyright 1991-2018 Free Software Foundation, Inc.,
151 | | licensed under the GNU Lesser General Public License version 3+ (http://www.gnu.org/licenses/lgpl.html).
152 | | (http://gmplib.org/)
153 | |
154 | \`-> nettle, Copyright (C) 2001-2018 Niels Möller,
155 | licensed under the GNU Lesser General Public License version 2.1+ (https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
156 | (http://www.lysator.liu.se/~nisse/nettle)
157 | EOF
158 |
159 | # KindleTool
160 | echo "* Building KindleTool . . ."
161 | echo ""
162 | cd KindleTool/KindleTool
163 | rm -rf lib includes
164 | make clean
165 | make strip
166 |
167 | # Package it
168 | git log --stat --graph > ../../ChangeLog
169 | ./version.sh PMS STATIC
170 | VER_FILE="VERSION"
171 | VER_CURRENT="$(<${VER_FILE})"
172 | # Strip the git commit
173 | REV="${VER_CURRENT%%-*}"
174 | #REV="${VER_CURRENT}"
175 | cd ../..
176 | cp -v KindleTool/KindleTool/Release/kindletool ./kindletool
177 | cp -v KindleTool/README.md ./README
178 | # Quick! Markdown => plaintext
179 | sed -si 's///g;s/<\/b>//g;s///g;s/<\/i>//g;s/<//g;s/&/&/g;s/^* / /g;s/*//g;s/>> /\t/g;s/^> / /g;s/^## //g;s/### //g;s/\t/ /g;s/^\([[:digit:]]\)\./ \1)/g;s/^#.*$//;s/[[:blank:]]*$//g' README
180 | cp -v KindleTool/KindleTool/kindletool.1 ./kindletool.1
181 | mv -v KindleTool/KindleTool/VERSION ./VERSION
182 | tar -cvzf "kindletool-${REV}-linux-${ARCH}.tar.gz" kindletool CREDITS README kindletool.1 ChangeLog VERSION
183 | rm -f kindletool CREDITS README kindletool.1 ChangeLog VERSION
184 | }
185 |
186 | # Main
187 | case "${OSTYPE}" in
188 | "Linux" )
189 | Build_Linux
190 | ;;
191 | * )
192 | echo "Unknown OS: ${OSTYPE}"
193 | exit 1
194 | ;;
195 | esac
196 |
--------------------------------------------------------------------------------
/KindleTool/version.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Make sure we put our stuff in the proper directory (ie. the same one as this script)
4 | KT_DIR="${0%/*}"
5 |
6 | # Build a make include with, among other things, our version tag, straight from git (heavily inspired from git's GIT-VERSION-GEN)
7 | VER_FILE="${KT_DIR}/version-inc"
8 | VERSION_FILE="${KT_DIR}/VERSION"
9 |
10 | # Fallback version
11 | FALLBACK_VER="v1.6.5-GIT"
12 |
13 | # Apparently, bsdmake hates me, so, get uname's output from here
14 | UNAME="$(uname -s)"
15 |
16 | # Used to add a Linux like user@host compile-time tag
17 | COMPILE_BY="$(whoami | sed 's/\\/\\\\/')"
18 |
19 | case "${UNAME}" in
20 | CYGWIN* )
21 | # Cygwin's version of hostname doesn't handle the -s flag...
22 | COMPILE_HOST="$(hostname)"
23 | ;;
24 | * )
25 | # We want the short hostname, OS X defaults to fqdn...
26 | COMPILE_HOST="$(hostname -s)"
27 | ;;
28 | esac
29 |
30 | # Check libarchive's version and get the proper CPP/LDFLAGS via pkg-config, to make sure we pickup the correct libarchive version
31 | # NOTE: On OS X, we don't tweak PKG_CONFIG_PATH="/usr/local/opt/libarchive/lib/pkgconfig" manually,
32 | # because we don't want to override what Homebrew & our static build scripts do. The Makefile should use sane defaults as fallback.
33 | if pkg-config --atleast-version=3.0.3 libarchive ; then
34 | HAS_PC_LIBARCHIVE="true"
35 | PC_LIBARCHIVE_CPPFLAGS="$(pkg-config libarchive --cflags-only-I)"
36 | PC_LIBARCHIVE_LDFLAGS="$(pkg-config libarchive --libs-only-L)"
37 | # We need to pickup Libs.private for MingW builds...
38 | if [[ "${2}" == "STATIC" ]] ; then
39 | PC_LIBARCHIVE_LIBS="$(pkg-config libarchive --libs-only-l --libs-only-other --static)"
40 | else
41 | PC_LIBARCHIVE_LIBS="$(pkg-config libarchive --libs-only-l --libs-only-other)"
42 | fi
43 | else
44 | HAS_PC_LIBARCHIVE="false"
45 | PC_LIBARCHIVE_CPPFLAGS=""
46 | PC_LIBARCHIVE_LDFLAGS=""
47 | PC_LIBARCHIVE_LIBS=""
48 | echo "**!** @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ **!**"
49 | echo "**!** @ Couldn't find libarchive >= 3.0.3 via pkg-config, don't be surprised if the build fails! @ **!**"
50 | echo "**!** @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ **!**"
51 | fi
52 |
53 | # Check for a recent nettle version (Note that nettle >= 3.4 is preferred, especially on 64bits hosts)...
54 | if pkg-config --atleast-version=2.6 nettle ; then
55 | HAS_PC_NETTLE="true"
56 | # Check for hogweed, since we need it, and static, to properly pull in gmp
57 | PC_NETTLE_CPPFLAGS="$(pkg-config hogweed --cflags-only-I --static)"
58 | PC_NETTLE_LDFLAGS="$(pkg-config hogweed --libs-only-L --static)"
59 | PC_NETTLE_LIBS="$(pkg-config hogweed --libs-only-l --libs-only-other --static)"
60 | # Export the nettle version since there is no built-in way to get it at buildtime...
61 | PC_NETTLE_VERSION="$(pkg-config --modversion nettle)"
62 | else
63 | HAS_PC_NETTLE="false"
64 | PC_NETTLE_CPPFLAGS=""
65 | PC_NETTLE_LDFLAGS=""
66 | PC_NETTLE_LIBS=""
67 | PC_NETTLE_VERSION=""
68 | echo "**!** @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ **!**"
69 | echo "**!** @ Couldn't find nettle >= 2.6 via pkg-config, don't be surprised if the build fails! @ **!**"
70 | echo "**!** @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ **!**"
71 | fi
72 |
73 | if [[ "${UNAME}" == "Linux" ]] ; then
74 | # Also check the distro name, we'll use pkg-config's cflags in the Makefile on every distro out there except Gentoo, in order
75 | # to link against the correct libarchive version on distros where libarchive-2 and libarchive-3 can coexist (Debian/Ubuntu, for example).
76 | # NOTE: I'm fully aware that lsb_release is not installed/properly setup by default on every distro,
77 | # but the only distro on which the Makefile expects this to be accurate is Gentoo, so that should cover it ;).
78 | if [[ -f /etc/lsb-release ]] ; then
79 | . /etc/lsb-release
80 | else
81 | if [[ -f /etc/gentoo-release ]] ; then
82 | # Make sure we detect Gentoo, even if sys-apps/lsb-release isn't installed
83 | DISTRIB_ID="Gentoo"
84 | else
85 | DISTRIB_ID="Linux"
86 | fi
87 | fi
88 | elif [[ "${UNAME}" == "Darwin" ]] ; then
89 | DISTRIB_ID="Mac OS X $(sw_vers -productVersion)"
90 | else
91 | # Cygwin?
92 | DISTRIB_ID="${UNAME}"
93 | fi
94 |
95 | # If we don't have git installed (why, oh why would you do that? :D), just use the fallback
96 | if ! git help &>/dev/null ; then
97 | echo "${FALLBACK_VER}" > "${VERSION_FILE}"
98 | fi
99 |
100 | # If we have a VERSION file, just use that (that's useful for package managers)
101 | # Otherwise, and if we have a proper git repo, use git (unless we asked for a new VERSION file)!
102 | if [[ -f "${VERSION_FILE}" ]] && [[ "${1}" != "PMS" ]] ; then
103 | VER="$(< "${VERSION_FILE}")"
104 | elif [[ -z "${VER}" && -d "${GIT_DIR:-${KT_DIR}/../.git}" || -f "${KT_DIR}/../.git" ]] ; then
105 | # Get a properly formatted version string from our latest tag
106 | VER="$(git describe --match "v[0-9]*" HEAD 2>/dev/null)"
107 | # Or from the first commit (provided we manually tagged $(git rev-list --max-parents=0 HEAD) as TAIL, which we did)
108 | #VER="$(git describe --match TAIL 2>/dev/null)"
109 | case "$VER" in
110 | v[0-9]*)
111 | # Check if our working directory is dirty
112 | git update-index -q --refresh
113 | # Not sure I understand the details, but this helps to avoid ending up with a dirty tag when building through Homebrew...
114 | if [[ -n "${GIT_DIR}" ]] ; then
115 | [[ -z "$(git diff-index --name-only HEAD -m --relative=KindleTool --)" ]] || VER="${VER}-dirty"
116 | else
117 | [[ -z "$(git diff-index --name-only HEAD --)" ]] || VER="${VER}-dirty"
118 | fi
119 | # - => .
120 | #VER=${VER//-/.}
121 | # - => ., but only the first (rev since tag)
122 | VER=${VER/-/.}
123 | ;;
124 | TAIL*)
125 | git update-index -q --refresh
126 | # Same thing as before, special case GIT_DIR...
127 | if [[ -n "${GIT_DIR}" ]] ; then
128 | [[ -z "$(git diff-index --name-only HEAD -m --relative=KindleTool --)" ]] || VER="${VER}-dirty"
129 | else
130 | [[ -z "$(git diff-index --name-only HEAD --)" ]] || VER="${VER}-dirty"
131 | fi
132 | # - => .
133 | #VER=${VER//-/.}
134 | # TAIL- => r (ala SVN)
135 | VER="${VER//TAIL-/r}"
136 | # Technically, we get the number of commits *after* TAIL, so, effectively, TAIL is r0, not r1 like in SVN.
137 | # Tweak the output some more to fake that :).
138 | # Strip everything after the first dash
139 | REV="${VER%%-*}"
140 | # Strip the first char (r)
141 | REV="${REV:1}"
142 | # Fake our rev number
143 | FREV="$(( REV + 1 ))"
144 | # NOTE: In our case, another cheap way to get this commit count would be via $(git rev-list HEAD | wc -l)
145 | # Switch the rev number in our final output
146 | VER="${VER/r${REV}/r${FREV}}"
147 | ;;
148 | *)
149 | VER="${FALLBACK_VER}"
150 | esac
151 | else
152 | VER="${FALLBACK_VER}"
153 | fi
154 |
155 | # Strip the leading 'v'
156 | #VER=${VER#v*}
157 |
158 | # Get current version from include file
159 | if [[ -r "${VER_FILE}" ]] ; then
160 | VER_CURRENT="$(head -n 1 "${VER_FILE}")"
161 | # Strip var assignment
162 | VER_CURRENT="${VER_CURRENT/KT_VERSION = /}"
163 | else
164 | VER_CURRENT="unset"
165 | fi
166 |
167 | # Update our include file, if need be
168 | if [[ "${VER}" != "${VER_CURRENT}" ]] ; then
169 | echo >&2 "KT_VERSION = ${VER}"
170 | echo "KT_VERSION = ${VER}" > "${VER_FILE}"
171 | {
172 | echo "OSTYPE = ${UNAME}";
173 | echo "COMPILE_BY = ${COMPILE_BY}";
174 | echo "COMPILE_HOST = ${COMPILE_HOST}";
175 | echo "HAS_PC_LIBARCHIVE = ${HAS_PC_LIBARCHIVE}";
176 | echo "PC_LIBARCHIVE_CPPFLAGS = ${PC_LIBARCHIVE_CPPFLAGS}";
177 | echo "PC_LIBARCHIVE_LDFLAGS = ${PC_LIBARCHIVE_LDFLAGS}";
178 | echo "PC_LIBARCHIVE_LIBS = ${PC_LIBARCHIVE_LIBS}";
179 | echo "HAS_PC_NETTLE = ${HAS_PC_NETTLE}";
180 | echo "PC_NETTLE_CPPFLAGS = ${PC_NETTLE_CPPFLAGS}";
181 | echo "PC_NETTLE_LDFLAGS = ${PC_NETTLE_LDFLAGS}";
182 | echo "PC_NETTLE_LIBS = ${PC_NETTLE_LIBS}";
183 | echo "PC_NETTLE_VERSION = ${PC_NETTLE_VERSION}";
184 | echo "DISTRIB_ID = ${DISTRIB_ID}";
185 | } >> "${VER_FILE}"
186 | fi
187 |
188 | # Build a proper VERSION file (PMS)
189 | if [[ "${1}" == "PMS" ]] ; then
190 | echo "${VER}" > "${VERSION_FILE}"
191 | fi
192 |
--------------------------------------------------------------------------------
/tools/mingw/kindletool-mingw-build.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | #
5 | # KindleTool cross mingw-w64 buildscript
6 | #
7 | ##
8 |
9 | ## NOTE: Getting a decent cross-toolchain is a bit of a chore...
10 | ## Official releases are found @ https://sourceforge.net/projects/mingw-w64/files/
11 | ## But currently, they only provide *native* binaries.
12 | ## Historically, rubenvb provided binaries for cross-toolchains, but they're now horribly outdated.
13 | ## NOTE: Thankfully, there's http://sourceforge.net/projects/mingw-w64-dgn/ which does provide up to date binaries.
14 | ## NOTE: Alternatively, you could use MXE (http://mxe.cc) to build one yourself,
15 | ## although it's currently only using GCC 5.5.0 & binutils 2.28 (but with the latest mingw-w64 release),
16 | ## and has a bit too much dependencies for a headless box...
17 | ## NOTE: Or some other build script, like https://github.com/shinchiro/mpv-winbuild-cmake
18 | ## FIXME: Might need to symlink bcrypt.h to Bcrypt.h & windows.h to Windows.h to make libarchive happy...
19 |
20 | # Remember where we are...
21 | SCRIPT_NAME="${BASH_SOURCE[0]-${(%):-%x}}"
22 | SCRIPT_BASE_DIR="$(readlink -f "${SCRIPT_NAME%/*}")"
23 |
24 | # Make sure we're up to date
25 | git pull
26 |
27 | echo "* Setting environment up . . ."
28 | echo ""
29 | ARCH_FLAGS="-march=x86-64 -mtune=generic"
30 | CROSS_TC="x86_64-w64-mingw32"
31 | TC_BUILD_DIR="/home/niluje/Kindle/KTool_Static/MinGW/Build_W64"
32 |
33 | export PATH="/home/niluje/x-tools/mingw64/install/bin:${PATH}"
34 |
35 | BASE_CFLAGS="${ARCH_FLAGS} -O2 -pipe -fomit-frame-pointer"
36 | export CFLAGS="${BASE_CFLAGS}"
37 | export CXXFLAGS="${BASE_CFLAGS}"
38 | BASE_CPPFLAGS="-isystem${TC_BUILD_DIR}/include"
39 | export CPPFLAGS="${BASE_CPPFLAGS}"
40 | BASE_LDFLAGS="-L${TC_BUILD_DIR}/lib -Wl,-O1 -Wl,--as-needed"
41 | export LDFLAGS="${BASE_LDFLAGS}"
42 |
43 | BASE_PKG_CONFIG_PATH="${TC_BUILD_DIR}/lib/pkgconfig"
44 | BASE_PKG_CONFIG_LIBDIR="${TC_BUILD_DIR}/lib/pkgconfig"
45 | export PKG_CONFIG_DIR=
46 | export PKG_CONFIG_PATH="${BASE_PKG_CONFIG_PATH}"
47 | export PKG_CONFIG_LIBDIR="${BASE_PKG_CONFIG_LIBDIR}"
48 |
49 | ## Go :)
50 | ## Get to our build dir
51 | mkdir -p "${TC_BUILD_DIR}"
52 | cd "${TC_BUILD_DIR}"
53 |
54 | ZLIB_VER="1.2.11"
55 | ZLIB_DIR="zlib-${ZLIB_VER}"
56 | ZLIB_FILE="zlib${ZLIB_VER//.}.zip"
57 | GMP_VER="6.2.1"
58 | GMP_DIR="gmp-${GMP_VER%a}"
59 | NETTLE_VER="3.6"
60 | NETTLE_DIR="nettle-${NETTLE_VER}"
61 | LIBARCHIVE_VER="3.5.0"
62 | LIBARCHIVE_DIR="libarchive-${LIBARCHIVE_VER}"
63 |
64 | if [[ ! -d "${ZLIB_DIR}" ]] ; then
65 | echo "* Building zlib . . ."
66 | echo ""
67 | if [[ ! -f "./${ZLIB_FILE}" ]] ; then
68 | wget -O "${ZLIB_FILE}" "http://zlib.net/${ZLIB_FILE}"
69 | fi
70 | unzip ./${ZLIB_FILE}
71 | cd ${ZLIB_DIR}
72 | patch -p1 < ../../../KindleTool/tools/mingw/zlib-1.2.7-mingw-makefile-fix.patch
73 | make -f win32/Makefile.gcc
74 | mkdir -p ${TC_BUILD_DIR}/include ${TC_BUILD_DIR}/bin ${TC_BUILD_DIR}/lib
75 | #cp -v zlib1.dll ${TC_BUILD_DIR}/bin
76 | cp -v zconf.h zlib.h ${TC_BUILD_DIR}/include
77 | cp -v libz.a ${TC_BUILD_DIR}/lib
78 | #cp -v libz.dll.a ${TC_BUILD_DIR}/lib
79 | cd ..
80 | fi
81 |
82 | # GMP
83 | if [[ ! -d "${GMP_DIR}" ]] ; then
84 | echo "* Building ${GMP_DIR} . . ."
85 | echo ""
86 | if [[ ! -f "./${GMP_DIR}.tar.xz" ]] ; then
87 | wget -O "./${GMP_DIR}.tar.xz" "https://gmplib.org/download/gmp/${GMP_DIR}.tar.xz"
88 | fi
89 | tar -xvJf ./${GMP_DIR}.tar.xz
90 | cd ${GMP_DIR}
91 | autoreconf -fi
92 | libtoolize
93 | ./configure --prefix="${TC_BUILD_DIR}" --host="${CROSS_TC}" --enable-static --disable-shared --disable-cxx
94 | make -j2
95 | make install
96 | cd ..
97 | fi
98 |
99 | # nettle
100 | if [[ "${USE_STABLE_NETTLE}" == "true" ]] ; then
101 | if [[ ! -d "${NETTLE_DIR}" ]] ; then
102 | echo "* Building ${NETTLE_DIR} . . ."
103 | echo ""
104 | if [[ ! -f "./${NETTLE_DIR}.tar.gz" ]] ; then
105 | wget -O "./${NETTLE_DIR}.tar.gz" "http://www.lysator.liu.se/~nisse/archive/${NETTLE_DIR}.tar.gz"
106 | fi
107 | tar -xvzf ./${NETTLE_DIR}.tar.gz
108 | cd ${NETTLE_DIR}
109 | sed -e '/CFLAGS=/s: -ggdb3::' -e 's/solaris\*)/sunldsolaris*)/' -i configure.ac
110 | sed -i '/SUBDIRS/s/testsuite examples//' Makefile.in
111 | autoreconf -fi
112 | ./configure --prefix="${TC_BUILD_DIR}" --libdir="${TC_BUILD_DIR}/lib" --host="${CROSS_TC}" --enable-static --disable-shared --enable-public-key --disable-openssl --disable-documentation
113 | make -j2
114 | make install
115 | cd ..
116 | fi
117 | else
118 | if [[ ! -d "nettle-git" ]] ; then
119 | echo "* Building nettle . . ."
120 | echo ""
121 | git clone https://git.lysator.liu.se/nettle/nettle.git nettle-git
122 | cd nettle-git
123 | sed -e '/CFLAGS=/s: -ggdb3::' -e 's/solaris\*)/sunldsolaris*)/' -i configure.ac
124 | sed -i '/SUBDIRS/s/testsuite examples//' Makefile.in
125 | # Fix MinGW builds...
126 | # shellcheck disable=SC2016
127 | sed -e 's#desdata$(EXEEXT)#desdata$(EXEEXT_FOR_BUILD)#g' -i Makefile.in
128 | sh ./.bootstrap
129 | ./configure --prefix="${TC_BUILD_DIR}" --libdir="${TC_BUILD_DIR}/lib" --host="${CROSS_TC}" --enable-static --disable-shared --enable-public-key --disable-openssl --disable-documentation
130 | make -j2
131 | make install
132 | cd ..
133 | fi
134 | fi
135 |
136 | # libarchive
137 | if [[ "${USE_STABLE_LIBARCHIVE}" == "true" ]] ; then
138 | if [[ ! -d "${LIBARCHIVE_DIR}" ]] ; then
139 | echo "* Building ${LIBARCHIVE_DIR} . . ."
140 | echo ""
141 | if [[ ! -f "./${LIBARCHIVE_DIR}.tar.gz" ]] ; then
142 | wget -O "./${LIBARCHIVE_DIR}.tar.gz" "http://github.com/libarchive/libarchive/archive/v${LIBARCHIVE_VER}.tar.gz"
143 | fi
144 | tar -xvzf ./${LIBARCHIVE_DIR}.tar.gz
145 | cd ${LIBARCHIVE_DIR}
146 | ./build/autogen.sh
147 | ./configure --prefix="${TC_BUILD_DIR}" --host="${CROSS_TC}" --enable-static --disable-shared --disable-xattr --disable-acl --with-zlib --without-bz2lib --without-lzmadec --without-iconv --without-lzma --with-nettle --without-openssl --without-expat --without-xml2 --without-lz4 --without-zstd --disable-bsdcat --disable-bsdtar --disable-bsdcpio
148 | make -j2
149 | make install
150 | cd ..
151 | fi
152 | else
153 | if [[ ! -d "libarchive-git" ]] ; then
154 | echo "* Building libarchive . . ."
155 | echo ""
156 | git clone https://github.com/libarchive/libarchive.git libarchive-git
157 | cd libarchive-git
158 | # Remove -Werror, there might be some warnings depending on the TC used...
159 | sed -e 's/-Werror //' -i ./Makefile.am
160 | ./build/autogen.sh
161 | ./configure --prefix="${TC_BUILD_DIR}" --host="${CROSS_TC}" --enable-static --disable-shared --disable-xattr --disable-acl --with-zlib --without-bz2lib --without-lzmadec --without-iconv --without-lzma --with-nettle --without-openssl --without-expat --without-xml2 --without-lz4 --without-zstd --disable-bsdcat --disable-bsdtar --disable-bsdcpio
162 | make -j2
163 | make install
164 | cd ..
165 | fi
166 | fi
167 |
168 | # Build KT package credits
169 | cat > ../../CREDITS << EOF
170 | * kindletool.exe: KindleTool, Copyright (C) 2011-2012 Yifan Lu & Copyright (C) 2012-2023 NiLuJe, licensed under the GNU General Public License version 3+ (http://www.gnu.org/licenses/gpl.html).
171 | (https://github.com/NiLuJe/KindleTool/)
172 |
173 | |-> zlib, Copyright (C) 1995-2018 Jean-loup Gailly and Mark Adler,
174 | | Licensed under the zlib license (http://zlib.net/zlib_license.html)
175 | | (http://zlib.net/)
176 | |
177 | |-> libarchive, Copyright (C) Tim Kientzle, licensed under the New BSD License (http://www.opensource.org/licenses/bsd-license.php)
178 | | (http://libarchive.github.com/)
179 | |
180 | |-> GMP, GNU MP Library, Copyright 1991-2018 Free Software Foundation, Inc.,
181 | | licensed under the GNU Lesser General Public License version 3+ (http://www.gnu.org/licenses/lgpl.html).
182 | | (http://gmplib.org/)
183 | |
184 | |-> nettle, Copyright (C) 2001-2018 Niels Möller,
185 | | licensed under the GNU Lesser General Public License version 2.1+ (https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
186 | | (http://www.lysator.liu.se/~nisse/nettle)
187 | |
188 | \`-> Built using MinGW-w64 and statically linked against the MinGW-w64 runtime, Copyright (C) 2009-2019 by the mingw-w64 project,
189 | Licensed mostly under the Zope Public License (ZPL) Version 2.1. (http://sourceforge.net/p/mingw-w64/code/HEAD/tree/stable/v3.x/COPYING.MinGW-w64-runtime/COPYING.MinGW-w64-runtime.txt)
190 | (http://mingw-w64.sourceforge.net/)
191 | EOF
192 |
193 | # KindleTool
194 | echo "* Building KindleTool . . ."
195 | echo ""
196 | cd ../..
197 | cd KindleTool/KindleTool
198 | rm -rf lib includes
199 | make clean
200 | make mingw MINGW=true
201 |
202 | # Package it
203 | git log --stat --graph > ../../ChangeLog
204 | ./version.sh PMS STATIC
205 | VER_FILE="VERSION"
206 | VER_CURRENT="$(<${VER_FILE})"
207 | # Strip the git commit
208 | REV="${VER_CURRENT%%-*}"
209 | #REV="${VER_CURRENT}"
210 | cd ../..
211 | cp -v KindleTool/KindleTool/MinGW/kindletool.exe ./kindletool.exe
212 | cp -v KindleTool/README.md ./README
213 | # Quick! Markdown => plaintext
214 | sed -si 's///g;s/<\/b>//g;s///g;s/<\/i>//g;s/<//g;s/&/&/g;s/^* / /g;s/*//g;s/>> /\t/g;s/^> / /g;s/^## //g;s/### //g;s/\t/ /g;s/^\([[:digit:]]\)\./ \1)/g;s/^#.*$//;s/[[:blank:]]*$//g' README
215 | mv -v KindleTool/KindleTool/VERSION ./VERSION
216 | # LF => CRLF...
217 | unix2dos CREDITS README ChangeLog
218 | 7z a -tzip "kindletool-${REV}-mingw.zip" kindletool.exe CREDITS README ChangeLog VERSION
219 | rm -f kindletool.exe CREDITS README ChangeLog VERSION
220 |
--------------------------------------------------------------------------------
/KindleTool/kindletool.1:
--------------------------------------------------------------------------------
1 | .TH KINDLETOOL 1 04/11/21 Linux KindleTool
2 | .SH NAME
3 | KindleTool \- creates/extracts Kindle updates and more.
4 | .SH SYNOPSIS
5 | .B kindletool
6 | .RB < create | convert | extract | info | md | dm | version | help >
7 | .RI [ options ]
8 | .SH DESCRIPTION
9 | KindleTool will help you, among other things, create, convert, mangle or extract Kindle update packages.
10 | .SH OPTIONS
11 | .SS create
12 | .IR Syntax :
13 | .RB < type "> <" devices "> [" options "] <" dir | file ">... [<" output ">]"
14 | .RS
15 | Creates a Kindle update package.
16 | .br
17 | You should be able to throw a mix of files & directories as input without trouble.
18 | .br
19 | Just keep in mind that by default, if you feed it absolute paths, it will archive absolute paths, which usually isn't what you want!
20 | .br
21 | If input is a single gzipped tarball
22 | .RI ( .tgz " or " .tar.gz )
23 | file, we assume it is properly packaged (bundlefile & sigfile), and will only convert it to an update.
24 | .br
25 | Output should be a file with the extension
26 | .IR .bin ,
27 | if it is not provided, or if it's a single dash, output to standard output.
28 | .br
29 | In case of OTA updates, all files with the extension
30 | .IR .ffs " or " .sh
31 | will be treated as update scripts.
32 | .RE
33 | .TP
34 | .RB < ota | ota2 | recovery | recovery2 | sig >
35 | Set the update type.
36 | .br
37 | .B OTA V1.
38 | OTA update package. Works on Kindle 3 and older.
39 | .br
40 | .B OTA V2.
41 | Signed OTA V2 update package. Works on Kindle 4 and newer.
42 | .br
43 | .B Recovery.
44 | Recovery package for restoring partitions.
45 | .br
46 | .B Recovery V2.
47 | Recovery V2 package for restoring partitions. Works on FW >= 5.2 (PaperWhite) and newer.
48 | .br
49 | .B Signature envelope.
50 | Use this to build a signed userdata package with the -U switch (FW >= 5.1 only, but device agnostic).
51 | .TP
52 | .BI \-d ", " \-\-device " device"
53 | Set the target device(s).
54 | .br
55 | .BR "OTA V1" " and " Recovery
56 | packages only support one device.
57 | .br
58 | .BR "OTA V2" " and " "Recovery V2"
59 | packages can support multiple devices, this parameter can then be specified multiple times.
60 | .br
61 | .I device
62 | is one of
63 | .BR k1 ", " k2 ", " k2i ", " dx ", " dxi ", " dxg ", " k3w ", " k3g ", " k3gb ", " k4 ", " k4b ", " kindle2 ", " kindledx ", " kindle3 ", " legacy ", " kindle4 ", " touch ", " paperwhite ", " paperwhite2 ", " basic ", " voyage ", " paperwhite3 ", " oasis ", " basic2 ", " oasis2 ", " paperwhite4 ", " basic3 ", " oasis3 ", " paperwhite5 ", " basic4 ", " scribe ", " basic5 ", " paperwhite6 ", " scribe2 ", " colorsoft ", " kindle5 ", " none " or " auto .
64 | .TP
65 | .BI \-p ", " \-\-platform " platform"
66 | Set the target platform.
67 | .br
68 | .BR "Recovery FB02" " with " "header rev 2" " and " "Recovery V2" " only."
69 | Use a single platform per package.
70 | .br
71 | .I platform
72 | is one of
73 | .BR unspecified ", " mario ", " luigi ", " banjo ", " yoshi ", " yoshime-p ", " yoshime ", " wario ", " duet ", " heisenberg ", " zelda ", " rex ", " bellatrix ", " bellatrix3 " or " bellatrix4 .
74 | .TP
75 | .BI \-B ", " \-\-board " board"
76 | Set the target board.
77 | .br
78 | .BR "Recovery FB02" " with " "header rev 2" " and " "Recovery V2" " only."
79 | Use a single board per package.
80 | .br
81 | .I board
82 | is one of
83 | .BR unspecified ", " tequila " or " whitney .
84 | .TP
85 | .BR \-k ", " \-\-key " file"
86 | PEM file containing RSA private key to sign update. Default is popular jailbreak key.
87 | .TP
88 | .BR \-b ", " \-\-bundle " type"
89 | Manually specify package magic number. May override the default magic number of the chosen update type, if it makes sense.
90 | .br
91 | .I type
92 | is one of
93 | .BR FB01 ", " FB02 " for "
94 | .IR recovery ;
95 | .BR FB03 " for "
96 | .IR recovery2 ;
97 | .BR FC02 ", " FD03 " for "
98 | .IR ota " or "
99 | .BR FC04 ", " FD04 ", " FL01 " for "
100 | .IR ota2 " or "
101 | .BR SP01 " for "
102 | .I sig
103 | .TP
104 | .BR \-s ", " \-\-srcrev " uint"
105 | .B OTA
106 | updates only. Source revision.
107 | .B OTA V1
108 | uses
109 | .IR uint ,
110 | .B OTA V2
111 | uses
112 | .IR ulong .
113 | .br
114 | Lowest version of device that package supports. Default is
115 | .IR 0 .
116 | .br
117 | Also acccepts \fBmin\fR for \fI0\fR.
118 | .TP
119 | .BR \-t ", " \-\-tgtrev " uint"
120 | .BR OTA ", " "Recovery V2" " and " "Recovery FB02 with header rev 2"
121 | updates only. Target revision.
122 | .BR "OTA V1" " and " "Recovery V1H2"
123 | use
124 | .IR uint ,
125 | .BR "OTA V2" " and " "Recovery V2"
126 | use
127 | .IR ulong .
128 | .br
129 | Highest version of device that package supports. Default is
130 | .I ulong/uint max
131 | value.
132 | .br
133 | Also acccepts \fBmax\fR for the appropriate maximum value for the chosen update package type.
134 | .TP
135 | .BR \-h ", " \-\-hdrrev " uint"
136 | .BR "Recovery FB02" " and " "Recovery V2" " only."
137 | Header Revision. Default is
138 | .IR 0 .
139 | .TP
140 | .BR \-1 ", " \-\-magic1 " uint"
141 | .B Recovery
142 | updates only. Magic number 1. Default is
143 | .IR 0 .
144 | .TP
145 | .BR \-2 ", " \-\-magic2 " uint"
146 | .B Recovery
147 | updates only. Magic number 2. Default is
148 | .IR 0 .
149 | .TP
150 | .BR \-m ", " \-\-minor " uint"
151 | .B Recovery
152 | updates only. Minor number. Default is
153 | .IR 0 .
154 | .TP
155 | .BR \-c ", " \-\-cert " ushort"
156 | .BR "OTA V2" " and " "Recovery V2"
157 | updates only. The number of the certificate to use (found in /etc/uks on device). Default is
158 | .IR 0 .
159 | .br
160 | .BR 0 " = "
161 | .IR pubdevkey01.pem ,
162 | .BR 1 " = "
163 | .IR pubprodkey01.pem ,
164 | .BR 2 " = "
165 | .I pubprodkey02.pem
166 | .TP
167 | .BR \-o ", " \-\-opt " uchar"
168 | .B OTA V1
169 | updates only. One byte optional data expressed as a number. Default is
170 | .IR 0 .
171 | .TP
172 | .BR \-r ", " \-\-crit " uchar"
173 | .B OTA V2
174 | updates only. One byte optional data expressed as a number. Default is
175 | .IR 0 .
176 | .TP
177 | .BR \-x ", " \-\-meta " str"
178 | .B OTA V2
179 | updates only. An optional string to add. This parameter can then be specified multiple times.
180 | .br
181 | Format of metastring must be:
182 | .BR key = \fIvalue
183 | .TP
184 | .BR \-X ", " \-\-packaging
185 | .B OTA V2
186 | updates only. Adds \fBPackagedWith\fR, \fBPackagedBy\fR & \fBPackagedOn\fR metastrings, storing packaging metadata.
187 | .TP
188 | .BR \-a ", " \-\-archive
189 | Keep the intermediate archive.
190 | .TP
191 | .BR \-u ", " \-\-unsigned
192 | Build an unsigned & mangled userdata package.
193 | .TP
194 | .BR \-U ", " \-\-userdata
195 | Build an userdata package (can only be used with the sig update type).
196 | .TP
197 | .BR \-O ", " \-\-ota
198 | Build a versioned OTA bundle (can only be used with the ota2 update type).
199 | .TP
200 | .BR \-C ", " \-\-legacy
201 | Emulate the behaviour of yifanlu's KindleTool regarding directories. By default, we behave like tar:
202 | .br
203 | every path passed on the commandline is stored as-is in the archive. This switch changes that, and store paths
204 | .br
205 | relative to the path passed on the commandline, like if we had chdir'ed into it.
206 | .SS convert
207 | .IR Syntax :
208 | .RB [ options "] <" input >...
209 | .RS
210 | Converts a Kindle update package to a gzipped tar archive file, and delete input.
211 | .RE
212 | .TP
213 | .BR \-c ", " \-\-stdout
214 | Write to standard output, keeping original files unchanged.
215 | .TP
216 | .BR \-i ", " \-\-info
217 | Just print the package information, no conversion done.
218 | .TP
219 | .BR \-s ", " \-\-sig
220 | .BR "OTA V2" ", " "Recovery V2" " and " "Recovery FB02 with header rev 2"
221 | updates only. Extract the payload signature.
222 | .TP
223 | .BR \-k ", " \-\-keep
224 | Don't delete the input package.
225 | .TP
226 | .BR \-u ", " \-\-unsigned
227 | Assume input is an unsigned & mangled userdata package.
228 | .TP
229 | .BR \-w ", " \-\-unwrap
230 | Just unwrap the package, if it's wrapped in an UpdateSignature header (especially useful for userdata packages).
231 | .SS extract
232 | .IR Syntax :
233 | .RB [ options "] <" input "> <" output >
234 | .RS
235 | Extracts a Kindle update package to a directory.
236 | .RE
237 | .TP
238 | .BR \-u ", " \-\-unsigned
239 | Assume input is an unsigned & mangled userdata package.
240 | .SS info
241 | .IR Syntax :
242 | .RB < serialno >
243 | .RS
244 | Get the default root password.
245 | .br
246 | Unless you changed your password manually, the first password shown will be the right one.
247 | .br
248 | (The Kindle defaults to DES hashed passwords, which are truncated to 8 characters.
249 | .br
250 | See
251 | .BR crypt (3)
252 | for more details).
253 | .br
254 | If you're looking for the recovery MMC export password, that's the second one.
255 | .RE
256 | .SS md
257 | .IR Syntax :
258 | .RB [< input ">] [<" output >]
259 | .RS
260 | Obfuscates data using Amazon's update algorithm.
261 | .br
262 | If no input is provided, input from stdin
263 | .br
264 | If no output is provided, output to stdout
265 | .RE
266 | .SS dm
267 | .IR Syntax :
268 | .RB [< input ">] [<" output >]
269 | .RS
270 | Deobfuscates data using Amazon's update algorithm.
271 | .br
272 | If no input is provided, input from stdin
273 | .br
274 | If no output is provided, output to stdout
275 | .RE
276 | .SS version
277 | Show some info about this KindleTool build.
278 | .SS help
279 | Show the help screen.
280 | .SH NOTES
281 | If the variable
282 | .B KT_WITH_UNKNOWN_DEVCODES
283 | is set in your environment (no matter the value), some device checks will be relaxed with the create command.
284 | .br
285 | If the variable
286 | .B KT_PKG_METADATA_DUMP
287 | is set in your environment, convert will dump header info in a shell-friendly format in the file this variable points to.
288 | .br
289 | Currently, even though
290 | .B OTA V2
291 | supports updates that run on multiple devices,
292 | .br
293 | it is not possible to create an update package that will run on both
294 | .I FW 4.x
295 | (Kindle 4) and
296 | .I FW 5.x
297 | (Basically everything since the Kindle Touch).
298 | .SH BUGS
299 | Updates with meta-strings will probably fail to run when passed to
300 | .BR "Update Your Kindle" .
301 |
--------------------------------------------------------------------------------
/KindleTool/nettle_pem.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** KindleTool, nettle_pem.c
3 | **
4 | ** Copyright (C) 2011-2012 Yifan Lu
5 | ** Copyright (C) 2012-2023 NiLuJe
6 | ** Concept based on an original Python implementation by Igor Skochinsky & Jean-Yves Avenard,
7 | ** cf., http://www.mobileread.com/forums/showthread.php?t=63225
8 | **
9 | ** This program is free software: you can redistribute it and/or modify
10 | ** it under the terms of the GNU General Public License as published by
11 | ** the Free Software Foundation, either version 3 of the License, or
12 | ** (at your option) any later version.
13 | **
14 | ** This program is distributed in the hope that it will be useful,
15 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ** GNU General Public License for more details.
18 | **
19 | ** You should have received a copy of the GNU General Public License
20 | ** along with this program. If not, see .
21 | */
22 |
23 | #include "kindle_tool.h"
24 |
25 | // This was pretty much just lifted straight off from nettle's tools/pkcs1-conv.c,
26 | // Copyright (C) 2005, 2009 Niels Möller, Magnus Holmgren
27 | // Copyright (C) 2014 Niels Möller
28 | // with a very few tweaks to better suit our needs...
29 | enum object_type
30 | {
31 | RSA_PRIVATE_KEY = 0x200,
32 | RSA_PUBLIC_KEY,
33 | DSA_PRIVATE_KEY,
34 | GENERAL_PUBLIC_KEY,
35 | };
36 |
37 | /* Return 1 on success, 0 on error, -1 on eof */
38 | static int
39 | read_line(struct nettle_buffer* buffer, FILE* f)
40 | {
41 | int c;
42 |
43 | // Flawfinder: ignore
44 | while ((c = getc(f)) != EOF) {
45 | if (!NETTLE_BUFFER_PUTC(buffer, (uint8_t) c)) {
46 | return 0;
47 | }
48 |
49 | if (c == '\n') {
50 | return 1;
51 | }
52 | }
53 | if (ferror(f)) {
54 | fprintf(stderr, "Read failed: %s.\n", strerror(errno));
55 | return 0;
56 | } else {
57 | return -1;
58 | }
59 | }
60 |
61 | static int
62 | read_file(struct nettle_buffer* buffer, FILE* f)
63 | {
64 | int c;
65 |
66 | // Flawfinder: ignore
67 | while ((c = getc(f)) != EOF) {
68 | if (!NETTLE_BUFFER_PUTC(buffer, (uint8_t) c)) {
69 | return 0;
70 | }
71 | }
72 |
73 | if (ferror(f)) {
74 | fprintf(stderr, "Read failed: %s.\n", strerror(errno));
75 | return 0;
76 | } else {
77 | return 1;
78 | }
79 | }
80 |
81 | static const uint8_t pem_start_pattern[11] __attribute__((nonstring)) = "-----BEGIN ";
82 |
83 | static const uint8_t pem_end_pattern[9] __attribute__((nonstring)) = "-----END ";
84 |
85 | static const uint8_t pem_trailer_pattern[5] __attribute__((nonstring)) = "-----";
86 |
87 | static const char pem_ws[33] = {
88 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, /* \t, \n, \v, \f, \r */
89 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 /* SPC */
90 | };
91 |
92 | #define PEM_IS_SPACE(c) ((c) < sizeof(pem_ws) && pem_ws[(c)])
93 |
94 | /* Returns 1 on match, otherwise 0. */
95 | static int
96 | match_pem_start(size_t length, const uint8_t* line, size_t* marker_start, size_t* marker_length)
97 | {
98 | while (length > 0 && PEM_IS_SPACE(line[length - 1])) {
99 | length--;
100 | }
101 |
102 | if (length > (sizeof(pem_start_pattern) + sizeof(pem_trailer_pattern)) &&
103 | memcmp(line, pem_start_pattern, sizeof(pem_start_pattern)) == 0 &&
104 | memcmp(line + length - sizeof(pem_trailer_pattern), pem_trailer_pattern, sizeof(pem_trailer_pattern)) == 0) {
105 | *marker_start = 11;
106 | *marker_length = length - (sizeof(pem_start_pattern) + sizeof(pem_trailer_pattern));
107 |
108 | return 1;
109 | } else {
110 | return 0;
111 | }
112 | }
113 |
114 | /* Returns 1 on match, -1 if the line is of the right form except for
115 | the marker, otherwise 0. */
116 | static int
117 | match_pem_end(size_t length, const uint8_t* line, size_t marker_length, const uint8_t* marker)
118 | {
119 | while (length > 0 && PEM_IS_SPACE(line[length - 1])) {
120 | length--;
121 | }
122 |
123 | if (length > (sizeof(pem_end_pattern) + sizeof(pem_trailer_pattern)) &&
124 | memcmp(line, pem_end_pattern, sizeof(pem_end_pattern)) == 0 &&
125 | memcmp(line + length - sizeof(pem_trailer_pattern), pem_trailer_pattern, sizeof(pem_trailer_pattern)) == 0) {
126 | /* Right form. Check marker */
127 | if (length == marker_length + (sizeof(pem_end_pattern) + sizeof(pem_trailer_pattern)) &&
128 | memcmp(line + sizeof(pem_end_pattern), marker, marker_length) == 0) {
129 | return 1;
130 | } else {
131 | return -1;
132 | }
133 | } else {
134 | return 0;
135 | }
136 | }
137 |
138 | struct pem_info
139 | {
140 | /* The FOO part in "-----BEGIN FOO-----" */
141 | size_t marker_start;
142 | size_t marker_length;
143 | size_t data_start;
144 | size_t data_length;
145 | };
146 |
147 | static int
148 | read_pem(struct nettle_buffer* buffer, FILE* f, struct pem_info* info)
149 | {
150 | /* Find start line */
151 | for (;;) {
152 | int res;
153 |
154 | nettle_buffer_reset(buffer);
155 |
156 | res = read_line(buffer, f);
157 | if (res != 1) {
158 | return res;
159 | }
160 |
161 | if (match_pem_start(buffer->size, buffer->contents, &info->marker_start, &info->marker_length)) {
162 | break;
163 | }
164 | }
165 |
166 | /* NUL-terminate the marker. Don't care to check for embedded NULs. */
167 | buffer->contents[info->marker_start + info->marker_length] = 0;
168 |
169 | info->data_start = buffer->size;
170 |
171 | for (;;) {
172 | size_t line_start = buffer->size;
173 |
174 | if (read_line(buffer, f) != 1) {
175 | return 0;
176 | }
177 |
178 | switch (match_pem_end(buffer->size - line_start,
179 | buffer->contents + line_start,
180 | info->marker_length,
181 | buffer->contents + info->marker_start)) {
182 | case 0:
183 | break;
184 | case -1:
185 | fprintf(stderr, "PEM END line doesn't match BEGIN.\n");
186 | return 0;
187 | case 1:
188 | /* Return base 64 data; let caller do the decoding */
189 | info->data_length = line_start - info->data_start;
190 | return 1;
191 | }
192 | }
193 | }
194 |
195 | static inline int
196 | base64_decode_in_place(struct base64_decode_ctx* ctx, size_t* dst_length, size_t length, uint8_t* data)
197 | {
198 | return base64_decode_update(ctx, dst_length, data, length, (const char*) data);
199 | }
200 |
201 | static int
202 | decode_base64(struct nettle_buffer* buffer, size_t start, size_t* length)
203 | {
204 | struct base64_decode_ctx ctx;
205 |
206 | base64_decode_init(&ctx);
207 |
208 | /* Decode in place */
209 | if (base64_decode_in_place(&ctx, length, *length, buffer->contents + start) && base64_decode_final(&ctx)) {
210 | return 1;
211 | } else {
212 | fprintf(stderr, "Invalid base64 data.\n");
213 | return 0;
214 | }
215 | }
216 |
217 | static int
218 | convert_rsa_private_key(struct nettle_buffer* buffer,
219 | size_t length,
220 | const uint8_t* data,
221 | struct rsa_private_key* rsa_pkey)
222 | {
223 | struct rsa_public_key pub;
224 | int res;
225 |
226 | // NOTE: Unlike rsa_keypair_from_sexp, we *HAVE* to init the pubkey too, or everything blows up,
227 | // the from_der codepath expects it to be setup...
228 | rsa_public_key_init(&pub);
229 |
230 | if (rsa_keypair_from_der(&pub, rsa_pkey, 0, length, data)) {
231 | nettle_buffer_reset(buffer);
232 | res = 1;
233 | } else {
234 | fprintf(stderr, "Invalid PKCS#1 private key.\n");
235 | res = 0;
236 | }
237 |
238 | rsa_public_key_clear(&pub);
239 |
240 | return res;
241 | }
242 |
243 | // NOTE: Destroys contents of buffer
244 | // Returns 1 on success, 0 on error, and -1 for unsupported algorithms.
245 | static int
246 | convert_type(struct nettle_buffer* buffer,
247 | enum object_type type,
248 | size_t length,
249 | const uint8_t* data,
250 | struct rsa_private_key* rsa_pkey)
251 | {
252 | int res;
253 |
254 | switch (type) {
255 | default:
256 | fprintf(stderr, "Unsupported key type!\n");
257 | return -1;
258 |
259 | case RSA_PRIVATE_KEY:
260 | res = convert_rsa_private_key(buffer, length, data, rsa_pkey);
261 | break;
262 | }
263 |
264 | return res;
265 | }
266 |
267 | static int
268 | load_pem(struct nettle_buffer* buffer, FILE* f, struct rsa_private_key* rsa_pkey, enum object_type type, int base64)
269 | {
270 | if (type) {
271 | read_file(buffer, f);
272 | if (base64 && !decode_base64(buffer, 0, &buffer->size)) {
273 | return 0;
274 | }
275 |
276 | if (convert_type(buffer, type, buffer->size, buffer->contents, rsa_pkey) != 1) {
277 | return 0;
278 | }
279 |
280 | return 1;
281 | } else {
282 | /* PEM processing */
283 | for (;;) {
284 | struct pem_info info;
285 | const uint8_t* marker;
286 |
287 | nettle_buffer_reset(buffer);
288 | switch (read_pem(buffer, f, &info)) {
289 | default:
290 | return 0;
291 | case 1:
292 | break;
293 | case -1:
294 | /* EOF */
295 | return 1;
296 | }
297 |
298 | if (!decode_base64(buffer, info.data_start, &info.data_length)) {
299 | fprintf(stderr, "decode_base64 failed!\n");
300 | return 0;
301 | }
302 |
303 | marker = buffer->contents + info.marker_start;
304 |
305 | type = 0;
306 | switch (info.marker_length) {
307 | case 10:
308 | if (memcmp(marker, "PUBLIC KEY", 10) == 0) {
309 | type = GENERAL_PUBLIC_KEY;
310 | }
311 | break;
312 | case 14:
313 | if (memcmp(marker, "RSA PUBLIC KEY", 14) == 0) {
314 | type = RSA_PUBLIC_KEY;
315 | }
316 | break;
317 | case 15:
318 | if (memcmp(marker, "RSA PRIVATE KEY", 15) == 0) {
319 | type = RSA_PRIVATE_KEY;
320 | } else if (memcmp(marker, "DSA PRIVATE KEY", 15) == 0) {
321 | type = DSA_PRIVATE_KEY;
322 | }
323 | break;
324 | }
325 |
326 | if (!type) {
327 | fprintf(stderr, "Ignoring unsupported object type `%s'.\n", marker);
328 | } else if (convert_type(
329 | buffer, type, info.data_length, buffer->contents + info.data_start, rsa_pkey) !=
330 | 1) {
331 | fprintf(stderr, "convert_type failed!\n");
332 | return 0;
333 | }
334 | }
335 | }
336 | }
337 |
338 | int
339 | nettle_rsa_privkey_from_pem(const char* pem_filename, struct rsa_private_key* rsa_pkey)
340 | {
341 | struct nettle_buffer buffer;
342 | enum object_type type = 0;
343 | int base64 = 0;
344 |
345 | nettle_buffer_init_realloc(&buffer, NULL, nettle_xrealloc);
346 |
347 | const char* mode = (type || base64) ? "r" : "rb";
348 |
349 | FILE* f = fopen(pem_filename, mode);
350 | if (!f) {
351 | fprintf(stderr, "Failed to open `%s': %s.\n", pem_filename, strerror(errno));
352 | return EXIT_FAILURE;
353 | }
354 |
355 | if (!load_pem(&buffer, f, rsa_pkey, type, base64)) {
356 | fprintf(stderr, "load_pem failed!\n");
357 | return EXIT_FAILURE;
358 | }
359 |
360 | fclose(f);
361 | nettle_buffer_clear(&buffer);
362 |
363 | return EXIT_SUCCESS;
364 | }
365 |
--------------------------------------------------------------------------------
/KindleTool.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | B21B788A1866531E0046BFE2 /* nettle_pem.c in Sources */ = {isa = PBXBuildFile; fileRef = B21B78891866531E0046BFE2 /* nettle_pem.c */; };
11 | CE1DABEC14AF9C1E003B5CBA /* create.c in Sources */ = {isa = PBXBuildFile; fileRef = CE1DABEB14AF9C1E003B5CBA /* create.c */; };
12 | CEE4226814589F0C005E216E /* kindle_tool.c in Sources */ = {isa = PBXBuildFile; fileRef = CEE4226714589F0C005E216E /* kindle_tool.c */; };
13 | CEE4226A14589F0C005E216E /* kindletool.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = CEE4226914589F0C005E216E /* kindletool.1 */; };
14 | CEE42277145B818D005E216E /* convert.c in Sources */ = {isa = PBXBuildFile; fileRef = CEE42276145B818D005E216E /* convert.c */; };
15 | /* End PBXBuildFile section */
16 |
17 | /* Begin PBXCopyFilesBuildPhase section */
18 | CEE4226114589F0C005E216E /* CopyFiles */ = {
19 | isa = PBXCopyFilesBuildPhase;
20 | buildActionMask = 2147483647;
21 | dstPath = /usr/local/share/man/man1;
22 | dstSubfolderSpec = 0;
23 | files = (
24 | CEE4226A14589F0C005E216E /* kindletool.1 in CopyFiles */,
25 | );
26 | runOnlyForDeploymentPostprocessing = 1;
27 | };
28 | /* End PBXCopyFilesBuildPhase section */
29 |
30 | /* Begin PBXFileReference section */
31 | B21B78891866531E0046BFE2 /* nettle_pem.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = nettle_pem.c; sourceTree = ""; };
32 | CE1DABEB14AF9C1E003B5CBA /* create.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = create.c; sourceTree = ""; };
33 | CEE4226314589F0C005E216E /* KindleTool */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = KindleTool; sourceTree = BUILT_PRODUCTS_DIR; };
34 | CEE4226714589F0C005E216E /* kindle_tool.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = kindle_tool.c; sourceTree = ""; };
35 | CEE4226914589F0C005E216E /* kindletool.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = kindletool.1; sourceTree = ""; };
36 | CEE42276145B818D005E216E /* convert.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = convert.c; sourceTree = ""; };
37 | CEE42278145B82E0005E216E /* kindle_tool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = kindle_tool.h; sourceTree = ""; };
38 | /* End PBXFileReference section */
39 |
40 | /* Begin PBXFrameworksBuildPhase section */
41 | CEE4226014589F0C005E216E /* Frameworks */ = {
42 | isa = PBXFrameworksBuildPhase;
43 | buildActionMask = 2147483647;
44 | files = (
45 | );
46 | runOnlyForDeploymentPostprocessing = 0;
47 | };
48 | /* End PBXFrameworksBuildPhase section */
49 |
50 | /* Begin PBXGroup section */
51 | CEE4225814589F0C005E216E = {
52 | isa = PBXGroup;
53 | children = (
54 | CEE4226614589F0C005E216E /* KindleTool */,
55 | CEE4226414589F0C005E216E /* Products */,
56 | );
57 | sourceTree = "";
58 | };
59 | CEE4226414589F0C005E216E /* Products */ = {
60 | isa = PBXGroup;
61 | children = (
62 | CEE4226314589F0C005E216E /* KindleTool */,
63 | );
64 | name = Products;
65 | sourceTree = "";
66 | };
67 | CEE4226614589F0C005E216E /* KindleTool */ = {
68 | isa = PBXGroup;
69 | children = (
70 | B21B78891866531E0046BFE2 /* nettle_pem.c */,
71 | CEE42276145B818D005E216E /* convert.c */,
72 | CE1DABEB14AF9C1E003B5CBA /* create.c */,
73 | CEE42278145B82E0005E216E /* kindle_tool.h */,
74 | CEE4226714589F0C005E216E /* kindle_tool.c */,
75 | CEE4226914589F0C005E216E /* kindletool.1 */,
76 | );
77 | path = KindleTool;
78 | sourceTree = "";
79 | };
80 | /* End PBXGroup section */
81 |
82 | /* Begin PBXNativeTarget section */
83 | CEE4226214589F0C005E216E /* KindleTool */ = {
84 | isa = PBXNativeTarget;
85 | buildConfigurationList = CEE4226D14589F0C005E216E /* Build configuration list for PBXNativeTarget "KindleTool" */;
86 | buildPhases = (
87 | CEE4225F14589F0C005E216E /* Sources */,
88 | CEE4226014589F0C005E216E /* Frameworks */,
89 | CEE4226114589F0C005E216E /* CopyFiles */,
90 | );
91 | buildRules = (
92 | );
93 | dependencies = (
94 | );
95 | name = KindleTool;
96 | productName = KindleTool;
97 | productReference = CEE4226314589F0C005E216E /* KindleTool */;
98 | productType = "com.apple.product-type.tool";
99 | };
100 | /* End PBXNativeTarget section */
101 |
102 | /* Begin PBXProject section */
103 | CEE4225A14589F0C005E216E /* Project object */ = {
104 | isa = PBXProject;
105 | attributes = {
106 | LastUpgradeCheck = 0510;
107 | };
108 | buildConfigurationList = CEE4225D14589F0C005E216E /* Build configuration list for PBXProject "KindleTool" */;
109 | compatibilityVersion = "Xcode 3.2";
110 | developmentRegion = English;
111 | hasScannedForEncodings = 0;
112 | knownRegions = (
113 | en,
114 | );
115 | mainGroup = CEE4225814589F0C005E216E;
116 | productRefGroup = CEE4226414589F0C005E216E /* Products */;
117 | projectDirPath = "";
118 | projectRoot = "";
119 | targets = (
120 | CEE4226214589F0C005E216E /* KindleTool */,
121 | );
122 | };
123 | /* End PBXProject section */
124 |
125 | /* Begin PBXSourcesBuildPhase section */
126 | CEE4225F14589F0C005E216E /* Sources */ = {
127 | isa = PBXSourcesBuildPhase;
128 | buildActionMask = 2147483647;
129 | files = (
130 | CEE4226814589F0C005E216E /* kindle_tool.c in Sources */,
131 | CEE42277145B818D005E216E /* convert.c in Sources */,
132 | B21B788A1866531E0046BFE2 /* nettle_pem.c in Sources */,
133 | CE1DABEC14AF9C1E003B5CBA /* create.c in Sources */,
134 | );
135 | runOnlyForDeploymentPostprocessing = 0;
136 | };
137 | /* End PBXSourcesBuildPhase section */
138 |
139 | /* Begin XCBuildConfiguration section */
140 | CEE4226B14589F0C005E216E /* Debug */ = {
141 | isa = XCBuildConfiguration;
142 | buildSettings = {
143 | ALWAYS_SEARCH_USER_PATHS = YES;
144 | CLANG_ENABLE_OBJC_ARC = NO;
145 | CLANG_WARN_BOOL_CONVERSION = YES;
146 | CLANG_WARN_CONSTANT_CONVERSION = YES;
147 | CLANG_WARN_EMPTY_BODY = YES;
148 | CLANG_WARN_ENUM_CONVERSION = YES;
149 | CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
150 | CLANG_WARN_INT_CONVERSION = YES;
151 | CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
152 | CLANG_WARN__DUPLICATE_METHOD_MATCH = NO;
153 | COPY_PHASE_STRIP = NO;
154 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
155 | GCC_C_LANGUAGE_STANDARD = gnu99;
156 | GCC_DYNAMIC_NO_PIC = NO;
157 | GCC_ENABLE_OBJC_EXCEPTIONS = YES;
158 | GCC_OPTIMIZATION_LEVEL = 0;
159 | GCC_PREPROCESSOR_DEFINITIONS = (
160 | "DEBUG=1",
161 | "$(inherited)",
162 | );
163 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
164 | GCC_VERSION = "";
165 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
166 | GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
167 | GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
168 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
169 | GCC_WARN_ABOUT_RETURN_TYPE = YES;
170 | GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES;
171 | GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
172 | GCC_WARN_SHADOW = YES;
173 | GCC_WARN_SIGN_COMPARE = YES;
174 | GCC_WARN_UNDECLARED_SELECTOR = NO;
175 | GCC_WARN_UNINITIALIZED_AUTOS = YES;
176 | GCC_WARN_UNUSED_FUNCTION = YES;
177 | GCC_WARN_UNUSED_LABEL = YES;
178 | GCC_WARN_UNUSED_PARAMETER = YES;
179 | GCC_WARN_UNUSED_VARIABLE = YES;
180 | LIBRARY_SEARCH_PATHS = (
181 | /usr/local/lib,
182 | /usr/local/opt/libarchive/lib,
183 | );
184 | MACOSX_DEPLOYMENT_TARGET = 10.6;
185 | ONLY_ACTIVE_ARCH = YES;
186 | OTHER_LDFLAGS = (
187 | "-larchive",
188 | "-lhogweed",
189 | "-lgmp",
190 | "-lnettle",
191 | "-lz",
192 | );
193 | SDKROOT = macosx;
194 | USER_HEADER_SEARCH_PATHS = "/usr/local/include /usr/local/opt/libarchive/include";
195 | };
196 | name = Debug;
197 | };
198 | CEE4226C14589F0C005E216E /* Release */ = {
199 | isa = XCBuildConfiguration;
200 | buildSettings = {
201 | ALWAYS_SEARCH_USER_PATHS = YES;
202 | CLANG_ENABLE_OBJC_ARC = NO;
203 | CLANG_WARN_BOOL_CONVERSION = YES;
204 | CLANG_WARN_CONSTANT_CONVERSION = YES;
205 | CLANG_WARN_EMPTY_BODY = YES;
206 | CLANG_WARN_ENUM_CONVERSION = YES;
207 | CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
208 | CLANG_WARN_INT_CONVERSION = YES;
209 | CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
210 | CLANG_WARN__DUPLICATE_METHOD_MATCH = NO;
211 | COPY_PHASE_STRIP = YES;
212 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
213 | GCC_C_LANGUAGE_STANDARD = gnu99;
214 | GCC_ENABLE_OBJC_EXCEPTIONS = YES;
215 | GCC_VERSION = "";
216 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
217 | GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
218 | GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
219 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
220 | GCC_WARN_ABOUT_RETURN_TYPE = YES;
221 | GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES;
222 | GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
223 | GCC_WARN_SHADOW = YES;
224 | GCC_WARN_SIGN_COMPARE = YES;
225 | GCC_WARN_UNDECLARED_SELECTOR = NO;
226 | GCC_WARN_UNINITIALIZED_AUTOS = YES;
227 | GCC_WARN_UNUSED_FUNCTION = YES;
228 | GCC_WARN_UNUSED_LABEL = YES;
229 | GCC_WARN_UNUSED_PARAMETER = YES;
230 | GCC_WARN_UNUSED_VARIABLE = YES;
231 | LIBRARY_SEARCH_PATHS = (
232 | /usr/local/lib,
233 | /usr/local/opt/libarchive/lib,
234 | );
235 | MACOSX_DEPLOYMENT_TARGET = 10.6;
236 | ONLY_ACTIVE_ARCH = NO;
237 | OTHER_LDFLAGS = (
238 | "-larchive",
239 | "-lhogweed",
240 | "-lgmp",
241 | "-lnettle",
242 | "-lz",
243 | );
244 | SDKROOT = macosx;
245 | USER_HEADER_SEARCH_PATHS = "/usr/local/include /usr/local/opt/libarchive/include";
246 | };
247 | name = Release;
248 | };
249 | CEE4226E14589F0C005E216E /* Debug */ = {
250 | isa = XCBuildConfiguration;
251 | buildSettings = {
252 | PRODUCT_NAME = "$(TARGET_NAME)";
253 | };
254 | name = Debug;
255 | };
256 | CEE4226F14589F0C005E216E /* Release */ = {
257 | isa = XCBuildConfiguration;
258 | buildSettings = {
259 | PRODUCT_NAME = "$(TARGET_NAME)";
260 | };
261 | name = Release;
262 | };
263 | /* End XCBuildConfiguration section */
264 |
265 | /* Begin XCConfigurationList section */
266 | CEE4225D14589F0C005E216E /* Build configuration list for PBXProject "KindleTool" */ = {
267 | isa = XCConfigurationList;
268 | buildConfigurations = (
269 | CEE4226B14589F0C005E216E /* Debug */,
270 | CEE4226C14589F0C005E216E /* Release */,
271 | );
272 | defaultConfigurationIsVisible = 0;
273 | defaultConfigurationName = Release;
274 | };
275 | CEE4226D14589F0C005E216E /* Build configuration list for PBXNativeTarget "KindleTool" */ = {
276 | isa = XCConfigurationList;
277 | buildConfigurations = (
278 | CEE4226E14589F0C005E216E /* Debug */,
279 | CEE4226F14589F0C005E216E /* Release */,
280 | );
281 | defaultConfigurationIsVisible = 0;
282 | defaultConfigurationName = Release;
283 | };
284 | /* End XCConfigurationList section */
285 | };
286 | rootObject = CEE4225A14589F0C005E216E /* Project object */;
287 | }
288 |
--------------------------------------------------------------------------------
/KindleTool/Makefile:
--------------------------------------------------------------------------------
1 | CC?=gcc
2 | STRIP?=strip
3 | DEBUG_CFLAGS:=-Og -march=native -fno-omit-frame-pointer -pipe -g3
4 | CLANG_DEBUG_CFLAGS:=-O0 -march=native -fno-omit-frame-pointer -pipe -g3
5 | OPT_CFLAGS:=-O3 -ffast-math -march=native -fomit-frame-pointer -frename-registers -fweb -pipe
6 | CLANG_OPT_CFLAGS:=-O3 -ffast-math -march=native -fomit-frame-pointer -pipe
7 | K3_CFLAGS:=-O3 -ffast-math -march=armv6j -mtune=arm1136jf-s -fomit-frame-pointer -frename-registers -fweb -pipe -fno-stack-protector -U_FORTIFY_SOURCE
8 | MINGW_CFLAGS:=-O3 -ffast-math -march=x86-64 -mtune=generic -fomit-frame-pointer -pipe
9 | # When we want to use clang's asan (http://clang.llvm.org/docs/AddressSanitizer.html), because it rocks.
10 | ASAN_CLFAGS:=-O1 -march=native -fno-omit-frame-pointer -pipe -fno-optimize-sibling-calls -Weverything -Wno-disabled-macro-expansion -fsanitize=address -g3
11 | # In the same vein, since valgrind 2.8.0 now runs properly on my Gentoo system, here's a few notes about its current report:
12 | # (Using --leak-check=full --track-origins=yes --show-reachable=yes)
13 | # The getpwuid_r/getgrgid_r thing from libarchive's archive_read_disk_set_standard_lookup is mostly harmless (cf. http://sourceware.org/bugzilla/show_bug.cgi?id=2314),
14 | # and only happens when using the NSS compat stuff (which happened to be the default on my system...)
15 |
16 | # Kindle cross toolchain prefix
17 | ifdef KINDLE
18 | CROSS_PREFIX?=arm-kindle-linux-gnueabi-
19 | endif
20 | # MinGW-w64 (64bit) cross toolchain prefix
21 | ifdef MINGW
22 | CROSS_PREFIX?=x86_64-w64-mingw32-
23 | NEED_STATIC_PKGC:=STATIC
24 | endif
25 |
26 | SRCS:=kindle_tool.c create.c convert.c nettle_pem.c
27 |
28 | default: all
29 |
30 | # OS, version, pkgconfig & misc stuff handling (heavily inspired from git's Makefiles ;))
31 | # It's basically our fake automated configure script, and it uses bash features, so override the default shell!
32 | SHELL:=/usr/bin/env bash
33 | version-inc:
34 | @$(SHELL) ./version.sh GIT $(NEED_STATIC_PKGC)
35 | -include version-inc
36 |
37 | # Try to use sane defaults for DESTDIR/PREFIX, while still playing nice with PMS
38 | ifndef DESTDIR
39 | PREFIX:=/.
40 | else
41 | ifeq "$(OSTYPE)" "Darwin"
42 | # Play nice with Homebrew (not so much, in fact, but whatever).
43 | PREFIX?=/usr/local
44 | else
45 | # Should play nice with various Linux PMS, specifically non-prefixed Portage/Paludis setups
46 | PREFIX:=/usr
47 | endif
48 | endif
49 | DESTDIR?=/usr/local
50 | BINDIR:=$(DESTDIR)/$(PREFIX)/bin
51 | MANDIR:=$(DESTDIR)/$(PREFIX)/share/man/man1
52 |
53 | ifeq "$(OSTYPE)" "Darwin"
54 | # Homebrew default paths... (w/ libarchive keg)
55 | CPPFLAGS?=-I/usr/local/include -I/usr/local/opt/libarchive/include
56 | else
57 | CPPFLAGS?=-Iincludes
58 | endif
59 |
60 | # We of course need libarchive (try to use sane fallbacks on the off chance we have it somewhere but pkg-config failed to find it...)
61 | ifeq "$(HAS_PC_LIBARCHIVE)" "true"
62 | LIBS:=$(PC_LIBARCHIVE_LIBS)
63 | else
64 | LIBS:=-larchive
65 | endif
66 | # And nettle...
67 | ifeq "$(HAS_PC_NETTLE)" "true"
68 | LIBS+=$(PC_NETTLE_LIBS)
69 | else
70 | LIBS+=-lhogweed -lgmp -lnettle
71 | endif
72 | # And zlib (for libarchive)
73 | LIBS+=-lz
74 |
75 | # If we want to use part of gperftools (http://gperftools.googlecode.com/svn/trunk/doc/heap_checker.html for example)
76 | #ifeq "$(OSTYPE)" "Linux"
77 | # LIBS+=-ltcmalloc
78 | #endif
79 |
80 | # Detect GCC version because reasons...
81 | # (namely, GCC emitting an error instead of a warning on unknown -W options)
82 | MOAR_WARNIGS:=0
83 | # Tests heavily inspired from Linux's build system ;).
84 | CC_IS_CLANG:=$(shell $(CC) -v 2>&1 | grep -q "clang version" && echo 1 || echo 0)
85 | CC_VERSION:=$(shell printf "%02d%02d%02d" `echo __GNUC__ | $(CC) -E -x c - | tail -n 1` `echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1` `echo __GNUC_PATCHLEVEL__ | $(CC) -E -x c - | tail -n 1`)
86 | # Detect Clang's SA, too...
87 | ifeq "$(CC_IS_CLANG)" "0"
88 | ifeq "$(lastword $(subst /, ,$(CC)))" "ccc-analyzer"
89 | CC_IS_CLANG:=1
90 | endif
91 | endif
92 | ifeq "$(CC_IS_CLANG)" "1"
93 | # This is Clang
94 | MOAR_WARNIGS:=1
95 | endif
96 | ifeq "$(shell expr $(CC_VERSION) \>= 070000)" "1"
97 | # This is GCC >= 7
98 | MOAR_WARNIGS:=1
99 | endif
100 |
101 | ifdef DEBUG
102 | OUT_DIR:=Debug
103 | # Clang doesn't support -Og...
104 | ifeq "$(CC_IS_CLANG)" "1"
105 | CFLAGS:=$(CLANG_DEBUG_CFLAGS)
106 | else
107 | CFLAGS:=$(DEBUG_CFLAGS)
108 | endif
109 | else
110 | OUT_DIR:=Release
111 | # Don't default to stuff that'll make clang unhappy
112 | ifeq "$(CC_IS_CLANG)" "1"
113 | CFLAGS?=$(CLANG_OPT_CFLAGS)
114 | else
115 | CFLAGS?=$(OPT_CFLAGS)
116 | endif
117 | # Enforce aggressive optimizations...
118 | ifeq (,$(findstring -O3,$(CFLAGS)))
119 | override CFLAGS:=$(CFLAGS:-O%=-O3)
120 | endif
121 | ifeq (,$(findstring -ffast-math,$(CFLAGS)))
122 | KT_CFLAGS+=-ffast-math
123 | endif
124 | ifeq (,$(findstring -ftree-vectorize,$(CFLAGS)))
125 | KT_CFLAGS+=-ftree-vectorize
126 | endif
127 | ifeq (,$(findstring -funroll-loops,$(CFLAGS)))
128 | KT_CFLAGS+=-funroll-loops
129 | endif
130 | endif
131 |
132 | ifdef KINDLE
133 | OUT_DIR:=Kindle
134 | CFLAGS?=$(K3_CFLAGS)
135 | CC:=$(CROSS_PREFIX)gcc
136 | STRIP:=$(CROSS_PREFIX)strip
137 | endif
138 |
139 | ifdef MINGW
140 | OUT_DIR:=MinGW
141 | CFLAGS?=$(MINGW_CFLAGS)
142 | CC:=$(CROSS_PREFIX)gcc
143 | STRIP:=$(CROSS_PREFIX)strip
144 | endif
145 |
146 | # Oh, OS X...
147 | ifeq "$(OSTYPE)" "Darwin"
148 | STRIP_OPTS:=
149 | else
150 | STRIP_OPTS:=--strip-unneeded
151 | endif
152 |
153 | # It appears that Windows is using a strange & incongruous file extension for its binaries... ;D
154 | ifdef MINGW
155 | # Cygwin is smart enough to take care of it itself, so just check MinGW ;)
156 | BINEXT:=.exe
157 | else
158 | BINEXT:=
159 | endif
160 |
161 | # NOTE: All the KT_ prefixed *FLAGS are stuff that we *always* want set, no matter what the user does.
162 | # Moar warnings!
163 | ifeq "$(MOAR_WARNIGS)" "1"
164 | KT_CFLAGS+=-Wall
165 | KT_CFLAGS+=-Wextra -Wunused
166 | KT_CFLAGS+=-Wformat=2
167 | KT_CFLAGS+=-Wformat-signedness
168 | # NOTE: This doesn't really play nice w/ FORTIFY, leading to an assload of false-positives, unless LTO is enabled
169 | ifneq (,$(findstring flto,$(CFLAGS)))
170 | KT_CFLAGS+=-Wformat-truncation=2
171 | else
172 | KT_CFLAGS+=-Wno-format-truncation
173 | endif
174 | KT_CFLAGS+=-Wnull-dereference
175 | KT_CFLAGS+=-Wuninitialized
176 | KT_CFLAGS+=-Wduplicated-branches -Wduplicated-cond
177 | KT_CFLAGS+=-Wundef
178 | KT_CFLAGS+=-Wbad-function-cast
179 | KT_CFLAGS+=-Wwrite-strings
180 | KT_CFLAGS+=-Wjump-misses-init
181 | KT_CFLAGS+=-Wlogical-op
182 | KT_CFLAGS+=-Wstrict-prototypes -Wold-style-definition
183 | KT_CFLAGS+=-Wshadow
184 | KT_CFLAGS+=-Wmissing-prototypes -Wmissing-declarations
185 | KT_CFLAGS+=-Wnested-externs
186 | KT_CFLAGS+=-Winline
187 | KT_CFLAGS+=-Wcast-qual
188 | # NOTE: GCC 8 introduces -Wcast-align=strict to warn regardless of the target architecture (i.e., like clang)
189 | KT_CFLAGS+=-Wcast-align
190 | KT_CFLAGS+=-Wconversion
191 | # Output padding info when debugging (NOTE: Clang is slightly more verbose)
192 | # As well as function attribute hints
193 | ifdef DEBUG
194 | KT_CFLAGS+=-Wpadded
195 | KT_CFLAGS+=-Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -Wmissing-format-attribute
196 | endif
197 | # Annoying with our typedefs
198 | KT_CFLAGS+=-Wno-bad-function-cast
199 | # And disable some very verbose and/or annoying stuff
200 | KT_CFLAGS+=-Wno-jump-misses-init
201 | # And just because that's annoying...
202 | ifeq "$(CC_IS_CLANG)" "1"
203 | KT_CFLAGS+=-Wno-ignored-optimization-argument -Wno-unknown-warning-option -Wno-unknown-attributes
204 | endif
205 | endif
206 |
207 | # libarchive is always built with large files support, do the same to avoid issues.
208 | KT_CPPFLAGS+=-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
209 | # Get a printf function family with GNU extensions support on MinGW...
210 | ifdef MINGW
211 | # That's enough for MinGW
212 | KT_CPPFLAGS+=-D_GNU_SOURCE
213 | # But not for MinGW-w64...
214 | KT_CPPFLAGS+=-D__USE_MINGW_ANSI_STDIO=1
215 | endif
216 | KT_CPPFLAGS+=-DKT_VERSION='"$(KT_VERSION)"'
217 | # Add a user@host build tag, unless explicitly forbidden
218 | ifndef KT_NO_USERATHOST_TAG
219 | KT_CPPFLAGS+=-DKT_USERATHOST='"$(COMPILE_BY)@$(COMPILE_HOST) on $(DISTRIB_ID)"'
220 | endif
221 | # Also pass our stupid hack to get the buildtime nettle version, if it's not empty...
222 | ifneq "$(PC_NETTLE_VERSION)" ""
223 | KT_CPPFLAGS+=-DNETTLE_VERSION='"$(PC_NETTLE_VERSION)"'
224 | endif
225 |
226 | ifndef LDFLAGS
227 | ifeq "$(OSTYPE)" "Darwin"
228 | # Again, Homebrew default paths, w/ libarchive keg
229 | LDFLAGS:=-L/usr/local/lib -L/usr/local/opt/libarchive/lib
230 | else
231 | LDFLAGS:=-Llib
232 | LDFLAGS+=-Wl,-O1 -Wl,--as-needed
233 | endif
234 | endif
235 |
236 | # On platforms where we rely on pkg-config (Linux & OS X), make sure we obey it!
237 | # That should help us link against the correct libarchive version on Debian/Ubuntu, where libarchive-2 and libarchive-3 coexist with a single -dev package;
238 | # And on OS X, where libarchive is keg-only with Homebrew.
239 | ifeq "$(HAS_PC_LIBARCHIVE)" "true"
240 | CPPFLAGS+=$(PC_LIBARCHIVE_CPPFLAGS)
241 | LDFLAGS+=$(PC_LIBARCHIVE_LDFLAGS)
242 | endif
243 | # Do the same for nettle
244 | ifeq "$(HAS_PC_NETTLE)" "true"
245 | CPPFLAGS+=$(PC_NETTLE_CPPFLAGS)
246 | LDFLAGS+=$(PC_NETTLE_LDFLAGS)
247 | endif
248 |
249 | # Let's say we want to default to building stuff that will work on OS X 10.6/10.7... If I get how this stuff works, that should do it...
250 | #ifeq "$(OSTYPE)" "Darwin"
251 | # # Check that we don't mess with Homebrew, which defaults to the OS version... (I'm not sure Homebrew even sets it for us, since we're not using autotools...)
252 | # # Although it supposedly defaults to the OS version since OS X 10.5 anyway, so...
253 | # ifndef MACOSX_DEPLOYMENT_TARGET
254 | # export MACOSX_DEPLOYMENT_TARGET:=10.6
255 | # KT_CFLAGS+=-mmacosx-version-min=10.6
256 | # endif
257 | #endif
258 |
259 | OBJS:=$(addprefix $(OUT_DIR)/, $(SRCS:.c=.o))
260 |
261 | $(OUT_DIR)/%.o: %.c
262 | $(CC) $(CPPFLAGS) $(KT_CPPFLAGS) $(CFLAGS) $(KT_CFLAGS) -o $@ -c $<
263 |
264 | outdir:
265 | mkdir -p $(OUT_DIR)
266 |
267 | # Make absolutely sure we create our output directories first, even with unfortunate // timings!
268 | # c.f., https://www.gnu.org/software/make/manual/html_node/Prerequisite-Types.html#Prerequisite-Types
269 | $(OBJS): | outdir
270 |
271 | all: kindletool
272 |
273 | kindletool: version-inc $(OBJS)
274 | $(CC) $(CPPFLAGS) $(KT_CPPFLAGS) $(CFLAGS) $(KT_CFLAGS) $(LDFLAGS) -o$(OUT_DIR)/$@$(BINEXT) $(OBJS) $(LIBS)
275 |
276 | strip: all
277 | $(STRIP) $(STRIP_OPTS) $(OUT_DIR)/kindletool$(BINEXT)
278 |
279 | debug:
280 | $(MAKE) all DEBUG=true
281 |
282 | kindle:
283 | $(MAKE) strip KINDLE=true
284 |
285 | mingw:
286 | $(MAKE) strip MINGW=true
287 |
288 | clean:
289 | rm -rf Release/*.o
290 | rm -rf Release/kindletool
291 | rm -rf Debug/*.o
292 | rm -rf Debug/kindletool
293 | rm -rf Kindle/*.o
294 | rm -rf Kindle/kindletool
295 | rm -rf MinGW/*.o
296 | rm -rf MinGW/kindletool.exe
297 | rm -rf version-inc
298 | rm -rf VERSION
299 |
300 | install: all
301 | install -d -m 755 $(BINDIR)
302 | install '$(OUT_DIR)/kindletool' $(BINDIR)
303 | install -d -m 755 $(MANDIR)
304 | install -m 644 kindletool.1 $(MANDIR)
305 |
306 |
307 | .PHONY: all install clean default outdir kindletool strip debug kindle mingw
308 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # KindleTool
2 | [](/LICENSE) [](https://www.codacy.com/app/NiLuJe/KindleTool?utm_source=github.com&utm_medium=referral&utm_content=NiLuJe/KindleTool&utm_campaign=Badge_Grade) [](https://github.com/NiLuJe/KindleTool/releases/)
3 |
4 | ## Usage
5 | - KindleTool md [ <input> ] [ <output> ]
6 |
7 | > Obfuscates data using Amazon's update algorithm.
8 | > If no input is provided, input from stdin
9 | > If no output is provided, output to stdout
10 |
11 | - KindleTool dm [ <input> ] [ <output> ]
12 |
13 | > Deobfuscates data using Amazon's update algorithm.
14 | > If no input is provided, input from stdin
15 | > If no output is provided, output to stdout
16 |
17 | - KindleTool convert [options] <input>...
18 |
19 | > Converts a Kindle update package to a gzipped tar archive file, and delete input.
20 |
21 | Options:
22 | -c, --stdout Write to standard output, keeping original files unchanged.
23 | -i, --info Just print the package information, no conversion done.
24 | -s, --sig OTA V2, Recovery V2 & Recovery FB02 with header rev 2 updates only. Extract the payload signature.
25 | -k, --keep Don't delete the input package.
26 | -u, --unsigned Assume input is an unsigned & mangled userdata package.
27 | -w, --unwrap Just unwrap the package, if it's wrapped in an UpdateSignature header (especially useful for userdata packages).
28 |
29 | - KindleTool extract [options] <input> <output>
30 |
31 | > Extracts a Kindle update package to a directory.
32 |
33 | Options:
34 | -u, --unsigned Assume input is an unsigned & mangled userdata package.
35 |
36 | - KindleTool create <type> <devices> [options] <dir|file>... [ <output> ]
37 |
38 | > Creates a Kindle update package.
39 | > You should be able to throw a mix of files & directories as input without trouble.
40 | > Just keep in mind that by default, if you feed it absolute paths, it will archive absolute paths, which usually isn't what you want!
41 | > If input is a single gzipped tarball (".tgz" or ".tar.gz") file, we assume it is properly packaged (bundlefile & sigfile), and will only convert it to an update.
42 | > Output should be a file with the extension ".bin", if it is not provided, or if it's a single dash, outputs to standard output.
43 | > In case of OTA updates, all files with the extension ".ffs" or ".sh" will be treated as update scripts.
44 |
45 | Type:
46 | ota OTA V1 update package. Works on Kindle 3 and older.
47 | ota2 OTA V2 signed update package. Works on Kindle 4 and newer.
48 | recovery Recovery package for restoring partitions.
49 | recovery2 Recovery V2 package for restoring partitions. Works on FW >= 5.2 (PaperWhite) and newer
50 | sig Signature envelope. Use this to build a signed userdata package with the -U switch (FW >= 5.1 only, but device agnostic).
51 |
52 | Devices:
53 | OTA V1 & Recovery packages only support one device. OTA V2 & Recovery V2 packages can support multiple devices.
54 |
55 | -d, --device k1 Kindle 1
56 | -d, --device k2 Kindle 2 US
57 | -d, --device k2i Kindle 2 International
58 | -d, --device dx Kindle DX US
59 | -d, --device dxi Kindle DX International
60 | -d, --device dxg Kindle DX Graphite
61 | -d, --device k3w Kindle 3 WiFi
62 | -d, --device k3g Kindle 3 WiFi+3G
63 | -d, --device k3gb Kindle 3 WiFi+3G Europe
64 | -d, --device k4 Silver Kindle 4 (Non-Touch) (2011)
65 | -d, --device k4b Black Kindle 4 (Non-Touch) (2012)
66 | -d, --device kindle2 Alias for k2 + k2i
67 | -d, --device kindledx Alias for dx + dxi + dxg
68 | -d, --device kindle3 Alias for k3w + k3g + k3gb
69 | -d, --device legacy Alias for kindle2 + kindledx + kindle3
70 | -d, --device kindle4 Alias for k4 + k4b
71 | -d, --device touch Includes all known Kindle Touch variants
72 | -d, --device paperwhite Includes all known Kindle PaperWhite 1 variants
73 | -d, --device paperwhite2 Includes all known Kindle PaperWhite 2 variants
74 | -d, --device basic Includes all known Kindle Basic 1 variants
75 | -d, --device voyage Includes all known Kindle Voyage variants
76 | -d, --device paperwhite3 Includes all known Kindle PaperWhite 3 variants
77 | -d, --device oasis Includes all known Kindle Oasis 1 variants
78 | -d, --device basic2 Includes all known Kindle Basic 2 variants
79 | -d, --device oasis2 Includes all known Kindle Oasis 2 variants
80 | -d, --device paperwhite4 Includes all known Kindle PaperWhite 4 variants
81 | -d, --device basic3 Includes all known Kindle Basic 3 variants
82 | -d, --device oasis3 Includes all known Kindle Oasis 3 variants
83 | -d, --device paperwhite5 Includes all known Kindle PaperWhite 5 variants
84 | -d, --device basic4 Includes all known Kindle Basic 4 variants
85 | -d, --device scribe Includes all known Kindle Scribe variants
86 | -d, --device basic5 Includes all known Kindle Basic 5 variants
87 | -d, --device paperwhite6 Includes all known Kindle PaperWhite 6 variants
88 | -d, --device scribe2 Includes all known Kindle Scribe 2 variants
89 | -d, --device colorsoft Includes all known Kindle ColorSoft variants
90 | -d, --device kindle5 Alias for touch + paperwhite + paperwhite2 + basic + voyage + paperwhite3 + oasis + basic2 + oasis2 + paperwhite4 + basic3 + oasis3 + paperwhite5 + basic4 + scribe + basic5 + paperwhite6 + scribe2 + colorsoft
91 | -d, --device none No specific device (Recovery V2 & Recovery FB02 with header rev 2 only, default).
92 | -d, --device auto The current device (Obviously, has to be run from a Kindle).
93 |
94 | Platforms:
95 | Recovery V2 & Recovery FB02 with header rev 2 updates only. Use a single platform per package.
96 |
97 | -p, --platform unspecified Don't target a specific platform.
98 | -p, --platform mario Mario (mostly devices shipped on FW 1.x?) [Deprecated].
99 | -p, --platform luigi Luigi (mostly devices shipped on FW 2.x?).
100 | -p, --platform banjo Banjo (devices shipped on FW 3.x?).
101 | -p, --platform yoshi Yoshi (mostly devices shipped on FW <= 5.1).
102 | -p, --platform yoshime-p Yoshime (Prototype).
103 | -p, --platform yoshime Yoshime (Also known as Yoshime3, mostly devices shipped on FW >= 5.2).
104 | -p, --platform wario Wario (mostly devices shipped on FW >= 5.4).
105 | -p, --platform duet Duet (mostly devices shipped on FW >= 5.7).
106 | -p, --platform heisenberg Heisenberg (mostly devices shipped on FW >= 5.8).
107 | -p, --platform zelda Zelda (mostly devices shipped on FW >= 5.9).
108 | -p, --platform rex Rex (mostly devices shipped on FW >= 5.10).
109 | -p, --platform bellatrix Bellatrix (mostly devices shipped on FW >= 5.14).
110 | -p, --platform bellatrix3 Bellatrix3 (mostly devices shipped on FW >= 5.16).
111 | -p, --platform bellatrix4 Bellatrix4 (mostly devices shipped on FW >= 5.18).
112 |
113 | Boards:
114 | Recovery V2 & Recovery FB02 with header rev 2 updates only. Use a single board per package.
115 |
116 | -B, --board unspecified Don't target a specific board, skip the device check.
117 | -B, --board tequila Tequila (Kindle 4)
118 | -B, --board whitney Whitney (Kindle Touch)
119 |
120 | Options:
121 | All the following options are optional and advanced.
122 | -k, --key PEM file containing RSA private key to sign update. Default is popular jailbreak key.
123 | -b, --bundle Manually specify package magic number. May override the value dictated by "type", if it makes sense. Valid bundle versions:
124 | FB01, FB02 = recovery; FB03 = recovery2; FC02, FD03 = ota; FC04, FD04, FL01 = ota2; SP01 = sig
125 | -s, --srcrev OTA updates only. Source revision. OTA V1 uses uint, OTA V2 uses ulong.
126 | Lowest version of device that package supports. Default is 0.
127 | Also acccepts min for 0.
128 | -t, --tgtrev OTA, Recovery V2 & Recovery FB02 with header rev 2 updates only. Target revision. OTA V1 & Recovery V1H2 uses uint, OTA V2 & Recovery V2 uses ulong.
129 | Highest version of device that package supports. Default is ulong/uint max value.
130 | Also acccepts max for the appropriate maximum value for the chosen update package type.
131 | -h, --hdrrev Recovery V2 & Recovery FB02 updates only. Header Revision. Default is 0.
132 | -1, --magic1 Recovery updates only. Magic number 1. Default is 0.
133 | -2, --magic2 Recovery updates only. Magic number 2. Default is 0.
134 | -m, --minor Recovery updates only. Minor number. Default is 0.
135 | -c, --cert OTA V2 & Recovery V2 updates only. The number of the certificate to use (found in /etc/uks on device). Default is 0.
136 | 0 = pubdevkey01.pem, 1 = pubprodkey01.pem, 2 = pubprodkey02.pem
137 | -o, --opt OTA V1 updates only. One byte optional data expressed as a number. Default is 0.
138 | -r, --crit OTA V2 updates only. One byte optional data expressed as a number. Default is 0.
139 | -x, --meta OTA V2 updates only. An optional string to add. Multiple "--meta" options supported.
140 | Format of metastring must be: key=value
141 | -X, --packaging OTA V2 updates only. Adds PackagedWith, PackagedBy & PackagedOn metastrings, storing packaging metadata.
142 | -a, --archive Keep the intermediate archive.
143 | -u, --unsigned Build an unsigned & mangled userdata package.
144 | -U, --userdata Build an userdata package (can only be used with the sig update type).
145 | -O, --ota Build a versioned OTA bundle (can only be used with the ota2 update type).
146 | -C, --legacy Emulate the behaviour of yifanlu's KindleTool regarding directories. By default, we behave like tar:
147 | every path passed on the commandline is stored as-is in the archive. This switch changes that, and store paths
148 | relative to the path passed on the commandline, like if we had chdir'ed into it.
149 |
150 | - KindleTool info <serialno>
151 |
152 | > Get the default root password.
153 | > Unless you changed your password manually, the first password shown will be the right one.
154 | > (The Kindle defaults to DES hashed passwords, which are truncated to 8 characters).
155 | > If you're looking for the recovery MMC export password, that's the second one.
156 |
157 | - KindleTool version
158 |
159 | > Show some info about this KindleTool build.
160 |
161 | - KindleTool help
162 |
163 | > Show this help screen.
164 |
165 | ### Notices
166 | 1. If the variable KT_WITH_UNKNOWN_DEVCODES is set in your environment (no matter the value), some device checks will be relaxed with the create command.
167 | 2. If the variable KT_PKG_METADATA_DUMP is set in your environment, convert will dump header info in a shell-friendly format in the file this variable points to.
168 | 3. Updates with meta-strings will probably fail to run when passed to "Update Your Kindle".
169 | 4. Currently, even though OTA V2 supports updates that run on multiple devices, it is not possible to create an update package that will run on both FW 4.x (Kindle 4) and FW 5.x (Basically everything since the Kindle Touch).
170 |
171 | ### Building
172 |
173 | See [COMPILING](/COMPILING).
174 |
175 |
176 |
--------------------------------------------------------------------------------
/tools/kindle_model_sort.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import sys
4 | from operator import itemgetter
5 |
6 | # NOTE: Pilfered from https://code.activestate.com/recipes/65212/
7 | # FIXME: Crockford's Base32, but with the "L" & "U" re-added in?
8 | # NOTE: In case this ever needs fixing, don't forget to update the horrible regex used in MRPI to parse our verbose output,
9 | # to avoid a repeat of what r16043 fixed...
10 | def baseN(num, base, numerals="0123456789ABCDEFGHJKLMNPQRSTUVWX"):
11 | if num == 0:
12 | return "0"
13 |
14 | if num < 0:
15 | return '-' + baseN((-1) * num, base, numerals)
16 |
17 | if not 2 <= base <= len(numerals):
18 | raise ValueError('Base must be between 2 and %d' % len(numerals))
19 |
20 | left_digits = num // base
21 | if left_digits == 0:
22 | return numerals[num % base]
23 | else:
24 | return baseN(left_digits, base, numerals) + numerals[num % base]
25 |
26 | # NOTE: Pilfered from https://stackoverflow.com/questions/1119722/
27 | BASE_LIST = tuple("0123456789ABCDEFGHJKLMNPQRSTUVWX")
28 | BASE_DICT = dict((c, v) for v, c in enumerate(BASE_LIST))
29 | BASE_LEN = len(BASE_LIST)
30 |
31 | def devCode(string):
32 | num = 0
33 | for char in string:
34 | num = num * BASE_LEN + BASE_DICT[char]
35 | return num
36 |
37 | # Just do a conversion (SN -> devCode) if we were passed an argument...
38 | if len(sys.argv) > 1:
39 | print("0x{:03X}".format(devCode(sys.argv[1])))
40 | exit()
41 |
42 | model_tuples = [
43 | ('Kindle1', 0x01, 'ATVPDKIKX0DER'),
44 | ('Kindle2US', 0x02, 'A3UN6WX5RRO2AG'),
45 | ('Kindle2International', 0x03, 'A1F83G8C2ARO7P'),
46 | ('KindleDXUS', 0x04, 'A1PA6795UKMFR9'),
47 | ('KindleDXInternational', 0x05, 'A13V1IB3VIYZZH'),
48 | ('ValidKindleUnknown_0x07', 0x07, 'A2EUQ1WTGCTBG2'),
49 | ('Kindle3WiFi3G', 0x06, 'A1VC38T7YXB528'),
50 | ('Kindle3WiFi', 0x08, 'A3AEGXETSR30VB'),
51 | ('KindleDXGraphite', 0x09, 'A3P5ROKL5A1OLE'),
52 | ('Kindle3WiFi3GEurope', 0x0A, 'A3JWKAKR8XB7XF'),
53 | ('ValidKindleUnknown_0x0B', 0x0B, 'A1X6FK5RDHNB96'),
54 | ('ValidKindleUnknown_0x0C', 0x0C, 'AN1VRQENFRJN5'),
55 | ('ValidKindleUnknown_0x0D', 0x0D, 'A3DWYIK6Y9EEQB'),
56 | ('Kindle4NonTouch', 0x0E, 'A3R76HOPU0Z2CB'),
57 | ('Kindle5TouchWiFi3G', 0x0F, 'A1IM4EOPHS76S7'),
58 | ('Kindle5TouchWiFi3GEurope', 0x10, 'A138L1TOL8PIJT'),
59 | ('Kindle5TouchWiFi', 0x11, 'A3T4TT2Z381HKD'),
60 | ('Kindle5TouchUnknown', 0x12, 'A3LJ5WMKNRFKQS'),
61 | ('KindlePaperWhiteWiFi3G', 0x1B, 'A1JYRMDPD0WRC1'),
62 | ('KindlePaperWhiteWiFi3GCanada', 0x1C, 'A1U5RCOVU0NYF2'),
63 | ('KindlePaperWhiteWiFi3GEurope', 0x1D, 'A1I7TFXKDRQDZL'),
64 | ('KindlePaperWhiteWiFi3GJapan', 0x1F, 'A1K21FY43GMZF8'),
65 | ('KindlePaperWhiteWiFi3GBrazil', 0x20, 'A3RN7G7QC5MWSZ'),
66 | ('Kindle4NonTouchBlack', 0x23, 'AMMK0LS9EDNM8'),
67 | ('KindlePaperWhiteWiFi', 0x24, 'A3VSAZHKW7EWVH'),
68 | ('KindlePaperWhite2WiFiJapan', 0x5A, 'A1XFE4LQM16OSW'),
69 | ('KindlePaperWhite2WiFi', 0xD4, 'A2X1JOFWQIYV75'),
70 | ('KindlePaperWhite2WiFi3G', 0xD5, 'A2LTUGSV2JQ93O'),
71 | ('KindlePaperWhite2WiFi3GCanada', 0xD6, 'A3CG2RMGG8NQEJ'),
72 | ('KindlePaperWhite2WiFi3GEurope', 0xD7, 'A2RWEQK36M6DUE'),
73 | ('KindlePaperWhite2WiFi3GRussia', 0xD8, 'A3DM9ZTSZGUSMW'),
74 | ('KindlePaperWhite2WiFi3GJapan', 0xF2, 'A36L7QE2V0XKCZ'),
75 | ('KindlePaperWhite2WiFi4GBInternational', 0x17, 'A3I3CR3NPZFVHY'),
76 | ('KindlePaperWhite2WiFi3G4GBCanada', 0x5F, 'A16EMENY0O3Z2H'),
77 | ('KindlePaperWhite2WiFi3G4GBEurope', 0x60, 'A3D1N3J5SXSYPF'),
78 | ('KindlePaperWhite2WiFi3G4GBBrazil', 0x61, 'A3NRQ2KXEO33BF'),
79 | ('KindlePaperWhite2WiFi3G4GB', 0x62, 'A3QT0UFVNUDPAE'),
80 | ('KindlePaperWhite2Unknown_0xF4', 0xF4, 'A3JI3C11GUW6OM'),
81 | ('KindlePaperWhite2Unknown_0xF9', 0xF9, 'A148QFVDZ3MQ8V'),
82 | ('KindleVoyageWiFi', 0x13, 'A3FE7AD5N5R11'),
83 | ('KindleVoyageWiFi3G', 0x54, 'A1VHVRSIVA49BF'),
84 | ('KindleVoyageWiFi3GJapan', 0x2A, 'A2KSI370ME58SV'),
85 | ('KindleVoyageWiFi3G_0x4F', 0x4F, 'AEK24W3B90XSI'),
86 | ('KindleVoyageWiFi3GMexico', 0x52, 'A66ZTOXC8UWFP'),
87 | ('KindleVoyageWiFi3GEurope', 0x53, 'A26JMGYIXWMKGL'),
88 | ('KindleBasic', 0xC6, 'A2TNPB8EVLW5FA'),
89 | ('ValidKindleUnknown_0x99', 0x99, 'A2I96HKA5TK143'),
90 | ('KindleBasicKiwi', 0xDD, 'A9N06WOIL49CA'),
91 | ('ValidKindleUnknown_0x16', 0x16),
92 | ('ValidKindleUnknown_0x21', 0x21),
93 | ('KindlePaperWhite3WiFi', 0x201, 'A21RY355YUXQAF'), # 0G1
94 | ('KindlePaperWhite3WiFi3G', 0x202, 'A6S0KGW65V1TV'), # 0G2
95 | ('KindlePaperWhite3WiFi3GMexico', 0x204, 'A3P87LH4DLAKE2'), # 0G4
96 | ('KindlePaperWhite3WiFi3GEurope', 0x205, 'A3OLIINW419WLP'), # 0G5
97 | ('KindlePaperWhite3WiFi3GCanada', 0x206, 'AOPKCG97868D2'), # 0G6
98 | ('KindlePaperWhite3WiFi3GJapan', 0x207, 'A3MTNJ7FDYZOPO'), # 0G7
99 | ('KindlePaperWhite3WhiteWiFi', 0x26B, 'A21RY355YUXQAF'), # 0KB
100 | ('KindlePaperWhite3WhiteWiFi3GJapan', 0x26C, 'A3MTNJ7FDYZOPO'), # 0KC
101 | ('KindlePW3WhiteUnknown_0KD', 0x26D, 'AOPKCG97868D2'), # 0KD?
102 | ('KindlePaperWhite3WhiteWiFi3GInternational', 0x26E, 'A3OLIINW419WLP'), # 0KE
103 | ('KindlePaperWhite3WhiteWiFi3GInternationalBis', 0x26F, 'A6S0KGW65V1TV'), # 0KF
104 | ('KindlePW3WhiteUnknown_0KG', 0x270, 'A3P87LH4DLAKE2'), # 0KG?
105 | ('KindlePaperWhite3WiFi32GBJapanBlack', 0x293, 'A2T9E09EBKRBWU'), # 0LK
106 | ('KindlePaperWhite3WiFi32GBJapanWhite', 0x294, 'A2T9E09EBKRBWU'), # 0LL
107 | ('KindlePW3Unknown_TTT', 0x6F7B, 'A21RY355YUXQAF'), # TTT?
108 | ('KindleOasisWiFi', 0x20C, 'A2NP90AR02CXEG'), # 0GC
109 | ('KindleOasisWiFi3G', 0x20D, 'A370DV3BFIHFD3'), # 0GD
110 | ('KindleOasisWiFi3GInternational', 0x219, 'A21R12JDS0I7HR'), # 0GR
111 | ('KindleOasisUnknown_0GS', 0x21A, 'A2G9XCYZJMNLQK'), # 0GS?
112 | ('KindleOasisWiFi3GChina', 0x21B, 'AIOUHGSC1FXK5'), # 0GT
113 | ('KindleOasisWiFi3GEurope', 0x21C, 'A1VYPQEAEVB479'), # 0GU
114 | ('KindleBasic2Unknown_0DU', 0x1BC), # 0DU?
115 | ('KindleBasic2', 0x269, 'A363JBKK6AP29Q'), # 0K9
116 | ('KindleBasic2White', 0x26A, 'A363JBKK6AP29Q'), # 0KA
117 | ('KindleOasis2Unknown_0LM', 0x295, 'A2AVNKP6ZINL5'), # 0LM?
118 | ('KindleOasis2Unknown_0LN', 0x296, 'A1SZ6LXIZK7826'), # 0LN?
119 | ('KindleOasis2Unknown_0LP', 0x297, 'A3M646A6GS49CA'), # 0LP?
120 | ('KindleOasis2Unknown_0LQ', 0x298, 'A39S6AFBERWZOH'), # 0LQ?
121 | ('KindleOasis2WiFi32GBChampagne', 0x2E1, 'A1SZ6LXIZK7826'), # 0P1
122 | ('KindleOasis2Unknown_0P2', 0x2E2, 'A2AVNKP6ZINL5'), # 0P2?
123 | ('KindleOasis2Unknown_0P6', 0x2E6, 'A3M646A6GS49CA'), # 0P6
124 | ('KindleOasis2Unknown_0P7', 0x2E7, 'A39S6AFBERWZOH'), # 0P7?
125 | ('KindleOasis2WiFi8GB', 0x2E8, 'A1SZ6LXIZK7826'), # 0P8
126 | ('KindleOasis2WiFi3G32GB', 0x341, 'A2AVNKP6ZINL5'), # 0S1
127 | ('KindleOasis2WiFi3G32GBEurope', 0x342, 'A3M646A6GS49CA'), # 0S2
128 | ('KindleOasis2Unknown_0S3', 0x343, 'A39S6AFBERWZOH'), # 0S3?
129 | ('KindleOasis2Unknown_0S4', 0x344, 'A1SZ6LXIZK7826'), # 0S4?
130 | ('KindleOasis2Unknown_0S7', 0x347, 'A1SZ6LXIZK7826'), # 0S7?
131 | ('KindleOasis2WiFi32GB', 0x34A, 'A1SZ6LXIZK7826'), # 0SA
132 | ('KindlePaperWhite4WiFi8GB', 0x2F7, 'AJRLVDTOPT1LE'), # 0PP
133 | ('KindlePaperWhite4WiFi4G32GB', 0x361, 'A3IT5K46YEJ8DG'), # 0T1
134 | ('KindlePaperWhite4WiFi4G32GBEurope', 0x362, 'A2J0U8ZY7AYQWV'), # 0T2
135 | ('KindlePaperWhite4WiFi4G32GBJapan', 0x363, 'AV9Q59KU8EJQE'), # 0T3
136 | ('KindlePaperWhite4Unknown_0T4', 0x364, 'A27ME72Q2PS699'), # 0T4?
137 | ('KindlePaperWhite4Unknown_0T5', 0x365, 'A3IT5K46YEJ8DG'), # 0T5?
138 | ('KindlePaperWhite4WiFi32GB', 0x366, 'AJRLVDTOPT1LE'), # 0T6
139 | ('KindlePaperWhite4Unknown_0T7', 0x367, 'AJRLVDTOPT1LE'), # 0T7?
140 | ('KindlePaperWhite4Unknown_0TJ', 0x372, 'AJRLVDTOPT1LE'), # 0TJ?
141 | ('KindlePaperWhite4Unknown_0TK', 0x373, 'AJRLVDTOPT1LE'), # 0TK?
142 | ('KindlePaperWhite4Unknown_0TL', 0x374, 'A2J0U8ZY7AYQWV'), # 0TL?
143 | ('KindlePaperWhite4Unknown_0TM', 0x375, 'AV9Q59KU8EJQE'), # 0TM?
144 | ('KindlePaperWhite4Unknown_0TN', 0x376, 'A27ME72Q2PS699'), # 0TN?
145 | ('KindlePaperWhite4WiFi8GBIndia', 0x402, 'AJRLVDTOPT1LE'), # 102
146 | ('KindlePaperWhite4WiFi32GBIndia', 0x403, 'A2J0U8ZY7AYQWV'), # 103
147 | ('KindlePaperWhite4WiFi32GBBlue', 0x4D8, 'AJRLVDTOPT1LE'), # 16Q
148 | ('KindlePaperWhite4WiFi32GBPlum', 0x4D9, 'AJRLVDTOPT1LE'), # 16R
149 | ('KindlePaperWhite4WiFi32GBSage', 0x4DA, 'AJRLVDTOPT1LE'), # 16S
150 | ('KindlePaperWhite4WiFi8GBBlue', 0x4DB, 'AJRLVDTOPT1LE'), # 16T
151 | ('KindlePaperWhite4WiFi8GBPlum', 0x4DC, 'AJRLVDTOPT1LE'), # 16U
152 | ('KindlePaperWhite4WiFi8GBSage', 0x4DD, 'AJRLVDTOPT1LE'), # 16V
153 | ('KindlePW4Unknown_0PL', 0x2F4, 'A3IT5K46YEJ8DG'), # 0PL?
154 | ('KindleBasic3', 0x414, 'AHU5VU98ZZYIL'), # 10L
155 | ('KindleBasic3White8GB', 0x3CF, 'AHU5VU98ZZYIL'), # 0WF
156 | ('KindleBasic3Unknown_0WG', 0x3D0, 'AHU5VU98ZZYIL'), # 0WG?
157 | ('KindleBasic3White', 0x3D1, 'AHU5VU98ZZYIL'), # 0WH
158 | ('KindleBasic3Unknown_0WJ', 0x3D2, 'AHU5VU98ZZYIL'), # 0WJ?
159 | ('KindleBasic3KidsEdition', 0x3AB, 'AHU5VU98ZZYIL'), # 0VB
160 | ('KindleOasis3WiFi32GBChampagne', 0x434, 'A2NW3VDYR5P8Z0'), # 11L
161 | ('KindleOasis3WiFi4G32GBJapan', 0x3D8, 'A28MDQJEP7D12S'), # 0WQ
162 | ('KindleOasis3WiFi4G32GBIndia', 0x3D7, 'A2M7UZTFTYKRHM'), # 0WP
163 | ('KindleOasis3WiFi4G32GB', 0x3D6, 'AB6KN53ZYVL6D'), # 0WN
164 | ('KindleOasis3WiFi32GB', 0x3D5, 'A2NW3VDYR5P8Z0'), # 0WM
165 | ('KindleOasis3WiFi8GB', 0x3D4, 'A2NW3VDYR5P8Z0'), # 0WL
166 | ('KindlePaperWhite5SignatureEdition', 0x690, 'A328XUBPG464LQ'), # 1LG
167 | ('KindlePaperWhite5Unknown_1Q0', 0x700, 'A328XUBPG464LQ'), # 1Q0?
168 | ('KindlePaperWhite5', 0x6FF, 'A328XUBPG464LQ'), # 1PX
169 | ('KindlePaperWhite5Unknown_1VD', 0x7AD, 'A328XUBPG464LQ'), # 1VD?
170 | ('KindlePaperWhite5SE_219', 0x829, 'A328XUBPG464LQ'), # 219
171 | ('KindlePaperWhite5_21A', 0x82A, 'A328XUBPG464LQ'), # 21A
172 | ('KindlePaperWhite5SE_2BH', 0x971, 'A328XUBPG464LQ'), # 2BH
173 | ('KindlePaperWhite5Unknown_2BJ', 0x972, 'A328XUBPG464LQ'), # 2BJ?
174 | ('KindlePaperWhite5_2DK', 0x9B3, 'A328XUBPG464LQ'), # 2DK
175 | ('KindleBasic4Unknown_22D', 0x84D, 'A1S35GJCTB6VUN'), # 22D?
176 | ('KindleBasic4Unknown_25T', 0x8BB, 'A1S35GJCTB6VUN'), # 25T?
177 | ('KindleBasic4Unknown_23A', 0x86A, 'A1S35GJCTB6VUN'), # 23A?
178 | ('KindleBasic4_2AQ', 0x958, 'A1S35GJCTB6VUN'), # 2AQ
179 | ('KindleBasic4_2AP', 0x957, 'A1S35GJCTB6VUN'), # 2AP
180 | ('KindleBasic4Unknown_1XH', 0x7F1, 'A1S35GJCTB6VUN'), # 1XH?
181 | ('KindleBasic4Unknown_22C', 0x84C, 'A1S35GJCTB6VUN'), # 22C?
182 | ('KindleScribeUnknown_27J', 0x8F2, 'A12KI9K1KHHBVF'), # 27J?
183 | ('KindleScribeUnknown_2BL', 0x974, 'A12KI9K1KHHBVF'), # 2BL?
184 | ('KindleScribeUnknown_263', 0x8C3, 'A12KI9K1KHHBVF'), # 263?
185 | ('KindleScribe16GB_227', 0x847, 'A12KI9K1KHHBVF'), # 227
186 | ('KindleScribeUnknown_2BM', 0x975, 'A12KI9K1KHHBVF'), # 2BM?
187 | ('KindleScribe_23L', 0x874, 'A12KI9K1KHHBVF'), # 23L
188 | ('KindleScribe64GB_23M', 0x875, 'A12KI9K1KHHBVF'), # 23M
189 | ('KindleScribeUnknown_270', 0x8E0, 'A12KI9K1KHHBVF'), # 270?
190 | ('KindleBasic5Unknown_3L5', 0xE85, 'A2AJ1N357FEMTV'), # 3L5?
191 | ('KindleBasic5Unknown_3L6', 0xE86, 'A2AJ1N357FEMTV'), # 3L6?
192 | ('KindleBasic5Unknown_3L4', 0xE84, 'A2AJ1N357FEMTV'), # 3L4?
193 | ('KindleBasic5Unknown_3L3', 0xE83, 'A2AJ1N357FEMTV'), # 3L3?
194 | ('KindleBasic5Unknown_A89', 0x2909, 'A2AJ1N357FEMTV'), # A89?
195 | ('KindleBasic5Unknown_3L2', 0xE82, 'A2AJ1N357FEMTV'), # 3L2?
196 | ('KindleBasic5Unknown_3KM', 0xE75, 'A2AJ1N357FEMTV'), # 3KM
197 | ('KindlePaperWhite6Unknown_349', 0xC89, 'A1BF5SA90HOYO2'), # 349?
198 | ('KindlePaperWhite6Unknown_346', 0xC86, 'A1BF5SA90HOYO2'), # 346?
199 | ('KindlePaperWhite6Unknown_33X', 0xC7F, 'A1BF5SA90HOYO2'), # 33X
200 | ('KindlePaperWhite6Unknown_33W', 0xC7E, 'A1BF5SA90HOYO2'), # 33W?
201 | ('KindlePaperWhite6Unknown_3HA', 0xE2A, 'A1BF5SA90HOYO2'), # 3HA?
202 | ('KindlePaperWhite6Unknown_3H5', 0xE25, 'A1BF5SA90HOYO2'), # 3H5?
203 | ('KindlePaperWhite6Unknown_3H3', 0xE23, 'A1BF5SA90HOYO2'), # 3H3?
204 | ('KindlePaperWhite6Unknown_3H8', 0xE28, 'A1BF5SA90HOYO2'), # 3H8?
205 | ('KindlePaperWhite6Unknown_3J5', 0xE45, 'A1BF5SA90HOYO2'), # 3J5?
206 | ('KindlePaperWhite6Unknown_3JS', 0xE5A, 'A1BF5SA90HOYO2'), # 3JS?
207 | ('KindleScribe2Unknown_3V0', 0xFA0, 'A3TY6T3X94EBV6'), # 3V0?
208 | ('KindleScribe2Unknown_3V1', 0xFA1, 'A3TY6T3X94EBV6'), # 3V1?
209 | ('KindleScribe2Unknown_3X5', 0xFE5, 'A3TY6T3X94EBV6'), # 3X5?
210 | ('KindleScribe2Unknown_3UV', 0xF9D, 'A3TY6T3X94EBV6'), # 3UV?
211 | ('KindleScribe2Unknown_3X4', 0xFE4, 'A3TY6T3X94EBV6'), # 3X4?
212 | ('KindleScribe2Unknown_3X3', 0xFE3, 'A3TY6T3X94EBV6'), # 3X3?
213 | ('KindleScribe2Unknown_41E', 0x102E, 'A3TY6T3X94EBV6'), # 41E?
214 | ('KindleScribe2Unknown_41D', 0x102D, 'A3TY6T3X94EBV6'), # 41D?
215 | ('KindleColorSoftUnknown_3H9', 0xE29, 'A2CU9ZQDNZFID4'), # 3H9?
216 | ('KindleColorSoftUnknown_3H4', 0xE24, 'A2CU9ZQDNZFID4'), # 3H4?
217 | ('KindleColorSoftUnknown_3HB', 0xE2B, 'A2CU9ZQDNZFID4'), # 3HB?
218 | ('KindleColorSoftUnknown_3H6', 0xE26, 'A2CU9ZQDNZFID4'), # 3H6?
219 | ('KindleColorSoftUnknown_3H2', 0xE22, 'A2CU9ZQDNZFID4'), # 3H2?
220 | ('KindleColorSoftUnknown_34X', 0xC9F, 'A2CU9ZQDNZFID4'), # 34X?
221 | ('KindleColorSoftUnknown_3H7', 0xE27, 'A2CU9ZQDNZFID4'), # 3H7
222 | ('KindleColorSoftUnknown_3JT', 0xE5B, 'A2CU9ZQDNZFID4'), # 3JT?
223 | ('KindleColorSoftUnknown_3J6', 0xE46, 'A2CU9ZQDNZFID4'), # 3J6?
224 | ('KindleColorSoftUnknown_456', 0x10A6, 'A2CU9ZQDNZFID4'), # 456?
225 | ('KindleColorSoftUnknown_455', 0x10A5, 'A2CU9ZQDNZFID4'), # 455?
226 | ('KindleColorSoftUnknown_4EP', 0x11D7, 'A2CU9ZQDNZFID4'), # 4EP?
227 | ('KindleUnknown', 0x00)
228 | ]
229 |
230 | # We need the ID of a few very specific cutoff models...
231 | wario_cutoff_id = 0
232 | for i, v in enumerate(model_tuples):
233 | if v[0] == 'KindleVoyageWiFi3GJapan':
234 | wario_cutoff_id = v[1]
235 |
236 |
237 | print('Kindle models sorted by device code\n')
238 | for t in sorted(model_tuples, key=itemgetter(1)):
239 | # Handle the base32hex device IDs in a dedicated manner...
240 | if t[1] > 0xFF:
241 | print("{:<45} 0x{:03X} ({:0>3}) {:4} {:<14}".format(t[0], t[1], baseN(t[1], 32), '', t[2] if len(t) == 3 else ''))
242 | else:
243 | print("{:<45} 0x{:02X} {:11} {:<14}".format(t[0], t[1], '', t[2] if len(t) == 3 else ''))
244 |
245 | print('\nKindle models >= KindleVoyageWiFi3GJapan (i.e., Platform >= Wario)\n')
246 | for t in model_tuples:
247 | if t[1] >= wario_cutoff_id:
248 | if t[1] > 0xFF:
249 | print("{:<45} 0x{:03X} ({:0>3})".format(t[0], t[1], baseN(t[1], 32)))
250 | else:
251 | print("{:<45} 0x{:02X}".format(t[0], t[1]))
252 | # # That's to double-check that everything's sane for KindleTool's info command...
253 | # else:
254 | # print("!!{:<44}!!".format(t[0]))
255 |
256 | print('\nKindle models with new device code decoding (i.e., >= PW3)\n')
257 | for t in model_tuples:
258 | if t[1] >= wario_cutoff_id:
259 | if t[1] > 0xFF:
260 | print("{:<45} 0x{:03X} ({:0>3} <-> 0x{:03X})".format(t[0], t[1], baseN(t[1], 32), devCode(baseN(t[1], 32))))
261 |
--------------------------------------------------------------------------------
/tools/kindletool-static-build.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | OSTYPE="$(uname -s)"
5 | ARCH="$(uname -m)"
6 | KERNREL="$(uname -r)"
7 |
8 | # Remember where we are...
9 | SCRIPT_NAME="${BASH_SOURCE[0]-${(%):-%x}}"
10 | if [[ "${OSTYPE}" == "Linux" ]] ; then
11 | SCRIPT_BASE_DIR="$(readlink -f "${SCRIPT_NAME%/*}")"
12 | else
13 | SCRIPT_BASE_DIR="$(greadlink -f "${SCRIPT_NAME%/*}")"
14 | fi
15 |
16 | ## Setup parallellization... Shamelessly stolen from crosstool-ng ;).
17 | AUTO_JOBS=$(($(getconf _NPROCESSORS_ONLN 2> /dev/null || echo 0) + 1))
18 | JOBSFLAGS="-j${AUTO_JOBS}"
19 |
20 | ## Linux!
21 | Build_Linux() {
22 | echo "* Preparing a static KindleTool build on Linux . . ."
23 | if [[ "${ARCH}" == "x86_64" ]] ; then
24 | export CFLAGS="-march=core2 -pipe -O2 -fomit-frame-pointer -frename-registers -fweb -fno-stack-protector -U_FORTIFY_SOURCE"
25 | export CXXFLAGS="-march=core2 -pipe -O2 -fomit-frame-pointer -frename-registers -fweb -fno-stack-protector -U_FORTIFY_SOURCE"
26 | export GMPABI="64"
27 | # Mangle i686 builds on my desktop...
28 | if [[ "${KERNREL}" == *-niluje* ]] && [[ "${KERNREL}" != *-hardened* ]] ; then
29 | export CFLAGS="-march=i686 -mtune=generic -m32 -pipe -O2 -fomit-frame-pointer -fno-stack-protector -U_FORTIFY_SOURCE"
30 | export CXXFLAGS="-march=i686 -mtune=generic -m32 -pipe -O2 -fomit-frame-pointer -fno-stack-protector -U_FORTIFY_SOURCE"
31 | export GMPABI="32"
32 | ARCH="i686"
33 | fi
34 | else
35 | export CFLAGS="-march=i686 -mtune=generic -pipe -O2 -fomit-frame-pointer -fno-stack-protector -U_FORTIFY_SOURCE"
36 | export CXXFLAGS="-march=i686 -mtune=generic -pipe -O2 -fomit-frame-pointer -fno-stack-protector -U_FORTIFY_SOURCE"
37 | export GMPABI="32"
38 | fi
39 |
40 | GMP_VER="6.2.1"
41 | GMP_DIR="gmp-${GMP_VER%a}"
42 | NETTLE_VER="3.6"
43 | NETTLE_DIR="nettle-${NETTLE_VER}"
44 | LIBARCHIVE_VER="3.5.0"
45 | LIBARCHIVE_DIR="libarchive-${LIBARCHIVE_VER}"
46 |
47 | # Make sure we're up to date
48 | git pull
49 |
50 | # Get out of our git tree
51 | cd ../..
52 |
53 | KT_SYSROOT="${PWD}/kt-sysroot-lin-${ARCH}"
54 | # NOTE: Use -isystem so that gmp doesn't do crazy stuff...
55 | export CPPFLAGS="-isystem${KT_SYSROOT}/include"
56 | export LDFLAGS="-L${KT_SYSROOT}/lib -Wl,-O1 -Wl,--as-needed"
57 |
58 | BASE_PKG_CONFIG_PATH="${KT_SYSROOT}/lib/pkgconfig"
59 | BASE_PKG_CONFIG_LIBDIR="${KT_SYSROOT}/lib/pkgconfig"
60 | export PKG_CONFIG_DIR=
61 | export PKG_CONFIG_PATH="${BASE_PKG_CONFIG_PATH}"
62 | export PKG_CONFIG_LIBDIR="${BASE_PKG_CONFIG_LIBDIR}"
63 |
64 | # GMP
65 | if [[ ! -d "${GMP_DIR}" ]] ; then
66 | echo "* Building ${GMP_DIR} . . ."
67 | echo ""
68 | if [[ ! -f "./${GMP_DIR}.tar.xz" ]] ; then
69 | wget -O "./${GMP_DIR}.tar.xz" "https://gmplib.org/download/gmp/${GMP_DIR}.tar.xz"
70 | fi
71 | tar -xvJf ./${GMP_DIR}.tar.xz
72 | cd ${GMP_DIR}
73 | autoreconf -fi
74 | libtoolize
75 | ./configure ABI=${GMPABI} --prefix="${KT_SYSROOT}" --enable-static --disable-shared --disable-cxx
76 | make ${JOBSFLAGS}
77 | make install
78 | cd ..
79 | fi
80 |
81 | # nettle
82 | if [[ "${USE_STABLE_NETTLE}" == "true" ]] ; then
83 | if [[ ! -d "${NETTLE_DIR}" ]] ; then
84 | echo "* Building ${NETTLE_DIR} . . ."
85 | echo ""
86 | if [[ ! -f "./${NETTLE_DIR}.tar.gz" ]] ; then
87 | wget -O "./${NETTLE_DIR}.tar.gz" "http://www.lysator.liu.se/~nisse/archive/${NETTLE_DIR}.tar.gz"
88 | fi
89 | tar -xvzf ./${NETTLE_DIR}.tar.gz
90 | cd ${NETTLE_DIR}
91 | sed -e '/CFLAGS=/s: -ggdb3::' -e 's/solaris\*)/sunldsolaris*)/' -i configure.ac
92 | sed -e '/SUBDIRS/s/testsuite examples//' -i Makefile.in
93 | autoreconf -fi
94 | ./configure --prefix="${KT_SYSROOT}" --libdir="${KT_SYSROOT}/lib" --enable-static --disable-shared --enable-public-key --disable-openssl --disable-documentation
95 | make ${JOBSFLAGS}
96 | make install
97 | cd ..
98 | fi
99 | else
100 | if [[ ! -d "nettle-git" ]] ; then
101 | echo "* Building nettle . . ."
102 | echo ""
103 | git clone https://git.lysator.liu.se/nettle/nettle.git nettle-git
104 | cd nettle-git
105 | sed -e '/CFLAGS=/s: -ggdb3::' -e 's/solaris\*)/sunldsolaris*)/' -i configure.ac
106 | sed -e '/SUBDIRS/s/testsuite examples//' -i Makefile.in
107 | sh ./.bootstrap
108 | ./configure --prefix="${KT_SYSROOT}" --libdir="${KT_SYSROOT}/lib" --enable-static --disable-shared --enable-public-key --disable-openssl --disable-documentation
109 | make ${JOBSFLAGS}
110 | make install
111 | cd ..
112 | fi
113 | fi
114 |
115 | # libarchive
116 | if [[ "${USE_STABLE_LIBARCHIVE}" == "true" ]] ; then
117 | if [[ ! -d "${LIBARCHIVE_DIR}" ]] ; then
118 | echo "* Building ${LIBARCHIVE_DIR} . . ."
119 | echo ""
120 | if [[ ! -f "./${LIBARCHIVE_DIR}.tar.gz" ]] ; then
121 | wget -O "./${LIBARCHIVE_DIR}.tar.gz" "http://github.com/libarchive/libarchive/archive/v${LIBARCHIVE_VER}.tar.gz"
122 | fi
123 | tar -xvzf ./${LIBARCHIVE_DIR}.tar.gz
124 | cd ${LIBARCHIVE_DIR}
125 | export ac_cv_header_ext2fs_ext2_fs_h=0
126 | ./build/autogen.sh
127 | ./configure --prefix="${KT_SYSROOT}" --enable-static --disable-shared --disable-xattr --disable-acl --with-zlib --without-bz2lib --without-lzmadec --without-iconv --without-lzma --with-nettle --without-openssl --without-expat --without-xml2 --without-lz4 --without-zstd
128 | make ${JOBSFLAGS}
129 | make install
130 | unset ac_cv_header_ext2fs_ext2_fs_h
131 | cd ..
132 | fi
133 | else
134 | if [[ ! -d "libarchive-git" ]] ; then
135 | echo "* Building libarchive . . ."
136 | echo ""
137 | git clone https://github.com/libarchive/libarchive.git libarchive-git
138 | cd libarchive-git
139 | # Kill -Werror, git master doesn't always build with it...
140 | sed -e 's/-Werror //' -i ./Makefile.am
141 | export ac_cv_header_ext2fs_ext2_fs_h=0
142 | ./build/autogen.sh
143 | ./configure --prefix="${KT_SYSROOT}" --enable-static --disable-shared --disable-xattr --disable-acl --with-zlib --without-bz2lib --without-lzmadec --without-iconv --without-lzma --with-nettle --without-openssl --without-expat --without-xml2 --without-lz4 --without-zstd
144 | make ${JOBSFLAGS}
145 | make install
146 | unset ac_cv_header_ext2fs_ext2_fs_h
147 | cd ..
148 | fi
149 | fi
150 |
151 | # Build KT package credits
152 | cat > CREDITS << EOF
153 | * kindletool:
154 |
155 | KindleTool, Copyright (C) 2011-2012 Yifan Lu & Copyright (C) 2012-2023 NiLuJe, licensed under the GNU General Public License version 3+ (http://www.gnu.org/licenses/gpl.html).
156 | (https://github.com/NiLuJe/KindleTool/)
157 |
158 | |
159 | |-> libarchive, Copyright (C) Tim Kientzle, licensed under the New BSD License (http://www.opensource.org/licenses/bsd-license.php)
160 | | (http://libarchive.github.com/)
161 | |
162 | |-> GMP, GNU MP Library, Copyright 1991-2018 Free Software Foundation, Inc.,
163 | | licensed under the GNU Lesser General Public License version 3+ (http://www.gnu.org/licenses/lgpl.html).
164 | | (http://gmplib.org/)
165 | |
166 | \`-> nettle, Copyright (C) 2001-2018 Niels Möller,
167 | licensed under the GNU Lesser General Public License version 2.1+ (https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
168 | (http://www.lysator.liu.se/~nisse/nettle)
169 | EOF
170 |
171 | # KindleTool
172 | echo "* Building KindleTool . . ."
173 | echo ""
174 | # Fake user@host tag
175 | if [[ "$(whoami)" == "niluje" ]] ; then
176 | export KT_NO_USERATHOST_TAG="true"
177 | if [[ "${ARCH}" == "x86_64" ]] ; then
178 | export CFLAGS="-march=core2 -pipe -O2 -fomit-frame-pointer -frename-registers -fweb -fno-stack-protector -U_FORTIFY_SOURCE -DKT_USERATHOST='\"niluje@tyrande on Gentoo\"'"
179 | else
180 | export CFLAGS="-march=i686 -mtune=generic -m32 -pipe -O2 -fomit-frame-pointer -fno-stack-protector -U_FORTIFY_SOURCE -DKT_USERATHOST='\"niluje@tyrande on Gentoo\"'"
181 | fi
182 | fi
183 | cd KindleTool/KindleTool
184 | rm -rf lib includes
185 | make clean
186 | make strip
187 |
188 | # Package it
189 | git log --stat --graph > ../../ChangeLog
190 | ./version.sh PMS STATIC
191 | VER_FILE="VERSION"
192 | VER_CURRENT="$(<${VER_FILE})"
193 | # Strip the git commit
194 | REV="${VER_CURRENT%%-*}"
195 | #REV="${VER_CURRENT}"
196 | cd ../..
197 | cp -v KindleTool/KindleTool/Release/kindletool ./kindletool
198 | cp -v KindleTool/README.md ./README
199 | # Quick! Markdown => plaintext
200 | sed -si 's///g;s/<\/b>//g;s///g;s/<\/i>//g;s/<//g;s/&/&/g;s/^* / /g;s/*//g;s/>> /\t/g;s/^> / /g;s/^## //g;s/### //g;s/\t/ /g;s/^\([[:digit:]]\)\./ \1)/g;s/^#.*$//;s/[[:blank:]]*$//g' README
201 | cp -v KindleTool/KindleTool/kindletool.1 ./kindletool.1
202 | mv -v KindleTool/KindleTool/VERSION ./VERSION
203 | tar -cvzf "kindletool-${REV}-linux-${ARCH}.tar.gz" kindletool CREDITS README kindletool.1 ChangeLog VERSION
204 | rm -f kindletool CREDITS README kindletool.1 ChangeLog VERSION
205 | }
206 |
207 | # Win32 !
208 | Build_Cygwin() {
209 | echo "* Preparing a static KindleTool build on Cygwin . . ."
210 | # NOTE: Horrible hack. _NSIG isn't defined on Cygwin (it's defined in the linux headers), and CMake doesn't give a damn about CPPFLAGS.
211 | export CFLAGS="-D_NSIG=64 -march=i686 -mtune=generic -pipe -O2 -fomit-frame-pointer"
212 | export CXXFLAGS="-march=i686 -mtune=generic -pipe -O2 -fomit-frame-pointer"
213 | export LDFLAGS="-Wl,-O1 -Wl,--as-needed"
214 |
215 | LIBARCHIVE_VER="3.5.0"
216 | LIBARCHIVE_DIR="libarchive-${LIBARCHIVE_VER}"
217 |
218 | # Make sure we're up to date
219 | git pull
220 |
221 | # Get out of our git tree
222 | cd ../..
223 |
224 | # libarchive
225 | if [[ "${USE_STABLE_LIBARCHIVE}" == "true" ]] ; then
226 | if [[ ! -d "${LIBARCHIVE_DIR}" ]] ; then
227 | echo "* Building ${LIBARCHIVE_DIR} . . ."
228 | echo ""
229 | if [[ ! -f "./${LIBARCHIVE_DIR}.tar.gz" ]] ; then
230 | wget -O "./${LIBARCHIVE_DIR}.tar.gz" "http://github.com/libarchive/libarchive/archive/v${LIBARCHIVE_VER}.tar.gz"
231 | fi
232 | tar -xvzf ./${LIBARCHIVE_DIR}.tar.gz
233 | cd ${LIBARCHIVE_DIR}
234 | # NOTE: The win crypto stuff breaks horribly with the current Cygwin packages...
235 | # Switch to cmake, which will properly use Nettle on Cygwin, and hope it doesn't break everything, because the tests still fail horribly to build...
236 | cmake -DCMAKE_INSTALL_PREFIX="/usr" -DCMAKE_BUILD_TYPE="Release" -DENABLE_TEST=FALSE -DBUILD_TESTING=FALSE -DENABLE_TAR=ON -DENABLE_XATTR=FALSE -DENABLE_ACL=FALSE -DENABLE_ICONV=FALSE -DENABLE_CPIO=FALSE -DENABLE_NETTLE=ON -DENABLE_OPENSSL=FALSE -DENABLE_LZMA=FALSE -DENABLE_ZLIB=ON -DENABLE_BZip2=FALSE -DENABLE_EXPAT=FALSE -DENABLE_ZSTD=FALSE
237 | make
238 | make install
239 | cd ..
240 | fi
241 | else
242 | if [[ ! -d "libarchive-git" ]] ; then
243 | echo "* Building libarchive . . ."
244 | echo ""
245 | git clone https://github.com/libarchive/libarchive.git libarchive-git
246 | cd libarchive-git
247 | # NOTE: CMake isn't up to date in the Cygwin repos, but is new enough for our purposes. Revert part of 1052c76, it doesn't concern us on Cygwin anyway.
248 | sed -e 's/CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12 FATAL_ERROR)/CMAKE_MINIMUM_REQUIRED(VERSION 2.8.6 FATAL_ERROR)/' -i CMakeLists.txt
249 | # NOTE: The win crypto stuff breaks horribly with the current Cygwin packages...
250 | # Switch to cmake, which will properly use Nettle on Cygwin, and hope it doesn't break everything, because the tests still fail horribly to build...
251 | cmake -DCMAKE_INSTALL_PREFIX="/usr" -DCMAKE_BUILD_TYPE="Release" -DENABLE_TEST=FALSE -DBUILD_TESTING=FALSE -DENABLE_TAR=ON -DENABLE_XATTR=FALSE -DENABLE_ACL=FALSE -DENABLE_ICONV=FALSE -DENABLE_CPIO=FALSE -DENABLE_NETTLE=ON -DENABLE_OPENSSL=FALSE -DENABLE_LZMA=FALSE -DENABLE_ZLIB=ON -DENABLE_BZip2=FALSE -DENABLE_EXPAT=FALSE -DENABLE_ZSTD=FALSE
252 | make
253 | make install
254 | cd ..
255 | fi
256 | fi
257 |
258 | # Build KT package credits
259 | cat > CREDITS << EOF
260 | * kindletool.exe:
261 |
262 | KindleTool, Copyright (C) 2011-2012 Yifan Lu & Copyright (C) 2012-2023 NiLuJe, licensed under the GNU General Public License version 3+ (http://www.gnu.org/licenses/gpl.html).
263 | (https://github.com/NiLuJe/KindleTool/)
264 |
265 | |
266 | \`-> libarchive, Copyright (C) Tim Kientzle, licensed under the New BSD License (http://www.opensource.org/licenses/bsd-license.php)
267 | (http://libarchive.github.com/)
268 | EOF
269 |
270 | # KindleTool
271 | echo "* Building KindleTool . . ."
272 | echo ""
273 | # Fake user@host tag
274 | if [[ "$(whoami)" == "NiLuJe" ]] ; then
275 | export KT_NO_USERATHOST_TAG="true"
276 | export CFLAGS="-march=i686 -mtune=generic -pipe -O2 -fomit-frame-pointer -DKT_USERATHOST='\"NiLuJe@Tyrande on $(uname -s)\"'"
277 | fi
278 | cd KindleTool/KindleTool
279 | # Disable dynamic libraries...
280 | mv -v /usr/lib/libarchive.dll.a{,.disabled}
281 | mv -v /usr/bin/cygarchive-14.dll{,.disabled}
282 | make clean
283 | make strip
284 | ## Restore dynamic libraries...
285 | mv -v /usr/lib/libarchive.dll.a{.disabled,}
286 | mv -v /usr/bin/cygarchive-14.dll{.disabled,}
287 |
288 | # Package it
289 | git log --stat --graph > ../../ChangeLog
290 | ./version.sh PMS STATIC
291 | VER_FILE="VERSION"
292 | VER_CURRENT="$(<${VER_FILE})"
293 | # Strip the git commit
294 | REV="${VER_CURRENT%%-*}"
295 | #REV="${VER_CURRENT}"
296 | cd ../..
297 | cp -v KindleTool/KindleTool/Release/kindletool.exe ./kindletool.exe
298 | cp -v KindleTool/README.md ./README
299 | # Quick! Markdown => plaintext
300 | sed -si 's///g;s/<\/b>//g;s///g;s/<\/i>//g;s/<//g;s/&/&/g;s/^* / /g;s/*//g;s/>> /\t/g;s/^> / /g;s/^## //g;s/### //g;s/\t/ /g;s/^\([[:digit:]]\)\./ \1)/g;s/^#.*$//;s/[[:blank:]]*$//g' README
301 | mv -v KindleTool/KindleTool/VERSION ./VERSION
302 | # LF => CRLF...
303 | unix2dos CREDITS README ChangeLog
304 | 7z a -tzip "kindletool-${REV}-cygwin.zip" kindletool.exe CREDITS README ChangeLog VERSION
305 | rm -f kindletool.exe CREDITS README ChangeLog VERSION
306 | }
307 |
308 | # OS X !
309 | Build_OSX() {
310 | echo "* Preparing a static KindleTool build on OS X . . ."
311 | # Make sure it'll run on OS X 10.6, too
312 | export MACOSX_DEPLOYMENT_TARGET=10.6
313 | export CFLAGS="-march=core2 -pipe -O2 -fomit-frame-pointer -mmacosx-version-min=10.6"
314 | export CXXFLAGS="-march=core2 -pipe -O2 -fomit-frame-pointer -mmacosx-version-min=10.6"
315 | # NOTE: Don't pull fstatat & openat, they were introduced in 10.10, and I don't want to have to keep an old SDK around to handle this the right way...
316 | export ac_cv_func_fstatat=no
317 | export ac_cv_func_openat=no
318 |
319 | GMP_VER="6.2.1"
320 | GMP_DIR="gmp-${GMP_VER%a}"
321 | NETTLE_VER="3.6"
322 | NETTLE_DIR="nettle-${NETTLE_VER}"
323 | LIBARCHIVE_VER="3.5.0"
324 | LIBARCHIVE_DIR="libarchive-${LIBARCHIVE_VER}"
325 |
326 | # Make sure we're up to date
327 | git pull
328 |
329 | # Get out of our git tree
330 | cd ../..
331 |
332 | KT_SYSROOT="${PWD}/kt-sysroot-osx"
333 | # NOTE: We can't use -isystem because we'd be picking up Homebrew's includes in /usr/local...
334 | export CPPFLAGS="-I${KT_SYSROOT}/include"
335 | export LDFLAGS="-L${KT_SYSROOT}/lib"
336 |
337 | BASE_PKG_CONFIG_PATH="${KT_SYSROOT}/lib/pkgconfig"
338 | BASE_PKG_CONFIG_LIBDIR="${KT_SYSROOT}/lib/pkgconfig"
339 | export PKG_CONFIG_DIR=
340 | export PKG_CONFIG_PATH="${BASE_PKG_CONFIG_PATH}"
341 | export PKG_CONFIG_LIBDIR="${BASE_PKG_CONFIG_LIBDIR}"
342 |
343 | # GMP
344 | if [[ ! -d "${GMP_DIR}" ]] ; then
345 | echo "* Building ${GMP_DIR} . . ."
346 | echo ""
347 | if [[ ! -f "./${GMP_DIR}.tar.xz" ]] ; then
348 | curl -L "https://gmplib.org/download/gmp/${GMP_DIR}.tar.xz" -o "./${GMP_DIR}.tar.xz"
349 | fi
350 | tar -xvJf ./${GMP_DIR}.tar.xz
351 | cd ${GMP_DIR}
352 | # Don't target my host cpu...
353 | my_host="core2-$(clang --version | grep Target | awk '{print $2}' | cut -d- -f2-)"
354 | ./configure --host="${my_host}" --prefix="${KT_SYSROOT}" --enable-static --disable-shared --disable-cxx --with-pic
355 | make ${JOBSFLAGS}
356 | make install
357 | cd ..
358 | fi
359 |
360 | # nettle
361 | if [[ "${USE_STABLE_NETTLE}" == "true" ]] ; then
362 | if [[ ! -d "${NETTLE_DIR}" ]] ; then
363 | echo "* Building ${NETTLE_DIR} . . ."
364 | echo ""
365 | if [[ ! -f "./${NETTLE_DIR}.tar.gz" ]] ; then
366 | curl -L "http://www.lysator.liu.se/~nisse/archive/${NETTLE_DIR}.tar.gz" -o "./${NETTLE_DIR}.tar.gz"
367 | fi
368 | tar -xvzf ./${NETTLE_DIR}.tar.gz
369 | cd ${NETTLE_DIR}
370 | sed -e '/CFLAGS=/s: -ggdb3::' -e 's/solaris\*)/sunldsolaris*)/' -i '' configure.ac
371 | sed -e '/SUBDIRS/s/testsuite examples//' -i '' Makefile.in
372 | autoreconf -fi
373 | ./configure --prefix="${KT_SYSROOT}" --libdir="${KT_SYSROOT}/lib" --enable-static --disable-shared --enable-public-key --disable-openssl --disable-documentation
374 | make ${JOBSFLAGS}
375 | make install
376 | cd ..
377 | fi
378 | else
379 | if [[ ! -d "nettle-git" ]] ; then
380 | echo "* Building nettle . . ."
381 | echo ""
382 | git clone https://git.lysator.liu.se/nettle/nettle.git nettle-git
383 | cd nettle-git
384 | sed -e '/CFLAGS=/s: -ggdb3::' -e 's/solaris\*)/sunldsolaris*)/' -i '' configure.ac
385 | sed -e '/SUBDIRS/s/testsuite examples//' -i '' Makefile.in
386 | sh ./.bootstrap
387 | ./configure --prefix="${KT_SYSROOT}" --libdir="${KT_SYSROOT}/lib" --enable-static --disable-shared --enable-public-key --disable-openssl --disable-documentation
388 | make ${JOBSFLAGS}
389 | make install
390 | cd ..
391 | fi
392 | fi
393 |
394 | # libarchive
395 | if [[ "${USE_STABLE_LIBARCHIVE}" == "true" ]] ; then
396 | if [[ ! -d "${LIBARCHIVE_DIR}" ]] ; then
397 | echo "* Building ${LIBARCHIVE_DIR} . . ."
398 | echo ""
399 | if [[ ! -f "./${LIBARCHIVE_DIR}.tar.gz" ]] ; then
400 | curl -L "http://github.com/libarchive/libarchive/archive/v${LIBARCHIVE_VER}.tar.gz" -o "./${LIBARCHIVE_DIR}.tar.gz"
401 | fi
402 | tar -xvzf ./${LIBARCHIVE_DIR}.tar.gz
403 | cd ${LIBARCHIVE_DIR}
404 | ./build/autogen.sh
405 | ./configure --prefix="${KT_SYSROOT}" --enable-static --disable-shared --disable-xattr --disable-acl --with-zlib --without-bz2lib --without-lzmadec --without-iconv --without-lzma --with-nettle --without-openssl --without-expat --without-xml2 --without-lz4 --without-zstd
406 | make ${JOBSFLAGS}
407 | make install
408 | cd ..
409 | fi
410 | else
411 | if [[ ! -d "libarchive-git" ]] ; then
412 | echo "* Building libarchive . . ."
413 | echo ""
414 | git clone https://github.com/libarchive/libarchive.git libarchive-git
415 | cd libarchive-git
416 | # Kill -Werror, git master doesn't always build with it...
417 | sed -e 's/-Werror //' -i '' ./Makefile.am
418 | ./build/autogen.sh
419 | ./configure --prefix="${KT_SYSROOT}" --enable-static --disable-shared --disable-xattr --disable-acl --with-zlib --without-bz2lib --without-lzmadec --without-iconv --without-lzma --with-nettle --without-openssl --without-expat --without-xml2 --without-lz4 --without-zstd
420 | make ${JOBSFLAGS}
421 | make install
422 | cd ..
423 | fi
424 | fi
425 |
426 | # Prepare our Release directory to avoid some case sensitivity sillyness...
427 | mkdir -p Release
428 |
429 | # Build KT package credits
430 | cat > Release/CREDITS << EOF
431 | * kindletool:
432 |
433 | KindleTool, Copyright (C) 2011-2012 Yifan Lu & Copyright (C) 2012-2023 NiLuJe, licensed under the GNU General Public License version 3+ (http://www.gnu.org/licenses/gpl.html).
434 | (https://github.com/NiLuJe/KindleTool/)
435 |
436 | |
437 | |-> libarchive, Copyright (C) Tim Kientzle, licensed under the New BSD License (http://www.opensource.org/licenses/bsd-license.php)
438 | | (http://libarchive.github.com/)
439 | |
440 | |-> GMP, GNU MP Library, Copyright 1991-2018 Free Software Foundation, Inc.,
441 | | licensed under the GNU Lesser General Public License version 3+ (http://www.gnu.org/licenses/lgpl.html).
442 | | (http://gmplib.org/)
443 | |
444 | \`-> nettle, Copyright (C) 2001-2018 Niels Möller,
445 | licensed under the GNU Lesser General Public License version 2.1+ (https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
446 | (http://www.lysator.liu.se/~nisse/nettle)
447 | EOF
448 |
449 | # KindleTool
450 | echo "* Building KindleTool . . ."
451 | echo ""
452 | # Fake user@host tag
453 | if whoami | grep -E -e '^[nNiIlLuUjJeE]{6}' > /dev/null 2>&1 ; then
454 | export KT_NO_USERATHOST_TAG="true"
455 | export CFLAGS="-march=core2 -pipe -O2 -fomit-frame-pointer -mmacosx-version-min=10.6 -DKT_USERATHOST='\"niluje@tyrande on Mac OS X $(sw_vers -productVersion)\"'"
456 | fi
457 | cd KindleTool/KindleTool
458 | rm -rf lib includes
459 | make clean
460 | make strip
461 |
462 | # Package it
463 | git log --stat --graph > ../../Release/ChangeLog
464 | ./version.sh PMS STATIC
465 | VER_FILE="VERSION"
466 | VER_CURRENT="$(<${VER_FILE})"
467 | # Strip the git commit
468 | REV="${VER_CURRENT%%-*}"
469 | #REV="${VER_CURRENT}"
470 | cd ../..
471 | cd Release
472 | cp -v ../KindleTool/KindleTool/Release/kindletool ./kindletool
473 | cp -v ../KindleTool/README.md ./README
474 | # Quick! Markdown => plaintext
475 | perl -pi -e 's///g;s/<\/b>//g;s///g;s/<\/i>//g;s/<//g;s/&/&/g;s/^\* / /g;s/\*//g;s/>> /\t/g;s/^> / /g;s/^## //g;s/### //g;s/\t/ /g;s/^([[:digit:]])\./ \1)/g;s/^#.*$//;s/[[:blank:]]*$//g' ./README
476 | cp -v ../KindleTool/KindleTool/kindletool.1 ./kindletool.1
477 | mv -v ../KindleTool/KindleTool/VERSION ./VERSION
478 | rm -f "kindletool-${REV}-osx.zip"
479 | # Don't store uid/gid & attr, I'm packaging this on a 3rd party's computer
480 | zip -X "kindletool-${REV}-osx.zip" kindletool CREDITS README kindletool.1 ChangeLog VERSION
481 | rm -f kindletool CREDITS README kindletool.1 ChangeLog VERSION
482 | cd ..
483 | }
484 |
485 | # Main
486 | case "${OSTYPE}" in
487 | "Linux" )
488 | Build_Linux
489 | ;;
490 | CYGWIN* )
491 | ## NOTE: Output from uname -s is uppercase and appends info about the host's Windows version (ie. CYGWIN_NT-6.1), while uname -o will simply report Cygwin
492 | Build_Cygwin
493 | ;;
494 | "Darwin" )
495 | Build_OSX
496 | ;;
497 | * )
498 | echo "Unknown OS: ${OSTYPE}"
499 | exit 1
500 | ;;
501 | esac
502 |
--------------------------------------------------------------------------------
/KindleTool/kindle_tool.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** KindleTool, kindle_tool.h
3 | **
4 | ** Copyright (C) 2011-2012 Yifan Lu
5 | ** Copyright (C) 2012-2023 NiLuJe
6 | ** Concept based on an original Python implementation by Igor Skochinsky & Jean-Yves Avenard,
7 | ** cf., http://www.mobileread.com/forums/showthread.php?t=63225
8 | **
9 | ** This program is free software: you can redistribute it and/or modify
10 | ** it under the terms of the GNU General Public License as published by
11 | ** the Free Software Foundation, either version 3 of the License, or
12 | ** (at your option) any later version.
13 | **
14 | ** This program is distributed in the hope that it will be useful,
15 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ** GNU General Public License for more details.
18 | **
19 | ** You should have received a copy of the GNU General Public License
20 | ** along with this program. If not, see .
21 | */
22 |
23 | #ifndef __KINDLETOOL_H
24 | #define __KINDLETOOL_H
25 |
26 | // NOTE: Mainly to shut KDevelop up without any actual impact...
27 | // We do build MinGW w/ _GNU_SOURCE though.
28 | #if defined(__linux__)
29 | # ifndef _DEFAULT_SOURCE
30 | # define _DEFAULT_SOURCE
31 | # endif
32 | #endif
33 |
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include
44 | #include
45 | #include
46 | #if !defined(_WIN32) && !defined(__CYGWIN__)
47 | # include
48 | #endif
49 | #include
50 | #if defined(__linux__)
51 | # include
52 | #endif
53 | #include
54 |
55 | // libarchive does not pull that in for us anymore ;).
56 | #if defined(_WIN32) && !defined(__CYGWIN__)
57 | # define WIN32_LEAN_AND_MEAN
58 | # include
59 | // For _SH_* constants for kt_win_tmpfile
60 | # include
61 | #endif
62 |
63 | #include
64 | #include
65 |
66 | #include
67 | #include
68 | #include
69 | #include
70 | #include
71 | #include
72 | #include
73 |
74 | // Die in a slightly more graceful manner than by spewing a whole lot of warnings & errors
75 | // if we're not building against at least libarchive 3.0.3
76 | #if ARCHIVE_VERSION_NUMBER < 3000003
77 | # error Your libarchive version is too old, KindleTool depends on libarchive >= 3.0.3
78 | #endif
79 |
80 | #define BUFFER_SIZE PIPE_BUF // 4K
81 | #define BLOCK_SIZE 64
82 | #define RECOVERY_BLOCK_SIZE 131072
83 |
84 | #define MAGIC_NUMBER_LENGTH 4
85 | #define MD5_HASH_LENGTH 32
86 | #define SHA256_HASH_LENGTH 64
87 |
88 | #define OTA_UPDATE_BLOCK_SIZE 60
89 | #define OTA_UPDATE_V2_BLOCK_SIZE 18
90 | #define OTA_UPDATE_V2_PART_2_BLOCK_SIZE 36
91 | #define RECOVERY_UPDATE_BLOCK_SIZE 131068
92 | #define UPDATE_SIGNATURE_BLOCK_SIZE 60
93 |
94 | #define CERTIFICATE_DEV_SIZE 128
95 | #define CERTIFICATE_1K_SIZE 128
96 | #define CERTIFICATE_2K_SIZE 256
97 |
98 | #define INDEX_FILE_NAME "update-filelist.dat"
99 |
100 | #define SERIAL_NO_LENGTH 16
101 |
102 | #define DEFAULT_BYTES_PER_BLOCK (20 * 512)
103 |
104 | #define IS_SCRIPT(filename) (strncasecmp(filename + (strlen(filename) - 4), ".ffs", 4) == 0) // Flawfinder: ignore
105 | #define IS_SHELL(filename) (strncasecmp(filename + (strlen(filename) - 3), ".sh", 3) == 0) // Flawfinder: ignore
106 | #define IS_SIG(filename) (strncasecmp(filename + (strlen(filename) - 4), ".sig", 4) == 0) // Flawfinder: ignore
107 | #define IS_BIN(filename) (strncasecmp(filename + (strlen(filename) - 4), ".bin", 4) == 0) // Flawfinder: ignore
108 | #define IS_STGZ(filename) (strncasecmp(filename + (strlen(filename) - 5), ".stgz", 5) == 0) // Flawfinder: ignore
109 | #define IS_TGZ(filename) (strncasecmp(filename + (strlen(filename) - 4), ".tgz", 4) == 0) // Flawfinder: ignore
110 | #define IS_TARBALL(filename) (strncasecmp(filename + (strlen(filename) - 7), ".tar.gz", 7) == 0) // Flawfinder: ignore
111 | #define IS_DAT(filename) (strncasecmp(filename + (strlen(filename) - 4), ".dat", 4) == 0) // Flawfinder: ignore
112 | #define IS_UIMAGE(filename) (strncmp(filename + (strlen(filename) - 6), "uImage", 6) == 0) // Flawfinder: ignore
113 |
114 | // Don't break tempfiles on Win32... It doesn't like paths starting with // because that means an 'extended' path
115 | // (network shares and more weird stuff like that), but P_tmpdir defaults to / on Win32,
116 | // and we prepend our own constants with / because it's /tmp on POSIX...
117 | // Note that this is only used as a last resort, if for some reason GetTempPath returns something we can't use...
118 | // In any case, don't even try to put tempfiles on the root drive (because unprivileged users can't write there),
119 | // so use "./" (current dir) instead as a crappy workaround.
120 | // NOTE: Geekmaster also experimented with using "../" (parent dir), which may or may not be a better idea...
121 | #if defined(_WIN32) && !defined(__CYGWIN__)
122 | # define KT_TMPDIR "."
123 |
124 | // NOTE: cf. kindle_tool.c
125 | FILE* kt_win_tmpfile(void);
126 |
127 | // NOTE: Override the functions the hard way, shutting up GCC in the proces...
128 | # ifdef tmpfile
129 | # undef tmpfile
130 | # endif
131 | # define tmpfile kt_win_tmpfile
132 | // -> POSIX, assume P_tmpdir (usually /tmp) is a sane fallback.
133 | #else
134 | # define KT_TMPDIR P_tmpdir
135 | #endif
136 |
137 | // HOST_NAME_MAX is undefined on macOS, it instead kindly asks you to query _SC_HOST_NAME_MAX via sysconf()...
138 | #ifndef HOST_NAME_MAX
139 | # define HOST_NAME_MAX 256
140 | #endif
141 |
142 | // Bundlefile status bitmasks
143 | #define BUNDLE_OPEN 1 // 1 << 0 (bit 0)
144 | #define BUNDLE_CREATED 2 // 1 << 1 (bit 1)
145 |
146 | // Version tag fallback
147 | #ifndef KT_VERSION
148 | # define KT_VERSION "v1.6.5-GIT"
149 | #endif
150 |
151 | // user@host tag fallback
152 | #ifndef KT_USERATHOST
153 | # define KT_USERATHOST "someone@somewhere on something"
154 | #endif
155 |
156 | // nettle version fallback
157 | #ifndef NETTLE_VERSION
158 | # define NETTLE_VERSION ">= 2.6"
159 | #endif
160 |
161 | // GCC version checks... (We check !clang in addition to GCC, because Clang 'helpfully' defines __GNUC__ ...)
162 | #if !defined(__clang__) && defined(__GNUC__)
163 | # define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
164 | #endif
165 |
166 | typedef enum
167 | {
168 | UpdateSignature,
169 | OTAUpdateV2,
170 | OTAUpdate,
171 | RecoveryUpdate,
172 | RecoveryUpdateV2,
173 | UserDataPackage, // Actually just a gzipped tarball, but easier to implement this way...
174 | AndroidUpdate, // Actually a JAR, designed for the weird Kindle X Migu Chinese exclusive
175 | ComponentUpdate,
176 | UnknownUpdate = -1
177 | } BundleVersion;
178 |
179 | typedef enum
180 | {
181 | BundleNone = 0,
182 | BundleMD5,
183 | BundleSHA256,
184 | BundleUnknown = -1,
185 | } BundleHashAlgorithm;
186 |
187 | typedef enum
188 | {
189 | CertificateDeveloper = 0x00,
190 | Certificate1K = 0x01,
191 | Certificate2K = 0x02,
192 | CertificateUnknown = 0xFF
193 | } CertificateNumber;
194 |
195 | typedef enum
196 | {
197 | Kindle1 = 0x01,
198 | Kindle2US = 0x02,
199 | Kindle2International = 0x03,
200 | KindleDXUS = 0x04,
201 | KindleDXInternational = 0x05,
202 | KindleDXGraphite = 0x09,
203 | Kindle3WiFi = 0x08,
204 | Kindle3WiFi3G = 0x06,
205 | Kindle3WiFi3GEurope = 0x0A,
206 | Kindle4NonTouch = 0x0E, // Kindle 4 with a silver bezel, released fall 2011
207 | Kindle5TouchWiFi3G = 0x0F,
208 | Kindle5TouchWiFi = 0x11,
209 | Kindle5TouchWiFi3GEurope = 0x10,
210 | Kindle5TouchUnknown = 0x12,
211 | Kindle4NonTouchBlack = 0x23, // Kindle 4 with a black bezel, released fall 2012
212 | KindlePaperWhiteWiFi = 0x24, // Kindle PaperWhite (black bezel), released fall 2012 on FW 5.2.0
213 | KindlePaperWhiteWiFi3G = 0x1B,
214 | KindlePaperWhiteWiFi3GCanada = 0x1C,
215 | KindlePaperWhiteWiFi3GEurope = 0x1D,
216 | KindlePaperWhiteWiFi3GJapan = 0x1F,
217 | KindlePaperWhiteWiFi3GBrazil = 0x20,
218 | KindlePaperWhite2WiFi = 0xD4, // Kindle PaperWhite 2 (black bezel), released fall 2013 on FW 5.4.0
219 | KindlePaperWhite2WiFiJapan = 0x5A,
220 | KindlePaperWhite2WiFi3G = 0xD5,
221 | KindlePaperWhite2WiFi3GCanada = 0xD6,
222 | KindlePaperWhite2WiFi3GEurope = 0xD7,
223 | KindlePaperWhite2WiFi3GRussia = 0xD8,
224 | KindlePaperWhite2WiFi3GJapan = 0xF2,
225 | KindlePaperWhite2WiFi4GBInternational = 0x17,
226 | KindlePaperWhite2WiFi3G4GBEurope = 0x60,
227 | KindlePaperWhite2Unknown_0xF4 = 0xF4,
228 | KindlePaperWhite2Unknown_0xF9 = 0xF9,
229 | KindlePaperWhite2WiFi3G4GB = 0x62,
230 | KindlePaperWhite2WiFi3G4GBBrazil = 0x61,
231 | KindlePaperWhite2WiFi3G4GBCanada = 0x5F,
232 | KindleBasic = 0xC6, // Kindle Basic (Pearl, Touch), released fall 2014 on FW 5.6.0
233 | KindleVoyageWiFi = 0x13, // Kindle Voyage, released fall 2014 on FW 5.5.0
234 | ValidKindleUnknown_0x16 = 0x16,
235 | ValidKindleUnknown_0x21 = 0x21,
236 | KindleVoyageWiFi3G = 0x54,
237 | KindleVoyageWiFi3GJapan = 0x2A,
238 | KindleVoyageWiFi3G_0x4F = 0x4F, // CA?
239 | KindleVoyageWiFi3GMexico = 0x52,
240 | KindleVoyageWiFi3GEurope = 0x53,
241 | ValidKindleUnknown_0x07 = 0x07,
242 | ValidKindleUnknown_0x0B = 0x0B,
243 | ValidKindleUnknown_0x0C = 0x0C,
244 | ValidKindleUnknown_0x0D = 0x0D,
245 | ValidKindleUnknown_0x99 = 0x99,
246 | KindleBasicKiwi = 0xDD,
247 | /* KindlePaperWhite3 = 0x90, */ // Kindle PaperWhite 3, released summer 2015 on FW 5.6.1 (NOTE: This is a bogus ID, the proper one is now found at chars 4 to 6 of the S/N)
248 | KindlePaperWhite3WiFi = 0x201, // 0G1
249 | KindlePaperWhite3WiFi3G = 0x202, // 0G2
250 | KindlePaperWhite3WiFi3GMexico = 0x204, // 0G4 NOTE: Might be better flagged as "Southern America"?
251 | KindlePaperWhite3WiFi3GEurope = 0x205, // 0G5
252 | KindlePaperWhite3WiFi3GCanada = 0x206, // 0G6
253 | KindlePaperWhite3WiFi3GJapan = 0x207, // 0G7
254 | // Kindle PaperWhite 3, White, appeared w/ FW 5.7.3.1, released summer 2016 on FW 5.7.x?
255 | KindlePaperWhite3WhiteWiFi = 0x26B, // 0KB
256 | KindlePaperWhite3WhiteWiFi3GJapan = 0x26C, // 0KC
257 | KindlePW3WhiteUnknown_0KD = 0x26D, // 0KD?
258 | KindlePaperWhite3WhiteWiFi3GInternational = 0x26E, // 0KE
259 | KindlePaperWhite3WhiteWiFi3GInternationalBis = 0x26F, // 0KF
260 | KindlePW3WhiteUnknown_0KG = 0x270, // 0KG?
261 | KindlePaperWhite3BlackWiFi32GBJapan = 0x293, // 0LK
262 | KindlePaperWhite3WhiteWiFi32GBJapan = 0x294, // 0LL
263 | KindlePW3Unknown_TTT = 0x6F7B, // TTT?
264 | // Kindle Oasis, released late spring 2016 on FW 5.7.1.1
265 | KindleOasisWiFi = 0x20C, // 0GC
266 | KindleOasisWiFi3G = 0x20D, // 0GD
267 | KindleOasisWiFi3GInternational = 0x219, // 0GR
268 | KindleOasisUnknown_0GS = 0x21A, // 0GS?
269 | KindleOasisWiFi3GChina = 0x21B, // 0GT
270 | KindleOasisWiFi3GEurope = 0x21C, // 0GU
271 | // Kindle Basic 2, released summer 2016 on FW 5.8.0
272 | KindleBasic2Unknown_0DU = 0x1BC, // 0DU?? FIXME: A good ID to check the sanity of my base32 tweaks...
273 | KindleBasic2 = 0x269, // 0K9 (Black)
274 | KindleBasic2White = 0x26A, // 0KA (White)
275 | // Kindle Oasis 2, released winter 2017 on FW 5.9.0.6
276 | KindleOasis2Unknown_0LM = 0x295, // 0LM?
277 | KindleOasis2Unknown_0LN = 0x296, // 0LN?
278 | KindleOasis2Unknown_0LP = 0x297, // 0LP?
279 | KindleOasis2Unknown_0LQ = 0x298, // 0LQ?
280 | KindleOasis2WiFi32GBChampagne = 0x2E1, // 0P1
281 | KindleOasis2Unknown_0P2 = 0x2E2, // 0P2?
282 | KindleOasis2Unknown_0P6 = 0x2E6, // 0P6 (FIXME: Seen in the wild, WiFi+4G, 32GB, Graphite, not enough info)
283 | KindleOasis2Unknown_0P7 = 0x2E7, // 0P7?
284 | KindleOasis2WiFi8GB = 0x2E8, // 0P8
285 | KindleOasis2WiFi3G32GB = 0x341, // 0S1
286 | KindleOasis2WiFi3G32GBEurope = 0x342, // 0S2
287 | KindleOasis2Unknown_0S3 = 0x343, // 0S3?
288 | KindleOasis2Unknown_0S4 = 0x344, // 0S4?
289 | KindleOasis2Unknown_0S7 = 0x347, // 0S7?
290 | KindleOasis2WiFi32GB = 0x34A, // 0SA
291 | // Kindle PaperWhite 4, released November 7 2018 on FW 5.10.0.1/5.10.0.2
292 | KindlePaperWhite4WiFi8GB = 0x2F7, // 0PP
293 | KindlePaperWhite4WiFi4G32GB = 0x361, // 0T1
294 | KindlePaperWhite4WiFi4G32GBEurope = 0x362, // 0T2
295 | KindlePaperWhite4WiFi4G32GBJapan = 0x363, // 0T3
296 | KindlePaperWhite4Unknown_0T4 = 0x364, // 0T4?
297 | KindlePaperWhite4Unknown_0T5 = 0x365, // 0T5?
298 | KindlePaperWhite4WiFi32GB = 0x366, // 0T6
299 | KindlePaperWhite4Unknown_0T7 = 0x367, // 0T7?
300 | KindlePaperWhite4Unknown_0TJ = 0x372, // 0TJ?
301 | KindlePaperWhite4Unknown_0TK = 0x373, // 0TK?
302 | KindlePaperWhite4Unknown_0TL = 0x374, // 0TL?
303 | KindlePaperWhite4Unknown_0TM = 0x375, // 0TM?
304 | KindlePaperWhite4Unknown_0TN = 0x376, // 0TN?
305 | KindlePaperWhite4WiFi8GBIndia = 0x402, // 102 NOTE: Appeared in 5.10.1.3...
306 | KindlePaperWhite4WiFi32GBIndia = 0x403, // 103
307 | KindlePaperWhite4WiFi32GBBlue = 0x4D8, // 16Q (Twilight Blue, ??) NOTE: Appeared in 5.11.2...
308 | KindlePaperWhite4WiFi32GBPlum = 0x4D9, // 16R
309 | KindlePaperWhite4WiFi32GBSage = 0x4DA, // 16S
310 | KindlePaperWhite4WiFi8GBBlue = 0x4DB, // 16T (Twilight Blue, DE)
311 | KindlePaperWhite4WiFi8GBPlum = 0x4DC, // 16U (Plum. New batch of colors released summer 2020, on 5.12.3)
312 | KindlePaperWhite4WiFi8GBSage = 0x4DD, // 16V (Sage. Ditto)
313 | KindlePW4Unknown_0PL = 0x2F4, // 0PL?
314 | // Kindle Basic 3, released April 10 2019 on FW 5.1x.y
315 | KindleBasic3 = 0x414, // 10L
316 | KindleBasic3White8GB = 0x3CF, // 0WF (White, WiFi, DE. 4GB -> 8GB)
317 | KindleBasic3Unknown_0WG = 0x3D0, // 0WG?
318 | KindleBasic3White = 0x3D1, // 0WH
319 | KindleBasic3Unknown_0WJ = 0x3D2, // 0WJ?
320 | KindleBasic3KidsEdition = 0x3AB, // 0VB NOTE: Ships on a custom OTA-only FW branch. May be a special snowflake.
321 | // Kindle Oasis 3, released July 24 2019 on FW 5.12.0
322 | KindleOasis3WiFi32GBChampagne = 0x434, // 11L (Champagne, US)
323 | KindleOasis3WiFi4G32GBJapan = 0x3D8, // 0WQ (Graphite, JP)
324 | KindleOasis3WiFi4G32GBIndia = 0x3D7, // 0WP (Graphite, IN)
325 | KindleOasis3WiFi4G32GB = 0x3D6, // 0WN (Graphite, US)
326 | KindleOasis3WiFi32GB = 0x3D5, // 0WM (Graphite, DE)
327 | KindleOasis3WiFi8GB = 0x3D4, // 0WL (Graphite, DE)
328 | // Kindle PaperWhite 5, released October 27 2021 on FW 5.14.0
329 | KindlePaperWhite5SignatureEdition = 0x690, // 1LG (Black, 32GB, US)
330 | KindlePaperWhite5Unknown_1Q0 = 0x700, // 1Q0?
331 | KindlePaperWhite5 = 0x6FF, // 1PX (Black & White, 8GB, UK, FR, IT)
332 | KindlePaperWhite5Unknown_1VD = 0x7AD, // 1VD?
333 | KindlePaperWhite5SE_219 = 0x829, // 219 (SE, 32GB, Denim, US)
334 | KindlePaperWhite5_21A = 0x82A, // 21A
335 | KindlePaperWhite5SE_2BH = 0x971, // 2BH NOTE: Appeared in 5.14.2... (SE)
336 | KindlePaperWhite5Unknown_2BJ = 0x972, // 2BJ?
337 | KindlePaperWhite5_2DK = 0x9B3, // 2DK NOTE: Appeared in 5.14.3... (Black, Kids or not, US)
338 | // Kindle Basic 4, released October 12 2022 on FW 5.15.0
339 | KindleBasic4Unknown_22D = 0x84D, // 22D?
340 | KindleBasic4Unknown_25T = 0x8BB, // 25T?
341 | KindleBasic4Unknown_23A = 0x86A, // 23A?
342 | KindleBasic4_2AQ = 0x958, // 2AQ (Refurb seen in the wild)
343 | KindleBasic4_2AP = 0x957, // 2AP (Seen in the wild, possibly EU-ish)
344 | KindleBasic4Unknown_1XH = 0x7F1, // 1XH?
345 | KindleBasic4Unknown_22C = 0x84C, // 22C?
346 | // Kindle Scribe, released December 2022 on FW 5.16.0
347 | KindleScribeUnknown_27J = 0x8F2, // 27J?
348 | KindleScribeUnknown_2BL = 0x974, // 2BL?
349 | KindleScribeUnknown_263 = 0x8C3, // 263?
350 | KindleScribe16GB_227 = 0x847, // 227 (JP, 16GB, Premium Pen)
351 | KindleScribeUnknown_2BM = 0x975, // 2BM?
352 | KindleScribe_23L = 0x874, // 23L
353 | KindleScribe64GB_23M = 0x875, // 23M (US, 64GB, Premium Pen)
354 | KindleScribeUnknown_270 = 0x8E0, // 270?
355 | // Kindle Basic 5, released October 2024 on FW 5.17.x
356 | KindleBasic5Unknown_3L5 = 0xE85, // 3L5?
357 | KindleBasic5Unknown_3L6 = 0xE86, // 3L6?
358 | KindleBasic5Unknown_3L4 = 0xE84, // 3L4?
359 | KindleBasic5Unknown_3L3 = 0xE83, // 3L3?
360 | KindleBasic5Unknown_A89 = 0x2909, // A89?
361 | KindleBasic5Unknown_3L2 = 0xE82, // 3L2?
362 | KindleBasic5Unknown_3KM = 0xE75, // 3KM
363 | // Kindle PaperWhite 6, released October 2024 on FW 5.17.x
364 | KindlePaperWhite6Unknown_349 = 0xC89, // 349?
365 | KindlePaperWhite6Unknown_346 = 0xC86, // 346?
366 | KindlePaperWhite6Unknown_33X = 0xC7F, // 33X
367 | KindlePaperWhite6Unknown_33W = 0xC7E, // 33W?
368 | KindlePaperWhite6Unknown_3HA = 0xE2A, // 3HA?
369 | KindlePaperWhite6Unknown_3H5 = 0xE25, // 3H5?
370 | KindlePaperWhite6Unknown_3H3 = 0xE23, // 3H3?
371 | KindlePaperWhite6Unknown_3H8 = 0xE28, // 3H8?
372 | KindlePaperWhite6Unknown_3J5 = 0xE45, // 3J5?
373 | KindlePaperWhite6Unknown_3JS = 0xE5A, // 3JS?
374 | // Kindle Scribe 2, released October 2024 on FW 5.17.x
375 | KindleScribe2Unknown_3V0 = 0xFA0, // 3V0?
376 | KindleScribe2Unknown_3V1 = 0xFA1, // 3V1?
377 | KindleScribe2Unknown_3X5 = 0xFE5, // 3X5?
378 | KindleScribe2Unknown_3UV = 0xF9D, // 3UV?
379 | KindleScribe2Unknown_3X4 = 0xFE4, // 3X4?
380 | KindleScribe2Unknown_3X3 = 0xFE3, // 3X3?
381 | KindleScribe2Unknown_41E = 0x102E, // 41E?
382 | KindleScribe2Unknown_41D = 0x102D, // 41D?
383 | // Kindle ColorSoft, released October 2024 on FW 5.18.0
384 | KindleColorSoftUnknown_3H9 = 0xE29, // 3H9?
385 | KindleColorSoftUnknown_3H4 = 0xE24, // 3H4?
386 | KindleColorSoftUnknown_3HB = 0xE2B, // 3HB?
387 | KindleColorSoftUnknown_3H6 = 0xE26, // 3H6?
388 | KindleColorSoftUnknown_3H2 = 0xE22, // 3H2?
389 | KindleColorSoftUnknown_34X = 0xC9F, // 34X?
390 | KindleColorSoftUnknown_3H7 = 0xE27, // 3H7
391 | KindleColorSoftUnknown_3JT = 0xE5B, // 3JT?
392 | KindleColorSoftUnknown_3J6 = 0xE46, // 3J6?
393 | KindleColorSoftUnknown_456 = 0x10A6, // 456?
394 | KindleColorSoftUnknown_455 = 0x10A5, // 455?
395 | KindleColorSoftUnknown_4EP = 0x11D7, // 4EP?
396 | KindleUnknown = 0x00
397 | } Device;
398 |
399 | typedef enum
400 | {
401 | Plat_Unspecified = 0x00,
402 | MarioDeprecated = 0x01, // Kindle 2
403 | Luigi = 0x02, // Kindle 3
404 | Banjo = 0x03, // ??
405 | Yoshi = 0x04, // Kindle Touch (and Kindle 4)
406 | YoshimeProto = 0x05, // Early PW proto? (NB: Platform AKA Yoshime)
407 | Yoshime = 0x06, // Kindle PW (NB: Platform AKA Yoshime3)
408 | Wario = 0x07, // Kindle PW2, Basic, Voyage, PW3
409 | Duet = 0x08, // Kindle Oasis
410 | Heisenberg = 0x09, // Kindle Basic 2 (8th gen)
411 | Zelda = 0x0A, // Kindle Oasis 2, Oasis 3
412 | Rex = 0x0B, // Kindle PW4, Basic 3 (10th gen)
413 | Bellatrix = 0x0C, // Kindle PW5 (11th gen), Basic 4
414 | Bellatrix3 = 0x0D, // Kindle Scribe
415 | Bellatrix4 = 0x0E, // Kindle PW6 (12th gen), ColorSoft
416 | } Platform;
417 |
418 | typedef enum
419 | {
420 | Board_Unspecified = 0x00, // Used since the PW (skip board check)
421 | Tequila = 0x03, // Silver Kindle 4
422 | Whitney = 0x05 // Kindle Touch
423 | // Other potentially relevant (OTA|Recovery)v2 ready boards:
424 | /*
425 | Sauza = 0xFF // Black Kindle 4
426 | Celeste = 0xFF // Kindle PW
427 | Icewine = 0xFF // Kindle Voyage (also a dev/proto on the Yoshime3 platform)
428 | Pinot = 0xFF // Kindle PW2
429 | Bourbon = 0xFF // Kindle Basic
430 | Muscat = 0xFF // Kindle PW3
431 | Whisky = 0xFF // Kindle Oasis
432 | Woody = 0xFF // ?? (in the Basic line? (no 3G))
433 | Eanab = 0xFF // Kindle Basic 2
434 | Cognac = 0xFF // Kindle Oasis 2
435 | Moonshine = 0xFF // Kindle PW4
436 | Jaeger = 0xFF // Kindle Basic 3
437 | Stinger = 0xFF // Kindle Oasis 3
438 | Malbec = 0xFF // Kindle PW5
439 | Cava = 0xFF // Kindle Basic 4
440 | Barolo = 0xFF // Kindle Scribe
441 | Rossini = 0xFF // Kindle Basic 5
442 | Sangria = 0xFF // Kindle PW6
443 | SeaBreeze = 0xFF // Kindle ColorSoft
444 | */
445 | } Board;
446 |
447 | // For reference, list of boards (AFAICT, in chronological order), trailing name is the inane marketing name used on the *US* market:
448 | // ADS // K1 proto? (w/ ETH)
449 | // Fiona // Kindle 1 - Kindle (1st Generation)
450 | // Mario // Kindle 2? (w/ ETH) [Also a platform]
451 | // Nell/NellSL/NellWW // DX & DXG & DXi? - Kindle DX (2nd Generation)
452 | // Turing/TuringWW // Kindle 2 & Kindle 2 International - Kindle (2nd Generation)
453 | // Luigi/Luigi3 // ?? (r3 w/ ETH) [Also a platform]
454 | // Shasta (+ WFO variant) // Kindle 3 - Kindle Keyboard (Wi-Fi), Kindle Keyboard 3G (Free 3G + Wi-Fi) (3rd Generation)
455 | // Yoshi // ?? [Also a platform]
456 | // Primer // Deprecated proto
457 | // Harv // K4 proto?
458 | // Tequila (is WFO) // Silver Kindle 4 - Kindle Wi-Fi, 6" E Ink Display (4th and 5th Generation)
459 | // Sauza // Black Kindle 4? (NOT in chronological order)
460 | // Finkle // Touch proto?
461 | // Whitney (+ WFO variant) // Kindle Touch - Kindle Touch, Kindle Touch 3G (Free 3G + Wi-Fi) (4th Generation)
462 | // Yoshime // Temp. Yoshime dev board [Also a Platform, which we call YoshimeProto]
463 | // Yoshime3 // Temp. Yoshime3 dev boards (w/ ETH). PW proto? [Also a Platform, which we call Yoshime]
464 | // Celeste (+ WFO variant) // Kindle PW - Kindle Paperwhite (5th Generation)
465 | // Icewine (+ WFO variants) // Dev/Proto, next rumored product [Used on two different platforms (so far), Yoshime3 & Wario]
466 | // Wario // Temp. Wario dev boards [Also a Platform]
467 | // Pinot (+ WFO variant) // Kindle PW2 - Kindle Paperwhite (6th Generation)
468 | // Bourbon // Kindle Basic (KT2) - Kindle (7th Generation)
469 | // Icewine (on Wario) // Kindle Voyage - Kindle Voyage (7th Generation)
470 | // Muscat // Kindle PW3 - Kindle Paperwhite (7th Generation)
471 | // Whisky // Kindle Oasis - Kindle Oasis (8th Generation)
472 | // Woody // ?? (Dev/Proto? Duet platform, Basic line)
473 | // Eanab // Kindle Basic 2 (KT3) - Kindle (8th Generation)
474 | // Cognac // Kindle Oasis 2 - Kindle Oasis (9th Generation)
475 | // Moonshine // Kindle PW4 - Kindle Paperwhite (10th Generation)
476 | // Jaeger // Kindle Basic 3 (KT4) - Kindle (10th Generation)
477 | // Stinger // Kindle Oasis 3 - Kindle Oasis (10th Generation)
478 | // Malbec // Kindle PW5 (First Bellatrix board. No longer an i.MX SoC, but a MediaTek one: MT8110, likely based on the MT8512) - Kindle Paperwhite (11th Generation)
479 | // Cava // Kindle Basic 4 (KT5) [Kindle 11th gen] - Kindle (11th Generation)
480 | // Barolo // Kindle Scribe (First Bellatrix3 board) - Kindle Scribe
481 | // Rossini // Kindle Basic 5 (KT6) [Kindle 11th gen - 2024] - Kindle (11th Generation) - 2024 Release
482 | // Sangria // Kindle PW6 (First Bellatrix4 board w/ the CS) - Kindle Paperwhite (12th Generation) - 2024 Release
483 | // SeaBreeze // Kindle CS - Kindle ColorSoft
484 |
485 | typedef struct
486 | {
487 | CertificateNumber certificate_number;
488 | } UpdateSignatureHeader;
489 |
490 | typedef struct
491 | {
492 | uint32_t source_revision;
493 | uint32_t target_revision;
494 | uint16_t device;
495 | unsigned char optional;
496 | unsigned char unused;
497 | char md5_sum[MD5_HASH_LENGTH];
498 | } OTAUpdateHeader;
499 |
500 | typedef struct
501 | {
502 | unsigned char unused[12];
503 | char md5_sum[MD5_HASH_LENGTH];
504 | uint32_t magic_1;
505 | uint32_t magic_2;
506 | uint32_t minor;
507 | uint32_t device;
508 | } RecoveryUpdateHeader;
509 |
510 | typedef struct
511 | {
512 | unsigned char foo[4];
513 | uint64_t target_revision; // NOTE: This would enforce 8 bytes padding/alignment, hence the packing
514 | char md5_sum[MD5_HASH_LENGTH];
515 | uint32_t magic_1;
516 | uint32_t magic_2;
517 | uint32_t minor;
518 | uint32_t platform;
519 | uint32_t header_rev;
520 | uint32_t board;
521 | } __attribute__((packed)) RecoveryH2UpdateHeader; // FB02 with V2 Header, not FB03
522 |
523 | typedef struct
524 | {
525 | char magic_number[MAGIC_NUMBER_LENGTH] __attribute__((nonstring));
526 | union
527 | {
528 | OTAUpdateHeader ota_update;
529 | RecoveryUpdateHeader recovery_update;
530 | RecoveryH2UpdateHeader recovery_h2_update;
531 | UpdateSignatureHeader signature;
532 | unsigned char ota_header_data[OTA_UPDATE_BLOCK_SIZE];
533 | unsigned char signature_header_data[UPDATE_SIGNATURE_BLOCK_SIZE];
534 | unsigned char recovery_header_data[RECOVERY_UPDATE_BLOCK_SIZE];
535 | } data;
536 | } UpdateHeader;
537 |
538 | // Ugly global. Used to cache the state of the KT_WITH_UNKNOWN_DEVCODES env var...
539 | // NOTE: While this looks like the ideal candidate to be a bool,
540 | // we can't do that because we use its value in unsigned operations,
541 | // and I can't be arsed to add a bunch of casts there (because for some mystical reason, bool is signed :?)
542 | extern unsigned int kt_with_unknown_devcodes;
543 |
544 | // Another for the shell metadata dumps in convert
545 | extern const char* kt_pkg_metadata_dump;
546 |
547 | // And another to store the tmpdir...
548 | extern char kt_tempdir[PATH_MAX];
549 |
550 | uint32_t from_base(const char*, uint8_t);
551 |
552 | void md(unsigned char*, size_t);
553 | void dm(unsigned char*, size_t);
554 | int munger(FILE*, FILE*, size_t, const bool);
555 | int demunger(FILE*, FILE*, size_t, const bool);
556 | const char* convert_device_id(Device) __attribute__((const));
557 | const char* convert_platform_id(Platform) __attribute__((const));
558 | const char* convert_board_id(Board) __attribute__((const));
559 | BundleVersion get_bundle_version(const char[MAGIC_NUMBER_LENGTH]) __attribute__((pure));
560 | int md5_sum(FILE*, char output_string[BASE16_ENCODE_LENGTH(MD5_DIGEST_SIZE)]);
561 | int sha256_sum(FILE*, char output_string[BASE16_ENCODE_LENGTH(SHA256_DIGEST_SIZE)]);
562 |
563 | int kindle_convert_main(int, char**);
564 |
565 | int kindle_extract_main(int, char**);
566 |
567 | int kindle_create_main(int, char**);
568 |
569 | int nettle_rsa_privkey_from_pem(const char*, struct rsa_private_key*);
570 |
571 | #endif
572 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------