Fix Mega Server

This commit is contained in:
Alhaziel
2019-10-15 18:27:27 +02:00
parent 0aba0a833a
commit f50e460e33
3 changed files with 32 additions and 29 deletions
+11 -8
View File
@@ -1,4 +1,5 @@
import urllib2
import traceback
class Cursor(object):
def __init__(self, file):
@@ -21,9 +22,11 @@ class Cursor(object):
req.headers['Range'] = 'bytes=%s-' % (offset)
try:
self.conn = urllib2.urlopen(req)
self.prepare_decoder(offset)
try:
self.prepare_decoder(offset)
except:
print(traceback.format_exc())
except:
#La url del archivo expira transcurrido un tiempo, si da error 403, reintenta volviendo a solicitar la url mediante la API
self.mega_request(offset, True)
def read(self,n=None):
@@ -35,7 +38,6 @@ class Cursor(object):
self.pos+=len(res)
return res
def seek(self,n):
if n>self._file.size:
n=self._file.size
@@ -53,20 +55,21 @@ class Cursor(object):
def __exit__(self,exc_type, exc_val, exc_tb):
self._file.cursors.remove(self)
if len(self._file.cursors) == 0: self._file.cursor = False
def decode(self, data):
return self.decryptor.decrypt(data)
def prepare_decoder(self,offset):
initial_value = self.initial_value + int(offset/16)
try:
from Cryptodome.Cipher import AES
from Cryptodome.Util import Counter
self.decryptor = AES.new(self._file._client.a32_to_str(self.k), AES.MODE_CTR, counter = Counter.new(128, initial_value = initial_value))
except:
from Crypto.Cipher import AES
from Crypto.Util import Counter
self.decryptor = AES.new(self._file._client.a32_to_str(self.k), AES.MODE_CTR, counter = Counter.new(128, initial_value = initial_value))
except:
from pyaes import aes
self.decryptor = aes.AESModeOfOperationCTR(f=self,key=self._client.a32_to_str(self.k),counter=aes.Counter(initial_value=initial_value))
rest = offset - int(offset/16)*16
if rest:
self.decode(str(0)*rest)
self.decode(str(0)*rest)