Skip to content

Commit

Permalink
DeDRM ion: Clean out errorneous whitespace and UTF8 definition from p…
Browse files Browse the repository at this point in the history
…ython 2 times
  • Loading branch information
C0rn3j authored and noDRM committed Nov 10, 2024
1 parent 3373d93 commit 195ea69
Showing 1 changed file with 28 additions and 32 deletions.
60 changes: 28 additions & 32 deletions DeDRM_plugin/ion.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# ion.py
# Copyright © 2013-2020 Apprentice Harper et al.

__license__ = 'GPL v3'
__version__ = '3.0'

# Revision history:
# Pascal implementation by lulzkabulz.
# BinaryIon.pas + DrmIon.pas + IonSymbols.pas
# 1.0 - Python translation by apprenticenaomi.
# 1.1 - DeDRM integration by anon.
# 1.2 - Added pylzma import fallback
# 1.3 - Fixed lzma support for calibre 4.6+
# 2.0 - VoucherEnvelope v2/v3 support by apprenticesakuya.
# 3.0 - Added Python 3 compatibility for calibre 5.0

"""
Decrypt Kindle KFX files.
"""ion.py: Decrypt Kindle KFX files.
Revision history:
Pascal implementation by lulzkabulz.
BinaryIon.pas + DrmIon.pas + IonSymbols.pas
1.0 - Python translation by apprenticenaomi.
1.1 - DeDRM integration by anon.
1.2 - Added pylzma import fallback
1.3 - Fixed lzma support for calibre 4.6+
2.0 - VoucherEnvelope v2/v3 support by apprenticesakuya.
3.0 - Added Python 3 compatibility for calibre 5.0
Copyright © 2013-2020 Apprentice Harper et al.
"""

import collections
Expand All @@ -30,6 +23,9 @@

from io import BytesIO

__license__ = 'GPL v3'
__version__ = '3.0'

#@@CALIBRE_COMPAT_CODE@@


Expand Down Expand Up @@ -1096,11 +1092,11 @@ def process_V9888(st):
ws.sbox(d0x6a0bf4d0,d0x6a0dab50,[1,2])
ws.sbox(d0x6a0ba4d0,d0x6a0dab50,[1,2])
ws.shuffle(repl)
ws.shuffle(repl)
ws.shuffle(repl)
ws.shuffle(repl)
ws.sbox(d0x6a0bf4d0,d0x6a0dab50,[1,2])
ws.sbox(d0x6a0ba4d0,d0x6a0dab50,[1,2])
ws.exlookup(d0x6a0be4d0)
ws.exlookup(d0x6a0be4d0)
dat=ws.mask(st[sto:sto+16])
out+=dat
sto+=16
Expand All @@ -1124,7 +1120,7 @@ def process_V4648(st):
ws.sbox(d0x6a0c51a8,d0x6a0dab50,[1,3])
ws.shuffle(repl)
ws.shuffle(repl)
ws.exlookup(d0x6a0c91a8)
ws.exlookup(d0x6a0c91a8)
dat=ws.mask(st[sto:sto+16])
out+=dat
sto+=16
Expand All @@ -1148,7 +1144,7 @@ def process_V5683(st):
ws.shuffle(repl)
ws.sbox(d0x6a0cfe80,d0x6a0dab50,[])
ws.shuffle(repl)
ws.exlookup(d0x6a0d3e80)
ws.exlookup(d0x6a0d3e80)
dat=ws.mask(st[sto:sto+16])
out+=dat
sto+=16
Expand All @@ -1163,12 +1159,12 @@ def process_V5683(st):
# if a<0: a=256+a
# ax.append(ha[(a>>4)]+ha[a%16])
# return "".join(ax)
#
#
# def memhex(adr,sz):
# emu=EmulatorHelper(currentProgram)
# arr=emu.readMemory(getAddress(adr),sz)
# return a2hex(arr)
#
#



Expand Down Expand Up @@ -1254,7 +1250,7 @@ def scramble3(st,magic):
iVar5 = iVar5 - magic
index -= 1
if uVar4<=-1: break
else:
else:
if (offset < magic):
iVar3 = 0
else :
Expand All @@ -1274,9 +1270,9 @@ def scramble3(st,magic):
index=index-1
iVar5 = iVar5 + magic;
cntr += 1;
if iVar3>=divs: break
if iVar3>=divs: break
offset = offset + 1
if offset >= ((magic - 1) + divs) :break
if offset >= ((magic - 1) + divs) :break
return ret

#not sure if the third variant is used anywhere, but it is in Kindle, so I tried to add it
Expand Down Expand Up @@ -1342,12 +1338,12 @@ def decryptvoucher(self):
_assert(False, "Unknown lock parameter: %s" % param)


# i know that version maps to scramble pretty much 1 to 1, but there was precendent where they changed it, so...
# i know that version maps to scramble pretty much 1 to 1, but there was precendent where they changed it, so...
sharedsecrets = [obfuscate(shared, self.version),obfuscate2(shared, self.version),obfuscate3(shared, self.version),
process_V9708(shared), process_V1031(shared), process_V2069(shared), process_V9041(shared),
process_V3646(shared), process_V6052(shared), process_V9479(shared), process_V9888(shared),
process_V4648(shared), process_V5683(shared)]

decrypted=False
ex=None
for sharedsecret in sharedsecrets:
Expand All @@ -1361,7 +1357,7 @@ def decryptvoucher(self):

_assert(self.drmkey.hasnext() and self.drmkey.next() == TID_LIST and self.drmkey.gettypename() == "[email protected]",
"Expected KeySet, got %s" % self.drmkey.gettypename())
decrypted=True
decrypted=True

print("Decryption succeeded")
break
Expand Down

0 comments on commit 195ea69

Please sign in to comment.