"""
Decrypts Barnes & Noble encrypted PDF files.
"""
+from __future__ import print_function
__license__ = 'GPL v3'
__version__ = "0.1"
if not pos:
pos = self.bufpos+self.charpos
self.fp.seek(pos)
- ##print >>sys.stderr, 'poll(%d): %r' % (pos, self.fp.read(n))
+ # print('poll(%d): %r' % (pos, self.fp.read(n)), file=sys.stderr)
self.fp.seek(pos0)
return
'''
while not self.results:
(pos, token) = self.nexttoken()
- ##print (pos,token), (self.curtype, self.curstack)
+ # print((pos, token), (self.curtype, self.curstack))
if (isinstance(token, int) or
isinstance(token, Decimal) or
isinstance(token, bool) or
try:
(pos, objs) = self.end_type('d')
if len(objs) % 2 != 0:
- print "Incomplete dictionary construct"
+ print("Incomplete dictionary construct")
objs.append("") # this isn't necessary.
# temporary fix. is this due to rental books?
# raise PSSyntaxError(
if 'Filter' not in self.dic:
self.data = data
self.rawdata = None
- ##print self.dict
+ ##print(self.dict)
return
filters = self.dic['Filter']
if not isinstance(filters, list):
V = ord(bookkey[0])
bookkey = bookkey[1:]
else:
- print "ebx_V is %d and ebx_type is %d" % (ebx_V, ebx_type)
- print "length is %d and len(bookkey) is %d" % (length, len(bookkey))
- print "bookkey[0] is %d" % ord(bookkey[0])
+ print("ebx_V is %d and ebx_type is %d" % (ebx_V, ebx_type))
+ print("length is %d and len(bookkey) is %d" % (length, len(bookkey)))
+ print("bookkey[0] is %d" % ord(bookkey[0]))
raise IGNOBLEError('error decrypting book session key - mismatched length')
else:
# proper length unknown try with whatever you have
- print "ebx_V is %d and ebx_type is %d" % (ebx_V, ebx_type)
- print "length is %d and len(bookkey) is %d" % (length, len(bookkey))
- print "bookkey[0] is %d" % ord(bookkey[0])
+ print("ebx_V is %d and ebx_type is %d" % (ebx_V, ebx_type))
+ print("length is %d and len(bookkey) is %d" % (length, len(bookkey)))
+ print("bookkey[0] is %d" % ord(bookkey[0]))
if ebx_V == 3:
V = 3
else:
plaintext = AES.new(key,AES.MODE_CBC,ivector).decrypt(data)
# remove pkcs#5 aes padding
cutter = -1 * ord(plaintext[-1])
- #print cutter
+ #print(cutter)
plaintext = plaintext[:cutter]
return plaintext
plaintext = AES.new(key,AES.MODE_CBC,ivector).decrypt(data)
# remove pkcs#5 aes padding
cutter = -1 * ord(plaintext[-1])
- #print cutter
+ #print(cutter)
plaintext = plaintext[:cutter]
return plaintext
#try:
serializer = PDFSerializer(inf, userkey)
#except:
- # print "Error serializing pdf {0}. Probably wrong key.".format(os.path.basename(inpath))
+ # print("Error serializing pdf {0}. Probably wrong key.".format(os.path.basename(inpath)))
# return 2
# hope this will fix the 'bad file descriptor' problem
with open(outpath, 'wb') as outf:
try:
serializer.dump(outf)
except Exception, e:
- print "error writing pdf: {0}".format(e.args[0])
+ print("error writing pdf: {0}".format(e.args[0]))
return 2
return 0
argv=unicode_argv()
progname = os.path.basename(argv[0])
if len(argv) != 4:
- print "usage: {0} <keyfile.b64> <inbook.pdf> <outbook.pdf>".format(progname)
+ print("usage: {0} <keyfile.b64> <inbook.pdf> <outbook.pdf>".format(progname))
return 1
keypath, inpath, outpath = argv[1:]
userkey = open(keypath,'rb').read()
result = decryptBook(userkey, inpath, outpath)
if result == 0:
- print "Successfully decrypted {0:s} as {1:s}".format(os.path.basename(inpath),os.path.basename(outpath))
+ print("Successfully decrypted {0:s} as {1:s}".format(os.path.basename(inpath),os.path.basename(outpath)))
return result