mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
MOBI debug: Last remaininng TBS type almost completely deciphered
This commit is contained in:
parent
c8545cb7d7
commit
769c1dc678
@ -941,27 +941,33 @@ class TBSIndexing(object): # {{{
|
|||||||
def interpret_periodical(self, tbs_type, byts):
|
def interpret_periodical(self, tbs_type, byts):
|
||||||
ans = []
|
ans = []
|
||||||
|
|
||||||
def tbs_type_6(byts, psi=None): # {{{
|
def tbs_type_6(byts, psi=None, msg=None): # {{{
|
||||||
if psi is None:
|
if psi is None:
|
||||||
# Assume parent section is 1
|
# Assume parent section is 1
|
||||||
psi = self.get_index(1)
|
psi = self.get_index(1)
|
||||||
|
if msg is None:
|
||||||
|
msg = ('Article index at start of record or first article'
|
||||||
|
' index, relative to parent section')
|
||||||
if byts:
|
if byts:
|
||||||
# byts could be empty
|
# byts could be empty
|
||||||
arg, consumed = decint(byts)
|
arg, consumed = decint(byts)
|
||||||
byts = byts[consumed:]
|
byts = byts[consumed:]
|
||||||
flags = (arg & 0b1111)
|
flags = (arg & 0b1111)
|
||||||
ai = (arg >> 4)
|
ai = (arg >> 4)
|
||||||
ans.append(('Article index at start of record or first article'
|
ans.append('%s (fvwi): %d [%d absolute]'%(msg, ai,
|
||||||
' index, relative to parent section (fvwi): %d [%d absolute]'%(ai,
|
ai+psi.index))
|
||||||
ai+psi.index)))
|
|
||||||
if flags == 1:
|
if flags == 1:
|
||||||
arg, consumed = decint(byts)
|
arg, consumed = decint(byts)
|
||||||
byts = byts[consumed:]
|
byts = byts[consumed:]
|
||||||
ans.append('EOF (vwi: should be 0): %d'%arg)
|
ans.append('EOF (vwi: should be 0): %d'%arg)
|
||||||
elif flags == 4:
|
elif flags in (4, 5):
|
||||||
num = byts[0]
|
num = byts[0]
|
||||||
byts = byts[1:]
|
byts = byts[1:]
|
||||||
ans.append('Number of article nodes in the record (byte): %d'%num)
|
ans.append('Number of article nodes in the record (byte): %d'%num)
|
||||||
|
if flags == 5:
|
||||||
|
arg, consumed = decint(byts)
|
||||||
|
byts = byts[consumed:]
|
||||||
|
ans.append('Unknown ??? (vwi)): %d'%(arg))
|
||||||
elif flags == 0:
|
elif flags == 0:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@ -971,70 +977,33 @@ class TBSIndexing(object): # {{{
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
if tbs_type == 3: # {{{
|
if tbs_type == 3: # {{{
|
||||||
if byts:
|
|
||||||
arg2, consumed = decint(byts)
|
arg2, consumed = decint(byts)
|
||||||
byts = byts[consumed:]
|
byts = byts[consumed:]
|
||||||
ans.append('Unknown: %d'%arg2)
|
ans.append('Unknown (vwi: always 0?): %d'%arg2)
|
||||||
if byts:
|
|
||||||
arg3, consumed = decint(byts)
|
arg3, consumed = decint(byts)
|
||||||
byts = byts[consumed:]
|
byts = byts[consumed:]
|
||||||
fsi = arg3 >> 4
|
fsi = arg3 >> 4
|
||||||
extra = arg3 & 0b1111
|
extra = arg3 & 0b1111
|
||||||
ans.append('First section index: %d'%fsi)
|
ans.append('First section index (fvwi): %d'%fsi)
|
||||||
psi = self.get_index(fsi)
|
psi = self.get_index(fsi)
|
||||||
ans.append('Extra bits: %d'%extra)
|
ans.append('Extra bits (flag: always 0?): %d'%extra)
|
||||||
|
|
||||||
|
byts = tbs_type_6(byts, psi=psi,
|
||||||
|
msg=('First article of ending section, relative to its'
|
||||||
|
' parent\'s index'))
|
||||||
if byts:
|
if byts:
|
||||||
if byts[0] == fsi:
|
# We have a transition not just an opening first section
|
||||||
ssi = psi.index+1
|
psi = self.get_index(psi.index+1)
|
||||||
ans.append('First section ends')
|
|
||||||
byts = byts[1:]
|
|
||||||
arg, consumed = decint(byts)
|
arg, consumed = decint(byts)
|
||||||
raw = byts[:consumed]
|
off = arg >> 4
|
||||||
byts = byts[consumed:]
|
byts = byts[consumed:]
|
||||||
flags = arg & 0b1111
|
flags = arg & 0b1111
|
||||||
ans.append('Unknown (art index at start of record?):'
|
|
||||||
' %d %r'%((arg>>4), raw))
|
|
||||||
ans.append('Flags: %d'%flags)
|
|
||||||
num = 1
|
|
||||||
if flags >= 4:
|
|
||||||
num = byts[0]
|
|
||||||
byts = byts[1:]
|
|
||||||
ans.append('Number of articles in closing section: %d'%num)
|
|
||||||
if flags == 5:
|
|
||||||
arg, consumed = decint(byts)
|
|
||||||
ans.append('Unknown: %r'%bytes(byts[:consumed]))
|
|
||||||
byts = byts[consumed:]
|
|
||||||
arg, consumed = decint(byts)
|
|
||||||
byts = byts[consumed:]
|
|
||||||
off = arg >> 4
|
|
||||||
ans.append('Last article of ending section w.r.t. starting'
|
ans.append('Last article of ending section w.r.t. starting'
|
||||||
' section offset: %d [%d absolute]'%(off,
|
' section offset (fvwi): %d [%d absolute]'%(off,
|
||||||
ssi+off))
|
psi.index+off))
|
||||||
ans.append('Extra bits: %d'%(arg & 0b1111))
|
ans.append('Flags (always 8?): %d'%flags)
|
||||||
arg, consumed = decint(byts)
|
byts = tbs_type_6(byts, psi=psi)
|
||||||
byts = byts[consumed:]
|
|
||||||
off = arg >> 4
|
|
||||||
flag = arg & 0b1111
|
|
||||||
ans.append('Offset to first article of starting section: %d'
|
|
||||||
' [%d absolute]'%(off, ssi+off))
|
|
||||||
ans.append('Flags: %d'%flag)
|
|
||||||
num = 1
|
|
||||||
if flag == 4:
|
|
||||||
num = byts[0]
|
|
||||||
byts = byts[1:]
|
|
||||||
ans.append('Number of articles in starting section: %d'%num)
|
|
||||||
else:
|
|
||||||
ans.append('First section starts')
|
|
||||||
off, consumed = decint(byts)
|
|
||||||
flags = off & 0b1111
|
|
||||||
off = off >> 4
|
|
||||||
byts = byts[consumed:]
|
|
||||||
ans.append('Article at start of block as offset from '
|
|
||||||
'parent index: %d [%d absolute]'%(off, psi.index+off))
|
|
||||||
ans.append('Flags: %d'%flags)
|
|
||||||
if flags == 4:
|
|
||||||
ans.append('Number of articles: %d'%byts[0])
|
|
||||||
byts = byts[1:]
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
elif tbs_type == 7: # {{{
|
elif tbs_type == 7: # {{{
|
||||||
|
@ -142,6 +142,27 @@ In such a record there is a transition from one section to the next. As such the
|
|||||||
|
|
||||||
TODO: Note you have to test the cases of first section, a single transition and multiple transitions.
|
TODO: Note you have to test the cases of first section, a single transition and multiple transitions.
|
||||||
|
|
||||||
|
1. The first section::
|
||||||
|
|
||||||
|
Record #2: Starts at: 4096 Ends at: 8191
|
||||||
|
Contains: 2 index entries (0 ends, 0 complete, 2 starts)
|
||||||
|
TBS bytes: 83 80 80 90 c0
|
||||||
|
Starts:
|
||||||
|
Index Entry: 1 (Parent index: 0, Depth: 1, Offset: 7758, Size: 26279) [Ars Technica]
|
||||||
|
Index Entry: 5 (Parent index: 1, Depth: 2, Offset: 7766, Size: 1866) [Week in gaming: 3DS review, Crysis 2, George Hotz]
|
||||||
|
TBS Type: 011 (3)
|
||||||
|
Outer Index entry: 0
|
||||||
|
Unknown (vwi: always 0?): 0
|
||||||
|
Unknown (vwi: always 0?): 0
|
||||||
|
First section index (fvwi) : 1
|
||||||
|
Extra bits: 0
|
||||||
|
First section starts
|
||||||
|
Article at start of block as offset from parent index (fvwi): 4 [5 absolute]
|
||||||
|
Flags: 0
|
||||||
|
|
||||||
|
If there was more than one article at the start then the last byte would be replaced by: c4 n where n is the number of articles
|
||||||
|
|
||||||
|
|
||||||
Ending record
|
Ending record
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user