parent
92dafd94b2
commit
d427f758f6
@ -1,123 +0,0 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
# ineptkeymac.py, version 1
|
||||
|
||||
# This program runs on Mac OS X, version 10.6.2 and probably several other
|
||||
# versions. It uses Python 2.6, but it probably also runs on all versions
|
||||
# 2.x with x >= 5.
|
||||
|
||||
# This program extracts the private RSA key for your ADE account in a
|
||||
# standard binary form (DER format) in a file of your choosing. Its purpose
|
||||
# is to make a backup of that key so that your legally bought ADE encoded
|
||||
# ebooks can be salvaged in case they would no longer be supported by ADE
|
||||
# software. No other usages are intended.
|
||||
|
||||
# It has been tested with the key storage structure of ADE 1.7.1 and 1.7.2
|
||||
# and Sony Reader Library.
|
||||
|
||||
# This software does not contain any encryption code. Its only use of
|
||||
# external encryption software is the use of openssl for the conversion of
|
||||
# the private key from pem to der format. It doesn't use encryption or
|
||||
# decryption, however.
|
||||
|
||||
# You can run this program from the command line (python ineptkeymac.py
|
||||
# filename), or by doubleclicking when it has been associated with
|
||||
# Pythonlauncher. When no filename is given it will show a dialog to obtain one.
|
||||
|
||||
from __future__ import with_statement
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
import sys
|
||||
import os
|
||||
import xml.etree.ElementTree as etree
|
||||
from contextlib import closing
|
||||
import Tkinter
|
||||
import Tkconstants
|
||||
import tkFileDialog
|
||||
from tkMessageBox import showerror
|
||||
from subprocess import Popen, PIPE
|
||||
import textwrap
|
||||
|
||||
NS = 'http://ns.adobe.com/adept'
|
||||
ACTFILE = '~/Library/Application Support/Adobe/Digital Editions/activation.dat'
|
||||
HEADER = '-----BEGIN PRIVATE KEY-----\n'
|
||||
FOOTER = '\n-----END PRIVATE KEY-----\n'
|
||||
|
||||
Gui = False
|
||||
|
||||
def get_key():
|
||||
'''Returns the private key as a binary string (DER format)'''
|
||||
try:
|
||||
filename = os.path.expanduser(ACTFILE)
|
||||
tree = etree.parse(filename)
|
||||
xpath = '//{%s}credentials/{%s}privateLicenseKey' % (NS, NS)
|
||||
b64key = tree.findtext(xpath)
|
||||
pemkey = HEADER + textwrap.fill(b64key, 64) + FOOTER
|
||||
|
||||
cmd = ['openssl', 'rsa', '-outform', 'der']
|
||||
proc = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
||||
stdout, stderr = proc.communicate(pemkey)
|
||||
|
||||
if proc.returncode != 0:
|
||||
error("openssl error: " + stderr)
|
||||
return None
|
||||
return stdout
|
||||
|
||||
except IOError:
|
||||
error("Can find keyfile. Maybe you should activate your Adobe ID.")
|
||||
sys.exit(1)
|
||||
|
||||
def store_key(key, keypath):
|
||||
'''Store the key in the file given as keypath. If no keypath is given a
|
||||
dialog will ask for one.'''
|
||||
|
||||
try:
|
||||
if keypath is None:
|
||||
keypath = get_keypath()
|
||||
if not keypath: # Cancelled
|
||||
return
|
||||
|
||||
with closing(open(keypath, 'wb')) as outf:
|
||||
outf.write(key)
|
||||
|
||||
except IOError, e:
|
||||
error("Can write keyfile: " + str(e))
|
||||
|
||||
def get_keypath():
|
||||
keypath = tkFileDialog.asksaveasfilename(
|
||||
parent = None, title = 'Select file to store ADEPT key',
|
||||
initialdir = os.path.expanduser('~/Desktop'),
|
||||
initialfile = 'adeptkey.der',
|
||||
defaultextension = '.der', filetypes = [('DER-encoded files', '.der'),
|
||||
('All Files', '.*')])
|
||||
if keypath:
|
||||
keypath = os.path.normpath(keypath)
|
||||
return keypath
|
||||
|
||||
def error(text):
|
||||
print text
|
||||
if Gui: showerror('Error!', text)
|
||||
|
||||
def gui_main():
|
||||
root = Tkinter.Tk()
|
||||
root.iconify()
|
||||
global Gui
|
||||
Gui = True
|
||||
store_key(get_key(), None)
|
||||
|
||||
return 0
|
||||
|
||||
def main(argv=sys.argv):
|
||||
progname = os.path.basename(argv[0])
|
||||
|
||||
if len(argv) == 1: # assume GUI if no argument given
|
||||
return gui_main()
|
||||
if len(argv) != 2:
|
||||
print "usage: %s KEYFILE" % (progname,)
|
||||
return 1
|
||||
|
||||
store_key(get_key(), argv[1])
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
@ -0,0 +1,88 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <conio.h>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Variables
|
||||
int TopazTrue = 0;
|
||||
int strlength = 0;
|
||||
char uinfile[80];
|
||||
char outfile[80];
|
||||
char command[80];
|
||||
char buffer[80];
|
||||
|
||||
// String initialization
|
||||
strcpy(uinfile,"");
|
||||
strcpy(outfile,"");
|
||||
strcpy(buffer,"");
|
||||
strcpy(command,"skindle "); // string preloaded with "skindle "
|
||||
|
||||
|
||||
cout << "\n\n\n Please enter the name of the book to be converted:\n\n ";
|
||||
cout << " Don't forget the prc file extension!\n\n ";
|
||||
cout << " Watch out for zeros and Os. Zeros are skinny and Os are fat.\n\n\n ";
|
||||
|
||||
cin >> uinfile; // get file name of the book to be converted from user
|
||||
|
||||
|
||||
ifstream infile(uinfile);
|
||||
infile.getline(buffer,4);
|
||||
|
||||
|
||||
if (strncmp (buffer,"TPZ",3)==0) // open file and test first 3 char if TPZ then book is topaz
|
||||
{
|
||||
TopazTrue = 1; // This is a Topaz file
|
||||
}
|
||||
|
||||
|
||||
strlength = strlen(uinfile);
|
||||
|
||||
if(strlength > 13)
|
||||
{
|
||||
strncat(outfile,uinfile,10); // Create output file name using first 10 char of input file name
|
||||
}
|
||||
else
|
||||
{
|
||||
strncat(outfile,uinfile, (strlength - 4)); // If file name is less than 10 characters
|
||||
}
|
||||
if(TopazTrue == 1) // This is Topaz Book
|
||||
{
|
||||
strcat(command,"-d "); // Add the topaz switch to the command line
|
||||
|
||||
strcat(outfile,".tpz"); // give tpz file extension to topaz output file
|
||||
} // end of TopazTrue
|
||||
else
|
||||
{
|
||||
strcat(outfile,".azw");
|
||||
} // if not Topaz make it azw
|
||||
|
||||
strcat(command,"-i "); // Add the input switch to the command line
|
||||
strcat(command,uinfile); // add the input file name to the command line
|
||||
strcat(command," -o "); // add the output switch to the command line
|
||||
strcat(command,outfile); // Add the output file name to the command line
|
||||
|
||||
cout << "\n\n The skindle program is called here.\n";
|
||||
cout << " Any errors reported between here and \"The command line used was:\"\n";
|
||||
cout << " Are errors from the skindle program. Not EZskindle4PC.\n\n";
|
||||
|
||||
|
||||
system(command); // call skindle program to convert the book
|
||||
|
||||
|
||||
cout << "\n\n The command line used was:\n\n";
|
||||
cout << " " << command << "\n";
|
||||
cout << "\n\n\n Please note the output file is created from the input";
|
||||
cout << "\n file name. The file extension is changed to tpz for Topaz";
|
||||
cout << "\n files and to azw for non-Topaz files. Also, _EBOK is removed ";
|
||||
cout << "\n from the file name. This is to make it eaiser to identify ";
|
||||
cout << "\n the file with no DRM.";
|
||||
|
||||
|
||||
|
||||
system("PAUSE");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Binary file not shown.
@ -0,0 +1,150 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
//#include <conio.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Variable Declarations ??
|
||||
char buffer[80];
|
||||
int error = 0;
|
||||
// int YesNo = 0;
|
||||
// int exit = 0;
|
||||
// Variables EZskindle4PC
|
||||
int TopazTrue = 0;
|
||||
int strlength = 0;
|
||||
char uinfile[80];
|
||||
char outfile[80];
|
||||
char command[80];
|
||||
char buffer2[20];
|
||||
char tempfile[80];
|
||||
|
||||
// Initialize strings
|
||||
strcpy(uinfile,"");
|
||||
strcpy(outfile,"");
|
||||
strcpy(buffer,"");
|
||||
strcpy(buffer2,"");
|
||||
strcpy(command,"skindle "); // string preloaded with "skindle "
|
||||
|
||||
|
||||
//// Beginning of program code ////////////////////////////////////////////////////////////
|
||||
|
||||
system("dir /b .\\input\\*.* > books.txt"); // Create txt file with list of books
|
||||
// No testing of file type being done
|
||||
// I am letting skindle determing if valid
|
||||
// file type
|
||||
// Read in the list of book file names
|
||||
|
||||
ifstream infile("books.txt");
|
||||
|
||||
do // while not end of file
|
||||
{
|
||||
infile.getline(buffer,50); // load the first 50 characters of the line to buffer
|
||||
|
||||
|
||||
if(strcmp(buffer, "")!= 0) // If there is file name in the buffer do this on last loop buffer will be empty
|
||||
{
|
||||
strcpy(uinfile,buffer); // load file name from buffer
|
||||
|
||||
strcpy(tempfile,".\\input\\"); // load directory name for input files
|
||||
strcat(tempfile,buffer); // load the file name
|
||||
ifstream infile2(tempfile); // open the book file for reading
|
||||
infile2.getline(buffer2,4); // load first 4 char from file
|
||||
|
||||
infile2.close(); // close the book file
|
||||
|
||||
|
||||
if (strncmp (buffer2,"TPZ",3)==0) // open file and test first 3 char if TPZ then book is topaz
|
||||
{
|
||||
TopazTrue = 1; // This is a Topaz file
|
||||
}
|
||||
|
||||
|
||||
strlength = strlen(uinfile);
|
||||
|
||||
if(strlength > 13)
|
||||
{
|
||||
strncat(outfile,uinfile,10); // Create output file name using first 10 char of input file name
|
||||
}
|
||||
else
|
||||
{
|
||||
strncat(outfile,uinfile, (strlength - 4)); // If file name is less than 10 characters
|
||||
}
|
||||
if(TopazTrue == 1) // This is Topaz Book
|
||||
{
|
||||
strcat(command,"-d "); // Add the topaz switch to the command line
|
||||
|
||||
strcat(outfile,".tpz"); // give tpz file extension to topaz output file
|
||||
} // end of TopazTrue
|
||||
else
|
||||
{
|
||||
strcat(outfile,".azw");
|
||||
} // if not Topaz make it azw
|
||||
|
||||
strcat(command,"-i "); // Add the input switch to the command line
|
||||
strcat(command,".\\input\\"); // Add the input directory to the command line
|
||||
strcat(command,uinfile); // add the input file name to the command line
|
||||
strcat(command," -o "); // add the output switch to the command line
|
||||
strcat(command,".\\output\\"); // Add directory for out files
|
||||
strcat(command,outfile); // Add the output file name to the command line
|
||||
|
||||
cout << "\n\n The skindle program is called here.\n";
|
||||
cout << " Any errors reported between here and \"The command line used was:\"\n";
|
||||
cout << " Are errors from the skindle program. Not EZskindle4PC.\n\n";
|
||||
|
||||
|
||||
system(command); // call skindle program to convert the book
|
||||
|
||||
|
||||
cout << "\n\n The command line used was:\n\n";
|
||||
cout << " " << command << "\n\n\n\n";
|
||||
|
||||
|
||||
}// end of file name in the buffer required to prevent execution on EOF
|
||||
|
||||
|
||||
|
||||
strcpy(command,"skindle "); // reset strings and variables for next book
|
||||
strcpy(outfile,"");
|
||||
strcpy(uinfile,"");
|
||||
strcpy(buffer,"");
|
||||
strcpy(buffer2,"");
|
||||
TopazTrue = 0;
|
||||
strlength = 0;
|
||||
|
||||
}while (! infile.eof() ); // no more books in the file
|
||||
|
||||
infile.close(); // close books.txt
|
||||
|
||||
|
||||
// cout << "\n\n\n Do you want to delete all of the books from the input directory?\n\n";
|
||||
// cout << " DO NOT DELETE IF THESE ARE ONLY COPY OF YOUR BOOKS!!!!\n\n";
|
||||
// cout << " Y or N: ";
|
||||
|
||||
|
||||
// do { // while not yes or no
|
||||
// YesNo = getch(); // This is a DOS/Windows console command not standard C may not be
|
||||
// // Usable under Unix or Mac implementations
|
||||
//
|
||||
// if((YesNo == 121)||(YesNo == 89)) // y or Y is true
|
||||
// {
|
||||
// exit = 1; // valid input exit do while loop
|
||||
// cout << "\n\n";
|
||||
// system("del .\\input\\*.*"); // delete everything in the input directory
|
||||
// cout << "\n\n";
|
||||
// }
|
||||
// if((YesNo == 110)||(YesNo == 78)) // n or N is true
|
||||
// {
|
||||
// exit = 1; // valid input exit do while loop
|
||||
// }
|
||||
//
|
||||
// }while (exit != 1);
|
||||
// cout << "\n\nYesNo = " << YesNo << "\n\n";
|
||||
|
||||
system("PAUSE");
|
||||
|
||||
system("del books.txt"); // Delete txt file with list of books
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Binary file not shown.
@ -0,0 +1,200 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab
|
||||
|
||||
import sys
|
||||
sys.path.append('lib')
|
||||
|
||||
import os, os.path, urllib
|
||||
import subprocess
|
||||
from subprocess import Popen, PIPE, STDOUT
|
||||
import Tkinter
|
||||
import Tkconstants
|
||||
import tkFileDialog
|
||||
import tkMessageBox
|
||||
import subasyncio
|
||||
from subasyncio import Process
|
||||
from scrolltextwidget import ScrolledText
|
||||
|
||||
class MainDialog(Tkinter.Frame):
|
||||
def __init__(self, root):
|
||||
Tkinter.Frame.__init__(self, root, border=5)
|
||||
self.root = root
|
||||
self.interval = 2000
|
||||
self.p2 = None
|
||||
self.status = Tkinter.Label(self, text='Extract Contents of Topaz eBook to a Directory')
|
||||
self.status.pack(fill=Tkconstants.X, expand=1)
|
||||
body = Tkinter.Frame(self)
|
||||
body.pack(fill=Tkconstants.X, expand=1)
|
||||
sticky = Tkconstants.E + Tkconstants.W
|
||||
body.grid_columnconfigure(1, weight=2)
|
||||
|
||||
Tkinter.Label(body, text='Topaz eBook input file').grid(row=0, sticky=Tkconstants.E)
|
||||
self.tpzpath = Tkinter.Entry(body, width=50)
|
||||
self.tpzpath.grid(row=0, column=1, sticky=sticky)
|
||||
cwd = os.getcwdu()
|
||||
cwd = cwd.encode('utf-8')
|
||||
self.tpzpath.insert(0, cwd)
|
||||
button = Tkinter.Button(body, text="...", command=self.get_tpzpath)
|
||||
button.grid(row=0, column=2)
|
||||
|
||||
Tkinter.Label(body, text='Output Directory').grid(row=1, sticky=Tkconstants.E)
|
||||
self.outpath = Tkinter.Entry(body, width=50)
|
||||
self.outpath.grid(row=1, column=1, sticky=sticky)
|
||||
cwd = os.getcwdu()
|
||||
cwd = cwd.encode('utf-8')
|
||||
self.outpath.insert(0, cwd)
|
||||
button = Tkinter.Button(body, text="...", command=self.get_outpath)
|
||||
button.grid(row=1, column=2)
|
||||
|
||||
Tkinter.Label(body, text='First 8 characters of PID').grid(row=3, sticky=Tkconstants.E)
|
||||
self.pidnum = Tkinter.StringVar()
|
||||
self.ccinfo = Tkinter.Entry(body, width=10, textvariable=self.pidnum)
|
||||
self.ccinfo.grid(row=3, column=1, sticky=sticky)
|
||||
|
||||
msg1 = 'Conversion Log \n\n'
|
||||
self.stext = ScrolledText(body, bd=5, relief=Tkconstants.RIDGE, height=15, width=60, wrap=Tkconstants.WORD)
|
||||
self.stext.grid(row=4, column=0, columnspan=2,sticky=sticky)
|
||||
self.stext.insert(Tkconstants.END,msg1)
|
||||
|
||||
buttons = Tkinter.Frame(self)
|
||||
buttons.pack()
|
||||
self.sbotton = Tkinter.Button(
|
||||
buttons, text="Start", width=10, command=self.convertit)
|
||||
self.sbotton.pack(side=Tkconstants.LEFT)
|
||||
|
||||
Tkinter.Frame(buttons, width=10).pack(side=Tkconstants.LEFT)
|
||||
self.qbutton = Tkinter.Button(
|
||||
buttons, text="Quit", width=10, command=self.quitting)
|
||||
self.qbutton.pack(side=Tkconstants.RIGHT)
|
||||
|
||||
# read from subprocess pipe without blocking
|
||||
# invoked every interval via the widget "after"
|
||||
# option being used, so need to reset it for the next time
|
||||
def processPipe(self):
|
||||
poll = self.p2.wait('nowait')
|
||||
if poll != None:
|
||||
text = self.p2.readerr()
|
||||
text += self.p2.read()
|
||||
msg = text + '\n\n' + 'Files successfully extracted\n'
|
||||
if poll != 0:
|
||||
msg = text + '\n\n' + 'Error: File Extraction Failed\n'
|
||||
self.showCmdOutput(msg)
|
||||
self.p2 = None
|
||||
self.sbotton.configure(state='normal')
|
||||
return
|
||||
text = self.p2.readerr()
|
||||
text += self.p2.read()
|
||||
self.showCmdOutput(text)
|
||||
# make sure we get invoked again by event loop after interval
|
||||
self.stext.after(self.interval,self.processPipe)
|
||||
return
|
||||
|
||||
# post output from subprocess in scrolled text widget
|
||||
def showCmdOutput(self, msg):
|
||||
if msg and msg !='':
|
||||
msg = msg.encode('utf-8')
|
||||
self.stext.insert(Tkconstants.END,msg)
|
||||
self.stext.yview_pickplace(Tkconstants.END)
|
||||
return
|
||||
|
||||
# run as a subprocess via pipes and collect stdout
|
||||
def topazrdr(self, infile, outdir, pidnum):
|
||||
# os.putenv('PYTHONUNBUFFERED', '1')
|
||||
pidoption = ' -p "' + pidnum + '" '
|
||||
outoption = ' -o "' + outdir + '" '
|
||||
cmdline = 'python ./lib/cmbtc_dump_nonK4PC.py -v -d ' + pidoption + outoption + '"' + infile + '"'
|
||||
if sys.platform[0:3] == 'win':
|
||||
search_path = os.environ['PATH']
|
||||
search_path = search_path.lower()
|
||||
if search_path.find('python') >= 0:
|
||||
cmdline = 'python lib\cmbtc_dump_nonK4PC.py -v -d ' + pidoption + outoption + '"' + infile + '"'
|
||||
else :
|
||||
cmdline = 'lib\cmbtc_dump_nonK4PC.py -v -d ' + pidoption + outoption + '"' + infile + '"'
|
||||
|
||||
cmdline = cmdline.encode(sys.getfilesystemencoding())
|
||||
p2 = Process(cmdline, shell=True, bufsize=1, stdin=None, stdout=PIPE, stderr=PIPE, close_fds=False)
|
||||
return p2
|
||||
|
||||
|
||||
def get_tpzpath(self):
|
||||
tpzpath = tkFileDialog.askopenfilename(
|
||||
parent=None, title='Select Topaz File',
|
||||
defaultextension='.prc', filetypes=[('Topaz azw1', '.azw1'), ('Topaz prc', '.prc'),('Topaz azw', '.azw'),
|
||||
('All Files', '.*')])
|
||||
if tpzpath:
|
||||
tpzpath = os.path.normpath(tpzpath)
|
||||
self.tpzpath.delete(0, Tkconstants.END)
|
||||
self.tpzpath.insert(0, tpzpath)
|
||||
return
|
||||
|
||||
def get_outpath(self):
|
||||
cwd = os.getcwdu()
|
||||
cwd = cwd.encode('utf-8')
|
||||
outpath = tkFileDialog.askdirectory(
|
||||
parent=None, title='Directory to Extract Files into',
|
||||
initialdir=cwd, initialfile=None)
|
||||
if outpath:
|
||||
outpath = os.path.normpath(outpath)
|
||||
self.outpath.delete(0, Tkconstants.END)
|
||||
self.outpath.insert(0, outpath)
|
||||
return
|
||||
|
||||
def quitting(self):
|
||||
# kill any still running subprocess
|
||||
if self.p2 != None:
|
||||
if (self.p2.wait('nowait') == None):
|
||||
self.p2.terminate()
|
||||
self.root.destroy()
|
||||
|
||||
# actually ready to run the subprocess and get its output
|
||||
def convertit(self):
|
||||
# now disable the button to prevent multiple launches
|
||||
self.sbotton.configure(state='disabled')
|
||||
tpzpath = self.tpzpath.get()
|
||||
outpath = self.outpath.get()
|
||||
if not tpzpath or not os.path.exists(tpzpath):
|
||||
self.status['text'] = 'Specified Topaz eBook file does not exist'
|
||||
self.sbotton.configure(state='normal')
|
||||
return
|
||||
if not outpath:
|
||||
self.status['text'] = 'No output directory specified'
|
||||
self.sbotton.configure(state='normal')
|
||||
return
|
||||
if not os.path.exists(outpath):
|
||||
os.makedirs(outpath)
|
||||
pidnum = self.pidnum.get()
|
||||
if not pidnum or pidnum == '':
|
||||
self.status['text'] = 'You have not entered a PID '
|
||||
self.sbotton.configure(state='normal')
|
||||
return
|
||||
|
||||
log = 'Command = "python cmbtc_dump_nonK4PC.py"\n'
|
||||
log += 'Topaz Path Path = "'+ tpzpath + '"\n'
|
||||
log += 'Output Directory = "' + outpath + '"\n'
|
||||
log += 'First 8 chars of PID = "' + pidnum + '"\n'
|
||||
log += '\n\n'
|
||||
log += 'Please Wait ...\n'
|
||||
log = log.encode('utf-8')
|
||||
self.stext.insert(Tkconstants.END,log)
|
||||
self.p2 = self.topazrdr(tpzpath, outpath, pidnum)
|
||||
|
||||
# python does not seem to allow you to create
|
||||
# your own eventloop which every other gui does - strange
|
||||
# so need to use the widget "after" command to force
|
||||
# event loop to run non-gui events every interval
|
||||
self.stext.after(self.interval,self.processPipe)
|
||||
return
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
root = Tkinter.Tk()
|
||||
root.title('Topaz eBook File Extraction')
|
||||
root.resizable(True, False)
|
||||
root.minsize(300, 0)
|
||||
MainDialog(root).pack(fill=Tkconstants.X, expand=1)
|
||||
root.mainloop()
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
Loading…
Reference in New Issue