Skip to content
Browse files

Further improvement of detection of encrypted RAR files.

  • Loading branch information...
1 parent cab42a4 commit eda7642af1f222cab256e4f3f592859e5f759105 @shypike shypike committed Nov 16, 2011
Showing with 12 additions and 9 deletions.
  1. +8 −7 sabnzbd/assembler.py
  2. +4 −2 sabnzbd/utils/rarfile.py
View
15 sabnzbd/assembler.py
@@ -40,7 +40,7 @@
from sabnzbd.postproc import PostProcessor
import sabnzbd.downloader
from sabnzbd.utils.rarfile import RarFile, is_rarfile
-from sabnzbd.encoding import latin1
+from sabnzbd.encoding import latin1, unicoder
#------------------------------------------------------------------------------
@@ -269,12 +269,13 @@ def ParseFilePacket(f, header):
return nothing
-def is_cloaked(names):
+def is_cloaked(path, names):
""" Return True if this is likely to be a cloaked encrypted post """
+ fname = unicoder(os.path.split(path)[1]).lower()
for name in names:
- name = name.lower()
- if name.endswith('.rar') or 'password' in name:
- return len(names) < 3
+ name = unicoder(name.lower())
+ if fname == name or 'password' in name:
+ return True
return False
@@ -283,8 +284,8 @@ def check_encrypted_rar(nzo, filepath):
encrypted = False
if not nzo.password and cfg.pause_on_pwrar() and is_rarfile(filepath):
try:
- zf = RarFile(filepath)
- encrypted = zf.encrypted or is_cloaked(zf.namelist())
+ zf = RarFile(filepath, all_names=True)
+ encrypted = zf.encrypted or is_cloaked(filepath, zf.namelist())
if encrypted and int(nzo.encrypted) < 2:
nzo.encrypted = 1
else:
View
6 sabnzbd/utils/rarfile.py
@@ -124,9 +124,11 @@ def isdir(self):
class RarFile:
'''Rar archive handling.'''
- def __init__(self, rarfile, mode="r", charset='cp850', info_callback=None):
+ def __init__(self, rarfile, mode="r", charset='cp850', info_callback=None, all_names=False):
+ # 'all_names' = show names of 'split' files too
self.rarfile = rarfile
self.charset = charset
+ self.all_names = all_names
self.info_list = []
self.is_solid = 0
@@ -215,7 +217,7 @@ def _process_entry(self, item):
# RAR_BLOCK_NEWSUB has files too: CMT, RR
if item.type == RAR_BLOCK_FILE:
# use only first part
- if (item.flags & RAR_FILE_SPLIT_BEFORE) == 0:
+ if self.all_names or (item.flags & RAR_FILE_SPLIT_BEFORE) == 0:
# Always use Unix separators
item.filename = item.filename.replace('\\', '/')
item.unicode_filename = item.unicode_filename.replace(u'\\', u'/')

0 comments on commit eda7642

Please sign in to comment.
Something went wrong with that request. Please try again.