]> xmof Git - DeDRM.git/commitdiff
Altered standalone invokation
authorSatsuoni <satsuoni@gmail.com>
Tue, 24 Jun 2025 01:37:02 +0000 (10:37 +0900)
committerSatsuoni <satsuoni@gmail.com>
Tue, 24 Jun 2025 01:37:02 +0000 (10:37 +0900)
DeDRM_plugin/__main__.py
DeDRM_plugin/kfxdedrm.py
DeDRM_plugin/standalone/__init__.py
DeDRM_plugin/standalone/remove_drm.py
Other_Tools/KRFKeyExtractor/KRFKeyExtractor.cpp
Other_Tools/KRFKeyExtractor/kindleFridaInstr.py

index 6c925d250663531ffe43bd350eff48d2d148cc64..cd10bd216b4b6c0863fe25f3be69a77b2e0ef304 100644 (file)
@@ -27,8 +27,12 @@ Run DeDRM plugin without Calibre.
 
 # Import __init__.py from the standalone folder so we can have all the 
 # standalone / non-Calibre code in that subfolder.
-
-import standalone.__init__ as mdata
+try:
+  import standalone.__init__ as mdata
+  mn=mdata.main
+except:
+  from . import standalone
+  mdata=standalone.main
+  mn=mdata
 import sys
-
-mdata.main(sys.argv)
\ No newline at end of file
+mn(sys.argv)
\ No newline at end of file
index a2f887ca68e0868ea1bcb4d7a3493cad3f2c890b..bc3139a31eb322ab332a62c4731d6ca7b0820bba 100644 (file)
@@ -70,8 +70,10 @@ class KFXZipBook:
                     if b'ProtectedData' in data:
                         break   # found DRM voucher
             else:
-                raise Exception("The .kfx-zip archive contains an encrypted DRMION file without a DRM voucher")
-
+                #raise Exception("The .kfx-zip archive contains an encrypted DRMION file without a DRM voucher")
+                print("The .kfx-zip archive contains an encrypted DRMION file without a DRM voucher. Just in case it is a rare decrypted KFX, we continue")
+                self.voucher = None
+                return
         print("Decrypting KFX DRM voucher: {0}".format(info.filename))
 
         for pid in [''] + totalpids:
index 60d236ea66a6f989415bd091a9f8a9959072617b..17a2ad9e7a8c968bb73096f9a8ff6e625d174322 100644 (file)
@@ -54,8 +54,7 @@ _function = None
 global config_file_path
 config_file_path = "dedrm.json"
 
-# Path to a Kindle voucher key file passed via --keyfile
-kfx_skeyfile = None
+# Path to a Kindle voucher key file passed via --keyfile now in remove_drm
 
 def print_fname(f, info):
     print("  " + f.ljust(15) + " " + info)
@@ -130,9 +129,6 @@ def handle_single_argument(arg, next):
     used_up = 0
     global _additional_params
     global config_file_path
-    
-    global kfx_skeyfile
-
     if arg in ["--username", "--password", "--output", "--outputdir", "--keyfile"]:
         used_up = 1
         _additional_params.append(arg)
@@ -143,7 +139,7 @@ def handle_single_argument(arg, next):
         else:
             val = next[0]
             if arg == "--keyfile":
-                kfx_skeyfile = val
+                _additional_params.append(val)
             else:
                 _additional_params.append(val)
     
@@ -212,14 +208,13 @@ def main(argv):
     skip_opts = False
 
     # First element is always the ZIP name, remove that. 
-    if not arguments[0].lower().endswith(".zip") and not "calibre" in sys.modules:
-        print("Warning: File name does not end in .zip ...")
-        print(arguments)
+    #if not arguments[0].lower().endswith(".zip") and not "calibre" in sys.modules:
+    #    print("Warning: File name does not end in .zip ...")
+    #    print(arguments)
     arguments.pop(0)
 
     while len(arguments) > 0:
         arg = arguments.pop(0)
-
         if arg == "--":
             skip_opts = True
             continue
index 8f26d921ae809cb72179084ba17e26761ae4efb8..68148b5d718600374d8c6f8520736cd3b4641dfc 100644 (file)
@@ -110,7 +110,7 @@ def determine_file_type(file):
      
 
 
-def dedrm_single_file(input_file, output_file):
+def dedrm_single_file(input_file, output_file,skeyfile=None):
     # When this runs, all the stupid file handling is done. 
     # Just take the file at the absolute path "input_file"
     # and export it, DRM-free, to "output_file". 
@@ -150,8 +150,8 @@ def dedrm_single_file(input_file, output_file):
 
     if ftype == "KFX-ZIP":
         from ..kfxdedrm import KFXZipBook
-        from .__init__ import kfx_skeyfile
-        keyfile = kfx_skeyfile
+        keyfile = skeyfile
+        print(f"Using keyfile {keyfile}")
         temp_keyfile = None
         try:
             book = KFXZipBook(input_file, keyfile)
@@ -181,7 +181,7 @@ def perform_action(params, files):
     outputdir = None
     force = False
     overwrite_original = False
-
+    skeyfile=None
 
     if len(files) == 0:
         print_removedrm_help()
@@ -193,6 +193,8 @@ def perform_action(params, files):
             output = params.pop(0)
         elif p == "--outputdir":
             outputdir = params.pop(0)
+        elif p == "--keyfile":
+            skeyfile = params.pop(0)
         elif p == "--force":
             force = True
         elif p == "--overwrite":
@@ -258,7 +260,7 @@ def perform_action(params, files):
 
         
 
-        dedrm_single_file(file, output_filename)
+        dedrm_single_file(file, output_filename,skeyfile)
 
        
 
index 6bd8b75cb9d872b00d5890ddebcd24a82ede9ba2..f2bde73d76b41d7626520c823286bd087d84f599 100644 (file)
@@ -270,7 +270,6 @@ bool enumerateKindleFolder(TCHAR *path, DrmParameters * out)
 }
 
 
-
 int  tryOpeningBook(KrfAccessFunctions* ctx, const std::string& serial, const std::string& secret, DrmParameters* params,KeyData* out)
 {
     keydataAccumulator.reset();
@@ -280,16 +279,23 @@ int  tryOpeningBook(KrfAccessFunctions* ctx, const std::string& serial, const st
     secrets.push_back(secret);
     ctx->DrmDataProvider((void*)sub, serial, secrets, params->vouchers);
     void* bookFactory = ctx->GetBookFactory();
-    int rebook[2];
+    //int rebook[2] = { 0 };
+    std::shared_ptr<void*> rebook;
     krfErr err;
     err.code = 0;
-    ctx->OpenBook(bookFactory, rebook, params->bookFile, sub, &err, params->resources);
+    ctx->OpenBook(bookFactory, &rebook, params->bookFile, sub, &err, params->resources);
     std::cout << "BookOpen error " << err.code << " " << err.msg << std::endl;
     if (err.code == 0)
     {
         out->aggregate( &keydataAccumulator);
         //return true;
     }
+    //std::cout << rebook[0]<< std::endl;
+    if (rebook != nullptr)
+    {
+        rebook.reset();
+    }
+
     return err.code;
 }
 
@@ -713,7 +719,7 @@ int main(int argc, char* argv[])
     {
         std::cout << "Usage: executable <memdump path> <kindle documents path> <output file>" << std::endl;
         std::cout << "This program needs accress to Kindle dlls, so it is easiest to run it in the folder with kindle executable or copied dlls" << std::endl;
-        std::cout << "Please ensure that KRFDynamic.dll is of the appropriate version (currently md5 22ccc712f186e3f03567e2bec2189d6a, kindle 2.7.1(70978)" << std::endl;
+        std::cout << "Please ensure that KRFDynamic.dll is of the appropriate version (currently md5 22ccc712f186e3f03567e2bec2189d6a, kindle 2.7.1(70978))" << std::endl;
         return 1;
     }
     HINSTANCE hinstLib;
@@ -721,6 +727,7 @@ int main(int argc, char* argv[])
     std::string dump_path = argv[1];
     std::string folder_path = argv[2];
     std::string out_path = argv[3];
+    std::cout << folder_path << std:: endl;
     //this is a bit dumb but I don't know of good ways of flipping between char types
     std::basic_string<TCHAR> wfolder_path = std::basic_string<wchar_t>(folder_path.begin(),folder_path.end());
     if (hinstLib)
index 9e92b33ae724856f2158b5244f47aba9dfd523d1..f77d5e402addcebdf496be1880ed6d5ba5395a14 100644 (file)
@@ -6,6 +6,7 @@ from frida_tools.reactor import Reactor
 import threading
 import sys
 import signal
+import numbers
 ##copied out from ion.py and subtly modified
 
 TID_NULL = 0
@@ -832,11 +833,10 @@ class MiniReactor(object):
         else:
             if host=="local":
                 self._host=None
-                self._device_type="local"
+                self._device_type=None#"local"
             else:
                 self._host=host
                 self._device_type="remote"
-        self._host=host
         self._device_id=None
         self._keepalive_interval=None
         self._schedule_on_output = lambda pid, fd, data: self._reactor.schedule(lambda: self._on_output(pid, fd, data))
@@ -872,7 +872,7 @@ class MiniReactor(object):
                 return
         elif (self._host is not None) or (self._device_type == "remote"):
             host = self._host
-
+            print("remote")
             options = {}
             if self._keepalive_interval is not None:
                 options["keepalive_interval"] = self._keepalive_interval