More general changes, and get mobidedrm and kindlekey to work on Mac.

This commit is contained in:
Apprentice Harper
2020-10-14 16:23:49 +01:00
parent e31752e334
commit 781268e17e
32 changed files with 479 additions and 497 deletions

View File

@@ -58,10 +58,11 @@ class SafeUnbuffered:
if self.encoding == None:
self.encoding = "utf-8"
def write(self, data):
if isinstance(data,bytes):
if isinstance(data, str):
data = data.encode(self.encoding,"replace")
self.stream.write(data)
self.stream.flush()
self.stream.buffer.write(data)
self.stream.buffer.flush()
def __getattr__(self, attr):
return getattr(self.stream, attr)
@@ -473,79 +474,79 @@ def cli_main():
def gui_main():
try:
import Tkinter
import Tkconstants
import tkFileDialog
import tkMessageBox
import tkinter
import tkinter_constants
import tkinter_filedialog
import tkinter_messagebox
import traceback
except:
return cli_main()
class DecryptionDialog(Tkinter.Frame):
class DecryptionDialog(tkinter.Frame):
def __init__(self, root):
Tkinter.Frame.__init__(self, root, border=5)
self.status = Tkinter.Label(self, text="Select files for decryption")
self.status.pack(fill=Tkconstants.X, expand=1)
body = Tkinter.Frame(self)
body.pack(fill=Tkconstants.X, expand=1)
sticky = Tkconstants.E + Tkconstants.W
tkinter.Frame.__init__(self, root, border=5)
self.status = tkinter.Label(self, text="Select files for decryption")
self.status.pack(fill=tkinter_constants.X, expand=1)
body = tkinter.Frame(self)
body.pack(fill=tkinter_constants.X, expand=1)
sticky = tkinter_constants.E + tkinter_constants.W
body.grid_columnconfigure(1, weight=2)
Tkinter.Label(body, text="Key file").grid(row=0)
self.keypath = Tkinter.Entry(body, width=30)
tkinter.Label(body, text="Key file").grid(row=0)
self.keypath = tkinter.Entry(body, width=30)
self.keypath.grid(row=0, column=1, sticky=sticky)
if os.path.exists("adeptkey.der"):
self.keypath.insert(0, "adeptkey.der")
button = Tkinter.Button(body, text="...", command=self.get_keypath)
button = tkinter.Button(body, text="...", command=self.get_keypath)
button.grid(row=0, column=2)
Tkinter.Label(body, text="Input file").grid(row=1)
self.inpath = Tkinter.Entry(body, width=30)
tkinter.Label(body, text="Input file").grid(row=1)
self.inpath = tkinter.Entry(body, width=30)
self.inpath.grid(row=1, column=1, sticky=sticky)
button = Tkinter.Button(body, text="...", command=self.get_inpath)
button = tkinter.Button(body, text="...", command=self.get_inpath)
button.grid(row=1, column=2)
Tkinter.Label(body, text="Output file").grid(row=2)
self.outpath = Tkinter.Entry(body, width=30)
tkinter.Label(body, text="Output file").grid(row=2)
self.outpath = tkinter.Entry(body, width=30)
self.outpath.grid(row=2, column=1, sticky=sticky)
button = Tkinter.Button(body, text="...", command=self.get_outpath)
button = tkinter.Button(body, text="...", command=self.get_outpath)
button.grid(row=2, column=2)
buttons = Tkinter.Frame(self)
buttons = tkinter.Frame(self)
buttons.pack()
botton = Tkinter.Button(
botton = tkinter.Button(
buttons, text="Decrypt", width=10, command=self.decrypt)
botton.pack(side=Tkconstants.LEFT)
Tkinter.Frame(buttons, width=10).pack(side=Tkconstants.LEFT)
button = Tkinter.Button(
botton.pack(side=tkinter_constants.LEFT)
tkinter.Frame(buttons, width=10).pack(side=tkinter_constants.LEFT)
button = tkinter.Button(
buttons, text="Quit", width=10, command=self.quit)
button.pack(side=Tkconstants.RIGHT)
button.pack(side=tkinter_constants.RIGHT)
def get_keypath(self):
keypath = tkFileDialog.askopenfilename(
keypath = tkinter_filedialog.askopenfilename(
parent=None, title="Select Adobe Adept \'.der\' key file",
defaultextension=".der",
filetypes=[('Adobe Adept DER-encoded files', '.der'),
('All Files', '.*')])
if keypath:
keypath = os.path.normpath(keypath)
self.keypath.delete(0, Tkconstants.END)
self.keypath.delete(0, tkinter_constants.END)
self.keypath.insert(0, keypath)
return
def get_inpath(self):
inpath = tkFileDialog.askopenfilename(
inpath = tkinter_filedialog.askopenfilename(
parent=None, title="Select ADEPT-encrypted ePub file to decrypt",
defaultextension=".epub", filetypes=[('ePub files', '.epub')])
if inpath:
inpath = os.path.normpath(inpath)
self.inpath.delete(0, Tkconstants.END)
self.inpath.delete(0, tkinter_constants.END)
self.inpath.insert(0, inpath)
return
def get_outpath(self):
outpath = tkFileDialog.asksaveasfilename(
outpath = tkinter_filedialog.asksaveasfilename(
parent=None, title="Select unencrypted ePub file to produce",
defaultextension=".epub", filetypes=[('ePub files', '.epub')])
if outpath:
outpath = os.path.normpath(outpath)
self.outpath.delete(0, Tkconstants.END)
self.outpath.delete(0, tkinter_constants.END)
self.outpath.insert(0, outpath)
return
@@ -577,11 +578,11 @@ def gui_main():
else:
self.status['text'] = "The was an error decrypting the file."
root = Tkinter.Tk()
root = tkinter.Tk()
root.title("Adobe Adept ePub Decrypter v.{0}".format(__version__))
root.resizable(True, False)
root.minsize(300, 0)
DecryptionDialog(root).pack(fill=Tkconstants.X, expand=1)
DecryptionDialog(root).pack(fill=tkinter_constants.X, expand=1)
root.mainloop()
return 0