For a class assignment, I'm analyzing how Amazon's Kindle digital rights management implementation works as well as how to defeat it. In my research, I came across a set of Python scripts that extract out the book data from the encryption. It fits my needs for explaining the encryption-cracking part of my paper.
Problem is, I'm not fluent in Python or have any experience other than print 'Hello World'.
When working my way through the source code, I came across this snippet
def __init__(self, infile):
# initial sanity check on file
self.data_file = file(infile, 'rb').read()
self.mobi_data = ''
self.header = self.data_file[0:78]
if self.header[0x3C:0x3C+8] != 'BOOKMOBI' and self.header[0x3C:0x3C+8] != 'TEXtREAd':
raise DrmException("invalid file format")
self.magic = self.header[0x3C:0x3C+8]
self.crypto_type = -1
My interpretation of the code goes like this:
self.data_fileis a byte array that is returned byread()on thefile(infile, 'rb')call.self.headeris the value of the first 79 bytes of the data file
The problem I'm having is just what does self.header[0x3C:0x3C+8] mean?
[0:78]is 78, not 79. A slice doesn't include the ending value, so it's0..77.