11 #ifndef libmobi_util_h
12 #define libmobi_util_h
23 #define strdup mobi_strdup
28 #define m_uncompress mz_uncompress
29 #define m_crc32 mz_crc32
33 #define m_uncompress uncompress
38 #define UNUSED(x) (void)(x)
41 #define AUDI_MAGIC "AUDI"
42 #define CDIC_MAGIC "CDIC"
43 #define CMET_MAGIC "CMET"
44 #define EXTH_MAGIC "EXTH"
45 #define FDST_MAGIC "FDST"
46 #define FONT_MAGIC "FONT"
47 #define HUFF_MAGIC "HUFF"
48 #define IDXT_MAGIC "IDXT"
49 #define INDX_MAGIC "INDX"
50 #define LIGT_MAGIC "LIGT"
51 #define MOBI_MAGIC "MOBI"
52 #define ORDT_MAGIC "ORDT"
53 #define RESC_MAGIC "RESC"
54 #define SRCS_MAGIC "SRCS"
55 #define TAGX_MAGIC "TAGX"
56 #define VIDE_MAGIC "VIDE"
57 #define BOUNDARY_MAGIC "BOUNDARY"
58 #define EOF_MAGIC "\xe9\x8e\r\n"
59 #define REPLICA_MAGIC "%MOP"
62 #define EPOCH_MAC_DIFF 2082844800UL
68 #define PALMDB_HEADER_LEN 78
69 #define PALMDB_NAME_SIZE_MAX 32
70 #define PALMDB_RECORD_INFO_SIZE 8
77 #define PALMDB_ATTRIBUTE_DEFAULT 0
78 #define PALMDB_VERSION_DEFAULT 0
79 #define PALMDB_MODNUM_DEFAULT 0
80 #define PALMDB_APPINFO_DEFAULT 0
81 #define PALMDB_SORTINFO_DEFAULT 0
82 #define PALMDB_TYPE_DEFAULT "BOOK"
83 #define PALMDB_CREATOR_DEFAULT "MOBI"
84 #define PALMDB_NEXTREC_DEFAULT 0
91 #define RECORD0_HEADER_LEN 16
92 #define RECORD0_TEXT_SIZE_MAX 4096
93 #define RECORD0_FULLNAME_SIZE_MAX 1024
100 #define CDIC_HEADER_LEN 16
101 #define CDIC_RECORD_MAXCNT 1024
102 #define HUFF_CODELEN_MAX 16
103 #define HUFF_HEADER_LEN 24
104 #define HUFF_RECORD_MAXCNT 1024
105 #define HUFF_RECORD_MINSIZE 2584
106 #define FONT_HEADER_LEN 24
107 #define MEDIA_HEADER_LEN 12
108 #define FONT_SIZEMAX (50 * 1024 * 1024)
109 #define RAWTEXT_SIZEMAX 0xfffffff
110 #define MOBI_HEADER_V2_SIZE 0x18
111 #define MOBI_HEADER_V3_SIZE 0x74
112 #define MOBI_HEADER_V4_SIZE 0xd0
113 #define MOBI_HEADER_V5_SIZE 0xe4
114 #define MOBI_HEADER_V6_SIZE 0xe4
115 #define MOBI_HEADER_V6_EXT_SIZE 0xe8
116 #define MOBI_HEADER_V7_SIZE 0xe4
120 #define max(a, b) ((a) > (b) ? (a) : (b))
123 #define min(a, b) ((a) < (b) ? (a) : (b))
126 #define ARRAYSIZE(arr) (sizeof(arr) / sizeof(arr[0]))
128 #define MOBI_TITLE_SIZEMAX 1024
MOBI_RET
Error codes returned by functions.
Definition: mobi.h:59
MOBIFiletype
Types of files stored in database records.
Definition: mobi.h:176
header file for third party miniz.c, zlib replacement
Libmobi main header file.
Main structure holding all metadata and unparsed records data.
Definition: mobi.h:381
Reconstructed source file.
Definition: mobi.h:453
Metadata and data of a record. All records form a linked list.
Definition: mobi.h:251
Main structure containing reconstructed source parts and indices.
Definition: mobi.h:464
MOBI_RET mobi_set_pdbname(MOBIData *m, const char *name)
Set palm database name.
Definition: util.c:817
MOBIFiletype mobi_get_resourcetype_by_uid(const MOBIRawml *rawml, const size_t uid)
Get MOBIFiletype type of MOBIPart resource record with given unique id.
Definition: util.c:989
uint32_t mobi_get32le(const unsigned char buf[4])
Convert char buffer to 32-bit unsigned integer little endian.
Definition: util.c:3555
uint16_t mobi_ligature_to_utf16(const uint32_t byte1, const uint32_t byte2)
Decode ligature to utf-16.
Definition: util.c:371
char * mobi_strdup(const char *s)
strdup replacement
Definition: util.c:432
MOBIFiletype mobi_determine_flowpart_type(const MOBIRawml *rawml, const size_t part_number)
Get file type of given part with number [part_number].
Definition: util.c:2195
MOBI_RET mobi_add_video_resource(MOBIPart *part)
Replace part data with decoded video data.
Definition: util.c:2307
uint32_t mobi_get32be(const unsigned char buf[4])
Convert char buffer to 32-bit unsigned integer big endian.
Definition: util.c:3541
bool mobi_is_cp1252(const MOBIData *m)
Check if document's text is cp1252 encoded.
Definition: util.c:420
MOBI_RET mobi_delete_record_by_seqnumber(MOBIData *m, const size_t num)
Delete palm database record with given sequential number from MOBIData structure.
Definition: util.c:1207
uint8_t mobi_ligature_to_cp1252(const uint8_t byte1, const uint8_t byte2)
Decode ligature to cp1252.
Definition: util.c:338
bool mobi_has_drmkey(const MOBIData *m)
Check if DRM key is set for the document.
Definition: util.c:2747
MOBI_RET mobi_set_fullname(MOBIData *m, const char *fullname)
Set ebook full name stored in Record 0 at offset given in MOBI header.
Definition: util.c:778
void mobi_remove_zeros(unsigned char *buffer, size_t *len)
Remove null characters from char buffer.
Definition: util.c:3119
void mobi_free_internals(MOBIData *m)
Free internals.
Definition: util.c:3527
MOBIFiletype mobi_determine_resource_type(const MOBIPdbRecord *record)
Get resource type (image, font) by checking its magic header.
Definition: util.c:2599
MOBI_RET mobi_utf8_to_cp1252(char *output, const char *input, size_t *outsize, const size_t insize)
Convert utf-8 encoded string to cp1252.
Definition: util.c:193
uint32_t mobi_get_drmsize(const MOBIData *m)
Get size of serialized DRM data.
Definition: util.c:3074
MOBI_RET mobi_add_font_resource(MOBIPart *part)
Replace part data with decoded font data.
Definition: util.c:2476
bool mobi_has_drmcookies(const MOBIData *m)
Check if DRM cookies are set for the document.
Definition: util.c:2767
MOBI_RET mobi_add_audio_resource(MOBIPart *part)
Replace part data with decoded audio data.
Definition: util.c:2253
uint32_t mobi_get_exthsize(const MOBIData *m)
Get size of serialized exth record including padding.
Definition: util.c:3046
int mobi_bitcount(const uint8_t byte)
Get number of bits set in a given byte.
Definition: util.c:1784
uint16_t mobi_get_records_count(const MOBIData *m)
Get count of palm database records.
Definition: util.c:3098
MOBI_RET mobi_base32_decode(uint32_t *decoded, const char *encoded)
Decode positive number from base 32 to base 10.
Definition: util.c:2960
MOBI_RET mobi_cp1252_to_utf8(char *output, const char *input, size_t *outsize, const size_t insize)
Convert cp1252 encoded string to utf-8.
Definition: util.c:133
MOBI_RET mobi_swap_mobidata(MOBIData *m)
Swap KF7 and KF8 MOBIData structures in a hybrid file.
Definition: util.c:3414